SNIC UART Interface library for Murata Type-YD module

Dependents:   WebSocketServerTest

Fork of SNICInterface_mod by Toyomasa Watarai

Committer:
MACRUM
Date:
Sun Mar 22 14:13:10 2015 +0000
Revision:
50:d390d41d1405
Parent:
43:d80bbb12ffe6
Added default constructor and create() method

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 39:a1233ca02edf 1 /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License
kishino 41:1c1b5ad4d491 2 * muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART.
kishino 20:dd736d328de6 3 *
kishino 39:a1233ca02edf 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
kishino 39:a1233ca02edf 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
kishino 39:a1233ca02edf 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
kishino 39:a1233ca02edf 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
kishino 39:a1233ca02edf 8 * furnished to do so, subject to the following conditions:
kishino 20:dd736d328de6 9 *
kishino 39:a1233ca02edf 10 * The above copyright notice and this permission notice shall be included in all copies or
kishino 39:a1233ca02edf 11 * substantial portions of the Software.
kishino 20:dd736d328de6 12 *
kishino 39:a1233ca02edf 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
kishino 39:a1233ca02edf 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
kishino 39:a1233ca02edf 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kishino 39:a1233ca02edf 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kishino 39:a1233ca02edf 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kishino 39:a1233ca02edf 18 */
kishino 20:dd736d328de6 19 #include "mbed.h"
kishino 20:dd736d328de6 20 #include "SNIC_Core.h"
kishino 20:dd736d328de6 21 #include "SNIC_UartMsgUtil.h"
kishino 20:dd736d328de6 22 #include <string>
kishino 20:dd736d328de6 23
kishino 29:6a0ba999597d 24 /** Wait signal ID of UART recv */
kishino 35:e4e7f86fd975 25 #define UART_DISPATCH_SIGNAL 0x00000002
kishino 20:dd736d328de6 26
kishino 35:e4e7f86fd975 27 #define UART_RECVBUF_SIZE 2048
kishino 29:6a0ba999597d 28 #define UART_THREAD_STACK_SIZE 512
kishino 39:a1233ca02edf 29 #define UART_FIXED_HEADER_SIZE 3
kishino 39:a1233ca02edf 30 #define UART_FIXED_SIZE_IN_FRAME 6
kishino 39:a1233ca02edf 31 #define UART_RECV_QUEUE_TIMEOUT 500
kishino 29:6a0ba999597d 32
kishino 20:dd736d328de6 33 typedef struct
kishino 20:dd736d328de6 34 {
kishino 35:e4e7f86fd975 35 tagMEMPOOL_BLOCK_T *mem_p;
kishino 20:dd736d328de6 36 unsigned int size;
kishino 20:dd736d328de6 37 }tagUART_RECVBUF_T;
kishino 20:dd736d328de6 38
kishino 29:6a0ba999597d 39 /*
kishino 29:6a0ba999597d 40 Define the global buffer using the area for Ethernet.
kishino 29:6a0ba999597d 41 */
kishino 29:6a0ba999597d 42 unsigned char gUART_TEMP_BUF[UART_RECVBUF_SIZE] __attribute__((section("AHBSRAM1")));
kishino 29:6a0ba999597d 43 unsigned char gUART_COMMAND_BUF[UART_REQUEST_PAYLOAD_MAX] __attribute__((section("AHBSRAM1")));
kishino 29:6a0ba999597d 44 /** MemoryPool for payload of UART response */
kishino 43:d80bbb12ffe6 45 //MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload __attribute__((section("AHBSRAM1")));
kishino 43:d80bbb12ffe6 46 MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload __attribute__((section("AHBSRAM0")));
kishino 29:6a0ba999597d 47 /** MemoryPool for UART receive */
kishino 43:d80bbb12ffe6 48 MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_UART_RECV_NUM> mMemPoolUartRecv __attribute__((section("AHBSRAM0")));
kishino 35:e4e7f86fd975 49 Queue<tagMEMPOOL_BLOCK_T, MEMPOOL_UART_RECV_NUM> mUartRecvQueue;
kishino 29:6a0ba999597d 50
kishino 29:6a0ba999597d 51 tagMEMPOOL_BLOCK_T *gUART_RCVBUF_p;
kishino 43:d80bbb12ffe6 52 int gUART_RECV_COUNT = 0;
kishino 43:d80bbb12ffe6 53
kishino 20:dd736d328de6 54 C_SNIC_Core *C_SNIC_Core::mInstance_p = NULL;
kishino 20:dd736d328de6 55
kishino 20:dd736d328de6 56 C_SNIC_Core *C_SNIC_Core::getInstance()
kishino 20:dd736d328de6 57 {
kishino 20:dd736d328de6 58 if( mInstance_p == NULL )
kishino 20:dd736d328de6 59 {
kishino 20:dd736d328de6 60 mInstance_p = new C_SNIC_Core();
kishino 20:dd736d328de6 61 }
kishino 20:dd736d328de6 62 return mInstance_p;
kishino 20:dd736d328de6 63 }
kishino 20:dd736d328de6 64
kishino 20:dd736d328de6 65 C_SNIC_Core::C_SNIC_Core()
kishino 20:dd736d328de6 66 {
kishino 20:dd736d328de6 67 int i;
kishino 20:dd736d328de6 68
kishino 20:dd736d328de6 69 mUartCommand_p = new C_SNIC_UartCommandManager();
kishino 20:dd736d328de6 70 for( i = 0; i < MAX_SOCKET_ID+1; i++ )
kishino 20:dd736d328de6 71 {
kishino 20:dd736d328de6 72 mConnectInfo[i].recvbuf_p = NULL;
kishino 20:dd736d328de6 73 mConnectInfo[i].is_connected = false;
kishino 43:d80bbb12ffe6 74 mConnectInfo[i].is_receive_complete = true;
kishino 33:33f1bc919486 75
kishino 33:33f1bc919486 76 mUdpRecvInfo[i].recvbuf_p = NULL;
kishino 33:33f1bc919486 77 mUdpRecvInfo[i].is_received = false;
kishino 20:dd736d328de6 78 }
kishino 20:dd736d328de6 79
kishino 29:6a0ba999597d 80 mUartRecvThread_p = NULL;
kishino 29:6a0ba999597d 81 mUartRecvDispatchThread_p = NULL;
kishino 20:dd736d328de6 82 }
kishino 20:dd736d328de6 83
kishino 26:f2e1030964e4 84 C_SNIC_Core::~C_SNIC_Core()
kishino 26:f2e1030964e4 85 {
kishino 26:f2e1030964e4 86 }
kishino 26:f2e1030964e4 87
kishino 29:6a0ba999597d 88 int C_SNIC_Core::resetModule( PinName reset )
kishino 29:6a0ba999597d 89 {
kishino 29:6a0ba999597d 90 DigitalOut reset_pin( reset );
kishino 29:6a0ba999597d 91
kishino 29:6a0ba999597d 92 reset_pin = 0;
kishino 43:d80bbb12ffe6 93 wait(0.3);
kishino 29:6a0ba999597d 94 reset_pin = 1;
kishino 43:d80bbb12ffe6 95 wait(0.3);
kishino 29:6a0ba999597d 96
kishino 29:6a0ba999597d 97 return 0;
kishino 29:6a0ba999597d 98 }
kishino 29:6a0ba999597d 99
kishino 20:dd736d328de6 100 int C_SNIC_Core::initUart(PinName tx, PinName rx, int baud)
kishino 20:dd736d328de6 101 {
kishino 38:f13e4e563d65 102 mUartRequestSeq = 0;
kishino 20:dd736d328de6 103
kishino 20:dd736d328de6 104 mUart_p = new RawSerial( tx, rx );
kishino 20:dd736d328de6 105 mUart_p->baud( baud );
kishino 20:dd736d328de6 106 mUart_p->format(8, SerialBase::None, 1);
kishino 29:6a0ba999597d 107
kishino 20:dd736d328de6 108 // Initialize uart
kishino 38:f13e4e563d65 109 gUART_RCVBUF_p = NULL;
kishino 20:dd736d328de6 110
kishino 35:e4e7f86fd975 111 mUart_p->attach( C_SNIC_Core::uartRecvCallback );
kishino 29:6a0ba999597d 112 // Create UART recv dispatch thread
kishino 29:6a0ba999597d 113 mUartRecvDispatchThread_p = new Thread( C_SNIC_Core::uartRecvDispatchThread, NULL, osPriorityNormal, UART_THREAD_STACK_SIZE);
kishino 29:6a0ba999597d 114 if( mUartRecvDispatchThread_p == NULL )
kishino 20:dd736d328de6 115 {
kishino 40:b6b10c22a121 116 DEBUG_PRINT("[C_SNIC_Core::initUart] thread create failed\r\n");
kishino 20:dd736d328de6 117 return -1;
kishino 20:dd736d328de6 118 }
kishino 20:dd736d328de6 119
kishino 20:dd736d328de6 120 return 0;
kishino 20:dd736d328de6 121 }
kishino 38:f13e4e563d65 122 unsigned int C_SNIC_Core::preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid
kishino 20:dd736d328de6 123 , unsigned char *req_buf_p, unsigned int req_buf_len
kishino 20:dd736d328de6 124 , unsigned char *response_buf_p, unsigned char *command_p )
kishino 20:dd736d328de6 125 {
kishino 38:f13e4e563d65 126 unsigned int command_len = 0;
kishino 20:dd736d328de6 127
kishino 20:dd736d328de6 128 // Make all command request
kishino 36:f33fcf5975ab 129 command_len = C_SNIC_UartMsgUtil::makeRequest( cmd_id, req_buf_p, req_buf_len, command_p );
kishino 20:dd736d328de6 130
kishino 20:dd736d328de6 131 // Set data for response
kishino 20:dd736d328de6 132 mUartCommand_p->setCommandID( cmd_id );
kishino 20:dd736d328de6 133 mUartCommand_p->setCommandSID( cmd_sid | 0x80 );
kishino 20:dd736d328de6 134 mUartCommand_p->setResponseBuf( response_buf_p );
kishino 20:dd736d328de6 135
kishino 20:dd736d328de6 136 return command_len;
kishino 20:dd736d328de6 137 }
kishino 20:dd736d328de6 138
kishino 20:dd736d328de6 139 int C_SNIC_Core::sendUart( unsigned int len, unsigned char *data )
kishino 20:dd736d328de6 140 {
kishino 20:dd736d328de6 141 int ret = 0;
kishino 20:dd736d328de6 142 mUartMutex.lock();
kishino 20:dd736d328de6 143 for( int i = 0; i < len; i++ )
kishino 20:dd736d328de6 144 {
kishino 20:dd736d328de6 145 // Write to UART
kishino 20:dd736d328de6 146 ret = mUart_p->putc( data[i] );
kishino 20:dd736d328de6 147 if( ret == -1 )
kishino 20:dd736d328de6 148 {
kishino 20:dd736d328de6 149 break;
kishino 20:dd736d328de6 150 }
kishino 20:dd736d328de6 151 }
kishino 20:dd736d328de6 152 mUartMutex.unlock();
kishino 36:f33fcf5975ab 153
kishino 20:dd736d328de6 154 return ret;
kishino 20:dd736d328de6 155 }
kishino 20:dd736d328de6 156
kishino 29:6a0ba999597d 157 tagMEMPOOL_BLOCK_T *C_SNIC_Core::allocCmdBuf()
kishino 20:dd736d328de6 158 {
kishino 20:dd736d328de6 159 // Get buffer from MemoryPool
kishino 20:dd736d328de6 160 return mMemPoolPayload.alloc();
kishino 20:dd736d328de6 161 }
kishino 20:dd736d328de6 162
kishino 20:dd736d328de6 163 void C_SNIC_Core::freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p )
kishino 20:dd736d328de6 164 {
kishino 20:dd736d328de6 165 mMemPoolPayload.free( buf_p );
kishino 20:dd736d328de6 166 }
kishino 20:dd736d328de6 167
kishino 29:6a0ba999597d 168 tagMEMPOOL_BLOCK_T *C_SNIC_Core::allocUartRcvBuf()
kishino 29:6a0ba999597d 169 {
kishino 29:6a0ba999597d 170 // Get buffer from MemoryPool
kishino 29:6a0ba999597d 171 return mMemPoolUartRecv.alloc();
kishino 29:6a0ba999597d 172 }
kishino 29:6a0ba999597d 173
kishino 29:6a0ba999597d 174 void C_SNIC_Core::freeUartRecvBuf( tagMEMPOOL_BLOCK_T *buf_p )
kishino 29:6a0ba999597d 175 {
kishino 29:6a0ba999597d 176 mMemPoolUartRecv.free( buf_p );
kishino 29:6a0ba999597d 177 }
kishino 29:6a0ba999597d 178
kishino 22:a9ec0cad4f84 179 C_SNIC_Core::tagCONNECT_INFO_T *C_SNIC_Core::getConnectInfo( int socket_id )
kishino 20:dd736d328de6 180 {
kishino 20:dd736d328de6 181 if( (socket_id < 0) || (socket_id > MAX_SOCKET_ID) )
kishino 20:dd736d328de6 182 {
kishino 20:dd736d328de6 183 return NULL;
kishino 20:dd736d328de6 184 }
kishino 20:dd736d328de6 185 return &mConnectInfo[socket_id];
kishino 20:dd736d328de6 186 }
kishino 20:dd736d328de6 187
kishino 33:33f1bc919486 188 C_SNIC_Core::tagUDP_RECVINFO_T *C_SNIC_Core::getUdpRecvInfo( int socket_id )
kishino 33:33f1bc919486 189 {
kishino 33:33f1bc919486 190 if( (socket_id < 0) || (socket_id > MAX_SOCKET_ID) )
kishino 33:33f1bc919486 191 {
kishino 33:33f1bc919486 192 return NULL;
kishino 33:33f1bc919486 193 }
kishino 33:33f1bc919486 194 return &mUdpRecvInfo[socket_id];
kishino 33:33f1bc919486 195 }
kishino 33:33f1bc919486 196
kishino 20:dd736d328de6 197 C_SNIC_UartCommandManager *C_SNIC_Core::getUartCommand()
kishino 20:dd736d328de6 198 {
kishino 20:dd736d328de6 199 return mUartCommand_p;
kishino 20:dd736d328de6 200 }
kishino 20:dd736d328de6 201
kishino 29:6a0ba999597d 202 unsigned char *C_SNIC_Core::getCommandBuf()
kishino 29:6a0ba999597d 203 {
kishino 29:6a0ba999597d 204 return gUART_COMMAND_BUF;
kishino 29:6a0ba999597d 205 }
kishino 20:dd736d328de6 206
kishino 43:d80bbb12ffe6 207 void C_SNIC_Core::lockAPI( void )
kishino 43:d80bbb12ffe6 208 {
kishino 43:d80bbb12ffe6 209 mAPIMutex.lock();
kishino 43:d80bbb12ffe6 210 }
kishino 43:d80bbb12ffe6 211
kishino 43:d80bbb12ffe6 212 void C_SNIC_Core::unlockAPI( void )
kishino 43:d80bbb12ffe6 213 {
kishino 43:d80bbb12ffe6 214 mAPIMutex.unlock();
kishino 43:d80bbb12ffe6 215 }
kishino 43:d80bbb12ffe6 216
kishino 29:6a0ba999597d 217 void C_SNIC_Core::uartRecvCallback( void )
kishino 29:6a0ba999597d 218 {
kishino 20:dd736d328de6 219 C_SNIC_Core *instance_p = C_SNIC_Core::getInstance();
kishino 29:6a0ba999597d 220 if( instance_p != NULL )
kishino 20:dd736d328de6 221 {
kishino 29:6a0ba999597d 222 int recvdata = 0;
kishino 20:dd736d328de6 223
kishino 39:a1233ca02edf 224 // Check received data from UART.
kishino 39:a1233ca02edf 225 while( instance_p->mUart_p->readable() )
kishino 20:dd736d328de6 226 {
kishino 20:dd736d328de6 227 // Receive data from UART.
kishino 20:dd736d328de6 228 recvdata = instance_p->mUart_p->getc();
kishino 20:dd736d328de6 229
kishino 29:6a0ba999597d 230 // Check UART receiving buffer
kishino 29:6a0ba999597d 231 if( gUART_RCVBUF_p != NULL )
kishino 20:dd736d328de6 232 {
kishino 29:6a0ba999597d 233 gUART_RCVBUF_p->buf[ gUART_RCVBUF_p->size ] = (unsigned char)recvdata;
kishino 29:6a0ba999597d 234 gUART_RCVBUF_p->size++;
kishino 29:6a0ba999597d 235
kishino 39:a1233ca02edf 236 if( gUART_RCVBUF_p->size == UART_FIXED_HEADER_SIZE )
kishino 20:dd736d328de6 237 {
kishino 36:f33fcf5975ab 238 // get demand size
kishino 36:f33fcf5975ab 239 unsigned short payload_len = ( ( (gUART_RCVBUF_p->buf[1] & ~0x80) & 0xff) | ( ( (gUART_RCVBUF_p->buf[2] & ~0xC0) << 7) & 0xff80) );
kishino 39:a1233ca02edf 240 gUART_RCVBUF_p->demand_size = payload_len + UART_FIXED_SIZE_IN_FRAME;
kishino 39:a1233ca02edf 241 if( gUART_RCVBUF_p->demand_size > MEMPOOL_BLOCK_SIZE )
kishino 39:a1233ca02edf 242 {
kishino 39:a1233ca02edf 243 gUART_RCVBUF_p->demand_size = MEMPOOL_BLOCK_SIZE;
kishino 39:a1233ca02edf 244 }
kishino 36:f33fcf5975ab 245 }
kishino 36:f33fcf5975ab 246
kishino 36:f33fcf5975ab 247 if( gUART_RCVBUF_p->demand_size > 0 )
kishino 36:f33fcf5975ab 248 {
kishino 36:f33fcf5975ab 249 // Check size of received data.
kishino 36:f33fcf5975ab 250 if( gUART_RCVBUF_p->size >= gUART_RCVBUF_p->demand_size )
kishino 36:f33fcf5975ab 251 {
kishino 36:f33fcf5975ab 252 // Add queue
kishino 36:f33fcf5975ab 253 mUartRecvQueue.put( gUART_RCVBUF_p );
kishino 36:f33fcf5975ab 254
kishino 36:f33fcf5975ab 255 gUART_RCVBUF_p = NULL;
kishino 20:dd736d328de6 256
kishino 43:d80bbb12ffe6 257 if( gUART_RECV_COUNT >= MEMPOOL_UART_RECV_NUM )
kishino 43:d80bbb12ffe6 258 {
kishino 43:d80bbb12ffe6 259 instance_p->mUart_p->attach( NULL );
kishino 43:d80bbb12ffe6 260 }
kishino 36:f33fcf5975ab 261 // set signal for dispatch thread
kishino 36:f33fcf5975ab 262 instance_p->mUartRecvDispatchThread_p->signal_set( UART_DISPATCH_SIGNAL );
kishino 43:d80bbb12ffe6 263 break;
kishino 36:f33fcf5975ab 264 }
kishino 20:dd736d328de6 265 }
kishino 20:dd736d328de6 266 }
kishino 20:dd736d328de6 267 else
kishino 20:dd736d328de6 268 {
kishino 20:dd736d328de6 269 // Check received data is SOM.
kishino 20:dd736d328de6 270 if( recvdata == UART_CMD_SOM )
kishino 20:dd736d328de6 271 {
kishino 29:6a0ba999597d 272 gUART_RCVBUF_p = instance_p->allocUartRcvBuf();
kishino 43:d80bbb12ffe6 273 gUART_RECV_COUNT++;
kishino 29:6a0ba999597d 274 gUART_RCVBUF_p->size = 0;
kishino 36:f33fcf5975ab 275 gUART_RCVBUF_p->demand_size = 0;
kishino 43:d80bbb12ffe6 276
kishino 29:6a0ba999597d 277 // get buffer for Uart receive
kishino 29:6a0ba999597d 278 gUART_RCVBUF_p->buf[ 0 ] = (unsigned char)recvdata;
kishino 29:6a0ba999597d 279
kishino 29:6a0ba999597d 280 gUART_RCVBUF_p->size++;
kishino 20:dd736d328de6 281 }
kishino 20:dd736d328de6 282 }
kishino 20:dd736d328de6 283 }
kishino 20:dd736d328de6 284 }
kishino 20:dd736d328de6 285 }
kishino 20:dd736d328de6 286
kishino 29:6a0ba999597d 287 void C_SNIC_Core::uartRecvDispatchThread (void const *args_p)
kishino 29:6a0ba999597d 288 {
kishino 29:6a0ba999597d 289 C_SNIC_Core *instance_p = C_SNIC_Core::getInstance();
kishino 29:6a0ba999597d 290 C_SNIC_UartCommandManager *uartCmdMgr_p = instance_p->getUartCommand();
kishino 29:6a0ba999597d 291
kishino 29:6a0ba999597d 292 tagMEMPOOL_BLOCK_T *uartRecvBuf_p;
kishino 29:6a0ba999597d 293 osEvent evt;
kishino 29:6a0ba999597d 294
kishino 29:6a0ba999597d 295 for(;;)
kishino 29:6a0ba999597d 296 {
kishino 29:6a0ba999597d 297 // wait
kishino 29:6a0ba999597d 298 Thread::signal_wait( UART_DISPATCH_SIGNAL );
kishino 29:6a0ba999597d 299
kishino 29:6a0ba999597d 300 // Get scanresults from queue
kishino 39:a1233ca02edf 301 evt = mUartRecvQueue.get(UART_RECV_QUEUE_TIMEOUT);
kishino 29:6a0ba999597d 302 if (evt.status == osEventMessage)
kishino 29:6a0ba999597d 303 {
kishino 29:6a0ba999597d 304 do
kishino 29:6a0ba999597d 305 {
kishino 29:6a0ba999597d 306 uartRecvBuf_p = (tagMEMPOOL_BLOCK_T *)evt.value.p;
kishino 29:6a0ba999597d 307
kishino 38:f13e4e563d65 308 #if 0 /* for Debug */
kishino 29:6a0ba999597d 309 {
kishino 29:6a0ba999597d 310 int i;
kishino 29:6a0ba999597d 311 for(i=0;i<uartRecvBuf_p->size;i++)
kishino 29:6a0ba999597d 312 {
kishino 40:b6b10c22a121 313 DEBUG_PRINT("%02x", uartRecvBuf_p->buf[i]);
kishino 29:6a0ba999597d 314 }
kishino 40:b6b10c22a121 315 DEBUG_PRINT("\r\n");
kishino 29:6a0ba999597d 316 }
kishino 32:ae95309643aa 317 #endif
kishino 29:6a0ba999597d 318 unsigned char command_id;
kishino 29:6a0ba999597d 319 // Get payload from received data from UART.
kishino 29:6a0ba999597d 320 int payload_len = C_SNIC_UartMsgUtil::getResponsePayload( uartRecvBuf_p->size, uartRecvBuf_p->buf
kishino 29:6a0ba999597d 321 , &command_id, gUART_TEMP_BUF );
kishino 33:33f1bc919486 322 // Check receive a TCP packet
kishino 29:6a0ba999597d 323 if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_CONNECTION_RECV_IND) )
kishino 29:6a0ba999597d 324 {
kishino 29:6a0ba999597d 325 // Packet buffering
kishino 29:6a0ba999597d 326 uartCmdMgr_p->bufferredPacket( gUART_TEMP_BUF, payload_len );
kishino 29:6a0ba999597d 327 }
kishino 32:ae95309643aa 328 // Check connected from TCP client
kishino 32:ae95309643aa 329 else if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_TCP_CLIENT_SOCKET_IND) )
kishino 32:ae95309643aa 330 {
kishino 32:ae95309643aa 331 // Connected from TCP client
kishino 32:ae95309643aa 332 uartCmdMgr_p->connectedTCPClient( gUART_TEMP_BUF, payload_len );
kishino 32:ae95309643aa 333 }
kishino 33:33f1bc919486 334 // Check receive UDP packet
kishino 33:33f1bc919486 335 else if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_UDP_RECV_IND) )
kishino 33:33f1bc919486 336 {
kishino 33:33f1bc919486 337 // UDP packet buffering
kishino 33:33f1bc919486 338 uartCmdMgr_p->bufferredUDPPacket( gUART_TEMP_BUF, payload_len );
kishino 33:33f1bc919486 339 }
kishino 29:6a0ba999597d 340 // Check scan results indication
kishino 29:6a0ba999597d 341 else if( (command_id == UART_CMD_ID_WIFI) && (gUART_TEMP_BUF[0] == UART_CMD_SID_WIFI_SCAN_RESULT_IND) )
kishino 29:6a0ba999597d 342 {
kishino 29:6a0ba999597d 343 // Scan result indicate
kishino 29:6a0ba999597d 344 uartCmdMgr_p->scanResultIndicate( gUART_TEMP_BUF, payload_len );
kishino 29:6a0ba999597d 345 }
kishino 29:6a0ba999597d 346 // Checks in the command which is waiting.
kishino 29:6a0ba999597d 347 else if( uartCmdMgr_p->isWaitingCommand(command_id, gUART_TEMP_BUF) )
kishino 29:6a0ba999597d 348 {
kishino 29:6a0ba999597d 349 // Get buffer for payload data
kishino 29:6a0ba999597d 350 unsigned char *payload_buf_p = uartCmdMgr_p->getResponseBuf();
kishino 29:6a0ba999597d 351 if( payload_buf_p != NULL )
kishino 29:6a0ba999597d 352 {
kishino 29:6a0ba999597d 353 memcpy( payload_buf_p, gUART_TEMP_BUF, payload_len );
kishino 29:6a0ba999597d 354 uartCmdMgr_p->setResponseBuf( NULL );
kishino 29:6a0ba999597d 355 }
kishino 29:6a0ba999597d 356 // Set status
kishino 29:6a0ba999597d 357 uartCmdMgr_p->setCommandStatus( gUART_TEMP_BUF[2] );
kishino 29:6a0ba999597d 358 // Set signal for command response wait.
kishino 29:6a0ba999597d 359 uartCmdMgr_p->signal();
kishino 29:6a0ba999597d 360 }
kishino 39:a1233ca02edf 361 else
kishino 39:a1233ca02edf 362 {
kishino 43:d80bbb12ffe6 363 //DEBUG_PRINT(" The received data is not expected.\r\n");
kishino 39:a1233ca02edf 364 }
kishino 39:a1233ca02edf 365
kishino 29:6a0ba999597d 366 //
kishino 29:6a0ba999597d 367 instance_p->freeUartRecvBuf( uartRecvBuf_p );
kishino 43:d80bbb12ffe6 368 gUART_RECV_COUNT--;
kishino 43:d80bbb12ffe6 369 if( gUART_RECV_COUNT == (MEMPOOL_UART_RECV_NUM-1) )
kishino 43:d80bbb12ffe6 370 {
kishino 43:d80bbb12ffe6 371 instance_p->mUart_p->attach( C_SNIC_Core::uartRecvCallback ); //debug
kishino 43:d80bbb12ffe6 372 }
kishino 29:6a0ba999597d 373
kishino 29:6a0ba999597d 374 evt = mUartRecvQueue.get(500);
kishino 29:6a0ba999597d 375 } while( evt.status == osEventMessage );
kishino 29:6a0ba999597d 376 }
kishino 29:6a0ba999597d 377 }
kishino 29:6a0ba999597d 378 }