Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sensor_driver.cpp
00001 /** 00002 * @defgroup sensor_control Sensor Control API 00003 * @{ 00004 */ 00005 00006 #include "sensor_driver.h" 00007 //#include "mbed-trace/mbed_trace.h" 00008 //#include "src/SensorProfile/sensor_profile.h" 00009 #include "src/DatastructConversion/conversions.h" 00010 //#include "src/TimeEngine/time_engine.h" 00011 //#include "src/TraceManager/trace_manager.h" 00012 //#include "src/TraceManager/trace_macro.h" 00013 00014 //#define TRACE_GROUP "SensorDriver" 00015 00016 /* General Functions for type conversions */ 00017 00018 std::string SensorDriver::ConvertSerialNumber(uint8_t sn_arr[]) 00019 { 00020 std::string sn_str = ""; 00021 for (int i = 0; i < sizeof(sn_arr); i++) 00022 { 00023 std::string str = IntToHex(sn_arr[i]); 00024 sn_str.append(str); 00025 } 00026 return sn_str; 00027 } 00028 00029 00030 std::string SensorDriver::ConvertDataToString(float data) 00031 { 00032 char buf[32]; 00033 std::string data_str = DoubleToChar(buf, data, 2); 00034 return data_str; 00035 } 00036 00037 00038 int SensorDriver::ValidateData(float data, float data_min, float data_max) 00039 { 00040 if (data > data_max | data < data_min) 00041 { 00042 return SENSOR_DATAOOR; 00043 } 00044 else return SENSOR_DATAOK; 00045 } 00046 00047 00048 void SensorDriver::SendSensorEmTrace(int err, std::string trace_string) 00049 { 00050 if (err == SENSOR_DCN) 00051 { 00052 // EmTrace(trace_level[WARN], trace_name[P1_DISCONN], RtcTimeNow()); // trace macro too specific to port 00053 pc.printf("Warning: Sensor Disconnect\r\n"); 00054 } 00055 00056 if (err == SENSOR_CN) 00057 { 00058 // EmTrace(trace_level[INFO], trace_name[P1_CONN], RtcTimeNow()); // trace macro too specific to port 00059 pc.printf("Info: Sensor Connect\r\n"); 00060 } 00061 00062 if (err == SENSOR_DATAERR) 00063 { 00064 // EmTrace(trace_level[WARN], trace_name[SEN_DATA_NOT_RDY], RtcTimeNow()); // trace macro not specific to port 00065 pc.printf("Warning: Sensor Data Error\r\n"); 00066 } 00067 00068 if (err == SENSOR_DATAOOR) 00069 { 00070 // EmTrace(trace_level[WARN], trace_string, RtcTimeNow()); 00071 pc.printf("Warning: Sensor Data Out of Range\r\n"); 00072 } 00073 00074 return; 00075 } 00076 00077 /** @}*/
Generated on Tue Jul 26 2022 07:43:19 by
1.7.2