Maxim Integrated / Mbed OS MAXREFDES220_HR_SPO2_MONITOR

Dependencies:   max32630fthr USBDevice

Fork of MAXREFDES220_HEART_RATE_MONITOR by Maxim Integrated

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SensorComm.cpp Source File

SensorComm.cpp

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 #include <ctype.h>
00035 #include "SensorComm.h"
00036 #include "Peripherals.h"
00037 
00038 #ifdef ENABLE_BLE
00039 #include "BLE_ICARUS.h"
00040 #endif
00041 
00042 SensorComm::SensorComm(const char *type, bool visible)
00043 {
00044     sensor = NULL;
00045     sensor_type = type;
00046     vis = visible;
00047 }
00048 
00049 SensorComm::~SensorComm()
00050 {
00051 }
00052 
00053 void SensorComm::comm_init(MaximSensor *s)
00054 {
00055     sensor = s;
00056 }
00057 
00058 const char* SensorComm::get_type()
00059 {
00060     return sensor_type;
00061 }
00062 
00063 const char* SensorComm::get_part_name()
00064 {
00065     if (sensor != NULL)
00066     {
00067         return sensor->get_sensor_part_name();
00068     }
00069     else
00070     {
00071         return "unknown";
00072     }
00073 }
00074 
00075 const char* SensorComm::get_algo_ver()
00076 {
00077     if (sensor != NULL)
00078     {
00079         return sensor->get_sensor_algo_ver();
00080     }
00081     else
00082     {
00083         return "unknown";
00084     }
00085 }
00086 
00087 int SensorComm::get_part_info(uint8_t *part_id, uint8_t *rev_id)
00088 {
00089     if (sensor != NULL) {
00090         return sensor->get_part_info(part_id, rev_id);
00091     } else {
00092         *part_id = 0xFF;
00093         *rev_id = 0xFF;
00094         return -1;
00095     }
00096 }
00097 
00098 bool SensorComm::is_enabled()
00099 {
00100     return (data_report_mode != 0);
00101 }
00102 
00103 int SensorComm::sensor_get_reg(char *ptr_ch, uint8_t *reg_addr, uint8_t *value)
00104 {
00105     int ret = EXIT_FAILURE;
00106     uint8_t num_found;
00107     int which_reg;
00108     *value = 0;
00109 
00110     while (*ptr_ch) {
00111         if (isxdigit((int)*ptr_ch)) {
00112             num_found = (uint8_t)sscanf(ptr_ch, "%x", &which_reg);
00113             if (num_found == 1) {
00114                 *reg_addr = which_reg;
00115                 ret = sensor->readRegister(*reg_addr, value, 1);
00116             }
00117             break;
00118         } else {
00119             ptr_ch++;
00120         }
00121     }
00122     return ret;
00123 }
00124 
00125 int SensorComm::sensor_set_reg(char *ptr_ch)
00126 {
00127     int ret = EXIT_FAILURE;
00128     uint8_t num_found;
00129     unsigned int reg_addr, value;
00130     char *ptr_char;
00131 
00132     ptr_char = ptr_ch;
00133     while (*ptr_char) {
00134         if (isxdigit((int)*ptr_char)) {
00135             num_found = (uint8_t)sscanf(ptr_char, "%x %x", &reg_addr, &value);
00136             if (num_found == 2) {
00137                 ret = sensor->writeRegister(reg_addr, (uint8_t)value);
00138             }
00139             break;
00140         } else {
00141             ptr_char++;
00142         }
00143     }
00144     return ret;
00145 }
00146 
00147 
00148 int SensorComm::InsertRegValuesIntoBleQeueu(addr_val_pair *reg_values, uint8_t reg_count){
00149     Reg_Val_BLE values = {0};
00150     int ret = 0;
00151 #ifdef ENABLE_BLE
00152     if (!BLE_Icarus_Interface_Exists())
00153         return 0;
00154 
00155     while(reg_count >= kMaxRegisterInOneStruct){
00156         for(uint8_t i = 0; i < kMaxRegisterInOneStruct; ++i){
00157             values.reg_adresses[i] = reg_values[i].addr;
00158             values.reg_values[i] = reg_values[i].val;
00159         }
00160         ret |= BLE_Icarus_AddtoQueue((uint8_t *)(&values), sizeof(Reg_Val_BLE), sizeof(Reg_Val_BLE));
00161         reg_count -= kMaxRegisterInOneStruct;
00162     }
00163 
00164     if(reg_count){
00165         for(uint8_t i = 0; i < reg_count; ++i){
00166             values.reg_adresses[i] = reg_values[i].addr;
00167             values.reg_values[i] = reg_values[i].val;
00168         }
00169         ret |= BLE_Icarus_AddtoQueue((uint8_t *)(&values), sizeof(Reg_Val_BLE), sizeof(Reg_Val_BLE));
00170     }
00171 #endif
00172     return ret;
00173 }
00174 
00175 void SensorComm::stop() { }
00176 
00177 bool SensorComm::parse_command(const char* cmd) { return false; }
00178 
00179 int SensorComm::data_report_execute(char* buf, int size) { return 0; }
00180