Hi,
I am using a rpi3 to communicate with the CC3D FC, when i request an objectID from the controller, i seem to recieve a different id back, not matching the id i sent. I originally thought this may have been the controller using an old version of the firmware, however i have updated my controller to next and my object ids being generated via the arduino headers in the project on the next branch.
Any suggestion to why this may have happened?
i did notice when i tried to update the firmware on the board it said i had to manually do it as it wasn't responding, i tried again and it did the same but when i plug it in, it says the most up to date bootloader 4 and 16.09 firmware.
below is my code for the request and receive of the objects,
void request(unsigned long objId) {
wiringSetup();
_pBuf[0] = 0x3c; //sync
_pBuf[1] = 0x21; //msgtype (0x21 = request)
_pBuf[2] = 0x0a; //len
_pBuf[3] = 0x00; //len
_pBuf[4] = (objId >> (8*0)) & 0xff;
_pBuf[5] = (objId >> (8*1)) & 0xff;
_pBuf[6] = (objId >> (8*2)) & 0xff;
_pBuf[7] = (objId >> (8*3)) & 0xff;
_pBuf[8] = 0x00; //iid
_pBuf[9] = 0x00; //iid
_pBuf[10] = _crc(10); //crc
printf("i am about to send the data \n");
serialPuts (fd, reinterpret_cast<const char*>(_pBuf));
}
And the code for receiving the message
bool receive(){
wiringSetup();
byte objId = FLIGHTSTATUS_OBJID;
byte *ret = FlightStatusDataUnion.arr;
bool loop = 1;
unsigned long time = millis();
while(loop) {
if (serialDataAvail(fd)) {
unsigned int timeout=2000;
loop = millis() <= time + timeout; //loop as long as start + timeout lower than current time
_pBuf[0] = serialGetchar(fd);;
if (_pBuf[0] == 0){
//NOOP
} else if(_pBuf[0] != 0x3c) {
//Serial.print(sync, HEX);
//printf(" Bad Byte ");
} else {
printf(" in the main loop \n");
_pBuf[1] = serialGetchar(fd); //msgtype
printf("sync value = %X \n",_pBuf[0]);
_pBuf[2] = serialGetchar(fd);
printf("msg type = %X \n",_pBuf[1]);
printf("length = %X",_pBuf[2]);
_pBuf[3] = serialGetchar(fd);
printf("%X \n",_pBuf[3]);
unsigned int len = (unsigned int) _pBuf[2] | (unsigned int) _pBuf[3] << 8;
if(len < 10 || len > 265) {
} else {
printf("\n");
unsigned long oid0 = serialGetchar(fd);
_pBuf[4] = oid0;
printf("%X \n",_pBuf[4]);
unsigned long oid1 = serialGetchar(fd);
_pBuf[5] = oid1;
printf("%X \n",_pBuf[5]);
unsigned long oid2 = serialGetchar(fd);
_pBuf[6] = oid2;
printf("%X \n",_pBuf[6]);
unsigned long oid3 = serialGetchar(fd);
_pBuf[7] = oid3;
printf("%X \n",_pBuf[7]);
unsigned long oid_n = oid0 + oid1 + oid2 + oid3;
unsigned long oid = oid0 + oid1 * 256 + oid2 * 65536 + oid3 * 16777216;
printf("\n\n");
printf("%lu", oid);
printf("\n");
printf("%lu", oid_n);
printf("\n just before objID");
if(oid != objId) {
printf("values aint equal");
} else {
loop = 0;
int iid0 = serialGetchar(fd);
_pBuf[8] = iid0;
int iid1 = serialGetchar(fd);
_pBuf[9] = iid1;
unsigned int iid = iid0 + iid1 * 256;
int datalen = len - 10;;
int j;
for (j = 10; j < len; j++) {
_pBuf[j] = serialGetchar(fd);
ret[j-10] = _pBuf[j];
// printf("putting values in the union struct");
}
for(int i=0;i<sizeof(ret);i++){
printf("%X",ret[i]);
}
byte crc = serialGetchar(fd);
byte ccrc = _crc(len);
return crc == ccrc;
}
}
}
} else {
loop = 0;
}
}
return false;
}
I've basically copied the same thing the guy on Extend Arduino did. Any suggestion as to why my objIds may be different? Or am i missing something?
Any help much appreciated!
Jonny