@@ -43,11 +43,17 @@ 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
+
46
48
// Attempt to decode the incoming message into a Ds18x20Add message
49
+ unsigned long decode_start_time = millis ();
47
50
if (!_DS18X20_model->DecodeDS18x20Add (stream)) {
48
51
WS_DEBUG_PRINTLN (" ERROR: Unable to decode Ds18x20Add message" );
49
52
return false ;
50
53
}
54
+ unsigned long decode_end_time = millis ();
55
+ WS_DEBUG_PRINT (" Decode time: " );
56
+ WS_DEBUG_PRINTLN (decode_end_time - decode_start_time);
51
57
52
58
// If we receive no sensor types to configure, bail out
53
59
if (_DS18X20_model->GetDS18x20AddMsg ()->sensor_types_count == 0 ) {
@@ -59,17 +65,26 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
59
65
uint8_t pin_name = atoi (_DS18X20_model->GetDS18x20AddMsg ()->onewire_pin + 1 );
60
66
61
67
// Initialize the DS18X20Hardware object
68
+ unsigned long init_start_time = millis ();
62
69
auto new_dsx_driver = std::make_unique<DS18X20Hardware>(pin_name);
63
70
// Attempt to get the sensor's ID on the OneWire bus to show it's been init'd
64
71
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
if (is_initialized) {
66
77
WS_DEBUG_PRINTLN (" Sensor found on OneWire bus and initialized" );
78
+
67
79
// Set the sensor's resolution
68
80
new_dsx_driver->SetResolution (
69
81
_DS18X20_model->GetDS18x20AddMsg ()->sensor_resolution );
82
+
70
83
// Set the sensor's period
71
84
new_dsx_driver->SetPeriod (_DS18X20_model->GetDS18x20AddMsg ()->period );
85
+
72
86
// Configure the types of sensor reads to perform
87
+ unsigned long config_types_start_time = millis ();
73
88
for (int i = 0 ; i < _DS18X20_model->GetDS18x20AddMsg ()->sensor_types_count ;
74
89
i++) {
75
90
if (_DS18X20_model->GetDS18x20AddMsg ()->sensor_types [i] ==
@@ -81,31 +96,44 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
81
96
new_dsx_driver->is_read_temp_f = true ;
82
97
}
83
98
}
99
+
84
100
// Add the DS18X20Hardware object to the vector of hardware objects
85
- // _DS18X20_pins.push_back(new_dsx_driver);
86
101
_DS18X20_pins.push_back (std::move (new_dsx_driver));
87
102
} else {
88
103
WS_DEBUG_PRINTLN (
89
104
" ERROR: Unable to get ds18x sensor ID, ds18x sensor not initialized" );
90
105
}
91
106
92
107
// Encode and publish a Ds18x20Added message back to the broker
108
+ unsigned long encode_start_time = millis ();
93
109
if (!_DS18X20_model->EncodeDS18x20Added (
94
110
_DS18X20_model->GetDS18x20AddMsg ()->onewire_pin , is_initialized)) {
95
111
WS_DEBUG_PRINTLN (" ERROR: Unable to encode Ds18x20Added message" );
96
112
return false ;
97
113
}
114
+ unsigned long encode_end_time = millis ();
115
+ WS_DEBUG_PRINT (" Encode message time: " );
116
+ WS_DEBUG_PRINTLN (encode_end_time - encode_start_time);
98
117
99
118
// Publish the AnalogIO message to the broker
119
+ unsigned long publish_start_time = millis ();
100
120
if (!WsV2.PublishSignal (wippersnapper_signal_DeviceToBroker_ds18x20_added_tag,
101
121
_DS18X20_model->GetDS18x20AddedMsg ())) {
102
122
WS_DEBUG_PRINTLN (" ERROR: Unable to publish Ds18x20Added message" );
103
123
return false ;
104
124
}
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);
105
132
106
133
return true ;
107
134
}
108
135
136
+
109
137
/* **********************************************************************/
110
138
/* !
111
139
@brief Handles a Ds18x20Remove message from the broker. Attempts to
@@ -146,22 +174,31 @@ bool DS18X20Controller::Handle_Ds18x20Remove(pb_istream_t *stream) {
146
174
*/
147
175
/* **********************************************************************/
148
176
void DS18X20Controller::update () {
177
+ unsigned long total_start_time = millis ();
178
+
149
179
// Bail out if there are no OneWire pins to poll
150
180
if (_DS18X20_pins.empty ())
151
181
return ;
152
182
153
183
// Iterate through the vector
154
184
for (uint8_t i = 0 ; i < _DS18X20_pins.size (); i++) {
155
- // Create a temporary DS18X20Hardware driver
185
+ unsigned long sensor_start_time = millis ();
186
+
187
+ // Create a reference to the DS18X20Hardware object
156
188
DS18X20Hardware &temp_dsx_driver = *(_DS18X20_pins[i]);
189
+
157
190
// Check if the driver's timer has not expired yet
158
191
if (!temp_dsx_driver.IsTimerExpired ()) {
159
192
continue ;
160
193
}
194
+
161
195
// Create a new sensor_event
162
196
_DS18X20_model->InitDS18x20EventMsg ();
197
+
163
198
// Are we reading the temperature in Celsius, Fahrenheit, or both?
164
199
if (temp_dsx_driver.is_read_temp_c ) {
200
+ unsigned long temp_c_start_time = millis ();
201
+
165
202
WS_DEBUG_PRINTLN (" Reading temperature in Celsius" ); // TODO: Debug remove
166
203
// Attempt to read the temperature in Celsius
167
204
if (!temp_dsx_driver.ReadTemperatureC ()) {
@@ -172,10 +209,15 @@ void DS18X20Controller::update() {
172
209
_DS18X20_model->addSensorEvent (
173
210
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE,
174
211
temp_c);
212
+
213
+ unsigned long temp_c_end_time = millis ();
214
+ WS_DEBUG_PRINT (" Read temperature Celsius time: " );
215
+ WS_DEBUG_PRINTLN (temp_c_end_time - temp_c_start_time);
175
216
}
176
217
if (temp_dsx_driver.is_read_temp_f ) {
177
- WS_DEBUG_PRINTLN (
178
- " Reading temperature in Fahrenheit" ); // TODO: Debug remove
218
+ unsigned long temp_f_start_time = millis ();
219
+
220
+ WS_DEBUG_PRINTLN (" Reading temperature in Fahrenheit" ); // TODO: Debug remove
179
221
// Attempt to read the temperature in Fahrenheit
180
222
if (!temp_dsx_driver.ReadTemperatureF ()) {
181
223
WS_DEBUG_PRINTLN (" ERROR: Unable to read temperature in Fahrenheit" );
@@ -185,7 +227,12 @@ void DS18X20Controller::update() {
185
227
_DS18X20_model->addSensorEvent (
186
228
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT,
187
229
temp_f);
230
+
231
+ unsigned long temp_f_end_time = millis ();
232
+ WS_DEBUG_PRINT (" Read temperature Fahrenheit time: " );
233
+ WS_DEBUG_PRINTLN (temp_f_end_time - temp_f_start_time);
188
234
}
235
+
189
236
// Get and print out the SensorEvent message's contents
190
237
wippersnapper_ds18x20_Ds18x20Event event_msg =
191
238
*_DS18X20_model->GetDS18x20EventMsg ();
@@ -202,11 +249,17 @@ void DS18X20Controller::update() {
202
249
}
203
250
204
251
// Encode the Ds18x20Event message
252
+ unsigned long encode_start_time = millis ();
205
253
if (!_DS18X20_model->EncodeDs18x20Event ()) {
206
254
WS_DEBUG_PRINTLN (" ERROR: Failed to encode Ds18x20Event message" );
207
255
continue ;
208
256
}
257
+ unsigned long encode_end_time = millis ();
258
+ WS_DEBUG_PRINT (" Encode event message time: " );
259
+ WS_DEBUG_PRINTLN (encode_end_time - encode_start_time);
260
+
209
261
// Publish the Ds18x20Event message to the broker
262
+ unsigned long publish_start_time = millis ();
210
263
WS_DEBUG_PRINT (" Publishing Ds18x20Event message to broker..." );
211
264
if (!WsV2.PublishSignal (
212
265
wippersnapper_signal_DeviceToBroker_ds18x20_event_tag,
@@ -215,5 +268,16 @@ void DS18X20Controller::update() {
215
268
continue ;
216
269
}
217
270
WS_DEBUG_PRINTLN (" Published!" );
271
+ unsigned long publish_end_time = millis ();
272
+ WS_DEBUG_PRINT (" Publish event message time: " );
273
+ WS_DEBUG_PRINTLN (publish_end_time - publish_start_time);
274
+
275
+ unsigned long sensor_end_time = millis ();
276
+ WS_DEBUG_PRINT (" Total sensor processing time: " );
277
+ WS_DEBUG_PRINTLN (sensor_end_time - sensor_start_time);
218
278
}
219
- }
279
+
280
+ unsigned long total_end_time = millis ();
281
+ WS_DEBUG_PRINT (" Total update() execution time: " );
282
+ WS_DEBUG_PRINTLN (total_end_time - total_start_time);
283
+ }
0 commit comments