customized SNICInterface
Fork of NySNICInterface by
SNIC/SNIC_Core.cpp@37:f3a2053627c2, 2014-06-24 (annotated)
- Committer:
- kishino
- Date:
- Tue Jun 24 06:24:23 2014 +0000
- Revision:
- 37:f3a2053627c2
- Parent:
- 36:f33fcf5975ab
- Child:
- 38:f13e4e563d65
Fixed bugs that was found in the API test.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kishino | 20:dd736d328de6 | 1 | /******************* Murata Manufacturing Co.,Ltd. 2014 ***************** |
kishino | 20:dd736d328de6 | 2 | * |
kishino | 20:dd736d328de6 | 3 | * Filename: SNIC_Core.cpp |
kishino | 20:dd736d328de6 | 4 | * |
kishino | 20:dd736d328de6 | 5 | * Purpose: This module has implementation of internal common function for API. |
kishino | 20:dd736d328de6 | 6 | * |
kishino | 20:dd736d328de6 | 7 | * $Author: kishino $ |
kishino | 20:dd736d328de6 | 8 | * |
kishino | 20:dd736d328de6 | 9 | * $Date: 2014/03/26 $ |
kishino | 20:dd736d328de6 | 10 | * |
kishino | 20:dd736d328de6 | 11 | * $Revision: 0.0.0.1 $ |
kishino | 20:dd736d328de6 | 12 | * ***********************************************************************/ |
kishino | 20:dd736d328de6 | 13 | #include "mbed.h" |
kishino | 20:dd736d328de6 | 14 | #include "SNIC_Core.h" |
kishino | 20:dd736d328de6 | 15 | #include "SNIC_UartMsgUtil.h" |
kishino | 20:dd736d328de6 | 16 | #include <string> |
kishino | 20:dd736d328de6 | 17 | |
kishino | 29:6a0ba999597d | 18 | /** Wait signal ID of UART recv */ |
kishino | 35:e4e7f86fd975 | 19 | #define UART_DISPATCH_SIGNAL 0x00000002 |
kishino | 20:dd736d328de6 | 20 | |
kishino | 35:e4e7f86fd975 | 21 | #define UART_RECVBUF_SIZE 2048 |
kishino | 29:6a0ba999597d | 22 | #define UART_THREAD_STACK_SIZE 512 |
kishino | 29:6a0ba999597d | 23 | |
kishino | 20:dd736d328de6 | 24 | typedef struct |
kishino | 20:dd736d328de6 | 25 | { |
kishino | 35:e4e7f86fd975 | 26 | tagMEMPOOL_BLOCK_T *mem_p; |
kishino | 20:dd736d328de6 | 27 | unsigned int size; |
kishino | 20:dd736d328de6 | 28 | }tagUART_RECVBUF_T; |
kishino | 20:dd736d328de6 | 29 | |
kishino | 29:6a0ba999597d | 30 | /* |
kishino | 29:6a0ba999597d | 31 | Define the global buffer using the area for Ethernet. |
kishino | 29:6a0ba999597d | 32 | */ |
kishino | 29:6a0ba999597d | 33 | unsigned char gUART_TEMP_BUF[UART_RECVBUF_SIZE] __attribute__((section("AHBSRAM1"))); |
kishino | 29:6a0ba999597d | 34 | unsigned char gUART_COMMAND_BUF[UART_REQUEST_PAYLOAD_MAX] __attribute__((section("AHBSRAM1"))); |
kishino | 29:6a0ba999597d | 35 | /** MemoryPool for payload of UART response */ |
kishino | 29:6a0ba999597d | 36 | MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> mMemPoolPayload __attribute__((section("AHBSRAM1"))); |
kishino | 29:6a0ba999597d | 37 | /** MemoryPool for UART receive */ |
kishino | 29:6a0ba999597d | 38 | MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_UART_RECV_NUM> mMemPoolUartRecv __attribute__((section("AHBSRAM1"))); |
kishino | 35:e4e7f86fd975 | 39 | Queue<tagMEMPOOL_BLOCK_T, MEMPOOL_UART_RECV_NUM> mUartRecvQueue; |
kishino | 29:6a0ba999597d | 40 | |
kishino | 29:6a0ba999597d | 41 | tagMEMPOOL_BLOCK_T *gUART_RCVBUF_p; |
kishino | 20:dd736d328de6 | 42 | C_SNIC_Core *C_SNIC_Core::mInstance_p = NULL; |
kishino | 20:dd736d328de6 | 43 | |
kishino | 20:dd736d328de6 | 44 | C_SNIC_Core *C_SNIC_Core::getInstance() |
kishino | 20:dd736d328de6 | 45 | { |
kishino | 20:dd736d328de6 | 46 | if( mInstance_p == NULL ) |
kishino | 20:dd736d328de6 | 47 | { |
kishino | 20:dd736d328de6 | 48 | mInstance_p = new C_SNIC_Core(); |
kishino | 20:dd736d328de6 | 49 | } |
kishino | 20:dd736d328de6 | 50 | return mInstance_p; |
kishino | 20:dd736d328de6 | 51 | } |
kishino | 20:dd736d328de6 | 52 | |
kishino | 20:dd736d328de6 | 53 | C_SNIC_Core::C_SNIC_Core() |
kishino | 20:dd736d328de6 | 54 | { |
kishino | 20:dd736d328de6 | 55 | int i; |
kishino | 20:dd736d328de6 | 56 | |
kishino | 20:dd736d328de6 | 57 | mUartCommand_p = new C_SNIC_UartCommandManager(); |
kishino | 20:dd736d328de6 | 58 | for( i = 0; i < MAX_SOCKET_ID+1; i++ ) |
kishino | 20:dd736d328de6 | 59 | { |
kishino | 20:dd736d328de6 | 60 | mConnectInfo[i].recvbuf_p = NULL; |
kishino | 20:dd736d328de6 | 61 | mConnectInfo[i].is_connected = false; |
kishino | 33:33f1bc919486 | 62 | |
kishino | 33:33f1bc919486 | 63 | mUdpRecvInfo[i].recvbuf_p = NULL; |
kishino | 33:33f1bc919486 | 64 | mUdpRecvInfo[i].is_received = false; |
kishino | 20:dd736d328de6 | 65 | } |
kishino | 20:dd736d328de6 | 66 | |
kishino | 29:6a0ba999597d | 67 | mUartRecvThread_p = NULL; |
kishino | 29:6a0ba999597d | 68 | mUartRecvDispatchThread_p = NULL; |
kishino | 20:dd736d328de6 | 69 | } |
kishino | 20:dd736d328de6 | 70 | |
kishino | 26:f2e1030964e4 | 71 | C_SNIC_Core::~C_SNIC_Core() |
kishino | 26:f2e1030964e4 | 72 | { |
kishino | 26:f2e1030964e4 | 73 | } |
kishino | 26:f2e1030964e4 | 74 | |
kishino | 29:6a0ba999597d | 75 | int C_SNIC_Core::resetModule( PinName reset ) |
kishino | 29:6a0ba999597d | 76 | { |
kishino | 29:6a0ba999597d | 77 | DigitalOut reset_pin( reset ); |
kishino | 29:6a0ba999597d | 78 | |
kishino | 29:6a0ba999597d | 79 | reset_pin = 0; |
kishino | 37:f3a2053627c2 | 80 | wait(0.1); |
kishino | 29:6a0ba999597d | 81 | reset_pin = 1; |
kishino | 37:f3a2053627c2 | 82 | wait(0.1); |
kishino | 29:6a0ba999597d | 83 | |
kishino | 29:6a0ba999597d | 84 | return 0; |
kishino | 29:6a0ba999597d | 85 | } |
kishino | 29:6a0ba999597d | 86 | |
kishino | 20:dd736d328de6 | 87 | int C_SNIC_Core::initUart(PinName tx, PinName rx, int baud) |
kishino | 20:dd736d328de6 | 88 | { |
kishino | 20:dd736d328de6 | 89 | mUartRequestSeq = 0; |
kishino | 20:dd736d328de6 | 90 | |
kishino | 20:dd736d328de6 | 91 | mUart_p = new RawSerial( tx, rx ); |
kishino | 20:dd736d328de6 | 92 | mUart_p->baud( baud ); |
kishino | 20:dd736d328de6 | 93 | mUart_p->format(8, SerialBase::None, 1); |
kishino | 29:6a0ba999597d | 94 | |
kishino | 20:dd736d328de6 | 95 | // Initialize uart |
kishino | 29:6a0ba999597d | 96 | gUART_RCVBUF_p = NULL; |
kishino | 20:dd736d328de6 | 97 | |
kishino | 35:e4e7f86fd975 | 98 | mUart_p->attach( C_SNIC_Core::uartRecvCallback ); |
kishino | 29:6a0ba999597d | 99 | // Create UART recv dispatch thread |
kishino | 29:6a0ba999597d | 100 | mUartRecvDispatchThread_p = new Thread( C_SNIC_Core::uartRecvDispatchThread, NULL, osPriorityNormal, UART_THREAD_STACK_SIZE); |
kishino | 29:6a0ba999597d | 101 | if( mUartRecvDispatchThread_p == NULL ) |
kishino | 20:dd736d328de6 | 102 | { |
kishino | 29:6a0ba999597d | 103 | printf("[C_SNIC_Core::initUart] thread create failed\r\n"); |
kishino | 20:dd736d328de6 | 104 | return -1; |
kishino | 20:dd736d328de6 | 105 | } |
kishino | 20:dd736d328de6 | 106 | |
kishino | 20:dd736d328de6 | 107 | return 0; |
kishino | 20:dd736d328de6 | 108 | } |
kishino | 29:6a0ba999597d | 109 | unsigned int C_SNIC_Core::preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid |
kishino | 20:dd736d328de6 | 110 | , unsigned char *req_buf_p, unsigned int req_buf_len |
kishino | 20:dd736d328de6 | 111 | , unsigned char *response_buf_p, unsigned char *command_p ) |
kishino | 20:dd736d328de6 | 112 | { |
kishino | 20:dd736d328de6 | 113 | unsigned int command_len = 0; |
kishino | 20:dd736d328de6 | 114 | |
kishino | 20:dd736d328de6 | 115 | // Make all command request |
kishino | 36:f33fcf5975ab | 116 | command_len = C_SNIC_UartMsgUtil::makeRequest( cmd_id, req_buf_p, req_buf_len, command_p ); |
kishino | 20:dd736d328de6 | 117 | |
kishino | 20:dd736d328de6 | 118 | // Set data for response |
kishino | 20:dd736d328de6 | 119 | mUartCommand_p->setCommandID( cmd_id ); |
kishino | 20:dd736d328de6 | 120 | mUartCommand_p->setCommandSID( cmd_sid | 0x80 ); |
kishino | 20:dd736d328de6 | 121 | mUartCommand_p->setResponseBuf( response_buf_p ); |
kishino | 20:dd736d328de6 | 122 | |
kishino | 20:dd736d328de6 | 123 | return command_len; |
kishino | 20:dd736d328de6 | 124 | } |
kishino | 20:dd736d328de6 | 125 | |
kishino | 20:dd736d328de6 | 126 | int C_SNIC_Core::sendUart( unsigned int len, unsigned char *data ) |
kishino | 20:dd736d328de6 | 127 | { |
kishino | 20:dd736d328de6 | 128 | int ret = 0; |
kishino | 20:dd736d328de6 | 129 | mUartMutex.lock(); |
kishino | 20:dd736d328de6 | 130 | for( int i = 0; i < len; i++ ) |
kishino | 20:dd736d328de6 | 131 | { |
kishino | 20:dd736d328de6 | 132 | // Write to UART |
kishino | 20:dd736d328de6 | 133 | ret = mUart_p->putc( data[i] ); |
kishino | 20:dd736d328de6 | 134 | if( ret == -1 ) |
kishino | 20:dd736d328de6 | 135 | { |
kishino | 20:dd736d328de6 | 136 | break; |
kishino | 20:dd736d328de6 | 137 | } |
kishino | 20:dd736d328de6 | 138 | } |
kishino | 20:dd736d328de6 | 139 | mUartMutex.unlock(); |
kishino | 36:f33fcf5975ab | 140 | |
kishino | 20:dd736d328de6 | 141 | return ret; |
kishino | 20:dd736d328de6 | 142 | } |
kishino | 20:dd736d328de6 | 143 | |
kishino | 29:6a0ba999597d | 144 | tagMEMPOOL_BLOCK_T *C_SNIC_Core::allocCmdBuf() |
kishino | 20:dd736d328de6 | 145 | { |
kishino | 20:dd736d328de6 | 146 | // Get buffer from MemoryPool |
kishino | 20:dd736d328de6 | 147 | return mMemPoolPayload.alloc(); |
kishino | 20:dd736d328de6 | 148 | } |
kishino | 20:dd736d328de6 | 149 | |
kishino | 20:dd736d328de6 | 150 | void C_SNIC_Core::freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p ) |
kishino | 20:dd736d328de6 | 151 | { |
kishino | 20:dd736d328de6 | 152 | mMemPoolPayload.free( buf_p ); |
kishino | 20:dd736d328de6 | 153 | } |
kishino | 20:dd736d328de6 | 154 | |
kishino | 29:6a0ba999597d | 155 | tagMEMPOOL_BLOCK_T *C_SNIC_Core::allocUartRcvBuf() |
kishino | 29:6a0ba999597d | 156 | { |
kishino | 29:6a0ba999597d | 157 | // Get buffer from MemoryPool |
kishino | 29:6a0ba999597d | 158 | return mMemPoolUartRecv.alloc(); |
kishino | 29:6a0ba999597d | 159 | } |
kishino | 29:6a0ba999597d | 160 | |
kishino | 29:6a0ba999597d | 161 | void C_SNIC_Core::freeUartRecvBuf( tagMEMPOOL_BLOCK_T *buf_p ) |
kishino | 29:6a0ba999597d | 162 | { |
kishino | 29:6a0ba999597d | 163 | mMemPoolUartRecv.free( buf_p ); |
kishino | 29:6a0ba999597d | 164 | } |
kishino | 29:6a0ba999597d | 165 | |
kishino | 22:a9ec0cad4f84 | 166 | C_SNIC_Core::tagCONNECT_INFO_T *C_SNIC_Core::getConnectInfo( int socket_id ) |
kishino | 20:dd736d328de6 | 167 | { |
kishino | 20:dd736d328de6 | 168 | if( (socket_id < 0) || (socket_id > MAX_SOCKET_ID) ) |
kishino | 20:dd736d328de6 | 169 | { |
kishino | 20:dd736d328de6 | 170 | return NULL; |
kishino | 20:dd736d328de6 | 171 | } |
kishino | 20:dd736d328de6 | 172 | return &mConnectInfo[socket_id]; |
kishino | 20:dd736d328de6 | 173 | } |
kishino | 20:dd736d328de6 | 174 | |
kishino | 33:33f1bc919486 | 175 | C_SNIC_Core::tagUDP_RECVINFO_T *C_SNIC_Core::getUdpRecvInfo( int socket_id ) |
kishino | 33:33f1bc919486 | 176 | { |
kishino | 33:33f1bc919486 | 177 | if( (socket_id < 0) || (socket_id > MAX_SOCKET_ID) ) |
kishino | 33:33f1bc919486 | 178 | { |
kishino | 33:33f1bc919486 | 179 | return NULL; |
kishino | 33:33f1bc919486 | 180 | } |
kishino | 33:33f1bc919486 | 181 | return &mUdpRecvInfo[socket_id]; |
kishino | 33:33f1bc919486 | 182 | } |
kishino | 33:33f1bc919486 | 183 | |
kishino | 20:dd736d328de6 | 184 | C_SNIC_UartCommandManager *C_SNIC_Core::getUartCommand() |
kishino | 20:dd736d328de6 | 185 | { |
kishino | 20:dd736d328de6 | 186 | return mUartCommand_p; |
kishino | 20:dd736d328de6 | 187 | } |
kishino | 20:dd736d328de6 | 188 | |
kishino | 29:6a0ba999597d | 189 | unsigned char *C_SNIC_Core::getCommandBuf() |
kishino | 29:6a0ba999597d | 190 | { |
kishino | 29:6a0ba999597d | 191 | return gUART_COMMAND_BUF; |
kishino | 29:6a0ba999597d | 192 | } |
kishino | 20:dd736d328de6 | 193 | |
kishino | 29:6a0ba999597d | 194 | void C_SNIC_Core::uartRecvCallback( void ) |
kishino | 29:6a0ba999597d | 195 | { |
kishino | 20:dd736d328de6 | 196 | C_SNIC_Core *instance_p = C_SNIC_Core::getInstance(); |
kishino | 29:6a0ba999597d | 197 | if( instance_p != NULL ) |
kishino | 20:dd736d328de6 | 198 | { |
kishino | 29:6a0ba999597d | 199 | int recvdata = 0; |
kishino | 20:dd736d328de6 | 200 | |
kishino | 29:6a0ba999597d | 201 | // set signal |
kishino | 29:6a0ba999597d | 202 | if( instance_p->mUart_p->readable() ) |
kishino | 20:dd736d328de6 | 203 | { |
kishino | 20:dd736d328de6 | 204 | // Receive data from UART. |
kishino | 20:dd736d328de6 | 205 | instance_p->mUartMutex.lock(); |
kishino | 20:dd736d328de6 | 206 | recvdata = instance_p->mUart_p->getc(); |
kishino | 20:dd736d328de6 | 207 | instance_p->mUartMutex.unlock(); |
kishino | 20:dd736d328de6 | 208 | |
kishino | 29:6a0ba999597d | 209 | // Check UART receiving buffer |
kishino | 29:6a0ba999597d | 210 | if( gUART_RCVBUF_p != NULL ) |
kishino | 20:dd736d328de6 | 211 | { |
kishino | 29:6a0ba999597d | 212 | gUART_RCVBUF_p->buf[ gUART_RCVBUF_p->size ] = (unsigned char)recvdata; |
kishino | 29:6a0ba999597d | 213 | gUART_RCVBUF_p->size++; |
kishino | 29:6a0ba999597d | 214 | |
kishino | 36:f33fcf5975ab | 215 | if( gUART_RCVBUF_p->size == 3 ) |
kishino | 20:dd736d328de6 | 216 | { |
kishino | 36:f33fcf5975ab | 217 | // get demand size |
kishino | 36:f33fcf5975ab | 218 | unsigned short payload_len = ( ( (gUART_RCVBUF_p->buf[1] & ~0x80) & 0xff) | ( ( (gUART_RCVBUF_p->buf[2] & ~0xC0) << 7) & 0xff80) ); |
kishino | 36:f33fcf5975ab | 219 | gUART_RCVBUF_p->demand_size = payload_len + 6; |
kishino | 36:f33fcf5975ab | 220 | |
kishino | 36:f33fcf5975ab | 221 | } |
kishino | 36:f33fcf5975ab | 222 | |
kishino | 36:f33fcf5975ab | 223 | if( gUART_RCVBUF_p->demand_size > 0 ) |
kishino | 36:f33fcf5975ab | 224 | { |
kishino | 36:f33fcf5975ab | 225 | // Check size of received data. |
kishino | 36:f33fcf5975ab | 226 | if( gUART_RCVBUF_p->size >= gUART_RCVBUF_p->demand_size ) |
kishino | 36:f33fcf5975ab | 227 | { |
kishino | 36:f33fcf5975ab | 228 | // Add queue |
kishino | 36:f33fcf5975ab | 229 | mUartRecvQueue.put( gUART_RCVBUF_p ); |
kishino | 36:f33fcf5975ab | 230 | |
kishino | 36:f33fcf5975ab | 231 | gUART_RCVBUF_p = NULL; |
kishino | 20:dd736d328de6 | 232 | |
kishino | 36:f33fcf5975ab | 233 | // set signal for dispatch thread |
kishino | 36:f33fcf5975ab | 234 | instance_p->mUartRecvDispatchThread_p->signal_set( UART_DISPATCH_SIGNAL ); |
kishino | 36:f33fcf5975ab | 235 | } |
kishino | 20:dd736d328de6 | 236 | } |
kishino | 36:f33fcf5975ab | 237 | |
kishino | 20:dd736d328de6 | 238 | } |
kishino | 20:dd736d328de6 | 239 | else |
kishino | 20:dd736d328de6 | 240 | { |
kishino | 20:dd736d328de6 | 241 | // Check received data is SOM. |
kishino | 20:dd736d328de6 | 242 | if( recvdata == UART_CMD_SOM ) |
kishino | 20:dd736d328de6 | 243 | { |
kishino | 29:6a0ba999597d | 244 | gUART_RCVBUF_p = instance_p->allocUartRcvBuf(); |
kishino | 29:6a0ba999597d | 245 | gUART_RCVBUF_p->size = 0; |
kishino | 36:f33fcf5975ab | 246 | gUART_RCVBUF_p->demand_size = 0; |
kishino | 29:6a0ba999597d | 247 | // get buffer for Uart receive |
kishino | 29:6a0ba999597d | 248 | gUART_RCVBUF_p->buf[ 0 ] = (unsigned char)recvdata; |
kishino | 29:6a0ba999597d | 249 | |
kishino | 29:6a0ba999597d | 250 | gUART_RCVBUF_p->size++; |
kishino | 20:dd736d328de6 | 251 | } |
kishino | 20:dd736d328de6 | 252 | } |
kishino | 20:dd736d328de6 | 253 | } |
kishino | 20:dd736d328de6 | 254 | } |
kishino | 20:dd736d328de6 | 255 | } |
kishino | 20:dd736d328de6 | 256 | |
kishino | 29:6a0ba999597d | 257 | void C_SNIC_Core::uartRecvDispatchThread (void const *args_p) |
kishino | 29:6a0ba999597d | 258 | { |
kishino | 29:6a0ba999597d | 259 | C_SNIC_Core *instance_p = C_SNIC_Core::getInstance(); |
kishino | 29:6a0ba999597d | 260 | C_SNIC_UartCommandManager *uartCmdMgr_p = instance_p->getUartCommand(); |
kishino | 29:6a0ba999597d | 261 | |
kishino | 29:6a0ba999597d | 262 | tagMEMPOOL_BLOCK_T *uartRecvBuf_p; |
kishino | 29:6a0ba999597d | 263 | osEvent evt; |
kishino | 29:6a0ba999597d | 264 | |
kishino | 29:6a0ba999597d | 265 | for(;;) |
kishino | 29:6a0ba999597d | 266 | { |
kishino | 29:6a0ba999597d | 267 | // wait |
kishino | 29:6a0ba999597d | 268 | Thread::signal_wait( UART_DISPATCH_SIGNAL ); |
kishino | 29:6a0ba999597d | 269 | |
kishino | 29:6a0ba999597d | 270 | // Get scanresults from queue |
kishino | 29:6a0ba999597d | 271 | evt = mUartRecvQueue.get(500); |
kishino | 29:6a0ba999597d | 272 | if (evt.status == osEventMessage) |
kishino | 29:6a0ba999597d | 273 | { |
kishino | 29:6a0ba999597d | 274 | do |
kishino | 29:6a0ba999597d | 275 | { |
kishino | 29:6a0ba999597d | 276 | uartRecvBuf_p = (tagMEMPOOL_BLOCK_T *)evt.value.p; |
kishino | 29:6a0ba999597d | 277 | |
kishino | 32:ae95309643aa | 278 | #if 0 |
kishino | 29:6a0ba999597d | 279 | { |
kishino | 29:6a0ba999597d | 280 | int i; |
kishino | 29:6a0ba999597d | 281 | for(i=0;i<uartRecvBuf_p->size;i++) |
kishino | 29:6a0ba999597d | 282 | { |
kishino | 29:6a0ba999597d | 283 | printf("%02x", uartRecvBuf_p->buf[i]); |
kishino | 29:6a0ba999597d | 284 | } |
kishino | 29:6a0ba999597d | 285 | printf("\r\n"); |
kishino | 29:6a0ba999597d | 286 | } |
kishino | 32:ae95309643aa | 287 | #endif |
kishino | 29:6a0ba999597d | 288 | unsigned char command_id; |
kishino | 29:6a0ba999597d | 289 | // Get payload from received data from UART. |
kishino | 29:6a0ba999597d | 290 | int payload_len = C_SNIC_UartMsgUtil::getResponsePayload( uartRecvBuf_p->size, uartRecvBuf_p->buf |
kishino | 29:6a0ba999597d | 291 | , &command_id, gUART_TEMP_BUF ); |
kishino | 33:33f1bc919486 | 292 | // Check receive a TCP packet |
kishino | 29:6a0ba999597d | 293 | if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_CONNECTION_RECV_IND) ) |
kishino | 29:6a0ba999597d | 294 | { |
kishino | 29:6a0ba999597d | 295 | // Packet buffering |
kishino | 29:6a0ba999597d | 296 | uartCmdMgr_p->bufferredPacket( gUART_TEMP_BUF, payload_len ); |
kishino | 29:6a0ba999597d | 297 | } |
kishino | 32:ae95309643aa | 298 | // Check connected from TCP client |
kishino | 32:ae95309643aa | 299 | else if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_TCP_CLIENT_SOCKET_IND) ) |
kishino | 32:ae95309643aa | 300 | { |
kishino | 32:ae95309643aa | 301 | // Connected from TCP client |
kishino | 32:ae95309643aa | 302 | uartCmdMgr_p->connectedTCPClient( gUART_TEMP_BUF, payload_len ); |
kishino | 32:ae95309643aa | 303 | } |
kishino | 33:33f1bc919486 | 304 | // Check receive UDP packet |
kishino | 33:33f1bc919486 | 305 | else if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_UDP_RECV_IND) ) |
kishino | 33:33f1bc919486 | 306 | { |
kishino | 33:33f1bc919486 | 307 | // UDP packet buffering |
kishino | 33:33f1bc919486 | 308 | uartCmdMgr_p->bufferredUDPPacket( gUART_TEMP_BUF, payload_len ); |
kishino | 33:33f1bc919486 | 309 | } |
kishino | 29:6a0ba999597d | 310 | // Check scan results indication |
kishino | 29:6a0ba999597d | 311 | else if( (command_id == UART_CMD_ID_WIFI) && (gUART_TEMP_BUF[0] == UART_CMD_SID_WIFI_SCAN_RESULT_IND) ) |
kishino | 29:6a0ba999597d | 312 | { |
kishino | 29:6a0ba999597d | 313 | // Scan result indicate |
kishino | 29:6a0ba999597d | 314 | uartCmdMgr_p->scanResultIndicate( gUART_TEMP_BUF, payload_len ); |
kishino | 29:6a0ba999597d | 315 | } |
kishino | 29:6a0ba999597d | 316 | // Checks in the command which is waiting. |
kishino | 29:6a0ba999597d | 317 | else if( uartCmdMgr_p->isWaitingCommand(command_id, gUART_TEMP_BUF) ) |
kishino | 29:6a0ba999597d | 318 | { |
kishino | 29:6a0ba999597d | 319 | // Get buffer for payload data |
kishino | 29:6a0ba999597d | 320 | unsigned char *payload_buf_p = uartCmdMgr_p->getResponseBuf(); |
kishino | 29:6a0ba999597d | 321 | if( payload_buf_p != NULL ) |
kishino | 29:6a0ba999597d | 322 | { |
kishino | 29:6a0ba999597d | 323 | memcpy( payload_buf_p, gUART_TEMP_BUF, payload_len ); |
kishino | 29:6a0ba999597d | 324 | uartCmdMgr_p->setResponseBuf( NULL ); |
kishino | 29:6a0ba999597d | 325 | } |
kishino | 29:6a0ba999597d | 326 | // Set status |
kishino | 29:6a0ba999597d | 327 | uartCmdMgr_p->setCommandStatus( gUART_TEMP_BUF[2] ); |
kishino | 29:6a0ba999597d | 328 | // Set signal for command response wait. |
kishino | 29:6a0ba999597d | 329 | uartCmdMgr_p->signal(); |
kishino | 29:6a0ba999597d | 330 | } |
kishino | 29:6a0ba999597d | 331 | // |
kishino | 29:6a0ba999597d | 332 | instance_p->freeUartRecvBuf( uartRecvBuf_p ); |
kishino | 29:6a0ba999597d | 333 | |
kishino | 29:6a0ba999597d | 334 | evt = mUartRecvQueue.get(500); |
kishino | 29:6a0ba999597d | 335 | Thread::yield(); |
kishino | 29:6a0ba999597d | 336 | } while( evt.status == osEventMessage ); |
kishino | 29:6a0ba999597d | 337 | } |
kishino | 29:6a0ba999597d | 338 | } |
kishino | 29:6a0ba999597d | 339 | } |