Starting since beginning..
I am building my own sensor platform for fast RC EDF aircraft. I am using Jumper T16 transmitter and FR Sky X8R receiver. I am using passthrough telemetry protocol (described in this spreadsheet) which talks with third party telemetry script installed on transmitter. Arduino with attached sensors is connected to smart port on X8R receiver. It is kind of UART transmission with baud rate of 57600.
Spreadsheet description is clear that all parametrs for given sensor id (for example 0x5002 for GPS) are included in single maximum 32bit value.
I am trying to make use of this library. It is designed to work with standard SmartPort telemetry, however if I manually create packet which I send by use of below command it works good. Of course I am able to manually write any packet, however the point is to create variables for sensor data input, then convert each variable to binary representation and merge all variable binary representations into one to write it to receiver by use of below command:
FrskySP.sendData (0x5002, 0b00000000000000000000000000000000); //example data
This command calls below function from FRskySP.cpp:
void FrskySP::sendData (uint16_t id, int32_t val) {
//this->sendData (id, (uint32_t) val);
this->sendData (0x10, id, (uint32_t) val); //mod
}
/*
* Packet format:
* content | length | remark
* --------- | ------ | ------
* type | 8 bit | always 0x10 at now
* sensor ID | 16 bit | sensor's logical ID (see FrskySP.h for values)
* data | 32 bit | preformated data
* crc | 8 bit | calculated by CRC()
*/
void FrskySP::sendData (uint8_t type, uint16_t id, int32_t val) {
int i = 0;
uint16_t crc = 0;
uint8_t *u8p;
// type
FrskySP::sendByte (type, &crc);
// id
u8p = (uint8_t*)&id;
FrskySP::sendByte (u8p[0], &crc);
FrskySP::sendByte (u8p[1], &crc);
// val
u8p = (uint8_t*)&val;
FrskySP::sendByte (u8p[0], &crc);
FrskySP::sendByte (u8p[1], &crc);
FrskySP::sendByte (u8p[2], &crc);
FrskySP::sendByte (u8p[3], &crc);
// crc
FrskySP::sendByte (0xFF - (uint8_t)crc, NULL);
}
that's more or less what it is all about..
Considering bitwise operations based on all the advices I created sketch:
void setup() {
Serial.begin(9600);
}
void loop() {
byte var0 = 0; //4 bit
byte var1 = 0; // 2 bits
byte var2 = 0; // 1 bit ok
byte var3 = 0; // 7 bits ok
byte var4 = 0; //1 bit ok
byte var5 = 1; // 7 bits
byte var6 = 3; //2 bits
byte var7 = 25; //7 bits
byte var8 = 1; //1 bit
uint32_t joinedvar = ((var8 & 0x1) << 31) | ((var7 & 0x7F) << 24) | ((var6 & 0x3) << 22) | ((var5 & 0x7F) << 15) | ((var4 & 0x1) << 14) | ((var3 & 0x7F) << 7) | ((var2 & 0x1) << 6) | ((var1 & 0x3) <<4) | (var0 & 0x0F);
for(int i = 0; i <= 31; i++)
{
int b =bitRead(joinedvar, i);
Serial.print(b);
}
Serial.println();
}
when I was testing this sketch by varying byte variables data it was working good until I changed var5 to zero. Serial monitor printed 32 zeroes
00000000000000000000000000000000
which is not what I expected because at least three variables was not set to 0.
My understanding of bitwise shifting is restricted to few hours of learning, that is most probable cause I can't find an error...
what do You think?