HSP Platform firmware evaluating ECG data and hearth rate over PPG data.

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 #ifndef _ECGCOMM_H_
gmehmet 1:f60eafbf009a 35 #define _ECGCOMM_H_
gmehmet 1:f60eafbf009a 36
gmehmet 1:f60eafbf009a 37 #include "mbed.h"
gmehmet 1:f60eafbf009a 38 #include "SensorComm.h"
gmehmet 1:f60eafbf009a 39 #include "USBSerial.h"
gmehmet 1:f60eafbf009a 40
gmehmet 1:f60eafbf009a 41 /**
gmehmet 1:f60eafbf009a 42 * @brief EcgComm ECG sensor command handler class.
gmehmet 1:f60eafbf009a 43 * @details
gmehmet 1:f60eafbf009a 44 */
gmehmet 1:f60eafbf009a 45 class EcgComm: public SensorComm
gmehmet 1:f60eafbf009a 46 {
gmehmet 1:f60eafbf009a 47 public:
gmehmet 1:f60eafbf009a 48
gmehmet 1:f60eafbf009a 49 static const uint8_t kEcgInitParametersCount = 11;
gmehmet 1:f60eafbf009a 50
gmehmet 1:f60eafbf009a 51 static const uint8_t kRtoRInitParametersCount = 9;
gmehmet 1:f60eafbf009a 52
gmehmet 1:f60eafbf009a 53 static const uint8_t kInterruptParametersCount = 17;
gmehmet 1:f60eafbf009a 54
gmehmet 1:f60eafbf009a 55
gmehmet 1:f60eafbf009a 56 /* PUBLIC FUNCTION DECLARATIONS */
gmehmet 1:f60eafbf009a 57 /**
gmehmet 1:f60eafbf009a 58 * @brief EcgComm constructor.
gmehmet 1:f60eafbf009a 59 *
gmehmet 1:f60eafbf009a 60 */
gmehmet 1:f60eafbf009a 61 EcgComm(USBSerial* USB);
gmehmet 1:f60eafbf009a 62
gmehmet 1:f60eafbf009a 63 /* PROTECTED FUNCTION DECLARATIONS */
gmehmet 1:f60eafbf009a 64 /**
gmehmet 1:f60eafbf009a 65 * @brief Parses DeviceStudio commands.
gmehmet 1:f60eafbf009a 66 * @details Parses and executes commands. Prints return code to i/o device.
gmehmet 1:f60eafbf009a 67 * @returns true if sensor acted upon the command, false if command was unknown
gmehmet 1:f60eafbf009a 68 */
gmehmet 1:f60eafbf009a 69 bool parse_command(const char* cmd);
gmehmet 1:f60eafbf009a 70
gmehmet 1:f60eafbf009a 71 /**
gmehmet 1:f60eafbf009a 72 * @brief Fill in buffer with sensor data
gmehmet 1:f60eafbf009a 73 *
gmehmet 1:f60eafbf009a 74 * @param[in] buf Buffer to fill data into
gmehmet 1:f60eafbf009a 75 * @param[in] size Maximum size of buffer
gmehmet 1:f60eafbf009a 76 * @param[out] Number of bytes written to buffer
gmehmet 1:f60eafbf009a 77 */
gmehmet 1:f60eafbf009a 78 int data_report_execute(char* buf, int size);
gmehmet 1:f60eafbf009a 79
gmehmet 1:f60eafbf009a 80
gmehmet 1:f60eafbf009a 81 /**
gmehmet 1:f60eafbf009a 82 * @brief Stop collecting data and disable sensor
gmehmet 1:f60eafbf009a 83 */
gmehmet 1:f60eafbf009a 84 void stop();
gmehmet 1:f60eafbf009a 85
gmehmet 1:f60eafbf009a 86 // this function parses the parameters for max30001_ECG_InitStart function
gmehmet 1:f60eafbf009a 87 int ECG_Parse_Parameters(char *substring, uint8_t parameters[], uint8_t parameters_len);
gmehmet 1:f60eafbf009a 88
gmehmet 1:f60eafbf009a 89 // this function parses the parameters for max30001_ECG_InitStart function for single digits
gmehmet 1:f60eafbf009a 90 virtual int ECG_Parse_Parameters_Single(const char *substring, uint8_t parameters[], uint8_t parameters_len);
gmehmet 1:f60eafbf009a 91
gmehmet 1:f60eafbf009a 92
gmehmet 1:f60eafbf009a 93 private:
gmehmet 1:f60eafbf009a 94 /* PRIVATE TYPE DEFINITIONS */
gmehmet 1:f60eafbf009a 95 typedef enum _cmd_state_t {
gmehmet 1:f60eafbf009a 96 InterruptInit=0,
gmehmet 1:f60eafbf009a 97 get_format_1,
gmehmet 1:f60eafbf009a 98 get_format_2,
gmehmet 1:f60eafbf009a 99 ecg_mode,
gmehmet 1:f60eafbf009a 100 ecg_mode_2, //android app data stream mode
gmehmet 1:f60eafbf009a 101 get_reg,
gmehmet 1:f60eafbf009a 102 set_reg,
gmehmet 1:f60eafbf009a 103 dump_regs,
gmehmet 1:f60eafbf009a 104 set_cfg_ecg_invert,
gmehmet 1:f60eafbf009a 105 NUM_CMDS,
gmehmet 1:f60eafbf009a 106 } cmd_state_t;
gmehmet 1:f60eafbf009a 107
gmehmet 1:f60eafbf009a 108 typedef struct __attribute__((packed)) {
gmehmet 1:f60eafbf009a 109 uint32_t start_byte :8;
gmehmet 1:f60eafbf009a 110 uint32_t sample_count :8; //Represent 0-127
gmehmet 1:f60eafbf009a 111 uint32_t ecg :24; //ECG ADC data
gmehmet 1:f60eafbf009a 112 uint32_t rtor :14; //R to R data
gmehmet 1:f60eafbf009a 113 uint32_t rtor_bpm :8;
gmehmet 1:f60eafbf009a 114 uint8_t :0; //Needed to align crc to byte boundary
gmehmet 1:f60eafbf009a 115 uint8_t crc8 :8;
gmehmet 1:f60eafbf009a 116 } ecg1_comm_packet;
gmehmet 1:f60eafbf009a 117
gmehmet 1:f60eafbf009a 118 typedef struct __attribute__((packed)) {
gmehmet 1:f60eafbf009a 119 uint32_t start_byte :8;
gmehmet 1:f60eafbf009a 120 uint32_t sample_count :8;
gmehmet 1:f60eafbf009a 121 uint32_t rtor :14; //R to R data
gmehmet 1:f60eafbf009a 122 uint32_t rtor_bpm :8;
gmehmet 1:f60eafbf009a 123 uint32_t ecg :24; //ECG ADC data
gmehmet 1:f60eafbf009a 124 uint32_t ecg_2 :24; //ECG ADC data 2
gmehmet 1:f60eafbf009a 125 uint32_t ecg_3 :24; //ECG ADC data 2
gmehmet 1:f60eafbf009a 126 uint32_t ecg_4 :24; //ECG ADC data 2
gmehmet 1:f60eafbf009a 127 uint8_t :0; //Needed to align crc to byte boundary
gmehmet 1:f60eafbf009a 128 uint8_t crc8 :8;
gmehmet 1:f60eafbf009a 129 } ecg_comm_packet_ble;
gmehmet 1:f60eafbf009a 130 static const uint8_t m_ecg_ble_packet_count_ = 4; //how many ecg info in a ble struct
gmehmet 1:f60eafbf009a 131
gmehmet 1:f60eafbf009a 132
gmehmet 1:f60eafbf009a 133
gmehmet 1:f60eafbf009a 134 /* PRIVATE VARIABLES */
gmehmet 1:f60eafbf009a 135 USBSerial *m_USB;
gmehmet 1:f60eafbf009a 136 };
gmehmet 1:f60eafbf009a 137
gmehmet 1:f60eafbf009a 138 char getHexDigit(char ch_hex, uint8_t *bt_hex);
gmehmet 1:f60eafbf009a 139
gmehmet 1:f60eafbf009a 140 int ConvertHexString2Decimal(char *ch_hex, uint8_t *bt_hex, int len);
gmehmet 1:f60eafbf009a 141
gmehmet 1:f60eafbf009a 142 /*! Sensor output data to report */
gmehmet 1:f60eafbf009a 143 typedef struct {
gmehmet 1:f60eafbf009a 144 int32_t ecg;
gmehmet 1:f60eafbf009a 145 uint16_t rtor;
gmehmet 1:f60eafbf009a 146 uint8_t rtor_bpm;
gmehmet 1:f60eafbf009a 147 uint8_t reserved;
gmehmet 1:f60eafbf009a 148 float x;
gmehmet 1:f60eafbf009a 149 float y;
gmehmet 1:f60eafbf009a 150 float z;
gmehmet 1:f60eafbf009a 151 } ecg_sensor_report;
gmehmet 1:f60eafbf009a 152
gmehmet 1:f60eafbf009a 153 #endif /* _PPGCOMM_H_ */