SNIC UART Interface library: Serial to Wi-Fi library for Murata TypeYD Wi-Fi module. For more information about TypeYD: http://www.murata.co.jp/products/microwave/module/lbwb1zzydz/index.html

Dependents:   SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more

Fork of YDwifiInterface by Takao Kishino

Files at this revision

API Documentation at this revision

Comitter:
kishino
Date:
Tue Mar 25 02:21:11 2014 +0000
Parent:
12:0254eaccfda2
Child:
14:54378c96d285
Commit message:
Created the function of the TCP / IP client. (packet send, receive)

Changed in this revision

SNIC/SNIC_Core.h Show annotated file Show diff for this revision Revisions of this file
Socket/Socket.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketConnection.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SNIC/SNIC_Core.h	Tue Mar 25 01:42:25 2014 +0000
+++ b/SNIC/SNIC_Core.h	Tue Mar 25 02:21:11 2014 +0000
@@ -89,10 +89,20 @@
     unsigned char  cmd_sid;
     unsigned char  seq;
     unsigned char  bind;
-    unsigned int   local_addr;
-    unsigned short local_port;
+    unsigned char  local_addr[4];
+    unsigned char  local_port[2];
 }tagSNIC_TCP_CREATE_SOCKET_REQ_T;
 
+/** SNIC_TCP_SEND_FROM_SOCKET_REQ */
+typedef struct
+{
+    unsigned char cmd_sid;
+    unsigned char seq;
+    unsigned char socket_id;
+    unsigned char option;
+    unsigned char payload_len[2];
+}tagSNIC_TCP_SEND_FROM_SOCKET_REQ_T;
+
 /** SNIC_TCP_CONNECT_TO_SERVER_REQ */
 typedef struct
 {
@@ -102,12 +112,7 @@
     unsigned char remote_addr[4];
     unsigned char remote_port[2];
     unsigned char recv_bufsize[2];
-/*
-    unsigned int   remote_addr;
-    unsigned short remote_port;
-    unsigned short recv_bufsize;
-*/
-    unsigned char  timeout;
+    unsigned char timeout;
 }tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T;
 
 /** WIFI_ON_REQ Command */
--- a/Socket/Socket.cpp	Tue Mar 25 01:42:25 2014 +0000
+++ b/Socket/Socket.cpp	Tue Mar 25 02:21:11 2014 +0000
@@ -73,10 +73,12 @@
     req_len++;
     if( bind != 0 )
     {
+/*
         req.local_addr = local_addr;
         req_len++;
         req.local_port = port;
         req_len++;
+*/
     }
 
     unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
--- a/Socket/TCPSocketConnection.cpp	Tue Mar 25 01:42:25 2014 +0000
+++ b/Socket/TCPSocketConnection.cpp	Tue Mar 25 02:21:11 2014 +0000
@@ -108,8 +108,59 @@
     return con_info_p->is_connected;
 }
 
+unsigned char gTCP_SEND_BUF[2048];
 int TCPSocketConnection::send(unsigned char* data_p, int length)
 {
+    // Get buffer for response payload from MemoryPool
+    tagMEMPOOL_BLOCK_T *payload_buf = mSnicWifi_p->getAlocCmdBuf();
+    if( payload_buf == NULL )
+    {
+        printf("connect payload_buf NULL\r\n");
+        return -1;
+    }
+
+    tagSNIC_TCP_SEND_FROM_SOCKET_REQ_T req;
+    // Make request
+    req.cmd_sid       = UART_CMD_SID_SNIC_SEND_FROM_SOCKET_REQ;
+    req.seq           = mUartRequestSeq++;
+    req.socket_id     = mSocketID;
+    req.option        = 0;
+    req.payload_len[0]= ( (length & 0xFF00) >> 8 );
+    req.payload_len[1]= (length & 0xFF);
+    
+    int req_size = sizeof(tagSNIC_TCP_SEND_FROM_SOCKET_REQ_T);
+    memcpy( gTCP_SEND_BUF, &req, req_size );
+    memcpy( &gTCP_SEND_BUF[req_size], data_p, length );
+    
+    unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
+    unsigned int  command_len;
+    // Preparation of command
+    command_len = mSnicWifi_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, gTCP_SEND_BUF
+                            , req_size + length, payload_buf->buf, command_array );
+
+    // Send uart command request
+    mSnicWifi_p->sendUart( command_len, command_array );
+
+//    mSnicWifi_p->mUartCommand.setCommandSID( req.cmd_sid );
+
+    // Wait UART response
+    int ret = mSnicWifi_p->mUartCommand.wait();
+    if( ret != 0 )
+    {
+        printf( "send failed\r\n" );
+        mSnicWifi_p->freeCmdBuf( payload_buf );
+        return -1;
+    }
+    
+    if( mSnicWifi_p->mUartCommand.getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS )
+    {
+        printf("send status:%02x\r\n", mSnicWifi_p->mUartCommand.getCommandStatus());
+        mSnicWifi_p->freeCmdBuf( payload_buf );
+        return -1;
+    }
+    mSnicWifi_p->freeCmdBuf( payload_buf );
+
+    // SNIC_SEND_FROM_SOCKET_REQ
     return 0;
 }