This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Fork of libMiMic by Ryo Iizuka

Files at this revision

API Documentation at this revision

Comitter:
nyatla
Date:
Thu Oct 03 02:37:22 2013 +0000
Parent:
59:cb5c3184c59f
Child:
62:8be8c5924c3e
Commit message:
fix bug under /mbed; 1.udp socket; ; add function; 1.add canread function to tcpsocket,udp socket

Changed in this revision

mbed/IpAddr.h Show annotated file Show diff for this revision Revisions of this file
mbed/TcpSocket.cpp Show annotated file Show diff for this revision Revisions of this file
mbed/TcpSocket.h Show annotated file Show diff for this revision Revisions of this file
mbed/UdpSocket.cpp Show annotated file Show diff for this revision Revisions of this file
mbed/UdpSocket.h Show annotated file Show diff for this revision Revisions of this file
--- a/mbed/IpAddr.h	Wed Oct 02 08:33:16 2013 +0000
+++ b/mbed/IpAddr.h	Thu Oct 03 02:37:22 2013 +0000
@@ -17,6 +17,8 @@
             struct NyLPC_TIPv4Addr v4;
         }addr;
     public:
+        IpAddr()
+        {this->setIPv4(0,0,0,0);}  
         IpAddr(unsigned char p4,unsigned char p3,unsigned char p2,unsigned char p1)
         {this->setIPv4(p4,p3,p2,p1);}
         
--- a/mbed/TcpSocket.cpp	Wed Oct 02 08:33:16 2013 +0000
+++ b/mbed/TcpSocket.cpp	Thu Oct 03 02:37:22 2013 +0000
@@ -46,6 +46,11 @@
         }
         return true;
     }
+    bool TcpSocket::canRecv()
+    {
+        const void* rx;
+        return NyLPC_cTcpSocket_precv(&this->_inst,&rx,0)>0;
+    }
     int TcpSocket::precv(const void* &i_rx)
     {
         return NyLPC_cTcpSocket_precv(&this->_inst,&i_rx,TIMEOUT_IN_MSEC);
--- a/mbed/TcpSocket.h	Wed Oct 02 08:33:16 2013 +0000
+++ b/mbed/TcpSocket.h	Thu Oct 03 02:37:22 2013 +0000
@@ -45,6 +45,12 @@
         int precv(const void* &i_rx);
         int precv(const char* &i_rx);
         /**
+         * true if precv has data.
+         * This can avoid the block of precv.
+         */
+        bool canRecv();
+
+        /**
          * This function seek rx pointer to next.
          * @param i_rx_size
          * seek size. Must be returned value which is small or equal by the precv.
--- a/mbed/UdpSocket.cpp	Wed Oct 02 08:33:16 2013 +0000
+++ b/mbed/UdpSocket.cpp	Thu Oct 03 02:37:22 2013 +0000
@@ -32,7 +32,12 @@
             free(this->_private_rx);
         }
     }
-    
+    bool UdpSocket::canRecv()
+    {
+        const void* rx;
+        const struct NyLPC_TIPv4RxInfo* info;
+        return NyLPC_cUdpSocket_precv(&this->_inst,&rx,&info,TIMEOUT_IN_MSEC)>0;
+    }
 
     int UdpSocket::precvfrom(const void* &i_rx,IpAddr* i_peer_host,unsigned short* i_port)
     {
@@ -48,6 +53,20 @@
         }
         return rs;
     }
+    int UdpSocket::precvfrom(const char* &i_rx,IpAddr* i_peer_host,unsigned short* i_port)
+    {
+        const struct NyLPC_TIPv4RxInfo* info;
+        int rs=NyLPC_cUdpSocket_precv(&this->_inst,(const void**)&i_rx,&info,TIMEOUT_IN_MSEC);
+        if(rs>1){
+            if(i_peer_host!=NULL){
+                i_peer_host->setIPv4(info->peer_ip);
+            }
+            if(i_port!=NULL){
+                *i_port=info->peer_port;
+            }
+        }
+        return rs;
+    }
 
     void UdpSocket::precvnext(void)
     {
@@ -57,7 +76,7 @@
     bool UdpSocket::sendTo(const IpAddr& i_host,unsigned short i_port,const void* i_tx,unsigned short i_tx_size)
     {
         int r=NyLPC_cUdpSocket_send(&this->_inst,&i_host.addr.v4,i_port,i_tx,i_tx_size,TIMEOUT_IN_MSEC);
-        return (r!=i_tx_size);
+        return (r==i_tx_size);
     
     }
     
--- a/mbed/UdpSocket.h	Wed Oct 02 08:33:16 2013 +0000
+++ b/mbed/UdpSocket.h	Thu Oct 03 02:37:22 2013 +0000
@@ -22,7 +22,21 @@
         NyLPC_TcUdpSocket_t* refBaseInstance(){return &this->_inst;}
     
     public:
+        /**
+         * @param i_port
+         * port number.
+         * @param i_rx_buf_size
+         * Size of the receive memory to allocate on heap
+         */
         UdpSocket(unsigned short i_port,unsigned short i_rx_buf_size=(unsigned short)512);
+        /**
+         * @param i_port
+         * port number.
+         * @param i_rx_buffer
+         * allocated memory for receiving. 
+         * @param i_rx_buf_size
+         * Size of the i_rx_buf
+         */
         UdpSocket(unsigned short i_port,void* i_rx_buf,unsigned short i_rx_buf_size);
         /**
          * This constructor accepts "large" packet by asynchronous handler.
@@ -38,10 +52,17 @@
          * must be IPv4 address format.
          */
         int precvfrom(const void* &i_rx,IpAddr* i_peer_host=NULL,unsigned short* i_port=NULL);
+        int precvfrom(const char* &i_rx,IpAddr* i_peer_host=NULL,unsigned short* i_port=NULL);
         /**
          * This function moves rx buffer to next packet.
          */
         void precvnext(void);
+        /**
+         * true if precv has data.
+         * This can avoid the block of precv.
+         */
+        bool canRecv();
+        
         bool sendTo(const IpAddr& i_host,unsigned short i_port,const void* i_tx,unsigned short i_tx_size);
         void joinMulticast(const IpAddr& i_host);
         void setBroadcast(void);