Fix for Arduino WiFi shield fragmentation issue.
authorAbhishek Sharma <ce.abhishek@samsung.com>
Fri, 27 Mar 2015 10:53:25 +0000 (16:23 +0530)
committerErich Keane <erich.keane@intel.com>
Fri, 3 Apr 2015 15:48:54 +0000 (15:48 +0000)
Added fix for Arduino WiFi shield fragmentation issue.
It was dropping outgoing packets that are more than 90 bytes.

Change-Id: I8d9f4a02268346b145ff8599232132414bc86123
Signed-off-by: Abhishek Sharma <ce.abhishek@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/594
Reviewed-by: Abhishek Pandey <abhi.siso@samsung.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
resource/csdk/connectivity/src/wifi_adapter/arduino/cawificlient.cpp

index 6731a91..db67cfe 100644 (file)
@@ -34,7 +34,7 @@
 #include "caadapterutils.h"
 
 /// This is the max buffer size between Arduino and WiFi Shield
-#define ARDUINO_WIFI_SPI_RECV_BUFFERSIZE (64)
+#define ARDUINO_WIFI_BUFFERSIZE (90)
 
 #define MOD_NAME "WC"
 
@@ -68,13 +68,31 @@ uint32_t CAWiFiSendData(const char *remoteAddress, uint32_t port,
 
     IPAddress remoteIp(ip);
     Udp.beginPacket(remoteIp, (uint16_t)port);
-    int32_t ret = (int32_t)Udp.write((char *)data, dataLength);
+
+    uint32_t bytesWritten = 0;
+    while(bytesWritten < dataLength)
+    {
+        // get remaining bytes
+        size_t writeCount = dataLength - bytesWritten;
+        // write upto max ARDUINO_WIFI_BUFFERSIZE bytes
+        writeCount = Udp.write((uint8_t *)data + bytesWritten,
+                                (writeCount > ARDUINO_WIFI_BUFFERSIZE ?
+                                 ARDUINO_WIFI_BUFFERSIZE : writeCount));
+        if(writeCount == 0)
+        {
+            // write failed
+            OIC_LOG_V(ERROR, MOD_NAME, "Failed after %u", bytesWritten);
+            break;
+        }
+        bytesWritten += writeCount;
+    }
+
     if (Udp.endPacket() == 0)
     {
         OIC_LOG(ERROR, MOD_NAME, "Failed to send");
         return 0;
     }
     OIC_LOG(DEBUG, MOD_NAME, "OUT");
-    return ret;
+    return bytesWritten;
 }