SNIC UART Interface library for Murata Type-YD module

Dependents:   WebSocketServerTest

Fork of SNICInterface_mod by Toyomasa Watarai

Committer:
kishino
Date:
Fri Mar 28 00:45:15 2014 +0000
Revision:
24:987e412ae879
Parent:
22:a9ec0cad4f84
Child:
27:dcc4f34448f0
Changed to that any classes do not have instance of C_SNIC_Core class.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 20:dd736d328de6 1 /* Copyright (C) 2012 mbed.org, MIT License
kishino 20:dd736d328de6 2 *
kishino 20:dd736d328de6 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
kishino 20:dd736d328de6 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
kishino 20:dd736d328de6 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
kishino 20:dd736d328de6 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
kishino 20:dd736d328de6 7 * furnished to do so, subject to the following conditions:
kishino 20:dd736d328de6 8 *
kishino 20:dd736d328de6 9 * The above copyright notice and this permission notice shall be included in all copies or
kishino 20:dd736d328de6 10 * substantial portions of the Software.
kishino 20:dd736d328de6 11 *
kishino 20:dd736d328de6 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
kishino 20:dd736d328de6 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
kishino 20:dd736d328de6 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kishino 20:dd736d328de6 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kishino 20:dd736d328de6 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kishino 20:dd736d328de6 17 */
kishino 20:dd736d328de6 18 /******************* Murata Manufacturing Co.,Ltd. 2014 *****************
kishino 20:dd736d328de6 19 *
kishino 20:dd736d328de6 20 * Filename: Socket.cpp
kishino 20:dd736d328de6 21 *
kishino 20:dd736d328de6 22 * Purpose: This module has implementation of socket.
kishino 20:dd736d328de6 23 *
kishino 20:dd736d328de6 24 * $Author: kishino $
kishino 20:dd736d328de6 25 *
kishino 20:dd736d328de6 26 * $Date: 2014/03/26 $
kishino 20:dd736d328de6 27 *
kishino 20:dd736d328de6 28 * $Revision: 0.0.0.1 $
kishino 20:dd736d328de6 29 * ***********************************************************************/
kishino 20:dd736d328de6 30 #include "Socket.h"
kishino 20:dd736d328de6 31 #include <cstring>
kishino 20:dd736d328de6 32
kishino 20:dd736d328de6 33 using namespace murata_wifi;
kishino 20:dd736d328de6 34
kishino 20:dd736d328de6 35 Socket::Socket()
kishino 20:dd736d328de6 36 {
kishino 20:dd736d328de6 37 mSocketID = -1;
kishino 20:dd736d328de6 38 }
kishino 20:dd736d328de6 39
kishino 20:dd736d328de6 40 Socket::~Socket() {
kishino 20:dd736d328de6 41 // close(); //Don't want to leak
kishino 20:dd736d328de6 42 }
kishino 20:dd736d328de6 43
kishino 20:dd736d328de6 44 int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen) {
kishino 20:dd736d328de6 45 return 0;
kishino 20:dd736d328de6 46 }
kishino 20:dd736d328de6 47
kishino 20:dd736d328de6 48 int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) {
kishino 20:dd736d328de6 49 return 0;
kishino 20:dd736d328de6 50 }
kishino 20:dd736d328de6 51
kishino 20:dd736d328de6 52 int Socket::close(bool shutdown)
kishino 20:dd736d328de6 53 {
kishino 20:dd736d328de6 54
kishino 20:dd736d328de6 55 return 0;
kishino 20:dd736d328de6 56 }
kishino 20:dd736d328de6 57
kishino 20:dd736d328de6 58 #if 0
kishino 20:dd736d328de6 59 int Socket::select(struct timeval *timeout, bool read, bool write)
kishino 20:dd736d328de6 60 {
kishino 20:dd736d328de6 61 return 0;
kishino 20:dd736d328de6 62 }
kishino 20:dd736d328de6 63 #endif
kishino 20:dd736d328de6 64
kishino 20:dd736d328de6 65 int Socket::createSocket( unsigned char bind, unsigned int local_addr, unsigned short port )
kishino 20:dd736d328de6 66 {
kishino 24:987e412ae879 67 C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
kishino 24:987e412ae879 68 C_SNIC_UartCommandManager *uartCmdMgr_p = snic_core_p->getUartCommand();
kishino 20:dd736d328de6 69 // Get buffer for response payload from MemoryPool
kishino 24:987e412ae879 70 C_SNIC_Core::tagMEMPOOL_BLOCK_T *payload_buf = snic_core_p->allocCmdBuf();
kishino 20:dd736d328de6 71 if( payload_buf == NULL )
kishino 20:dd736d328de6 72 {
kishino 20:dd736d328de6 73 printf("createSocket payload_buf NULL\r\n");
kishino 20:dd736d328de6 74 return -1;
kishino 20:dd736d328de6 75 }
kishino 20:dd736d328de6 76
kishino 22:a9ec0cad4f84 77 C_SNIC_Core::tagSNIC_TCP_CREATE_SOCKET_REQ_T req;
kishino 20:dd736d328de6 78 int req_len = 0;
kishino 20:dd736d328de6 79
kishino 20:dd736d328de6 80 // Make request
kishino 20:dd736d328de6 81 req.cmd_sid = UART_CMD_SID_SNIC_TCP_CREATE_SOCKET_REQ;
kishino 20:dd736d328de6 82 req_len++;
kishino 20:dd736d328de6 83 req.seq = mUartRequestSeq++;
kishino 20:dd736d328de6 84 req_len++;
kishino 20:dd736d328de6 85 req.bind = bind;
kishino 20:dd736d328de6 86 req_len++;
kishino 20:dd736d328de6 87 if( bind != 0 )
kishino 20:dd736d328de6 88 {
kishino 20:dd736d328de6 89 /*
kishino 20:dd736d328de6 90 req.local_addr = local_addr;
kishino 20:dd736d328de6 91 req_len++;
kishino 20:dd736d328de6 92 req.local_port = port;
kishino 20:dd736d328de6 93 req_len++;
kishino 20:dd736d328de6 94 */
kishino 20:dd736d328de6 95 }
kishino 20:dd736d328de6 96
kishino 20:dd736d328de6 97 unsigned char command_array[UART_REQUEST_PAYLOAD_MAX];
kishino 20:dd736d328de6 98 unsigned int command_len;
kishino 20:dd736d328de6 99 // Preparation of command
kishino 24:987e412ae879 100 command_len = snic_core_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req
kishino 20:dd736d328de6 101 , req_len, payload_buf->buf, command_array );
kishino 20:dd736d328de6 102
kishino 20:dd736d328de6 103 // Send uart command request
kishino 24:987e412ae879 104 snic_core_p->sendUart( command_len, command_array );
kishino 20:dd736d328de6 105
kishino 20:dd736d328de6 106 int ret;
kishino 20:dd736d328de6 107 // Wait UART response
kishino 20:dd736d328de6 108 ret = uartCmdMgr_p->wait();
kishino 20:dd736d328de6 109 if( ret != 0 )
kishino 20:dd736d328de6 110 {
kishino 20:dd736d328de6 111 printf( "createSocket failed\r\n" );
kishino 24:987e412ae879 112 snic_core_p->freeCmdBuf( payload_buf );
kishino 20:dd736d328de6 113 return -1;
kishino 20:dd736d328de6 114 }
kishino 20:dd736d328de6 115
kishino 20:dd736d328de6 116 if( uartCmdMgr_p->getCommandStatus() != 0 )
kishino 20:dd736d328de6 117 {
kishino 20:dd736d328de6 118 printf("createSocket status:%02x\r\n", uartCmdMgr_p->getCommandStatus());
kishino 24:987e412ae879 119 snic_core_p->freeCmdBuf( payload_buf );
kishino 20:dd736d328de6 120 return -1;
kishino 20:dd736d328de6 121 }
kishino 20:dd736d328de6 122 mSocketID = payload_buf->buf[3];
kishino 24:987e412ae879 123 snic_core_p->freeCmdBuf( payload_buf );
kishino 20:dd736d328de6 124
kishino 20:dd736d328de6 125 return 0;
kishino 20:dd736d328de6 126 }