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