Arun Raj / Mbed OS MAXREFDES101_SOURCE

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

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 #include "BLE_ICARUS.h"
00038 
00039 //define and initialize the static AsciiEn which is declared in the header
00040 bool SensorComm::AsciiEn=false;
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 unsigned char SensorComm::get_sensor_id() {
00064 
00065     if (sensor!= NULL)
00066         return( sensor->get_sensor_id());
00067     else
00068         return(255);
00069 }
00070 
00071 const char* SensorComm::get_part_name()
00072 {
00073     if (sensor != NULL)
00074     {
00075         return sensor->get_sensor_part_name();
00076     }
00077     else
00078     {
00079         return "unknown";
00080     }
00081 }
00082 
00083 const char* SensorComm::get_algo_ver()
00084 {
00085     if (sensor != NULL)
00086     {
00087         return sensor->get_sensor_algo_ver();
00088     }
00089     else
00090     {
00091         return "unknown";
00092     }
00093 }
00094 
00095 int SensorComm::get_part_info(uint8_t *part_id, uint8_t *rev_id)
00096 {
00097     if (sensor != NULL) {
00098         return sensor->get_part_info(part_id, rev_id);
00099     } else {
00100         *part_id = 0xFF;
00101         *rev_id = 0xFF;
00102         return -1;
00103     }
00104 }
00105 
00106 bool SensorComm::is_enabled()
00107 {
00108     return (data_report_mode != 0);
00109 }
00110 
00111 uint8_t SensorComm::get_data_report_mode()
00112 {
00113     return (data_report_mode);
00114 }
00115 
00116 
00117 int SensorComm::sensor_get_reg(char *ptr_ch, uint8_t *reg_addr, uint8_t *value)
00118 {
00119     int ret = EXIT_FAILURE;
00120     uint8_t num_found;
00121     int which_reg;
00122     *value = 0;
00123 
00124     while (*ptr_ch) {
00125         if (isxdigit((int)*ptr_ch)) {
00126             num_found = (uint8_t)sscanf(ptr_ch, "%x", &which_reg);
00127             if (num_found == 1) {
00128                 *reg_addr = which_reg;
00129                 ret = sensor->readRegister(*reg_addr, value, 1);
00130             }
00131             break;
00132         } else {
00133             ptr_ch++;
00134         }
00135     }
00136     return ret;
00137 }
00138 
00139 int SensorComm::sensor_set_reg(char *ptr_ch)
00140 {
00141     int ret = EXIT_FAILURE;
00142     uint8_t num_found;
00143     unsigned int reg_addr, value;
00144     char *ptr_char;
00145 
00146     ptr_char = ptr_ch;
00147     while (*ptr_char) {
00148         if (isxdigit((int)*ptr_char)) {
00149             num_found = (uint8_t)sscanf(ptr_char, "%x %x", &reg_addr, &value);
00150             if (num_found == 2) {
00151                 ret = sensor->writeRegister(reg_addr, (uint8_t)value);
00152             }
00153             break;
00154         } else {
00155             ptr_char++;
00156         }
00157     }
00158     return ret;
00159 }
00160 
00161 
00162 int SensorComm::InsertRegValuesIntoBleQeueu(addr_val_pair *reg_values, uint8_t reg_count){
00163     Reg_Val_BLE values = {0};
00164     int ret = 0;
00165 
00166     if (!BLE::Instance().gap().getState().connected)
00167         return 0;
00168 
00169     while(reg_count >= kMaxRegisterInOneStruct){
00170         for(uint8_t i = 0; i < kMaxRegisterInOneStruct; ++i){
00171             values.reg_adresses[i] = reg_values[i].addr;
00172             values.reg_values[i] = reg_values[i].val;
00173         }
00174         ret |= BLE_Icarus_AddtoQueue((uint8_t *)(&values), sizeof(Reg_Val_BLE), sizeof(Reg_Val_BLE));
00175         reg_count -= kMaxRegisterInOneStruct;
00176     }
00177 
00178     if(reg_count){
00179         for(uint8_t i = 0; i < reg_count; ++i){
00180             values.reg_adresses[i] = reg_values[i].addr;
00181             values.reg_values[i] = reg_values[i].val;
00182         }
00183         ret |= BLE_Icarus_AddtoQueue((uint8_t *)(&values), sizeof(Reg_Val_BLE), sizeof(Reg_Val_BLE));
00184     }
00185 
00186     return ret;
00187 }
00188 
00189 void SensorComm::stop() { }
00190 
00191 bool SensorComm::parse_command(const char* cmd) { return false; }
00192 
00193 int SensorComm::data_report_execute(char* buf, int size) { return 0; }
00194 
00195 void SensorComm::SensorComm_Set_Ble_Status (bool status) {
00196     m_sensorcomm_ble_interface_exists_ = status;
00197 }
00198 
00199 void SensorComm::SensorComm_Set_Flash_Status(bool status) {
00200     m_sensorcomm_flash_rec_started_ = status;
00201 }