=================================================================================================================== HandleWirelessHEXData() - ACKs the wireless programming handshake and handles the complete transmission of the HEX image at the OTA programmed node side ===================================================================================================================
| 122 | // the complete transmission of the HEX image at the OTA programmed node side |
| 123 | //=================================================================================================================== |
| 124 | uint8_t HandleWirelessHEXData(RFM69& radio, uint16_t remoteID, SPIFlash& flash, uint8_t DEBUG, uint8_t LEDpin) { |
| 125 | uint32_t now=0; |
| 126 | uint16_t tmp,seq=0; |
| 127 | char buffer[16]; |
| 128 | uint16_t timeout = 3000; //3s for flash data |
| 129 | |
| 130 | #ifndef SHIFTCHANNEL |
| 131 | HandleHandshakeACK(radio, flash); |
| 132 | if (DEBUG) Serial.println(F("FLX?OK (ACK sent)")); |
| 133 | #endif |
| 134 | |
| 135 | //first clear the fist 32k block (dedicated to a new FLASH image) |
| 136 | flash.blockErase32K(0); |
| 137 | flash.writeBytes(0,"FLXIMG:", 7); |
| 138 | #if defined (MOTEINO_M0) |
| 139 | flash.writeByte(10,':'); |
| 140 | uint32_t bytesFlashed=11; |
| 141 | #else |
| 142 | flash.writeByte(9,':'); |
| 143 | uint32_t bytesFlashed=10; |
| 144 | #endif |
| 145 | now=millis(); |
| 146 | pinMode(LEDpin,OUTPUT); |
| 147 | |
| 148 | while(1) |
| 149 | { |
| 150 | if (radio.receiveDone() && radio.SENDERID == remoteID) |
| 151 | { |
| 152 | uint8_t dataLen = radio.DATALEN; |
| 153 | |
| 154 | digitalWrite(LEDpin,HIGH); |
| 155 | if (dataLen >= 4 && radio.DATA[0]=='F' && radio.DATA[1]=='L' && radio.DATA[2]=='X') |
| 156 | { |
| 157 | if (radio.DATA[3]==':' && dataLen >= 7) //FLX:_:_ |
| 158 | { |
| 159 | uint8_t index=3; |
| 160 | tmp = 0; |
| 161 | |
| 162 | //read packet SEQ |
| 163 | for (uint8_t i = 4; i<8; i++) //up to 4 characters for seq number |
| 164 | { |
| 165 | if (radio.DATA[i] >=48 && radio.DATA[i]<=57) |
| 166 | tmp = tmp*10+radio.DATA[i]-48; |
| 167 | else if (radio.DATA[i]==':') |
| 168 | { |
| 169 | if (i==4) |
| 170 | return false; |
| 171 | else break; |
| 172 | } |
| 173 | index++; |
| 174 | } |
| 175 | |
| 176 | if (DEBUG) { |
| 177 | Serial.print(F("radio [")); |
| 178 | Serial.print(dataLen); |
| 179 | Serial.print(F("] > ")); |
| 180 | PrintHex83((uint8_t*)radio.DATA, dataLen); |
| 181 | } |
no test coverage detected