The project in my previous thread continues. I’m pretty sure I’m down to one problem before I have full functionality!
That problem is that the code I ported to the Wixel expects a UART to have a buffer storing multiple bytes. The code is written to read 8 byte ‘command packets’ output by the Arbotix Commander to one Wixel, and transmitted via the radio to the other Wixel. However, the Wixel’s wireless communication ‘data packets’ often (always, in my experience) contain a single byte. The radioComRxAvailable() function reports the length of the most recent, aka current data packet. The radioComRxReceiveByte() reads bytes only from the current data packet. In essence, it seems that the data packet is my buffer, and I’m apparently stuck with a 1-byte buffer.
radio_com.c defines #define TX_QUEUE_THRESHOLD 1
by default, which should (based on the comments above this line in the code) result in multi-byte data packets being preferred. Is there some other factor affecting whether multi-byte packets happen? (I’d rather solve this on the Wixel end, than on the Arbotix Commander end)
I’ve attempted to work around this in a simple (and unappealing) approach that is essentially this:
uint8 CmdrReadMsgs(){
int8 avail = radioComRxAvailable();
while(avail == TRUE){
// Code that reads a byte, and exits loop/function when 8 bytes have accumulated...
avail = radioComRxAvailable();
while(avail == 0) { avail = radioComRxAvailable(); }
}
}
But even that does not seem to let me read multiple bytes within one call to the function… Any insights/ideas on how to get around this? I’ll probably look at the other radio libraries next…
I do know that the correct bytes are being sent from the Commander, as verified by Commander → Wixel UART → other Wixel → other Wixel USB → computer.
The full code for this method is standalone, for purposes of understanding (e.g. what I’m doing with the 8byte ‘command packet’)… :
/* process messages coming from Commander
* format = 0xFF RIGHT_H RIGHT_V LEFT_H LEFT_V BUTTONS EXT checksum_cmdr */
uint8 CmdrReadMsgs(){
int8 loopCount = 0;
int8 avail = radioComRxAvailable();
while(avail == TRUE){
loopCount += 1;
if (loopCount > 2) { ax12LED(61,1); }
if(index_cmdr == -1){ // looking for new packet
if(radioComRxReceiveByte() == 0xff){ //read until packet start
index_cmdr = 0;
checksum_cmdr = 0;
}
}else if(index_cmdr == 0){
// add next byte to vals
vals[index_cmdr] = (unsigned char) radioComRxReceiveByte();
// look for first real byte (non 0xFF)
if(vals[index_cmdr] != 0xff){
checksum_cmdr += (int) vals[index_cmdr];
index_cmdr++;
}
}else{ //for bytes after the 0th byte
vals[index_cmdr] = (unsigned char) radioComRxReceiveByte();
//loops will sequentially read bytes and store them here
checksum_cmdr += (int) vals[index_cmdr];
index_cmdr++;
if(index_cmdr == 7){ // packet complete
if(checksum_cmdr%256 != 255){
// packet error!
index_cmdr = -1;
return 0;
}
// DO STUFF
index_cmdr = -1;
return 1;
}
}
// delayMicroseconds(250);
// delayMicroseconds(250);
// delayMicroseconds(250);
// delayMicroseconds(249);
avail = radioComRxAvailable();
while(avail == 0) { avail = radioComRxAvailable(); }
}
ax12LED(61,0);
return 0;
}
loopCount and ax12LED() (which toggles a servo’s LED) are my approach to debugging
Thanks!