Maxim Integrated / Mbed OS MAXREFDES101_SOURCE

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EcgComm.h Source File

EcgComm.h

00001 /*******************************************************************************
00002  * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 
00034 #ifndef _ECGCOMM_H_
00035 #define _ECGCOMM_H_
00036 
00037 #include "mbed.h"
00038 #include "SensorComm.h"
00039 #include "USBSerial.h"
00040 
00041 /**
00042  * @brief   EcgComm ECG sensor command handler class.
00043  * @details
00044  */
00045 class EcgComm:  public SensorComm
00046 {
00047 public:
00048 
00049     static const uint8_t kEcgInitParametersCount = 11;
00050 
00051     static const uint8_t kRtoRInitParametersCount = 9;
00052 
00053     static const uint8_t kInterruptParametersCount = 17;
00054 
00055 
00056     /* PUBLIC FUNCTION DECLARATIONS */
00057     /**
00058     * @brief    EcgComm constructor.
00059     *
00060     */
00061     EcgComm(USBSerial* USB);
00062 
00063     /* PROTECTED FUNCTION DECLARATIONS */
00064     /**
00065     * @brief    Parses DeviceStudio commands.
00066     * @details  Parses and executes commands. Prints return code to i/o device.
00067     * @returns true if sensor acted upon the command, false if command was unknown
00068     */
00069     bool parse_command(const char* cmd);
00070 
00071     /**
00072     * @brief     Fill in buffer with sensor data
00073     *
00074     * @param[in]     buf Buffer to fill data into
00075     * @param[in]     size Maximum size of buffer
00076     * @param[out]   Number of bytes written to buffer
00077     */
00078     int data_report_execute(char* buf, int size);
00079 
00080 
00081     /**
00082     * @brief    Stop collecting data and disable sensor
00083     */
00084     void stop();
00085 
00086     // this function parses the parameters for max30001_ECG_InitStart function
00087     int ECG_Parse_Parameters(char *substring, uint8_t parameters[], uint8_t parameters_len);
00088 
00089     // this function parses the parameters for max30001_ECG_InitStart function for single digits
00090     virtual int ECG_Parse_Parameters_Single(const char *substring, uint8_t parameters[], uint8_t parameters_len);
00091 
00092 
00093 private:
00094     /* PRIVATE TYPE DEFINITIONS */
00095     typedef enum _cmd_state_t {
00096         InterruptInit=0,
00097         get_format_1,
00098         get_format_2,
00099         ecg_mode,
00100         ecg_mode_2,     //android app data stream mode
00101         get_reg,
00102         set_reg,
00103         dump_regs,
00104         set_cfg_ecg_invert,
00105         NUM_CMDS,
00106     } cmd_state_t;
00107 
00108     typedef struct __attribute__((packed)) {
00109         uint32_t start_byte     :8;
00110         uint32_t sample_count   :8;     //Represent 0-127
00111         uint32_t ecg            :24;    //ECG ADC data
00112         uint32_t rtor           :14;    //R to R data
00113         uint32_t rtor_bpm       :8;
00114         uint8_t                 :0;     //Needed to align crc to byte boundary
00115         uint8_t crc8            :8;
00116     } ecg1_comm_packet;
00117 
00118     typedef struct __attribute__((packed)) {
00119         uint32_t start_byte     :8;
00120         uint32_t sample_count   :8;
00121         uint32_t rtor           :14;    //R to R data
00122         uint32_t rtor_bpm       :8;
00123         uint32_t ecg            :24;    //ECG ADC data
00124         uint32_t ecg_2          :24;    //ECG ADC data 2
00125         uint32_t ecg_3          :24;    //ECG ADC data 2
00126         uint32_t ecg_4          :24;    //ECG ADC data 2
00127         uint8_t                 :0;     //Needed to align crc to byte boundary
00128         uint8_t crc8            :8;
00129     } ecg_comm_packet_ble;
00130     static const uint8_t m_ecg_ble_packet_count_ = 4;   //how many ecg info in a ble struct
00131 
00132 
00133 
00134     /* PRIVATE VARIABLES */
00135     USBSerial *m_USB;
00136 };
00137 
00138 char getHexDigit(char ch_hex, uint8_t *bt_hex);
00139 
00140 int ConvertHexString2Decimal(char *ch_hex, uint8_t *bt_hex, int len);
00141 
00142         /*! Sensor output data to report */
00143 typedef struct {
00144     int32_t ecg;
00145     uint16_t rtor;
00146     uint8_t rtor_bpm;
00147     uint8_t reserved;
00148     float x;
00149     float y;
00150     float z;
00151 } ecg_sensor_report ;
00152 
00153 #endif /* _PPGCOMM_H_ */