Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
2:e67f7c158087
Parent:
1:e392595b4b76
Child:
3:24c5f0f50bf1
--- a/Websocket.cpp	Fri Jul 20 19:04:02 2012 +0000
+++ b/Websocket.cpp	Tue Jul 24 02:07:23 2012 +0000
@@ -158,6 +158,10 @@
         while (true) {
             Net::poll();
             if (time(0) > timeout) {
+                /*
+                printf("connect timeout %u > %u\r\n",
+                    time(0), timeout);
+                */
                 return false;
             }
             if (tmr.read() > 0.05) {
@@ -316,9 +320,11 @@
 #endif //target
 }
 
-bool Websocket::sendBinary(char* str, const uint32_t len) 
+bool Websocket::sendBinary(const char* hbuf, const uint32_t hlen,
+                           char* str, const uint32_t len) 
 {
     // CJR: add function for sending binary
+    // force header info to be sent on each call
 #ifdef DEBUG
     printf("SENDBINARY()\r\n");
 #endif
@@ -346,6 +352,12 @@
     if (netif == ETH) 
     {
         Net::poll();
+        // first send the header
+        const char* hh = hbuf;
+        for (uint32_t j=0; j<hlen; j++, hh++) {
+            sendChar(*hh);
+        }
+        // now send the message
         uint32_t nbytes=0;
         char* s = str;
         for (uint32_t i=0; i<len; i++, s++) {
@@ -358,12 +370,14 @@
     return false;
 }
 
-bool Websocket::sendBinary(FILE* f, const uint32_t nbytes) 
+bool Websocket::sendBinary(const char* hbuf, const uint32_t hlen,
+                           FILE* f, const uint32_t nbytes) 
 {
 #ifdef DEBUG
     printf("SENDBINARY(FILE*)\r\n");
 #endif
     // CJR: add function for sending binary
+    // force header info to be sent on each call
     // return false if EOF or file error before nbytes sent
     
     //printf("SEND()\r\n");
@@ -391,8 +405,13 @@
     if (netif == ETH) 
     {
         Net::poll();
+        // first send the header
+        const char* hh = hbuf;
+        for (uint32_t j=0; j<hlen; j++, hh++) {
+            sendChar(*hh);
+        }
+        // conserve mbed memory by reading byte-by-byte
         uint8_t c;
-        // conserve mbed memory by reading byte-by-byte
         for (uint32_t i=0; i<nbytes; i++) {
             fread(&c, 1, 1, f);
             if ((feof(f)==0) && (ferror(f)==0)) {
@@ -407,12 +426,12 @@
     return true;
 }
 
-bool Websocket::read(char * message, const uint32_t timeout) 
+bool Websocket::read(char * message, uint32_t& len_msg, const uint32_t timeout) 
 {
 #ifdef DEBUG
     printf("READ()\r\n");
 #endif
-    uint32_t len_msg; //32 bit size
+    //uint32_t len_msg; //32 bit size
     char opcode = 0; //continuation frame
     char mask[4] = {0, 0, 0, 0}; //no mask
 #ifdef TARGET_LPC1768