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-httpclient-example SNIC-ntpclient-example
Fork of SNICInterface by
YDwifi/YDwifiUartCommand.cpp@7:e88ccbe0225f, 2014-03-14 (annotated)
- Committer:
- kishino
- Date:
- Fri Mar 14 08:48:12 2014 +0000
- Revision:
- 7:e88ccbe0225f
- Parent:
- 3:9f90024d7fb2
Scan handler interface modify
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kishino | 2:0ba43344c814 | 1 | #include "YDwifiUartCommand.h" |
| kishino | 2:0ba43344c814 | 2 | |
| kishino | 2:0ba43344c814 | 3 | using namespace murata_wifi; |
| kishino | 2:0ba43344c814 | 4 | |
| kishino | 2:0ba43344c814 | 5 | void C_YDwifiUartCommand::setCommandID( unsigned char cmd_id ) |
| kishino | 2:0ba43344c814 | 6 | { |
| kishino | 2:0ba43344c814 | 7 | mCommandID = cmd_id; |
| kishino | 2:0ba43344c814 | 8 | } |
| kishino | 2:0ba43344c814 | 9 | |
| kishino | 2:0ba43344c814 | 10 | unsigned char C_YDwifiUartCommand::getCommandID() |
| kishino | 2:0ba43344c814 | 11 | { |
| kishino | 2:0ba43344c814 | 12 | return mCommandID; |
| kishino | 2:0ba43344c814 | 13 | } |
| kishino | 2:0ba43344c814 | 14 | |
| kishino | 2:0ba43344c814 | 15 | void C_YDwifiUartCommand::setCommandSID( unsigned char cmd_sid ) |
| kishino | 2:0ba43344c814 | 16 | { |
| kishino | 2:0ba43344c814 | 17 | mCommandSID = cmd_sid; |
| kishino | 2:0ba43344c814 | 18 | } |
| kishino | 2:0ba43344c814 | 19 | |
| kishino | 2:0ba43344c814 | 20 | unsigned char C_YDwifiUartCommand::getCommandSID() |
| kishino | 2:0ba43344c814 | 21 | { |
| kishino | 2:0ba43344c814 | 22 | return mCommandSID; |
| kishino | 2:0ba43344c814 | 23 | } |
| kishino | 2:0ba43344c814 | 24 | |
| kishino | 2:0ba43344c814 | 25 | void C_YDwifiUartCommand::setCommandStatus( unsigned char status ) |
| kishino | 2:0ba43344c814 | 26 | { |
| kishino | 2:0ba43344c814 | 27 | mCommandStatus = status; |
| kishino | 2:0ba43344c814 | 28 | } |
| kishino | 2:0ba43344c814 | 29 | |
| kishino | 2:0ba43344c814 | 30 | unsigned char C_YDwifiUartCommand::getCommandStatus() |
| kishino | 2:0ba43344c814 | 31 | { |
| kishino | 2:0ba43344c814 | 32 | return mCommandStatus; |
| kishino | 2:0ba43344c814 | 33 | } |
| kishino | 2:0ba43344c814 | 34 | |
| kishino | 2:0ba43344c814 | 35 | void C_YDwifiUartCommand::setResponseBuf( unsigned char *buf_p ) |
| kishino | 2:0ba43344c814 | 36 | { |
| kishino | 2:0ba43344c814 | 37 | mResponseBuf_p = buf_p; |
| kishino | 2:0ba43344c814 | 38 | } |
| kishino | 2:0ba43344c814 | 39 | |
| kishino | 2:0ba43344c814 | 40 | unsigned char *C_YDwifiUartCommand::getResponseBuf() |
| kishino | 2:0ba43344c814 | 41 | { |
| kishino | 2:0ba43344c814 | 42 | return mResponseBuf_p; |
| kishino | 2:0ba43344c814 | 43 | } |
| kishino | 2:0ba43344c814 | 44 | |
| kishino | 3:9f90024d7fb2 | 45 | void C_YDwifiUartCommand::setScanResultHandler( void (*handler_p)(tagSCAN_RESULT_T *scan_result) ) |
| kishino | 3:9f90024d7fb2 | 46 | { |
| kishino | 3:9f90024d7fb2 | 47 | mScanResultHandler_p = handler_p; |
| kishino | 3:9f90024d7fb2 | 48 | } |
| kishino | 3:9f90024d7fb2 | 49 | |
| kishino | 2:0ba43344c814 | 50 | |
| kishino | 2:0ba43344c814 | 51 | int C_YDwifiUartCommand::wait() |
| kishino | 2:0ba43344c814 | 52 | { |
| kishino | 2:0ba43344c814 | 53 | int ret = 0; |
| kishino | 7:e88ccbe0225f | 54 | |
| kishino | 2:0ba43344c814 | 55 | // Get thread ID |
| kishino | 2:0ba43344c814 | 56 | mCommandThreadID = osThreadGetId(); |
| kishino | 2:0ba43344c814 | 57 | |
| kishino | 2:0ba43344c814 | 58 | // Signal flags that are reported as event are automatically cleared. |
| kishino | 2:0ba43344c814 | 59 | osEvent event_ret = osSignalWait( UART_COMMAND_SIGNAL, UART_COMMAND_WAIT_TIMEOUT); |
| kishino | 2:0ba43344c814 | 60 | if( event_ret.status != osEventSignal ) |
| kishino | 2:0ba43344c814 | 61 | { |
| kishino | 2:0ba43344c814 | 62 | ret = -1; |
| kishino | 2:0ba43344c814 | 63 | } |
| kishino | 7:e88ccbe0225f | 64 | |
| kishino | 2:0ba43344c814 | 65 | return ret; |
| kishino | 2:0ba43344c814 | 66 | } |
| kishino | 2:0ba43344c814 | 67 | |
| kishino | 2:0ba43344c814 | 68 | int C_YDwifiUartCommand::signal() |
| kishino | 2:0ba43344c814 | 69 | { |
| kishino | 2:0ba43344c814 | 70 | // set signal |
| kishino | 7:e88ccbe0225f | 71 | return osSignalSet(mCommandThreadID, UART_COMMAND_SIGNAL); |
| kishino | 2:0ba43344c814 | 72 | } |
| kishino | 2:0ba43344c814 | 73 | |
| kishino | 2:0ba43344c814 | 74 | bool C_YDwifiUartCommand::isWaitingCommand( unsigned int command_id, unsigned char *payload_p ) |
| kishino | 2:0ba43344c814 | 75 | { |
| kishino | 2:0ba43344c814 | 76 | bool ret = false; |
| kishino | 2:0ba43344c814 | 77 | |
| kishino | 2:0ba43344c814 | 78 | if( (command_id == getCommandID()) |
| kishino | 2:0ba43344c814 | 79 | && (payload_p[0] == (getCommandSID() | 0x80) ) ) |
| kishino | 2:0ba43344c814 | 80 | { |
| kishino | 2:0ba43344c814 | 81 | ret = true; |
| kishino | 2:0ba43344c814 | 82 | } |
| kishino | 2:0ba43344c814 | 83 | return ret; |
| kishino | 2:0ba43344c814 | 84 | } |
| kishino | 2:0ba43344c814 | 85 | |
| kishino | 3:9f90024d7fb2 | 86 | void C_YDwifiUartCommand::scanResultIndicate( unsigned char *payload_p, int payload_len ) |
| kishino | 3:9f90024d7fb2 | 87 | { |
| kishino | 3:9f90024d7fb2 | 88 | if( (payload_p == NULL) || (mScanResultHandler_p == NULL) ) |
| kishino | 3:9f90024d7fb2 | 89 | { |
| kishino | 3:9f90024d7fb2 | 90 | return; |
| kishino | 3:9f90024d7fb2 | 91 | } |
| kishino | 3:9f90024d7fb2 | 92 | |
| kishino | 3:9f90024d7fb2 | 93 | tagSCAN_RESULT_T scan_result; |
| kishino | 7:e88ccbe0225f | 94 | int ap_count = payload_p[2]; |
| kishino | 7:e88ccbe0225f | 95 | |
| kishino | 7:e88ccbe0225f | 96 | if( ap_count == 0 ) |
| kishino | 7:e88ccbe0225f | 97 | { |
| kishino | 7:e88ccbe0225f | 98 | mScanResultHandler_p( NULL ); |
| kishino | 7:e88ccbe0225f | 99 | } |
| kishino | 7:e88ccbe0225f | 100 | |
| kishino | 3:9f90024d7fb2 | 101 | unsigned char *ap_info_p = &payload_p[3]; |
| kishino | 3:9f90024d7fb2 | 102 | int ap_info_idx = 0; |
| kishino | 7:e88ccbe0225f | 103 | |
| kishino | 3:9f90024d7fb2 | 104 | for( int i = 0; i < ap_count; i++ ) |
| kishino | 3:9f90024d7fb2 | 105 | { |
| kishino | 3:9f90024d7fb2 | 106 | scan_result.channel = ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 107 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 108 | scan_result.rssi = (signed)ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 109 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 110 | scan_result.security= ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 111 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 112 | memcpy( scan_result.bssid, &ap_info_p[ap_info_idx], BSSID_MAC_LENTH ); |
| kishino | 3:9f90024d7fb2 | 113 | ap_info_idx += BSSID_MAC_LENTH; |
| kishino | 3:9f90024d7fb2 | 114 | scan_result.network_type= ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 115 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 116 | scan_result.max_rate= ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 117 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 118 | ap_info_idx++; // reserved |
| kishino | 3:9f90024d7fb2 | 119 | strcpy( scan_result.ssid, (char *)&ap_info_p[ap_info_idx] ); |
| kishino | 3:9f90024d7fb2 | 120 | ap_info_idx += strlen( (char *)&ap_info_p[ap_info_idx] ); |
| kishino | 3:9f90024d7fb2 | 121 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 122 | |
| kishino | 3:9f90024d7fb2 | 123 | // Scanresult callback |
| kishino | 3:9f90024d7fb2 | 124 | mScanResultHandler_p( &scan_result ); |
| kishino | 3:9f90024d7fb2 | 125 | } |
| kishino | 3:9f90024d7fb2 | 126 | } |
