disk91 / WioLoRaWANFieldTester

85 stars 32 forks source link

Flush E5 serial even if we are not in a cmd mode #78

Closed thompsa closed 3 weeks ago

thompsa commented 9 months ago

In some scenarios the firmware returns the downlink after CMSGHEX is done and the current code will ignore that. It also returns it with the +MSG: prefix which seems to be undocumented behaviour. I have my E5 in ABP mode, I didnt notice it when it was in OTAA mode.

<manual tx push #1>

AT+PORT=1
+PORT: 1
AT+CMSGHEX=XXXXXXXXXXXXXXXXXXXX
+CMSGHEX: Start
+CMSGHEX: Wait ACK
+CMSGHEX: Done

<manual tx push #2>

AT+PORT=1
+MSG: FPENDING
+MSG: ACK Received
+MSG: PORT: 2; RX: "006B93242402"
+MSG: RXWIN1, RSSI -56, SNR 2.0
+MSG: Done
+PORT: 1
AT+CMSGHEX=XXXXXXXXXXXXXXXXXXXX
+CMSGHEX: Start
+CMSGHEX: Wait ACK
+CMSGHEX: Done

As we can see there were bytes waiting on the serial port with our missing downlink. The AT+PORT flushes these while looking for "+PORT: 1" and they never get processed.

The code now flushes serial even if we are not in command mode and will look for TX messages. Change processTx() to strip the start as it could be any of CMSGHEX/MSGHEX/MSG. Note that MSGHEX sending would never have worked before.

Now the following is read and processed on a Tx.

AT+PORT=1
+PORT: 1
AT+CMSGHEX=XXXXXXXXXXXXXXXXXXXX
+CMSGHEX: Start
+CMSGHEX: Wait ACK
+CMSGHEX: Done
+MSG: ACK Received
+MSG: PORT: 2; RX: "007198242402"
+MSG: RXWIN1, RSSI -61, SNR 3.0
+MSG: Done