Host software for the MAXREFDES220 Heart Rate Monitor Smart Sensor. Hosted on the MAX32630FTHR.
Dependencies: max32630fthr USBDevice
Fork of MAXREFDES220_HEART_RATE_MONITOR by
Finger Heart Rate Monitor and SpO2 Monitor
The MAXREFDES220 Smart Sensor FeatherWing board is a integrated solution for providing finger-based heart rate measurements and SpO2 (blood oxygen saturation). This evaluation board interfaces to the host computer using the I2C interface. Heart rate outpu is available in beats per minute (BPM) and SpO2 is reported in percentages.; the PPG (photoplethysmography) raw data is also available. The board has an MAX30101 chip which is a low power heart rate monitor with adjustable sample rates and adjustable LED currents. The low cost MAX32664 microcontroller is pre-flashed with C code for finger-based pulse rate and SpO2 monitoring. Bootloader software is included to allow for future algorithms or updates to the algorithm from Maxim Integrated.
Ordering information will be available soon.
Note: SpO2 values are not calibrated. Calibration should be performed using the final end product.
Warning
The MAXREFDES220 source code listed is dated and only compatible with the 1.2.8a.msbl. The latest sample host source code is available on the MAX32664 website.
MAXREFDES220 FeatherWing Pinout Connections
Interfaces/DeviceStudio/DSInterface.cpp@14:3fdc09d9017b, 2021-02-05 (annotated)
- Committer:
- phonemacro
- Date:
- Fri Feb 05 01:59:25 2021 +0000
- Revision:
- 14:3fdc09d9017b
- Parent:
- 8:0f55f59ca341
Remove code for EventStats irq_evt - it no longer compiles on mBed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Shaun Kelsey |
0:da5f5b56060a | 1 | /*************************************************************************** |
Shaun Kelsey |
0:da5f5b56060a | 2 | * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. |
Shaun Kelsey |
0:da5f5b56060a | 3 | * |
Shaun Kelsey |
0:da5f5b56060a | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
Shaun Kelsey |
0:da5f5b56060a | 5 | * copy of this software and associated documentation files (the "Software"), |
Shaun Kelsey |
0:da5f5b56060a | 6 | * to deal in the Software without restriction, including without limitation |
Shaun Kelsey |
0:da5f5b56060a | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Shaun Kelsey |
0:da5f5b56060a | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
Shaun Kelsey |
0:da5f5b56060a | 9 | * Software is furnished to do so, subject to the following conditions: |
Shaun Kelsey |
0:da5f5b56060a | 10 | * |
Shaun Kelsey |
0:da5f5b56060a | 11 | * The above copyright notice and this permission notice shall be included |
Shaun Kelsey |
0:da5f5b56060a | 12 | * in all copies or substantial portions of the Software. |
Shaun Kelsey |
0:da5f5b56060a | 13 | * |
Shaun Kelsey |
0:da5f5b56060a | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Shaun Kelsey |
0:da5f5b56060a | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Shaun Kelsey |
0:da5f5b56060a | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Shaun Kelsey |
0:da5f5b56060a | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Shaun Kelsey |
0:da5f5b56060a | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Shaun Kelsey |
0:da5f5b56060a | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Shaun Kelsey |
0:da5f5b56060a | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
Shaun Kelsey |
0:da5f5b56060a | 21 | * |
Shaun Kelsey |
0:da5f5b56060a | 22 | * Except as contained in this notice, the name of Maxim Integrated |
Shaun Kelsey |
0:da5f5b56060a | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Shaun Kelsey |
0:da5f5b56060a | 24 | * Products, Inc. Branding Policy. |
Shaun Kelsey |
0:da5f5b56060a | 25 | * |
Shaun Kelsey |
0:da5f5b56060a | 26 | * The mere transfer of this software does not imply any licenses |
Shaun Kelsey |
0:da5f5b56060a | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
Shaun Kelsey |
0:da5f5b56060a | 28 | * trademarks, maskwork rights, or any other form of intellectual |
Shaun Kelsey |
0:da5f5b56060a | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Shaun Kelsey |
0:da5f5b56060a | 30 | * ownership rights. |
Shaun Kelsey |
0:da5f5b56060a | 31 | **************************************************************************** |
Shaun Kelsey |
0:da5f5b56060a | 32 | */ |
Shaun Kelsey |
0:da5f5b56060a | 33 | |
Shaun Kelsey |
0:da5f5b56060a | 34 | #include <ctype.h> |
Shaun Kelsey |
0:da5f5b56060a | 35 | #include <string.h> |
Shaun Kelsey |
0:da5f5b56060a | 36 | #include "DSInterface.h" |
Shaun Kelsey |
0:da5f5b56060a | 37 | #include "../version.h" |
Shaun Kelsey |
0:da5f5b56060a | 38 | #include "Peripherals.h" |
Shaun Kelsey |
0:da5f5b56060a | 39 | #include "assert.h" |
Shaun Kelsey |
5:e458409e913f | 40 | #include "utils.h" |
Shaun Kelsey |
5:e458409e913f | 41 | |
Shaun Kelsey |
5:e458409e913f | 42 | #ifdef ENABLE_BLE |
Shaun Kelsey |
5:e458409e913f | 43 | #include "BLE_ICARUS.h" |
Shaun Kelsey |
5:e458409e913f | 44 | #endif |
Shaun Kelsey |
0:da5f5b56060a | 45 | |
Shaun Kelsey |
0:da5f5b56060a | 46 | static const char *glbl_cmds[] = { |
Shaun Kelsey |
0:da5f5b56060a | 47 | "stop", |
Shaun Kelsey |
0:da5f5b56060a | 48 | "get_device_info", |
Shaun Kelsey |
0:da5f5b56060a | 49 | "silent_mode 0", |
Shaun Kelsey |
0:da5f5b56060a | 50 | "silent_mode 1", |
Shaun Kelsey |
0:da5f5b56060a | 51 | "pause 0", |
Shaun Kelsey |
0:da5f5b56060a | 52 | "pause 1", |
Shaun Kelsey |
0:da5f5b56060a | 53 | "enable console", |
Shaun Kelsey |
0:da5f5b56060a | 54 | "disable console", |
Shaun Kelsey |
0:da5f5b56060a | 55 | }; |
Shaun Kelsey |
0:da5f5b56060a | 56 | |
Shaun Kelsey |
0:da5f5b56060a | 57 | typedef enum { |
Shaun Kelsey |
0:da5f5b56060a | 58 | stop=0, |
Shaun Kelsey |
0:da5f5b56060a | 59 | get_device_info, |
Shaun Kelsey |
0:da5f5b56060a | 60 | silent0_mode, |
Shaun Kelsey |
0:da5f5b56060a | 61 | silent1_mode, |
Shaun Kelsey |
0:da5f5b56060a | 62 | pause0_mode, |
Shaun Kelsey |
0:da5f5b56060a | 63 | pause1_mode, |
Shaun Kelsey |
0:da5f5b56060a | 64 | enable_console, |
Shaun Kelsey |
0:da5f5b56060a | 65 | disable_console, |
Shaun Kelsey |
0:da5f5b56060a | 66 | NUM_CMDS, |
Shaun Kelsey |
0:da5f5b56060a | 67 | } glbl_cmd_state; |
Shaun Kelsey |
0:da5f5b56060a | 68 | |
Shaun Kelsey |
0:da5f5b56060a | 69 | |
Shaun Kelsey |
0:da5f5b56060a | 70 | DSInterface::DSInterface(USBSerial* USB) |
Shaun Kelsey |
0:da5f5b56060a | 71 | { |
Shaun Kelsey |
0:da5f5b56060a | 72 | cmd_idx = 0; |
Shaun Kelsey |
0:da5f5b56060a | 73 | silent_mode = false; |
Shaun Kelsey |
0:da5f5b56060a | 74 | pause_mode = false; |
Shaun Kelsey |
0:da5f5b56060a | 75 | |
Shaun Kelsey |
0:da5f5b56060a | 76 | memset(sensor_list, 0, DS_MAX_NUM_SENSORCOMMS * sizeof(SensorComm*)); |
Shaun Kelsey |
0:da5f5b56060a | 77 | num_sensors = 0; |
Shaun Kelsey |
0:da5f5b56060a | 78 | |
Shaun Kelsey |
0:da5f5b56060a | 79 | m_USB = USB; |
Shaun Kelsey |
0:da5f5b56060a | 80 | |
keremsahin | 8:0f55f59ca341 | 81 | ds_console_interface_exists_ = false; |
Shaun Kelsey |
0:da5f5b56060a | 82 | } |
Shaun Kelsey |
0:da5f5b56060a | 83 | |
Shaun Kelsey |
0:da5f5b56060a | 84 | DSInterface::~DSInterface() |
Shaun Kelsey |
0:da5f5b56060a | 85 | { |
Shaun Kelsey |
0:da5f5b56060a | 86 | } |
Shaun Kelsey |
0:da5f5b56060a | 87 | |
Shaun Kelsey |
0:da5f5b56060a | 88 | void DSInterface::add_sensor_comm(SensorComm *s) |
Shaun Kelsey |
0:da5f5b56060a | 89 | { |
Shaun Kelsey |
0:da5f5b56060a | 90 | assert_msg(num_sensors < DS_MAX_NUM_SENSORCOMMS, "Too many sensors added to DSInterface. Increase DS_MAX_NUM_SENSORCOMMS."); |
Shaun Kelsey |
0:da5f5b56060a | 91 | sensor_list[num_sensors++] = s; |
Shaun Kelsey |
0:da5f5b56060a | 92 | } |
Shaun Kelsey |
0:da5f5b56060a | 93 | |
Shaun Kelsey |
0:da5f5b56060a | 94 | void DSInterface::enable_console_interface() |
Shaun Kelsey |
0:da5f5b56060a | 95 | { |
keremsahin | 8:0f55f59ca341 | 96 | ds_console_interface_exists_ = true; |
Shaun Kelsey |
0:da5f5b56060a | 97 | } |
Shaun Kelsey |
0:da5f5b56060a | 98 | |
Shaun Kelsey |
0:da5f5b56060a | 99 | void DSInterface::build_command(char ch) |
Shaun Kelsey |
0:da5f5b56060a | 100 | { |
Shaun Kelsey |
0:da5f5b56060a | 101 | if (!this->silent_mode) /* BUG: POTENTIAL BUG, what uart port to echo, not only console */ |
Shaun Kelsey |
0:da5f5b56060a | 102 | m_USB->printf("%c", ch); |
Shaun Kelsey |
0:da5f5b56060a | 103 | |
Shaun Kelsey |
0:da5f5b56060a | 104 | if (ch == 0x00) { |
Shaun Kelsey |
0:da5f5b56060a | 105 | pr_err("Ignored char 0x00"); |
Shaun Kelsey |
0:da5f5b56060a | 106 | return; |
Shaun Kelsey |
0:da5f5b56060a | 107 | } |
Shaun Kelsey |
0:da5f5b56060a | 108 | |
Shaun Kelsey |
0:da5f5b56060a | 109 | if ((ch == '\n') || (ch == '\r')) { |
Shaun Kelsey |
5:e458409e913f | 110 | if (cmd_idx < (int)CONSOLE_STR_BUF_SZ) |
Shaun Kelsey |
0:da5f5b56060a | 111 | cmd_str[cmd_idx++] = '\0'; |
Shaun Kelsey |
0:da5f5b56060a | 112 | m_USB->printf("\r\n"); |
Shaun Kelsey |
0:da5f5b56060a | 113 | parse_command(); |
Shaun Kelsey |
0:da5f5b56060a | 114 | |
Shaun Kelsey |
0:da5f5b56060a | 115 | //Clear cmd_str |
Shaun Kelsey |
0:da5f5b56060a | 116 | while (cmd_idx > 0) /* BUG: POTENTIAL BUG for multiple port access */ |
Shaun Kelsey |
0:da5f5b56060a | 117 | cmd_str[--cmd_idx] = '\0'; |
Shaun Kelsey |
0:da5f5b56060a | 118 | |
Shaun Kelsey |
0:da5f5b56060a | 119 | } else if ((ch == 0x08 || ch == 0x7F) && cmd_idx > 0) { |
Shaun Kelsey |
0:da5f5b56060a | 120 | //Backspace character |
Shaun Kelsey |
0:da5f5b56060a | 121 | if (cmd_idx > 0) |
Shaun Kelsey |
0:da5f5b56060a | 122 | cmd_str[--cmd_idx] = '\0'; |
Shaun Kelsey |
0:da5f5b56060a | 123 | } else { |
Shaun Kelsey |
0:da5f5b56060a | 124 | /* BUG: POTENTIAL BUG for multiple port access */ |
Shaun Kelsey |
5:e458409e913f | 125 | if (cmd_idx < (int)CONSOLE_STR_BUF_SZ) |
Shaun Kelsey |
0:da5f5b56060a | 126 | cmd_str[cmd_idx++] = ch; |
Shaun Kelsey |
0:da5f5b56060a | 127 | } |
Shaun Kelsey |
0:da5f5b56060a | 128 | |
Shaun Kelsey |
0:da5f5b56060a | 129 | } |
Shaun Kelsey |
0:da5f5b56060a | 130 | |
Shaun Kelsey |
0:da5f5b56060a | 131 | void DSInterface::parse_command() |
Shaun Kelsey |
0:da5f5b56060a | 132 | { |
Shaun Kelsey |
0:da5f5b56060a | 133 | int i; |
Shaun Kelsey |
0:da5f5b56060a | 134 | glbl_cmd_state cmd; |
Shaun Kelsey |
0:da5f5b56060a | 135 | char charbuf[512]; |
Shaun Kelsey |
0:da5f5b56060a | 136 | int data_len = 0; |
Shaun Kelsey |
0:da5f5b56060a | 137 | int ret; |
Shaun Kelsey |
5:e458409e913f | 138 | bool parsed_cmd = true; |
Shaun Kelsey |
0:da5f5b56060a | 139 | |
Shaun Kelsey |
0:da5f5b56060a | 140 | //If top level command, then handle it |
Shaun Kelsey |
0:da5f5b56060a | 141 | for (i = 0; i < NUM_CMDS; i++) { |
Shaun Kelsey |
5:e458409e913f | 142 | if (starts_with(&cmd_str[0], glbl_cmds[i])) { |
Shaun Kelsey |
0:da5f5b56060a | 143 | cmd = (glbl_cmd_state)i; |
Shaun Kelsey |
0:da5f5b56060a | 144 | |
Shaun Kelsey |
0:da5f5b56060a | 145 | switch (cmd) { |
Shaun Kelsey |
0:da5f5b56060a | 146 | case (stop): { |
Shaun Kelsey |
0:da5f5b56060a | 147 | for (int i = 0; i < num_sensors; i++) { |
Shaun Kelsey |
0:da5f5b56060a | 148 | sensor_list[i]->stop(); |
Shaun Kelsey |
0:da5f5b56060a | 149 | } |
Shaun Kelsey |
5:e458409e913f | 150 | data_len += snprintf(charbuf, sizeof(charbuf) - 1, |
Shaun Kelsey |
5:e458409e913f | 151 | "\r\n%s err=0\r\n", cmd_str); |
Shaun Kelsey |
0:da5f5b56060a | 152 | } break; |
Shaun Kelsey |
0:da5f5b56060a | 153 | case (get_device_info): { |
Shaun Kelsey |
0:da5f5b56060a | 154 | data_len = snprintf(charbuf, sizeof(charbuf), |
Shaun Kelsey |
5:e458409e913f | 155 | "\r\n%s platform=%s firmware_ver=%s sensors=", cmd_str, platform_name, firmware_version); |
Shaun Kelsey |
0:da5f5b56060a | 156 | |
Shaun Kelsey |
0:da5f5b56060a | 157 | //Add list of sensors |
Shaun Kelsey |
0:da5f5b56060a | 158 | for (int i = 0; i < num_sensors; i++) { |
Shaun Kelsey |
0:da5f5b56060a | 159 | if (sensor_list[i]->is_visible()) { |
Shaun Kelsey |
0:da5f5b56060a | 160 | data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, |
Shaun Kelsey |
0:da5f5b56060a | 161 | "%s", sensor_list[i]->get_type()); |
Shaun Kelsey |
0:da5f5b56060a | 162 | if (i < (num_sensors - 1)) |
Shaun Kelsey |
0:da5f5b56060a | 163 | data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, ","); |
Shaun Kelsey |
0:da5f5b56060a | 164 | } |
Shaun Kelsey |
0:da5f5b56060a | 165 | } |
Shaun Kelsey |
0:da5f5b56060a | 166 | |
Shaun Kelsey |
0:da5f5b56060a | 167 | |
Shaun Kelsey |
0:da5f5b56060a | 168 | for (int i = 0; i < num_sensors; i++) { |
Shaun Kelsey |
0:da5f5b56060a | 169 | SensorComm *s = sensor_list[i]; |
Shaun Kelsey |
0:da5f5b56060a | 170 | if (!s->is_visible()) |
Shaun Kelsey |
0:da5f5b56060a | 171 | continue; |
Shaun Kelsey |
0:da5f5b56060a | 172 | |
keremsahin | 8:0f55f59ca341 | 173 | //Add algo_ver |
keremsahin | 8:0f55f59ca341 | 174 | data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, |
keremsahin | 8:0f55f59ca341 | 175 | " algo_ver_%s=%s", s->get_type(), s->get_algo_ver()); |
keremsahin | 8:0f55f59ca341 | 176 | |
Shaun Kelsey |
0:da5f5b56060a | 177 | //Add part name |
Shaun Kelsey |
0:da5f5b56060a | 178 | data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, |
Shaun Kelsey |
0:da5f5b56060a | 179 | " part_name_%s=%s", s->get_type(), s->get_part_name()); |
Shaun Kelsey |
0:da5f5b56060a | 180 | |
Shaun Kelsey |
0:da5f5b56060a | 181 | uint8_t part_id, part_rev; |
Shaun Kelsey |
0:da5f5b56060a | 182 | ret = s->get_part_info(&part_id, &part_rev); |
Shaun Kelsey |
0:da5f5b56060a | 183 | |
Shaun Kelsey |
0:da5f5b56060a | 184 | if (ret == 0) { |
Shaun Kelsey |
0:da5f5b56060a | 185 | //Add part id |
Shaun Kelsey |
0:da5f5b56060a | 186 | data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, |
Shaun Kelsey |
0:da5f5b56060a | 187 | " part_id_%s=%d", s->get_type(), part_id); |
Shaun Kelsey |
0:da5f5b56060a | 188 | |
Shaun Kelsey |
0:da5f5b56060a | 189 | //Add rev id |
Shaun Kelsey |
0:da5f5b56060a | 190 | data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, |
Shaun Kelsey |
0:da5f5b56060a | 191 | " part_rev_%s=%d", s->get_type(), part_rev); |
Shaun Kelsey |
0:da5f5b56060a | 192 | } |
Shaun Kelsey |
0:da5f5b56060a | 193 | } |
Shaun Kelsey |
0:da5f5b56060a | 194 | |
Shaun Kelsey |
0:da5f5b56060a | 195 | |
Shaun Kelsey |
5:e458409e913f | 196 | data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, " err=0\r\n"); |
Shaun Kelsey |
0:da5f5b56060a | 197 | |
Shaun Kelsey |
0:da5f5b56060a | 198 | } break; |
Shaun Kelsey |
0:da5f5b56060a | 199 | case (silent0_mode): { |
Shaun Kelsey |
0:da5f5b56060a | 200 | silent_mode = false; |
Shaun Kelsey |
5:e458409e913f | 201 | data_len += snprintf(charbuf, sizeof(charbuf) - 1, |
Shaun Kelsey |
5:e458409e913f | 202 | "\r\n%s err=0\r\n", cmd_str); |
Shaun Kelsey |
0:da5f5b56060a | 203 | } break; |
Shaun Kelsey |
0:da5f5b56060a | 204 | case (silent1_mode): { |
Shaun Kelsey |
0:da5f5b56060a | 205 | silent_mode = true; |
Shaun Kelsey |
5:e458409e913f | 206 | data_len += snprintf(charbuf, sizeof(charbuf) - 1, |
Shaun Kelsey |
5:e458409e913f | 207 | "\r\n%s err=0\r\n", cmd_str); |
Shaun Kelsey |
0:da5f5b56060a | 208 | } break; |
Shaun Kelsey |
0:da5f5b56060a | 209 | case (pause0_mode): { |
Shaun Kelsey |
0:da5f5b56060a | 210 | pause_mode = false; |
Shaun Kelsey |
5:e458409e913f | 211 | data_len += snprintf(charbuf, sizeof(charbuf) - 1, |
Shaun Kelsey |
5:e458409e913f | 212 | "\r\n%s err=0\r\n", cmd_str); |
Shaun Kelsey |
0:da5f5b56060a | 213 | } break; |
Shaun Kelsey |
0:da5f5b56060a | 214 | case (pause1_mode): { |
Shaun Kelsey |
0:da5f5b56060a | 215 | pause_mode = true; |
Shaun Kelsey |
5:e458409e913f | 216 | data_len += snprintf(charbuf, sizeof(charbuf) - 1, |
Shaun Kelsey |
5:e458409e913f | 217 | "\r\n%s err=0\r\n", cmd_str); |
Shaun Kelsey |
0:da5f5b56060a | 218 | } break; |
Shaun Kelsey |
0:da5f5b56060a | 219 | case (enable_console): { |
keremsahin | 8:0f55f59ca341 | 220 | ds_console_interface_exists_ = true; |
Shaun Kelsey |
5:e458409e913f | 221 | data_len += snprintf(charbuf, sizeof(charbuf) - 1, |
Shaun Kelsey |
5:e458409e913f | 222 | "\r\n%s err=0\r\n", cmd_str); |
Shaun Kelsey |
0:da5f5b56060a | 223 | } break; |
Shaun Kelsey |
0:da5f5b56060a | 224 | case (disable_console): { |
keremsahin | 8:0f55f59ca341 | 225 | ds_console_interface_exists_ = false; |
Shaun Kelsey |
5:e458409e913f | 226 | data_len += snprintf(charbuf, sizeof(charbuf) - 1, |
Shaun Kelsey |
5:e458409e913f | 227 | "\r\n%s err=0\r\n", cmd_str); |
Shaun Kelsey |
0:da5f5b56060a | 228 | } break; |
Shaun Kelsey |
0:da5f5b56060a | 229 | default: |
Shaun Kelsey |
5:e458409e913f | 230 | parsed_cmd = false; |
Shaun Kelsey |
0:da5f5b56060a | 231 | break; |
Shaun Kelsey |
0:da5f5b56060a | 232 | } |
Shaun Kelsey |
0:da5f5b56060a | 233 | |
Shaun Kelsey |
5:e458409e913f | 234 | if (parsed_cmd) { |
Shaun Kelsey |
5:e458409e913f | 235 | m_USB->printf(charbuf); |
Shaun Kelsey |
5:e458409e913f | 236 | #if ENABLE_BLE |
Shaun Kelsey |
5:e458409e913f | 237 | if (BLE_Icarus_Interface_Exists()) { |
Shaun Kelsey |
5:e458409e913f | 238 | BLE_Icarus_AddtoQueue((uint8_t *)charbuf, (int32_t)sizeof(charbuf), data_len); |
Shaun Kelsey |
5:e458409e913f | 239 | } |
Shaun Kelsey |
5:e458409e913f | 240 | #endif |
Shaun Kelsey |
5:e458409e913f | 241 | } |
Shaun Kelsey |
5:e458409e913f | 242 | |
Shaun Kelsey |
0:da5f5b56060a | 243 | return; |
Shaun Kelsey |
0:da5f5b56060a | 244 | } |
Shaun Kelsey |
0:da5f5b56060a | 245 | } |
Shaun Kelsey |
0:da5f5b56060a | 246 | |
Shaun Kelsey |
0:da5f5b56060a | 247 | //Loop through each sensor in sensorList |
Shaun Kelsey |
0:da5f5b56060a | 248 | //If sensor.get_type() is contained in cmd_str, pass cmd_str to that sensor's parser |
Shaun Kelsey |
0:da5f5b56060a | 249 | for (int i = 0; i < num_sensors; i++) { |
Shaun Kelsey |
0:da5f5b56060a | 250 | if (strstr(&cmd_str[0], sensor_list[i]->get_type())) { |
Shaun Kelsey |
0:da5f5b56060a | 251 | if (sensor_list[i]->parse_command(cmd_str)) |
Shaun Kelsey |
0:da5f5b56060a | 252 | return; |
Shaun Kelsey |
0:da5f5b56060a | 253 | break; |
Shaun Kelsey |
0:da5f5b56060a | 254 | } |
Shaun Kelsey |
0:da5f5b56060a | 255 | } |
Shaun Kelsey |
0:da5f5b56060a | 256 | |
Shaun Kelsey |
0:da5f5b56060a | 257 | //If we still haven't found a way to parse the command, |
Shaun Kelsey |
0:da5f5b56060a | 258 | //send it to every sensor until one handles it |
Shaun Kelsey |
0:da5f5b56060a | 259 | for (int i = 0; i < num_sensors; i++) { |
Shaun Kelsey |
0:da5f5b56060a | 260 | if (sensor_list[i]->parse_command(cmd_str)) |
Shaun Kelsey |
0:da5f5b56060a | 261 | return; |
Shaun Kelsey |
0:da5f5b56060a | 262 | } |
Shaun Kelsey |
0:da5f5b56060a | 263 | |
Shaun Kelsey |
0:da5f5b56060a | 264 | |
Shaun Kelsey |
0:da5f5b56060a | 265 | //No one could handle the command, print cmd not recognized string |
Shaun Kelsey |
5:e458409e913f | 266 | data_len += snprintf(charbuf, sizeof(charbuf) - 1, |
Shaun Kelsey |
5:e458409e913f | 267 | "\r\n%s err=-255\r\n", cmd_str); |
Shaun Kelsey |
5:e458409e913f | 268 | m_USB->printf(charbuf); |
Shaun Kelsey |
5:e458409e913f | 269 | #if ENABLE_BLE |
Shaun Kelsey |
5:e458409e913f | 270 | if (BLE_Icarus_Interface_Exists()) { |
Shaun Kelsey |
5:e458409e913f | 271 | BLE_Icarus_AddtoQueue((uint8_t *)charbuf, (int32_t)sizeof(charbuf), data_len); |
Shaun Kelsey |
5:e458409e913f | 272 | } |
Shaun Kelsey |
5:e458409e913f | 273 | #endif |
Shaun Kelsey |
0:da5f5b56060a | 274 | } |
Shaun Kelsey |
0:da5f5b56060a | 275 | |
Shaun Kelsey |
0:da5f5b56060a | 276 | void DSInterface::data_report_execute() |
Shaun Kelsey |
0:da5f5b56060a | 277 | { |
Shaun Kelsey |
0:da5f5b56060a | 278 | char buffer[256]; |
Shaun Kelsey |
0:da5f5b56060a | 279 | int data_len = 0; |
Shaun Kelsey |
0:da5f5b56060a | 280 | |
Shaun Kelsey |
0:da5f5b56060a | 281 | buffer[0] = '\0'; |
Shaun Kelsey |
0:da5f5b56060a | 282 | |
Shaun Kelsey |
0:da5f5b56060a | 283 | for (int i = 0; i < num_sensors; i++) { |
Shaun Kelsey |
0:da5f5b56060a | 284 | //if ((*it)->is_enabled()) { |
Shaun Kelsey |
0:da5f5b56060a | 285 | data_len = sensor_list[i]->data_report_execute(buffer, sizeof(buffer)); |
Shaun Kelsey |
0:da5f5b56060a | 286 | if (!this->pause_mode && (data_len > 0)) { |
Shaun Kelsey |
5:e458409e913f | 287 | #ifdef ENABLE_BLE |
Shaun Kelsey |
5:e458409e913f | 288 | if (BLE_Icarus_Interface_Exists()) { |
Shaun Kelsey |
5:e458409e913f | 289 | BLE_Icarus_AddtoQueue((uint8_t *)buffer, (int32_t)sizeof(buffer), data_len); |
Shaun Kelsey |
5:e458409e913f | 290 | } |
Shaun Kelsey |
5:e458409e913f | 291 | #endif |
keremsahin | 8:0f55f59ca341 | 292 | if (ds_console_interface_exists_){ |
Shaun Kelsey |
0:da5f5b56060a | 293 | #ifdef ASCII_COMM |
Shaun Kelsey |
0:da5f5b56060a | 294 | m_USB->printf(buffer); |
Shaun Kelsey |
0:da5f5b56060a | 295 | #else |
Shaun Kelsey |
0:da5f5b56060a | 296 | m_USB->writeBlock((uint8_t*)buffer, data_len); |
Shaun Kelsey |
0:da5f5b56060a | 297 | #endif |
Shaun Kelsey |
0:da5f5b56060a | 298 | } |
Shaun Kelsey |
0:da5f5b56060a | 299 | data_len = 0; |
Shaun Kelsey |
0:da5f5b56060a | 300 | } |
Shaun Kelsey |
0:da5f5b56060a | 301 | //We only support streaming from one device at a time, so break here |
Shaun Kelsey |
0:da5f5b56060a | 302 | // break; |
Shaun Kelsey |
0:da5f5b56060a | 303 | //} |
Shaun Kelsey |
0:da5f5b56060a | 304 | } |
Shaun Kelsey |
0:da5f5b56060a | 305 | } |
Shaun Kelsey |
0:da5f5b56060a | 306 | |
Shaun Kelsey |
0:da5f5b56060a | 307 | void DSInterface::set_fw_version(const char* version) |
Shaun Kelsey |
0:da5f5b56060a | 308 | { |
Shaun Kelsey |
0:da5f5b56060a | 309 | if (version && *version) |
Shaun Kelsey |
0:da5f5b56060a | 310 | firmware_version = version; |
Shaun Kelsey |
0:da5f5b56060a | 311 | } |
Shaun Kelsey |
0:da5f5b56060a | 312 | |
Shaun Kelsey |
0:da5f5b56060a | 313 | void DSInterface::set_fw_platform(const char* platform) |
Shaun Kelsey |
0:da5f5b56060a | 314 | { |
Shaun Kelsey |
0:da5f5b56060a | 315 | if (platform && *platform) |
Shaun Kelsey |
0:da5f5b56060a | 316 | platform_name = platform; |
Shaun Kelsey |
0:da5f5b56060a | 317 | } |