I found a bug in Waspmote API v0.15 when I was trying to set XBee link keys. The API failed to set the key as specified in the code. The bug lies in function gen_data()” in lines 4355-4403. Details below. However, it was corrected in v0.18.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
/* Function: Generates the API frame to send to the XBee module Parameters: data : The string that contains part ofthe API frame param : The param to set Returns: Nothing Values: Stores in 'command' variable the API frame to send to the XBee module */ void WaspXBeeCore::gen_data(const char* data, uint8_t* param) { uint8_t inc=0; uint8_t inc2=0; clearCommand(); it=0; while(data[it] != '\0') { inc++; it++; } inc/=2; while(inc2<inc){ command[inc2]=Utils.converter(data[2*inc2],data[2*inc2+1]); inc2++; } if(inc>11) { for(it=0;it<8;it++) { command[inc-9+it]=param[it]; } } else if(inc==11) { for(it=0;it<3;it++) { command[inc-4+it]=param[it]; } } else if(inc==10) { for(it=0;it<2;it++) { command[inc-3+it]=param[it]; } } else command[inc-2]=param[0]; } |
The function in v0.18 is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
/* Function: Generates the API frame to send to the XBee module Parameters: data : The string that contains part of the API frame param : The param to set Returns: Nothing Values: Stores in 'command' variable the API frame to send to the XBee module */ void WaspXBeeCore::gen_data(const char* data, uint8_t* param) { uint8_t inc=0; uint8_t inc2=0; clearCommand(); it=0; while(data[it] != '\0') { inc++; it++; } inc/=2; while(inc2<inc){ command[inc2]=Utils.converter(data[2*inc2],data[2*inc2+1]); inc2++; } // The following lines have been updated. if(inc==24) { for(it=0;it<16;it++) { command[inc-17+it]=param[it]; } } else if(inc==16) { for(it=0;it<8;it++) { command[inc-9+it]=param[it]; } } else if(inc==11) { for(it=0;it<3;it++) { command[inc-4+it]=param[it]; } } else if(inc==10) { for(it=0;it<2;it++) { command[inc-3+it]=param[it]; } } else command[inc-2]=param[0]; } |