=================================================================================================================== HandleSerialHEXData() - handles the transmission of the HEX image from the serial port to the node being OTA programmed this is called at the OTA programmer side ===================================================================================================================
| 353 | // this is called at the OTA programmer side |
| 354 | //=================================================================================================================== |
| 355 | uint8_t HandleSerialHEXData(RFM69& radio, uint16_t targetID, uint16_t TIMEOUT, uint16_t ACKTIMEOUT, uint8_t DEBUG) { |
| 356 | long now=millis(); |
| 357 | uint16_t seq=0, tmp=0, inputLen; |
| 358 | uint16_t remoteID = radio.SENDERID; //save the remoteID as soon as possible |
| 359 | uint8_t sendBuf[57]; |
| 360 | char input[115]; |
| 361 | //a FLASH record should not be more than 64 bytes: FLX:9999:10042000FF4FA591B4912FB7F894662321F48C91D6 |
| 362 | |
| 363 | while(1) { |
| 364 | inputLen = readSerialLine(input); |
| 365 | if (inputLen == 0) goto timeoutcheck; |
| 366 | tmp = 0; |
| 367 | |
| 368 | if (inputLen >= 6) { //FLX:9: |
| 369 | if (input[0]=='F' && input[1]=='L' && input[2]=='X') |
| 370 | { |
| 371 | if (input[3]==':') |
| 372 | { |
| 373 | uint8_t index = 3; |
| 374 | for (uint8_t i = 4; i<8; i++) //up to 4 characters for seq number |
| 375 | { |
| 376 | if (input[i] >=48 && input[i]<=57) |
| 377 | tmp = tmp*10+input[i]-48; |
| 378 | else if (input[i]==':') |
| 379 | { |
| 380 | if (i==4) |
| 381 | return false; |
| 382 | else break; |
| 383 | } |
| 384 | index++; |
| 385 | } |
| 386 | //Serial.print(F("input[index] = "));Serial.print(F("["));Serial.print(index);Serial.print(F("]="));Serial.println(input[index]); |
| 387 | if (input[++index] != ':') return false; |
| 388 | now = millis(); //got good packet |
| 389 | index++; |
| 390 | uint8_t hexDataLen = validateHEXData(input+index, inputLen-index); |
| 391 | |
| 392 | if (hexDataLen>0 && hexDataLen<253) |
| 393 | { |
| 394 | if (tmp==seq) //only read data when packet number is the next expected SEQ number |
| 395 | { |
| 396 | uint8_t sendBufLen = prepareSendBuffer(input+index+8, sendBuf, hexDataLen, seq); //extract HEX data from input to BYTE data into sendBuf (go from 2 HEX bytes to 1 byte), +8 jumps over the header to the HEX raw data |
| 397 | //Serial.print(F("PREP "));Serial.print(sendBufLen); Serial.print(F(" > ")); PrintHex83(sendBuf, sendBufLen); |
| 398 | |
| 399 | //SEND RADIO DATA |
| 400 | if (sendHEXPacket(radio, remoteID, sendBuf, sendBufLen, seq, TIMEOUT, ACKTIMEOUT, DEBUG)) |
| 401 | { |
| 402 | sprintf((char*)sendBuf, "FLX:%u:OK",seq); |
| 403 | Serial.println((char*)sendBuf); //response to host |
| 404 | seq++; |
| 405 | } |
| 406 | else return false; |
| 407 | } |
| 408 | } |
| 409 | //else Serial.print(F("FLX:INV")); |
| 410 | else { Serial.print(F("FLX:INV:"));Serial.println(hexDataLen); } |
| 411 | } |
| 412 | if (inputLen==7 && input[3]=='?' && input[4]=='E' && input[5]=='O' && input[6]=='F') |
no test coverage detected