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
Revision 18:51d3fea96518, committed 2014-03-27
- Comitter:
- kishino
- Date:
- Thu Mar 27 06:38:56 2014 +0000
- Parent:
- 17:d8bc02c455a6
- Child:
- 19:f219d1fb6171
- Commit message:
- Changed to library from folder.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SNIC.lib Thu Mar 27 06:38:56 2014 +0000 @@ -0,0 +1,1 @@ +SNIC#841bb6e6c2aa
--- a/SNIC/CBuffer.h Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef CIRCBUFFER_H_ -#define CIRCBUFFER_H_ - -template <class T> -class CircBuffer { -public: - CircBuffer(int length) { - write = 0; - read = 0; - size = length + 1; - buf = (T *)malloc(size * sizeof(T)); - }; - - bool isFull() { - return (((write + 1) % size) == read); - }; - - bool isEmpty() { - return (read == write); - }; - - void queue(T k) { - - if (isFull()) { - read++; - read %= size; - } - buf[write++] = k; - write %= size; - } - - void flush() { - read = 0; - write = 0; - } - - - uint32_t available() { - return (write >= read) ? write - read : size - read + write; - }; - - bool dequeue(T * c) { - bool empty = isEmpty(); - if (!empty) { - *c = buf[read++]; - read %= size; - } - return(!empty); - }; - -private: - volatile uint32_t write; - volatile uint32_t read; - uint32_t size; - T * buf; -}; - -#endif
--- a/SNIC/SNIC_Core.cpp Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,242 +0,0 @@ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: SNIC_Core.cpp - * - * Purpose: This module has implementation of internal common function for API. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#include "mbed.h" -#include "SNIC_Core.h" -#include "SNIC_UartMsgUtil.h" -#include <string> - -using namespace murata_wifi; - -#define UART_RECVBUF_SIZE 2048 -typedef struct -{ - unsigned char buf[UART_RECVBUF_SIZE]; - unsigned int size; - bool is_receive; -}tagUART_RECVBUF_T; -tagUART_RECVBUF_T gUART_RCVBUF; -unsigned char gUART_TEMP_BUF[UART_RECVBUF_SIZE]; - -C_SNIC_Core *C_SNIC_Core::mInstance_p = NULL; - -C_SNIC_Core *C_SNIC_Core::getInstance() -{ - if( mInstance_p == NULL ) - { - mInstance_p = new C_SNIC_Core(); - } - return mInstance_p; -} - -C_SNIC_Core::C_SNIC_Core() -{ - int i; - - mUartCommand_p = new C_SNIC_UartCommandManager(); - for( i = 0; i < MAX_SOCKET_ID+1; i++ ) - { - mConnectInfo[i].recvbuf_p = NULL; - mConnectInfo[i].is_connected = false; - } - - mUartRecvThread_p = NULL; -} - -int C_SNIC_Core::initUart(PinName tx, PinName rx, int baud) -{ -// printf("[C_SNIC_Core::initUart]1\r\n"); - - mUartRequestSeq = 0; - - mUart_p = new RawSerial( tx, rx ); - mUart_p->baud( baud ); - mUart_p->format(8, SerialBase::None, 1); - -// printf("[C_SNIC_Core::initUart]2\r\n"); - // Initialize uart - gUART_RCVBUF.is_receive = false; - gUART_RCVBUF.size = 0; - - // Create UART recv thread - mUartRecvThread_p = new Thread( C_SNIC_Core::uartRecvThread ); -// printf("[C_SNIC_Core::initUart]3\r\n"); - if( mUartRecvThread_p == NULL ) - { - printf("[C_SNIC_Core::initUart] thread cread failed\r\n"); - return -1; - } - - return 0; -} - -unsigned int C_SNIC_Core::preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid - , unsigned char *req_buf_p, unsigned int req_buf_len - , unsigned char *response_buf_p, unsigned char *command_p ) -{ - unsigned char payload_array[UART_REQUEST_PAYLOAD_MAX]; - unsigned short payload_len; - unsigned int command_len = 0; - - // Make command payload - payload_len = C_SNIC_UartMsgUtil::makePayload( req_buf_len, req_buf_p, payload_array ); - // Make all command request - command_len = C_SNIC_UartMsgUtil::makeRequest( cmd_id, payload_array, payload_len, command_p ); - - // Set data for response - mUartCommand_p->setCommandID( cmd_id ); - mUartCommand_p->setCommandSID( cmd_sid | 0x80 ); - mUartCommand_p->setResponseBuf( response_buf_p ); - - return command_len; -} - -int C_SNIC_Core::sendUart( unsigned int len, unsigned char *data ) -{ - int ret = 0; - - mUartMutex.lock(); - for( int i = 0; i < len; i++ ) - { - // Write to UART - ret = mUart_p->putc( data[i] ); - if( ret == -1 ) - { - ret = -1; - break; - } - } - mUartMutex.unlock(); - return ret; -} - -tagMEMPOOL_BLOCK_T *C_SNIC_Core::allocCmdBuf() -{ - // Get buffer from MemoryPool - return mMemPoolPayload.alloc(); -} - -void C_SNIC_Core::freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p ) -{ - mMemPoolPayload.free( buf_p ); -} - -tagCONNECT_INFO_T *C_SNIC_Core::getConnectInfo( int socket_id ) -{ - if( (socket_id < 0) || (socket_id > MAX_SOCKET_ID) ) - { - return NULL; - } - return &mConnectInfo[socket_id]; -} - -C_SNIC_UartCommandManager *C_SNIC_Core::getUartCommand() -{ - return mUartCommand_p; -} - -DigitalOut led1(LED1); -void C_SNIC_Core::uartRecvThread (void const *args_p) { - - C_SNIC_Core *instance_p = C_SNIC_Core::getInstance(); - if ( instance_p == NULL ) - { - printf("Socket constructor error: no wifly instance available!\r\n"); - } - C_SNIC_UartCommandManager *uartCmdMgr_p = instance_p->getUartCommand(); - - int recvdata = 0; - int i; - - /* UART recv thread main loop */ - for (;;) - { - while( instance_p->mUart_p->readable() ) - { - // Receive data from UART. - instance_p->mUartMutex.lock(); - recvdata = instance_p->mUart_p->getc(); - instance_p->mUartMutex.unlock(); - - // Check UART receiving flg - if( gUART_RCVBUF.is_receive ) - { - gUART_RCVBUF.buf[ gUART_RCVBUF.size ] = (unsigned char)recvdata; - gUART_RCVBUF.size++; - // Check received data is EOM. - if( recvdata == UART_CMD_EOM ) - { - led1 = 0; -#if 0 - printf("[recv]\r\n"); - for( i = 0; i < gUART_RCVBUF.size; i++ ) - { - printf("%02x ", gUART_RCVBUF.buf[i]); - } - printf("\r\n"); -#endif - unsigned char command_id; - // Get payload from received data from UART. - int payload_len = C_SNIC_UartMsgUtil::getResponsePayload( gUART_RCVBUF.size, gUART_RCVBUF.buf - , &command_id, gUART_TEMP_BUF ); - - // Check receive a TCP or UDP packet - if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_CONNECTION_RECV_IND) ) - { - // Packet buffering - uartCmdMgr_p->bufferredPacket( gUART_TEMP_BUF, payload_len ); - } - - // Check scan results indication - else if( (command_id == UART_CMD_ID_WIFI) && (gUART_TEMP_BUF[0] == UART_CMD_SID_WIFI_SCAN_RESULT_IND) ) - { - // Scan result indicate - uartCmdMgr_p->scanResultIndicate( gUART_TEMP_BUF, payload_len ); - } - // Checks in the command which is waiting. - else if( uartCmdMgr_p->isWaitingCommand(command_id, gUART_TEMP_BUF) ) - { - // Get buffer for payload data - unsigned char *payload_buf_p = uartCmdMgr_p->getResponseBuf(); - if( payload_buf_p != NULL ) - { - memcpy( payload_buf_p, gUART_TEMP_BUF, payload_len ); - uartCmdMgr_p->setResponseBuf( NULL ); - } - // Set status - uartCmdMgr_p->setCommandStatus( gUART_TEMP_BUF[2] ); - // Set signal for command response wait. - uartCmdMgr_p->signal(); - } - - gUART_RCVBUF.size = 0; - gUART_RCVBUF.is_receive = false; - } - } - else - { - // Check received data is SOM. - if( recvdata == UART_CMD_SOM ) - { - led1 = 1; - gUART_RCVBUF.size = 0; - gUART_RCVBUF.buf[ gUART_RCVBUF.size ] = (unsigned char)recvdata; - gUART_RCVBUF.size++; - gUART_RCVBUF.is_receive = true; - } - } -// Thread::yield(); - } - Thread::yield(); - } -} -
--- a/SNIC/SNIC_Core.h Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,264 +0,0 @@ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: SNIC_Core.h - * - * Purpose: This module has define of internal common function for API. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#ifndef _SNIC_CORE_H_ -#define _SNIC_CORE_H_ - -#include "mbed.h" -#include "rtos.h" -#include "RawSerial.h" -#include "CBuffer.h" - -#include "SNIC_UartCommandManager.h" - -namespace murata_wifi -{ -#define UART_REQUEST_PAYLOAD_MAX 256 - -#define MEMPOOL_BLOCK_SIZE 2048 -#define MEMPOOL_PAYLOAD_NUM 1 -typedef struct -{ - unsigned char buf[MEMPOOL_BLOCK_SIZE]; -}tagMEMPOOL_BLOCK_T; - -#define MAX_SOCKET_ID 5 - -/** Connection information -*/ -typedef struct { - CircBuffer<unsigned char> *recvbuf_p; - bool is_connected; - bool is_received; -}tagCONNECT_INFO_T; - -/** Wi-Fi security - */ -typedef enum SECURITY { - /** Securiry Open */ - e_SEC_OPEN = 0x00, - /** Securiry WEP */ - e_SEC_WEP = 0x01, - /** Securiry WPA-PSK(TKIP) */ - e_SEC_WPA_TKIP = 0x02, - /** Securiry WPA2-PSK(AES) */ - e_SEC_WPA2_AES = 0x04, - /** Securiry WPA2-PSK(TKIP/AES) */ - e_SEC_WPA2_MIXED = 0x06, - /** Securiry WPA-PSK(AES) */ - e_SEC_WPA_AES = 0x07 -}E_SECURITY; - -/** Wi-Fi Network type - */ -typedef enum NETWORK_TYPE { - /** Infrastructure */ - e_INFRA = 0, - /** Adhoc */ - e_ADHOC = 1 -}E_NETWORK_TYPE; - -/** Wi-Fi status - */ -typedef enum WIFI_STATUS { - /** Wi-Fi OFF */ - e_STATUS_OFF = 0, - /** No network */ - e_NO_NETWORK, - /** Connected to AP (STA mode) */ - e_STA_JOINED, - /** Started on AP mode */ - e_AP_STARTED -}E_WIFI_STATUS; - -/** GEN_FW_VER_GET_REQ Command */ -typedef struct -{ - unsigned char cmd_sid; - unsigned char seq; -}tagGEN_FW_VER_GET_REQ_T; - -/** SNIC_INIT_REQ */ -typedef struct -{ - unsigned char cmd_sid; - unsigned char seq; - unsigned short buf_size; -}tagSNIC_INIT_REQ_T; - -/** SNIC_TCP_CREATE_SOCKET_REQ */ -typedef struct -{ - unsigned char cmd_sid; - unsigned char seq; - unsigned char bind; - 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 -{ - unsigned char cmd_sid; - unsigned char seq; - unsigned char socket_id; - unsigned char remote_addr[4]; - unsigned char remote_port[2]; - unsigned char recv_bufsize[2]; - unsigned char timeout; -}tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T; - -/** WIFI_ON_REQ Command */ -typedef struct -{ - unsigned char cmd_sid; - unsigned char seq; - char country[COUNTRYC_CODE_LENTH]; -}tagWIFI_ON_REQ_T; - -/** WIFI_OFF_REQ Command */ -typedef struct -{ - unsigned char cmd_sid; - unsigned char seq; -}tagWIFI_OFF_REQ_T; - -/** WIFI_DISCONNECT_REQ Command */ -typedef struct -{ - unsigned char cmd_sid; - unsigned char seq; -}tagWIFI_DISCONNECT_REQ_T; - -/** WIFI_GET_STA_RSSI_REQ Command */ -typedef struct -{ - unsigned char cmd_sid; - unsigned char seq; -}tagWIFI_GET_STA_RSSI_REQ_T; - -/** WIFI_GET_STATUS_REQ Command */ -typedef struct -{ - unsigned char cmd_sid; - unsigned char seq; - unsigned char interface; -}tagWIFI_GET_STATUS_REQ_T; - -/** WIFI_SCAN_REQ Command */ -typedef struct -{ - unsigned char cmd_sid; - unsigned char seq; - unsigned char scan_type; - unsigned char bss_type; - unsigned char bssid[BSSID_MAC_LENTH]; - unsigned char chan_list; - unsigned char ssid[SSID_MAX_LENGTH+1]; -}tagWIFI_SCAN_REQ_T; - -/** C_SNIC_Core class - */ -class C_SNIC_Core -{ - -public: - - /** Get buffer for command from memory pool. - @return Pointer of buffer - */ - tagMEMPOOL_BLOCK_T *allocCmdBuf(); - - /** Release buffer to memory pool. - @param buf_p Pointer of buffer - */ - void freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p ); - - /** Initialize UART - */ - int initUart( PinName tx, PinName rx, int baud ); - - /** Send data to UART - @param len Length of send data - @param data Pointer of send data - @return 0:success/other:fail - */ - int sendUart( unsigned int len, unsigned char *data ); - - /** Preparation of the UART command - @param cmd_id UART Command ID - @param cmd_sid UART Command SubID - @param req_buf_p Pointer of UART request buffer - @param req_buf_len Length of UART request buffer - @param response_buf_p Pointer of UART response buffer - @param command_p Pointer of UART command[output] - @return Length of UART command. - */ - unsigned int preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid - , unsigned char *req_buf_p, unsigned int req_buf_len - , unsigned char *response_buf_p, unsigned char *command_p ); - - /** - Get pointer of connection information. - @param socket_id Socket ID - @return The pointer of connection information - */ - tagCONNECT_INFO_T *getConnectInfo( int socket_id ); - - /** - Get pointer of the instance of C_SNIC_UartCommandManager. - @return The pointer of the instance of C_SNIC_UartCommandManager. - */ - C_SNIC_UartCommandManager *getUartCommand(); - - /** Get an instance of the C_SNIC_Core class. - @return Instance of the C_SNIC_Core class - @note Please do not create an instance in the default constructor this class. - Please use this method when you want to get an instance. - */ - static C_SNIC_Core *getInstance(); - -private: - static C_SNIC_Core *mInstance_p; - Thread *mUartRecvThread_p; - RawSerial *mUart_p; - Mutex mUartMutex; -// DigitalInOut mModuleReset; - C_SNIC_UartCommandManager *mUartCommand_p; - - /** MemoryPool for payload of UART response */ - MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload; - - /** Socket buffer */ - tagCONNECT_INFO_T mConnectInfo[MAX_SOCKET_ID+1]; - - /** Constructor - */ - C_SNIC_Core(); - - /** Receiving thread of UART - */ - static void uartRecvThread( void const *args_p ); -}; -} - -#endif \ No newline at end of file
--- a/SNIC/SNIC_UartCommandManager.cpp Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,183 +0,0 @@ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: SNIC_UartCommandManager.cpp - * - * Purpose: This module has implementation of function for management of - SNIC UART Command. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#include "SNIC_UartCommandManager.h" -#include "SNIC_Core.h" - -using namespace murata_wifi; - -void C_SNIC_UartCommandManager::setCommandID( unsigned char cmd_id ) -{ - mCommandID = cmd_id; -} - -unsigned char C_SNIC_UartCommandManager::getCommandID() -{ - return mCommandID; -} - -void C_SNIC_UartCommandManager::setCommandSID( unsigned char cmd_sid ) -{ - mCommandSID = cmd_sid; -} - -unsigned char C_SNIC_UartCommandManager::getCommandSID() -{ - return mCommandSID; -} - -void C_SNIC_UartCommandManager::setCommandStatus( unsigned char status ) -{ - mCommandStatus = status; -} - -unsigned char C_SNIC_UartCommandManager::getCommandStatus() -{ - return mCommandStatus; -} - -void C_SNIC_UartCommandManager::setResponseBuf( unsigned char *buf_p ) -{ - mResponseBuf_p = buf_p; -} - -unsigned char *C_SNIC_UartCommandManager::getResponseBuf() -{ - return mResponseBuf_p; -} - -void C_SNIC_UartCommandManager::setScanResultHandler( void (*handler_p)(tagSCAN_RESULT_T *scan_result) ) -{ - mScanResultHandler_p = handler_p; -} - - -int C_SNIC_UartCommandManager::wait() -{ - int ret = 0; - - // Get thread ID - mCommandThreadID = osThreadGetId(); - - // Signal flags that are reported as event are automatically cleared. - osEvent event_ret = osSignalWait( UART_COMMAND_SIGNAL, UART_COMMAND_WAIT_TIMEOUT); - if( event_ret.status != osEventSignal ) - { - ret = -1; - } - - return ret; -} - -int C_SNIC_UartCommandManager::signal() -{ - // set signal - return osSignalSet(mCommandThreadID, UART_COMMAND_SIGNAL); -} - -bool C_SNIC_UartCommandManager::isWaitingCommand( unsigned int command_id, unsigned char *payload_p ) -{ - bool ret = false; - - if( (command_id == getCommandID()) - && (payload_p[0] == getCommandSID()) ) - { - ret = true; - } - return ret; -} - -void C_SNIC_UartCommandManager::scanResultIndicate( unsigned char *payload_p, int payload_len ) -{ - if( (payload_p == NULL) || (mScanResultHandler_p == NULL) ) - { - return; - } - - tagSCAN_RESULT_T scan_result; - int ap_count = payload_p[2]; - - if( ap_count == 0 ) - { - mScanResultHandler_p( NULL ); - } - - unsigned char *ap_info_p = &payload_p[3]; - int ap_info_idx = 0; - - for( int i = 0; i < ap_count; i++ ) - { - scan_result.channel = ap_info_p[ap_info_idx]; - ap_info_idx++; - scan_result.rssi = (signed)ap_info_p[ap_info_idx]; - ap_info_idx++; - scan_result.security= ap_info_p[ap_info_idx]; - ap_info_idx++; - memcpy( scan_result.bssid, &ap_info_p[ap_info_idx], BSSID_MAC_LENTH ); - ap_info_idx += BSSID_MAC_LENTH; - scan_result.network_type= ap_info_p[ap_info_idx]; - ap_info_idx++; - scan_result.max_rate= ap_info_p[ap_info_idx]; - ap_info_idx++; - ap_info_idx++; // reserved - strcpy( scan_result.ssid, (char *)&ap_info_p[ap_info_idx] ); - ap_info_idx += strlen( (char *)&ap_info_p[ap_info_idx] ); - ap_info_idx++; - - // Scanresult callback - mScanResultHandler_p( &scan_result ); - } -} - -void C_SNIC_UartCommandManager::bufferredPacket( unsigned char *payload_p, int payload_len ) -{ - if( (payload_p == NULL) || (payload_len == 0) ) - { - return; - } - - C_SNIC_Core *instance_p = C_SNIC_Core::getInstance(); - - int socket_id; - unsigned short recv_len; - - // Get socket id from payload - socket_id = payload_p[2]; - // Get Connection information - tagCONNECT_INFO_T *con_info_p = instance_p->getConnectInfo( socket_id ); - if( con_info_p == NULL ) - { - return; - } - - if( con_info_p->is_connected == false ) - { - printf(" Socket id \"%d\" is not connected\r\n", socket_id); - return; - } - - // Get receive length from payload - recv_len= ((payload_p[3]<<8) & 0xFF00) | payload_p[4]; - for( int i = 0; i < recv_len; i++ ) - { - if( con_info_p->recvbuf_p->isFull() ) - { - printf("Receive buffer is full.\r\n"); - break; - } - - // Add to receive buffer - con_info_p->recvbuf_p->queue( payload_p[5+i] ); - } - con_info_p->is_received = true; -}
--- a/SNIC/SNIC_UartCommandManager.h Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: SNIC_UartCommandManager.h - * - * Purpose: This module has define of function for management of - SNIC UART Command. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#ifndef _SNIC_UART_COMMAND_MANAGER_H_ -#define _SNIC_UART_COMMAND_MANAGER_H_ -#include "mbed.h" -#include "rtos.h" - -namespace murata_wifi -{ -/** Max length of SSID */ -#define SSID_MAX_LENGTH 32 -/** Max length of BSSID */ -#define BSSID_MAC_LENTH 6 -/** Length of Country code */ -#define COUNTRYC_CODE_LENTH 2 - -/** Wait signal ID of UART command */ -#define UART_COMMAND_SIGNAL 0x00000001 -/** Timeout of UART command wait(ms)*/ -#define UART_COMMAND_WAIT_TIMEOUT 10000 - -/** Scan result -*/ -typedef struct { - bool is_complete; - /** Channel */ - unsigned char channel; - /** RSSI */ - signed char rssi; - /** Security type */ - unsigned char security; - /** BSSID */ - unsigned char bssid[BSSID_MAC_LENTH]; - /** Network type */ - unsigned char network_type; - /** Max data rate */ - unsigned char max_rate; - /** SSID */ - char ssid[SSID_MAX_LENGTH+1]; -}tagSCAN_RESULT_T; - -/** C_SNIC_UartCommandManager class - */ -class C_SNIC_UartCommandManager -{ -public: - /** Set Command ID - @param cmd_id Command ID - */ - void setCommandID( unsigned char cmd_id ); - - /** Get Command ID - @return Command ID - */ - unsigned char getCommandID(); - - /** Set Command SubID - @param cmd_sid Command Sub ID - */ - void setCommandSID( unsigned char cmd_sid ); - - /** Get Command SubID - @return Command Sub ID - */ - unsigned char getCommandSID(); - - /** Set Command status - @param status Command status - */ - void setCommandStatus( unsigned char status ); - - /** Get Command status - @return Command status - */ - unsigned char getCommandStatus(); - - /** Set Response buffer - @param buf_p Pointer of response buffer - */ - void setResponseBuf( unsigned char *buf_p ); - - /** Get Response buffer - @return Pointer of response buffer - */ - unsigned char *getResponseBuf(); - - /** Set scan result callback hander - @param handler_p Pointer of callback function - */ - void setScanResultHandler( void (*handler_p)(tagSCAN_RESULT_T *scan_result) ); - - void bufferredPacket( unsigned char *payload_p, int payload_len ); - - void scanResultIndicate( unsigned char *payload_p, int payload_len ); - - /** Checks in the command which is waiting from Command ID and Sub ID. - @param command_id Command ID - @param payload_p Command payload - @return true: Waiting command / false: Not waiting command - */ - bool isWaitingCommand( unsigned int command_id, unsigned char *payload_p ); - - int wait(); - - int signal(); - -private: - /** Command request thread ID */ - osThreadId mCommandThreadID; - /** Command ID */ - unsigned char mCommandID; - /** Command SubID */ - unsigned char mCommandSID; - /** Status of command response */ - unsigned char mCommandStatus; - /** ResponseData of command response */ - unsigned char *mResponseBuf_p; - /** Scan result handler */ - void (*mScanResultHandler_p)(tagSCAN_RESULT_T *scan_result); -}; - -} -#endif
--- a/SNIC/SNIC_UartMsgUtil.cpp Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: SNIC_UartMsgUtil.cpp - * - * Purpose: This module has implementation of function for utilities - * of SNIC UART Command. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#include "SNIC_UartMsgUtil.h" - -using namespace murata_wifi; - -C_SNIC_UartMsgUtil::C_SNIC_UartMsgUtil() -{ -} - -unsigned short C_SNIC_UartMsgUtil::makePayload( unsigned int cmd_len, unsigned char *cmd_p, unsigned char *payload_p ) -{ - unsigned short payload_len = 0; - int i; - - for( i = 0; i < cmd_len; i++, payload_p++, payload_len++ ) - { - /* check Escape code */ - if( ( cmd_p[i] == UART_CMD_SOM ) || ( cmd_p[i] == UART_CMD_EOM ) || ( cmd_p[i] == UART_CMD_ESC ) ) - { - /* Add ESC */ - *payload_p = UART_CMD_ESC; - payload_len++; - - payload_p++; - *payload_p = (0x80 | cmd_p[i]); - } - else - { - *payload_p = cmd_p[i]; - } - } - - return payload_len; -} - -unsigned int C_SNIC_UartMsgUtil::makeRequest( unsigned char cmd_id,unsigned char *payload_p - , unsigned short payload_len, unsigned char *uart_command_p ) -{ - unsigned char check_sum = 0; // Check Sum - unsigned int uart_cmd_len = 0; - int i; - - // set SOM - *uart_command_p = UART_CMD_SOM; - uart_command_p++; - uart_cmd_len++; - - // set payload length L0 - *uart_command_p = (0x80 | (payload_len & 0x007f)); - check_sum += *uart_command_p; - uart_command_p++; - uart_cmd_len++; - - // set payload length L1 - *uart_command_p = (0x80 | ( (payload_len >> 7) & 0x003f)); - check_sum += *uart_command_p; - uart_command_p++; - uart_cmd_len++; - - // set Command ID - *uart_command_p = (0x80 | cmd_id); - check_sum += *uart_command_p; - uart_command_p++; - uart_cmd_len++; - - // set Payload - for( i = 0; i < payload_len; i++, uart_command_p++, uart_cmd_len++ ) - { - *uart_command_p = payload_p[i]; - check_sum += *uart_command_p; - } - - // set Check sum - *uart_command_p = (0x80 | check_sum); - uart_command_p++; - uart_cmd_len++; - - // set EOM - *uart_command_p = UART_CMD_EOM; - uart_cmd_len++; - - return uart_cmd_len; -} - -unsigned int C_SNIC_UartMsgUtil::getResponsePayload( unsigned int recvdata_len, unsigned char *recvdata_p - , unsigned char *command_id_p, unsigned char *payload_p ) -{ - unsigned short payload_len = 0; - unsigned int response_len = 0; - unsigned char *buf = NULL; - bool isESC = false; - int i; - - // get payload length - payload_len = ( ( (recvdata_p[1] & ~0x80) & 0xff) | ( ( (recvdata_p[2] & ~0xC0) << 7) & 0xff80) ); - - // get Command ID - *command_id_p = (recvdata_p[3] & ~0x80); - - buf = &recvdata_p[4]; - - // get payload data - for( i = 0; i < payload_len; i++, buf++ ) - { - if( isESC ) - { - *payload_p = (*buf & ~0x80); - payload_p++; - response_len++; - isESC = false; - } - else - { - // Check Escape code - if( *buf == UART_CMD_ESC ) - { - isESC = true; - continue; - } - else - { - *payload_p = *buf; - payload_p++; - response_len++; - } - } - } - - return response_len; -} \ No newline at end of file
--- a/SNIC/SNIC_UartMsgUtil.h Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: SNIC_UartMsgUtil.h - * - * Purpose: This module has define of function for utilities - * of SNIC UART Command. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#ifndef _SNIC_WIFI_UART_MSG_UTIL_H_ -#define _SNIC_WIFI_UART_MSG_UTILH_ - -#include "mbed.h" -#include "rtos.h" -#include "RawSerial.h" - -namespace murata_wifi -{ - -#define UART_CMD_SOM 0x02 -#define UART_CMD_EOM 0x04 -#define UART_CMD_ESC 0x10 - -/* SNIC UART Command ID */ -#define UART_CMD_ID_GEN 0x01 //General command -#define UART_CMD_ID_SNIC 0x70 //SNIC command -#define UART_CMD_ID_WIFI 0x50 //Wi-Fi command - -/* SNIC UART Subcommand ID */ -#define UART_CMD_SID_GEN_PWR_UP_IND 0x00 //Power up indication -#define UART_CMD_SID_GEN_FW_VER_GET_REQ 0x08 //Get firmware version string - -#define UART_CMD_SID_SNIC_INIT_REQ 0x00 // SNIC API initialization -#define UART_CMD_SID_SNIC_CLEANUP_REQ 0x01 // SNIC API cleanup -#define UART_CMD_SID_SNIC_SEND_FROM_SOCKET_REQ 0x02 // Send from socket -#define UART_CMD_SID_SNIC_CLOSE_SOCKET_REQ 0x03 // Close socket -#define UART_CMD_SID_SNIC_ SOCKET _PARTIAL_CLOSE_ REQ 0x04 // Socket partial close -#define UART_CMD_SID_SNIC_GETSOCKOPT_REQ 0x05 // Get socket option -#define UART_CMD_SID_SNIC_SETSOCKOPT_REQ 0x06 // Set socket option -#define UART_CMD_SID_SNIC_SOCKET_GETNAME_REQ 0x07 // Get name or peer name -#define UART_CMD_SID_SNIC_SEND_ARP_REQ 0x08 // Send ARP request -#define UART_CMD_SID_SNIC_GET_DHCP_INFO_REQ 0x09 // Get DHCP info -#define UART_CMD_SID_SNIC_RESOLVE_NAME_REQ 0x0A // Resolve a host name to IP address -#define UART_CMD_SID_SNIC_IP_CONFIG_REQ 0x0B // Configure DHCP or static IP -#define UART_CMD_SID_SNIC_DATA_IND_ACK_CONFIG_REQ 0x0C // ACK configuration for data indications -#define UART_CMD_SID_SNIC_TCP_CREATE_SOCKET_REQ 0x10 // Create TCP socket -#define UART_CMD_SID_SNIC_TCP_CREATE_CONNECTION_REQ 0x11 // Create TCP connection server -#define UART_CMD_SID_SNIC_TCP_CONNECT_TO_SERVER_REQ 0x12 // Connect to TCP server -#define UART_CMD_SID_SNIC_UDP_CREATE_SOCKET_REQ 0x13 // Create UDP socket -#define UART_CMD_SID_SNIC_UDP_START_RECV_REQ 0x14 // Start UDP receive on socket -#define UART_CMD_SID_SNIC_UDP_SIMPLE_SEND_REQ 0x15 // Send UDP packet -#define UART_CMD_SID_SNIC_UDP_SEND_ FROM_SOCKET_REQ 0x16 // Send UDP packet from socket -#define UART_CMD_SID_SNIC_HTTP_REQ 0x17 // Send HTTP request -#define UART_CMD_SID_SNIC_HTTP_MORE_REQ 0x18 // Send HTTP more data request -#define UART_CMD_SID_SNIC_HTTPS_REQ 0x19 // Send HTTPS request -#define UART_CMD_SID_SNIC_TCP_CREATE_ADV_TLS_SOCKET_REQ 0x1A // Create advanced TLS TCP socket -#define UART_CMD_SID_SNIC_TCP_CREAET_SIMPLE_TLS_SOCKET_REQ 0x1B // Create simple TLS TCP socket -#define UART_CMD_SID_SNIC_TCP_CONNECTION_STATUS_IND 0x20 // Connection status indication -#define UART_CMD_SID_SNIC_TCP_CLIENT_SOCKET_IND 0x21 // TCP client socket indication -#define UART_CMD_SID_SNIC_CONNECTION_RECV_IND 0x22 // TCP or connected UDP packet received indication -#define UART_CMD_SID_SNIC_UDP_RECV_IND 0x23 // UCP packet received indication -#define UART_CMD_SID_SNIC_ARP_REPLY_IND 0x24 // ARP reply indication -#define UART_CMD_SID_SNIC_HTTP_RSP_IND 0x25 // HTTP response indication - -#define UART_CMD_SID_WIFI_ON_REQ 0x00 // Turn on Wifi -#define UART_CMD_SID_WIFI_OFF_REQ 0x01 // Turn off Wifi -#define UART_CMD_SID_WIFI_JOIN_REQ 0x02 // Associate to a network -#define UART_CMD_SID_WIFI_DISCONNECT_REQ 0x03 // Disconnect from a network -#define UART_CMD_SID_WIFI_GET_STATUS_REQ 0x04 // Get WiFi status -#define UART_CMD_SID_WIFI_SCAN_REQ 0x05 // Scan WiFi networks -#define UART_CMD_SID_WIFI_GET_STA_RSSI_REQ 0x06 // Get STA signal strength (RSSI) -#define UART_CMD_SID_WIFI_AP_CTRL_REQ 0x07 // Soft AP on-off control -#define UART_CMD_SID_WIFI_WPS_REQ 0x08 // Start WPS process -#define UART_CMD_SID_WIFI_AP_GET_CLIENT_REQ 0x0A // Get clients that are associated to the soft AP. -#define UART_CMD_SID_WIFI_NETWORK_STATUS_IND 0x10 // Network status indication -#define UART_CMD_SID_WIFI_SCAN_RESULT_IND 0x11 // Scan result indication - -/* SNIC UART Command response status code */ -#define UART_CMD_RES_SNIC_SUCCESS 0x00 -#define UART_CMD_RES_SNIC_FAIL 0x01 -#define UART_CMD_RES_SNIC_INIT_FAIL 0x02 -#define UART_CMD_RES_SNIC_CLEANUP_FAIL 0x03 -#define UART_CMD_RES_SNIC_GETADDRINFO_FAIL 0x04 -#define UART_CMD_RES_SNIC_CREATE_SOCKET_FAIL 0x05 -#define UART_CMD_RES_SNIC_BIND_SOCKET_FAIL 0x06 -#define UART_CMD_RES_SNIC_LISTEN_SOCKET_FAIL 0x07 -#define UART_CMD_RES_SNIC_ACCEPT_SOCKET_FAIL 0x08 -#define UART_CMD_RES_SNIC_PARTIAL_CLOSE_FAIL 0x09 -#define UART_CMD_RES_SNIC_SOCKET_PARTIALLY_CLOSED 0x0A -#define UART_CMD_RES_SNIC_SOCKET_CLOSED 0x0B -#define UART_CMD_RES_SNIC_CLOSE_SOCKET_FAIL 0x0C -#define UART_CMD_RES_SNIC_PACKET_TOO_LARGE 0x0D -#define UART_CMD_RES_SNIC_SEND_FAIL 0x0E -#define UART_CMD_RES_SNIC_CONNECT_TO_SERVER_FAIL 0x0F -#define UART_CMD_RES_SNIC_NOT_ENOUGH_MEMORY 0x10 -#define UART_CMD_RES_SNIC_TIMEOUT 0x11 -#define UART_CMD_RES_SNIC_CONNECTION_UP 0x12 -#define UART_CMD_RES_SNIC_GETSOCKOPT_FAIL 0x13 -#define UART_CMD_RES_SNIC_SETSOCKOPT_FAIL 0x14 -#define UART_CMD_RES_SNIC_INVALID_ARGUMENT 0x15 -#define UART_CMD_RES_SNIC_SEND_ARP_FAIL 0x16 -#define UART_CMD_RES_SNIC_INVALID_SOCKET 0x17 -#define UART_CMD_RES_SNIC_COMMAND_PENDING 0x18 -#define UART_CMD_RES_SNIC_SOCKET_NOT_BOUND 0x19 -#define UART_CMD_RES_SNIC_SOCKET_NOT_CONNECTED 0x1A -#define UART_CMD_RES_SNIC_NO_NETWORK 0x20 -#define UART_CMD_RES_SNIC_INIT_NOT_DONE 0x21 -#define UART_CMD_RES_SNIC_NET_IF_FAIL 0x22 -#define UART_CMD_RES_SNIC_NET_IF_NOT_UP 0x23 -#define UART_CMD_RES_SNIC_DHCP_START_FAIL 0x24 - -#define UART_CMD_RES_WIFI_SUCCESS 0x00 -#define UART_CMD_RES_WIFI_ERR_UNKNOWN_COUNTRY 0x01 -#define UART_CMD_RES_WIFI_ERR_INIT_FAIL 0x02 -#define UART_CMD_RES_WIFI_ERR_ALREADY_JOINED 0x03 -#define UART_CMD_RES_WIFI_ERR_AUTH_TYPE 0x04 -#define UART_CMD_RES_WIFI_ERR_JOIN_FAIL 0x05 -#define UART_CMD_RES_WIFI_ERR_NOT_JOINED 0x06 -#define UART_CMD_RES_WIFI_ERR_LEAVE_FAILED 0x07 -#define UART_CMD_RES_WIFI_COMMAND_PENDING 0x08 -#define UART_CMD_RES_WIFI_WPS_NO_CONFIG 0x09 -#define UART_CMD_RES_WIFI_NETWORK_UP 0x10 -#define UART_CMD_RES_WIFI_NETWORK_DOWN 0x11 -#define UART_CMD_RES_WIFI_FAIL 0xFF - -/** UART Command sequence number -*/ -static unsigned char mUartRequestSeq; - -/** C_SNIC_UartMsgUtil class - */ -class C_SNIC_UartMsgUtil -{ - -public: - C_SNIC_UartMsgUtil(); - - /** Make SNIC UART command payload. - @param cmd_len Command length - @param cmd_p Command pointer - @param payload_p Payload pointer[output] - @return payload length - */ - static unsigned short makePayload( unsigned int cmd_len, unsigned char *cmd_p, unsigned char *payload_p ); - - /** Make SNIC UART command. - @param cmd_id Command ID - @param payload_p Payload pointer - @param uart_command_p UART Command pointer [output] - @return UART Command length - */ - static unsigned int makeRequest( unsigned char cmd_id, unsigned char *payload_p, unsigned short payload_len, unsigned char *uart_command_p ); - - - /** Get uart command from receive data. - @param recvdata_len Receive data length - @param recvdata_p Pointer of received data from UART - @param command_id_p Pointer of command ID[output] - @param payload_p Pointer of payload[output] - @return Payload length - */ - static unsigned int getResponsePayload( unsigned int recvdata_len, unsigned char *recvdata_p - , unsigned char *command_id_p, unsigned char *payload_p ); -protected: - -}; -} -#endif /* _YD_WIFI_UART_MSG_H_ */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Socket.lib Thu Mar 27 06:38:56 2014 +0000 @@ -0,0 +1,1 @@ +Socket#1d9aee205ae4
--- a/Socket/Endpoint.cpp Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: Endpoint.cpp - * - * Purpose: This module has implementation of socket end point. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#include "Socket.h" -#include "Endpoint.h" -#include <cstring> -#include <cstdio> - -using namespace murata_wifi; - -Endpoint::Endpoint() -{ - reset_address(); -} - -Endpoint::~Endpoint() -{ -} - -void Endpoint::reset_address(void) -{ - _ipAddress[0] = '\0'; -} - -#include "stdio.h" - -int Endpoint::set_address(const char* host, const int port) -{ - reset_address(); - - return 0; -} - -char* Endpoint::get_address() -{ - return 0; -} - -int Endpoint::get_port() -{ - return 0; -}
--- a/Socket/Endpoint.h Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: Endpoint.h - * - * Purpose: This module has define of socket end point. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#ifndef ENDPOINT_H -#define ENDPOINT_H - -namespace murata_wifi -{ - -class UDPSocket; - -/** -IP Endpoint (address, port) -*/ -class Endpoint { - friend class UDPSocket; - -public: - /** IP Endpoint (address, port) - */ - Endpoint(void); - - ~Endpoint(void); - - /** Reset the address of this endpoint - */ - void reset_address(void); - - /** Set the address of this endpoint - \param host The endpoint address (it can either be an IP Address or a hostname that will be resolved with DNS). - \param port The endpoint port - \return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). - */ - int set_address(const char* host, const int port); - - /** Get the IP address of this endpoint - \return The IP address of this endpoint. - */ - char* get_address(void); - - /** Get the port of this endpoint - \return The port of this endpoint - */ - int get_port(void); - -protected: - char _ipAddress[17]; -// struct sockaddr_in _remoteHost; - -}; -} -#endif
--- a/Socket/Socket.cpp Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: Socket.cpp - * - * Purpose: This module has implementation of socket. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#include "Socket.h" -#include <cstring> - -using namespace murata_wifi; - -Socket::Socket() -{ - mSnicWifi_p = C_SNIC_Core::getInstance(); - mSocketID = -1; -} - -Socket::~Socket() { -// close(); //Don't want to leak -} - -int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen) { - return 0; -} - -int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) { - return 0; -} - -int Socket::close(bool shutdown) -{ - - return 0; -} - -#if 0 -int Socket::select(struct timeval *timeout, bool read, bool write) -{ - return 0; -} -#endif - -int Socket::createSocket( unsigned char bind, unsigned int local_addr, unsigned short port ) -{ - C_SNIC_UartCommandManager *uartCmdMgr_p = mSnicWifi_p->getUartCommand(); - // Get buffer for response payload from MemoryPool - tagMEMPOOL_BLOCK_T *payload_buf = mSnicWifi_p->allocCmdBuf(); - if( payload_buf == NULL ) - { - printf("createSocket payload_buf NULL\r\n"); - return -1; - } - - tagSNIC_TCP_CREATE_SOCKET_REQ_T req; - int req_len = 0; - - // Make request - req.cmd_sid = UART_CMD_SID_SNIC_TCP_CREATE_SOCKET_REQ; - req_len++; - req.seq = mUartRequestSeq++; - req_len++; - req.bind = bind; - 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]; - unsigned int command_len; - // Preparation of command - command_len = mSnicWifi_p->preparationSendCommand( UART_CMD_ID_SNIC, req.cmd_sid, (unsigned char *)&req - , req_len, payload_buf->buf, command_array ); - - // Send uart command request - mSnicWifi_p->sendUart( command_len, command_array ); - - int ret; - // Wait UART response - ret = uartCmdMgr_p->wait(); - if( ret != 0 ) - { - printf( "createSocket failed\r\n" ); - mSnicWifi_p->freeCmdBuf( payload_buf ); - return -1; - } - - if( uartCmdMgr_p->getCommandStatus() != 0 ) - { - printf("createSocket status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); - mSnicWifi_p->freeCmdBuf( payload_buf ); - return -1; - } - mSocketID = payload_buf->buf[3]; - mSnicWifi_p->freeCmdBuf( payload_buf ); - - return 0; -}
--- a/Socket/Socket.h Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: Socket.h - * - * Purpose: This module has define of socket. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#ifndef SOCKET_H_ -#define SOCKET_H_ - -#include "SNIC_Core.h" -#include "SNIC_UartMsgUtil.h" - -typedef unsigned long socklen_t; - -namespace murata_wifi -{ - -#define SNIC_UART_RECVBUF_SIZE 2048 - -/** Socket file descriptor and select wrapper - */ -class Socket { -public: - /** Socket - */ - Socket(); - - /** Set socket options - @param level stack level (see: lwip/sockets.h) - @param optname option ID - @param optval option value - @param socklen_t length of the option value - @return 0 on success, -1 on failure - */ - int set_option(int level, int optname, const void *optval, socklen_t optlen); - - /** Get socket options - @param level stack level (see: lwip/sockets.h) - @param optname option ID - \param optval buffer pointer where to write the option value - \param socklen_t length of the option value - \return 0 on success, -1 on failure - */ - int get_option(int level, int optname, void *optval, socklen_t *optlen); - - /** Close the socket - \param shutdown free the left-over data in message queues - */ - int close(bool shutdown=true); - - ~Socket(); - - int createSocket( unsigned char bind = 0, unsigned int local_addr = 0, unsigned short port = 0 ); - -protected: - int mSocketID; - C_SNIC_Core *mSnicWifi_p; - -#if 0 - bool _blocking; - int _timeout; - GSwifi * _wifi; - - bool _server; - int _cid; - int _port; -#endif - -private: - -// int select(struct timeval *timeout, bool read, bool write); -}; -} - -#endif /* SOCKET_H_ */
--- a/Socket/TCPSocketConnection.cpp Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,228 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: TCPSocketConnection.cpp - * - * Purpose: This module has implementation of TCP connection. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#include "TCPSocketConnection.h" -#include <cstring> - -using namespace murata_wifi; - -TCPSocketConnection::TCPSocketConnection() -{ -} - -int TCPSocketConnection::connect( unsigned int ip_addr, unsigned short port) -{ - int ret; - C_SNIC_UartCommandManager *uartCmdMgr_p = mSnicWifi_p->getUartCommand(); - - // Socket create - ret = createSocket(); - if( ret != 0 ) - { - printf("createSocket error : %d\r\n", ret); - return -1; - } - - // Get buffer for response payload from MemoryPool - tagMEMPOOL_BLOCK_T *payload_buf = mSnicWifi_p->allocCmdBuf(); - if( payload_buf == NULL ) - { - printf("connect payload_buf NULL\r\n"); - return -1; - } - - tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T req; - // Make request - req.cmd_sid = UART_CMD_SID_SNIC_TCP_CONNECT_TO_SERVER_REQ; - req.seq = mUartRequestSeq++; - req.socket_id = mSocketID; - - // set ip addr ( byte order ) - req.remote_addr[0] = ( (ip_addr & 0xFF000000) >> 24 ); - req.remote_addr[1] = ( (ip_addr & 0xFF0000) >> 16 ); - req.remote_addr[2] = ( (ip_addr & 0xFF00) >> 8 ); - req.remote_addr[3] = (ip_addr & 0xFF); - req.remote_port[0] = ( (port & 0xFF00) >> 8 ); - req.remote_port[1] = (port & 0xFF); - req.recv_bufsize[0] = ( (SNIC_UART_RECVBUF_SIZE & 0xFF00) >> 8 ); - req.recv_bufsize[1] = (SNIC_UART_RECVBUF_SIZE & 0xFF); - req.timeout = 60; - - 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, (unsigned char *)&req - , sizeof(tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T), payload_buf->buf, command_array ); - - // Send uart command request - mSnicWifi_p->sendUart( command_len, command_array ); - - uartCmdMgr_p->setCommandSID( UART_CMD_SID_SNIC_TCP_CONNECTION_STATUS_IND ); - - // Wait UART response - ret = uartCmdMgr_p->wait(); - if( ret != 0 ) - { - printf( "connect failed\r\n" ); - mSnicWifi_p->freeCmdBuf( payload_buf ); - return -1; - } - - if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_CONNECTION_UP ) - { - printf("connect status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); - mSnicWifi_p->freeCmdBuf( payload_buf ); - return -1; - } - mSnicWifi_p->freeCmdBuf( payload_buf ); - - // Initialize connection information - tagCONNECT_INFO_T *con_info_p = mSnicWifi_p->getConnectInfo( mSocketID ); - if( con_info_p->recvbuf_p == NULL ) - { - printf( "create recv buffer[socket:%d]\r\n", mSocketID); - con_info_p->recvbuf_p = new CircBuffer<unsigned char>(SNIC_UART_RECVBUF_SIZE); - } - con_info_p->is_connected = true; - con_info_p->is_received = false; - - return 0; -} - -bool TCPSocketConnection::is_connected(void) -{ - tagCONNECT_INFO_T *con_info_p = mSnicWifi_p->getConnectInfo( mSocketID ); - return con_info_p->is_connected; -} - -unsigned char gTCP_SEND_BUF[2048]; -int TCPSocketConnection::send(unsigned char* data_p, int length) -{ - C_SNIC_UartCommandManager *uartCmdMgr_p = mSnicWifi_p->getUartCommand(); - - // Get buffer for response payload from MemoryPool - tagMEMPOOL_BLOCK_T *payload_buf = mSnicWifi_p->allocCmdBuf(); - 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 = uartCmdMgr_p->wait(); - if( ret != 0 ) - { - printf( "send failed\r\n" ); - mSnicWifi_p->freeCmdBuf( payload_buf ); - return -1; - } - - if( uartCmdMgr_p->getCommandStatus() != UART_CMD_RES_SNIC_SUCCESS ) - { - printf("send status:%02x\r\n", uartCmdMgr_p->getCommandStatus()); - mSnicWifi_p->freeCmdBuf( payload_buf ); - return -1; - } - mSnicWifi_p->freeCmdBuf( payload_buf ); - - // SNIC_SEND_FROM_SOCKET_REQ - return 0; -} - -int TCPSocketConnection::receive(unsigned char* data_p, int length) -{ - int i = 0; - - if( (data_p == NULL) || (length < 1) ) - { - printf("TCPSocketConnection::receive parameter error\r\n"); - return -1; - } - - // Initialize connection information - tagCONNECT_INFO_T *con_info_p = mSnicWifi_p->getConnectInfo( mSocketID ); - if( con_info_p->recvbuf_p == NULL ) - { - printf("TCPSocketConnection::receive Conncection info error\r\n"); - return -1; - } - - // Check connection - if( con_info_p->is_connected == false ) - { - printf(" Socket id \"%d\" is not connected\r\n", mSocketID); - return -1; - } - - if( con_info_p->is_received == false ) - { -// printf(" Socket id \"%d\" is not received\r\n", mSocketID); - return 0; - } - - // Get packet data from buffer for receive. - for (i = 0; i < length; i ++) - { - if (con_info_p->recvbuf_p->dequeue(&data_p[i]) == false) - { - break; - } - } - - if( con_info_p->recvbuf_p->isEmpty() ) - { - con_info_p->is_received = false; - } - - return i; -}
--- a/Socket/TCPSocketConnection.h Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: TCPSocketConnection.h - * - * Purpose: This module has define of TCP connection. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ - -#ifndef TCPSOCKET_H -#define TCPSOCKET_H - -#include "Socket.h" -#include "Endpoint.h" - -namespace murata_wifi -{ - -/** -TCP socket connection -*/ -class TCPSocketConnection : public Socket, public Endpoint { - -public: - /** TCP socket connection - */ - TCPSocketConnection(); - - /** Connects this TCP socket to the server - @param host The ip address to connect to.(hexadecimal)("192.168.0.1"->0xC0A80001) - @param port The host's port to connect to. - @return 0 on success, -1 on failure. - @note This function is blocked until a returns. - When you use it by UI thread, be careful. - */ - int connect( unsigned int ip_addr, unsigned short port ); - - /** Check if the socket is connected - @return true if connected, false otherwise. - */ - bool is_connected(void); - - /** Send data to the remote host. - @param data The buffer to send to the host. - @param length The length of the buffer to send. - @return the number of written bytes on success (>=0) or -1 on failure - */ - int send(unsigned char *data_p, int length); - - /** Receive data from the remote host. - @param data The buffer in which to store the data received from the host. - @param length The maximum length of the buffer. - @return the number of received bytes on success (>=0) or -1 on failure - */ - int receive(unsigned char *data_p, int length); - -private: - -}; -} -#endif
--- a/Socket/TCPSocketServer.cpp Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: TCPSocketServer.cpp - * - * Purpose: This module has implementation of TCP server. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#include "TCPSocketServer.h" - -#include <cstring> - -using namespace murata_wifi; - -TCPSocketServer::TCPSocketServer() -{ -} - -int TCPSocketServer::bind(int port) -{ - return 0; -} - -int TCPSocketServer::listen(int max) -{ - return 0; -} - -int TCPSocketServer::accept(TCPSocketConnection& connection) -{ - return 0; -}
--- a/Socket/TCPSocketServer.h Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: TCPSocketServer.h - * - * Purpose: This module has define of TCP server. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ -#ifndef TCPSOCKETSERVER_H -#define TCPSOCKETSERVER_H - -#include "Socket.h" -#include "TCPSocketConnection.h" - -namespace murata_wifi -{ - -/** TCP Server. - */ -class TCPSocketServer : public Socket { - public: - /** Instantiate a TCP Server. - */ - TCPSocketServer(); - - /** Bind a socket to a specific port. - \param port The port to listen for incoming connections on. - \return 0 on success, -1 on failure. - */ - int bind(int port); - - /** Start listening for incoming connections. - \param backlog number of pending connections that can be queued up at any - one time [Default: 1]. - \return 0 on success, -1 on failure. - */ - int listen(int backlog=1); - - /** Accept a new connection. - \param connection A TCPSocketConnection instance that will handle the incoming connection. - \return 0 on success, -1 on failure. - */ - int accept(TCPSocketConnection& connection); -}; -} - -#endif
--- a/Socket/UDPSocket.cpp Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: UDPSocket.cpp - * - * Purpose: This module has implementation of UDP socket. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ - -#include "Socket/UDPSocket.h" - -#include <cstring> - -using namespace murata_wifi; - -UDPSocket::UDPSocket() { -} - -int UDPSocket::init(void) -{ - return 0; -} - -// Server initialization -int UDPSocket::bind(int port) -{ - return 0; -} - -// -1 if unsuccessful, else number of bytes written -int UDPSocket::sendTo(Endpoint &remote, char *packet, int length) -{ - return 0; -} - -// -1 if unsuccessful, else number of bytes received -int UDPSocket::receiveFrom(Endpoint &remote, char *buffer, int length) -{ - return 0; -}
--- a/Socket/UDPSocket.h Thu Mar 27 06:04:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** - * - * Filename: UDPSocket.h - * - * Purpose: This module has define of UDP socket. - * - * $Author: kishino $ - * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ - -#ifndef UDPSOCKET_H -#define UDPSOCKET_H - -#include "Socket.h" -#include "Endpoint.h" - -namespace murata_wifi -{ - -/** -UDP Socket -*/ -class UDPSocket : public Socket { - -public: - /** Instantiate an UDP Socket. - */ - UDPSocket(); - - /** Init the UDP Client Socket without binding it to any specific port - \return 0 on success, -1 on failure. - */ - int init(void); - - /** Bind a UDP Server Socket to a specific port - \param port The port to listen for incoming connections on - \return 0 on success, -1 on failure. - */ - int bind(int port); - - /** Send a packet to a remote endpoint - \param remote The remote endpoint - \param packet The packet to be sent - \param length The length of the packet to be sent - \return the number of written bytes on success (>=0) or -1 on failure - */ - int sendTo(Endpoint &remote, char *packet, int length); - - /** Receive a packet from a remote endpoint - \param remote The remote endpoint - \param buffer The buffer for storing the incoming packet data. If a packet - is too long to fit in the supplied buffer, excess bytes are discarded - \param length The length of the buffer - \return the number of received bytes on success (>=0) or -1 on failure - */ - int receiveFrom(Endpoint &remote, char *buffer, int length); -}; -} - -#endif