Maxim Integrated / Mbed OS MAXREFDES220_HEART_RATE_MONITOR

Dependencies:   USBDevice max32630fthr

Fork of MAXREFDES220# by Maxim Integrated

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DSInterface.h Source File

DSInterface.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 _DSINTERFACE_H_
00035 #define _DSINTERFACE_H_
00036 
00037 #include "mbed.h"
00038 #include <stdint.h>
00039 #include "SensorComm.h"
00040 #include "MaximSensor.h"
00041 #include "USBSerial.h"
00042 
00043 #define COMM_SUCCESS        0
00044 #define COMM_GENERAL_ERROR  -1
00045 #define COMM_INVALID_PARAM  -254
00046 #define COMM_NOT_RECOGNIZED -255
00047 
00048 #define FLASH_ERR_GENERAL   -1
00049 #define FLASH_ERR_CHECKSUM  -2
00050 #define FLASH_ERR_AUTH      -3
00051 
00052 #define DS_MAX_NUM_SENSORCOMMS  8
00053 
00054 #define DS_BINARY_PACKET_START_BYTE 0xAA
00055 
00056 /**
00057  * @brief   DSInterface is Maxim's DeviceStudio Interface class
00058  */
00059 class DSInterface
00060 {
00061 public:
00062 
00063     /* PUBLIC FUNCTION DECLARATIONS */
00064     /**
00065     * @brief    DSInterface constructor.
00066     *
00067     * @param[in]    fw_version Firmware version number.
00068     * @param[in]    fw_platform Firmware platform name.
00069     * @param[in]    USB Pointer to USBSerial device
00070     */
00071     DSInterface(USBSerial* USB);
00072 
00073     /**
00074     * @brief    DSInterface destructor.
00075     *
00076     */
00077     virtual ~DSInterface();
00078 
00079     /**
00080     * @brief    Add SensorComm for DSInterface to pass commands to
00081     *
00082     * @param[in]    s SensorComm instance to handle sensor commands.
00083     */
00084     void add_sensor_comm(SensorComm *s);
00085 
00086     /**
00087     * @brief    Command builder from i/o device.
00088     * @details  Reads character and builds command from DeviceStudio commands.
00089     *
00090     * @param[in]    ch Input character from i/o device.
00091     */
00092     void build_command(char ch);
00093 
00094     /**
00095     * @brief    Prints latest sensor data to USB stream
00096     * @details  Should be called on every pass thorugh the main loop in main.cpp
00097     *
00098     */
00099     void data_report_execute();
00100 
00101     /**
00102     * @brief    Set the fw version which DSInterface will replay with for "get_device_info" command
00103     *
00104     * @param[in]    fw_version Firmware version number.
00105     */
00106     void set_fw_version(const char *fw_version);
00107 
00108     /**
00109     * @brief    Set the fw platform which DSInterface will replay with for "get_device_info" command
00110     *
00111     * @param[in]    fw_platform Firmware platform name.
00112     */
00113     void set_fw_platform(const char *fw_platform);
00114 
00115     /**
00116      * @brief   Enable data output on the console interface (USB)
00117      */
00118     void enable_console_interface();
00119 
00120 
00121 
00122 protected:
00123 
00124     /* PROTECTED FUNCTION DECLARATIONS */
00125     /**
00126     * @brief    Parses DeviceStudio commands.
00127     * @details  Parses and executes commands. Prints return code to i/o device.
00128     */
00129     void parse_command();
00130 
00131 
00132     /* PROTECTED VARIABLES */
00133     USBSerial *m_USB;
00134     Mutex comm_mutex;
00135 
00136     int num_sensors;
00137     SensorComm* sensor_list[DS_MAX_NUM_SENSORCOMMS];
00138 
00139     volatile uint8_t data_report_mode;
00140     volatile uint8_t console_interface_exists;
00141 
00142     const char* platform_name;
00143     const char* firmware_version;
00144 
00145     static const uint32_t SENSOR_STR_BUF_SZ = 80;
00146     static const uint32_t CONSOLE_STR_BUF_SZ = 256;
00147 
00148     char console_tx_buf[CONSOLE_STR_BUF_SZ];
00149     int cmd_idx;
00150     char cmd_str[SENSOR_STR_BUF_SZ];
00151     bool silent_mode;
00152     bool pause_mode;
00153 };
00154 
00155 #endif /* _DSINTERFACE_H_ */