ThingPlug Test

Dependents:   WizFi310_ThingPlug_Test WizFi310_ThingPlug_Test_P

Fork of WizFi310Interface by WIZnet

Revision:
1:16e57103a7dd
Parent:
0:df571f8f8c03
Child:
5:72212beb817c
--- a/WizFi310/WizFi310_msg.cpp	Wed Oct 05 09:40:30 2016 +0000
+++ b/WizFi310/WizFi310_msg.cpp	Mon Oct 10 05:12:51 2016 +0000
@@ -27,11 +27,16 @@
 #define WIZ_DBG(x, ...)
 #endif
 
+//daniel
+char g_asyncbuf[256];
+
 // This function is operating in ISR. So you can't use debug message.
 void WizFi310::recvData ( char c )
 {
     static int cid, sub, len, count;
-
+    static int is_mqtt_data = 0;
+    char tbf[10];
+    
     switch(_state.mode)
     {
         case MODE_COMMAND:
@@ -76,6 +81,7 @@
             break;
 
         case MODE_DATA_RX:
+            
             switch(sub)
             {
                 case 0:
@@ -90,6 +96,13 @@
                     count = 0;
                     len = 0;
                 }
+                //daniel add for mqtt
+                else if ( c == 'Q' )
+                {
+                    cid = 0;
+                    is_mqtt_data = 1;
+                }
+                //
                 else
                 {
                     _state.mode = MODE_COMMAND;
@@ -97,8 +110,9 @@
                 break;
 
             case 1:
-                // ip
-                if ((c >= '0' && c <= '9') || c == '.')
+                // ip                
+//                if ((c >= '0' && c <= '9') || c == '.')
+                if (((c >= '0' && c <= '9') || c == '.') && is_mqtt_data == 0 )
                 {
                     _con[cid].ip[count] = c;
                     count++;
@@ -109,7 +123,14 @@
                     _con[cid].port = 0;
                     sub++;
                 }
-                else
+                //daniel for mqtt
+                else if( is_mqtt_data == 1)
+                {
+                    rcvd_mqtt_topic[count] = c;
+                    count++;
+                }
+//              else 
+                else if( is_mqtt_data == 0 )
                 {
                     _state.mode = MODE_COMMAND;
                 }
@@ -152,6 +173,7 @@
                 break;
 
             default:
+
                 if(_con[cid].buf != NULL)
                 {
                     _con[cid].buf->queue(c);
@@ -166,6 +188,8 @@
                 if(_con[cid].recv_length == 0)
                 {
                      //WIZ_DBG("recv cid: %d, count : %d, len : %d",cid, count, len);
+                     //sprintf(tbf, "recv cid: %d, count : %d, len : %d",cid, count, len);
+                     //strcat(g_asyncbuf, tbf);
                     _con[cid].received = true;
                     _state.mode = MODE_COMMAND;
                 }
@@ -176,7 +200,9 @@
 }
 
 
-#define MSG_TABLE_NUM 6
+//#define MSG_TABLE_NUM 6
+//daniel
+#define MSG_TABLE_NUM 8
 #define RES_TABLE_NUM 7
 int WizFi310::parseMessage () {
     int i;
@@ -192,6 +218,9 @@
         {"[CONNECT ",               &WizFi310::msgConnect},
         {"[DISCONNECT ",            &WizFi310::msgDisconnect},
         {"[LISTEN ",                &WizFi310::msgListen},
+        //daniel
+        {"[MQTT CONNECT]",               &WizFi310::msgMQTTConnect},
+        {"[MQTT DISCONNECT]",               &WizFi310::msgMQTTDisconnect},
     };
     static const struct RES_TABLE{
         const Response res;
@@ -286,6 +315,35 @@
     _con[cid].connected = false;
 }
 
+
+void WizFi310::msgMQTTConnect (const char *buf)
+{
+    int cid = 0;
+
+    //if (buf[9] < '0' || buf[9] > '8' || buf[10] != ']') return;
+
+    //cid = x2i(buf[9]);
+    initCon(cid, true);
+    _state.cid = cid;
+    _con[cid].accept = true;
+    _con[cid].parent = cid;
+    
+    _con[cid].connected = true;
+    _state.res = RES_NULL;
+    _state.ok = true;
+}
+
+void WizFi310::msgMQTTDisconnect (const char *buf)
+{
+    int cid = 0;
+
+    //if(buf[12] < '0' || buf[12] > '8' || buf[13] != ']')    return;
+
+    //cid = x2i(buf[12]);
+    _con[cid].connected = false;
+}
+
+
 void WizFi310::msgListen (const char *buf)
 {
     int cid;
@@ -428,4 +486,4 @@
         _state.gateway[gw_idx] = '\0';
         _state.res = RES_NULL;
     }
-}
+}
\ No newline at end of file