Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
ISM43362.h
00001 /* ISM43362Interface Example 00002 * Copyright (c) STMicroelectronics 2017 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef ISM43362_H 00018 #define ISM43362_H 00019 #include "ATParser.h" 00020 00021 #define ES_WIFI_MAX_SSID_NAME_SIZE 32 00022 #define ES_WIFI_MAX_PSWD_NAME_SIZE 32 00023 #define ES_WIFI_PRODUCT_ID_SIZE 32 00024 #define ES_WIFI_PRODUCT_NAME_SIZE 32 00025 #define ES_WIFI_FW_REV_SIZE 16 00026 #define ES_WIFI_API_REV_SIZE 16 00027 #define ES_WIFI_STACK_REV_SIZE 16 00028 #define ES_WIFI_RTOS_REV_SIZE 16 00029 00030 // The input range for AT Command 'R1' is 0 to 1200 bytes 00031 // 'R1' Set Read Transport Packet Size (bytes) 00032 #define ES_WIFI_MAX_RX_PACKET_SIZE 1200 00033 // Module maxume DATA payload for Tx packet is 1460 00034 #define ES_WIFI_MAX_TX_PACKET_SIZE 1460 00035 typedef enum ism_security { 00036 ISM_SECURITY_NONE = 0x0, /*!< open access point */ 00037 ISM_SECURITY_WEP = 0x1, /*!< phrase conforms to WEP */ 00038 ISM_SECURITY_WPA = 0x2, /*!< phrase conforms to WPA */ 00039 ISM_SECURITY_WPA2 = 0x3, /*!< phrase conforms to WPA2 */ 00040 ISM_SECURITY_WPA_WPA2 = 0x4, /*!< phrase conforms to WPA/WPA2 */ 00041 ISM_SECURITY_UNKNOWN = 0xFF, /*!< unknown/unsupported security in scan results */ 00042 } ism_security_t; 00043 00044 extern "C" int32_t ParseNumber(char *ptr, uint8_t *cnt); 00045 00046 /** ISM43362Interface class. 00047 This is an interface to a ISM43362 radio. 00048 */ 00049 class ISM43362 { 00050 public: 00051 ISM43362(PinName mosi, PinName miso, PinName clk, PinName nss, PinName resetpin, PinName datareadypin, PinName wakeup, bool debug = false); 00052 00053 /** 00054 * Check firmware version of ISM43362 00055 * 00056 * @return fw version or null if no version is read 00057 */ 00058 uint32_t get_firmware_version(void); 00059 00060 /** 00061 * Reset ISM43362 00062 * 00063 * @return true only if ISM43362 resets successfully 00064 */ 00065 bool reset(void); 00066 00067 /** 00068 * Enable/Disable DHCP 00069 * 00070 * @param enabled DHCP enabled when true 00071 * @return true only if ISM43362 enables/disables DHCP successfully 00072 */ 00073 bool dhcp(bool enabled); 00074 00075 /** 00076 * Connect ISM43362 to AP 00077 * 00078 * @param ap the name of the AP 00079 * @param passPhrase the password of AP 00080 * @param ap_sec the security level of network AP 00081 * @return nsapi_error enum 00082 */ 00083 int connect(const char *ap, const char *passPhrase, ism_security_t ap_sec); 00084 00085 /** 00086 * Disconnect ISM43362 from AP 00087 * 00088 * @return true only if ISM43362 is disconnected successfully 00089 */ 00090 bool disconnect(void); 00091 00092 /** 00093 * Get the IP address of ISM43362 00094 * 00095 * @return null-teriminated IP address or null if no IP address is assigned 00096 */ 00097 const char *getIPAddress(void); 00098 00099 /** 00100 * Get the MAC address of ISM43362 00101 * 00102 * @return null-terminated MAC address or null if no MAC address is assigned 00103 */ 00104 const char *getMACAddress(void); 00105 00106 /** Get the local gateway 00107 * 00108 * @return Null-terminated representation of the local gateway 00109 * or null if no network mask has been recieved 00110 */ 00111 const char *getGateway(); 00112 00113 /** Get the local network mask 00114 * 00115 * @return Null-terminated representation of the local network mask 00116 * or null if no network mask has been recieved 00117 */ 00118 const char *getNetmask(); 00119 00120 /* Return RSSI for active connection 00121 * 00122 * @return Measured RSSI 00123 */ 00124 int8_t getRSSI(); 00125 00126 /** 00127 * Check if ISM43362 is conenected 00128 * 00129 * @return true only if the chip has an IP address 00130 */ 00131 bool isConnected(void); 00132 00133 /** Scan for available networks 00134 * 00135 * @param ap Pointer to allocated array to store discovered AP 00136 * @param limit Size of allocated @a res array, or 0 to only count available AP 00137 * @return Number of entries in @a res, or if @a count was 0 number of available networks, negative on error 00138 * see @a nsapi_error 00139 */ 00140 int scan(WiFiAccessPoint *res, unsigned limit); 00141 00142 /**Perform a dns query 00143 * 00144 * @param name Hostname to resolve 00145 * @param ip Buffer to store IP address 00146 * @return 0 true on success, false on failure 00147 */ 00148 bool dns_lookup(const char *name, char *ip); 00149 00150 /** 00151 * Open a socketed connection 00152 * 00153 * @param type the type of socket to open "UDP" or "TCP" 00154 * @param id id to give the new socket, valid 0-4 00155 * @param port port to open connection with 00156 * @param addr the IP address of the destination 00157 * @return true only if socket opened successfully 00158 */ 00159 bool open(const char *type, int id, const char *addr, int port); 00160 00161 /** 00162 * Sends data to an open socket 00163 * 00164 * @param id id of socket to send to 00165 * @param data data to be sent 00166 * @param amount amount of data to be sent - max 1024 00167 * @return true only if data sent successfully 00168 */ 00169 bool send(int id, const void *data, uint32_t amount); 00170 00171 /** 00172 * Receives data from an open socket 00173 * 00174 * @param id id to receive from 00175 * @param data placeholder for returned information 00176 * @param amount number of bytes to be received 00177 * @return the number of bytes received 00178 */ 00179 int32_t recv(int id, void *data, uint32_t amount); 00180 00181 /** 00182 * Closes a socket 00183 * 00184 * @param id id of socket to close, valid only 0-4 00185 * @return true only if socket is closed successfully 00186 */ 00187 bool close(int id); 00188 00189 /** 00190 * Checks if data is available 00191 */ 00192 bool readable(); 00193 00194 /** 00195 * Checks if data can be written 00196 */ 00197 bool writeable(); 00198 00199 /** 00200 * Attach a function to call whenever network state has changed 00201 * 00202 * @param func A pointer to a void function, or 0 to set as none 00203 */ 00204 void attach(Callback<void()> func); 00205 00206 /** 00207 * Check is datas are available to read for a socket 00208 * @param id socket id 00209 * @param data placeholder for returned information 00210 * @param amount size to read for the check 00211 * @return amount of read value, or -1 for errors 00212 */ 00213 int check_recv_status(int id, void *data); 00214 00215 /** 00216 * Attach a function to call whenever network state has changed 00217 * 00218 * @param obj pointer to the object to call the member function on 00219 * @param method pointer to the member function to call 00220 */ 00221 template <typename T, typename M> 00222 void attach(T *obj, M method) 00223 { 00224 attach(Callback<void()>(obj, method)); 00225 } 00226 00227 private: 00228 BufferedSpi _bufferspi; 00229 ATParser _parser; 00230 DigitalOut _resetpin; 00231 volatile int _active_id; 00232 void print_rx_buff(void); 00233 bool check_response(void); 00234 struct packet { 00235 struct packet *next; 00236 int id; 00237 uint32_t len; 00238 // data follows 00239 } *_packets, * *_packets_end; 00240 void _packet_handler(); 00241 bool _ism_debug; 00242 00243 char _ip_buffer[16]; 00244 char _gateway_buffer[16]; 00245 char _netmask_buffer[16]; 00246 char _mac_buffer[18]; 00247 uint32_t _FwVersionId; 00248 }; 00249 00250 #endif
Generated on Tue Jul 12 2022 19:12:12 by 1.7.2