Wireless programming not working with large HEX [SOLVED]

Started by englund, September 25, 2013, 04:30:21 PM

englund

Hi, this time I'll hopefully actually contribute with something :)

Wireless programming has been working fine for me but then I've added a bunch of stuff to my wireless node code and when I tied to upload the HEX I always managed to send 999 packets and then it died:

On the gateway:

TX > FLX:999:103E6E0072617475726520666F722044657669633F
Moteino: RFTX > 464c583a3939393a72617475726520666f72204465766963
Moteino: RFACK > 10 > 464c583a3939393a4f4b
Moteino: FLX:999:OK
TX > FLX:1000:103E7E006520312069733A2000726164696F2025D4
Moteino: FLASH IMG TRANSMISSION FAIL


On the node:

radio [24] > 464c583a3939393a72617475726520666f72204465766963
FLX:999:OK
Timeout, erasing written data ... DONE


So I had a look in WirelessHEX69.cpp https://github.com/LowPowerLab/WirelessProgramming/blob/master/WirelessHEX69/WirelessHEX69.cpp and found a off-by-one bug in two places. Since it's such a small fix I thought I'd just post it here so you can Fix it Felix™ :) In lines 76 and 224 it should be "<9" instead of "<8" or else it breaks for 4 digit sequence numbers.

One interesting thing. The code already on the node when I experienced the error sent a packet every 3 seconds and after the above error on the gateway the serial terminal just spammed out all the packets (maybe 30 or so) that where sent during the HEX upload. This has to mean that there is a packet queue implemented in the RFM69 hardware, right?

Felix

Thanks, I'll have to check into this.
But at first glance ...

for (byte i = 4; i<8; i++)


... means 4, 5, 6, 7. Four digits. Am I missing something?

englund

The problem occurs after the sequence number has been extracted. The code expects the index to be pointing at the ':' after the sequence number but with a 4 digit number it will be pointing at the last digit instead.

Felix

Ok I looked at this a little more. The loop is fine as it is. The problem is with the index increment, it's unconditionally incremented. The index++ needs to be moved at the end of the loop and the post-loop check

if (radioDATA[index++] != ':')


needs to become:

if (radioDATA[++index] != ':')


That way there's no confusion that the loop can read UP TO 4 digits, and exit early if there are less than 4.
If I simply extend the range of the loop I allow for another subtle logical bug which I won't go into detail explaining.
But thanks for bringing this up. I will check in this later today.

englund

Yeah, that solves it too. It's working fine with the extended loop range for me though..

Felix