1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 | //
//
//
#include "driver_OxygenSensor.h"
/**
* \brief Initialize Oxygen sensor class.
*
* \param model Model of the oxygen sensor
* \param handle handle to the DriverContext
*/
void OxygenSensor::Init(t_OxygenSensorModel model, void* handle)
{
DriverContext* dc;
dc = (DriverContext*)handle;
hwi = (HW*)dc->hwi;<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected. See also: https://www.securecoding.cert.org/confluence/display/cplusplus/EXP05-CPP.+Do+not+use+C-style+casts.
dbg = (DebugIfaceClass*)dc->dbg;<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected. See also: https://www.securecoding.cert.org/confluence/display/cplusplus/EXP05-CPP.+Do+not+use+C-style+casts.
_oxmodel = model;
//Load the calibration coefficient in fucntion of the model of
//oxygen sensor
if (_oxmodel == OxygenSensorA)
{
calib_q = 0.00452689;
calib_m = -1.63;
calib_interval_seconds = 3600 * 24 * 7; //7 days
}
//Reset varaible
_adc_oxygen=0;
_temperature=0;
calib_second_counter=0;
second_counter=0;
second_counter = hwi->GetMillis();
}
/**
* \brief Return the oxygen concentration.
*
* \return Oxygen in %
*/
float OxygenSensor::GetConcentration()
{
float o2;
o2 = _adc_oxygen * calib_q + calib_m;
o2 = o2 > 100 ? 100 : o2;
return o2;
}
/**
* \brief Event triggered when the ADC converted the analog value.
*
* \param adc_oxygen analog value read by ADC
* \param temprature gas temperature
* \return
*/
bool OxygenSensor::setData(float adc_oxygen, float temprature)
{
_adc_oxygen = adc_oxygen;
_temperature = temprature;
}
/**
* \brief Calibrate the sesor at 21%.
*
*/
void OxygenSensor::CalibrateAir()
{
calib_m = -((_adc_oxygen*calib_q) - 21);
calib_second_counter = 0;
}
/**
* \brief Calibrate the sesor at 100%.
*
*/
void OxygenSensor::CalibratePureOxygen()
{
calib_m = -((_adc_oxygen*calib_q) - 100);
calib_second_counter = 0;
}
/**
* \brief Check if sensor must be recalibrated.
*
* This function check it time from last calibration is higher
* than the calibration period of selected sensor
*
* \return true if must be recalibrated
*/
bool OxygenSensor::CheckNeedRecalibrate()<--- The function 'CheckNeedRecalibrate' is never used.
{
if (calib_second_counter > calib_interval_seconds)
return true;
else
return false;
}
/**
* \brief Period action in the driver.
*
*/
void OxygenSensor::Tick()
{
if (hwi->Get_dT_millis(second_counter) > 1000)
{
calib_second_counter++;
}
}
// # # ###
// ## # #
// # # # #
// # # # #
// # # # #
// # ## #
// # # ###
//
// Nuclear Instruments 2020 - All rights reserved
// Any commercial use of this code is forbidden
// Contact info@nuclearinstruments.eu
|