SNIC UART Interface library for Murata Type-YD module
Dependents: WebSocketServerTest
Fork of SNICInterface_mod by
SNIC/SNIC_Core.cpp@36:f33fcf5975ab, 2014-06-19 (annotated)
- Committer:
- kishino
- Date:
- Thu Jun 19 10:15:47 2014 +0000
- Revision:
- 36:f33fcf5975ab
- Parent:
- 35:e4e7f86fd975
- Child:
- 37:f3a2053627c2
Supported a new command format of SNIC UART.
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 | 29:6a0ba999597d | 80 | wait(0.2); |
kishino | 29:6a0ba999597d | 81 | reset_pin = 1; |
kishino | 29:6a0ba999597d | 82 | wait(0.2); |
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 short payload_len; |
kishino | 20:dd736d328de6 | 114 | unsigned int command_len = 0; |
kishino | 20:dd736d328de6 | 115 | |
kishino | 20:dd736d328de6 | 116 | // Make all command request |
kishino | 36:f33fcf5975ab | 117 | command_len = C_SNIC_UartMsgUtil::makeRequest( cmd_id, req_buf_p, req_buf_len, command_p ); |
kishino | 20:dd736d328de6 | 118 | |
kishino | 20:dd736d328de6 | 119 | // Set data for response |
kishino | 20:dd736d328de6 | 120 | mUartCommand_p->setCommandID( cmd_id ); |
kishino | 20:dd736d328de6 | 121 | mUartCommand_p->setCommandSID( cmd_sid | 0x80 ); |
kishino | 20:dd736d328de6 | 122 | mUartCommand_p->setResponseBuf( response_buf_p ); |
kishino | 20:dd736d328de6 | 123 | |
kishino | 20:dd736d328de6 | 124 | return command_len; |
kishino | 20:dd736d328de6 | 125 | } |
kishino | 20:dd736d328de6 | 126 | |
kishino | 20:dd736d328de6 | 127 | int C_SNIC_Core::sendUart( unsigned int len, unsigned char *data ) |
kishino | 20:dd736d328de6 | 128 | { |
kishino | 20:dd736d328de6 | 129 | int ret = 0; |
kishino | 20:dd736d328de6 | 130 | mUartMutex.lock(); |
kishino | 20:dd736d328de6 | 131 | for( int i = 0; i < len; i++ ) |
kishino | 20:dd736d328de6 | 132 | { |
kishino | 20:dd736d328de6 | 133 | // Write to UART |
kishino | 20:dd736d328de6 | 134 | ret = mUart_p->putc( data[i] ); |
kishino | 20:dd736d328de6 | 135 | if( ret == -1 ) |
kishino | 20:dd736d328de6 | 136 | { |
kishino | 20:dd736d328de6 | 137 | break; |
kishino | 20:dd736d328de6 | 138 | } |
kishino | 20:dd736d328de6 | 139 | } |
kishino | 20:dd736d328de6 | 140 | mUartMutex.unlock(); |
kishino | 36:f33fcf5975ab | 141 | |
kishino | 20:dd736d328de6 | 142 | return ret; |
kishino | 20:dd736d328de6 | 143 | } |
kishino | 20:dd736d328de6 | 144 | |
kishino | 29:6a0ba999597d | 145 | tagMEMPOOL_BLOCK_T *C_SNIC_Core::allocCmdBuf() |
kishino | 20:dd736d328de6 | 146 | { |
kishino | 20:dd736d328de6 | 147 | // Get buffer from MemoryPool |
kishino | 20:dd736d328de6 | 148 | return mMemPoolPayload.alloc(); |
kishino | 20:dd736d328de6 | 149 | } |
kishino | 20:dd736d328de6 | 150 | |
kishino | 20:dd736d328de6 | 151 | void C_SNIC_Core::freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p ) |
kishino | 20:dd736d328de6 | 152 | { |
kishino | 20:dd736d328de6 | 153 | mMemPoolPayload.free( buf_p ); |
kishino | 20:dd736d328de6 | 154 | } |
kishino | 20:dd736d328de6 | 155 | |
kishino | 29:6a0ba999597d | 156 | tagMEMPOOL_BLOCK_T *C_SNIC_Core::allocUartRcvBuf() |
kishino | 29:6a0ba999597d | 157 | { |
kishino | 29:6a0ba999597d | 158 | // Get buffer from MemoryPool |
kishino | 29:6a0ba999597d | 159 | return mMemPoolUartRecv.alloc(); |
kishino | 29:6a0ba999597d | 160 | } |
kishino | 29:6a0ba999597d | 161 | |
kishino | 29:6a0ba999597d | 162 | void C_SNIC_Core::freeUartRecvBuf( tagMEMPOOL_BLOCK_T *buf_p ) |
kishino | 29:6a0ba999597d | 163 | { |
kishino | 29:6a0ba999597d | 164 | mMemPoolUartRecv.free( buf_p ); |
kishino | 29:6a0ba999597d | 165 | } |
kishino | 29:6a0ba999597d | 166 | |
kishino | 22:a9ec0cad4f84 | 167 | C_SNIC_Core::tagCONNECT_INFO_T *C_SNIC_Core::getConnectInfo( int socket_id ) |
kishino | 20:dd736d328de6 | 168 | { |
kishino | 20:dd736d328de6 | 169 | if( (socket_id < 0) || (socket_id > MAX_SOCKET_ID) ) |
kishino | 20:dd736d328de6 | 170 | { |
kishino | 20:dd736d328de6 | 171 | return NULL; |
kishino | 20:dd736d328de6 | 172 | } |
kishino | 20:dd736d328de6 | 173 | return &mConnectInfo[socket_id]; |
kishino | 20:dd736d328de6 | 174 | } |
kishino | 20:dd736d328de6 | 175 | |
kishino | 33:33f1bc919486 | 176 | C_SNIC_Core::tagUDP_RECVINFO_T *C_SNIC_Core::getUdpRecvInfo( int socket_id ) |
kishino | 33:33f1bc919486 | 177 | { |
kishino | 33:33f1bc919486 | 178 | if( (socket_id < 0) || (socket_id > MAX_SOCKET_ID) ) |
kishino | 33:33f1bc919486 | 179 | { |
kishino | 33:33f1bc919486 | 180 | return NULL; |
kishino | 33:33f1bc919486 | 181 | } |
kishino | 33:33f1bc919486 | 182 | return &mUdpRecvInfo[socket_id]; |
kishino | 33:33f1bc919486 | 183 | } |
kishino | 33:33f1bc919486 | 184 | |
kishino | 20:dd736d328de6 | 185 | C_SNIC_UartCommandManager *C_SNIC_Core::getUartCommand() |
kishino | 20:dd736d328de6 | 186 | { |
kishino | 20:dd736d328de6 | 187 | return mUartCommand_p; |
kishino | 20:dd736d328de6 | 188 | } |
kishino | 20:dd736d328de6 | 189 | |
kishino | 29:6a0ba999597d | 190 | unsigned char *C_SNIC_Core::getCommandBuf() |
kishino | 29:6a0ba999597d | 191 | { |
kishino | 29:6a0ba999597d | 192 | return gUART_COMMAND_BUF; |
kishino | 29:6a0ba999597d | 193 | } |
kishino | 20:dd736d328de6 | 194 | |
kishino | 29:6a0ba999597d | 195 | void C_SNIC_Core::uartRecvCallback( void ) |
kishino | 29:6a0ba999597d | 196 | { |
kishino | 20:dd736d328de6 | 197 | C_SNIC_Core *instance_p = C_SNIC_Core::getInstance(); |
kishino | 29:6a0ba999597d | 198 | if( instance_p != NULL ) |
kishino | 20:dd736d328de6 | 199 | { |
kishino | 29:6a0ba999597d | 200 | int recvdata = 0; |
kishino | 20:dd736d328de6 | 201 | |
kishino | 29:6a0ba999597d | 202 | // set signal |
kishino | 29:6a0ba999597d | 203 | if( instance_p->mUart_p->readable() ) |
kishino | 20:dd736d328de6 | 204 | { |
kishino | 20:dd736d328de6 | 205 | // Receive data from UART. |
kishino | 20:dd736d328de6 | 206 | instance_p->mUartMutex.lock(); |
kishino | 20:dd736d328de6 | 207 | recvdata = instance_p->mUart_p->getc(); |
kishino | 20:dd736d328de6 | 208 | instance_p->mUartMutex.unlock(); |
kishino | 20:dd736d328de6 | 209 | |
kishino | 29:6a0ba999597d | 210 | // Check UART receiving buffer |
kishino | 29:6a0ba999597d | 211 | if( gUART_RCVBUF_p != NULL ) |
kishino | 20:dd736d328de6 | 212 | { |
kishino | 29:6a0ba999597d | 213 | gUART_RCVBUF_p->buf[ gUART_RCVBUF_p->size ] = (unsigned char)recvdata; |
kishino | 29:6a0ba999597d | 214 | gUART_RCVBUF_p->size++; |
kishino | 29:6a0ba999597d | 215 | |
kishino | 36:f33fcf5975ab | 216 | if( gUART_RCVBUF_p->size == 3 ) |
kishino | 20:dd736d328de6 | 217 | { |
kishino | 36:f33fcf5975ab | 218 | // get demand size |
kishino | 36:f33fcf5975ab | 219 | unsigned short payload_len = ( ( (gUART_RCVBUF_p->buf[1] & ~0x80) & 0xff) | ( ( (gUART_RCVBUF_p->buf[2] & ~0xC0) << 7) & 0xff80) ); |
kishino | 36:f33fcf5975ab | 220 | gUART_RCVBUF_p->demand_size = payload_len + 6; |
kishino | 36:f33fcf5975ab | 221 | |
kishino | 36:f33fcf5975ab | 222 | } |
kishino | 36:f33fcf5975ab | 223 | |
kishino | 36:f33fcf5975ab | 224 | if( gUART_RCVBUF_p->demand_size > 0 ) |
kishino | 36:f33fcf5975ab | 225 | { |
kishino | 36:f33fcf5975ab | 226 | // Check size of received data. |
kishino | 36:f33fcf5975ab | 227 | if( gUART_RCVBUF_p->size >= gUART_RCVBUF_p->demand_size ) |
kishino | 36:f33fcf5975ab | 228 | { |
kishino | 36:f33fcf5975ab | 229 | // Add queue |
kishino | 36:f33fcf5975ab | 230 | mUartRecvQueue.put( gUART_RCVBUF_p ); |
kishino | 36:f33fcf5975ab | 231 | |
kishino | 36:f33fcf5975ab | 232 | gUART_RCVBUF_p = NULL; |
kishino | 20:dd736d328de6 | 233 | |
kishino | 36:f33fcf5975ab | 234 | // set signal for dispatch thread |
kishino | 36:f33fcf5975ab | 235 | instance_p->mUartRecvDispatchThread_p->signal_set( UART_DISPATCH_SIGNAL ); |
kishino | 36:f33fcf5975ab | 236 | } |
kishino | 20:dd736d328de6 | 237 | } |
kishino | 36:f33fcf5975ab | 238 | |
kishino | 20:dd736d328de6 | 239 | } |
kishino | 20:dd736d328de6 | 240 | else |
kishino | 20:dd736d328de6 | 241 | { |
kishino | 20:dd736d328de6 | 242 | // Check received data is SOM. |
kishino | 20:dd736d328de6 | 243 | if( recvdata == UART_CMD_SOM ) |
kishino | 20:dd736d328de6 | 244 | { |
kishino | 29:6a0ba999597d | 245 | gUART_RCVBUF_p = instance_p->allocUartRcvBuf(); |
kishino | 29:6a0ba999597d | 246 | gUART_RCVBUF_p->size = 0; |
kishino | 36:f33fcf5975ab | 247 | gUART_RCVBUF_p->demand_size = 0; |
kishino | 29:6a0ba999597d | 248 | // get buffer for Uart receive |
kishino | 29:6a0ba999597d | 249 | gUART_RCVBUF_p->buf[ 0 ] = (unsigned char)recvdata; |
kishino | 29:6a0ba999597d | 250 | |
kishino | 29:6a0ba999597d | 251 | gUART_RCVBUF_p->size++; |
kishino | 20:dd736d328de6 | 252 | } |
kishino | 20:dd736d328de6 | 253 | } |
kishino | 20:dd736d328de6 | 254 | } |
kishino | 20:dd736d328de6 | 255 | } |
kishino | 20:dd736d328de6 | 256 | } |
kishino | 20:dd736d328de6 | 257 | |
kishino | 29:6a0ba999597d | 258 | void C_SNIC_Core::uartRecvDispatchThread (void const *args_p) |
kishino | 29:6a0ba999597d | 259 | { |
kishino | 29:6a0ba999597d | 260 | C_SNIC_Core *instance_p = C_SNIC_Core::getInstance(); |
kishino | 29:6a0ba999597d | 261 | C_SNIC_UartCommandManager *uartCmdMgr_p = instance_p->getUartCommand(); |
kishino | 29:6a0ba999597d | 262 | |
kishino | 29:6a0ba999597d | 263 | tagMEMPOOL_BLOCK_T *uartRecvBuf_p; |
kishino | 29:6a0ba999597d | 264 | osEvent evt; |
kishino | 29:6a0ba999597d | 265 | |
kishino | 29:6a0ba999597d | 266 | for(;;) |
kishino | 29:6a0ba999597d | 267 | { |
kishino | 29:6a0ba999597d | 268 | // wait |
kishino | 29:6a0ba999597d | 269 | Thread::signal_wait( UART_DISPATCH_SIGNAL ); |
kishino | 29:6a0ba999597d | 270 | |
kishino | 29:6a0ba999597d | 271 | // Get scanresults from queue |
kishino | 29:6a0ba999597d | 272 | evt = mUartRecvQueue.get(500); |
kishino | 29:6a0ba999597d | 273 | if (evt.status == osEventMessage) |
kishino | 29:6a0ba999597d | 274 | { |
kishino | 29:6a0ba999597d | 275 | do |
kishino | 29:6a0ba999597d | 276 | { |
kishino | 29:6a0ba999597d | 277 | uartRecvBuf_p = (tagMEMPOOL_BLOCK_T *)evt.value.p; |
kishino | 29:6a0ba999597d | 278 | |
kishino | 32:ae95309643aa | 279 | #if 0 |
kishino | 29:6a0ba999597d | 280 | { |
kishino | 29:6a0ba999597d | 281 | int i; |
kishino | 29:6a0ba999597d | 282 | for(i=0;i<uartRecvBuf_p->size;i++) |
kishino | 29:6a0ba999597d | 283 | { |
kishino | 29:6a0ba999597d | 284 | printf("%02x", uartRecvBuf_p->buf[i]); |
kishino | 29:6a0ba999597d | 285 | } |
kishino | 29:6a0ba999597d | 286 | printf("\r\n"); |
kishino | 29:6a0ba999597d | 287 | } |
kishino | 32:ae95309643aa | 288 | #endif |
kishino | 29:6a0ba999597d | 289 | unsigned char command_id; |
kishino | 29:6a0ba999597d | 290 | // Get payload from received data from UART. |
kishino | 29:6a0ba999597d | 291 | int payload_len = C_SNIC_UartMsgUtil::getResponsePayload( uartRecvBuf_p->size, uartRecvBuf_p->buf |
kishino | 29:6a0ba999597d | 292 | , &command_id, gUART_TEMP_BUF ); |
kishino | 33:33f1bc919486 | 293 | // Check receive a TCP packet |
kishino | 29:6a0ba999597d | 294 | if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_CONNECTION_RECV_IND) ) |
kishino | 29:6a0ba999597d | 295 | { |
kishino | 29:6a0ba999597d | 296 | // Packet buffering |
kishino | 29:6a0ba999597d | 297 | uartCmdMgr_p->bufferredPacket( gUART_TEMP_BUF, payload_len ); |
kishino | 29:6a0ba999597d | 298 | } |
kishino | 32:ae95309643aa | 299 | // Check connected from TCP client |
kishino | 32:ae95309643aa | 300 | else if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_TCP_CLIENT_SOCKET_IND) ) |
kishino | 32:ae95309643aa | 301 | { |
kishino | 32:ae95309643aa | 302 | // Connected from TCP client |
kishino | 32:ae95309643aa | 303 | uartCmdMgr_p->connectedTCPClient( gUART_TEMP_BUF, payload_len ); |
kishino | 32:ae95309643aa | 304 | } |
kishino | 33:33f1bc919486 | 305 | // Check receive UDP packet |
kishino | 33:33f1bc919486 | 306 | else if( (command_id == UART_CMD_ID_SNIC) && (gUART_TEMP_BUF[0] == UART_CMD_SID_SNIC_UDP_RECV_IND) ) |
kishino | 33:33f1bc919486 | 307 | { |
kishino | 33:33f1bc919486 | 308 | // UDP packet buffering |
kishino | 33:33f1bc919486 | 309 | uartCmdMgr_p->bufferredUDPPacket( gUART_TEMP_BUF, payload_len ); |
kishino | 33:33f1bc919486 | 310 | } |
kishino | 29:6a0ba999597d | 311 | // Check scan results indication |
kishino | 29:6a0ba999597d | 312 | else if( (command_id == UART_CMD_ID_WIFI) && (gUART_TEMP_BUF[0] == UART_CMD_SID_WIFI_SCAN_RESULT_IND) ) |
kishino | 29:6a0ba999597d | 313 | { |
kishino | 29:6a0ba999597d | 314 | // Scan result indicate |
kishino | 29:6a0ba999597d | 315 | uartCmdMgr_p->scanResultIndicate( gUART_TEMP_BUF, payload_len ); |
kishino | 29:6a0ba999597d | 316 | } |
kishino | 29:6a0ba999597d | 317 | // Checks in the command which is waiting. |
kishino | 29:6a0ba999597d | 318 | else if( uartCmdMgr_p->isWaitingCommand(command_id, gUART_TEMP_BUF) ) |
kishino | 29:6a0ba999597d | 319 | { |
kishino | 29:6a0ba999597d | 320 | // Get buffer for payload data |
kishino | 29:6a0ba999597d | 321 | unsigned char *payload_buf_p = uartCmdMgr_p->getResponseBuf(); |
kishino | 29:6a0ba999597d | 322 | if( payload_buf_p != NULL ) |
kishino | 29:6a0ba999597d | 323 | { |
kishino | 29:6a0ba999597d | 324 | memcpy( payload_buf_p, gUART_TEMP_BUF, payload_len ); |
kishino | 29:6a0ba999597d | 325 | uartCmdMgr_p->setResponseBuf( NULL ); |
kishino | 29:6a0ba999597d | 326 | } |
kishino | 29:6a0ba999597d | 327 | // Set status |
kishino | 29:6a0ba999597d | 328 | uartCmdMgr_p->setCommandStatus( gUART_TEMP_BUF[2] ); |
kishino | 29:6a0ba999597d | 329 | // Set signal for command response wait. |
kishino | 29:6a0ba999597d | 330 | uartCmdMgr_p->signal(); |
kishino | 29:6a0ba999597d | 331 | } |
kishino | 29:6a0ba999597d | 332 | // |
kishino | 29:6a0ba999597d | 333 | instance_p->freeUartRecvBuf( uartRecvBuf_p ); |
kishino | 29:6a0ba999597d | 334 | |
kishino | 29:6a0ba999597d | 335 | evt = mUartRecvQueue.get(500); |
kishino | 29:6a0ba999597d | 336 | Thread::yield(); |
kishino | 29:6a0ba999597d | 337 | } while( evt.status == osEventMessage ); |
kishino | 29:6a0ba999597d | 338 | } |
kishino | 29:6a0ba999597d | 339 | } |
kishino | 29:6a0ba999597d | 340 | } |