@@ -26,6 +26,7 @@ uint8_t GoGoBoardArduino::gblExtSerialCmdCounter = 0;
2626bool GoGoBoardArduino::gblUseFirstExtCmdBuffer = false ;
2727bool GoGoBoardArduino::gblNewExtCmdReady = false ;
2828bool GoGoBoardArduino::gblRequestResponseAvailable = false ;
29+ bool GoGoBoardArduino::gblResponseArduinoInit = false ;
2930uint8_t GoGoBoardArduino::gbl1stExtCMDBuffer[GOGO_DEFAULT_BUFFER_SIZE ] = {0 };
3031uint8_t GoGoBoardArduino::gbl2ndExtCMDBuffer[GOGO_DEFAULT_BUFFER_SIZE ] = {0 };
3132uint8_t *GoGoBoardArduino::gblActiveBuffer = NULL ;
@@ -107,8 +108,20 @@ void GoGoBoardArduino::processPacket()
107108
108109 switch (gblExtSerialPacketType)
109110 {
110- case ARDUINO_REQUEST_PACKET_TYPE :
111- gblRequestResponseAvailable = true ;
111+ case ARDUINO_REQUEST_PACKET_TYPE : // ? response request packet type from gogoboard
112+ switch ((gblActiveBuffer[0 ]))
113+ {
114+ case REQ_READ_INPUT :
115+ gblRequestResponseAvailable = true ;
116+ break ;
117+
118+ case CMD_ARDUINO_INIT :
119+ gblResponseArduinoInit = true ;
120+ break ;
121+
122+ default :
123+ break ;
124+ }
112125 break ;
113126
114127 case ARDUINO_GMESSAGE_PACKET_TYPE :
@@ -183,8 +196,8 @@ void GoGoBoardArduino::begin(void)
183196 gogoTimer->resume ();
184197#endif
185198
186- delay (3000 ); // ? waiting for gogo to boot up
187- sendCmdPacket ((uint8_t )CMD_PACKET , (uint8_t )CMD_ARDUINO_INIT );
199+ delay (2000 ); // ? waiting for gogo to boot up
200+ sendCmdPacket ((uint8_t )CMD_PACKET , (uint8_t )CMD_ARDUINO_INIT , 0 , 0 , false );
188201}
189202
190203int GoGoBoardArduino::readInput (uint8_t port)
@@ -199,7 +212,7 @@ int GoGoBoardArduino::readInput(uint8_t port)
199212 {
200213 gblRequestResponseAvailable = false ;
201214
202- return (int )gblActiveBuffer[0 ] << 8 | gblActiveBuffer[1 ];
215+ return (int )gblActiveBuffer[1 ] << 8 | gblActiveBuffer[2 ];
203216 }
204217 else
205218 {
@@ -393,7 +406,8 @@ void GoGoBoardArduino::setBroadcastPassword(const String &password)
393406
394407void GoGoBoardArduino::sendBroadcast (const String &topic)
395408{
396- sendIoTPacket (CATEGORY_IOT_BROADCAST , IOT_BROADCAST_SEND , (uint8_t *)topic.c_str (), topic.length ());
409+ if (gblResponseArduinoInit)
410+ sendIoTPacket (CATEGORY_IOT_BROADCAST , IOT_BROADCAST_SEND , (uint8_t *)topic.c_str (), topic.length ());
397411}
398412
399413bool GoGoBoardArduino::receiveBroadcast (const String &topic)
@@ -408,7 +422,8 @@ bool GoGoBoardArduino::receiveBroadcast(const String &topic)
408422 }
409423 else // ? may not subscribe broadcast topic yet
410424 {
411- sendIoTPacket (CATEGORY_IOT_BROADCAST , IOT_BROADCAST_RECEIVE , (uint8_t *)topic.c_str (), topic.length ());
425+ if (gblResponseArduinoInit)
426+ sendIoTPacket (CATEGORY_IOT_BROADCAST , IOT_BROADCAST_RECEIVE , (uint8_t *)topic.c_str (), topic.length ());
412427 }
413428 return false ;
414429}
@@ -417,14 +432,16 @@ void GoGoBoardArduino::sendCloudMessage(const String &topic, const float payload
417432{
418433 _dataStr = topic + " ," + String (payload);
419434
420- sendIoTPacket (CATEGORY_IOT_CLOUD_MESSAGE , IOT_CLOUD_MESSAGE_PUBLISH , (uint8_t *)_dataStr.c_str (), _dataStr.length ());
435+ if (gblResponseArduinoInit)
436+ sendIoTPacket (CATEGORY_IOT_CLOUD_MESSAGE , IOT_CLOUD_MESSAGE_PUBLISH , (uint8_t *)_dataStr.c_str (), _dataStr.length ());
421437}
422438
423439void GoGoBoardArduino::sendCloudMessage (const String &topic, const String &payload)
424440{
425441 _dataStr = topic + " ," + payload;
426442
427- sendIoTPacket (CATEGORY_IOT_CLOUD_MESSAGE , IOT_CLOUD_MESSAGE_PUBLISH , (uint8_t *)_dataStr.c_str (), _dataStr.length ());
443+ if (gblResponseArduinoInit)
444+ sendIoTPacket (CATEGORY_IOT_CLOUD_MESSAGE , IOT_CLOUD_MESSAGE_PUBLISH , (uint8_t *)_dataStr.c_str (), _dataStr.length ());
428445}
429446
430447bool GoGoBoardArduino::isCloudMessageAvailable (const String &topic)
@@ -436,7 +453,8 @@ bool GoGoBoardArduino::isCloudMessageAvailable(const String &topic)
436453 }
437454 else // ? may not subscribe cloudmessage topic yet
438455 {
439- sendIoTPacket (CATEGORY_IOT_CLOUD_MESSAGE , IOT_CLOUD_MESSAGE_SUBSCRIBE , (uint8_t *)topic.c_str (), topic.length ());
456+ if (gblResponseArduinoInit)
457+ sendIoTPacket (CATEGORY_IOT_CLOUD_MESSAGE , IOT_CLOUD_MESSAGE_SUBSCRIBE , (uint8_t *)topic.c_str (), topic.length ());
440458 }
441459 return false ;
442460}
0 commit comments