@@ -43,17 +43,11 @@ DS18X20Controller::~DS18X20Controller() { delete _DS18X20_model; }
43
43
*/
44
44
/* **********************************************************************/
45
45
bool DS18X20Controller::Handle_Ds18x20Add (pb_istream_t *stream) {
46
- unsigned long total_start_time = millis ();
47
-
48
46
// Attempt to decode the incoming message into a Ds18x20Add message
49
- unsigned long decode_start_time = millis ();
50
47
if (!_DS18X20_model->DecodeDS18x20Add (stream)) {
51
48
WS_DEBUG_PRINTLN (" ERROR: Unable to decode Ds18x20Add message" );
52
49
return false ;
53
50
}
54
- unsigned long decode_end_time = millis ();
55
- WS_DEBUG_PRINT (" Decode time: " );
56
- WS_DEBUG_PRINTLN (decode_end_time - decode_start_time);
57
51
58
52
// If we receive no sensor types to configure, bail out
59
53
if (_DS18X20_model->GetDS18x20AddMsg ()->sensor_types_count == 0 ) {
@@ -65,13 +59,9 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
65
59
uint8_t pin_name = atoi (_DS18X20_model->GetDS18x20AddMsg ()->onewire_pin + 1 );
66
60
67
61
// Initialize the DS18X20Hardware object
68
- unsigned long init_start_time = millis ();
69
62
auto new_dsx_driver = std::make_unique<DS18X20Hardware>(pin_name);
70
63
// Attempt to get the sensor's ID on the OneWire bus to show it's been init'd
71
64
bool is_initialized = new_dsx_driver->GetSensor ();
72
- unsigned long init_end_time = millis ();
73
- WS_DEBUG_PRINT (" Initialization time: " );
74
- WS_DEBUG_PRINTLN (init_end_time - init_start_time);
75
65
76
66
if (is_initialized) {
77
67
WS_DEBUG_PRINTLN (" Sensor found on OneWire bus and initialized" );
@@ -84,7 +74,6 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
84
74
new_dsx_driver->SetPeriod (_DS18X20_model->GetDS18x20AddMsg ()->period );
85
75
86
76
// Configure the types of sensor reads to perform
87
- unsigned long config_types_start_time = millis ();
88
77
for (int i = 0 ; i < _DS18X20_model->GetDS18x20AddMsg ()->sensor_types_count ;
89
78
i++) {
90
79
if (_DS18X20_model->GetDS18x20AddMsg ()->sensor_types [i] ==
@@ -111,29 +100,16 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
111
100
WS_DEBUG_PRINTLN (" ERROR: Unable to encode Ds18x20Added message" );
112
101
return false ;
113
102
}
114
- unsigned long encode_end_time = millis ();
115
- WS_DEBUG_PRINT (" Encode message time: " );
116
- WS_DEBUG_PRINTLN (encode_end_time - encode_start_time);
117
103
118
- // Publish the AnalogIO message to the broker
119
- unsigned long publish_start_time = millis ();
120
104
if (!WsV2.PublishSignal (wippersnapper_signal_DeviceToBroker_ds18x20_added_tag,
121
105
_DS18X20_model->GetDS18x20AddedMsg ())) {
122
106
WS_DEBUG_PRINTLN (" ERROR: Unable to publish Ds18x20Added message" );
123
107
return false ;
124
108
}
125
- unsigned long publish_end_time = millis ();
126
- WS_DEBUG_PRINT (" Publish message time: " );
127
- WS_DEBUG_PRINTLN (publish_end_time - publish_start_time);
128
-
129
- unsigned long total_end_time = millis ();
130
- WS_DEBUG_PRINT (" Total function execution time: " );
131
- WS_DEBUG_PRINTLN (total_end_time - total_start_time);
132
109
133
110
return true ;
134
111
}
135
112
136
-
137
113
/* **********************************************************************/
138
114
/* !
139
115
@brief Handles a Ds18x20Remove message from the broker. Attempts to
@@ -174,15 +150,19 @@ bool DS18X20Controller::Handle_Ds18x20Remove(pb_istream_t *stream) {
174
150
*/
175
151
/* **********************************************************************/
176
152
void DS18X20Controller::update () {
153
+ #ifdef DEBUG_PROFILE
177
154
unsigned long total_start_time = millis ();
155
+ #endif
178
156
179
157
// Bail out if there are no OneWire pins to poll
180
158
if (_DS18X20_pins.empty ())
181
159
return ;
182
160
183
161
// Iterate through the vector
184
162
for (uint8_t i = 0 ; i < _DS18X20_pins.size (); i++) {
163
+ #ifdef DEBUG_PROFILE
185
164
unsigned long sensor_start_time = millis ();
165
+ #endif
186
166
187
167
// Create a reference to the DS18X20Hardware object
188
168
DS18X20Hardware &temp_dsx_driver = *(_DS18X20_pins[i]);
@@ -192,21 +172,24 @@ void DS18X20Controller::update() {
192
172
continue ;
193
173
}
194
174
195
- // Attempt to read the temperature in Celsius
196
- #ifdef DEBUG_PROFILE
197
- unsigned long temp_c_start_time = millis ();
198
- #endif
199
- if (!temp_dsx_driver.ReadTemperatureC ()) {
200
- WS_DEBUG_PRINTLN (" ERROR: Unable to read temperature in Celsius" );
201
- continue ;
202
- }
203
- #ifdef DEBUG_PROFILE
204
- unsigned long temp_c_end_time = millis ();
205
- WS_DEBUG_PRINT (" Read temperature Celsius time: " );
206
- WS_DEBUG_PRINTLN (temp_c_end_time - temp_c_start_time);
207
- #endif
175
+ // Attempt to read the temperature in Celsius
176
+ #ifdef DEBUG_PROFILE
177
+ unsigned long temp_c_start_time = millis ();
178
+ #endif
208
179
209
- // We got a temperature value from the hardware, let's create a new sensor_event
180
+ if (!temp_dsx_driver.ReadTemperatureC ()) {
181
+ WS_DEBUG_PRINTLN (" ERROR: Unable to read temperature in Celsius" );
182
+ continue ;
183
+ }
184
+
185
+ #ifdef DEBUG_PROFILE
186
+ unsigned long temp_c_end_time = millis ();
187
+ WS_DEBUG_PRINT (" Read temperature Celsius time: " );
188
+ WS_DEBUG_PRINTLN (temp_c_end_time - temp_c_start_time);
189
+ #endif
190
+
191
+ // We got a temperature value from the hardware, let's create a new
192
+ // sensor_event
210
193
_DS18X20_model->InitDS18x20EventMsg ();
211
194
212
195
// Are we reading the temperature in Celsius, Fahrenheit, or both?
@@ -224,10 +207,10 @@ void DS18X20Controller::update() {
224
207
}
225
208
226
209
// Get the Ds18x20Event message
227
- wippersnapper_ds18x20_Ds18x20Event* event_msg = _DS18X20_model->GetDS18x20EventMsg ();
210
+ wippersnapper_ds18x20_Ds18x20Event *event_msg =
211
+ _DS18X20_model->GetDS18x20EventMsg ();
228
212
pb_size_t event_count = event_msg->sensor_events_count ;
229
213
230
-
231
214
// Print the message's content out for debugging
232
215
WS_DEBUG_PRINT (" Sensor OneWire bus pin: " );
233
216
WS_DEBUG_PRINT (temp_dsx_driver.GetOneWirePin ());
@@ -255,19 +238,18 @@ void DS18X20Controller::update() {
255
238
}
256
239
WS_DEBUG_PRINTLN (" Published!" );
257
240
258
- #ifdef DEBUG_PROFILE
241
+ #ifdef DEBUG_PROFILE
259
242
unsigned long sensor_end_time = millis ();
260
243
WS_DEBUG_PRINT (" Total sensor processing time: " );
261
244
WS_DEBUG_PRINTLN (sensor_end_time - sensor_start_time);
262
- #endif
245
+ #endif
263
246
}
264
247
265
- #ifdef DEBUG_PROFILE
248
+ #ifdef DEBUG_PROFILE
266
249
unsigned long total_end_time = millis ();
267
250
if (total_end_time - total_start_time != 0 ) {
268
251
WS_DEBUG_PRINT (" Total update() execution time: " );
269
252
WS_DEBUG_PRINTLN (total_end_time - total_start_time);
270
253
}
271
- #endif
272
-
254
+ #endif
273
255
}
0 commit comments