Murata RF modules are designed to simplify wireless development and certification by minimizing the amount of RF expertise you need to wirelessly enable a wide range of applications.
Revision 9:0ce800923eda, committed 2016-03-16
- Comitter:
- yangcq88517
- Date:
- Wed Mar 16 15:04:46 2016 +0000
- Parent:
- 8:5856c23794b1
- Commit message:
- bug fix
Changed in this revision
diff -r 5856c23794b1 -r 0ce800923eda Config/DHCPConfig.cpp --- a/Config/DHCPConfig.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Config/DHCPConfig.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -68,25 +68,25 @@ return *this; } -DHCPConfig & DHCPConfig::SetLocalIP(const char * ip) +DHCPConfig & DHCPConfig::SetLocalIP(char * ip) { this->ip = new IPAddress(ip); return *this; } -DHCPConfig & DHCPConfig::SetNetmask(const char * netmask) +DHCPConfig & DHCPConfig::SetNetmask(char * netmask) { mask = new IPAddress(netmask); return *this; } -DHCPConfig & DHCPConfig::SetGatewayIP(const char * gateway) +DHCPConfig & DHCPConfig::SetGatewayIP(char * gateway) { this->gateway = new IPAddress(gateway); return *this; } -DHCPConfig & DHCPConfig::SetIPRange(const char * first, const char * last) +DHCPConfig & DHCPConfig::SetIPRange(char * first, char * last) { this->first = new IPAddress(first); this->last = new IPAddress(last);
diff -r 5856c23794b1 -r 0ce800923eda Config/DHCPConfig.h --- a/Config/DHCPConfig.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Config/DHCPConfig.h Wed Mar 16 15:04:46 2016 +0000 @@ -49,13 +49,13 @@ DHCPConfig & SetDHCPMode(const DHCPMode mode); - DHCPConfig & SetLocalIP(const char * ip); + DHCPConfig & SetLocalIP(char * ip); - DHCPConfig & SetNetmask(const char * netmask); + DHCPConfig & SetNetmask(char * netmask); - DHCPConfig & SetGatewayIP(const char * gateway); + DHCPConfig & SetGatewayIP(char * gateway); - DHCPConfig & SetIPRange(const char * first, const char * last); + DHCPConfig & SetIPRange(char * first, char * last); }; }
diff -r 5856c23794b1 -r 0ce800923eda Config/SoftAPConfig.cpp --- a/Config/SoftAPConfig.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Config/SoftAPConfig.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -8,9 +8,9 @@ SetOnOffState(state); } -char SoftAPConfig::GetOnOffStatus() +SoftAPConfig::State SoftAPConfig::GetOnOffStatus() { - return onOff; + return state; } char SoftAPConfig::GetPersistency() @@ -20,7 +20,7 @@ SoftAPConfig * SoftAPConfig::SetOnOffState(const State onOff) { - this->onOff = onOff; + state = onOff; return this; }
diff -r 5856c23794b1 -r 0ce800923eda Config/SoftAPConfig.h --- a/Config/SoftAPConfig.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Config/SoftAPConfig.h Wed Mar 16 15:04:46 2016 +0000 @@ -5,32 +5,42 @@ namespace SmartLabMuRata { +/* +* OnOff = 0 indicates AP is to be turned off. The rest of the parameters are ignored. +* BSSID is not required +* !!! cannot be WEP and WIFI_SECURITY_WPA_AES_PSK !!! +*/ class SoftAPConfig : public WIFINetwork { public : enum State { - /// <summary> - /// indicates AP is to be turned off. The rest of the parameters are ignored. - /// </summary> + /** + * indicates AP is to be turned off. The rest of the parameters are ignored. + */ OFF = 0x00, - /// <summary> - /// indicates turning on soft AP using existing NVM parameters, - /// </summary> + /** + * indicates turning on soft AP using existing NVM parameters. + */ ON_NVM = 0x01, - /// <summary> - /// indicates turning on AP with the parameters provided. If the soft AP is already on, it is first turned off. - /// </summary> + /** + * indicates turning on AP with the parameters provided. If the soft AP is already on, it is first turned off. + */ ON_PARAMETERS = 0x02, }; - SoftAPConfig(State state, const char * SSID = "", const SecurityMode securityMode = WIFI_SECURITY_OPEN, const char * securityKey = NULL); + SoftAPConfig(State state, const char * SSID = NULL, const SecurityMode securityMode = WIFI_SECURITY_OPEN, const char * securityKey = NULL); - char GetOnOffStatus(); + State GetOnOffStatus(); char GetPersistency(); + /** + * OFF + * ON_NVM + * ON_PARAMETERS + */ SoftAPConfig * SetOnOffState(const State onOff); SoftAPConfig * SetPersistency(const bool persistency); @@ -41,46 +51,25 @@ virtual SoftAPConfig * SetSSID(const char * SSID); - /// <summary> - /// WIFI_SECURITY_OPEN - /// WIFI_SECURITY_WPA_TKIP_PSK - /// WIFI_SECURITY_WPA2_AES_PSK - /// WIFI_SECURITY_WPA2_MIXED_PSK - /// supported - /// </summary> - /// <param name="securityMode"></param> - /// <returns></returns> + /** + * Supported values : + * WIFI_SECURITY_OPEN + * WIFI_SECURITY_WPA_TKIP_PSK + * WIFI_SECURITY_WPA2_AES_PSK + * WIFI_SECURITY_WPA2_MIXED_PSK + */ virtual SoftAPConfig * SetSecurityMode(const SecurityMode securityMode); virtual SoftAPConfig * SetChannel(const char channel); - /* - * Parameters are as follows: - * UINT8 Request Sequence - * UINT8 Onoff - * UINT8 Persistency - * UINT8 SSID [up to 33] - * UINT8 Channel - * UINT8 Security mode - * UINT8 Security key length (0-64) - * … Security key [ ] - * OnOff = 0 indicates AP is to be turned off. The rest of the parameters are ignored. - * OnOff = 1 indicates turning on soft AP using existing NVM parameters, - * OnOff = 2 indicates turning on AP with the parameters provided. If the soft AP is already on, it is first turned off. - * Persistency=1 indicates the soft AP’s on/off state and parameters (if OnOff = 2) will be saved in NVM. For example, if OnOff =0 and Persistency=1, the soft AP will not be turned on after a reset. - */ private : - State onOff; - bool persistency; + State state; - /// <summary> - /// OnOff = 0 indicates AP is to be turned off. The rest of the parameters are ignored. - /// BSSID is not required - /// !!! cannot be WEP and WIFI_SECURITY_WPA_AES_PSK !!! - /// </summary> - /// <param name="SSID">only required when OnOff = 2, which is ON_PARAMETERS</param> - /// <param name="securityMode"></param> - /// <param name="securityKey"></param> + /** + * Persistency=1 indicates the soft AP’s on/off state and parameters (if OnOff = 2) will be saved in NVM. + * For example, if OnOff =0 and Persistency=1, the soft AP will not be turned on after a reset. + */ + bool persistency; }; }
diff -r 5856c23794b1 -r 0ce800923eda ErrorCode/CMDCode.h --- a/ErrorCode/CMDCode.h Mon Feb 15 15:17:50 2016 +0000 +++ b/ErrorCode/CMDCode.h Wed Mar 16 15:04:46 2016 +0000 @@ -3,9 +3,18 @@ namespace SmartLabMuRata { +/** +* General Management Response Code +*/ enum CMDCode { + + /// Response timeout due to no data avaliable GEN_NORESPONSE = -1, + + /// OK GEN_SUCCESS = 0x00, + + /// ERROR GEN_FAILED = 0x01, }; }
diff -r 5856c23794b1 -r 0ce800923eda ErrorCode/SNICCode.h --- a/ErrorCode/SNICCode.h Mon Feb 15 15:17:50 2016 +0000 +++ b/ErrorCode/SNICCode.h Wed Mar 16 15:04:46 2016 +0000 @@ -3,6 +3,7 @@ namespace SmartLabMuRata { +/// SNIC API Response Code enum SNICCode { SNIC_NORESPONSE = -1, SNIC_SUCCESS = 0x00,
diff -r 5856c23794b1 -r 0ce800923eda ErrorCode/WIFICode.h --- a/ErrorCode/WIFICode.h Mon Feb 15 15:17:50 2016 +0000 +++ b/ErrorCode/WIFICode.h Wed Mar 16 15:04:46 2016 +0000 @@ -3,6 +3,7 @@ namespace SmartLabMuRata { +/// WIFI API Response Code enum WIFICode { WIFI_NORESPONSE = -1, WIFI_SUCCESS = 0x00,
diff -r 5856c23794b1 -r 0ce800923eda Indication/HTTPResponseIndication.cpp --- a/Indication/HTTPResponseIndication.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Indication/HTTPResponseIndication.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -5,6 +5,9 @@ HTTPResponseIndication::HTTPResponseIndication(Payload * payload) : Payload(payload) { + if (payload == NULL) + return; + contentLength = (GetData()[2] & 0x7F) << 8 | GetData()[3]; GetData()[PAYLOAD_OFFSET + contentLength] = 0x00; }
diff -r 5856c23794b1 -r 0ce800923eda Indication/PowerUpIndication.cpp --- a/Indication/PowerUpIndication.cpp Mon Feb 15 15:17:50 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#include "PowerUpIndication.h" - -using namespace SmartLabMuRata; - -PowerUpIndication::PowerUpIndication(Payload * payload) - : Payload(payload) -{ } - -ResetCode PowerUpIndication::GetResetCode() -{ - return (ResetCode)(GetData()[2] << 8 | GetData()[3]); -} \ No newline at end of file
diff -r 5856c23794b1 -r 0ce800923eda Indication/PowerUpIndication.h --- a/Indication/PowerUpIndication.h Mon Feb 15 15:17:50 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -#ifndef SmartLab_MuRata_Indication_PowerUpIndication -#define SmartLab_MuRata_Indication_PowerUpIndication - -#include "Payload.h" -#include "ResetCode.h" - -namespace SmartLabMuRata -{ -class PowerUpIndication : public Payload -{ -public: - PowerUpIndication(Payload * payload); - - ResetCode GetResetCode(); -}; -} - -#endif \ No newline at end of file
diff -r 5856c23794b1 -r 0ce800923eda Indication/SSIDRecordIndication.cpp --- a/Indication/SSIDRecordIndication.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Indication/SSIDRecordIndication.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -11,21 +11,21 @@ return GetData()[2]; } -void SSIDRecordIndication::GetRecords(WIFINetworkDetail * list) +void SSIDRecordIndication::GetRecords(WIFINetworkDetail * details) { int count = GetNumberofRecords(); if (count <= 0) return; - + int index = 0; int _position = 3; const char * value = GetData(); while (index < count) { - - list[index].SetChannel(value[_position++]) + + (details + index)->SetChannel(value[_position++]) ->SetRSSI(value[_position++]) ->SetSecurityMode((SecurityMode)value[_position++]) ->SetBSSID(value + _position) @@ -33,8 +33,8 @@ ->SetMaxDataRate(value[_position++]) ->SetSSID(value + (_position += 2)); - _position+= strlen(list[index].GetSSID()) + 1; - + _position+= strlen((details + index)->GetSSID()) + 1; + index++; } } \ No newline at end of file
diff -r 5856c23794b1 -r 0ce800923eda Indication/SSIDRecordIndication.h --- a/Indication/SSIDRecordIndication.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Indication/SSIDRecordIndication.h Wed Mar 16 15:04:46 2016 +0000 @@ -7,13 +7,13 @@ namespace SmartLabMuRata { class SSIDRecordIndication : public Payload -{ +{ public: SSIDRecordIndication(Payload * payload); int GetNumberofRecords(); - void GetRecords(WIFINetworkDetail * list); + void GetRecords(WIFINetworkDetail * details); }; }
diff -r 5856c23794b1 -r 0ce800923eda Indication/SocketReceiveInidcation.cpp --- a/Indication/SocketReceiveInidcation.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Indication/SocketReceiveInidcation.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -5,6 +5,9 @@ SocketReceiveInidcation::SocketReceiveInidcation(Payload * payload) : Payload(payload) { + if (payload == NULL) + return; + receiveLength = GetData()[3] << 8 | GetData()[4]; }
diff -r 5856c23794b1 -r 0ce800923eda Indication/TCPStatusIndication.cpp --- a/Indication/TCPStatusIndication.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Indication/TCPStatusIndication.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -5,6 +5,9 @@ TCPStatusIndication::TCPStatusIndication(Payload * payload) : Payload(payload) { + if (payload == NULL) + return; + socketID = GetData()[3]; }
diff -r 5856c23794b1 -r 0ce800923eda Indication/UDPReceivedIndication.cpp --- a/Indication/UDPReceivedIndication.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Indication/UDPReceivedIndication.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -5,6 +5,9 @@ UDPReceivedIndication::UDPReceivedIndication(Payload * payload) : Payload(payload) { + if (payload == NULL) + return; + receiveLength = GetData()[9] << 8 | GetData()[10]; }
diff -r 5856c23794b1 -r 0ce800923eda Indication/WIFIConnectionIndication.cpp --- a/Indication/WIFIConnectionIndication.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Indication/WIFIConnectionIndication.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -16,7 +16,7 @@ return (WIFICode)GetData()[3]; } -string WIFIConnectionIndication::GetSSID() +const char * WIFIConnectionIndication::GetSSID() { - return string(GetData() + 4); + return GetData() + 4; } \ No newline at end of file
diff -r 5856c23794b1 -r 0ce800923eda Indication/WIFIConnectionIndication.h --- a/Indication/WIFIConnectionIndication.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Indication/WIFIConnectionIndication.h Wed Mar 16 15:04:46 2016 +0000 @@ -4,7 +4,6 @@ #include "Payload.h" #include "WIFIInterface.h" #include "WIFICode.h" -#include <string> using namespace std; @@ -19,7 +18,7 @@ WIFICode GetStatus(); - string GetSSID(); + const char * GetSSID(); }; }
diff -r 5856c23794b1 -r 0ce800923eda MuRata.cpp --- a/MuRata.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/MuRata.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -3,6 +3,9 @@ using namespace SmartLabMuRata; MuRata::MuRata(PinName tx, PinName rx) + : _SSIDRecordIndication(NULL),_WIFIConnectionIndication(NULL),_TCPStatusIndication(NULL),_SocketReceiveInidcation(NULL), + _UDPReceivedIndication(NULL),_HTTPResponseIndication(NULL), + _WIFIStatusResponse(NULL),_InitializationResponse(NULL),_SendFromSocketResponse(NULL),_DHCPInfoResponse(NULL),_SocketStartReceiveResponse(NULL),_CreateSocketResponse(NULL),_HTTPResponse(NULL) { serial = new Serial(tx,rx); serial->format(); @@ -10,10 +13,13 @@ } MuRata::MuRata(PinName tx, PinName rx, int baudrate ,int bits, Serial::Parity parity, int stop_bits) + : _SSIDRecordIndication(NULL),_WIFIConnectionIndication(NULL),_TCPStatusIndication(NULL),_SocketReceiveInidcation(NULL), + _UDPReceivedIndication(NULL),_HTTPResponseIndication(NULL), + _WIFIStatusResponse(NULL),_InitializationResponse(NULL),_SendFromSocketResponse(NULL),_DHCPInfoResponse(NULL),_SocketStartReceiveResponse(NULL),_CreateSocketResponse(NULL),_HTTPResponse(NULL) { serial = new Serial(tx,rx); serial->format(bits, parity, stop_bits); - serial->baud(baudrate ); + serial->baud(baudrate); } SSIDRecordIndication * MuRata::Get_ScanResultIndication() @@ -21,8 +27,10 @@ if (FrameReceive()) if (_payload.GetResponseFlag() == Request_Indication && _frame.GetCommandID() == CMD_ID_WIFI - && _payload.GetSubCommandID() == WIFI_SCAN_RESULT_IND) - return new SSIDRecordIndication(&_payload); + && _payload.GetSubCommandID() == WIFI_SCAN_RESULT_IND) { + _SSIDRecordIndication.SetPayload(&_payload); + return &_SSIDRecordIndication; + } return NULL; } @@ -32,21 +40,23 @@ if (FrameReceive()) if (_payload.GetResponseFlag() == Request_Indication && _frame.GetCommandID() == CMD_ID_WIFI - && _payload.GetSubCommandID() == WIFI_NETWORK_STATUS_IND) - return new WIFIConnectionIndication(&_payload); + && _payload.GetSubCommandID() == WIFI_NETWORK_STATUS_IND) { + _WIFIConnectionIndication.SetPayload(&_payload); + return &_WIFIConnectionIndication; + } return NULL; } -PowerUpIndication * MuRata::Get_PowerUpIndication() +ResetCode MuRata::Get_PowerUpIndication() { if (FrameReceive()) if (_payload.GetResponseFlag() == Request_Indication && _frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_PWR_UP_IND) - return new PowerUpIndication(&_payload); + return (ResetCode)(_payload.GetData()[2] << 8 | _payload.GetData()[3]); - return NULL; + return N0_Indication; } TCPStatusIndication * MuRata::Get_TcpConnectionStatusIndication() @@ -54,8 +64,10 @@ if (FrameReceive()) if (_payload.GetResponseFlag() == Request_Indication && _frame.GetCommandID() == CMD_ID_SNIC - && _payload.GetSubCommandID() == SNIC_TCP_CONNECTION_STATUS_IND) - return new TCPStatusIndication(&_payload); + && _payload.GetSubCommandID() == SNIC_TCP_CONNECTION_STATUS_IND) { + _TCPStatusIndication.SetPayload(&_payload); + return &_TCPStatusIndication; + } return NULL; } @@ -65,8 +77,10 @@ if (FrameReceive()) if (_payload.GetResponseFlag() == Request_Indication && _frame.GetCommandID() == CMD_ID_SNIC - && _payload.GetSubCommandID() == SNIC_CONNECTION_RECV_IND) - return new SocketReceiveInidcation(&_payload); + && _payload.GetSubCommandID() == SNIC_CONNECTION_RECV_IND) { + _SocketReceiveInidcation.SetPayload(&_payload); + return &_SocketReceiveInidcation; + } return NULL; } @@ -76,8 +90,10 @@ if (FrameReceive()) if (_payload.GetResponseFlag() == Request_Indication && _frame.GetCommandID() == CMD_ID_SNIC - && _payload.GetSubCommandID() == SNIC_UDP_RECV_IND) - return new UDPReceivedIndication(&_payload); + && _payload.GetSubCommandID() == SNIC_UDP_RECV_IND) { + _UDPReceivedIndication.SetPayload(&_payload); + return &_UDPReceivedIndication; + } return NULL; } @@ -87,8 +103,10 @@ if (FrameReceive()) if (_payload.GetResponseFlag() == Request_Indication && _frame.GetCommandID() == CMD_ID_SNIC - && _payload.GetSubCommandID() == SNIC_HTTP_RSP_IND) - return new HTTPResponseIndication(&_payload); + && _payload.GetSubCommandID() == SNIC_HTTP_RSP_IND) { + _HTTPResponseIndication.SetPayload(&_payload); + return &_HTTPResponseIndication; + } return NULL; } @@ -116,20 +134,16 @@ { timer.reset(); timer.start(); - - while (serial->readable() <= 0) - { - if (timer.read_ms() > 1000) - { + + while (serial->readable() <= 0) { + if (timer.read_ms() > 1000) { timer.stop(); return false; } } - timer.stop(); - + int value = serial->getc(); - while (value != UARTFrame::SOM) value = serial->getc(); @@ -151,7 +165,7 @@ else return false; } -VersionInfoResponse * MuRata::GEN_GetFirmwareVersionInfo() +const char * MuRata::GEN_GetFirmwareVersionInfo() { _payload.Rewind(); _payload.SetSubCommandID(GEN_FW_VER_GET_REQ); @@ -162,10 +176,15 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_FW_VER_GET_REQ) - return new VersionInfoResponse(&_payload); - + while (FrameReceive()) { + if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_FW_VER_GET_REQ) { + if (_payload.GetData()[2] == GEN_SUCCESS) { + // set the null for the string + _payload.GetData()[4 + _payload.GetData()[3]] = 0x00; + return _payload.GetData() + 4; + } + } + } return NULL; } @@ -180,7 +199,7 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_RESTORE_REQ) return (CMDCode)_payload.GetData()[2]; @@ -198,26 +217,26 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_RESET_REQ) return (CMDCode)_payload.GetData()[2]; return GEN_NORESPONSE; } -CMDCode MuRata::GEN_UARTConfiguration(UARTConfig & config) +CMDCode MuRata::GEN_UARTConfiguration(UARTConfig * config) { _payload.Rewind(); _payload.SetSubCommandID(GEN_UART_CFG_REQ); _payload.SetFrameID(_payload.GetFrameID() + 1); - _payload.SetContent(config.GetValue(), 0, 6); + _payload.SetContent(config->GetValue(), 0, 6); _frame.SetCommandID(CMD_ID_GEN); _frame.SetPayload(&_payload); Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_UART_CFG_REQ) return (CMDCode)_payload.GetData()[2]; @@ -241,7 +260,7 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_ON_REQ) return (WIFICode)_payload.GetData()[2]; @@ -259,13 +278,28 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_OFF_REQ) return (WIFICode)_payload.GetData()[2]; return WIFI_NORESPONSE; } +/* + * Parameters are as follows: + * UINT8 Request Sequence + * UINT8 Onoff + * UINT8 Persistency + * UINT8 SSID [up to 33] + * UINT8 Channel + * UINT8 Security mode + * UINT8 Security key length (0-64) + * … Security key [ ] + * OnOff = 0 indicates AP is to be turned off. The rest of the parameters are ignored. + * OnOff = 1 indicates turning on soft AP using existing NVM parameters, + * OnOff = 2 indicates turning on AP with the parameters provided. If the soft AP is already on, it is first turned off. + * Persistency=1 indicates the soft AP’s on/off state and parameters (if OnOff = 2) will be saved in NVM. For example, if OnOff =0 and Persistency=1, the soft AP will not be turned on after a reset. + */ WIFICode MuRata::WIFI_SoftAPControl(SoftAPConfig * config) { _payload.Rewind(); @@ -274,25 +308,30 @@ _payload.SetContent(config->GetOnOffStatus()); _payload.SetContent(config->GetPersistency()); - if (config->GetOnOffStatus() == 0x02) { - int length = strlen(config->GetSSID()); - _payload.SetContent(config->GetSSID(), 0 , length); + if (config->GetOnOffStatus() == SoftAPConfig::ON_PARAMETERS) { + const char * ssid = config->GetSSID(); + int length = strlen(ssid); + _payload.SetContent(ssid, 0 , length); _payload.SetContent(0x00); } _payload.SetContent(config->GetChannel()); _payload.SetContent(config->GetSecurityMode()); - int keyLength = strlen(config->GetSecurityKey()); + const char * key = config->GetSecurityKey(); + int keyLength = 0; + if (key != NULL) + keyLength = strlen(key); + _payload.SetContent(keyLength); if (config->GetSecurityMode() != WIFI_SECURITY_OPEN && keyLength > 0) - _payload.SetContent(config->GetSecurityKey(), 0 , keyLength); + _payload.SetContent(key, 0 , keyLength); _frame.SetCommandID(CMD_ID_WIFI); _frame.SetPayload(&_payload); Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_AP_CTRL_REQ) return (WIFICode)_payload.GetData()[2]; @@ -324,7 +363,7 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_JOIN_REQ) return (WIFICode)_payload.GetData()[2]; @@ -342,7 +381,7 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_DISCONNECT_REQ) return (WIFICode)_payload.GetData()[2]; @@ -360,14 +399,16 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_GET_STATUS_REQ) - return new WIFIStatusResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_GET_STATUS_REQ) { + _WIFIStatusResponse.SetPayload(&_payload); + return &_WIFIStatusResponse; + } return NULL; } -int MuRata::WIFI_GetRSSI() +int8_t MuRata::WIFI_GetRSSI() { _payload.Rewind(); _payload.SetSubCommandID(WIFI_GET_STA_RSSI_REQ); @@ -378,15 +419,9 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_GET_STA_RSSI_REQ) { - char value = _payload.GetData()[2]; - - if (value >> 7 == 0x01) - return (~(_payload.GetData()[2] - 1) & 0x7F) * -1; - - return value; - } + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_GET_STA_RSSI_REQ) + return _payload.GetData()[2]; return 127; } @@ -411,7 +446,7 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_WPS_REQ) return (WIFICode)_payload.GetData()[2]; @@ -470,9 +505,11 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_INIT_REQ) - return new InitializationResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_INIT_REQ) { + _InitializationResponse.SetPayload(&_payload); + return &_InitializationResponse; + } return NULL; } @@ -488,7 +525,7 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_CLEANUP_REQ) return (SNICCode)_payload.GetData()[2]; @@ -513,9 +550,11 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_SEND_FROM_SOCKET_REQ) - return new SendFromSocketResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_SEND_FROM_SOCKET_REQ) { + _SendFromSocketResponse.SetPayload(&_payload); + return &_SendFromSocketResponse; + } return NULL; } @@ -532,7 +571,7 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_CLOSE_SOCKET_REQ) return (SNICCode)_payload.GetData()[2]; @@ -551,14 +590,16 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_GET_DHCP_INFO_REQ) - return new DHCPInfoResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_GET_DHCP_INFO_REQ) { + _DHCPInfoResponse.SetPayload(&_payload); + return &_DHCPInfoResponse; + } return NULL; } -bool MuRata::SNIC_ResolveHostName(const char * host, IPAddress * ip) +IPAddress * MuRata::SNIC_ResolveHostName(const char * host) { int hostLength = strlen(host); @@ -574,14 +615,14 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_RESOLVE_NAME_REQ) if ((SNICCode)_payload.GetData()[2] == SNIC_SUCCESS) { - ip->SetValue(_payload.GetData(), 3); - return true; + ip.SetValue(_payload.GetData(), 3); + return &ip; } - return false; + return NULL; } SNICCode MuRata::SNIC_ConfigureDHCPorStaticIP(DHCPConfig * config) @@ -608,7 +649,7 @@ Send(); - if (FrameReceive()) + while (FrameReceive()) if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_IP_CONFIG_REQ) return (SNICCode)_payload.GetData()[2]; @@ -633,9 +674,11 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_TCP_CONNECT_TO_SERVER_REQ) - return new SocketStartReceiveResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_TCP_CONNECT_TO_SERVER_REQ) { + _SocketStartReceiveResponse.SetPayload(&_payload); + return &_SocketStartReceiveResponse; + } return NULL; } @@ -676,9 +719,11 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == subID) - return new CreateSocketResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == subID) { + _CreateSocketResponse.SetPayload(&_payload); + return &_CreateSocketResponse; + } return NULL; } @@ -697,9 +742,11 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_START_RECV_REQ) - return new SocketStartReceiveResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_START_RECV_REQ) { + _SocketStartReceiveResponse.SetPayload(&_payload); + return &_SocketStartReceiveResponse; + } return NULL; } @@ -721,9 +768,11 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_SIMPLE_SEND_REQ) - return new SendFromSocketResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_SIMPLE_SEND_REQ) { + _SendFromSocketResponse.SetPayload(&_payload); + return &_SendFromSocketResponse; + } return NULL; } @@ -747,9 +796,11 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_SEND_FROM_SOCKET_REQ) - return new SendFromSocketResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_SEND_FROM_SOCKET_REQ) { + _SendFromSocketResponse.SetPayload(&_payload); + return &_SendFromSocketResponse; + } return NULL; } @@ -780,7 +831,7 @@ _payload.SetContent(_others.c_str(), 0, _others.length()); _payload.SetContent(0x00); - if (content->GetMethod() == POST) { + while (content->GetMethod() == POST) { int length = content->GetContentLength(); char msb = length >> 8; @@ -800,9 +851,11 @@ Send(); - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == _id) - return new HTTPResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == _id) { + _HTTPResponse.SetPayload(&_payload); + return &_HTTPResponse; + } return NULL; } @@ -833,9 +886,11 @@ if (chunked) return NULL; - if (FrameReceive()) - if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_HTTP_MORE_REQ) - return new HTTPResponse(&_payload); + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_HTTP_MORE_REQ) { + _HTTPResponse.SetPayload(&_payload); + return &_HTTPResponse; + } return NULL; }
diff -r 5856c23794b1 -r 0ce800923eda MuRata.h --- a/MuRata.h Mon Feb 15 15:17:50 2016 +0000 +++ b/MuRata.h Wed Mar 16 15:04:46 2016 +0000 @@ -29,7 +29,6 @@ #include "WIFIStatusCode.h" #include "WPSMode.h" -#include "PowerUpIndication.h" #include "SSIDRecordIndication.h" #include "TCPStatusIndication.h" #include "SocketReceiveInidcation.h" @@ -37,7 +36,6 @@ #include "WIFIConnectionIndication.h" #include "HTTPResponseIndication.h" -#include "VersionInfoResponse.h" #include "WIFIStatusResponse.h" #include "InitializationResponse.h" #include "SendFromSocketResponse.h" @@ -53,6 +51,23 @@ class MuRata { private : + SSIDRecordIndication _SSIDRecordIndication; + WIFIConnectionIndication _WIFIConnectionIndication; + TCPStatusIndication _TCPStatusIndication; + SocketReceiveInidcation _SocketReceiveInidcation; + UDPReceivedIndication _UDPReceivedIndication; + HTTPResponseIndication _HTTPResponseIndication; + + WIFIStatusResponse _WIFIStatusResponse; + InitializationResponse _InitializationResponse; + SendFromSocketResponse _SendFromSocketResponse; + DHCPInfoResponse _DHCPInfoResponse; + SocketStartReceiveResponse _SocketStartReceiveResponse; + CreateSocketResponse _CreateSocketResponse; + HTTPResponse _HTTPResponse; + + IPAddress ip; + Serial * serial; Payload _payload; UARTFrame _frame; @@ -62,8 +77,8 @@ bool FrameReceive(); CreateSocketResponse * SNIC_CreateSocket(const SubCommandID subID, const bool bind = false, IPAddress * localIP = NULL, const int localPort = 0); - - /// Time out when is no data received + + /// Time out when there is no data received Timer timer; public: @@ -78,22 +93,40 @@ WIFIConnectionIndication * Get_WiFiStatusIndication(); - PowerUpIndication * Get_PowerUpIndication(); - + /** + * This event reports the Murata module power up reason. Murata module is ready for serial communication after this report is generated. + * @return N0_Indication when no response is received. + */ + ResetCode Get_PowerUpIndication(); + TCPStatusIndication * Get_TcpConnectionStatusIndication(); - + SocketReceiveInidcation * Get_SocketReceiveIndication(); - + UDPReceivedIndication * Get_UDPReceiveIndication(); - + HTTPResponseIndication * Get_HTTPResponseIndication(); // ############################################################################## // constructor // ############################################################################## + /** + * Constructor + * @param tx mbed pin name for UART + * @param rx mbed pin name for UART + */ MuRata(PinName tx, PinName rx); + /** + * Constructor + * @param tx mbed pin name for UART + * @param rx mbed pin name for UART + * @param baudrate serial baud rate + * @param bits + * @param parity + * @param stop_bits + */ MuRata(PinName tx, PinName rx, int baudrate ,int bits=8, Serial::Parity parity=SerialBase::None, int stop_bits=1); @@ -101,289 +134,248 @@ // GEN // ############################################################################## - /// <summary> - /// SNIC firmware has a built in version string. Use this command to retrieve the version info. - /// </summary> - /// <returns>return null when timeout</returns> - VersionInfoResponse * GEN_GetFirmwareVersionInfo(); + /** + * SNIC firmware has a built in version string. Use this command to retrieve the version info. + * @returns return null when timeout + */ + const char * GEN_GetFirmwareVersionInfo(); - /// <summary> - /// This command restores the data stored in NVM to factory default values. Any web page update is not affected by this command. - /// A soft reset will be performed automatically after the NVM has been restored. - /// Application needs to send WIFI_GET_STATUS_REQ or SNIC_GET_DHCP_INFO_REQ commands to determine the new state of the Murata module. - /// </summary> - /// <returns></returns> + /** + * This command restores the data stored in NVM to factory default values. Any web page update is not affected by this command. + * A soft reset will be performed automatically after the NVM has been restored. + * Application needs to send WIFI_GET_STATUS_REQ or SNIC_GET_DHCP_INFO_REQ commands to determine the new state of the Murata module. + */ CMDCode GEN_RestoreNVMtoFactoryDefault(); - /// <summary> - /// This command resets the module. Application needs to send WIFI_GET_STATUS_REQ or SNIC_GET_DHCP_INFO_REQ commands to determine the new state of the module after the reset. - /// </summary> - /// <returns></returns> + /** + * This command resets the module. Application needs to send WIFI_GET_STATUS_REQ or SNIC_GET_DHCP_INFO_REQ commands to determine the new state of the module after the reset. + */ CMDCode GEN_SoftReset(); - /// <summary> - /// This command configures the UART interface. The specified parameters are saved into the NVM and they are used for the specified UART interface in subsequent powerups. - /// </summary> - /// <param name="config"></param> - /// <returns></returns> - CMDCode GEN_UARTConfiguration(UARTConfig & config); + /** + * This command configures the UART interface. The specified parameters are saved into the NVM and they are used for the specified UART interface in subsequent powerups. + */ + CMDCode GEN_UARTConfiguration(UARTConfig * config); // ############################################################################## // WiFi // ############################################################################## - /// <summary> - /// This command turns on Wifi on module. - /// The default country code is “US”, which is one of the startup parameters in NVM. If the WIFI_ON_REQ has no intention of changing the country code, put 0x0000 in the two-byte Country code, so that the firmware will use the country code configured in NVM. - /// The module supports both soft AP mode and STA mode at the same time. The module has reserved flash space (NVM) to store startup parameters for both the soft AP and the STA. Only STA’s parameters can be dynamically changed at run time. - /// Turning on WiFi would cause the following to happen: - /// The following operations occur using the parameters specified in the NVM if the AP mode is enabled. - /// 1. Turn on the soft AP - /// 2. Starts DNS server, DHCP server and HTTP server. The HTTP server provides a means for configuring the WLAN access parameters for the STA. - /// Turn on the STA. If the NVM has valid startup parameters, the STA will try to join the saved SSID with saved authentication information. The NVM also stores whether DHCP or static IP is used for STA. If DHCP is used, DHCP client will be started. After a successful join, STA’s IP will be configured according to the NVM. - /// By default, the soft AP is turned on to allow user to use a WiFi enabled computer to connect to the soft AP, and instructs the STA to join one of the surrounding APs. So WiFi is turned on by default and this command is not required at startup. - /// </summary> - /// <returns></returns> + /** + * This command turns on Wifi on module. + * The default country code is “US”, which is one of the startup parameters in NVM. If the WIFI_ON_REQ has no intention of changing the country code, put 0x0000 in the two-byte Country code, so that the firmware will use the country code configured in NVM. + * The module supports both soft AP mode and STA mode at the same time. The module has reserved flash space (NVM) to store startup parameters for both the soft AP and the STA. Only STA’s parameters can be dynamically changed at run time. + * Turning on WiFi would cause the following to happen: + * The following operations occur using the parameters specified in the NVM if the AP mode is enabled. + * 1. Turn on the soft AP + * 2. Starts DNS server, DHCP server and HTTP server. The HTTP server provides a means for configuring the WLAN access parameters for the STA. + * Turn on the STA. If the NVM has valid startup parameters, the STA will try to join the saved SSID with saved authentication information. The NVM also stores whether DHCP or static IP is used for STA. If DHCP is used, DHCP client will be started. After a successful join, STA’s IP will be configured according to the NVM. + * By default, the soft AP is turned on to allow user to use a WiFi enabled computer to connect to the soft AP, and instructs the STA to join one of the surrounding APs. So WiFi is turned on by default and this command is not required at startup. + */ WIFICode WIFI_TurnOn(); - /// <summary> - /// This command turns off Wifi on module. Turning off WiFi causes the following to happen: - /// 1. Turn off the soft AP, including shutting down DNS server, DHCP server and HTTP server. - /// 2. Disconnect STA from any joined network, and close all sockets opened by application. - /// </summary> - /// <returns></returns> + /** + * This command turns off Wifi on module. Turning off WiFi causes the following to happen: + * 1. Turn off the soft AP, including shutting down DNS server, DHCP server and HTTP server. + * 2. Disconnect STA from any joined network, and close all sockets opened by application. + */ WIFICode WIFI_TurnOff(); - /// <summary> - /// This command turns on or off the soft AP. The WIFI_ON(OFF)_REQ controls both the soft AP and STA at the same time, while this command only controls the soft AP. - /// An example use case is, the soft AP (and its web server) is turned on at startup to configure STA to join a network and is no longer needed after the STA is connected. - /// WIFI_AP_CTRL_REQ can be used to turn the soft AP off. - /// OnOff = 0 indicates AP is to be turned off. The rest of the parameters are ignored. - /// OnOff = 1 indicates turning on soft AP using existing NVM parameters, - /// OnOff = 2 indicates turning on AP with the parameters provided. If the soft AP is already on, it is first turned off. - /// Persistency=1 indicates the soft AP’s on/off state and parameters (if OnOff = 2) will be saved in NVM. For example, if OnOff =0 and Persistency=1, the soft AP will not be turned on after a reset. - /// </summary> - /// <param name="config"></param> - /// <returns></returns> + /** + * This command turns on or off the soft AP. The WIFI_ON(OFF)_REQ controls both the soft AP and STA at the same time, while this command only controls the soft AP. + * An example use case is, the soft AP (and its web server) is turned on at startup to configure STA to join a network and is no longer needed after the STA is connected. + * WIFI_AP_CTRL_REQ can be used to turn the soft AP off. + * OnOff = 0 indicates AP is to be turned off. The rest of the parameters are ignored. + * OnOff = 1 indicates turning on soft AP using existing NVM parameters, + * OnOff = 2 indicates turning on AP with the parameters provided. If the soft AP is already on, it is first turned off. + * Persistency=1 indicates the soft AP’s on/off state and parameters (if OnOff = 2) will be saved in NVM. For example, if OnOff =0 and Persistency=1, the soft AP will not be turned on after a reset. + */ WIFICode WIFI_SoftAPControl(SoftAPConfig * config); - /// <summary> - /// This command instructs module to associate to a network. - /// </summary> - /// <param name="AP"></param> - /// <returns></returns> + /** + * This command instructs module to associate to a network. + */ WIFICode WIFI_AssociateNetwork(WIFINetwork * AP); - /// <summary> - /// This command instructs the module to disconnect from a network. - /// Upon a successful reception of the command, the module disconnects from associated network. Sockets opened by application are not closed. - /// </summary> - /// <returns></returns> + /** + * This command instructs the module to disconnect from a network. + * Upon a successful reception of the command, the module disconnects from associated network. Sockets opened by application are not closed. + */ WIFICode WIFI_DisconnectNetwork(); - /// <summary> - /// This command queries the WiFi status from module. This command should be called by application after startup to determine the WiFi status since the module may have joined an AP automatically based on NVM parameters (see 6.1). - /// </summary> - /// <param name="WiFiInterface"></param> - /// <returns></returns> + /** + * This command queries the WiFi status from module. This command should be called by application after startup to determine the WiFi status since the module may have joined an AP automatically based on NVM parameters (see 6.1). + * </summary> + */ WIFIStatusResponse * WIFI_GetStatus(const WIFIInterface WiFiInterface); - /// <summary> - /// This command requests the reporting of the current RSSI from module’s STA interface - /// </summary> - /// <returns>RSSI in dBm. 127 means unspecified value</returns> - int WIFI_GetRSSI(); + /** + * This command requests the reporting of the current RSSI from module’s STA interface + * @returns RSSI in dBm. 127 means unspecified value + */ + int8_t WIFI_GetRSSI(); - /// <summary> - /// This command requests the module to use WPS to join the network. Two methods are supported: push button and pin-based configuration. - /// If Mode is 1, Pin value must be present. Pin value is NUL terminated ASCII string. Pin string length of 0, 4, 7, or 8 is valid. When length is 0, the module will use the WPS default pin configured in the NVM by using the SNIC monitor. When length is 8, the 8th digit must be the correct checksum of the first 7 digits. The pin checksum calculation method can be found from the Internet. When the length is 7, the module firmware will calculate the checksum automatically. When the length is 4, no checksum is required. - /// Upon a successful reception of the command, the module tries to associate to a network using the WPS configuration specified. Upon a successful completion of the join process, the SSID and authentication parameters will be saved in NVM which will be used in subsequent power up (see 6.1). - /// </summary> - /// <param name="mode"></param> - /// <param name="Pin"></param> - /// <returns></returns> + /** + * This command requests the module to use WPS to join the network. Two methods are supported: push button and pin-based configuration. + * If Mode is 1, Pin value must be present. Pin value is NUL terminated ASCII string. Pin string length of 0, 4, 7, or 8 is valid. When length is 0, the module will use the WPS default pin configured in the NVM by using the SNIC monitor. When length is 8, the 8th digit must be the correct checksum of the first 7 digits. The pin checksum calculation method can be found from the Internet. When the length is 7, the module firmware will calculate the checksum automatically. When the length is 4, no checksum is required. + * Upon a successful reception of the command, the module tries to associate to a network using the WPS configuration specified. Upon a successful completion of the join process, the SSID and authentication parameters will be saved in NVM which will be used in subsequent power up (see 6.1). + */ WIFICode WIFI_StartWPSProcess(const WPSMode mode, const char * pin = NULL, int pinLength = 0); - /// <summary> - /// Upon a successful reception of the command, the module starts to scan. The response will indicate only WIFI_SUCCESS if no error. Actual scan result shall be sent from module as multiple indications defined in WIFI_SCAN_RESULT_IND - /// </summary> - /// <param name="scan"></param> - /// <param name="bss"></param> - /// <param name="BSSID">6 bytes MAC address of the AP or STA.</param> - /// <param name="channelList">up to 10 array elements</param> - /// <param name="SSID">string for the AP or STA SSID, up to 32 bytes</param> - /// <returns></returns> + /** + * Upon a successful reception of the command, the module starts to scan. The response will indicate only WIFI_SUCCESS if no error. Actual scan result shall be sent from module as multiple indications defined in WIFI_SCAN_RESULT_IND + * </summary> + * @param scan + * @param bss + * @param BSSID 6 bytes MAC address of the AP or STA + * @param channelList up to 10 array elements + * @param SSID string for the AP or STA SSID, up to 32 bytes + */ WIFICode WIFI_ScanNetworks(const ScanType scan, const BSSType bss); // ############################################################################## // SNIC // ############################################################################## - /// <summary> - /// This command initializes the SNIC networking framework on module. TCP/UDP socket communication may be performed only after this command is called. - /// The Default receive buffer size is the default maximum size of receive buffer in the module. If 0 is specified, a system defined value (2048) will be used. If there is a Receive buffer size field in other commands, then it must be less than or equal to the Default receive buffer size. If the Receive buffer size in any of those commands is 0, the Default receive buffer size will be used. - /// </summary> - /// <param name="receiveBufferSize">Upon a successful reception of the command, the module sends to the host the following response. If user specified Default receive buffer size is bigger than what the module can handle, the system defined value will be returned in the response; otherwise, user specified Default receive buffer size will be retuned. Maximum number of UDP and TCP sockets supported by module will also be returned.</param> - /// <returns></returns> + /** + * This command initializes the SNIC networking framework on module. TCP/UDP socket communication may be performed only after this command is called. + * The Default receive buffer size is the default maximum size of receive buffer in the module. If 0 is specified, a system defined value (2048) will be used. If there is a Receive buffer size field in other commands, then it must be less than or equal to the Default receive buffer size. If the Receive buffer size in any of those commands is 0, the Default receive buffer size will be used. + * @param receiveBufferSize Upon a successful reception of the command, the module sends to the host the following response. If user specified Default receive buffer size is bigger than what the module can handle, the system defined value will be returned in the response; otherwise, user specified Default receive buffer size will be retuned. Maximum number of UDP and TCP sockets supported by module will also be returned. + */ InitializationResponse * SNIC_Initialization(int receiveBufferSize = 0); - /// <summary> - /// This command closes the SNIC networking framework on module. It should cleanup resources for socket communication on module. If some sockets are not closed, this command will close all of them. No more network communication can be performed until SNIC_INIT_REQ is called. - /// </summary> - /// <returns></returns> + /** + * This command closes the SNIC networking framework on module. It should cleanup resources for socket communication on module. If some sockets are not closed, this command will close all of them. No more network communication can be performed until SNIC_INIT_REQ is called. + */ SNICCode SNIC_Cleanup(); - /// <summary> - /// In TCP server case, Socket is the socket number returned by SNIC_TCP_CLIENT_SOCKET_IND. In TCP client case, Socket can be either from SNIC_CONNECT_TO_TCP_SERVER_RSP, or from the SNIC_TCP_CONNECTION_STATUS_IND with SNIC_CONNECTION_UP status. In UDP case, Socket is the socket number returned by SNIC_UDP_CREATE_SOCKET_REQ and it must be in connected mode. - /// A success response of this command does not guarantee the receiver receives the packet. If error occurs, a SNIC_TCP_CONNECTION_STATUS_IND with SNIC_SOCKET_CLOSED will be sent to the application in TCP case. No indication will be sent in UDP case. - /// Option is the action module will perform to the socket after the send operation. Use it when application is sure to close or shutdown the connection after sending. The effect is the same as using SNIC_CLOSE_SOCKET_REQ, but round-trip UART traffic is reduced. - /// </summary> - /// <param name="SocketID"></param> - /// <param name="option"></param> - /// <returns></returns> + /** + * In TCP server case, Socket is the socket number returned by SNIC_TCP_CLIENT_SOCKET_IND. In TCP client case, Socket can be either from SNIC_CONNECT_TO_TCP_SERVER_RSP, or from the SNIC_TCP_CONNECTION_STATUS_IND with SNIC_CONNECTION_UP status. In UDP case, Socket is the socket number returned by SNIC_UDP_CREATE_SOCKET_REQ and it must be in connected mode. + * A success response of this command does not guarantee the receiver receives the packet. If error occurs, a SNIC_TCP_CONNECTION_STATUS_IND with SNIC_SOCKET_CLOSED will be sent to the application in TCP case. No indication will be sent in UDP case. + * Option is the action module will perform to the socket after the send operation. Use it when application is sure to close or shutdown the connection after sending. The effect is the same as using SNIC_CLOSE_SOCKET_REQ, but round-trip UART traffic is reduced. + */ SendFromSocketResponse * SNIC_SendFromSocket(const char SocketID, const SocketSentOption option, const char * payload, int offset, int length); - /// <summary> - /// This command instructs the module to close a socket. - /// </summary> - /// <param name="SocketID"></param> - /// <returns></returns> + /** + * This command instructs the module to close a socket. + */ SNICCode SNIC_SloseSocket(const char SocketID); - /// <summary> - /// This command queries the DHCP information for a particular interface. - /// </summary> - /// <param name="wifiInterface"></param> - /// <returns></returns> + /** + * This command queries the DHCP information for a particular interface. + */ DHCPInfoResponse * SNIC_GetDHCPInfo(const WIFIInterface wifiInterface); - /// <summary> - /// This command converts a remote host name to IP address. - /// Interface number is either 0 or 1. 0 indicates STA interface. 1 indicates soft AP interface. Currently only STA interface is supported. - /// If multiple SNIC_RESOLVE_NAME_REQ’s need to be sent, it is required they be sent sequentially due to resource limitation. If the name is not resolved, it takes up to 15 seconds for the failure response to come back. While waiting for the response, host application can send other commands (except for SNIC_RESOLVE_NAME_REQ and SNIC_SEND_ARP_REQ). - /// </summary> - /// <param name="host"></param> - /// <returns></returns> - bool SNIC_ResolveHostName(const char * host,IPAddress * ip); + /** + * This command converts a remote host name to IP address. + * Interface number is either 0 or 1. 0 indicates STA interface. 1 indicates soft AP interface. Currently only STA interface is supported. + * If multiple SNIC_RESOLVE_NAME_REQ’s need to be sent, it is required they be sent sequentially due to resource limitation. If the name is not resolved, it takes up to 15 seconds for the failure response to come back. While waiting for the response, host application can send other commands (except for SNIC_RESOLVE_NAME_REQ and SNIC_SEND_ARP_REQ). + */ + IPAddress * SNIC_ResolveHostName(const char * host); - /// <summary> - /// This command instructs module configure the mechanism for obtaining the IP address. - /// DHCP mode specifies how the address is assigned for the interface. - /// 0: interface is assigned the static IP, NetMask and Gateway IP. First IP and Last IP are not present. Any active DHCP client or server is stopped. - /// 1: STA interface uses DHCP to obtain the address. All subsequent fields are not present. STA DHCP client is started if necessary. - /// 2: only for AP interface. If the soft AP is not started or SNIC_INIT_REQ is not done, this command fails. Otherwise, this command stops the HTTP server, DNS server and DHCP server if configured, and restarts them with new parameters. It assigns IP for clients in range [First IP, Last IP] within the subnet mask. The AP itself is assigned the address within the same subnet specified by IP which must not be in the range of [First IP, Last IP]. The value of GTW IP and IP should be the same. If there are clients connected to the soft AP before this command, make sure the clients reconnect to the soft AP after this command. - /// </summary> - /// <param name="config"></param> - /// <returns></returns> + /** + * This command instructs module configure the mechanism for obtaining the IP address. + * DHCP mode specifies how the address is assigned for the interface. + * 0: interface is assigned the static IP, NetMask and Gateway IP. First IP and Last IP are not present. Any active DHCP client or server is stopped. + * 1: STA interface uses DHCP to obtain the address. All subsequent fields are not present. STA DHCP client is started if necessary. + * 2: only for AP interface. If the soft AP is not started or SNIC_INIT_REQ is not done, this command fails. Otherwise, this command stops the HTTP server, DNS server and DHCP server if configured, and restarts them with new parameters. It assigns IP for clients in range [First IP, Last IP] within the subnet mask. The AP itself is assigned the address within the same subnet specified by IP which must not be in the range of [First IP, Last IP]. The value of GTW IP and IP should be the same. If there are clients connected to the soft AP before this command, make sure the clients reconnect to the soft AP after this command. + */ SNICCode SNIC_ConfigureDHCPorStaticIP(DHCPConfig * config); - /// <summary> - /// If the connect attempt is immediately completed, the response will contain SNIC_SUCCESS status, with the actual Receive buffer size. - /// If the connect attempt is not immediately completed, the response will have the SNIC_COMMAND_PENDING status. The Timeout value is the time (in seconds) the module will wait before aborting the connection attempt. If timeout occurs, the SNIC_TCP_CONNECTION_STATUS_IND indication with SNIC_TIMEOUT status will be sent to the application. If connection is successful before timeout, the SNIC_TCP_CONNECTION_STATUS_IND with SNIC_CONNECTION_UP status will be sent to the application. Timeout value should be non-zero. - /// </summary> - /// <param name="remoteHost"></param> - /// <param name="port"></param> - /// <param name="timeout">in seconds</param> - /// <param name="receiveBufferSize">Receive buffer size is the maximum packet size the application wants to receive per transmission. It must be less than or equal to the Default receive buffer size from SNIC_INIT_REQ in the module. If it is 0 or exceeds the system capability, the Default receive buffer size is returned.</param> + /** + * If the connect attempt is immediately completed, the response will contain SNIC_SUCCESS status, with the actual Receive buffer size. + * If the connect attempt is not immediately completed, the response will have the SNIC_COMMAND_PENDING status. The Timeout value is the time (in seconds) the module will wait before aborting the connection attempt. If timeout occurs, the SNIC_TCP_CONNECTION_STATUS_IND indication with SNIC_TIMEOUT status will be sent to the application. If connection is successful before timeout, the SNIC_TCP_CONNECTION_STATUS_IND with SNIC_CONNECTION_UP status will be sent to the application. Timeout value should be non-zero. + * @param remoteHost + * @param port + * @param timeout in seconds + * @param receiveBufferSize Receive buffer size is the maximum packet size the application wants to receive per transmission. It must be less than or equal to the Default receive buffer size from SNIC_INIT_REQ in the module. If it is 0 or exceeds the system capability, the Default receive buffer size is returned. + */ SocketStartReceiveResponse * SNIC_ConnectTCPServer(const char SocketID, IPAddress * remoteIP, const int remotePort, const char timeout, const int receiveBufferSize = 0); - /// <summary> - /// If Bind option is 0, the socket will not be bound, and Local IP address and Local port should not be present. Otherwise, it will be bound to Local IP address and Local port specified. 0x0 for IP or port are valid, which means system assigned. Port number 5000 is reserved for internal use. - /// the socket number must get and store separately, since the response payload may change - /// </summary> - /// <param name="bing">do not bing if this tcp socket is used as a client</param> - /// <param name="localIP"></param> - /// <param name="localPort"></param> - /// <returns></returns> + /** + * If Bind option is 0, the socket will not be bound, and Local IP address and Local port should not be present. Otherwise, it will be bound to Local IP address and Local port specified. 0x0 for IP or port are valid, which means system assigned. Port number 5000 is reserved for internal use. + * the socket number must get and store separately, since the response payload may change + * @param bing do not bing if this tcp socket is used as a client + * @param localIP + * @param localPort + */ CreateSocketResponse * SNIC_CreateTCPSocket(const bool bind = false, IPAddress * localIP = NULL, const int localPort = 0); - /// <summary> - /// If Bind option is 0, the socket will not be bound, and Local IP address and Local port should not be present. Otherwise, it will be bound to Local IP address and Local port specified. 0x0 for IP or port are valid, which means system assigned. Port number 5000 is reserved for internal use. - /// the socket number must get and store separately, since the response payload may change - /// </summary> - /// <param name="bind"></param> - /// <param name="localIP"></param> - /// <param name="localPort"></param> - /// <returns></returns> + /** + * If Bind option is 0, the socket will not be bound, and Local IP address and Local port should not be present. Otherwise, it will be bound to Local IP address and Local port specified. 0x0 for IP or port are valid, which means system assigned. Port number 5000 is reserved for internal use. + * the socket number must get and store separately, since the response payload may change + * @param bind + * @param localIP + * @param localPort + */ CreateSocketResponse * SNIC_CreateUDPSocket(const bool bind = false, IPAddress * localIP = NULL, const int localPort = 0); - /// <summary> - /// The Socket should have been created by command SNIC_UDP_CREATE_SOCKET_REQ. The same socket can be used in SNIC_UDP_SEND_FROM_SOCKET_REQ command, so that send and receive can be done via the same socket (port). The application is responsible to close the socket using SNIC_CLOSE_SOCKET_REQ. - /// Receive buffer size is the maximum packet size the application wants to receive per transmission. It must be less than or equal to the Default receive buffer size from SNIC_INIT_REQ in the module. If 0 or exceeds the system capability, the Default receive buffer size will be used and returned in the response. - /// After this command, the Socket can receive any UDP sender with connected mode or non-connected mode. The module will generate SNIC_UDP_RECV_IND indication for incoming data, which includes sender’s IP and port info. - /// But if this Socket is later connected to a peer UDP server by SNIC_UDP_SEND_FROM_SOCKET_REQ with Connection mode set to1, the module will generate SNIC_CONNECTION_RECV_IND indication without the sender’s IP and port info. See Section 5.19. After that, this Socket will only be able to receive from the one sender it connects to. - /// </summary> - /// <param name="SocketID"></param> - /// <param name="receiveBufferSize"></param> + /** + * The Socket should have been created by command SNIC_UDP_CREATE_SOCKET_REQ. The same socket can be used in SNIC_UDP_SEND_FROM_SOCKET_REQ command, so that send and receive can be done via the same socket (port). The application is responsible to close the socket using SNIC_CLOSE_SOCKET_REQ. + * Receive buffer size is the maximum packet size the application wants to receive per transmission. It must be less than or equal to the Default receive buffer size from SNIC_INIT_REQ in the module. If 0 or exceeds the system capability, the Default receive buffer size will be used and returned in the response. + * After this command, the Socket can receive any UDP sender with connected mode or non-connected mode. The module will generate SNIC_UDP_RECV_IND indication for incoming data, which includes sender’s IP and port info. + * But if this Socket is later connected to a peer UDP server by SNIC_UDP_SEND_FROM_SOCKET_REQ with Connection mode set to1, the module will generate SNIC_CONNECTION_RECV_IND indication without the sender’s IP and port info. See Section 5.19. After that, this Socket will only be able to receive from the one sender it connects to. + */ SocketStartReceiveResponse * SNIC_StartUDPReceive(const char SocketID, const int receiveBufferSize = 0); - /// <summary> - /// A socket will be created for sending the packet out through the default network connection, but will be closed after the transmission. This command can be used when the application just wants to send out one packet to peer, and it also does not expect to receive any packets from peer. - /// </summary> - /// <param name="remoteIP"></param> - /// <param name="remotePort"></param> - /// <param name="payload"></param> - /// <param name="offset"></param> - /// <param name="length"></param> + /** + * A socket will be created for sending the packet out through the default network connection, but will be closed after the transmission. This command can be used when the application just wants to send out one packet to peer, and it also does not expect to receive any packets from peer. + */ SendFromSocketResponse * SNIC_SendUDPPacket(IPAddress * remoteIP, const int remotePort, const char * payload, const int offset, const int length); - /// <summary> - /// The Socket should have been created by command SNIC_UDP_CREATE_SOCKET_REQ. If SNIC_UDP_START_RECV_REQ is not called on the socket, the application can only send out UDP packet from this socket. If SNIC_UDP_START_RECV_REQ has been called for this socket, the application can send and receive UDP packets from the socket. This implies the application can send and receive packets from the same local port. The application is responsible to close the socket using SNIC_CLOSE_SOCKET_REQ. - /// If Connection mode is 1, the module will first connect to the UDP server then send data. Since the socket is still connected after the call, application can send subsequent data using another command SNIC_SEND_FROM_SOCKET_REQ. - /// The benefit of the connected mode is that subsequent send can use SNIC_SEND_FROM_SOCKET_REQ, which does not require the receiver’s IP and port every time, and thus reduces overhead. If this socket is also used to receive by calling SNIC_UDP_START_RECV_REQ, the receive indication to the host will also omits the sender IP and port info, further reducing overhead. - /// </summary> - /// <param name="remoteIP"></param> - /// <param name="remotePort"></param> - /// <param name="SocketID"></param> - /// <param name="connectServer"></param> - /// <param name="payload"></param> - /// <param name="offset"></param> - /// <param name="length"></param> - /// <returns></returns> + /** + * The Socket should have been created by command SNIC_UDP_CREATE_SOCKET_REQ. If SNIC_UDP_START_RECV_REQ is not called on the socket, the application can only send out UDP packet from this socket. If SNIC_UDP_START_RECV_REQ has been called for this socket, the application can send and receive UDP packets from the socket. This implies the application can send and receive packets from the same local port. The application is responsible to close the socket using SNIC_CLOSE_SOCKET_REQ. + * If Connection mode is 1, the module will first connect to the UDP server then send data. Since the socket is still connected after the call, application can send subsequent data using another command SNIC_SEND_FROM_SOCKET_REQ. + * The benefit of the connected mode is that subsequent send can use SNIC_SEND_FROM_SOCKET_REQ, which does not require the receiver’s IP and port every time, and thus reduces overhead. If this socket is also used to receive by calling SNIC_UDP_START_RECV_REQ, the receive indication to the host will also omits the sender IP and port info, further reducing overhead. + * <param name="remoteIP"></param> + * <param name="remotePort"></param> + * <param name="SocketID"></param> + * <param name="connectServer"></param> + * <param name="payload"></param> + * <param name="offset"></param> + * <param name="length"></param> + */ SendFromSocketResponse * SNIC_SendUDPFromSocket(IPAddress * remoteIP, const int remotePort, const char SocketID, const bool connectServer, const char * payload, int offset, const int length); - /// <summary> - /// This command instructs the module to send a HTTP request packet to the remote HTTP server. - /// Post content can be binary. So even if it is text string, it should not contain NUL at the end. The most significant bit of Post content length is reserved to indicate if there is more data to send. If there is more data to send (as indicated by MSBit=1 in the content length), host application should use another API (SNIC_HTTP_MORE_REQ) to send the rest of the data until it is finished. If this bit is set to 1, then the “Transfer-Encoding” in the HTTP request will be set to “chunked” by SNIC. For GET method, the highest bit of Content length must be set to 0 (not chunked). - /// For HTTP request with chunked encoding, status code of SNIC_SUCCESS in the response only means the HTTP request has been sent. After one or more subsequent SNIC_HTTP_MORE_REQ/RSPs, the last SNIC_HTTP_MORE_RSP with HTTP status code will be sent to host containing the data from HTTP server. - /// The most significant bit of Content length is reserved to indicate if there is more response data to send to the host. If there is more data to send (Content length MSBit=1), module uses SNIC_HTTP_RSP_IND to send the rest of the data until it is finished, i.e., when this bit is 1, the host application should continue to receive SNIC_HTTP_RSP_IND, until this bit is 0. - /// The Content length is limited by the receive buffer size specified in SNIC_INIT_REQ and the system resource at that moment. - /// </summary> - /// <param name="content"></param> - /// <param name="isHTTPS"></param> - /// <param name="chunked"></param> - /// <returns></returns> + /** + * This command instructs the module to send a HTTP request packet to the remote HTTP server. + * Post content can be binary. So even if it is text string, it should not contain NUL at the end. The most significant bit of Post content length is reserved to indicate if there is more data to send. If there is more data to send (as indicated by MSBit=1 in the content length), host application should use another API (SNIC_HTTP_MORE_REQ) to send the rest of the data until it is finished. If this bit is set to 1, then the “Transfer-Encoding” in the HTTP request will be set to “chunked” by SNIC. For GET method, the highest bit of Content length must be set to 0 (not chunked). + * For HTTP request with chunked encoding, status code of SNIC_SUCCESS in the response only means the HTTP request has been sent. After one or more subsequent SNIC_HTTP_MORE_REQ/RSPs, the last SNIC_HTTP_MORE_RSP with HTTP status code will be sent to host containing the data from HTTP server. + * The most significant bit of Content length is reserved to indicate if there is more response data to send to the host. If there is more data to send (Content length MSBit=1), module uses SNIC_HTTP_RSP_IND to send the rest of the data until it is finished, i.e., when this bit is 1, the host application should continue to receive SNIC_HTTP_RSP_IND, until this bit is 0. + * The Content length is limited by the receive buffer size specified in SNIC_INIT_REQ and the system resource at that moment. + * <param name="content"></param> + * <param name="isHTTPS"></param> + * <param name="chunked"></param> + */ HTTPResponse * SNIC_SendHTTPRequest(HTTPContent * content, const bool isHTTPS = false, const bool chunked = false); - /// <summary> - /// This command instructs the module to send a subsequent HTTP request packet to the remote HTTP server if the initial SNIC_HTTP_REQ cannot finish the packet due to size or other consideration. It is used when the send method is POST. - /// </summary> - /// <param name="content"></param> - /// <param name="chunked"></param> - /// <returns></returns> + /** + * This command instructs the module to send a subsequent HTTP request packet to the remote HTTP server if the initial SNIC_HTTP_REQ cannot finish the packet due to size or other consideration. It is used when the send method is POST. + * <param name="content"></param> + * <param name="chunked"></param> + */ HTTPResponse * SNIC_SendHTTPMoreRequest(HTTPContent * content, const bool chunked = false); - /// <summary> - /// If Bind option is 0, the socket will not be bound, and Local IP address and Local port should not be present. Otherwise, it will be bound to Local IP address and Local port specified. 0x0 for IP or port are valid, which means system assigned. Port number 5000 is reserved for internal use. - /// the socket number must get and store separately, since the response payload may change - /// </summary> - /// <param name="bing">do not bing if this tcp socket is used as a client</param> - /// <param name="localIP"></param> - /// <param name="localPort"></param> - /// <returns></returns> + /** + * If Bind option is 0, the socket will not be bound, and Local IP address and Local port should not be present. Otherwise, it will be bound to Local IP address and Local port specified. 0x0 for IP or port are valid, which means system assigned. Port number 5000 is reserved for internal use. + * the socket number must get and store separately, since the response payload may change + * </summary> + * <param name="bing">do not bing if this tcp socket is used as a client</param> + * <param name="localIP"></param> + * <param name="localPort"></param> + */ CreateSocketResponse * SNIC_CreateAdvancedTLSTCP(const bool bind, IPAddress * localIP = NULL, const int localPort = 0); - /// <summary> - /// If Bind option is 0, the socket will not be bound, and Local IP address and Local port should not be present. Otherwise, it will be bound to Local IP address and Local port specified. 0x0 for IP or port are valid, which means system assigned. Port number 5000 is reserved for internal use. - /// the socket number must get and store separately, since the response payload may change - /// </summary> - /// <param name="bind"></param> - /// <param name="localIP"></param> - /// <param name="localPort"></param> - /// <returns></returns> + /** + * If Bind option is 0, the socket will not be bound, and Local IP address and Local port should not be present. Otherwise, it will be bound to Local IP address and Local port specified. 0x0 for IP or port are valid, which means system assigned. Port number 5000 is reserved for internal use. + * the socket number must get and store separately, since the response payload may change + * </summary> + * <param name="bind"></param> + * <param name="localIP"></param> + * <param name="localPort"></param> + */ CreateSocketResponse * SNIC_CreateSimpleTLSTCP(const bool bind, IPAddress * localIP = NULL, const int localPort = 0); - }; }
diff -r 5856c23794b1 -r 0ce800923eda Payload.cpp --- a/Payload.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Payload.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -11,8 +11,19 @@ Payload::Payload(Payload * payload) { + position = 0; + max = 0; + SetPayload(payload); +} + +void Payload::SetPayload(Payload * payload) +{ + if (payload == NULL) + return; + this->data = payload->data; this->position = payload->position; + this->max = payload->max; } char * Payload::GetData()
diff -r 5856c23794b1 -r 0ce800923eda Payload.h --- a/Payload.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Payload.h Wed Mar 16 15:04:46 2016 +0000 @@ -25,6 +25,8 @@ Payload(); Payload(Payload * payload); + + void SetPayload(Payload * payload); char * GetData();
diff -r 5856c23794b1 -r 0ce800923eda Response/HTTPResponse.cpp --- a/Response/HTTPResponse.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Response/HTTPResponse.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -5,6 +5,9 @@ HTTPResponse::HTTPResponse(Payload * payload) : Payload(payload) { + if (payload == NULL) + return; + statusCode = GetData()[2] << 8 | GetData()[3]; if (statusCode >= 100) { contentLength = (GetData()[4] & 0x7F) << 8 | GetData()[5];
diff -r 5856c23794b1 -r 0ce800923eda Response/VersionInfoResponse.cpp --- a/Response/VersionInfoResponse.cpp Mon Feb 15 15:17:50 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -#include "VersionInfoResponse.h" - -using namespace SmartLabMuRata; - -VersionInfoResponse::VersionInfoResponse(Payload * payload) - : Payload(payload) -{ } - -CMDCode VersionInfoResponse::GetStatus() -{ - return (CMDCode)GetData()[2]; -} - -char VersionInfoResponse::GetVersionStringLength() -{ - return GetData()[3]; -} - -string VersionInfoResponse::GetVsersionString() -{ - int size = GetVersionStringLength(); - return string(GetData() + 4, size); -} \ No newline at end of file
diff -r 5856c23794b1 -r 0ce800923eda Response/VersionInfoResponse.h --- a/Response/VersionInfoResponse.h Mon Feb 15 15:17:50 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#ifndef SmartLab_MuRata_Response_VersionInfoResponse -#define SmartLab_MuRata_Response_VersionInfoResponse - -#include "Payload.h" -#include "CMDCode.h" - -#include <string> - -using namespace std; - -namespace SmartLabMuRata -{ -class VersionInfoResponse : public Payload -{ -public : - VersionInfoResponse(Payload * payload); - - CMDCode GetStatus(); - - char GetVersionStringLength(); - - string GetVsersionString(); -}; -} - -#endif \ No newline at end of file
diff -r 5856c23794b1 -r 0ce800923eda Response/WIFIStatusResponse.cpp --- a/Response/WIFIStatusResponse.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Response/WIFIStatusResponse.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -19,11 +19,11 @@ return GetData() + 3; } -string WIFIStatusResponse::GetSSID() +const char * WIFIStatusResponse::GetSSID() { WIFIStatusCode code = GetWiFiStatusCode(); if (code == STA_JOINED || code == AP_STARTED) - return string(GetData() + 9); + return GetData() + 9; - return string(); + return NULL; } \ No newline at end of file
diff -r 5856c23794b1 -r 0ce800923eda Response/WIFIStatusResponse.h --- a/Response/WIFIStatusResponse.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Response/WIFIStatusResponse.h Wed Mar 16 15:04:46 2016 +0000 @@ -4,8 +4,6 @@ #include "Payload.h" #include "WIFIStatusCode.h" -#include <string> - using namespace std; namespace SmartLabMuRata @@ -27,7 +25,7 @@ /// Present only if WiFi Status code is STA_JOINED or AP_STARTED. /// </summary> /// <returns></returns> - string GetSSID(); + const char * GetSSID(); }; }
diff -r 5856c23794b1 -r 0ce800923eda Type/IPAddress.cpp --- a/Type/IPAddress.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/IPAddress.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -1,20 +1,28 @@ #include "IPAddress.h" using namespace SmartLabMuRata; -IPAddress::IPAddress() {} +IPAddress::IPAddress() +{} -IPAddress::IPAddress(const string & ip) +IPAddress::IPAddress(const char * ipString) { + if (ipString == NULL) + return; + + int size = strlen(ipString) + 1; + char temp[size]; + + memcpy(temp, ipString, size); + int i = 0; - size_t last = 0; - size_t index = ip.find_first_of(".", last); - while (index != string::npos) { - address[i++] = atoi(ip.substr(last, index - last).c_str()); - last = index + 1; - index = ip.find_first_of(".", last); + char * pch = strtok (temp, "."); + while (pch != NULL) { + address[i++] = atoi(pch); + pch = strtok (NULL, "."); + + if (i >= 4) + break; } - if (index - last > 0) - address[i++] = atoi(ip.substr(last, index - last).c_str()); } void IPAddress::SetValue(const char * data, int offset) @@ -31,11 +39,8 @@ return 4; } -void IPAddress::ToString(string * ipString) +const char * IPAddress::ToString() { - if (ipString == NULL) - return; - char buffer[16]; - sprintf (buffer, "%d.%d.%d.%d", address[0], address[1], address[2], address[3]); - ipString->assign(buffer); + sprintf (ip, "%d.%d.%d.%d", address[0], address[1], address[2], address[3]); + return ip; } \ No newline at end of file
diff -r 5856c23794b1 -r 0ce800923eda Type/IPAddress.h --- a/Type/IPAddress.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/IPAddress.h Wed Mar 16 15:04:46 2016 +0000 @@ -14,11 +14,13 @@ { private: char address[4]; + + char ip[16]; public : IPAddress(); - IPAddress(const string & ip); + IPAddress(const char * ipString); void SetValue(const char * data, int offset = 0); @@ -26,7 +28,7 @@ virtual int GetValueLength(); - void ToString(string * ipString); + const char * ToString(); }; }
diff -r 5856c23794b1 -r 0ce800923eda Type/ResetCode.h --- a/Type/ResetCode.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/ResetCode.h Wed Mar 16 15:04:46 2016 +0000 @@ -3,7 +3,9 @@ namespace SmartLabMuRata { +/// WiFi Reset Response Code enum ResetCode { + N0_Indication = -1, Window_Watchdog_Reset = 0x4000, Independent_Watchdog_Reset = 0x2000, Software_Reset = 0x1000,
diff -r 5856c23794b1 -r 0ce800923eda Type/SecurityMode.h --- a/Type/SecurityMode.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/SecurityMode.h Wed Mar 16 15:04:46 2016 +0000 @@ -9,7 +9,12 @@ WIFI_SECURITY_WPA_TKIP_PSK = 0x02, WIFI_SECURITY_WPA2_AES_PSK = 0x04, WIFI_SECURITY_WPA2_MIXED_PSK = 0x06, + + /** + * not avaliable for SOFT AP + */ WIFI_SECURITY_WPA_AES_PSK = 0x07, + NOT_SUPPORTED = 0xFF, }; }
diff -r 5856c23794b1 -r 0ce800923eda Type/WIFIInfo.cpp --- a/Type/WIFIInfo.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/WIFIInfo.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -4,7 +4,7 @@ const char * WIFIInfo::GetSSID() { - return ssid.c_str(); + return ssid; } SecurityMode WIFIInfo::GetSecurityMode() @@ -17,23 +17,36 @@ return channel; } -WIFIInfo::WIFIInfo() { } +WIFIInfo::WIFIInfo() +{ + ssid = NULL; +} WIFIInfo::WIFIInfo(const char * SSID, const SecurityMode securityMode) { + ssid = NULL; SetSSID(SSID)->SetSecurityMode(securityMode); } -/* + WIFIInfo::~WIFIInfo() { - delete[] ssid; + if (ssid != NULL) + delete[] ssid; } -*/ + WIFIInfo * WIFIInfo::SetSSID(const char * SSID) { - ssid.assign(SSID); + if (SSID == NULL) + return this; + + if (ssid != NULL) + delete[] ssid; + + int length = strlen(SSID) + 1; + ssid = new char[length]; + memcpy(ssid, SSID, length); return this; } @@ -49,7 +62,7 @@ return this; } -string & WIFIInfo::ToString() +const char * WIFIInfo::ToString() { return ssid; } \ No newline at end of file
diff -r 5856c23794b1 -r 0ce800923eda Type/WIFIInfo.h --- a/Type/WIFIInfo.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/WIFIInfo.h Wed Mar 16 15:04:46 2016 +0000 @@ -11,8 +11,13 @@ class WIFIInfo { private : + /** + * must be none 0 value, when used ad AP control. + */ char channel; - string ssid; + + char * ssid; + SecurityMode mode; public: @@ -25,8 +30,8 @@ WIFIInfo(); WIFIInfo(const char * SSID, const SecurityMode securityMode); - - //~WIFIInfo(); + + virtual ~WIFIInfo(); virtual WIFIInfo * SetSSID(const char * SSID); @@ -34,7 +39,7 @@ virtual WIFIInfo * SetChannel(const char channel); - string & ToString(); + const char * ToString(); }; }
diff -r 5856c23794b1 -r 0ce800923eda Type/WIFINetwork.cpp --- a/Type/WIFINetwork.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/WIFINetwork.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -4,40 +4,62 @@ const char * WIFINetwork::GetSecurityKey() { - return key.c_str(); + return key; } const char * WIFINetwork::GetBSSID() { - return BSSID; + return bssid; } -WIFINetwork::WIFINetwork() { BSSID = NULL; } +WIFINetwork::WIFINetwork() +{ + bssid = NULL; + key = NULL; +} WIFINetwork::WIFINetwork(const char * SSID, const SecurityMode securityMode, const char * securityKey) : WIFIInfo(SSID, securityMode) { - BSSID = NULL; + bssid = NULL; + key = NULL; SetSecurityKey(securityKey); } WIFINetwork::~WIFINetwork() { - delete[] BSSID; + if (bssid != NULL) + delete[] bssid; + + if (key != NULL) + delete[] key; } WIFINetwork * WIFINetwork::SetSecurityKey(const char * SecurityKey) { - key.assign(SecurityKey); + if (SecurityKey == NULL) + return this; + + if (key != NULL) + delete[] key; + + int length = strlen(SecurityKey) + 1; + + key = new char[length]; + memcpy(key, SecurityKey, length); return this; } WIFINetwork * WIFINetwork::SetBSSID(const char * BSSID) { - if (this->BSSID == NULL) - this->BSSID = new char[6]; + if (BSSID == NULL) + return this; - memcpy(this->BSSID, BSSID, 6); + if (bssid != NULL) + delete[] bssid; + + bssid = new char[6]; + memcpy(bssid, BSSID, 6); return this; }
diff -r 5856c23794b1 -r 0ce800923eda Type/WIFINetwork.h --- a/Type/WIFINetwork.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/WIFINetwork.h Wed Mar 16 15:04:46 2016 +0000 @@ -9,8 +9,8 @@ class WIFINetwork : public WIFIInfo { private : - string key; - char * BSSID; + char * key; + char * bssid; public: const char * GetSecurityKey(); @@ -21,7 +21,7 @@ WIFINetwork(const char * SSID, const SecurityMode securityMode, const char * securityKey = NULL); - ~WIFINetwork(); + virtual ~WIFINetwork(); virtual WIFINetwork * SetSecurityKey(const char * SecurityKey);
diff -r 5856c23794b1 -r 0ce800923eda Type/WIFINetworkDetail.cpp --- a/Type/WIFINetworkDetail.cpp Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/WIFINetworkDetail.cpp Wed Mar 16 15:04:46 2016 +0000 @@ -4,6 +4,8 @@ WIFINetworkDetail::WIFINetworkDetail() { } +WIFINetworkDetail::~WIFINetworkDetail() {} + WIFINetworkDetail::WIFINetworkDetail(const char * SSID, const SecurityMode securityMode, const BSSType networkType, const int rssi, const int maxDataRate) : WIFINetwork(SSID, securityMode) { @@ -12,7 +14,7 @@ this->maxDataRate = maxDataRate; } -int WIFINetworkDetail::GetRSSI() +int8_t WIFINetworkDetail::GetRSSI() { return rssi; } @@ -33,11 +35,7 @@ WIFINetworkDetail * WIFINetworkDetail::SetRSSI(const int rssi) { - - if (rssi >> 7 == 0x01) - this->rssi = (~(rssi - 1) & 0x7F) * -1; - else - this->rssi = rssi; + this->rssi = rssi; return this; }
diff -r 5856c23794b1 -r 0ce800923eda Type/WIFINetworkDetail.h --- a/Type/WIFINetworkDetail.h Mon Feb 15 15:17:50 2016 +0000 +++ b/Type/WIFINetworkDetail.h Wed Mar 16 15:04:46 2016 +0000 @@ -9,17 +9,19 @@ class WIFINetworkDetail : public WIFINetwork { private: - int rssi; + int8_t rssi; BSSType netType; // Max Data Rate (Mbps) int maxDataRate; public : WIFINetworkDetail(); + + virtual ~WIFINetworkDetail(); WIFINetworkDetail(const char * SSID, const SecurityMode securityMode, const BSSType networkType, const int rssi, const int maxDataRate); - int GetRSSI(); + int8_t GetRSSI(); /// <summary> /// Max Data Rate (Mbps)