Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Committer:
JimCarver
Date:
Thu Oct 25 14:00:12 2018 +0000
Revision:
4:e518dde96e59
Parent:
0:6b753f761943
Simulated dispenser

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimCarver 0:6b753f761943 1 /* ISM43362 Example
JimCarver 0:6b753f761943 2 *
JimCarver 0:6b753f761943 3 * Copyright (c) STMicroelectronics 2018
JimCarver 0:6b753f761943 4 *
JimCarver 0:6b753f761943 5 * Licensed under the Apache License, Version 2.0 (the "License");
JimCarver 0:6b753f761943 6 * you may not use this file except in compliance with the License.
JimCarver 0:6b753f761943 7 * You may obtain a copy of the License at
JimCarver 0:6b753f761943 8 *
JimCarver 0:6b753f761943 9 * http://www.apache.org/licenses/LICENSE-2.0
JimCarver 0:6b753f761943 10 *
JimCarver 0:6b753f761943 11 * Unless required by applicable law or agreed to in writing, software
JimCarver 0:6b753f761943 12 * distributed under the License is distributed on an "AS IS" BASIS,
JimCarver 0:6b753f761943 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JimCarver 0:6b753f761943 14 * See the License for the specific language governing permissions and
JimCarver 0:6b753f761943 15 * limitations under the License.
JimCarver 0:6b753f761943 16 */
JimCarver 0:6b753f761943 17 #include <string.h>
JimCarver 0:6b753f761943 18 #include "ISM43362.h"
JimCarver 0:6b753f761943 19 #include "mbed_debug.h"
JimCarver 0:6b753f761943 20
JimCarver 0:6b753f761943 21 // activate / de-activate debug
JimCarver 0:6b753f761943 22 #define ism_debug 0
JimCarver 0:6b753f761943 23
JimCarver 0:6b753f761943 24 ISM43362::ISM43362(PinName mosi, PinName miso, PinName sclk, PinName nss, PinName resetpin, PinName datareadypin, PinName wakeup, bool debug)
JimCarver 0:6b753f761943 25 : _bufferspi(mosi, miso, sclk, nss, datareadypin),
JimCarver 0:6b753f761943 26 _parser(_bufferspi),
JimCarver 0:6b753f761943 27 _resetpin(resetpin),
JimCarver 0:6b753f761943 28 _packets(0), _packets_end(&_packets)
JimCarver 0:6b753f761943 29 {
JimCarver 0:6b753f761943 30 DigitalOut wakeup_pin(wakeup);
JimCarver 0:6b753f761943 31 _bufferspi.format(16, 0); /* 16bits, ploarity low, phase 1Edge, master mode */
JimCarver 0:6b753f761943 32 _bufferspi.frequency(20000000); /* up to 20 MHz */
JimCarver 0:6b753f761943 33 _active_id = 0xFF;
JimCarver 0:6b753f761943 34 _FwVersionId = 0;
JimCarver 0:6b753f761943 35
JimCarver 0:6b753f761943 36 _ism_debug = debug || ism_debug;
JimCarver 0:6b753f761943 37 reset();
JimCarver 0:6b753f761943 38 }
JimCarver 0:6b753f761943 39
JimCarver 0:6b753f761943 40 /**
JimCarver 0:6b753f761943 41 * @brief Parses and returns number from string.
JimCarver 0:6b753f761943 42 * @param ptr: pointer to string
JimCarver 0:6b753f761943 43 * @param cnt: pointer to the number of parsed digit
JimCarver 0:6b753f761943 44 * @retval integer value.
JimCarver 0:6b753f761943 45 */
JimCarver 0:6b753f761943 46 #define CHARISHEXNUM(x) (((x) >= '0' && (x) <= '9') || \
JimCarver 0:6b753f761943 47 ((x) >= 'a' && (x) <= 'f') || \
JimCarver 0:6b753f761943 48 ((x) >= 'A' && (x) <= 'F'))
JimCarver 0:6b753f761943 49 #define CHARISNUM(x) ((x) >= '0' && (x) <= '9')
JimCarver 0:6b753f761943 50 #define CHAR2NUM(x) ((x) - '0')
JimCarver 0:6b753f761943 51
JimCarver 0:6b753f761943 52
JimCarver 0:6b753f761943 53 extern "C" int32_t ParseNumber(char *ptr, uint8_t *cnt)
JimCarver 0:6b753f761943 54 {
JimCarver 0:6b753f761943 55 uint8_t minus = 0, i = 0;
JimCarver 0:6b753f761943 56 int32_t sum = 0;
JimCarver 0:6b753f761943 57
JimCarver 0:6b753f761943 58 if (*ptr == '-') { /* Check for minus character */
JimCarver 0:6b753f761943 59 minus = 1;
JimCarver 0:6b753f761943 60 ptr++;
JimCarver 0:6b753f761943 61 i++;
JimCarver 0:6b753f761943 62 }
JimCarver 0:6b753f761943 63 if (*ptr == 'C') { /* input string from get_firmware_version is Cx.x.x.x */
JimCarver 0:6b753f761943 64 ptr++;
JimCarver 0:6b753f761943 65 }
JimCarver 0:6b753f761943 66
JimCarver 0:6b753f761943 67 while (CHARISNUM(*ptr) || (*ptr == '.')) { /* Parse number */
JimCarver 0:6b753f761943 68 if (*ptr == '.') {
JimCarver 0:6b753f761943 69 ptr++; // next char
JimCarver 0:6b753f761943 70 } else {
JimCarver 0:6b753f761943 71 sum = 10 * sum + CHAR2NUM(*ptr);
JimCarver 0:6b753f761943 72 ptr++;
JimCarver 0:6b753f761943 73 i++;
JimCarver 0:6b753f761943 74 }
JimCarver 0:6b753f761943 75 }
JimCarver 0:6b753f761943 76
JimCarver 0:6b753f761943 77 if (cnt != NULL) { /* Save number of characters used for number */
JimCarver 0:6b753f761943 78 *cnt = i;
JimCarver 0:6b753f761943 79 }
JimCarver 0:6b753f761943 80 if (minus) { /* Minus detected */
JimCarver 0:6b753f761943 81 return 0 - sum;
JimCarver 0:6b753f761943 82 }
JimCarver 0:6b753f761943 83 return sum; /* Return number */
JimCarver 0:6b753f761943 84 }
JimCarver 0:6b753f761943 85
JimCarver 0:6b753f761943 86 uint32_t ISM43362::get_firmware_version(void)
JimCarver 0:6b753f761943 87 {
JimCarver 0:6b753f761943 88 char tmp_buffer[250];
JimCarver 0:6b753f761943 89 char *ptr, *ptr2;
JimCarver 0:6b753f761943 90 char _fw_version[16];
JimCarver 0:6b753f761943 91
JimCarver 0:6b753f761943 92 /* Use %[^\n] instead of %s to allow having spaces in the string */
JimCarver 0:6b753f761943 93 if (!(_parser.send("I?") && _parser.recv("%[^\n^\r]\r\n", tmp_buffer) && check_response())) {
JimCarver 0:6b753f761943 94 debug_if(_ism_debug, "ISM43362: get_firmware_version is FAIL\r\n");
JimCarver 0:6b753f761943 95 return 0;
JimCarver 0:6b753f761943 96 }
JimCarver 0:6b753f761943 97 debug_if(_ism_debug, "ISM43362: get_firmware_version = %s\r\n", tmp_buffer);
JimCarver 0:6b753f761943 98
JimCarver 0:6b753f761943 99 // Get the first version in the string
JimCarver 0:6b753f761943 100 ptr = strtok((char *)tmp_buffer, ",");
JimCarver 0:6b753f761943 101 ptr = strtok(NULL, ",");
JimCarver 0:6b753f761943 102 ptr2 = strtok(NULL, ",");
JimCarver 0:6b753f761943 103 if (ptr == NULL) {
JimCarver 0:6b753f761943 104 debug_if(_ism_debug, "ISM43362: get_firmware_version decoding is FAIL\r\n");
JimCarver 0:6b753f761943 105 return 0;
JimCarver 0:6b753f761943 106 }
JimCarver 0:6b753f761943 107 strncpy(_fw_version, ptr, ptr2 - ptr);
JimCarver 0:6b753f761943 108 _FwVersionId = ParseNumber(_fw_version, NULL);
JimCarver 0:6b753f761943 109
JimCarver 0:6b753f761943 110 return _FwVersionId;
JimCarver 0:6b753f761943 111 }
JimCarver 0:6b753f761943 112
JimCarver 0:6b753f761943 113 bool ISM43362::reset(void)
JimCarver 0:6b753f761943 114 {
JimCarver 0:6b753f761943 115 char tmp_buffer[100];
JimCarver 0:6b753f761943 116 debug_if(_ism_debug, "ISM43362: Reset Module\r\n");
JimCarver 0:6b753f761943 117 _resetpin = 0;
JimCarver 0:6b753f761943 118 wait_ms(10);
JimCarver 0:6b753f761943 119 _resetpin = 1;
JimCarver 0:6b753f761943 120 wait_ms(500);
JimCarver 0:6b753f761943 121
JimCarver 0:6b753f761943 122 /* Wait for prompt line : the string is "> ". */
JimCarver 0:6b753f761943 123 /* As the space char is not detected by sscanf function in parser.recv, */
JimCarver 0:6b753f761943 124 /* we need to use %[\n] */
JimCarver 0:6b753f761943 125 if (!_parser.recv(">%[^\n]", tmp_buffer)) {
JimCarver 0:6b753f761943 126 debug_if(_ism_debug, "ISM43362: Reset Module failed\r\n");
JimCarver 0:6b753f761943 127 return false;
JimCarver 0:6b753f761943 128 }
JimCarver 0:6b753f761943 129 return true;
JimCarver 0:6b753f761943 130 }
JimCarver 0:6b753f761943 131
JimCarver 0:6b753f761943 132 void ISM43362::print_rx_buff(void)
JimCarver 0:6b753f761943 133 {
JimCarver 0:6b753f761943 134 char tmp[150] = {0};
JimCarver 0:6b753f761943 135 uint16_t i = 0;
JimCarver 0:6b753f761943 136 debug_if(_ism_debug, "ISM43362: ");
JimCarver 0:6b753f761943 137 while (i < 150) {
JimCarver 0:6b753f761943 138 int c = _parser.getc();
JimCarver 0:6b753f761943 139 if (c < 0) {
JimCarver 0:6b753f761943 140 break;
JimCarver 0:6b753f761943 141 }
JimCarver 0:6b753f761943 142 tmp[i] = c;
JimCarver 0:6b753f761943 143 debug_if(_ism_debug, "0x%2X ", c);
JimCarver 0:6b753f761943 144 i++;
JimCarver 0:6b753f761943 145 }
JimCarver 0:6b753f761943 146 debug_if(_ism_debug, "\n");
JimCarver 0:6b753f761943 147 debug_if(_ism_debug, "ISM43362: Buffer content =====%s=====\r\n", tmp);
JimCarver 0:6b753f761943 148 }
JimCarver 0:6b753f761943 149
JimCarver 0:6b753f761943 150 /* checks the standard OK response of the WIFI module, shouldbe:
JimCarver 0:6b753f761943 151 * \r\nDATA\r\nOK\r\n>sp
JimCarver 0:6b753f761943 152 * or
JimCarver 0:6b753f761943 153 * \r\nERROR\r\nUSAGE\r\n>sp
JimCarver 0:6b753f761943 154 * function returns true if OK, false otherwise. In case of error,
JimCarver 0:6b753f761943 155 * print error content then flush buffer */
JimCarver 0:6b753f761943 156 bool ISM43362::check_response(void)
JimCarver 0:6b753f761943 157 {
JimCarver 0:6b753f761943 158 char tmp_buffer[100];
JimCarver 0:6b753f761943 159 if (!_parser.recv("OK\r\n")) {
JimCarver 0:6b753f761943 160 print_rx_buff();
JimCarver 0:6b753f761943 161 _parser.flush();
JimCarver 0:6b753f761943 162 return false;
JimCarver 0:6b753f761943 163 }
JimCarver 0:6b753f761943 164
JimCarver 0:6b753f761943 165 /* Then we should get the prompt: "> " */
JimCarver 0:6b753f761943 166 /* As the space char is not detected by sscanf function in parser.recv, */
JimCarver 0:6b753f761943 167 /* we need to use %[\n] */
JimCarver 0:6b753f761943 168 if (!_parser.recv(">%[^\n]", tmp_buffer)) {
JimCarver 0:6b753f761943 169 debug_if(_ism_debug, "ISM43362: Missing prompt in WIFI resp\r\n");
JimCarver 0:6b753f761943 170 print_rx_buff();
JimCarver 0:6b753f761943 171 _parser.flush();
JimCarver 0:6b753f761943 172 return false;
JimCarver 0:6b753f761943 173 }
JimCarver 0:6b753f761943 174
JimCarver 0:6b753f761943 175 /* Inventek module do stuffing / padding of data with 0x15,
JimCarver 0:6b753f761943 176 * in case buffer contains such */
JimCarver 0:6b753f761943 177 while (1) {
JimCarver 0:6b753f761943 178 int c = _parser.getc();
JimCarver 0:6b753f761943 179 if (c == 0x15) {
JimCarver 0:6b753f761943 180 // debug_if(_ism_debug, "ISM43362: Flush char 0x%x\n", c);
JimCarver 0:6b753f761943 181 continue;
JimCarver 0:6b753f761943 182 } else {
JimCarver 0:6b753f761943 183 /* How to put it back if needed ? */
JimCarver 0:6b753f761943 184 break;
JimCarver 0:6b753f761943 185 }
JimCarver 0:6b753f761943 186 }
JimCarver 0:6b753f761943 187 return true;
JimCarver 0:6b753f761943 188 }
JimCarver 0:6b753f761943 189
JimCarver 0:6b753f761943 190 bool ISM43362::dhcp(bool enabled)
JimCarver 0:6b753f761943 191 {
JimCarver 0:6b753f761943 192 return (_parser.send("C4=%d", enabled ? 1 : 0) && check_response());
JimCarver 0:6b753f761943 193 }
JimCarver 0:6b753f761943 194
JimCarver 0:6b753f761943 195 int ISM43362::connect(const char *ap, const char *passPhrase, ism_security_t ap_sec)
JimCarver 0:6b753f761943 196 {
JimCarver 0:6b753f761943 197 char tmp[256];
JimCarver 0:6b753f761943 198
JimCarver 0:6b753f761943 199 if (!(_parser.send("C1=%s", ap) && check_response())) {
JimCarver 0:6b753f761943 200 return NSAPI_ERROR_PARAMETER;
JimCarver 0:6b753f761943 201 }
JimCarver 0:6b753f761943 202
JimCarver 0:6b753f761943 203 if (!(_parser.send("C2=%s", passPhrase) && check_response())) {
JimCarver 0:6b753f761943 204 return NSAPI_ERROR_PARAMETER;
JimCarver 0:6b753f761943 205 }
JimCarver 0:6b753f761943 206
JimCarver 0:6b753f761943 207 /* Check security level is acceptable */
JimCarver 0:6b753f761943 208 if (ap_sec > ISM_SECURITY_WPA_WPA2) {
JimCarver 0:6b753f761943 209 debug_if(_ism_debug, "ISM43362: Unsupported security level %d\n", ap_sec);
JimCarver 0:6b753f761943 210 return NSAPI_ERROR_UNSUPPORTED;
JimCarver 0:6b753f761943 211 }
JimCarver 0:6b753f761943 212
JimCarver 0:6b753f761943 213 if (!(_parser.send("C3=%d", ap_sec) && check_response())) {
JimCarver 0:6b753f761943 214 return NSAPI_ERROR_PARAMETER;
JimCarver 0:6b753f761943 215 }
JimCarver 0:6b753f761943 216
JimCarver 0:6b753f761943 217 if (_parser.send("C0")) {
JimCarver 0:6b753f761943 218 while (_parser.recv("%[^\n]\n", tmp)) {
JimCarver 0:6b753f761943 219 if (strstr(tmp, "OK")) {
JimCarver 0:6b753f761943 220 _parser.flush();
JimCarver 0:6b753f761943 221 return NSAPI_ERROR_OK;
JimCarver 0:6b753f761943 222 }
JimCarver 0:6b753f761943 223 if (strstr(tmp, "JOIN")) {
JimCarver 0:6b753f761943 224 if (strstr(tmp, "Failed")) {
JimCarver 0:6b753f761943 225 _parser.flush();
JimCarver 0:6b753f761943 226 return NSAPI_ERROR_AUTH_FAILURE;
JimCarver 0:6b753f761943 227 }
JimCarver 0:6b753f761943 228 }
JimCarver 0:6b753f761943 229 }
JimCarver 0:6b753f761943 230 }
JimCarver 0:6b753f761943 231
JimCarver 0:6b753f761943 232 return NSAPI_ERROR_NO_CONNECTION;
JimCarver 0:6b753f761943 233 }
JimCarver 0:6b753f761943 234
JimCarver 0:6b753f761943 235 bool ISM43362::disconnect(void)
JimCarver 0:6b753f761943 236 {
JimCarver 0:6b753f761943 237 return (_parser.send("CD") && check_response());
JimCarver 0:6b753f761943 238 }
JimCarver 0:6b753f761943 239
JimCarver 0:6b753f761943 240 const char *ISM43362::getIPAddress(void)
JimCarver 0:6b753f761943 241 {
JimCarver 0:6b753f761943 242 char tmp_ip_buffer[250];
JimCarver 0:6b753f761943 243 char *ptr, *ptr2;
JimCarver 0:6b753f761943 244
JimCarver 0:6b753f761943 245 /* Use %[^\n] instead of %s to allow having spaces in the string */
JimCarver 0:6b753f761943 246 if (!(_parser.send("C?")
JimCarver 0:6b753f761943 247 && _parser.recv("%[^\n^\r]\r\n", tmp_ip_buffer)
JimCarver 0:6b753f761943 248 && check_response())) {
JimCarver 0:6b753f761943 249 debug_if(_ism_debug, "ISM43362: getIPAddress LINE KO: %s\n", tmp_ip_buffer);
JimCarver 0:6b753f761943 250 return 0;
JimCarver 0:6b753f761943 251 }
JimCarver 0:6b753f761943 252
JimCarver 0:6b753f761943 253 /* Get the IP address in the result */
JimCarver 0:6b753f761943 254 /* TODO : check if the begining of the string is always = "eS-WiFi_AP_C47F51011231," */
JimCarver 0:6b753f761943 255 ptr = strtok((char *)tmp_ip_buffer, ",");
JimCarver 0:6b753f761943 256 ptr = strtok(NULL, ",");
JimCarver 0:6b753f761943 257 ptr = strtok(NULL, ",");
JimCarver 0:6b753f761943 258 ptr = strtok(NULL, ",");
JimCarver 0:6b753f761943 259 ptr = strtok(NULL, ",");
JimCarver 0:6b753f761943 260 ptr = strtok(NULL, ",");
JimCarver 0:6b753f761943 261 ptr2 = strtok(NULL, ",");
JimCarver 0:6b753f761943 262 if (ptr == NULL) {
JimCarver 0:6b753f761943 263 return 0;
JimCarver 0:6b753f761943 264 }
JimCarver 0:6b753f761943 265 strncpy(_ip_buffer, ptr, ptr2 - ptr);
JimCarver 0:6b753f761943 266
JimCarver 0:6b753f761943 267 tmp_ip_buffer[59] = 0;
JimCarver 0:6b753f761943 268 debug_if(_ism_debug, "ISM43362: receivedIPAddress: %s\n", _ip_buffer);
JimCarver 0:6b753f761943 269
JimCarver 0:6b753f761943 270 return _ip_buffer;
JimCarver 0:6b753f761943 271 }
JimCarver 0:6b753f761943 272
JimCarver 0:6b753f761943 273 const char *ISM43362::getMACAddress(void)
JimCarver 0:6b753f761943 274 {
JimCarver 0:6b753f761943 275 if (!(_parser.send("Z5") && _parser.recv("%s\r\n", _mac_buffer) && check_response())) {
JimCarver 0:6b753f761943 276 debug_if(_ism_debug, "ISM43362: receivedMacAddress LINE KO: %s\n", _mac_buffer);
JimCarver 0:6b753f761943 277 return 0;
JimCarver 0:6b753f761943 278 }
JimCarver 0:6b753f761943 279
JimCarver 0:6b753f761943 280 debug_if(_ism_debug, "ISM43362: receivedMacAddress:%s, size=%d\r\n", _mac_buffer, sizeof(_mac_buffer));
JimCarver 0:6b753f761943 281
JimCarver 0:6b753f761943 282 return _mac_buffer;
JimCarver 0:6b753f761943 283 }
JimCarver 0:6b753f761943 284
JimCarver 0:6b753f761943 285 const char *ISM43362::getGateway()
JimCarver 0:6b753f761943 286 {
JimCarver 0:6b753f761943 287 char tmp[250];
JimCarver 0:6b753f761943 288 /* Use %[^\n] instead of %s to allow having spaces in the string */
JimCarver 0:6b753f761943 289 if (!(_parser.send("C?") && _parser.recv("%[^\n^\r]\r\n", tmp) && check_response())) {
JimCarver 0:6b753f761943 290 debug_if(_ism_debug, "ISM43362: getGateway LINE KO: %s\r\n", tmp);
JimCarver 0:6b753f761943 291 return 0;
JimCarver 0:6b753f761943 292 }
JimCarver 0:6b753f761943 293
JimCarver 0:6b753f761943 294 /* Extract the Gateway in the received buffer */
JimCarver 0:6b753f761943 295 char *ptr;
JimCarver 0:6b753f761943 296 ptr = strtok(tmp, ",");
JimCarver 0:6b753f761943 297 for (int i = 0; i < 7; i++) {
JimCarver 0:6b753f761943 298 if (ptr == NULL) {
JimCarver 0:6b753f761943 299 break;
JimCarver 0:6b753f761943 300 }
JimCarver 0:6b753f761943 301 ptr = strtok(NULL, ",");
JimCarver 0:6b753f761943 302 }
JimCarver 0:6b753f761943 303
JimCarver 0:6b753f761943 304 strncpy(_gateway_buffer, ptr, sizeof(_gateway_buffer));
JimCarver 0:6b753f761943 305
JimCarver 0:6b753f761943 306 debug_if(_ism_debug, "ISM43362: getGateway: %s\r\n", _gateway_buffer);
JimCarver 0:6b753f761943 307
JimCarver 0:6b753f761943 308 return _gateway_buffer;
JimCarver 0:6b753f761943 309 }
JimCarver 0:6b753f761943 310
JimCarver 0:6b753f761943 311 const char *ISM43362::getNetmask()
JimCarver 0:6b753f761943 312 {
JimCarver 0:6b753f761943 313 char tmp[250];
JimCarver 0:6b753f761943 314 /* Use %[^\n] instead of %s to allow having spaces in the string */
JimCarver 0:6b753f761943 315 if (!(_parser.send("C?") && _parser.recv("%[^\n^\r]\r\n", tmp) && check_response())) {
JimCarver 0:6b753f761943 316 debug_if(_ism_debug, "ISM43362: getNetmask LINE KO: %s\n", tmp);
JimCarver 0:6b753f761943 317 return 0;
JimCarver 0:6b753f761943 318 }
JimCarver 0:6b753f761943 319
JimCarver 0:6b753f761943 320 /* Extract Netmask in the received buffer */
JimCarver 0:6b753f761943 321 char *ptr;
JimCarver 0:6b753f761943 322 ptr = strtok(tmp, ",");
JimCarver 0:6b753f761943 323 for (int i = 0; i < 6; i++) {
JimCarver 0:6b753f761943 324 if (ptr == NULL) {
JimCarver 0:6b753f761943 325 break;
JimCarver 0:6b753f761943 326 }
JimCarver 0:6b753f761943 327 ptr = strtok(NULL, ",");
JimCarver 0:6b753f761943 328 }
JimCarver 0:6b753f761943 329
JimCarver 0:6b753f761943 330 strncpy(_netmask_buffer, ptr, sizeof(_netmask_buffer));
JimCarver 0:6b753f761943 331
JimCarver 0:6b753f761943 332 debug_if(_ism_debug, "ISM43362: getNetmask: %s\r\n", _netmask_buffer);
JimCarver 0:6b753f761943 333
JimCarver 0:6b753f761943 334 return _netmask_buffer;
JimCarver 0:6b753f761943 335 }
JimCarver 0:6b753f761943 336
JimCarver 0:6b753f761943 337 int8_t ISM43362::getRSSI()
JimCarver 0:6b753f761943 338 {
JimCarver 0:6b753f761943 339 int8_t rssi;
JimCarver 0:6b753f761943 340 char tmp[25];
JimCarver 0:6b753f761943 341
JimCarver 0:6b753f761943 342 if (!(_parser.send("CR") && _parser.recv("%s\r\n", tmp) && check_response())) {
JimCarver 0:6b753f761943 343 debug_if(_ism_debug, "ISM43362: getRSSI LINE KO: %s\r\n", tmp);
JimCarver 0:6b753f761943 344 return 0;
JimCarver 0:6b753f761943 345 }
JimCarver 0:6b753f761943 346
JimCarver 0:6b753f761943 347 rssi = ParseNumber(tmp, NULL);
JimCarver 0:6b753f761943 348
JimCarver 0:6b753f761943 349 debug_if(_ism_debug, "ISM43362: getRSSI: %d\r\n", rssi);
JimCarver 0:6b753f761943 350
JimCarver 0:6b753f761943 351 return rssi;
JimCarver 0:6b753f761943 352 }
JimCarver 0:6b753f761943 353 /**
JimCarver 0:6b753f761943 354 * @brief Parses Security type.
JimCarver 0:6b753f761943 355 * @param ptr: pointer to string
JimCarver 0:6b753f761943 356 * @retval Encryption type.
JimCarver 0:6b753f761943 357 */
JimCarver 0:6b753f761943 358 extern "C" nsapi_security_t ParseSecurity(char *ptr)
JimCarver 0:6b753f761943 359 {
JimCarver 0:6b753f761943 360 if (strstr(ptr, "Open")) {
JimCarver 0:6b753f761943 361 return NSAPI_SECURITY_NONE;
JimCarver 0:6b753f761943 362 } else if (strstr(ptr, "WEP")) {
JimCarver 0:6b753f761943 363 return NSAPI_SECURITY_WEP;
JimCarver 0:6b753f761943 364 } else if (strstr(ptr, "WPA2 AES")) {
JimCarver 0:6b753f761943 365 return NSAPI_SECURITY_WPA2;
JimCarver 0:6b753f761943 366 } else if (strstr(ptr, "WPA WPA2")) {
JimCarver 0:6b753f761943 367 return NSAPI_SECURITY_WPA_WPA2;
JimCarver 0:6b753f761943 368 } else if (strstr(ptr, "WPA2 TKIP")) {
JimCarver 0:6b753f761943 369 return NSAPI_SECURITY_UNKNOWN; // no match in mbed
JimCarver 0:6b753f761943 370 } else if (strstr(ptr, "WPA2")) {
JimCarver 0:6b753f761943 371 return NSAPI_SECURITY_WPA2; // catch any other WPA2 formula
JimCarver 0:6b753f761943 372 } else if (strstr(ptr, "WPA")) {
JimCarver 0:6b753f761943 373 return NSAPI_SECURITY_WPA;
JimCarver 0:6b753f761943 374 } else {
JimCarver 0:6b753f761943 375 return NSAPI_SECURITY_UNKNOWN;
JimCarver 0:6b753f761943 376 }
JimCarver 0:6b753f761943 377 }
JimCarver 0:6b753f761943 378
JimCarver 0:6b753f761943 379 /**
JimCarver 0:6b753f761943 380 * @brief Convert char in Hex format to integer.
JimCarver 0:6b753f761943 381 * @param a: character to convert
JimCarver 0:6b753f761943 382 * @retval integer value.
JimCarver 0:6b753f761943 383 */
JimCarver 0:6b753f761943 384 extern "C" uint8_t Hex2Num(char a)
JimCarver 0:6b753f761943 385 {
JimCarver 0:6b753f761943 386 if (a >= '0' && a <= '9') { /* Char is num */
JimCarver 0:6b753f761943 387 return a - '0';
JimCarver 0:6b753f761943 388 } else if (a >= 'a' && a <= 'f') { /* Char is lowercase character A - Z (hex) */
JimCarver 0:6b753f761943 389 return (a - 'a') + 10;
JimCarver 0:6b753f761943 390 } else if (a >= 'A' && a <= 'F') { /* Char is uppercase character A - Z (hex) */
JimCarver 0:6b753f761943 391 return (a - 'A') + 10;
JimCarver 0:6b753f761943 392 }
JimCarver 0:6b753f761943 393
JimCarver 0:6b753f761943 394 return 0;
JimCarver 0:6b753f761943 395 }
JimCarver 0:6b753f761943 396
JimCarver 0:6b753f761943 397 /**
JimCarver 0:6b753f761943 398 * @brief Extract a hex number from a string.
JimCarver 0:6b753f761943 399 * @param ptr: pointer to string
JimCarver 0:6b753f761943 400 * @param cnt: pointer to the number of parsed digit
JimCarver 0:6b753f761943 401 * @retval Hex value.
JimCarver 0:6b753f761943 402 */
JimCarver 0:6b753f761943 403 extern "C" uint32_t ParseHexNumber(char *ptr, uint8_t *cnt)
JimCarver 0:6b753f761943 404 {
JimCarver 0:6b753f761943 405 uint32_t sum = 0;
JimCarver 0:6b753f761943 406 uint8_t i = 0;
JimCarver 0:6b753f761943 407
JimCarver 0:6b753f761943 408 while (CHARISHEXNUM(*ptr)) { /* Parse number */
JimCarver 0:6b753f761943 409 sum <<= 4;
JimCarver 0:6b753f761943 410 sum += Hex2Num(*ptr);
JimCarver 0:6b753f761943 411 ptr++;
JimCarver 0:6b753f761943 412 i++;
JimCarver 0:6b753f761943 413 }
JimCarver 0:6b753f761943 414
JimCarver 0:6b753f761943 415 if (cnt != NULL) { /* Save number of characters used for number */
JimCarver 0:6b753f761943 416 *cnt = i;
JimCarver 0:6b753f761943 417 }
JimCarver 0:6b753f761943 418 return sum; /* Return number */
JimCarver 0:6b753f761943 419 }
JimCarver 0:6b753f761943 420
JimCarver 0:6b753f761943 421 bool ISM43362::isConnected(void)
JimCarver 0:6b753f761943 422 {
JimCarver 0:6b753f761943 423 return getIPAddress() != 0;
JimCarver 0:6b753f761943 424 }
JimCarver 0:6b753f761943 425
JimCarver 0:6b753f761943 426 int ISM43362::scan(WiFiAccessPoint *res, unsigned limit)
JimCarver 0:6b753f761943 427 {
JimCarver 0:6b753f761943 428 unsigned cnt = 0, num = 0;
JimCarver 0:6b753f761943 429 char *ptr;
JimCarver 0:6b753f761943 430 char tmp[256];
JimCarver 0:6b753f761943 431
JimCarver 0:6b753f761943 432 if (!(_parser.send("F0"))) {
JimCarver 0:6b753f761943 433 debug_if(_ism_debug, "ISM43362: scan error\r\n");
JimCarver 0:6b753f761943 434 return 0;
JimCarver 0:6b753f761943 435 }
JimCarver 0:6b753f761943 436
JimCarver 0:6b753f761943 437 /* Parse the received buffer and fill AP buffer */
JimCarver 0:6b753f761943 438 /* Use %[^\n] instead of %s to allow having spaces in the string */
JimCarver 0:6b753f761943 439 while (_parser.recv("#%[^\n]\n", tmp)) {
JimCarver 0:6b753f761943 440 if (limit != 0 && cnt >= limit) {
JimCarver 0:6b753f761943 441 /* reached end */
JimCarver 0:6b753f761943 442 break;
JimCarver 0:6b753f761943 443 }
JimCarver 0:6b753f761943 444 nsapi_wifi_ap_t ap = {0};
JimCarver 0:6b753f761943 445 debug_if(_ism_debug, "ISM43362: received:%s\n", tmp);
JimCarver 0:6b753f761943 446 ptr = strtok(tmp, ",");
JimCarver 0:6b753f761943 447 num = 0;
JimCarver 0:6b753f761943 448 while (ptr != NULL) {
JimCarver 0:6b753f761943 449 switch (num++) {
JimCarver 0:6b753f761943 450 case 0: /* Ignore index */
JimCarver 0:6b753f761943 451 case 4: /* Ignore Max Rate */
JimCarver 0:6b753f761943 452 case 5: /* Ignore Network Type */
JimCarver 0:6b753f761943 453 case 7: /* Ignore Radio Band */
JimCarver 0:6b753f761943 454 break;
JimCarver 0:6b753f761943 455 case 1:
JimCarver 0:6b753f761943 456 ptr[strlen(ptr) - 1] = 0;
JimCarver 0:6b753f761943 457 strncpy((char *)ap.ssid, ptr + 1, 32);
JimCarver 0:6b753f761943 458 break;
JimCarver 0:6b753f761943 459 case 2:
JimCarver 0:6b753f761943 460 for (int i = 0; i < 6; i++) {
JimCarver 0:6b753f761943 461 ap.bssid[i] = ParseHexNumber(ptr + (i * 3), NULL);
JimCarver 0:6b753f761943 462 }
JimCarver 0:6b753f761943 463 break;
JimCarver 0:6b753f761943 464 case 3:
JimCarver 0:6b753f761943 465 ap.rssi = ParseNumber(ptr, NULL);
JimCarver 0:6b753f761943 466 break;
JimCarver 0:6b753f761943 467 case 6:
JimCarver 0:6b753f761943 468 ap.security = ParseSecurity(ptr);
JimCarver 0:6b753f761943 469 break;
JimCarver 0:6b753f761943 470 case 8:
JimCarver 0:6b753f761943 471 ap.channel = ParseNumber(ptr, NULL);
JimCarver 0:6b753f761943 472 num = 1;
JimCarver 0:6b753f761943 473 break;
JimCarver 0:6b753f761943 474 default:
JimCarver 0:6b753f761943 475 break;
JimCarver 0:6b753f761943 476 }
JimCarver 0:6b753f761943 477 ptr = strtok(NULL, ",");
JimCarver 0:6b753f761943 478 }
JimCarver 0:6b753f761943 479 if (res != NULL) {
JimCarver 0:6b753f761943 480 res[cnt] = WiFiAccessPoint(ap);
JimCarver 0:6b753f761943 481 }
JimCarver 0:6b753f761943 482 cnt++;
JimCarver 0:6b753f761943 483 }
JimCarver 0:6b753f761943 484
JimCarver 0:6b753f761943 485 /* We may stop before having read all the APs list, so flush the rest of
JimCarver 0:6b753f761943 486 * it as well as OK commands */
JimCarver 0:6b753f761943 487 _parser.flush();
JimCarver 0:6b753f761943 488
JimCarver 0:6b753f761943 489 debug_if(_ism_debug, "ISM43362: End of Scan: cnt=%d\n", cnt);
JimCarver 0:6b753f761943 490
JimCarver 0:6b753f761943 491 return cnt;
JimCarver 0:6b753f761943 492
JimCarver 0:6b753f761943 493 }
JimCarver 0:6b753f761943 494
JimCarver 0:6b753f761943 495 bool ISM43362::open(const char *type, int id, const char *addr, int port)
JimCarver 0:6b753f761943 496 {
JimCarver 0:6b753f761943 497 /* TODO : This is the implementation for the client socket, need to check if need to create openserver too */
JimCarver 0:6b753f761943 498 //IDs only 0-3
JimCarver 0:6b753f761943 499 if ((id < 0) || (id > 3)) {
JimCarver 0:6b753f761943 500 debug_if(_ism_debug, "ISM43362: open: wrong id\n");
JimCarver 0:6b753f761943 501 return false;
JimCarver 0:6b753f761943 502 }
JimCarver 0:6b753f761943 503 /* Set communication socket */
JimCarver 0:6b753f761943 504 _active_id = id;
JimCarver 0:6b753f761943 505 if (!(_parser.send("P0=%d", id) && check_response())) {
JimCarver 0:6b753f761943 506 debug_if(_ism_debug, "ISM43362: open: P0 issue\n");
JimCarver 0:6b753f761943 507 return false;
JimCarver 0:6b753f761943 508 }
JimCarver 0:6b753f761943 509 /* Set protocol */
JimCarver 0:6b753f761943 510 if (!(_parser.send("P1=%s", type) && check_response())) {
JimCarver 0:6b753f761943 511 debug_if(_ism_debug, "ISM43362: open: P1 issue\n");
JimCarver 0:6b753f761943 512 return false;
JimCarver 0:6b753f761943 513 }
JimCarver 0:6b753f761943 514 /* Set address */
JimCarver 0:6b753f761943 515 if (!(_parser.send("P3=%s", addr) && check_response())) {
JimCarver 0:6b753f761943 516 debug_if(_ism_debug, "ISM43362: open: P3 issue\n");
JimCarver 0:6b753f761943 517 return false;
JimCarver 0:6b753f761943 518 }
JimCarver 0:6b753f761943 519 if (!(_parser.send("P4=%d", port) && check_response())) {
JimCarver 0:6b753f761943 520 debug_if(_ism_debug, "ISM43362: open: P4 issue\n");
JimCarver 0:6b753f761943 521 return false;
JimCarver 0:6b753f761943 522 }
JimCarver 0:6b753f761943 523 /* Start client */
JimCarver 0:6b753f761943 524 if (!(_parser.send("P6=1") && check_response())) {
JimCarver 0:6b753f761943 525 debug_if(_ism_debug, "ISM43362: open: P6 issue\n");
JimCarver 0:6b753f761943 526 return false;
JimCarver 0:6b753f761943 527 }
JimCarver 0:6b753f761943 528
JimCarver 0:6b753f761943 529 /* request as much data as possible - i.e. module max size */
JimCarver 0:6b753f761943 530 if (!(_parser.send("R1=%d", ES_WIFI_MAX_RX_PACKET_SIZE) && check_response())) {
JimCarver 0:6b753f761943 531 debug_if(_ism_debug, "ISM43362: open: R1 issue\n");
JimCarver 0:6b753f761943 532 return -1;
JimCarver 0:6b753f761943 533 }
JimCarver 0:6b753f761943 534
JimCarver 0:6b753f761943 535 /* Non blocking mode : set Read Transport Timeout to 1ms */
JimCarver 0:6b753f761943 536 if (!(_parser.send("R2=1") && check_response())) {
JimCarver 0:6b753f761943 537 debug_if(_ism_debug, "ISM43362: open: R2 issue\n");
JimCarver 0:6b753f761943 538 return -1;
JimCarver 0:6b753f761943 539 }
JimCarver 0:6b753f761943 540
JimCarver 0:6b753f761943 541 debug_if(_ism_debug, "ISM43362: open ok with id %d type %s addr %s port %d\n", id, type, addr, port);
JimCarver 0:6b753f761943 542
JimCarver 0:6b753f761943 543 return true;
JimCarver 0:6b753f761943 544 }
JimCarver 0:6b753f761943 545
JimCarver 0:6b753f761943 546 bool ISM43362::dns_lookup(const char *name, char *ip)
JimCarver 0:6b753f761943 547 {
JimCarver 0:6b753f761943 548 char tmp[30];
JimCarver 0:6b753f761943 549
JimCarver 0:6b753f761943 550 if (!(_parser.send("D0=%s", name) && _parser.recv("%s\r\n", tmp)
JimCarver 0:6b753f761943 551 && check_response())) {
JimCarver 0:6b753f761943 552 debug_if(_ism_debug, "ISM43362 dns_lookup: D0 issue: %s\n", tmp);
JimCarver 0:6b753f761943 553 return 0;
JimCarver 0:6b753f761943 554 }
JimCarver 0:6b753f761943 555
JimCarver 0:6b753f761943 556 strncpy(ip, tmp, sizeof(tmp));
JimCarver 0:6b753f761943 557
JimCarver 0:6b753f761943 558 debug_if(_ism_debug, "ISM43362 dns_lookup: %s ok\n", ip);
JimCarver 0:6b753f761943 559 return 1;
JimCarver 0:6b753f761943 560 }
JimCarver 0:6b753f761943 561
JimCarver 0:6b753f761943 562 bool ISM43362::send(int id, const void *data, uint32_t amount)
JimCarver 0:6b753f761943 563 {
JimCarver 0:6b753f761943 564 // The Size limit has to be checked on caller side.
JimCarver 0:6b753f761943 565 if (amount > ES_WIFI_MAX_TX_PACKET_SIZE) {
JimCarver 0:6b753f761943 566 debug_if(_ism_debug, "ISM43362 send: max issue\n");
JimCarver 0:6b753f761943 567 return false;
JimCarver 0:6b753f761943 568 }
JimCarver 0:6b753f761943 569
JimCarver 0:6b753f761943 570 /* Activate the socket id in the wifi module */
JimCarver 0:6b753f761943 571 if ((id < 0) || (id > 3)) {
JimCarver 0:6b753f761943 572 return false;
JimCarver 0:6b753f761943 573 }
JimCarver 0:6b753f761943 574 if (_active_id != id) {
JimCarver 0:6b753f761943 575 _active_id = id;
JimCarver 0:6b753f761943 576 if (!(_parser.send("P0=%d", id) && check_response())) {
JimCarver 0:6b753f761943 577 debug_if(_ism_debug, "ISM43362 send: P0 issue\n");
JimCarver 0:6b753f761943 578 return false;
JimCarver 0:6b753f761943 579 }
JimCarver 0:6b753f761943 580 }
JimCarver 0:6b753f761943 581
JimCarver 0:6b753f761943 582 /* set Write Transport Packet Size */
JimCarver 0:6b753f761943 583 int i = _parser.printf("S3=%d\r", (int)amount);
JimCarver 0:6b753f761943 584 if (i < 0) {
JimCarver 0:6b753f761943 585 debug_if(_ism_debug, "ISM43362 send: S3 issue\n");
JimCarver 0:6b753f761943 586 return false;
JimCarver 0:6b753f761943 587 }
JimCarver 0:6b753f761943 588 i = _parser.write((const char *)data, amount, i);
JimCarver 0:6b753f761943 589 if (i < 0) {
JimCarver 0:6b753f761943 590 return false;
JimCarver 0:6b753f761943 591 }
JimCarver 0:6b753f761943 592
JimCarver 0:6b753f761943 593 if (!check_response()) {
JimCarver 0:6b753f761943 594 return false;
JimCarver 0:6b753f761943 595 }
JimCarver 0:6b753f761943 596
JimCarver 0:6b753f761943 597 debug_if(_ism_debug, "ISM43362 send: id %d amount %d\n", id, amount);
JimCarver 0:6b753f761943 598 return true;
JimCarver 0:6b753f761943 599 }
JimCarver 0:6b753f761943 600
JimCarver 0:6b753f761943 601 int ISM43362::check_recv_status(int id, void *data)
JimCarver 0:6b753f761943 602 {
JimCarver 0:6b753f761943 603 int read_amount;
JimCarver 0:6b753f761943 604
JimCarver 0:6b753f761943 605 debug_if(_ism_debug, "ISM43362 check_recv_status: id %d\r\n", id);
JimCarver 0:6b753f761943 606
JimCarver 0:6b753f761943 607 /* Activate the socket id in the wifi module */
JimCarver 0:6b753f761943 608 if ((id < 0) || (id > 3)) {
JimCarver 0:6b753f761943 609 debug_if(_ism_debug, "ISM43362 check_recv_status: ERROR with id %d\r\n", id);
JimCarver 0:6b753f761943 610 return -1;
JimCarver 0:6b753f761943 611 }
JimCarver 0:6b753f761943 612
JimCarver 0:6b753f761943 613 if (_active_id != id) {
JimCarver 0:6b753f761943 614 _active_id = id;
JimCarver 0:6b753f761943 615 if (!(_parser.send("P0=%d", id) && check_response())) {
JimCarver 0:6b753f761943 616 return -1;
JimCarver 0:6b753f761943 617 }
JimCarver 0:6b753f761943 618 }
JimCarver 0:6b753f761943 619
JimCarver 0:6b753f761943 620
JimCarver 0:6b753f761943 621 if (!_parser.send("R0")) {
JimCarver 0:6b753f761943 622 return -1;
JimCarver 0:6b753f761943 623 }
JimCarver 0:6b753f761943 624 read_amount = _parser.read((char *)data);
JimCarver 0:6b753f761943 625
JimCarver 0:6b753f761943 626 if (read_amount < 0) {
JimCarver 0:6b753f761943 627 debug_if(_ism_debug, "ISM43362 check_recv_status: ERROR in data RECV, timeout?\r\n");
JimCarver 0:6b753f761943 628 return -1; /* nothing to read */
JimCarver 0:6b753f761943 629 }
JimCarver 0:6b753f761943 630
JimCarver 0:6b753f761943 631 /* If there are spurious 0x15 at the end of the data, this is an error
JimCarver 0:6b753f761943 632 * we hall can get rid off of them :-(
JimCarver 0:6b753f761943 633 * This should not happen, but let's try to clean-up anyway
JimCarver 0:6b753f761943 634 */
JimCarver 0:6b753f761943 635 char *cleanup = (char *) data;
JimCarver 0:6b753f761943 636 while ((read_amount > 0) && (cleanup[read_amount - 1] == 0x15)) {
JimCarver 0:6b753f761943 637 // debug_if(_ism_debug, "ISM43362 check_recv_status: spurious 0X15 trashed\r\n");
JimCarver 0:6b753f761943 638 /* Remove the trailling char then search again */
JimCarver 0:6b753f761943 639 read_amount--;
JimCarver 0:6b753f761943 640 }
JimCarver 0:6b753f761943 641
JimCarver 0:6b753f761943 642 if ((read_amount >= 6) && (strncmp("OK\r\n> ", (char *)data, 6) == 0)) {
JimCarver 0:6b753f761943 643 // debug_if(_ism_debug, "ISM43362 check_recv_status: recv 2 nothing to read=%d\r\n", read_amount);
JimCarver 0:6b753f761943 644 // read_amount -= 6;
JimCarver 0:6b753f761943 645 return 0; /* nothing to read */
JimCarver 0:6b753f761943 646 } else if ((read_amount >= 8) && (strncmp((char *)((uint32_t) data + read_amount - 8), "\r\nOK\r\n> ", 8)) == 0) {
JimCarver 0:6b753f761943 647 /* bypass ""\r\nOK\r\n> " if present at the end of the chain */
JimCarver 0:6b753f761943 648 read_amount -= 8;
JimCarver 0:6b753f761943 649 } else {
JimCarver 0:6b753f761943 650 debug_if(_ism_debug, "ISM43362 check_recv_status: ERROR, flushing %d bytes: ", read_amount);
JimCarver 0:6b753f761943 651 // for (int i = 0; i < read_amount; i++) {
JimCarver 0:6b753f761943 652 // debug_if(_ism_debug, "%2X ", cleanup[i]);
JimCarver 0:6b753f761943 653 // }
JimCarver 0:6b753f761943 654 // debug_if(_ism_debug, "\r\n (ASCII)", cleanup);
JimCarver 0:6b753f761943 655 cleanup[read_amount] = 0;
JimCarver 0:6b753f761943 656 debug_if(_ism_debug, "%s\r\n", cleanup);
JimCarver 0:6b753f761943 657 return -1; /* nothing to read */
JimCarver 0:6b753f761943 658 }
JimCarver 0:6b753f761943 659
JimCarver 0:6b753f761943 660 debug_if(_ism_debug, "ISM43362 check_recv_status: id %d read_amount=%d\r\n", id, read_amount);
JimCarver 0:6b753f761943 661 return read_amount;
JimCarver 0:6b753f761943 662 }
JimCarver 0:6b753f761943 663
JimCarver 0:6b753f761943 664 bool ISM43362::close(int id)
JimCarver 0:6b753f761943 665 {
JimCarver 0:6b753f761943 666 if ((id < 0) || (id > 3)) {
JimCarver 0:6b753f761943 667 debug_if(_ism_debug, "ISM43362: Wrong socket number\n");
JimCarver 0:6b753f761943 668 return false;
JimCarver 0:6b753f761943 669 }
JimCarver 0:6b753f761943 670 /* Set connection on this socket */
JimCarver 0:6b753f761943 671 debug_if(_ism_debug, "ISM43362: CLOSE socket id=%d\n", id);
JimCarver 0:6b753f761943 672 _active_id = id;
JimCarver 0:6b753f761943 673 if (!(_parser.send("P0=%d", id) && check_response())) {
JimCarver 0:6b753f761943 674 return false;
JimCarver 0:6b753f761943 675 }
JimCarver 0:6b753f761943 676 /* close this socket */
JimCarver 0:6b753f761943 677 if (!(_parser.send("P6=0") && check_response())) {
JimCarver 0:6b753f761943 678 return false;
JimCarver 0:6b753f761943 679 }
JimCarver 0:6b753f761943 680 return true;
JimCarver 0:6b753f761943 681 }
JimCarver 0:6b753f761943 682
JimCarver 0:6b753f761943 683 bool ISM43362::readable()
JimCarver 0:6b753f761943 684 {
JimCarver 0:6b753f761943 685 /* not applicable with SPI api */
JimCarver 0:6b753f761943 686 return true;
JimCarver 0:6b753f761943 687 }
JimCarver 0:6b753f761943 688
JimCarver 0:6b753f761943 689 bool ISM43362::writeable()
JimCarver 0:6b753f761943 690 {
JimCarver 0:6b753f761943 691 /* not applicable with SPI api */
JimCarver 0:6b753f761943 692 return true;
JimCarver 0:6b753f761943 693 }
JimCarver 0:6b753f761943 694
JimCarver 0:6b753f761943 695 void ISM43362::attach(Callback<void()> func)
JimCarver 0:6b753f761943 696 {
JimCarver 0:6b753f761943 697 /* not applicable with SPI api */
JimCarver 0:6b753f761943 698 }
JimCarver 0:6b753f761943 699