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.

Committer:
yangcq88517
Date:
Mon Feb 15 15:17:50 2016 +0000
Revision:
8:5856c23794b1
Parent:
1:fd19bd683e90
Child:
9:0ce800923eda
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yangcq88517 0:8e83b9448758 1 #ifndef SmartLab_MuRata_MuRata
yangcq88517 0:8e83b9448758 2 #define SmartLab_MuRata_MuRata
yangcq88517 0:8e83b9448758 3
yangcq88517 0:8e83b9448758 4 #include "Payload.h"
yangcq88517 0:8e83b9448758 5 #include "UARTFrame.h"
yangcq88517 0:8e83b9448758 6
yangcq88517 0:8e83b9448758 7 #include "UARTConfig.h"
yangcq88517 0:8e83b9448758 8 #include "DHCPConfig.h"
yangcq88517 0:8e83b9448758 9 #include "SoftAPConfig.h"
yangcq88517 0:8e83b9448758 10
yangcq88517 0:8e83b9448758 11 #include "CMDCode.h"
yangcq88517 0:8e83b9448758 12 #include "SNICCode.h"
yangcq88517 0:8e83b9448758 13 #include "WIFICode.h"
yangcq88517 0:8e83b9448758 14
yangcq88517 0:8e83b9448758 15 #include "BSSType.h"
yangcq88517 0:8e83b9448758 16 #include "CommandID.h"
yangcq88517 0:8e83b9448758 17 #include "DHCPMode.h"
yangcq88517 0:8e83b9448758 18 #include "HTTPContent.h"
yangcq88517 0:8e83b9448758 19 #include "IPAddress.h"
yangcq88517 0:8e83b9448758 20 #include "ResetCode.h"
yangcq88517 0:8e83b9448758 21 #include "ScanType.h"
yangcq88517 0:8e83b9448758 22 #include "SecurityMode.h"
yangcq88517 0:8e83b9448758 23 #include "SocketSentOption.h"
yangcq88517 0:8e83b9448758 24 #include "SubCommandID.h"
yangcq88517 0:8e83b9448758 25 #include "WIFIInfo.h"
yangcq88517 0:8e83b9448758 26 #include "WIFINetwork.h"
yangcq88517 0:8e83b9448758 27 #include "WIFINetworkDetail.h"
yangcq88517 0:8e83b9448758 28 #include "WIFIInterface.h"
yangcq88517 0:8e83b9448758 29 #include "WIFIStatusCode.h"
yangcq88517 0:8e83b9448758 30 #include "WPSMode.h"
yangcq88517 0:8e83b9448758 31
yangcq88517 0:8e83b9448758 32 #include "PowerUpIndication.h"
yangcq88517 0:8e83b9448758 33 #include "SSIDRecordIndication.h"
yangcq88517 0:8e83b9448758 34 #include "TCPStatusIndication.h"
yangcq88517 0:8e83b9448758 35 #include "SocketReceiveInidcation.h"
yangcq88517 0:8e83b9448758 36 #include "UDPReceivedIndication.h"
yangcq88517 0:8e83b9448758 37 #include "WIFIConnectionIndication.h"
yangcq88517 0:8e83b9448758 38 #include "HTTPResponseIndication.h"
yangcq88517 0:8e83b9448758 39
yangcq88517 0:8e83b9448758 40 #include "VersionInfoResponse.h"
yangcq88517 0:8e83b9448758 41 #include "WIFIStatusResponse.h"
yangcq88517 0:8e83b9448758 42 #include "InitializationResponse.h"
yangcq88517 0:8e83b9448758 43 #include "SendFromSocketResponse.h"
yangcq88517 0:8e83b9448758 44 #include "CreateSocketResponse.h"
yangcq88517 0:8e83b9448758 45 #include "SocketStartReceiveResponse.h"
yangcq88517 0:8e83b9448758 46 #include "DHCPInfoResponse.h"
yangcq88517 0:8e83b9448758 47 #include "HTTPResponse.h"
yangcq88517 0:8e83b9448758 48
yangcq88517 0:8e83b9448758 49 #include "mbed.h"
yangcq88517 0:8e83b9448758 50
yangcq88517 0:8e83b9448758 51 namespace SmartLabMuRata
yangcq88517 0:8e83b9448758 52 {
yangcq88517 0:8e83b9448758 53 class MuRata
yangcq88517 0:8e83b9448758 54 {
yangcq88517 0:8e83b9448758 55 private :
yangcq88517 0:8e83b9448758 56 Serial * serial;
yangcq88517 0:8e83b9448758 57 Payload _payload;
yangcq88517 0:8e83b9448758 58 UARTFrame _frame;
yangcq88517 0:8e83b9448758 59
yangcq88517 0:8e83b9448758 60 void Send();
yangcq88517 0:8e83b9448758 61
yangcq88517 0:8e83b9448758 62 bool FrameReceive();
yangcq88517 0:8e83b9448758 63
yangcq88517 0:8e83b9448758 64 CreateSocketResponse * SNIC_CreateSocket(const SubCommandID subID, const bool bind = false, IPAddress * localIP = NULL, const int localPort = 0);
yangcq88517 8:5856c23794b1 65
yangcq88517 8:5856c23794b1 66 /// Time out when is no data received
yangcq88517 8:5856c23794b1 67 Timer timer;
yangcq88517 0:8e83b9448758 68
yangcq88517 0:8e83b9448758 69 public:
yangcq88517 0:8e83b9448758 70
yangcq88517 0:8e83b9448758 71 static const int DEFAULT_BAUDRATE = 921600;
yangcq88517 0:8e83b9448758 72
yangcq88517 0:8e83b9448758 73 // ##############################################################################
yangcq88517 0:8e83b9448758 74 // indication
yangcq88517 0:8e83b9448758 75 // ##############################################################################
yangcq88517 0:8e83b9448758 76
yangcq88517 0:8e83b9448758 77 SSIDRecordIndication * Get_ScanResultIndication();
yangcq88517 0:8e83b9448758 78
yangcq88517 0:8e83b9448758 79 WIFIConnectionIndication * Get_WiFiStatusIndication();
yangcq88517 0:8e83b9448758 80
yangcq88517 1:fd19bd683e90 81 PowerUpIndication * Get_PowerUpIndication();
yangcq88517 1:fd19bd683e90 82
yangcq88517 1:fd19bd683e90 83 TCPStatusIndication * Get_TcpConnectionStatusIndication();
yangcq88517 1:fd19bd683e90 84
yangcq88517 1:fd19bd683e90 85 SocketReceiveInidcation * Get_SocketReceiveIndication();
yangcq88517 1:fd19bd683e90 86
yangcq88517 1:fd19bd683e90 87 UDPReceivedIndication * Get_UDPReceiveIndication();
yangcq88517 1:fd19bd683e90 88
yangcq88517 1:fd19bd683e90 89 HTTPResponseIndication * Get_HTTPResponseIndication();
yangcq88517 1:fd19bd683e90 90
yangcq88517 0:8e83b9448758 91 // ##############################################################################
yangcq88517 0:8e83b9448758 92 // constructor
yangcq88517 0:8e83b9448758 93 // ##############################################################################
yangcq88517 0:8e83b9448758 94
yangcq88517 0:8e83b9448758 95 MuRata(PinName tx, PinName rx);
yangcq88517 0:8e83b9448758 96
yangcq88517 0:8e83b9448758 97 MuRata(PinName tx, PinName rx, int baudrate ,int bits=8, Serial::Parity parity=SerialBase::None, int stop_bits=1);
yangcq88517 0:8e83b9448758 98
yangcq88517 0:8e83b9448758 99
yangcq88517 0:8e83b9448758 100 // ##############################################################################
yangcq88517 0:8e83b9448758 101 // GEN
yangcq88517 0:8e83b9448758 102 // ##############################################################################
yangcq88517 0:8e83b9448758 103
yangcq88517 0:8e83b9448758 104 /// <summary>
yangcq88517 0:8e83b9448758 105 /// SNIC firmware has a built in version string. Use this command to retrieve the version info.
yangcq88517 0:8e83b9448758 106 /// </summary>
yangcq88517 0:8e83b9448758 107 /// <returns>return null when timeout</returns>
yangcq88517 0:8e83b9448758 108 VersionInfoResponse * GEN_GetFirmwareVersionInfo();
yangcq88517 0:8e83b9448758 109
yangcq88517 0:8e83b9448758 110 /// <summary>
yangcq88517 0:8e83b9448758 111 /// This command restores the data stored in NVM to factory default values. Any web page update is not affected by this command.
yangcq88517 0:8e83b9448758 112 /// A soft reset will be performed automatically after the NVM has been restored.
yangcq88517 0:8e83b9448758 113 /// Application needs to send WIFI_GET_STATUS_REQ or SNIC_GET_DHCP_INFO_REQ commands to determine the new state of the Murata module.
yangcq88517 0:8e83b9448758 114 /// </summary>
yangcq88517 0:8e83b9448758 115 /// <returns></returns>
yangcq88517 0:8e83b9448758 116 CMDCode GEN_RestoreNVMtoFactoryDefault();
yangcq88517 0:8e83b9448758 117
yangcq88517 0:8e83b9448758 118 /// <summary>
yangcq88517 0:8e83b9448758 119 /// 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.
yangcq88517 0:8e83b9448758 120 /// </summary>
yangcq88517 0:8e83b9448758 121 /// <returns></returns>
yangcq88517 0:8e83b9448758 122 CMDCode GEN_SoftReset();
yangcq88517 0:8e83b9448758 123
yangcq88517 0:8e83b9448758 124 /// <summary>
yangcq88517 0:8e83b9448758 125 /// 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.
yangcq88517 0:8e83b9448758 126 /// </summary>
yangcq88517 0:8e83b9448758 127 /// <param name="config"></param>
yangcq88517 0:8e83b9448758 128 /// <returns></returns>
yangcq88517 0:8e83b9448758 129 CMDCode GEN_UARTConfiguration(UARTConfig & config);
yangcq88517 0:8e83b9448758 130
yangcq88517 0:8e83b9448758 131 // ##############################################################################
yangcq88517 0:8e83b9448758 132 // WiFi
yangcq88517 0:8e83b9448758 133 // ##############################################################################
yangcq88517 0:8e83b9448758 134
yangcq88517 0:8e83b9448758 135 /// <summary>
yangcq88517 0:8e83b9448758 136 /// This command turns on Wifi on module.
yangcq88517 0:8e83b9448758 137 /// 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.
yangcq88517 0:8e83b9448758 138 /// 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.
yangcq88517 0:8e83b9448758 139 /// Turning on WiFi would cause the following to happen:
yangcq88517 0:8e83b9448758 140 /// The following operations occur using the parameters specified in the NVM if the AP mode is enabled.
yangcq88517 0:8e83b9448758 141 /// 1. Turn on the soft AP
yangcq88517 0:8e83b9448758 142 /// 2. Starts DNS server, DHCP server and HTTP server. The HTTP server provides a means for configuring the WLAN access parameters for the STA.
yangcq88517 0:8e83b9448758 143 /// 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.
yangcq88517 0:8e83b9448758 144 /// 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.
yangcq88517 0:8e83b9448758 145 /// </summary>
yangcq88517 0:8e83b9448758 146 /// <returns></returns>
yangcq88517 0:8e83b9448758 147 WIFICode WIFI_TurnOn();
yangcq88517 0:8e83b9448758 148
yangcq88517 0:8e83b9448758 149 /// <summary>
yangcq88517 0:8e83b9448758 150 /// This command turns off Wifi on module. Turning off WiFi causes the following to happen:
yangcq88517 0:8e83b9448758 151 /// 1. Turn off the soft AP, including shutting down DNS server, DHCP server and HTTP server.
yangcq88517 0:8e83b9448758 152 /// 2. Disconnect STA from any joined network, and close all sockets opened by application.
yangcq88517 0:8e83b9448758 153 /// </summary>
yangcq88517 0:8e83b9448758 154 /// <returns></returns>
yangcq88517 0:8e83b9448758 155 WIFICode WIFI_TurnOff();
yangcq88517 0:8e83b9448758 156
yangcq88517 0:8e83b9448758 157 /// <summary>
yangcq88517 0:8e83b9448758 158 /// 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.
yangcq88517 0:8e83b9448758 159 /// 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.
yangcq88517 0:8e83b9448758 160 /// WIFI_AP_CTRL_REQ can be used to turn the soft AP off.
yangcq88517 0:8e83b9448758 161 /// OnOff = 0 indicates AP is to be turned off. The rest of the parameters are ignored.
yangcq88517 0:8e83b9448758 162 /// OnOff = 1 indicates turning on soft AP using existing NVM parameters,
yangcq88517 0:8e83b9448758 163 /// OnOff = 2 indicates turning on AP with the parameters provided. If the soft AP is already on, it is first turned off.
yangcq88517 0:8e83b9448758 164 /// 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.
yangcq88517 0:8e83b9448758 165 /// </summary>
yangcq88517 0:8e83b9448758 166 /// <param name="config"></param>
yangcq88517 0:8e83b9448758 167 /// <returns></returns>
yangcq88517 0:8e83b9448758 168 WIFICode WIFI_SoftAPControl(SoftAPConfig * config);
yangcq88517 0:8e83b9448758 169
yangcq88517 0:8e83b9448758 170 /// <summary>
yangcq88517 0:8e83b9448758 171 /// This command instructs module to associate to a network.
yangcq88517 0:8e83b9448758 172 /// </summary>
yangcq88517 0:8e83b9448758 173 /// <param name="AP"></param>
yangcq88517 0:8e83b9448758 174 /// <returns></returns>
yangcq88517 0:8e83b9448758 175 WIFICode WIFI_AssociateNetwork(WIFINetwork * AP);
yangcq88517 0:8e83b9448758 176
yangcq88517 0:8e83b9448758 177 /// <summary>
yangcq88517 0:8e83b9448758 178 /// This command instructs the module to disconnect from a network.
yangcq88517 0:8e83b9448758 179 /// Upon a successful reception of the command, the module disconnects from associated network. Sockets opened by application are not closed.
yangcq88517 0:8e83b9448758 180 /// </summary>
yangcq88517 0:8e83b9448758 181 /// <returns></returns>
yangcq88517 0:8e83b9448758 182 WIFICode WIFI_DisconnectNetwork();
yangcq88517 0:8e83b9448758 183
yangcq88517 0:8e83b9448758 184 /// <summary>
yangcq88517 0:8e83b9448758 185 /// 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).
yangcq88517 0:8e83b9448758 186 /// </summary>
yangcq88517 0:8e83b9448758 187 /// <param name="WiFiInterface"></param>
yangcq88517 0:8e83b9448758 188 /// <returns></returns>
yangcq88517 0:8e83b9448758 189 WIFIStatusResponse * WIFI_GetStatus(const WIFIInterface WiFiInterface);
yangcq88517 0:8e83b9448758 190
yangcq88517 0:8e83b9448758 191 /// <summary>
yangcq88517 0:8e83b9448758 192 /// This command requests the reporting of the current RSSI from module’s STA interface
yangcq88517 0:8e83b9448758 193 /// </summary>
yangcq88517 0:8e83b9448758 194 /// <returns>RSSI in dBm. 127 means unspecified value</returns>
yangcq88517 0:8e83b9448758 195 int WIFI_GetRSSI();
yangcq88517 0:8e83b9448758 196
yangcq88517 0:8e83b9448758 197 /// <summary>
yangcq88517 0:8e83b9448758 198 /// This command requests the module to use WPS to join the network. Two methods are supported: push button and pin-based configuration.
yangcq88517 0:8e83b9448758 199 /// 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.
yangcq88517 0:8e83b9448758 200 /// 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).
yangcq88517 0:8e83b9448758 201 /// </summary>
yangcq88517 0:8e83b9448758 202 /// <param name="mode"></param>
yangcq88517 0:8e83b9448758 203 /// <param name="Pin"></param>
yangcq88517 0:8e83b9448758 204 /// <returns></returns>
yangcq88517 0:8e83b9448758 205 WIFICode WIFI_StartWPSProcess(const WPSMode mode, const char * pin = NULL, int pinLength = 0);
yangcq88517 0:8e83b9448758 206
yangcq88517 0:8e83b9448758 207 /// <summary>
yangcq88517 0:8e83b9448758 208 /// 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
yangcq88517 0:8e83b9448758 209 /// </summary>
yangcq88517 0:8e83b9448758 210 /// <param name="scan"></param>
yangcq88517 0:8e83b9448758 211 /// <param name="bss"></param>
yangcq88517 0:8e83b9448758 212 /// <param name="BSSID">6 bytes MAC address of the AP or STA.</param>
yangcq88517 0:8e83b9448758 213 /// <param name="channelList">up to 10 array elements</param>
yangcq88517 0:8e83b9448758 214 /// <param name="SSID">string for the AP or STA SSID, up to 32 bytes</param>
yangcq88517 0:8e83b9448758 215 /// <returns></returns>
yangcq88517 0:8e83b9448758 216 WIFICode WIFI_ScanNetworks(const ScanType scan, const BSSType bss);
yangcq88517 0:8e83b9448758 217
yangcq88517 0:8e83b9448758 218 // ##############################################################################
yangcq88517 0:8e83b9448758 219 // SNIC
yangcq88517 0:8e83b9448758 220 // ##############################################################################
yangcq88517 0:8e83b9448758 221
yangcq88517 0:8e83b9448758 222 /// <summary>
yangcq88517 0:8e83b9448758 223 /// This command initializes the SNIC networking framework on module. TCP/UDP socket communication may be performed only after this command is called.
yangcq88517 0:8e83b9448758 224 /// 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.
yangcq88517 0:8e83b9448758 225 /// </summary>
yangcq88517 0:8e83b9448758 226 /// <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>
yangcq88517 0:8e83b9448758 227 /// <returns></returns>
yangcq88517 0:8e83b9448758 228 InitializationResponse * SNIC_Initialization(int receiveBufferSize = 0);
yangcq88517 0:8e83b9448758 229
yangcq88517 0:8e83b9448758 230 /// <summary>
yangcq88517 0:8e83b9448758 231 /// 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.
yangcq88517 0:8e83b9448758 232 /// </summary>
yangcq88517 0:8e83b9448758 233 /// <returns></returns>
yangcq88517 0:8e83b9448758 234 SNICCode SNIC_Cleanup();
yangcq88517 0:8e83b9448758 235
yangcq88517 0:8e83b9448758 236 /// <summary>
yangcq88517 0:8e83b9448758 237 /// 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.
yangcq88517 0:8e83b9448758 238 /// 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.
yangcq88517 0:8e83b9448758 239 /// 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.
yangcq88517 0:8e83b9448758 240 /// </summary>
yangcq88517 0:8e83b9448758 241 /// <param name="SocketID"></param>
yangcq88517 0:8e83b9448758 242 /// <param name="option"></param>
yangcq88517 0:8e83b9448758 243 /// <returns></returns>
yangcq88517 0:8e83b9448758 244 SendFromSocketResponse * SNIC_SendFromSocket(const char SocketID, const SocketSentOption option, const char * payload, int offset, int length);
yangcq88517 0:8e83b9448758 245
yangcq88517 0:8e83b9448758 246 /// <summary>
yangcq88517 0:8e83b9448758 247 /// This command instructs the module to close a socket.
yangcq88517 0:8e83b9448758 248 /// </summary>
yangcq88517 0:8e83b9448758 249 /// <param name="SocketID"></param>
yangcq88517 0:8e83b9448758 250 /// <returns></returns>
yangcq88517 0:8e83b9448758 251 SNICCode SNIC_SloseSocket(const char SocketID);
yangcq88517 0:8e83b9448758 252
yangcq88517 0:8e83b9448758 253 /// <summary>
yangcq88517 0:8e83b9448758 254 /// This command queries the DHCP information for a particular interface.
yangcq88517 0:8e83b9448758 255 /// </summary>
yangcq88517 0:8e83b9448758 256 /// <param name="wifiInterface"></param>
yangcq88517 0:8e83b9448758 257 /// <returns></returns>
yangcq88517 0:8e83b9448758 258 DHCPInfoResponse * SNIC_GetDHCPInfo(const WIFIInterface wifiInterface);
yangcq88517 0:8e83b9448758 259
yangcq88517 0:8e83b9448758 260 /// <summary>
yangcq88517 0:8e83b9448758 261 /// This command converts a remote host name to IP address.
yangcq88517 0:8e83b9448758 262 /// Interface number is either 0 or 1. 0 indicates STA interface. 1 indicates soft AP interface. Currently only STA interface is supported.
yangcq88517 0:8e83b9448758 263 /// 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).
yangcq88517 0:8e83b9448758 264 /// </summary>
yangcq88517 0:8e83b9448758 265 /// <param name="host"></param>
yangcq88517 0:8e83b9448758 266 /// <returns></returns>
yangcq88517 1:fd19bd683e90 267 bool SNIC_ResolveHostName(const char * host,IPAddress * ip);
yangcq88517 0:8e83b9448758 268
yangcq88517 0:8e83b9448758 269 /// <summary>
yangcq88517 0:8e83b9448758 270 /// This command instructs module configure the mechanism for obtaining the IP address.
yangcq88517 0:8e83b9448758 271 /// DHCP mode specifies how the address is assigned for the interface.
yangcq88517 0:8e83b9448758 272 ///  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.
yangcq88517 0:8e83b9448758 273 ///  1: STA interface uses DHCP to obtain the address. All subsequent fields are not present. STA DHCP client is started if necessary.
yangcq88517 0:8e83b9448758 274 ///  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.
yangcq88517 0:8e83b9448758 275 /// </summary>
yangcq88517 0:8e83b9448758 276 /// <param name="config"></param>
yangcq88517 0:8e83b9448758 277 /// <returns></returns>
yangcq88517 0:8e83b9448758 278 SNICCode SNIC_ConfigureDHCPorStaticIP(DHCPConfig * config);
yangcq88517 1:fd19bd683e90 279
yangcq88517 0:8e83b9448758 280 /// <summary>
yangcq88517 0:8e83b9448758 281 /// If the connect attempt is immediately completed, the response will contain SNIC_SUCCESS status, with the actual Receive buffer size.
yangcq88517 0:8e83b9448758 282 /// 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.
yangcq88517 0:8e83b9448758 283 /// </summary>
yangcq88517 0:8e83b9448758 284 /// <param name="remoteHost"></param>
yangcq88517 0:8e83b9448758 285 /// <param name="port"></param>
yangcq88517 0:8e83b9448758 286 /// <param name="timeout">in seconds</param>
yangcq88517 0:8e83b9448758 287 /// <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>
yangcq88517 0:8e83b9448758 288 SocketStartReceiveResponse * SNIC_ConnectTCPServer(const char SocketID, IPAddress * remoteIP, const int remotePort, const char timeout, const int receiveBufferSize = 0);
yangcq88517 1:fd19bd683e90 289
yangcq88517 0:8e83b9448758 290 /// <summary>
yangcq88517 0:8e83b9448758 291 /// 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.
yangcq88517 0:8e83b9448758 292 /// the socket number must get and store separately, since the response payload may change
yangcq88517 0:8e83b9448758 293 /// </summary>
yangcq88517 0:8e83b9448758 294 /// <param name="bing">do not bing if this tcp socket is used as a client</param>
yangcq88517 0:8e83b9448758 295 /// <param name="localIP"></param>
yangcq88517 0:8e83b9448758 296 /// <param name="localPort"></param>
yangcq88517 0:8e83b9448758 297 /// <returns></returns>
yangcq88517 0:8e83b9448758 298 CreateSocketResponse * SNIC_CreateTCPSocket(const bool bind = false, IPAddress * localIP = NULL, const int localPort = 0);
yangcq88517 0:8e83b9448758 299
yangcq88517 0:8e83b9448758 300 /// <summary>
yangcq88517 0:8e83b9448758 301 /// 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.
yangcq88517 0:8e83b9448758 302 /// the socket number must get and store separately, since the response payload may change
yangcq88517 0:8e83b9448758 303 /// </summary>
yangcq88517 0:8e83b9448758 304 /// <param name="bind"></param>
yangcq88517 0:8e83b9448758 305 /// <param name="localIP"></param>
yangcq88517 0:8e83b9448758 306 /// <param name="localPort"></param>
yangcq88517 0:8e83b9448758 307 /// <returns></returns>
yangcq88517 0:8e83b9448758 308 CreateSocketResponse * SNIC_CreateUDPSocket(const bool bind = false, IPAddress * localIP = NULL, const int localPort = 0);
yangcq88517 0:8e83b9448758 309
yangcq88517 0:8e83b9448758 310 /// <summary>
yangcq88517 0:8e83b9448758 311 /// 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.
yangcq88517 0:8e83b9448758 312 /// 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.
yangcq88517 0:8e83b9448758 313 /// 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.
yangcq88517 0:8e83b9448758 314 /// 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.
yangcq88517 0:8e83b9448758 315 /// </summary>
yangcq88517 0:8e83b9448758 316 /// <param name="SocketID"></param>
yangcq88517 0:8e83b9448758 317 /// <param name="receiveBufferSize"></param>
yangcq88517 0:8e83b9448758 318 SocketStartReceiveResponse * SNIC_StartUDPReceive(const char SocketID, const int receiveBufferSize = 0);
yangcq88517 0:8e83b9448758 319
yangcq88517 0:8e83b9448758 320 /// <summary>
yangcq88517 0:8e83b9448758 321 /// 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.
yangcq88517 0:8e83b9448758 322 /// </summary>
yangcq88517 0:8e83b9448758 323 /// <param name="remoteIP"></param>
yangcq88517 0:8e83b9448758 324 /// <param name="remotePort"></param>
yangcq88517 0:8e83b9448758 325 /// <param name="payload"></param>
yangcq88517 0:8e83b9448758 326 /// <param name="offset"></param>
yangcq88517 0:8e83b9448758 327 /// <param name="length"></param>
yangcq88517 0:8e83b9448758 328 SendFromSocketResponse * SNIC_SendUDPPacket(IPAddress * remoteIP, const int remotePort, const char * payload, const int offset, const int length);
yangcq88517 0:8e83b9448758 329
yangcq88517 0:8e83b9448758 330 /// <summary>
yangcq88517 0:8e83b9448758 331 /// 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.
yangcq88517 0:8e83b9448758 332 /// 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.
yangcq88517 0:8e83b9448758 333 /// 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.
yangcq88517 0:8e83b9448758 334 /// </summary>
yangcq88517 0:8e83b9448758 335 /// <param name="remoteIP"></param>
yangcq88517 0:8e83b9448758 336 /// <param name="remotePort"></param>
yangcq88517 0:8e83b9448758 337 /// <param name="SocketID"></param>
yangcq88517 0:8e83b9448758 338 /// <param name="connectServer"></param>
yangcq88517 0:8e83b9448758 339 /// <param name="payload"></param>
yangcq88517 0:8e83b9448758 340 /// <param name="offset"></param>
yangcq88517 0:8e83b9448758 341 /// <param name="length"></param>
yangcq88517 0:8e83b9448758 342 /// <returns></returns>
yangcq88517 0:8e83b9448758 343 SendFromSocketResponse * SNIC_SendUDPFromSocket(IPAddress * remoteIP, const int remotePort, const char SocketID, const bool connectServer, const char * payload, int offset, const int length);
yangcq88517 0:8e83b9448758 344
yangcq88517 0:8e83b9448758 345 /// <summary>
yangcq88517 0:8e83b9448758 346 /// This command instructs the module to send a HTTP request packet to the remote HTTP server.
yangcq88517 0:8e83b9448758 347 /// 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).
yangcq88517 0:8e83b9448758 348 /// 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.
yangcq88517 0:8e83b9448758 349 /// 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.
yangcq88517 0:8e83b9448758 350 /// The Content length is limited by the receive buffer size specified in SNIC_INIT_REQ and the system resource at that moment.
yangcq88517 0:8e83b9448758 351 /// </summary>
yangcq88517 0:8e83b9448758 352 /// <param name="content"></param>
yangcq88517 0:8e83b9448758 353 /// <param name="isHTTPS"></param>
yangcq88517 0:8e83b9448758 354 /// <param name="chunked"></param>
yangcq88517 0:8e83b9448758 355 /// <returns></returns>
yangcq88517 0:8e83b9448758 356 HTTPResponse * SNIC_SendHTTPRequest(HTTPContent * content, const bool isHTTPS = false, const bool chunked = false);
yangcq88517 0:8e83b9448758 357
yangcq88517 0:8e83b9448758 358 /// <summary>
yangcq88517 0:8e83b9448758 359 /// 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.
yangcq88517 0:8e83b9448758 360 /// </summary>
yangcq88517 0:8e83b9448758 361 /// <param name="content"></param>
yangcq88517 0:8e83b9448758 362 /// <param name="chunked"></param>
yangcq88517 0:8e83b9448758 363 /// <returns></returns>
yangcq88517 0:8e83b9448758 364 HTTPResponse * SNIC_SendHTTPMoreRequest(HTTPContent * content, const bool chunked = false);
yangcq88517 0:8e83b9448758 365
yangcq88517 0:8e83b9448758 366 /// <summary>
yangcq88517 0:8e83b9448758 367 /// 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.
yangcq88517 0:8e83b9448758 368 /// the socket number must get and store separately, since the response payload may change
yangcq88517 0:8e83b9448758 369 /// </summary>
yangcq88517 0:8e83b9448758 370 /// <param name="bing">do not bing if this tcp socket is used as a client</param>
yangcq88517 0:8e83b9448758 371 /// <param name="localIP"></param>
yangcq88517 0:8e83b9448758 372 /// <param name="localPort"></param>
yangcq88517 0:8e83b9448758 373 /// <returns></returns>
yangcq88517 0:8e83b9448758 374 CreateSocketResponse * SNIC_CreateAdvancedTLSTCP(const bool bind, IPAddress * localIP = NULL, const int localPort = 0);
yangcq88517 0:8e83b9448758 375
yangcq88517 0:8e83b9448758 376 /// <summary>
yangcq88517 0:8e83b9448758 377 /// 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.
yangcq88517 0:8e83b9448758 378 /// the socket number must get and store separately, since the response payload may change
yangcq88517 0:8e83b9448758 379 /// </summary>
yangcq88517 0:8e83b9448758 380 /// <param name="bind"></param>
yangcq88517 0:8e83b9448758 381 /// <param name="localIP"></param>
yangcq88517 0:8e83b9448758 382 /// <param name="localPort"></param>
yangcq88517 0:8e83b9448758 383 /// <returns></returns>
yangcq88517 0:8e83b9448758 384 CreateSocketResponse * SNIC_CreateSimpleTLSTCP(const bool bind, IPAddress * localIP = NULL, const int localPort = 0);
yangcq88517 0:8e83b9448758 385
yangcq88517 0:8e83b9448758 386
yangcq88517 0:8e83b9448758 387 };
yangcq88517 0:8e83b9448758 388 }
yangcq88517 0:8e83b9448758 389
yangcq88517 0:8e83b9448758 390 #endif