// the loop function runs over and over again forever void loop() { switch (fwStatus) { case SmartSnippet: char readData; while (SerialUSB.available()) { readData = SerialUSB.read(); Serial1.write(readData); ledGreenLight(ledGLigth); ledGLigth = !ledGLigth; } while (Serial1.available()) { readData = Serial1.read(); SerialUSB.write(readData); ledBlueLight(ledBLigth); ledBLigth = !ledBLigth; } break; case Idle: break; case SizeWaiting: if (SerialUSB.available()) { ledGreenLight(HIGH); char inChar = (char)SerialUSB.read(); if (fwSize==-1) // first byte received fwSize = inChar<<8; else fwSize |= inChar; // Received the Last byte LINE_FEED if (inChar == 0x0A) { SerialUSB.print("Waiting Da15480 reset to starting the download of "); SerialUSB.print(fwSize, DEC); SerialUSB.println(" Bytes "); fwStatus = Downloading; } } break; case Downloading: if (asmeBle.fwDownload(fwSize)) { SerialUSB.println("Fw Download completed"); fwDwnOK = true; } else { SerialUSB.println("Error in Fw Download"); fwDwnOK = false; } fwStatus = Completed; break; default: Completed: ledError(fwDwnOK); break; } }
/* Report MCU error by LED */ static void _mcuSendCommand_Error(const void *pCmd, size_t szCmdLen, void *pResponse, size_t szResponseLen) { size_t i; if (pCmd != NULL) { diag_printf("MCU error, send (%d):", (int)szCmdLen); for (i = 0; i < szCmdLen; ++i) diag_printf(" %02x", (int) ((unsigned char *)pCmd)[i]); diag_printf("\n"); } if (pResponse != NULL) { diag_printf("MCU error, recv (%d):", (int)szResponseLen); for (i = 0; i < szResponseLen; ++i) diag_printf(" %02x", (int) ((unsigned char *)pResponse)[i]); diag_printf("\n"); } #if 1 //xhchen - MCU debug mcuReportError(g_uCmdSend, FALSE); #endif ledError(LED_ERROR_MCU); }