Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more
Fork of YDwifiInterface by
YDwifiInterface.cpp@2:0ba43344c814, 2014-03-11 (annotated)
- Committer:
- kishino
- Date:
- Tue Mar 11 10:38:36 2014 +0000
- Revision:
- 2:0ba43344c814
- Parent:
- 0:61c402886fbb
- Child:
- 3:9f90024d7fb2
Created the basic composition of SNIC UART command API.; Created the UART command for getting firmware's version.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kishino | 0:61c402886fbb | 1 | #include "YDwifiInterface.h" |
| kishino | 2:0ba43344c814 | 2 | #include "YDwifi_uartmsg.h" |
| kishino | 0:61c402886fbb | 3 | |
| kishino | 2:0ba43344c814 | 4 | using namespace murata_wifi; |
| kishino | 2:0ba43344c814 | 5 | |
| kishino | 2:0ba43344c814 | 6 | #define MEMPOOL_BLOCK_SIZE 2048 |
| kishino | 2:0ba43344c814 | 7 | typedef struct |
| kishino | 2:0ba43344c814 | 8 | { |
| kishino | 2:0ba43344c814 | 9 | unsigned char buf[MEMPOOL_BLOCK_SIZE]; |
| kishino | 2:0ba43344c814 | 10 | }tagMEMPOOL_BLOCK_T; |
| kishino | 2:0ba43344c814 | 11 | #define MEMPOOL_PAYLOAD_NUM 1 |
| kishino | 2:0ba43344c814 | 12 | /** MemoryPool for payload of UART response */ |
| kishino | 2:0ba43344c814 | 13 | MemoryPool<tagMEMPOOL_BLOCK_T, MEMPOOL_PAYLOAD_NUM> gMEMPOOL_PAYLOAD; |
| kishino | 2:0ba43344c814 | 14 | |
| kishino | 2:0ba43344c814 | 15 | #define UART_REQUEST_PAYLOAD_MAX 512 |
| kishino | 0:61c402886fbb | 16 | |
| kishino | 0:61c402886fbb | 17 | C_YDwifiInterface::C_YDwifiInterface( PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud): |
| kishino | 0:61c402886fbb | 18 | C_YDwifi(tx, rx, cts, rts, reset, alarm, baud) |
| kishino | 0:61c402886fbb | 19 | { |
| kishino | 0:61c402886fbb | 20 | } |
| kishino | 0:61c402886fbb | 21 | |
| kishino | 0:61c402886fbb | 22 | int C_YDwifiInterface::init() |
| kishino | 0:61c402886fbb | 23 | { |
| kishino | 0:61c402886fbb | 24 | /* Initialize UART */ |
| kishino | 0:61c402886fbb | 25 | initUart(); |
| kishino | 0:61c402886fbb | 26 | return 0; |
| kishino | 2:0ba43344c814 | 27 | } |
| kishino | 2:0ba43344c814 | 28 | |
| kishino | 2:0ba43344c814 | 29 | int C_YDwifiInterface::getFWVersion( unsigned char *version_p ) |
| kishino | 2:0ba43344c814 | 30 | { |
| kishino | 2:0ba43344c814 | 31 | // Get buffer for response payloadfrom MemoryPool |
| kishino | 2:0ba43344c814 | 32 | tagMEMPOOL_BLOCK_T *payload_buf = gMEMPOOL_PAYLOAD.alloc(); |
| kishino | 2:0ba43344c814 | 33 | if( payload_buf == NULL ) |
| kishino | 2:0ba43344c814 | 34 | { |
| kishino | 2:0ba43344c814 | 35 | printf("getFWVersion payload_buf NULL\r\n"); |
| kishino | 2:0ba43344c814 | 36 | return -1; |
| kishino | 2:0ba43344c814 | 37 | } |
| kishino | 2:0ba43344c814 | 38 | |
| kishino | 2:0ba43344c814 | 39 | tagGEN_FW_VER_GET_REQ_T req; |
| kishino | 2:0ba43344c814 | 40 | unsigned char payload_array[UART_REQUEST_PAYLOAD_MAX]; |
| kishino | 2:0ba43344c814 | 41 | unsigned char command_array[UART_REQUEST_PAYLOAD_MAX]; |
| kishino | 2:0ba43344c814 | 42 | unsigned short payload_len; |
| kishino | 2:0ba43344c814 | 43 | unsigned int command_len; |
| kishino | 2:0ba43344c814 | 44 | int ret; |
| kishino | 2:0ba43344c814 | 45 | |
| kishino | 2:0ba43344c814 | 46 | // Make request |
| kishino | 2:0ba43344c814 | 47 | req.cmd_sid = UART_CMD_SID_GEN_FW_VER_GET_REQ; |
| kishino | 2:0ba43344c814 | 48 | req.seq = mUartRequestSeq++; |
| kishino | 2:0ba43344c814 | 49 | |
| kishino | 2:0ba43344c814 | 50 | // Make command payload |
| kishino | 2:0ba43344c814 | 51 | payload_len = C_YD_UartMsg::makePayload( sizeof(tagGEN_FW_VER_GET_REQ_T), (unsigned char *)&req, payload_array ); |
| kishino | 2:0ba43344c814 | 52 | // Make all command request |
| kishino | 2:0ba43344c814 | 53 | command_len = C_YD_UartMsg::makeRequest( UART_CMD_ID_GEN, payload_array, payload_len, command_array ); |
| kishino | 2:0ba43344c814 | 54 | |
| kishino | 2:0ba43344c814 | 55 | // Set data for response |
| kishino | 2:0ba43344c814 | 56 | mUartCommand.setCommandID( UART_CMD_ID_GEN ); |
| kishino | 2:0ba43344c814 | 57 | mUartCommand.setCommandSID( UART_CMD_SID_GEN_FW_VER_GET_REQ ); |
| kishino | 2:0ba43344c814 | 58 | mUartCommand.setResponseBuf( payload_buf->buf ); |
| kishino | 2:0ba43344c814 | 59 | |
| kishino | 2:0ba43344c814 | 60 | // Send uart command request |
| kishino | 2:0ba43344c814 | 61 | sendUart( command_len, command_array ); |
| kishino | 2:0ba43344c814 | 62 | |
| kishino | 2:0ba43344c814 | 63 | // Wait UART response |
| kishino | 2:0ba43344c814 | 64 | ret = mUartCommand.wait(); |
| kishino | 2:0ba43344c814 | 65 | printf( "getFWversion wait:%d\r\n", ret ); |
| kishino | 2:0ba43344c814 | 66 | if( ret != 0 ) |
| kishino | 2:0ba43344c814 | 67 | { |
| kishino | 2:0ba43344c814 | 68 | printf( "getFWversion failed\r\n" ); |
| kishino | 2:0ba43344c814 | 69 | gMEMPOOL_PAYLOAD.free( payload_buf ); |
| kishino | 2:0ba43344c814 | 70 | return -1; |
| kishino | 2:0ba43344c814 | 71 | } |
| kishino | 2:0ba43344c814 | 72 | |
| kishino | 2:0ba43344c814 | 73 | printf("getFWversion status:%02x\r\n", mUartCommand.getCommandStatus()); |
| kishino | 2:0ba43344c814 | 74 | if( mUartCommand.getCommandStatus() == 0 ) |
| kishino | 2:0ba43344c814 | 75 | { |
| kishino | 2:0ba43344c814 | 76 | unsigned char version_len = payload_buf->buf[3]; |
| kishino | 2:0ba43344c814 | 77 | memcpy( version_p, &payload_buf->buf[4], version_len ); |
| kishino | 2:0ba43344c814 | 78 | } |
| kishino | 2:0ba43344c814 | 79 | gMEMPOOL_PAYLOAD.free( payload_buf ); |
| kishino | 2:0ba43344c814 | 80 | return 0; |
| kishino | 2:0ba43344c814 | 81 | } |

Murata TypeYD