Murata RF modules are designed to simplify wireless development and certification by minimizing the amount of RF expertise you need to wirelessly enable a wide range of applications.

Revision:
8:5856c23794b1
Parent:
7:a71d7c24afc0
Child:
9:0ce800923eda
--- a/MuRata.cpp	Sun Feb 08 01:22:29 2015 +0000
+++ b/MuRata.cpp	Mon Feb 15 15:17:50 2016 +0000
@@ -18,7 +18,7 @@
 
 SSIDRecordIndication * MuRata::Get_ScanResultIndication()
 {
-    while (FrameReceive())
+    if (FrameReceive())
         if (_payload.GetResponseFlag() == Request_Indication
                 && _frame.GetCommandID() == CMD_ID_WIFI
                 && _payload.GetSubCommandID() == WIFI_SCAN_RESULT_IND)
@@ -29,7 +29,7 @@
 
 WIFIConnectionIndication * MuRata::Get_WiFiStatusIndication()
 {
-    while (FrameReceive())
+    if (FrameReceive())
         if (_payload.GetResponseFlag() == Request_Indication
                 && _frame.GetCommandID() == CMD_ID_WIFI
                 && _payload.GetSubCommandID() == WIFI_NETWORK_STATUS_IND)
@@ -40,7 +40,7 @@
 
 PowerUpIndication * MuRata::Get_PowerUpIndication()
 {
-    while (FrameReceive())
+    if (FrameReceive())
         if (_payload.GetResponseFlag() == Request_Indication
                 && _frame.GetCommandID() == CMD_ID_GEN
                 && _payload.GetSubCommandID() == GEN_PWR_UP_IND)
@@ -51,7 +51,7 @@
 
 TCPStatusIndication * MuRata::Get_TcpConnectionStatusIndication()
 {
-    while (FrameReceive())
+    if (FrameReceive())
         if (_payload.GetResponseFlag() == Request_Indication
                 && _frame.GetCommandID() == CMD_ID_SNIC
                 && _payload.GetSubCommandID() == SNIC_TCP_CONNECTION_STATUS_IND)
@@ -62,7 +62,7 @@
 
 SocketReceiveInidcation * MuRata::Get_SocketReceiveIndication()
 {
-    while (FrameReceive())
+    if (FrameReceive())
         if (_payload.GetResponseFlag() == Request_Indication
                 && _frame.GetCommandID() == CMD_ID_SNIC
                 && _payload.GetSubCommandID() == SNIC_CONNECTION_RECV_IND)
@@ -73,7 +73,7 @@
 
 UDPReceivedIndication * MuRata::Get_UDPReceiveIndication()
 {
-    while (FrameReceive())
+    if (FrameReceive())
         if (_payload.GetResponseFlag() == Request_Indication
                 && _frame.GetCommandID() == CMD_ID_SNIC
                 && _payload.GetSubCommandID() == SNIC_UDP_RECV_IND)
@@ -84,7 +84,7 @@
 
 HTTPResponseIndication * MuRata::Get_HTTPResponseIndication()
 {
-    while (FrameReceive())
+    if (FrameReceive())
         if (_payload.GetResponseFlag() == Request_Indication
                 && _frame.GetCommandID() == CMD_ID_SNIC
                 && _payload.GetSubCommandID() == SNIC_HTTP_RSP_IND)
@@ -114,6 +114,20 @@
 
 bool MuRata::FrameReceive()
 {
+    timer.reset();
+    timer.start();
+    
+    while (serial->readable() <= 0)
+    {
+        if (timer.read_ms() > 1000)
+        {
+            timer.stop();
+            return false;
+        }
+    }
+    
+    timer.stop();
+        
     int value = serial->getc();
 
     while (value != UARTFrame::SOM)
@@ -148,7 +162,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_FW_VER_GET_REQ)
             return new VersionInfoResponse(&_payload);
 
@@ -166,7 +180,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_RESTORE_REQ)
             return (CMDCode)_payload.GetData()[2];
 
@@ -184,7 +198,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_RESET_REQ)
             return (CMDCode)_payload.GetData()[2];
 
@@ -203,7 +217,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_UART_CFG_REQ)
             return (CMDCode)_payload.GetData()[2];
 
@@ -227,7 +241,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_ON_REQ)
             return (WIFICode)_payload.GetData()[2];
 
@@ -245,7 +259,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_OFF_REQ)
             return (WIFICode)_payload.GetData()[2];
 
@@ -278,7 +292,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_AP_CTRL_REQ)
             return (WIFICode)_payload.GetData()[2];
 
@@ -310,7 +324,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_JOIN_REQ)
             return (WIFICode)_payload.GetData()[2];
 
@@ -328,7 +342,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_DISCONNECT_REQ)
             return (WIFICode)_payload.GetData()[2];
 
@@ -346,7 +360,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_GET_STATUS_REQ)
             return new WIFIStatusResponse(&_payload);
 
@@ -364,7 +378,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_GET_STA_RSSI_REQ) {
             char value = _payload.GetData()[2];
 
@@ -397,7 +411,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_WPS_REQ)
             return (WIFICode)_payload.GetData()[2];
 
@@ -436,7 +450,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_SCAN_REQ)
             return (WIFICode)_payload.GetData()[2];
 
@@ -456,7 +470,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_INIT_REQ)
             return new InitializationResponse(&_payload);
 
@@ -474,7 +488,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_CLEANUP_REQ)
             return (SNICCode)_payload.GetData()[2];
 
@@ -499,7 +513,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_SEND_FROM_SOCKET_REQ)
             return new SendFromSocketResponse(&_payload);
 
@@ -518,7 +532,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_CLOSE_SOCKET_REQ)
             return (SNICCode)_payload.GetData()[2];
 
@@ -537,7 +551,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_GET_DHCP_INFO_REQ)
             return new DHCPInfoResponse(&_payload);
 
@@ -560,7 +574,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_RESOLVE_NAME_REQ)
             if ((SNICCode)_payload.GetData()[2] == SNIC_SUCCESS) {
                 ip->SetValue(_payload.GetData(), 3);
@@ -594,7 +608,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_IP_CONFIG_REQ)
             return (SNICCode)_payload.GetData()[2];
 
@@ -619,7 +633,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_TCP_CONNECT_TO_SERVER_REQ)
             return new SocketStartReceiveResponse(&_payload);
 
@@ -662,7 +676,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == subID)
             return new CreateSocketResponse(&_payload);
 
@@ -683,7 +697,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_START_RECV_REQ)
             return new SocketStartReceiveResponse(&_payload);
 
@@ -707,7 +721,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_SIMPLE_SEND_REQ)
             return new SendFromSocketResponse(&_payload);
 
@@ -733,7 +747,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_SEND_FROM_SOCKET_REQ)
             return new SendFromSocketResponse(&_payload);
 
@@ -786,7 +800,7 @@
 
     Send();
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == _id)
             return new HTTPResponse(&_payload);
 
@@ -819,7 +833,7 @@
     if (chunked)
         return NULL;
 
-    while (FrameReceive())
+    if (FrameReceive())
         if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_HTTP_MORE_REQ)
             return new HTTPResponse(&_payload);