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.
Diff: MuRata.cpp
- Revision:
- 1:fd19bd683e90
- Parent:
- 0:8e83b9448758
- Child:
- 2:f8e393a81c25
--- a/MuRata.cpp Tue Feb 03 21:24:15 2015 +0000 +++ b/MuRata.cpp Wed Feb 04 18:10:30 2015 +0000 @@ -18,7 +18,7 @@ SSIDRecordIndication * MuRata::Get_ScanResultIndication() { - if (FrameReceive() + while (FrameReceive() && _payload.GetResponseFlag() == Request_Indication && _frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_SCAN_RESULT_IND) { @@ -30,7 +30,7 @@ WIFIConnectionIndication * MuRata::Get_WiFiStatusIndication() { - if (FrameReceive() + while (FrameReceive() && _payload.GetResponseFlag() == Request_Indication && _frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_NETWORK_STATUS_IND) { @@ -40,6 +40,66 @@ return NULL; } +PowerUpIndication * MuRata::Get_PowerUpIndication() +{ + while (FrameReceive() + && _payload.GetResponseFlag() == Request_Indication + && _frame.GetCommandID() == CMD_ID_GEN + && _payload.GetSubCommandID() == GEN_PWR_UP_IND) { + return new PowerUpIndication(&_payload); + } + + return NULL; +} + +TCPStatusIndication * MuRata::Get_TcpConnectionStatusIndication() +{ + while (FrameReceive() + && _payload.GetResponseFlag() == Request_Indication + && _frame.GetCommandID() == CMD_ID_SNIC + && _payload.GetSubCommandID() == SNIC_TCP_CONNECTION_STATUS_IND) { + return new TCPStatusIndication(&_payload); + } + + return NULL; +} + +SocketReceiveInidcation * MuRata::Get_SocketReceiveIndication() +{ + while (FrameReceive() + && _payload.GetResponseFlag() == Request_Indication + && _frame.GetCommandID() == CMD_ID_SNIC + && _payload.GetSubCommandID() == SNIC_CONNECTION_RECV_IND) { + return new SocketReceiveInidcation(&_payload); + } + + return NULL; +} + +UDPReceivedIndication * MuRata::Get_UDPReceiveIndication() +{ + while (FrameReceive() + && _payload.GetResponseFlag() == Request_Indication + && _frame.GetCommandID() == CMD_ID_SNIC + && _payload.GetSubCommandID() == SNIC_UDP_RECV_IND) { + return new UDPReceivedIndication(&_payload); + } + + return NULL; +} + +HTTPResponseIndication * MuRata::Get_HTTPResponseIndication() +{ + while (FrameReceive() + && _payload.GetResponseFlag() == Request_Indication + && _frame.GetCommandID() == CMD_ID_SNIC + && _payload.GetSubCommandID() == SNIC_HTTP_RSP_IND) { + return new HTTPResponseIndication(&_payload); + } + + return NULL; +} + void MuRata::Send() { _payload.SetResponseFlag(Request_Indication); @@ -94,10 +154,11 @@ Send(); - if (FrameReceive()) - return new VersionInfoResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_FW_VER_GET_REQ) + return new VersionInfoResponse(&_payload); + + return NULL; } CMDCode MuRata::GEN_RestoreNVMtoFactoryDefault() @@ -111,10 +172,11 @@ Send(); - if (FrameReceive()) - return (CMDCode)_payload.GetData()[2]; - else - return GEN_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_RESTORE_REQ) + return (CMDCode)_payload.GetData()[2]; + + return GEN_NORESPONSE; } CMDCode MuRata::GEN_SoftReset() @@ -128,10 +190,11 @@ Send(); - if (FrameReceive()) - return (CMDCode)_payload.GetData()[2]; - else - return GEN_NORESPONSE; + 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) @@ -146,10 +209,11 @@ Send(); - if (FrameReceive()) - return (CMDCode)_payload.GetData()[2]; - else - return GEN_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_GEN && _payload.GetSubCommandID() == GEN_UART_CFG_REQ) + return (CMDCode)_payload.GetData()[2]; + + return GEN_NORESPONSE; } @@ -169,10 +233,11 @@ Send(); - if (FrameReceive()) - return (WIFICode)_payload.GetData()[2]; - else - return WIFI_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_ON_REQ) + return (WIFICode)_payload.GetData()[2]; + + return WIFI_NORESPONSE; } WIFICode MuRata::WIFI_TurnOff() @@ -186,10 +251,11 @@ Send(); - if (FrameReceive()) - return (WIFICode)_payload.GetData()[2]; - else - return WIFI_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_OFF_REQ) + return (WIFICode)_payload.GetData()[2]; + + return WIFI_NORESPONSE; } WIFICode MuRata::WIFI_SoftAPControl(SoftAPConfig * config) @@ -201,27 +267,28 @@ _payload.SetContent(config->GetOnOffStatus()); _payload.SetContent(config->GetPersistency()); if (config->GetOnOffStatus() == 0x02) { - int length = config->GetSSID().length(); - _payload.SetContent(config->GetSSID().c_str(), 0 , length); + int length = strlen(config->GetSSID()); + _payload.SetContent(config->GetSSID(), 0 , length); _payload.SetContent(0x00); } _payload.SetContent(config->GetChannel()); _payload.SetContent((char)config->GetSecurityMode()); - int keyLength = config->GetSecurityKey().length(); + int keyLength = strlen(config->GetSecurityKey()); _payload.SetContent(keyLength); if (config->GetSecurityMode() != WIFI_SECURITY_OPEN && keyLength > 0) - _payload.SetContent(config->GetSecurityKey().c_str(), 0 , keyLength); + _payload.SetContent(config->GetSecurityKey(), 0 , keyLength); _frame.SetCommandID(CMD_ID_WIFI); _frame.SetPayload(&_payload); Send(); - if (FrameReceive()) - return (WIFICode)_payload.GetData()[2]; - else - return WIFI_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_AP_CTRL_REQ) + return (WIFICode)_payload.GetData()[2]; + + return WIFI_NORESPONSE; } WIFICode MuRata::WIFI_AssociateNetwork(WIFINetwork * AP) @@ -229,15 +296,15 @@ _payload.Rewind(); _payload.SetSubCommandID(WIFI_JOIN_REQ); _payload.SetFrameID(_payload.GetFrameID() + 1); - _payload.SetContent(AP->GetSSID().c_str(), 0, AP->GetSSID().length()); + _payload.SetContent(AP->GetSSID(), 0, strlen(AP->GetSSID())); _payload.SetContent(0x00); _payload.SetContent((char)AP->GetSecurityMode()); - int keyLength = AP->GetSecurityKey().length(); + int keyLength = strlen(AP->GetSecurityKey()); _payload.SetContent(keyLength); if (keyLength > 0) - _payload.SetContent(AP->GetSecurityKey().c_str(), 0, keyLength); + _payload.SetContent(AP->GetSecurityKey(), 0, keyLength); if (AP->GetBSSID() != NULL) { _payload.SetContent(AP->GetChannel()); @@ -249,10 +316,11 @@ Send(); - if (FrameReceive()) - return (WIFICode)_payload.GetData()[2]; - else - return WIFI_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_JOIN_REQ) + return (WIFICode)_payload.GetData()[2]; + + return WIFI_NORESPONSE; } WIFICode MuRata::WIFI_DisconnectNetwork() @@ -266,10 +334,11 @@ Send(); - if (FrameReceive()) - return (WIFICode)_payload.GetData()[2]; - else - return WIFI_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_DISCONNECT_REQ) + return (WIFICode)_payload.GetData()[2]; + + return WIFI_NORESPONSE; } WIFIStatusResponse * MuRata::WIFI_GetStatus(const WIFIInterface WiFiInterface) { @@ -283,10 +352,11 @@ Send(); - if (FrameReceive()) - return new WIFIStatusResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_GET_STATUS_REQ) + return new WIFIStatusResponse(&_payload); + + return NULL; } int MuRata::WIFI_GetRSSI() @@ -298,18 +368,19 @@ _frame.SetCommandID(CMD_ID_WIFI); _frame.SetPayload(&_payload); - Send(); - if (FrameReceive()) { - char value = _payload.GetData()[2]; + while (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; + if (value >> 7 == 0x01) + return (~(_payload.GetData()[2] - 1) & 0x7F) * -1; - return value; - } else - return 127; + return value; + } + + return 127; } WIFICode MuRata::WIFI_StartWPSProcess(const WPSMode mode, const char * pin, int pinLength) @@ -332,10 +403,11 @@ Send(); - if (FrameReceive()) - return (WIFICode)_payload.GetData()[2]; - else - return WIFI_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_WPS_REQ) + return (WIFICode)_payload.GetData()[2]; + + return WIFI_NORESPONSE; } WIFICode MuRata::WIFI_ScanNetworks(const ScanType scan, const BSSType bss) @@ -370,10 +442,11 @@ Send(); - if (FrameReceive()) - return (WIFICode)_payload.GetData()[2]; - else - return WIFI_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_WIFI && _payload.GetSubCommandID() == WIFI_SCAN_REQ) + return (WIFICode)_payload.GetData()[2]; + + return WIFI_NORESPONSE; } InitializationResponse * MuRata::SNIC_Initialization(int receiveBufferSize) @@ -389,10 +462,11 @@ Send(); - if (FrameReceive()) - return new InitializationResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_INIT_REQ) + return new InitializationResponse(&_payload); + + return NULL; } SNICCode MuRata::SNIC_Cleanup() @@ -406,10 +480,11 @@ Send(); - if (FrameReceive()) - return (SNICCode)_payload.GetData()[2]; - else - return SNIC_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_CLEANUP_REQ) + return (SNICCode)_payload.GetData()[2]; + + return SNIC_NORESPONSE; } @@ -430,10 +505,11 @@ Send(); - if (FrameReceive()) - return new SendFromSocketResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_SEND_FROM_SOCKET_REQ) + return new SendFromSocketResponse(&_payload); + + return NULL; } SNICCode MuRata::SNIC_SloseSocket(const char SocketID) @@ -448,10 +524,11 @@ Send(); - if (FrameReceive()) - return (SNICCode)_payload.GetData()[2]; - else - return SNIC_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_CLOSE_SOCKET_REQ) + return (SNICCode)_payload.GetData()[2]; + + return SNIC_NORESPONSE; } DHCPInfoResponse * MuRata::SNIC_GetDHCPInfo(const WIFIInterface wifiInterface) @@ -466,33 +543,37 @@ Send(); - if (FrameReceive()) - return new DHCPInfoResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_GET_DHCP_INFO_REQ) + return new DHCPInfoResponse(&_payload); + + return NULL; } -IPAddress MuRata::SNIC_ResolveHostName(const string * host) +bool MuRata::SNIC_ResolveHostName(const char * host, IPAddress * ip) { + int hostLength = strlen(host); + _payload.Rewind(); _payload.SetSubCommandID(SNIC_RESOLVE_NAME_REQ); _payload.SetFrameID(_payload.GetFrameID() + 1); _payload.SetContent((char)STA); - _payload.SetContent((char)host->length()); - _payload.SetContent(host->c_str(), 0, host->length()); + _payload.SetContent(hostLength); + _payload.SetContent(host, 0, hostLength); _frame.SetCommandID(CMD_ID_SNIC); _frame.SetPayload(&_payload); Send(); - IPAddress ip; + 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; + } - if (FrameReceive()) - if ((SNICCode)_payload.GetData()[2] == SNIC_SUCCESS) - ip.SetValue(_payload.GetData(), 3); - - return ip; + return false; } SNICCode MuRata::SNIC_ConfigureDHCPorStaticIP(DHCPConfig * config) @@ -519,10 +600,11 @@ Send(); - if (FrameReceive()) - return (SNICCode)_payload.GetData()[2]; - else - return SNIC_NORESPONSE; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_IP_CONFIG_REQ) + return (SNICCode)_payload.GetData()[2]; + + return SNIC_NORESPONSE; } SocketStartReceiveResponse * MuRata::SNIC_ConnectTCPServer(const char SocketID, IPAddress * remoteIP, const int remotePort, const char timeout, const int receiveBufferSize) @@ -543,10 +625,11 @@ Send(); - if (FrameReceive()) - return new SocketStartReceiveResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_TCP_CONNECT_TO_SERVER_REQ) + return new SocketStartReceiveResponse(&_payload); + + return NULL; } CreateSocketResponse * MuRata::SNIC_CreateTCPSocket(const bool bind, IPAddress * localIP, const int localPort) @@ -585,10 +668,11 @@ Send(); - if (FrameReceive()) - return new CreateSocketResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == subID) + return new CreateSocketResponse(&_payload); + + return NULL; } SocketStartReceiveResponse * MuRata::SNIC_StartUDPReceive(const char SocketID, const int receiveBufferSize) @@ -605,10 +689,11 @@ Send(); - if (FrameReceive()) - return new SocketStartReceiveResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_START_RECV_REQ) + return new SocketStartReceiveResponse(&_payload); + + return NULL; } SendFromSocketResponse * MuRata::SNIC_SendUDPPacket(IPAddress * remoteIP, const int remotePort, const char * payload, int offset, int length) @@ -628,10 +713,11 @@ Send(); - if (FrameReceive()) - return new SendFromSocketResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_SIMPLE_SEND_REQ) + return new SendFromSocketResponse(&_payload); + + return NULL; } SendFromSocketResponse * MuRata::SNIC_SendUDPFromSocket(IPAddress * remoteIP, const int remotePort, const char SocketID, const bool connectServer, const char * payload, int offset, int length) @@ -653,20 +739,20 @@ Send(); - if (FrameReceive()) - return new SendFromSocketResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_UDP_SEND_FROM_SOCKET_REQ) + return new SendFromSocketResponse(&_payload); + + return NULL; } HTTPResponse * MuRata::SNIC_SendHTTPRequest(HTTPContent * content, const bool isHTTPS, const bool chunked) { + SubCommandID _id = isHTTPS ? SNIC_HTTPS_REQ: SNIC_HTTP_REQ; + + _payload.Rewind(); - if (isHTTPS) - _payload.SetSubCommandID(SNIC_HTTPS_REQ); - else - _payload.SetSubCommandID(SNIC_HTTP_REQ); - + _payload.SetSubCommandID(_id); _payload.SetFrameID(_payload.GetFrameID() + 1); _payload.SetContent((char)(content->GetRemotePort() >> 8)); _payload.SetContent((char)content->GetRemotePort()); @@ -708,10 +794,11 @@ Send(); - if (FrameReceive()) - return new HTTPResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == _id) + return new HTTPResponse(&_payload); + + return NULL; } HTTPResponse * MuRata::SNIC_SendHTTPMoreRequest(HTTPContent * content, const bool chunked) @@ -740,10 +827,11 @@ if (chunked) return NULL; - if (FrameReceive()) - return new HTTPResponse(&_payload); - else - return NULL; + while (FrameReceive()) + if (_frame.GetCommandID() == CMD_ID_SNIC && _payload.GetSubCommandID() == SNIC_HTTP_MORE_REQ) + return new HTTPResponse(&_payload); + + return NULL; } CreateSocketResponse * MuRata::SNIC_CreateAdvancedTLSTCP(const bool bind, IPAddress * localIP, const int localPort)