TEST

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Committer:
gmehmet
Date:
Wed Apr 10 14:56:25 2019 +0300
Revision:
1:f60eafbf009a
upload from local

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmehmet 1:f60eafbf009a 1 /***************************************************************************
gmehmet 1:f60eafbf009a 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
gmehmet 1:f60eafbf009a 3 *
gmehmet 1:f60eafbf009a 4 * Permission is hereby granted, free of charge, to any person obtaining a
gmehmet 1:f60eafbf009a 5 * copy of this software and associated documentation files (the "Software"),
gmehmet 1:f60eafbf009a 6 * to deal in the Software without restriction, including without limitation
gmehmet 1:f60eafbf009a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
gmehmet 1:f60eafbf009a 8 * and/or sell copies of the Software, and to permit persons to whom the
gmehmet 1:f60eafbf009a 9 * Software is furnished to do so, subject to the following conditions:
gmehmet 1:f60eafbf009a 10 *
gmehmet 1:f60eafbf009a 11 * The above copyright notice and this permission notice shall be included
gmehmet 1:f60eafbf009a 12 * in all copies or substantial portions of the Software.
gmehmet 1:f60eafbf009a 13 *
gmehmet 1:f60eafbf009a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
gmehmet 1:f60eafbf009a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
gmehmet 1:f60eafbf009a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
gmehmet 1:f60eafbf009a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
gmehmet 1:f60eafbf009a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
gmehmet 1:f60eafbf009a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
gmehmet 1:f60eafbf009a 20 * OTHER DEALINGS IN THE SOFTWARE.
gmehmet 1:f60eafbf009a 21 *
gmehmet 1:f60eafbf009a 22 * Except as contained in this notice, the name of Maxim Integrated
gmehmet 1:f60eafbf009a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
gmehmet 1:f60eafbf009a 24 * Products, Inc. Branding Policy.
gmehmet 1:f60eafbf009a 25 *
gmehmet 1:f60eafbf009a 26 * The mere transfer of this software does not imply any licenses
gmehmet 1:f60eafbf009a 27 * of trade secrets, proprietary technology, copyrights, patents,
gmehmet 1:f60eafbf009a 28 * trademarks, maskwork rights, or any other form of intellectual
gmehmet 1:f60eafbf009a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
gmehmet 1:f60eafbf009a 30 * ownership rights.
gmehmet 1:f60eafbf009a 31 ****************************************************************************
gmehmet 1:f60eafbf009a 32 */
gmehmet 1:f60eafbf009a 33
gmehmet 1:f60eafbf009a 34 #include <ctype.h>
gmehmet 1:f60eafbf009a 35 #include <string.h>
gmehmet 1:f60eafbf009a 36 #include "DSInterface.h"
gmehmet 1:f60eafbf009a 37
gmehmet 1:f60eafbf009a 38 #include "../../Utilities/mxm_assert.h"
gmehmet 1:f60eafbf009a 39 #include "../version.h"
gmehmet 1:f60eafbf009a 40 #include "Peripherals.h"
gmehmet 1:f60eafbf009a 41 #include "utils.h"
gmehmet 1:f60eafbf009a 42 #include "Thread.h"
gmehmet 1:f60eafbf009a 43 #include "BLE_ICARUS.h"
gmehmet 1:f60eafbf009a 44
gmehmet 1:f60eafbf009a 45
gmehmet 1:f60eafbf009a 46
gmehmet 1:f60eafbf009a 47 #define HR_ENABLED 1 << 0
gmehmet 1:f60eafbf009a 48 #define SPO2_ENABLED 1 << 1
gmehmet 1:f60eafbf009a 49 #define BPT_ENABLED 1 << 2
gmehmet 1:f60eafbf009a 50 #define WHRM_ENABLED 1 << 3
gmehmet 1:f60eafbf009a 51 #define WSPO2_ENABLED 1 << 4
gmehmet 1:f60eafbf009a 52 #define AEC_ENABLED 1 << 5
gmehmet 1:f60eafbf009a 53 #define SCD_ENABLED 1 << 6
gmehmet 1:f60eafbf009a 54 #define AGC_ENABLED 1 << 7
gmehmet 1:f60eafbf009a 55
gmehmet 1:f60eafbf009a 56
gmehmet 1:f60eafbf009a 57
gmehmet 1:f60eafbf009a 58 typedef struct {
gmehmet 1:f60eafbf009a 59 uint8_t fwVersion[3];
gmehmet 1:f60eafbf009a 60 uint16_t enAlgoDescBitField;
gmehmet 1:f60eafbf009a 61 char me11ProductID;
gmehmet 1:f60eafbf009a 62 }fw_type_t;
gmehmet 1:f60eafbf009a 63
gmehmet 1:f60eafbf009a 64 const static fw_type_t HUB_FW_TABLE[] = {
gmehmet 1:f60eafbf009a 65
gmehmet 1:f60eafbf009a 66 {{1,8,3}, HR_ENABLED | SPO2_ENABLED | AGC_ENABLED , 'A' },
gmehmet 1:f60eafbf009a 67 {{20,1,1}, WHRM_ENABLED | SCD_ENABLED | AEC_ENABLED , 'B' },
gmehmet 1:f60eafbf009a 68 {{30,1,1}, WHRM_ENABLED | WSPO2_ENABLED | AGC_ENABLED | SCD_ENABLED | AEC_ENABLED , 'C' },
gmehmet 1:f60eafbf009a 69 {{40,0,4}, BPT_ENABLED | SPO2_ENABLED | AGC_ENABLED , 'D' }
gmehmet 1:f60eafbf009a 70
gmehmet 1:f60eafbf009a 71 };
gmehmet 1:f60eafbf009a 72
gmehmet 1:f60eafbf009a 73 static const char* ActivAlgoInfo[32] = {
gmehmet 1:f60eafbf009a 74 [0] = "hr,",
gmehmet 1:f60eafbf009a 75 [1] = "spo2,",
gmehmet 1:f60eafbf009a 76 [2] = "bpt,",
gmehmet 1:f60eafbf009a 77 [3] = "whrm,",
gmehmet 1:f60eafbf009a 78 [4] = "wspo2,",
gmehmet 1:f60eafbf009a 79 [5] = "aec,",
gmehmet 1:f60eafbf009a 80 [6] = "scd,",
gmehmet 1:f60eafbf009a 81 [7] = "agc,",
gmehmet 1:f60eafbf009a 82 };
gmehmet 1:f60eafbf009a 83
gmehmet 1:f60eafbf009a 84
gmehmet 1:f60eafbf009a 85 static const char *glbl_cmds[] = {
gmehmet 1:f60eafbf009a 86 "stop",
gmehmet 1:f60eafbf009a 87 "get_device_info",
gmehmet 1:f60eafbf009a 88 "silent_mode 0",
gmehmet 1:f60eafbf009a 89 "silent_mode 1",
gmehmet 1:f60eafbf009a 90 "pause 0",
gmehmet 1:f60eafbf009a 91 "pause 1",
gmehmet 1:f60eafbf009a 92 "enable console",
gmehmet 1:f60eafbf009a 93 "disable console",
gmehmet 1:f60eafbf009a 94 "set_cfg lcd time",
gmehmet 1:f60eafbf009a 95 "set_cfg flash log",
gmehmet 1:f60eafbf009a 96 "set_cfg stream ascii", // set streaming mode to ascii
gmehmet 1:f60eafbf009a 97 "set_cfg stream bin", // set streaming mode to binary
gmehmet 1:f60eafbf009a 98 "set_cfg report 1", //set report mode to 1 (brief)
gmehmet 1:f60eafbf009a 99 "set_cfg report 2" // set report mode to 2 (long)
gmehmet 1:f60eafbf009a 100 };
gmehmet 1:f60eafbf009a 101
gmehmet 1:f60eafbf009a 102 typedef enum {
gmehmet 1:f60eafbf009a 103 stop=0,
gmehmet 1:f60eafbf009a 104 get_device_info,
gmehmet 1:f60eafbf009a 105 silent0_mode,
gmehmet 1:f60eafbf009a 106 silent1_mode,
gmehmet 1:f60eafbf009a 107 pause0_mode,
gmehmet 1:f60eafbf009a 108 pause1_mode,
gmehmet 1:f60eafbf009a 109 enable_console,
gmehmet 1:f60eafbf009a 110 disable_console,
gmehmet 1:f60eafbf009a 111 set_lcd_time,
gmehmet 1:f60eafbf009a 112 set_flash_log,
gmehmet 1:f60eafbf009a 113 enable_ascii_mode,
gmehmet 1:f60eafbf009a 114 enable_bin_mode,
gmehmet 1:f60eafbf009a 115 set_cfg_report_1,
gmehmet 1:f60eafbf009a 116 set_cfg_report_2,
gmehmet 1:f60eafbf009a 117 NUM_CMDS,
gmehmet 1:f60eafbf009a 118 } glbl_cmd_state;
gmehmet 1:f60eafbf009a 119
gmehmet 1:f60eafbf009a 120
gmehmet 1:f60eafbf009a 121 DSInterface::DSInterface(USBSerial* USB)
gmehmet 1:f60eafbf009a 122 :flash_thread_(osPriorityNormal, 2 * 1024)
gmehmet 1:f60eafbf009a 123 {
gmehmet 1:f60eafbf009a 124 cmd_idx = 0;
gmehmet 1:f60eafbf009a 125 silent_mode = false;
gmehmet 1:f60eafbf009a 126 pause_mode = false;
gmehmet 1:f60eafbf009a 127
gmehmet 1:f60eafbf009a 128 memset(sensor_list, 0, DS_MAX_NUM_SENSORCOMMS * sizeof(SensorComm*));
gmehmet 1:f60eafbf009a 129 num_sensors = 0;
gmehmet 1:f60eafbf009a 130
gmehmet 1:f60eafbf009a 131 m_USB = USB;
gmehmet 1:f60eafbf009a 132
gmehmet 1:f60eafbf009a 133 ds_console_interface_exists_ = false;
gmehmet 1:f60eafbf009a 134 recordingStarted = false;
gmehmet 1:f60eafbf009a 135
gmehmet 1:f60eafbf009a 136 ds_queue_flash_ = &ds_queue_one_;
gmehmet 1:f60eafbf009a 137 ds_queue_fill_ = &ds_queue_two_;
gmehmet 1:f60eafbf009a 138 queue_init(ds_queue_flash_, buffer_one_, FLASH_MESSAGE_SIZE, sizeof(buffer_one_));
gmehmet 1:f60eafbf009a 139 queue_init(ds_queue_fill_, buffer_two_, FLASH_MESSAGE_SIZE, sizeof(buffer_two_));
gmehmet 1:f60eafbf009a 140 flash_thread_.start(callback(&event_queue_, &EventQueue::dispatch_forever));
gmehmet 1:f60eafbf009a 141 }
gmehmet 1:f60eafbf009a 142
gmehmet 1:f60eafbf009a 143 DSInterface::~DSInterface()
gmehmet 1:f60eafbf009a 144 {
gmehmet 1:f60eafbf009a 145 }
gmehmet 1:f60eafbf009a 146
gmehmet 1:f60eafbf009a 147 void DSInterface::add_sensor_comm(SensorComm *s)
gmehmet 1:f60eafbf009a 148 {
gmehmet 1:f60eafbf009a 149 mxm_assert_msg(num_sensors < DS_MAX_NUM_SENSORCOMMS, "Too many sensors added to DSInterface. Increase DS_MAX_NUM_SENSORCOMMS.");
gmehmet 1:f60eafbf009a 150 sensor_list[num_sensors++] = s;
gmehmet 1:f60eafbf009a 151 }
gmehmet 1:f60eafbf009a 152
gmehmet 1:f60eafbf009a 153 void DSInterface::enable_console_interface()
gmehmet 1:f60eafbf009a 154 {
gmehmet 1:f60eafbf009a 155 ds_console_interface_exists_ = true;
gmehmet 1:f60eafbf009a 156 }
gmehmet 1:f60eafbf009a 157
gmehmet 1:f60eafbf009a 158 void DSInterface::ds_set_ble_status(bool en){
gmehmet 1:f60eafbf009a 159 SensorComm *p_sensor;
gmehmet 1:f60eafbf009a 160 ds_ble_interface_exists_ = en;
gmehmet 1:f60eafbf009a 161
gmehmet 1:f60eafbf009a 162 for(int sensor_num = 0; sensor_num < num_sensors; ++sensor_num) {
gmehmet 1:f60eafbf009a 163 p_sensor = sensor_list[sensor_num];
gmehmet 1:f60eafbf009a 164 p_sensor->SensorComm_Set_Ble_Status(ds_ble_interface_exists_);
gmehmet 1:f60eafbf009a 165 }
gmehmet 1:f60eafbf009a 166 }
gmehmet 1:f60eafbf009a 167
gmehmet 1:f60eafbf009a 168 void DSInterface::ds_set_flash_rec_status(bool en) {
gmehmet 1:f60eafbf009a 169 SensorComm *p_sensor;
gmehmet 1:f60eafbf009a 170 recordingStarted = en;
gmehmet 1:f60eafbf009a 171 for(int sensor_num = 0; sensor_num < num_sensors; ++sensor_num) {
gmehmet 1:f60eafbf009a 172 p_sensor = sensor_list[sensor_num];
gmehmet 1:f60eafbf009a 173 p_sensor->SensorComm_Set_Flash_Status(en);
gmehmet 1:f60eafbf009a 174 }
gmehmet 1:f60eafbf009a 175 }
gmehmet 1:f60eafbf009a 176
gmehmet 1:f60eafbf009a 177 void DSInterface::build_command(char ch)
gmehmet 1:f60eafbf009a 178 {
gmehmet 1:f60eafbf009a 179 if (!this->silent_mode) /* BUG: POTENTIAL BUG, what uart port to echo, not only console */
gmehmet 1:f60eafbf009a 180 m_USB->printf("%c", ch);
gmehmet 1:f60eafbf009a 181
gmehmet 1:f60eafbf009a 182 if (ch == 0x00) {
gmehmet 1:f60eafbf009a 183 pr_err("Ignored char 0x00");
gmehmet 1:f60eafbf009a 184 return;
gmehmet 1:f60eafbf009a 185 }
gmehmet 1:f60eafbf009a 186
gmehmet 1:f60eafbf009a 187 if ((ch == '\n') || (ch == '\r')) {
gmehmet 1:f60eafbf009a 188 if (cmd_idx < (int)CONSOLE_STR_BUF_SZ)
gmehmet 1:f60eafbf009a 189 cmd_str[cmd_idx++] = '\0';
gmehmet 1:f60eafbf009a 190 m_USB->printf("\r\n");
gmehmet 1:f60eafbf009a 191 parse_command();
gmehmet 1:f60eafbf009a 192
gmehmet 1:f60eafbf009a 193 //Clear cmd_str
gmehmet 1:f60eafbf009a 194 while (cmd_idx > 0) /* BUG: POTENTIAL BUG for multiple port access */
gmehmet 1:f60eafbf009a 195 cmd_str[--cmd_idx] = '\0';
gmehmet 1:f60eafbf009a 196
gmehmet 1:f60eafbf009a 197 } else if ((ch == 0x08 || ch == 0x7F) && cmd_idx > 0) {
gmehmet 1:f60eafbf009a 198 //Backspace character
gmehmet 1:f60eafbf009a 199 if (cmd_idx > 0)
gmehmet 1:f60eafbf009a 200 cmd_str[--cmd_idx] = '\0';
gmehmet 1:f60eafbf009a 201 } else {
gmehmet 1:f60eafbf009a 202 /* BUG: POTENTIAL BUG for multiple port access */
gmehmet 1:f60eafbf009a 203 if (cmd_idx < (int)CONSOLE_STR_BUF_SZ)
gmehmet 1:f60eafbf009a 204 cmd_str[cmd_idx++] = ch;
gmehmet 1:f60eafbf009a 205 }
gmehmet 1:f60eafbf009a 206
gmehmet 1:f60eafbf009a 207 }
gmehmet 1:f60eafbf009a 208
gmehmet 1:f60eafbf009a 209 void DSInterface::stopcommand() {
gmehmet 1:f60eafbf009a 210 for (int i = 0; i < num_sensors; i++) {
gmehmet 1:f60eafbf009a 211 sensor_list[i]->stop();
gmehmet 1:f60eafbf009a 212 }
gmehmet 1:f60eafbf009a 213 ds_set_flash_rec_status(false);
gmehmet 1:f60eafbf009a 214
gmehmet 1:f60eafbf009a 215 }
gmehmet 1:f60eafbf009a 216
gmehmet 1:f60eafbf009a 217 void DSInterface::parse_command_str(const char* cmd ) {
gmehmet 1:f60eafbf009a 218 strncpy(cmd_str, cmd , strlen(cmd) + 1);
gmehmet 1:f60eafbf009a 219 parse_command();
gmehmet 1:f60eafbf009a 220 }
gmehmet 1:f60eafbf009a 221
gmehmet 1:f60eafbf009a 222 void DSInterface::write_to_flash_thread_funct() {
gmehmet 1:f60eafbf009a 223 //static Timer mytimer;
gmehmet 1:f60eafbf009a 224 //mytimer.reset();
gmehmet 1:f60eafbf009a 225 //mytimer.start();
gmehmet 1:f60eafbf009a 226 fwrite((uint8_t*)ds_queue_flash_->base, 1, ds_queue_flash_->item_size * ds_queue_flash_->num_item, flashFileHandle);
gmehmet 1:f60eafbf009a 227 queue_reset(ds_queue_flash_);
gmehmet 1:f60eafbf009a 228 //mytimer.stop();
gmehmet 1:f60eafbf009a 229 //printf("%f seconds\n", mytimer.read());
gmehmet 1:f60eafbf009a 230 }
gmehmet 1:f60eafbf009a 231
gmehmet 1:f60eafbf009a 232 void DSInterface::parse_command()
gmehmet 1:f60eafbf009a 233 {
gmehmet 1:f60eafbf009a 234 int i;
gmehmet 1:f60eafbf009a 235 glbl_cmd_state cmd;
gmehmet 1:f60eafbf009a 236 char charbuf[512];
gmehmet 1:f60eafbf009a 237 char tempbuf[32];
gmehmet 1:f60eafbf009a 238 int data_len = 0;
gmehmet 1:f60eafbf009a 239 int data_len_log=0;
gmehmet 1:f60eafbf009a 240 int ret;
gmehmet 1:f60eafbf009a 241 bool parsed_cmd = true;
gmehmet 1:f60eafbf009a 242
gmehmet 1:f60eafbf009a 243 printf("%s \n",cmd_str );
gmehmet 1:f60eafbf009a 244
gmehmet 1:f60eafbf009a 245 //If top level command, then handle it
gmehmet 1:f60eafbf009a 246 for (i = 0; i < NUM_CMDS; i++) {
gmehmet 1:f60eafbf009a 247 if (starts_with(&cmd_str[0], glbl_cmds[i])) {
gmehmet 1:f60eafbf009a 248 cmd = (glbl_cmd_state)i;
gmehmet 1:f60eafbf009a 249
gmehmet 1:f60eafbf009a 250 switch (cmd) {
gmehmet 1:f60eafbf009a 251 case (enable_ascii_mode): {
gmehmet 1:f60eafbf009a 252 sensor_list[0]->AsciiEn = true;
gmehmet 1:f60eafbf009a 253 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 254 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 255 } break;
gmehmet 1:f60eafbf009a 256 case (enable_bin_mode): {
gmehmet 1:f60eafbf009a 257 sensor_list[0]->AsciiEn = false;
gmehmet 1:f60eafbf009a 258 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 259 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 260 } break;
gmehmet 1:f60eafbf009a 261 case (stop): {
gmehmet 1:f60eafbf009a 262 for (int i = 0; i < num_sensors; i++) {
gmehmet 1:f60eafbf009a 263 sensor_list[i]->stop();
gmehmet 1:f60eafbf009a 264 }
gmehmet 1:f60eafbf009a 265
gmehmet 1:f60eafbf009a 266 ds_set_flash_rec_status(false);
gmehmet 1:f60eafbf009a 267
gmehmet 1:f60eafbf009a 268 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 269 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 270 } break;
gmehmet 1:f60eafbf009a 271 case (get_device_info): {
gmehmet 1:f60eafbf009a 272
gmehmet 1:f60eafbf009a 273 data_len = snprintf(charbuf, sizeof(charbuf),
gmehmet 1:f60eafbf009a 274 "\r\n%s platform=%s firmware_ver=%s sensors=", cmd_str, platform_name, FIRMWARE_VERSION);
gmehmet 1:f60eafbf009a 275
gmehmet 1:f60eafbf009a 276 //Add list of sensors
gmehmet 1:f60eafbf009a 277 for (int i = 0; i < num_sensors; i++) {
gmehmet 1:f60eafbf009a 278 if (sensor_list[i]->is_visible()) {
gmehmet 1:f60eafbf009a 279 data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len,
gmehmet 1:f60eafbf009a 280 "%s", sensor_list[i]->get_type());
gmehmet 1:f60eafbf009a 281 if (i < (num_sensors - 1))
gmehmet 1:f60eafbf009a 282 data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, ",");
gmehmet 1:f60eafbf009a 283 }
gmehmet 1:f60eafbf009a 284 }
gmehmet 1:f60eafbf009a 285
gmehmet 1:f60eafbf009a 286
gmehmet 1:f60eafbf009a 287 for (int i = 0; i < num_sensors; i++) {
gmehmet 1:f60eafbf009a 288 SensorComm *s = sensor_list[i];
gmehmet 1:f60eafbf009a 289 if (!s->is_visible())
gmehmet 1:f60eafbf009a 290 continue;
gmehmet 1:f60eafbf009a 291
gmehmet 1:f60eafbf009a 292 //Add algo_ver
gmehmet 1:f60eafbf009a 293 data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len,
gmehmet 1:f60eafbf009a 294 " algo_ver_%s=%s", s->get_type(), s->get_algo_ver());
gmehmet 1:f60eafbf009a 295
gmehmet 1:f60eafbf009a 296 //Add part name
gmehmet 1:f60eafbf009a 297 data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len,
gmehmet 1:f60eafbf009a 298 " part_name_%s=%s", s->get_type(), s->get_part_name());
gmehmet 1:f60eafbf009a 299
gmehmet 1:f60eafbf009a 300 uint8_t part_id, part_rev;
gmehmet 1:f60eafbf009a 301 ret = s->get_part_info(&part_id, &part_rev);
gmehmet 1:f60eafbf009a 302
gmehmet 1:f60eafbf009a 303 if (ret == 0) {
gmehmet 1:f60eafbf009a 304 //Add part id
gmehmet 1:f60eafbf009a 305 data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len,
gmehmet 1:f60eafbf009a 306 " part_id_%s=%d", s->get_type(), part_id);
gmehmet 1:f60eafbf009a 307
gmehmet 1:f60eafbf009a 308 //Add rev id
gmehmet 1:f60eafbf009a 309 data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len,
gmehmet 1:f60eafbf009a 310 " part_rev_%s=%d", s->get_type(), part_rev);
gmehmet 1:f60eafbf009a 311 }
gmehmet 1:f60eafbf009a 312 }
gmehmet 1:f60eafbf009a 313
gmehmet 1:f60eafbf009a 314 if(firmware_version){
gmehmet 1:f60eafbf009a 315 data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, " hub_firm_ver=%s", firmware_version);
gmehmet 1:f60eafbf009a 316 if(algo_desc_strsz > 0)
gmehmet 1:f60eafbf009a 317 data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, "%s", algo_desc_string);
gmehmet 1:f60eafbf009a 318 }
gmehmet 1:f60eafbf009a 319
gmehmet 1:f60eafbf009a 320 data_len += snprintf(charbuf + data_len, sizeof(charbuf) - data_len, " err=0\r\n");
gmehmet 1:f60eafbf009a 321
gmehmet 1:f60eafbf009a 322 } break;
gmehmet 1:f60eafbf009a 323 case (silent0_mode): {
gmehmet 1:f60eafbf009a 324 silent_mode = false;
gmehmet 1:f60eafbf009a 325 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 326 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 327 } break;
gmehmet 1:f60eafbf009a 328 case (silent1_mode): {
gmehmet 1:f60eafbf009a 329 silent_mode = true;
gmehmet 1:f60eafbf009a 330 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 331 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 332 } break;
gmehmet 1:f60eafbf009a 333 case (pause0_mode): {
gmehmet 1:f60eafbf009a 334 pause_mode = false;
gmehmet 1:f60eafbf009a 335 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 336 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 337 } break;
gmehmet 1:f60eafbf009a 338 case (pause1_mode): {
gmehmet 1:f60eafbf009a 339 pause_mode = true;
gmehmet 1:f60eafbf009a 340 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 341 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 342 } break;
gmehmet 1:f60eafbf009a 343 case (enable_console): {
gmehmet 1:f60eafbf009a 344 ds_console_interface_exists_ = true;
gmehmet 1:f60eafbf009a 345 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 346 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 347 } break;
gmehmet 1:f60eafbf009a 348 case (disable_console): {
gmehmet 1:f60eafbf009a 349 ds_console_interface_exists_ = false;
gmehmet 1:f60eafbf009a 350 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 351 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 352 } break;
gmehmet 1:f60eafbf009a 353 case (set_lcd_time): {
gmehmet 1:f60eafbf009a 354
gmehmet 1:f60eafbf009a 355 while(1)
gmehmet 1:f60eafbf009a 356 {
gmehmet 1:f60eafbf009a 357 if(cmd_str[17+lcd_time_count] == '\0')
gmehmet 1:f60eafbf009a 358 {
gmehmet 1:f60eafbf009a 359 lcd_time_str[lcd_time_count] = '\0';
gmehmet 1:f60eafbf009a 360 break;
gmehmet 1:f60eafbf009a 361 }
gmehmet 1:f60eafbf009a 362 lcd_time_str[lcd_time_count] = cmd_str[17+lcd_time_count];
gmehmet 1:f60eafbf009a 363 lcd_time_count++;
gmehmet 1:f60eafbf009a 364 }
gmehmet 1:f60eafbf009a 365
gmehmet 1:f60eafbf009a 366 sscanf(lcd_time_str,"%d",&lcd_time_val);
gmehmet 1:f60eafbf009a 367
gmehmet 1:f60eafbf009a 368 set_time(lcd_time_val);
gmehmet 1:f60eafbf009a 369
gmehmet 1:f60eafbf009a 370 lcd_time_count=0;
gmehmet 1:f60eafbf009a 371
gmehmet 1:f60eafbf009a 372 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 373 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 374
gmehmet 1:f60eafbf009a 375 } break;
gmehmet 1:f60eafbf009a 376 case (set_flash_log): {
gmehmet 1:f60eafbf009a 377
gmehmet 1:f60eafbf009a 378
gmehmet 1:f60eafbf009a 379
gmehmet 1:f60eafbf009a 380 if(cmd_str[18] == '1' )
gmehmet 1:f60eafbf009a 381 {
gmehmet 1:f60eafbf009a 382
gmehmet 1:f60eafbf009a 383
gmehmet 1:f60eafbf009a 384
gmehmet 1:f60eafbf009a 385 time_t seconds;
gmehmet 1:f60eafbf009a 386 seconds = time(NULL);
gmehmet 1:f60eafbf009a 387 strftime(tempbuf, 32, "/fs/log-%I-%M-%S.maximlog", localtime(&seconds));
gmehmet 1:f60eafbf009a 388
gmehmet 1:f60eafbf009a 389 flashFileHandle = fopen(tempbuf, "w+");
gmehmet 1:f60eafbf009a 390
gmehmet 1:f60eafbf009a 391 if ( flashFileHandle != NULL ) {
gmehmet 1:f60eafbf009a 392
gmehmet 1:f60eafbf009a 393 fprintf(flashFileHandle,"mxim");
gmehmet 1:f60eafbf009a 394
gmehmet 1:f60eafbf009a 395 //1 byte to indicate the version of the log
gmehmet 1:f60eafbf009a 396 unsigned char vers = 0;
gmehmet 1:f60eafbf009a 397 //4 bytes to indicate the number of bytes used to write the format
gmehmet 1:f60eafbf009a 398 unsigned int NumByteBLE = 764;
gmehmet 1:f60eafbf009a 399 unsigned int NumByteNoBLE = 659;
gmehmet 1:f60eafbf009a 400
gmehmet 1:f60eafbf009a 401 fwrite(&vers,sizeof(unsigned char),1,flashFileHandle);
gmehmet 1:f60eafbf009a 402
gmehmet 1:f60eafbf009a 403 if(BLE::Instance().gap().getState().connected){
gmehmet 1:f60eafbf009a 404 fwrite(&NumByteBLE,sizeof(unsigned int),1,flashFileHandle);
gmehmet 1:f60eafbf009a 405 }
gmehmet 1:f60eafbf009a 406 else
gmehmet 1:f60eafbf009a 407 fwrite(&NumByteNoBLE,sizeof(unsigned int),1,flashFileHandle);
gmehmet 1:f60eafbf009a 408
gmehmet 1:f60eafbf009a 409 ds_set_flash_rec_status(true);
gmehmet 1:f60eafbf009a 410
gmehmet 1:f60eafbf009a 411 //Write the formats
gmehmet 1:f60eafbf009a 412 data_len_log += snprintf(logbuf+data_len_log, sizeof(logbuf) - data_len_log- 1,"ppg 0 cs=1 format={smpleCnt,16},"
gmehmet 1:f60eafbf009a 413 "{grnCnt,20},{grn2Cnt,20},{accelX,14,3},{accelY,14,3},"
gmehmet 1:f60eafbf009a 414 "{accelZ,14,3},{hr,12},{hrconf,8},{r,11,1},{activity,8}\n"
gmehmet 1:f60eafbf009a 415 "ppg 1 cs=1 format={smpleCnt,8},{irCnt,20},{redCnt,20},{accelX,14,3},"
gmehmet 1:f60eafbf009a 416 "{accelY,14,3},{accelZ,14,3},{r,12,1},{wspo2conf,8},"
gmehmet 1:f60eafbf009a 417 "{spo2,11,1},{wspo2percentcomplete,8},{wspo2lowSNR,1},{wspo2motion,1},{status,8}\n"
gmehmet 1:f60eafbf009a 418 "bpt 0 cs=1 format={status,4},{irCnt,19},{hr,9},"
gmehmet 1:f60eafbf009a 419 "{prog,9},{sys_bp,9},{dia_bp,9}\n"
gmehmet 1:f60eafbf009a 420 "bpt 1 cs=1 format={status,4},{irCnt,19},{hr,9},"
gmehmet 1:f60eafbf009a 421 "{prog,9},{sys_bp,9},{dia_bp,9}\n");
gmehmet 1:f60eafbf009a 422 if(BLE::Instance().gap().getState().connected){
gmehmet 1:f60eafbf009a 423 data_len_log += snprintf(logbuf+data_len_log, sizeof(logbuf) -data_len_log- 1,"ecg 1 cs=1 format={smpleCnt,8},{rtor,14},{rtorbpm,8},"
gmehmet 1:f60eafbf009a 424 "{pTag.0,3},{eTag.0,3},{ecg.0,18},{pTag.1,3},{eTag.1,3},{ecg.1,18},"
gmehmet 1:f60eafbf009a 425 "{pTag.2,3},{eTag.2,3},{ecg.2,18},{pTag.3,3},{eTag.3,3},{ecg.3,18}\n");
gmehmet 1:f60eafbf009a 426 }else{
gmehmet 1:f60eafbf009a 427 data_len_log += snprintf(logbuf+data_len_log, sizeof(logbuf) -data_len_log- 1,"ecg 1 cs=1 format={smpleCnt,8},{pTag,3},{eTag,3},"
gmehmet 1:f60eafbf009a 428 "{ecg,18},{rtor,14},{rtorbpm,8}\n");
gmehmet 1:f60eafbf009a 429 }
gmehmet 1:f60eafbf009a 430 data_len_log += snprintf(logbuf+data_len_log, sizeof(logbuf)-data_len_log - 1,"ecg 2 cs=1 format={smplCnt,8},{rtor,15}\n");
gmehmet 1:f60eafbf009a 431 data_len_log += snprintf(logbuf+data_len_log, sizeof(logbuf) -data_len_log-1,"temp 0 cs=1 format={smpleCnt,8},{temp,16,2}\n");
gmehmet 1:f60eafbf009a 432
gmehmet 1:f60eafbf009a 433
gmehmet 1:f60eafbf009a 434 fprintf(flashFileHandle,logbuf,data_len_log);
gmehmet 1:f60eafbf009a 435 }
gmehmet 1:f60eafbf009a 436 else {
gmehmet 1:f60eafbf009a 437 ds_set_flash_rec_status(false);
gmehmet 1:f60eafbf009a 438 }
gmehmet 1:f60eafbf009a 439
gmehmet 1:f60eafbf009a 440 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 441 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 442
gmehmet 1:f60eafbf009a 443
gmehmet 1:f60eafbf009a 444
gmehmet 1:f60eafbf009a 445 }
gmehmet 1:f60eafbf009a 446
gmehmet 1:f60eafbf009a 447 else if (cmd_str[18] == '0'){
gmehmet 1:f60eafbf009a 448 ds_set_flash_rec_status(false);
gmehmet 1:f60eafbf009a 449 handle_file_close();
gmehmet 1:f60eafbf009a 450 data_len += snprintf(charbuf, sizeof(charbuf) - 1,"\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 451 }
gmehmet 1:f60eafbf009a 452 else{
gmehmet 1:f60eafbf009a 453 //print cmd not recognized string
gmehmet 1:f60eafbf009a 454 data_len += snprintf(charbuf, sizeof(charbuf) - 1,"\r\n%s err=-255\r\n", cmd_str);
gmehmet 1:f60eafbf009a 455 }
gmehmet 1:f60eafbf009a 456
gmehmet 1:f60eafbf009a 457 } break;
gmehmet 1:f60eafbf009a 458 case (set_cfg_report_1): {
gmehmet 1:f60eafbf009a 459 //m_USB->printf("\r\n MODE 1\r\n");
gmehmet 1:f60eafbf009a 460 algo_report_mode = 1;
gmehmet 1:f60eafbf009a 461 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 462 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 463
gmehmet 1:f60eafbf009a 464 } break;
gmehmet 1:f60eafbf009a 465 case (set_cfg_report_2): {
gmehmet 1:f60eafbf009a 466 //m_USB->printf("\r\n MODE 2\r\n");
gmehmet 1:f60eafbf009a 467 algo_report_mode = 2;
gmehmet 1:f60eafbf009a 468 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 469 "\r\n%s err=0\r\n", cmd_str);
gmehmet 1:f60eafbf009a 470 } break;
gmehmet 1:f60eafbf009a 471 default:
gmehmet 1:f60eafbf009a 472 parsed_cmd = false;
gmehmet 1:f60eafbf009a 473 break;
gmehmet 1:f60eafbf009a 474 }
gmehmet 1:f60eafbf009a 475
gmehmet 1:f60eafbf009a 476 if (parsed_cmd) {
gmehmet 1:f60eafbf009a 477 m_USB->printf(charbuf);
gmehmet 1:f60eafbf009a 478
gmehmet 1:f60eafbf009a 479 if (BLE::Instance().gap().getState().connected) {
gmehmet 1:f60eafbf009a 480 BLE_Icarus_AddtoQueue((uint8_t *)charbuf, (int32_t)sizeof(charbuf), data_len);
gmehmet 1:f60eafbf009a 481 }
gmehmet 1:f60eafbf009a 482
gmehmet 1:f60eafbf009a 483 }
gmehmet 1:f60eafbf009a 484
gmehmet 1:f60eafbf009a 485 return;
gmehmet 1:f60eafbf009a 486 }
gmehmet 1:f60eafbf009a 487 }
gmehmet 1:f60eafbf009a 488
gmehmet 1:f60eafbf009a 489 //Set the stream type to check the data streaming type later
gmehmet 1:f60eafbf009a 490 if(starts_with(&cmd_str[0],"read ppg 0")){
gmehmet 1:f60eafbf009a 491 stream_type=0x00;
gmehmet 1:f60eafbf009a 492 }
gmehmet 1:f60eafbf009a 493 else if(starts_with(&cmd_str[0],"read ppg 1")){
gmehmet 1:f60eafbf009a 494 stream_type=0x01;
gmehmet 1:f60eafbf009a 495 }
gmehmet 1:f60eafbf009a 496 else if(starts_with(&cmd_str[0],"read bpt 0")){
gmehmet 1:f60eafbf009a 497 stream_type=0x02;
gmehmet 1:f60eafbf009a 498 }
gmehmet 1:f60eafbf009a 499 else if(starts_with(&cmd_str[0],"read bpt 1")){
gmehmet 1:f60eafbf009a 500 stream_type=0x03;
gmehmet 1:f60eafbf009a 501 }
gmehmet 1:f60eafbf009a 502 else if(starts_with(&cmd_str[0],"read ecg 1")){
gmehmet 1:f60eafbf009a 503 stream_type=0x04;
gmehmet 1:f60eafbf009a 504 }
gmehmet 1:f60eafbf009a 505 else if(starts_with(&cmd_str[0],"read ecg 2")){
gmehmet 1:f60eafbf009a 506 stream_type=0x05;
gmehmet 1:f60eafbf009a 507 }
gmehmet 1:f60eafbf009a 508 else if(starts_with(&cmd_str[0],"read temp 0")){
gmehmet 1:f60eafbf009a 509 stream_type=0x06;
gmehmet 1:f60eafbf009a 510 }
gmehmet 1:f60eafbf009a 511
gmehmet 1:f60eafbf009a 512 //Loop through each sensor in sensorList
gmehmet 1:f60eafbf009a 513 //If sensor.get_type() is contained in cmd_str, pass cmd_str to that sensor's parser
gmehmet 1:f60eafbf009a 514 for (int i = 0; i < num_sensors; i++) {
gmehmet 1:f60eafbf009a 515 if (strstr(&cmd_str[0], sensor_list[i]->get_type())) {
gmehmet 1:f60eafbf009a 516 if (sensor_list[i]->parse_command(cmd_str))
gmehmet 1:f60eafbf009a 517 return;
gmehmet 1:f60eafbf009a 518
gmehmet 1:f60eafbf009a 519 break;
gmehmet 1:f60eafbf009a 520 }
gmehmet 1:f60eafbf009a 521 }
gmehmet 1:f60eafbf009a 522
gmehmet 1:f60eafbf009a 523 //If we still haven't found a way to parse the command,
gmehmet 1:f60eafbf009a 524 //send it to every sensor until one handles it
gmehmet 1:f60eafbf009a 525 for (int i = 0; i < num_sensors; i++) {
gmehmet 1:f60eafbf009a 526 if (sensor_list[i]->parse_command(cmd_str))
gmehmet 1:f60eafbf009a 527 return;
gmehmet 1:f60eafbf009a 528 }
gmehmet 1:f60eafbf009a 529
gmehmet 1:f60eafbf009a 530
gmehmet 1:f60eafbf009a 531 //No one could handle the command, print cmd not recognized string
gmehmet 1:f60eafbf009a 532 data_len += snprintf(charbuf, sizeof(charbuf) - 1,
gmehmet 1:f60eafbf009a 533 "\r\n%s err=-255\r\n", cmd_str);
gmehmet 1:f60eafbf009a 534 m_USB->printf(charbuf);
gmehmet 1:f60eafbf009a 535
gmehmet 1:f60eafbf009a 536 if (BLE::Instance().gap().getState().connected) {
gmehmet 1:f60eafbf009a 537 BLE_Icarus_AddtoQueue((uint8_t *)charbuf, (int32_t)sizeof(charbuf), data_len);
gmehmet 1:f60eafbf009a 538 }
gmehmet 1:f60eafbf009a 539
gmehmet 1:f60eafbf009a 540 }
gmehmet 1:f60eafbf009a 541
gmehmet 1:f60eafbf009a 542 void DSInterface::swap_queues() {
gmehmet 1:f60eafbf009a 543 if(flash_thread_.get_state() != Thread::WaitingEventFlag){
gmehmet 1:f60eafbf009a 544 printf("overflow happened state %d\r\n", flash_thread_.get_state());
gmehmet 1:f60eafbf009a 545 return;
gmehmet 1:f60eafbf009a 546 }
gmehmet 1:f60eafbf009a 547 queue_t * temp_queue = ds_queue_flash_;
gmehmet 1:f60eafbf009a 548 ds_queue_flash_ = ds_queue_fill_;
gmehmet 1:f60eafbf009a 549 ds_queue_fill_ = temp_queue;
gmehmet 1:f60eafbf009a 550 event_queue_.call(Callback<void()>(this, &DSInterface::write_to_flash_thread_funct));
gmehmet 1:f60eafbf009a 551 }
gmehmet 1:f60eafbf009a 552
gmehmet 1:f60eafbf009a 553 void DSInterface::handle_file_close() {
gmehmet 1:f60eafbf009a 554 //if recording is enabled do not close the file
gmehmet 1:f60eafbf009a 555 if(recordingStarted) {
gmehmet 1:f60eafbf009a 556 return;
gmehmet 1:f60eafbf009a 557 }
gmehmet 1:f60eafbf009a 558 if(flashFileHandle != NULL) {
gmehmet 1:f60eafbf009a 559 if(flash_thread_.get_state() != Thread::WaitingEventFlag)
gmehmet 1:f60eafbf009a 560 return;
gmehmet 1:f60eafbf009a 561
gmehmet 1:f60eafbf009a 562 if(ds_queue_fill_->num_item){
gmehmet 1:f60eafbf009a 563 swap_queues();
gmehmet 1:f60eafbf009a 564 return;
gmehmet 1:f60eafbf009a 565 }
gmehmet 1:f60eafbf009a 566 printf("closing file\r\n");
gmehmet 1:f60eafbf009a 567 fclose(flashFileHandle);
gmehmet 1:f60eafbf009a 568 flashFileHandle = NULL;
gmehmet 1:f60eafbf009a 569 }
gmehmet 1:f60eafbf009a 570 }
gmehmet 1:f60eafbf009a 571
gmehmet 1:f60eafbf009a 572
gmehmet 1:f60eafbf009a 573 void DSInterface::force_file_close() {
gmehmet 1:f60eafbf009a 574 if(flashFileHandle != NULL) {
gmehmet 1:f60eafbf009a 575 while(flash_thread_.get_state() != Thread::WaitingEventFlag) {
gmehmet 1:f60eafbf009a 576 wait_ms(1);
gmehmet 1:f60eafbf009a 577 }
gmehmet 1:f60eafbf009a 578
gmehmet 1:f60eafbf009a 579 if(ds_queue_fill_->num_item){
gmehmet 1:f60eafbf009a 580 swap_queues();
gmehmet 1:f60eafbf009a 581 }
gmehmet 1:f60eafbf009a 582
gmehmet 1:f60eafbf009a 583 while(flash_thread_.get_state() != Thread::WaitingEventFlag) {
gmehmet 1:f60eafbf009a 584 wait_ms(1);
gmehmet 1:f60eafbf009a 585 }
gmehmet 1:f60eafbf009a 586
gmehmet 1:f60eafbf009a 587 //printf("closing file\r\n");
gmehmet 1:f60eafbf009a 588 fclose(flashFileHandle);
gmehmet 1:f60eafbf009a 589 flashFileHandle = NULL;
gmehmet 1:f60eafbf009a 590 }
gmehmet 1:f60eafbf009a 591 }
gmehmet 1:f60eafbf009a 592
gmehmet 1:f60eafbf009a 593 #define ECGSENSOR_ID 0x02 //TODO:FIX THESE
gmehmet 1:f60eafbf009a 594 #define ECGSENSOR_DATA_REPORT_MODE 0x04 //TODO:FIX THESE
gmehmet 1:f60eafbf009a 595 void DSInterface::data_report_execute() {
gmehmet 1:f60eafbf009a 596 char buffer[256];
gmehmet 1:f60eafbf009a 597 int data_len = 0;
gmehmet 1:f60eafbf009a 598 buffer[0] = '\0';
gmehmet 1:f60eafbf009a 599 int ret;
gmehmet 1:f60eafbf009a 600 bool all_sensors_disabled = true;
gmehmet 1:f60eafbf009a 601
gmehmet 1:f60eafbf009a 602 for (int i = 0; i < num_sensors; i++) {
gmehmet 1:f60eafbf009a 603 //if ((*it)->is_enabled()) {
gmehmet 1:f60eafbf009a 604
gmehmet 1:f60eafbf009a 605 if(!recordingStarted)
gmehmet 1:f60eafbf009a 606 data_len = sensor_list[i]->data_report_execute(buffer, sizeof(buffer));
gmehmet 1:f60eafbf009a 607 else
gmehmet 1:f60eafbf009a 608 data_len = sensor_list[i]->data_report_execute(buffer + FLASH_MESSAGE_OFFSET
gmehmet 1:f60eafbf009a 609 , sizeof(buffer) - FLASH_MESSAGE_OFFSET);
gmehmet 1:f60eafbf009a 610
gmehmet 1:f60eafbf009a 611 if (!this->pause_mode && (data_len > 0)) {
gmehmet 1:f60eafbf009a 612 all_sensors_disabled = false;
gmehmet 1:f60eafbf009a 613
gmehmet 1:f60eafbf009a 614 if ((flashFileHandle != NULL) && (recordingStarted)) {
gmehmet 1:f60eafbf009a 615 if(data_len + FLASH_MESSAGE_OFFSET != ds_queue_flash_->item_size) {
gmehmet 1:f60eafbf009a 616 printf("Reinit item size: %d\r\n", data_len);
gmehmet 1:f60eafbf009a 617 queue_update_items_size(ds_queue_flash_, (data_len+ FLASH_MESSAGE_OFFSET));
gmehmet 1:f60eafbf009a 618 queue_update_items_size(ds_queue_fill_, (data_len+ FLASH_MESSAGE_OFFSET));
gmehmet 1:f60eafbf009a 619 }
gmehmet 1:f60eafbf009a 620 //set stream type
gmehmet 1:f60eafbf009a 621 buffer[0] = stream_type;
gmehmet 1:f60eafbf009a 622
gmehmet 1:f60eafbf009a 623 // enqueue data
gmehmet 1:f60eafbf009a 624 ret = enqueue(ds_queue_fill_, buffer);
gmehmet 1:f60eafbf009a 625 if(ret != 0) {
gmehmet 1:f60eafbf009a 626 printf("enqueue has failed %d\r\n", ds_queue_fill_->num_item);
gmehmet 1:f60eafbf009a 627 }
gmehmet 1:f60eafbf009a 628 if(queue_is_full(ds_queue_fill_)) {
gmehmet 1:f60eafbf009a 629 swap_queues();
gmehmet 1:f60eafbf009a 630 }
gmehmet 1:f60eafbf009a 631 }
gmehmet 1:f60eafbf009a 632
gmehmet 1:f60eafbf009a 633
gmehmet 1:f60eafbf009a 634 if (BLE::Instance().gap().getState().connected & !recordingStarted) {
gmehmet 1:f60eafbf009a 635 ds_console_interface_exists_ = false;
gmehmet 1:f60eafbf009a 636 BLE_Icarus_AddtoQueue((uint8_t *)buffer, (int32_t)sizeof(buffer), data_len);
gmehmet 1:f60eafbf009a 637 }
gmehmet 1:f60eafbf009a 638
gmehmet 1:f60eafbf009a 639 if (ds_console_interface_exists_ & !recordingStarted){
gmehmet 1:f60eafbf009a 640 if(sensor_list[0]->AsciiEn){
gmehmet 1:f60eafbf009a 641 m_USB->printf(buffer);
gmehmet 1:f60eafbf009a 642 }
gmehmet 1:f60eafbf009a 643 else{
gmehmet 1:f60eafbf009a 644 m_USB->writeBlock((uint8_t*)buffer, data_len);
gmehmet 1:f60eafbf009a 645 }
gmehmet 1:f60eafbf009a 646 }
gmehmet 1:f60eafbf009a 647 data_len = 0;
gmehmet 1:f60eafbf009a 648 }
gmehmet 1:f60eafbf009a 649 }
gmehmet 1:f60eafbf009a 650
gmehmet 1:f60eafbf009a 651 if(all_sensors_disabled)
gmehmet 1:f60eafbf009a 652 handle_file_close();
gmehmet 1:f60eafbf009a 653 }
gmehmet 1:f60eafbf009a 654
gmehmet 1:f60eafbf009a 655 void DSInterface::set_fw_version(const char* version)
gmehmet 1:f60eafbf009a 656 {
gmehmet 1:f60eafbf009a 657 if (version && *version){
gmehmet 1:f60eafbf009a 658 firmware_version = version;
gmehmet 1:f60eafbf009a 659 algo_desc_strsz = get_fw_algorithms();
gmehmet 1:f60eafbf009a 660 }
gmehmet 1:f60eafbf009a 661 }
gmehmet 1:f60eafbf009a 662
gmehmet 1:f60eafbf009a 663 int DSInterface::get_fw_algorithms( void )
gmehmet 1:f60eafbf009a 664 {
gmehmet 1:f60eafbf009a 665
gmehmet 1:f60eafbf009a 666 int i, fwToReport;
gmehmet 1:f60eafbf009a 667 char *start, *end;
gmehmet 1:f60eafbf009a 668 uint8_t fwIdx[3];
gmehmet 1:f60eafbf009a 669
gmehmet 1:f60eafbf009a 670 start = (char*) firmware_version;
gmehmet 1:f60eafbf009a 671
gmehmet 1:f60eafbf009a 672 /*MYG: no need to optimize ,lib function call, just called once at start of execution*/
gmehmet 1:f60eafbf009a 673
gmehmet 1:f60eafbf009a 674 fwIdx[0] = (uint8_t) strtol(start,&end, 10) ; start = end;
gmehmet 1:f60eafbf009a 675 fwIdx[1] = (uint8_t) strtol(start+1,&end, 10); start = end;
gmehmet 1:f60eafbf009a 676 fwIdx[2] = (uint8_t) strtol(start+1,&end, 10);
gmehmet 1:f60eafbf009a 677
gmehmet 1:f60eafbf009a 678 fwToReport = -1;
gmehmet 1:f60eafbf009a 679 for( i = 0 ; i < sizeof(HUB_FW_TABLE)/ sizeof(fw_type_t); i++ ){
gmehmet 1:f60eafbf009a 680
gmehmet 1:f60eafbf009a 681 if( HUB_FW_TABLE[i].fwVersion[0] == fwIdx[0]/* &
gmehmet 1:f60eafbf009a 682 HUB_FW_TABLE[i].fwVersion[1] == fwIdx[1] &
gmehmet 1:f60eafbf009a 683 HUB_FW_TABLE[i].fwVersion[2] == fwIdx[2] */) {
gmehmet 1:f60eafbf009a 684
gmehmet 1:f60eafbf009a 685 fwToReport = i;
gmehmet 1:f60eafbf009a 686 break;
gmehmet 1:f60eafbf009a 687 }
gmehmet 1:f60eafbf009a 688 }
gmehmet 1:f60eafbf009a 689
gmehmet 1:f60eafbf009a 690 if(fwToReport == -1){
gmehmet 1:f60eafbf009a 691 return -1;
gmehmet 1:f60eafbf009a 692 }
gmehmet 1:f60eafbf009a 693
gmehmet 1:f60eafbf009a 694 i = ((fwToReport == -1)? 0:1) * ( /*32 bit*/ 32 - __builtin_clz(HUB_FW_TABLE[fwToReport].enAlgoDescBitField));
gmehmet 1:f60eafbf009a 695
gmehmet 1:f60eafbf009a 696 strcpy(&algo_desc_string[0], " fw_algos=");
gmehmet 1:f60eafbf009a 697 int tail = strlen(" fw_algos=");
gmehmet 1:f60eafbf009a 698
gmehmet 1:f60eafbf009a 699 int descStrSz = sizeof(algo_desc_string);
gmehmet 1:f60eafbf009a 700 while(--i && tail < descStrSz) {
gmehmet 1:f60eafbf009a 701
gmehmet 1:f60eafbf009a 702 if( (HUB_FW_TABLE[fwToReport].enAlgoDescBitField >> i) & 0x0001) {
gmehmet 1:f60eafbf009a 703 strcpy( &algo_desc_string[tail], ActivAlgoInfo[i]);
gmehmet 1:f60eafbf009a 704 tail += strlen(ActivAlgoInfo[i]);
gmehmet 1:f60eafbf009a 705 }
gmehmet 1:f60eafbf009a 706
gmehmet 1:f60eafbf009a 707 }
gmehmet 1:f60eafbf009a 708 strcpy( &algo_desc_string[tail-1]," ");
gmehmet 1:f60eafbf009a 709
gmehmet 1:f60eafbf009a 710 return tail;
gmehmet 1:f60eafbf009a 711 //m_USB->printf("%d %s \r\n", tail , algo_desc_string);
gmehmet 1:f60eafbf009a 712
gmehmet 1:f60eafbf009a 713 }
gmehmet 1:f60eafbf009a 714
gmehmet 1:f60eafbf009a 715 void DSInterface::set_fw_platform(const char* platform)
gmehmet 1:f60eafbf009a 716 {
gmehmet 1:f60eafbf009a 717 if (platform && *platform)
gmehmet 1:f60eafbf009a 718 platform_name = platform;
gmehmet 1:f60eafbf009a 719 }