TEST
Dependencies: max32630fthr Adafruit_FeatherOLED USBDevice
Interfaces/DeviceStudio/DSInterface.h@4:291477e8690d, 2020-04-19 (annotated)
- Committer:
- wwwarunraj
- Date:
- Sun Apr 19 11:19:57 2020 +0000
- Revision:
- 4:291477e8690d
- Parent:
- 1:f60eafbf009a
19/04
Who changed what in which revision?
User | Revision | Line number | New 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 | #ifndef _DSINTERFACE_H_ |
gmehmet | 1:f60eafbf009a | 35 | #define _DSINTERFACE_H_ |
gmehmet | 1:f60eafbf009a | 36 | |
gmehmet | 1:f60eafbf009a | 37 | #include "mbed.h" |
gmehmet | 1:f60eafbf009a | 38 | #include <stdint.h> |
gmehmet | 1:f60eafbf009a | 39 | #include "SensorComm.h" |
gmehmet | 1:f60eafbf009a | 40 | #include "MaximSensor.h" |
gmehmet | 1:f60eafbf009a | 41 | #include "USBSerial.h" |
gmehmet | 1:f60eafbf009a | 42 | #include "../../Utilities/queue.h" |
gmehmet | 1:f60eafbf009a | 43 | #include "FATFileSystem.h" |
gmehmet | 1:f60eafbf009a | 44 | |
gmehmet | 1:f60eafbf009a | 45 | |
gmehmet | 1:f60eafbf009a | 46 | #define COMM_SUCCESS 0 |
gmehmet | 1:f60eafbf009a | 47 | #define COMM_GENERAL_ERROR -1 |
gmehmet | 1:f60eafbf009a | 48 | #define COMM_INVALID_PARAM -254 |
gmehmet | 1:f60eafbf009a | 49 | #define COMM_NOT_RECOGNIZED -255 |
gmehmet | 1:f60eafbf009a | 50 | |
gmehmet | 1:f60eafbf009a | 51 | #define FLASH_ERR_GENERAL -1 |
gmehmet | 1:f60eafbf009a | 52 | #define FLASH_ERR_CHECKSUM -2 |
gmehmet | 1:f60eafbf009a | 53 | #define FLASH_ERR_AUTH -3 |
gmehmet | 1:f60eafbf009a | 54 | |
gmehmet | 1:f60eafbf009a | 55 | #define DS_MAX_NUM_SENSORCOMMS 8 |
gmehmet | 1:f60eafbf009a | 56 | |
gmehmet | 1:f60eafbf009a | 57 | #define DS_BINARY_PACKET_START_BYTE 0xAA |
gmehmet | 1:f60eafbf009a | 58 | |
gmehmet | 1:f60eafbf009a | 59 | #define FLASH_MESSAGE_SIZE 32 |
gmehmet | 1:f60eafbf009a | 60 | #define CIRCULAR_QUEUE_COUNT 256 |
gmehmet | 1:f60eafbf009a | 61 | #define FLASH_MESSAGE_OFFSET 1 |
gmehmet | 1:f60eafbf009a | 62 | |
gmehmet | 1:f60eafbf009a | 63 | |
gmehmet | 1:f60eafbf009a | 64 | /** |
gmehmet | 1:f60eafbf009a | 65 | * @brief DSInterface is Maxim's DeviceStudio Interface class |
gmehmet | 1:f60eafbf009a | 66 | */ |
gmehmet | 1:f60eafbf009a | 67 | class DSInterface |
gmehmet | 1:f60eafbf009a | 68 | { |
gmehmet | 1:f60eafbf009a | 69 | public: |
gmehmet | 1:f60eafbf009a | 70 | |
gmehmet | 1:f60eafbf009a | 71 | /* PUBLIC FUNCTION DECLARATIONS */ |
gmehmet | 1:f60eafbf009a | 72 | /** |
gmehmet | 1:f60eafbf009a | 73 | * @brief DSInterface constructor. |
gmehmet | 1:f60eafbf009a | 74 | * |
gmehmet | 1:f60eafbf009a | 75 | * @param[in] fw_version Firmware version number. |
gmehmet | 1:f60eafbf009a | 76 | * @param[in] fw_platform Firmware platform name. |
gmehmet | 1:f60eafbf009a | 77 | * @param[in] USB Pointer to USBSerial device |
gmehmet | 1:f60eafbf009a | 78 | */ |
gmehmet | 1:f60eafbf009a | 79 | DSInterface(USBSerial* USB); |
gmehmet | 1:f60eafbf009a | 80 | |
gmehmet | 1:f60eafbf009a | 81 | /** |
gmehmet | 1:f60eafbf009a | 82 | * @brief DSInterface destructor. |
gmehmet | 1:f60eafbf009a | 83 | * |
gmehmet | 1:f60eafbf009a | 84 | */ |
gmehmet | 1:f60eafbf009a | 85 | virtual ~DSInterface(); |
gmehmet | 1:f60eafbf009a | 86 | |
gmehmet | 1:f60eafbf009a | 87 | /** |
gmehmet | 1:f60eafbf009a | 88 | * @brief Add SensorComm for DSInterface to pass commands to |
gmehmet | 1:f60eafbf009a | 89 | * |
gmehmet | 1:f60eafbf009a | 90 | * @param[in] s SensorComm instance to handle sensor commands. |
gmehmet | 1:f60eafbf009a | 91 | */ |
gmehmet | 1:f60eafbf009a | 92 | void add_sensor_comm(SensorComm *s); |
gmehmet | 1:f60eafbf009a | 93 | |
gmehmet | 1:f60eafbf009a | 94 | /** |
gmehmet | 1:f60eafbf009a | 95 | * @brief Command builder from i/o device. |
gmehmet | 1:f60eafbf009a | 96 | * @details Reads character and builds command from DeviceStudio commands. |
gmehmet | 1:f60eafbf009a | 97 | * |
gmehmet | 1:f60eafbf009a | 98 | * @param[in] ch Input character from i/o device. |
gmehmet | 1:f60eafbf009a | 99 | */ |
gmehmet | 1:f60eafbf009a | 100 | void build_command(char ch); |
gmehmet | 1:f60eafbf009a | 101 | |
gmehmet | 1:f60eafbf009a | 102 | /** |
gmehmet | 1:f60eafbf009a | 103 | * @brief Prints latest sensor data to USB stream |
gmehmet | 1:f60eafbf009a | 104 | * @details Should be called on every pass thorugh the main loop in main.cpp |
gmehmet | 1:f60eafbf009a | 105 | * |
gmehmet | 1:f60eafbf009a | 106 | */ |
gmehmet | 1:f60eafbf009a | 107 | void data_report_execute(); |
gmehmet | 1:f60eafbf009a | 108 | |
gmehmet | 1:f60eafbf009a | 109 | void handle_file_close(); |
gmehmet | 1:f60eafbf009a | 110 | |
gmehmet | 1:f60eafbf009a | 111 | void force_file_close(); |
gmehmet | 1:f60eafbf009a | 112 | |
gmehmet | 1:f60eafbf009a | 113 | void swap_queues(); |
gmehmet | 1:f60eafbf009a | 114 | |
gmehmet | 1:f60eafbf009a | 115 | /** |
gmehmet | 1:f60eafbf009a | 116 | * @brief Set the fw version which DSInterface will replay with for "get_device_info" command |
gmehmet | 1:f60eafbf009a | 117 | * |
gmehmet | 1:f60eafbf009a | 118 | * @param[in] fw_version Firmware version number. |
gmehmet | 1:f60eafbf009a | 119 | */ |
gmehmet | 1:f60eafbf009a | 120 | void set_fw_version(const char *fw_version); |
gmehmet | 1:f60eafbf009a | 121 | |
gmehmet | 1:f60eafbf009a | 122 | /** |
gmehmet | 1:f60eafbf009a | 123 | * @brief get the algorithms define within sesnor hub fw version |
gmehmet | 1:f60eafbf009a | 124 | * |
gmehmet | 1:f60eafbf009a | 125 | * @param[out] algorihm description string |
gmehmet | 1:f60eafbf009a | 126 | */ |
gmehmet | 1:f60eafbf009a | 127 | int get_fw_algorithms( void ); |
gmehmet | 1:f60eafbf009a | 128 | /** |
gmehmet | 1:f60eafbf009a | 129 | * @brief Set the fw platform which DSInterface will replay with for "get_device_info" command |
gmehmet | 1:f60eafbf009a | 130 | * |
gmehmet | 1:f60eafbf009a | 131 | * @param[in] fw_platform Firmware platform name. |
gmehmet | 1:f60eafbf009a | 132 | */ |
gmehmet | 1:f60eafbf009a | 133 | void set_fw_platform(const char *fw_platform); |
gmehmet | 1:f60eafbf009a | 134 | |
gmehmet | 1:f60eafbf009a | 135 | /** |
gmehmet | 1:f60eafbf009a | 136 | * @brief Enable data output on the console interface (USB) |
gmehmet | 1:f60eafbf009a | 137 | */ |
gmehmet | 1:f60eafbf009a | 138 | void enable_console_interface(); |
gmehmet | 1:f60eafbf009a | 139 | |
gmehmet | 1:f60eafbf009a | 140 | void ds_set_ble_status(bool en); |
gmehmet | 1:f60eafbf009a | 141 | |
gmehmet | 1:f60eafbf009a | 142 | void ds_set_flash_rec_status(bool en); |
gmehmet | 1:f60eafbf009a | 143 | |
gmehmet | 1:f60eafbf009a | 144 | void stopcommand(); |
gmehmet | 1:f60eafbf009a | 145 | void parse_command_str(const char* cmd ); |
wwwarunraj | 4:291477e8690d | 146 | uint8_t algo_report_mode; //= 1; // sets the mode for report 1/2 |
gmehmet | 1:f60eafbf009a | 147 | |
gmehmet | 1:f60eafbf009a | 148 | |
gmehmet | 1:f60eafbf009a | 149 | // FATFileSystem *logfilesystem; |
gmehmet | 1:f60eafbf009a | 150 | FILE *flashFileHandle; |
gmehmet | 1:f60eafbf009a | 151 | |
gmehmet | 1:f60eafbf009a | 152 | |
gmehmet | 1:f60eafbf009a | 153 | bool recordingStarted; |
gmehmet | 1:f60eafbf009a | 154 | |
gmehmet | 1:f60eafbf009a | 155 | |
gmehmet | 1:f60eafbf009a | 156 | protected: |
gmehmet | 1:f60eafbf009a | 157 | |
gmehmet | 1:f60eafbf009a | 158 | /* PROTECTED FUNCTION DECLARATIONS */ |
gmehmet | 1:f60eafbf009a | 159 | /** |
gmehmet | 1:f60eafbf009a | 160 | * @brief Parses DeviceStudio commands. |
gmehmet | 1:f60eafbf009a | 161 | * @details Parses and executes commands. Prints return code to i/o device. |
gmehmet | 1:f60eafbf009a | 162 | */ |
gmehmet | 1:f60eafbf009a | 163 | void parse_command(); |
gmehmet | 1:f60eafbf009a | 164 | |
gmehmet | 1:f60eafbf009a | 165 | void write_to_flash_thread_funct(); |
gmehmet | 1:f60eafbf009a | 166 | |
gmehmet | 1:f60eafbf009a | 167 | |
gmehmet | 1:f60eafbf009a | 168 | /* PROTECTED VARIABLES */ |
gmehmet | 1:f60eafbf009a | 169 | USBSerial *m_USB; |
gmehmet | 1:f60eafbf009a | 170 | Mutex comm_mutex; |
gmehmet | 1:f60eafbf009a | 171 | |
gmehmet | 1:f60eafbf009a | 172 | int num_sensors; |
gmehmet | 1:f60eafbf009a | 173 | SensorComm* sensor_list[DS_MAX_NUM_SENSORCOMMS]; |
gmehmet | 1:f60eafbf009a | 174 | |
gmehmet | 1:f60eafbf009a | 175 | volatile uint8_t ds_console_interface_exists_; |
gmehmet | 1:f60eafbf009a | 176 | volatile uint8_t ds_ble_interface_exists_; |
gmehmet | 1:f60eafbf009a | 177 | |
gmehmet | 1:f60eafbf009a | 178 | const char* platform_name; |
gmehmet | 1:f60eafbf009a | 179 | const char* firmware_version; |
gmehmet | 1:f60eafbf009a | 180 | |
gmehmet | 1:f60eafbf009a | 181 | char algo_desc_string[128]; |
gmehmet | 1:f60eafbf009a | 182 | int algo_desc_strsz; |
gmehmet | 1:f60eafbf009a | 183 | |
gmehmet | 1:f60eafbf009a | 184 | static const uint32_t CONSOLE_STR_BUF_SZ = 1024; |
gmehmet | 1:f60eafbf009a | 185 | |
gmehmet | 1:f60eafbf009a | 186 | char cmd_str[CONSOLE_STR_BUF_SZ]; |
gmehmet | 1:f60eafbf009a | 187 | int cmd_idx; |
gmehmet | 1:f60eafbf009a | 188 | bool silent_mode; |
gmehmet | 1:f60eafbf009a | 189 | bool pause_mode; |
gmehmet | 1:f60eafbf009a | 190 | char lcd_time_str[30]; |
wwwarunraj | 4:291477e8690d | 191 | int lcd_time_count;//=0; |
gmehmet | 1:f60eafbf009a | 192 | int lcd_time_val; |
gmehmet | 1:f60eafbf009a | 193 | |
gmehmet | 1:f60eafbf009a | 194 | //buffer to hold string that will be written into the log file |
gmehmet | 1:f60eafbf009a | 195 | char logbuf[1024]; |
gmehmet | 1:f60eafbf009a | 196 | |
gmehmet | 1:f60eafbf009a | 197 | //Flag to check which type of data streaming will occur |
gmehmet | 1:f60eafbf009a | 198 | char stream_type; |
gmehmet | 1:f60eafbf009a | 199 | |
gmehmet | 1:f60eafbf009a | 200 | // flash logging variables |
gmehmet | 1:f60eafbf009a | 201 | queue_t ds_queue_one_; |
gmehmet | 1:f60eafbf009a | 202 | queue_t ds_queue_two_; |
gmehmet | 1:f60eafbf009a | 203 | |
gmehmet | 1:f60eafbf009a | 204 | queue_t *ds_queue_flash_; |
gmehmet | 1:f60eafbf009a | 205 | queue_t *ds_queue_fill_; |
gmehmet | 1:f60eafbf009a | 206 | |
gmehmet | 1:f60eafbf009a | 207 | unsigned char buffer_one_[CIRCULAR_QUEUE_COUNT * FLASH_MESSAGE_SIZE]; |
gmehmet | 1:f60eafbf009a | 208 | unsigned char buffer_two_[CIRCULAR_QUEUE_COUNT * FLASH_MESSAGE_SIZE]; |
gmehmet | 1:f60eafbf009a | 209 | |
gmehmet | 1:f60eafbf009a | 210 | EventQueue event_queue_; |
gmehmet | 1:f60eafbf009a | 211 | Thread flash_thread_; |
gmehmet | 1:f60eafbf009a | 212 | }; |
gmehmet | 1:f60eafbf009a | 213 | |
gmehmet | 1:f60eafbf009a | 214 | #endif /* _DSINTERFACE_H_ */ |