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@3:9f90024d7fb2, 2014-03-13 (annotated)
- Committer:
- kishino
- Date:
- Thu Mar 13 01:34:56 2014 +0000
- Revision:
- 3:9f90024d7fb2
- Parent:
- 2:0ba43344c814
- Child:
- 7:e88ccbe0225f
The following API was created.; =>Connect to AP.; =>Disconnect from AP.; =>Scan AP.
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 | 2:0ba43344c814 | 54 | // Get thread ID |
| kishino | 2:0ba43344c814 | 55 | mCommandThreadID = osThreadGetId(); |
| kishino | 2:0ba43344c814 | 56 | |
| kishino | 2:0ba43344c814 | 57 | // Signal flags that are reported as event are automatically cleared. |
| kishino | 2:0ba43344c814 | 58 | osEvent event_ret = osSignalWait( UART_COMMAND_SIGNAL, UART_COMMAND_WAIT_TIMEOUT); |
| kishino | 2:0ba43344c814 | 59 | if( event_ret.status != osEventSignal ) |
| kishino | 2:0ba43344c814 | 60 | { |
| kishino | 2:0ba43344c814 | 61 | ret = -1; |
| kishino | 2:0ba43344c814 | 62 | } |
| kishino | 2:0ba43344c814 | 63 | return ret; |
| kishino | 2:0ba43344c814 | 64 | } |
| kishino | 2:0ba43344c814 | 65 | |
| kishino | 2:0ba43344c814 | 66 | int C_YDwifiUartCommand::signal() |
| kishino | 2:0ba43344c814 | 67 | { |
| kishino | 2:0ba43344c814 | 68 | // set signal |
| kishino | 2:0ba43344c814 | 69 | return osSignalSet(mCommandThreadID, UART_COMMAND_SIGNAL);; |
| kishino | 2:0ba43344c814 | 70 | } |
| kishino | 2:0ba43344c814 | 71 | |
| kishino | 2:0ba43344c814 | 72 | bool C_YDwifiUartCommand::isWaitingCommand( unsigned int command_id, unsigned char *payload_p ) |
| kishino | 2:0ba43344c814 | 73 | { |
| kishino | 2:0ba43344c814 | 74 | bool ret = false; |
| kishino | 2:0ba43344c814 | 75 | |
| kishino | 2:0ba43344c814 | 76 | if( (command_id == getCommandID()) |
| kishino | 2:0ba43344c814 | 77 | && (payload_p[0] == (getCommandSID() | 0x80) ) ) |
| kishino | 2:0ba43344c814 | 78 | { |
| kishino | 2:0ba43344c814 | 79 | ret = true; |
| kishino | 2:0ba43344c814 | 80 | } |
| kishino | 2:0ba43344c814 | 81 | return ret; |
| kishino | 2:0ba43344c814 | 82 | } |
| kishino | 2:0ba43344c814 | 83 | |
| kishino | 3:9f90024d7fb2 | 84 | void C_YDwifiUartCommand::scanResultIndicate( unsigned char *payload_p, int payload_len ) |
| kishino | 3:9f90024d7fb2 | 85 | { |
| kishino | 3:9f90024d7fb2 | 86 | if( (payload_p == NULL) || (mScanResultHandler_p == NULL) ) |
| kishino | 3:9f90024d7fb2 | 87 | { |
| kishino | 3:9f90024d7fb2 | 88 | return; |
| kishino | 3:9f90024d7fb2 | 89 | } |
| kishino | 3:9f90024d7fb2 | 90 | |
| kishino | 3:9f90024d7fb2 | 91 | tagSCAN_RESULT_T scan_result; |
| kishino | 3:9f90024d7fb2 | 92 | int ap_count = payload_p[2]; |
| kishino | 3:9f90024d7fb2 | 93 | unsigned char *ap_info_p = &payload_p[3]; |
| kishino | 3:9f90024d7fb2 | 94 | int ap_info_idx = 0; |
| kishino | 3:9f90024d7fb2 | 95 | |
| kishino | 3:9f90024d7fb2 | 96 | printf("%d\r\n", ap_count); |
| kishino | 3:9f90024d7fb2 | 97 | for( int i = 0; i < ap_count; i++ ) |
| kishino | 3:9f90024d7fb2 | 98 | { |
| kishino | 3:9f90024d7fb2 | 99 | scan_result.channel = ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 100 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 101 | scan_result.rssi = (signed)ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 102 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 103 | scan_result.security= ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 104 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 105 | memcpy( scan_result.bssid, &ap_info_p[ap_info_idx], BSSID_MAC_LENTH ); |
| kishino | 3:9f90024d7fb2 | 106 | ap_info_idx += BSSID_MAC_LENTH; |
| kishino | 3:9f90024d7fb2 | 107 | scan_result.network_type= ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 108 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 109 | scan_result.max_rate= ap_info_p[ap_info_idx]; |
| kishino | 3:9f90024d7fb2 | 110 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 111 | ap_info_idx++; // reserved |
| kishino | 3:9f90024d7fb2 | 112 | strcpy( scan_result.ssid, (char *)&ap_info_p[ap_info_idx] ); |
| kishino | 3:9f90024d7fb2 | 113 | ap_info_idx += strlen( (char *)&ap_info_p[ap_info_idx] ); |
| kishino | 3:9f90024d7fb2 | 114 | ap_info_idx++; |
| kishino | 3:9f90024d7fb2 | 115 | |
| kishino | 3:9f90024d7fb2 | 116 | // Scanresult callback |
| kishino | 3:9f90024d7fb2 | 117 | mScanResultHandler_p( &scan_result ); |
| kishino | 3:9f90024d7fb2 | 118 | } |
| kishino | 3:9f90024d7fb2 | 119 | } |
