Customized SNICInterface
Fork of NySNICInterface by
Diff: SNIC/SNIC_Core.cpp
- Revision:
- 39:a1233ca02edf
- Parent:
- 38:f13e4e563d65
- Child:
- 40:b6b10c22a121
--- a/SNIC/SNIC_Core.cpp Wed Jun 25 00:04:11 2014 +0000 +++ b/SNIC/SNIC_Core.cpp Tue Jul 15 02:08:42 2014 +0000 @@ -1,15 +1,21 @@ -/******************* Murata Manufacturing Co.,Ltd. 2014 ***************** +/* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License + * muRata, SWITCH SCIENCE Wi-FI module TypeYD-SNIC UART. * - * Filename: SNIC_Core.cpp + * 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: * - * Purpose: This module has implementation of internal common function for API. - * - * $Author: kishino $ + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. * - * $Date: 2014/03/26 $ - * - * $Revision: 0.0.0.1 $ - * ***********************************************************************/ + * 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. + */ #include "mbed.h" #include "SNIC_Core.h" #include "SNIC_UartMsgUtil.h" @@ -20,6 +26,9 @@ #define UART_RECVBUF_SIZE 2048 #define UART_THREAD_STACK_SIZE 512 +#define UART_FIXED_HEADER_SIZE 3 +#define UART_FIXED_SIZE_IN_FRAME 6 +#define UART_RECV_QUEUE_TIMEOUT 500 typedef struct { @@ -198,13 +207,11 @@ { int recvdata = 0; - // set signal - if( instance_p->mUart_p->readable() ) + // Check received data from UART. + 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 buffer if( gUART_RCVBUF_p != NULL ) @@ -212,12 +219,15 @@ gUART_RCVBUF_p->buf[ gUART_RCVBUF_p->size ] = (unsigned char)recvdata; gUART_RCVBUF_p->size++; - if( gUART_RCVBUF_p->size == 3 ) + if( gUART_RCVBUF_p->size == UART_FIXED_HEADER_SIZE ) { // get demand size unsigned short payload_len = ( ( (gUART_RCVBUF_p->buf[1] & ~0x80) & 0xff) | ( ( (gUART_RCVBUF_p->buf[2] & ~0xC0) << 7) & 0xff80) ); - gUART_RCVBUF_p->demand_size = payload_len + 6; - + gUART_RCVBUF_p->demand_size = payload_len + UART_FIXED_SIZE_IN_FRAME; + if( gUART_RCVBUF_p->demand_size > MEMPOOL_BLOCK_SIZE ) + { + gUART_RCVBUF_p->demand_size = MEMPOOL_BLOCK_SIZE; + } } if( gUART_RCVBUF_p->demand_size > 0 ) @@ -268,7 +278,7 @@ Thread::signal_wait( UART_DISPATCH_SIGNAL ); // Get scanresults from queue - evt = mUartRecvQueue.get(500); + evt = mUartRecvQueue.get(UART_RECV_QUEUE_TIMEOUT); if (evt.status == osEventMessage) { do @@ -328,11 +338,15 @@ // Set signal for command response wait. uartCmdMgr_p->signal(); } + else + { + printf(" The received data is not expected.\r\n"); + } + // instance_p->freeUartRecvBuf( uartRecvBuf_p ); evt = mUartRecvQueue.get(500); - Thread::yield(); } while( evt.status == osEventMessage ); } }