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:
Wed Mar 16 15:04:46 2016 +0000
Revision:
9:0ce800923eda
Parent:
8:5856c23794b1
bug fix

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