@@ -231,7 +231,7 @@ bool ws_sdcard::ParseAnalogIOAdd(
231
231
bool ws_sdcard::ParseDS18X20Add (
232
232
wippersnapper_ds18x20_Ds18x20Add &msg_DS18X20Add, const char *pin,
233
233
int resolution, float period, int num_sensors, const char *sensor_type_1,
234
- char *sensor_type_2) {
234
+ const char *sensor_type_2) {
235
235
strcpy (msg_DS18X20Add.onewire_pin , pin);
236
236
msg_DS18X20Add.sensor_resolution = resolution;
237
237
msg_DS18X20Add.period = period;
@@ -249,6 +249,35 @@ bool ws_sdcard::ParseDS18X20Add(
249
249
return true ;
250
250
}
251
251
252
+ bool ws_sdcard::PushSignalToSharedBuffer (
253
+ wippersnapper_signal_BrokerToDevice &msg_signal) {
254
+ // Create a temporary buffer to hold the encoded signal message
255
+ std::vector<uint8_t > tempBuf (128 );
256
+ size_t tempBufSz;
257
+
258
+ // Get the encoded size of the signal message first so we can resize the
259
+ // buffer prior to encoding
260
+ WS_DEBUG_PRINTLN (" Encoding D2b signal message..." );
261
+ if (!pb_get_encoded_size (&tempBufSz,
262
+ wippersnapper_signal_BrokerToDevice_fields,
263
+ &msg_signal)) {
264
+ WS_DEBUG_PRINTLN (" [SD] ERROR: Unable to get signal message size!" );
265
+ return false ;
266
+ }
267
+
268
+ // Encode and push the signal message to the shared config buffer
269
+ tempBuf.resize (tempBufSz);
270
+ pb_ostream_t ostream = pb_ostream_from_buffer (tempBuf.data (), tempBuf.size ());
271
+ if (!ws_pb_encode (&ostream, wippersnapper_signal_BrokerToDevice_fields,
272
+ &msg_signal)) {
273
+ WS_DEBUG_PRINTLN (" [SD] ERROR: Unable to encode D2B signal message!" );
274
+ return false ;
275
+ }
276
+ WsV2._sharedConfigBuffers .push_back (std::move (tempBuf));
277
+ WS_DEBUG_PRINTLN (" Encoded the D2b signal message" );
278
+ return true ;
279
+ }
280
+
252
281
/* *************************************************************************/
253
282
/* !
254
283
@brief Searches for and parses the JSON configuration file and sets up
@@ -340,19 +369,20 @@ bool ws_sdcard::parseConfigFile() {
340
369
// Parse the component API type
341
370
const char *component_api_type = component[" componentAPI" ];
342
371
if (component_api_type == nullptr ) {
343
- WS_DEBUG_PRINTLN (" [SD] FATAL Parsing error - No component API type found "
344
- " in JSON string !" );
372
+ WS_DEBUG_PRINTLN (
373
+ " [SD] FATAL Parsing error - Missing component API type !" );
345
374
return false ;
346
375
}
347
376
348
377
// Determine the component type and parse it into a PB message
349
378
if (strcmp (component_api_type, " digitalio" ) == 0 ) {
350
379
WS_DEBUG_PRINTLN (
351
380
" [SD] DigitalIO component found, decoding JSON to PB..." );
352
-
353
- // Parse: JSON->DigitalIOAdd
354
381
wippersnapper_digitalio_DigitalIOAdd msg_DigitalIOAdd =
355
382
wippersnapper_digitalio_DigitalIOAdd_init_default;
383
+ msg_signal_b2d.which_payload =
384
+ wippersnapper_signal_BrokerToDevice_digitalio_add_tag;
385
+ msg_signal_b2d.payload .digitalio_add = msg_DigitalIOAdd;
356
386
if (!ParseDigitalIOAdd (msg_DigitalIOAdd, component[" pinName" ],
357
387
component[" period" ], component[" value" ],
358
388
component[" sampleMode" ], component[" direction" ],
@@ -361,33 +391,27 @@ bool ws_sdcard::parseConfigFile() {
361
391
" [SD] FATAL Parsing error - Unable to parse DigitalIO component!" );
362
392
return false ;
363
393
}
364
-
365
- // Configure the signal message for the digitalio payload
366
- msg_signal_b2d.which_payload =
367
- wippersnapper_signal_BrokerToDevice_digitalio_add_tag;
368
- msg_signal_b2d.payload .digitalio_add = msg_DigitalIOAdd;
369
394
} else if (strcmp (component_api_type, " analogio" ) == 0 ) {
370
395
WS_DEBUG_PRINTLN (" [SD] AnalogIO component found, decoding JSON to PB..." );
371
396
wippersnapper_analogio_AnalogIOAdd msg_AnalogIOAdd =
372
397
wippersnapper_analogio_AnalogIOAdd_init_default;
373
-
398
+ msg_signal_b2d.which_payload =
399
+ wippersnapper_signal_BrokerToDevice_analogio_add_tag;
400
+ msg_signal_b2d.payload .analogio_add = msg_AnalogIOAdd;
374
401
// Parse: JSON->AnalogIOAdd
375
402
if (!ParseAnalogIOAdd (msg_AnalogIOAdd, component[" pinName" ],
376
403
component[" period" ], component[" analogReadMode" ])) {
377
404
WS_DEBUG_PRINTLN (
378
405
" [SD] FATAL Parsing error - Unable to parse AnalogIO component!" );
379
406
return false ;
380
407
}
381
-
382
- msg_signal_b2d.which_payload =
383
- wippersnapper_signal_BrokerToDevice_analogio_add_tag;
384
- msg_signal_b2d.payload .analogio_add = msg_AnalogIOAdd;
385
408
} else if (strcmp (component_api_type, " ds18x20" ) == 0 ) {
386
- WS_DEBUG_PRINTLN (" [SD] ds18x20 component found, decoding JSON to PB..." );
387
- // Create new DS18X20Add message
409
+ WS_DEBUG_PRINTLN (" [SD] Ds18x20 component found, decoding JSON to PB..." );
388
410
wippersnapper_ds18x20_Ds18x20Add msg_DS18X20Add =
389
411
wippersnapper_ds18x20_Ds18x20Add_init_default;
390
-
412
+ msg_signal_b2d.which_payload =
413
+ wippersnapper_signal_BrokerToDevice_ds18x20_add_tag;
414
+ msg_signal_b2d.payload .ds18x20_add = msg_DS18X20Add;
391
415
// Parse: JSON->DS18X20Add
392
416
if (!ParseDS18X20Add (msg_DS18X20Add, component[" pinName" ],
393
417
component[" sensorResolution" ], component[" period" ],
@@ -398,47 +422,23 @@ bool ws_sdcard::parseConfigFile() {
398
422
" [SD] FATAL Parsing error - Unable to parse DS18X20 component!" );
399
423
return false ;
400
424
}
401
-
402
- // Configure the signal message for the ds18x20 payload
403
- msg_signal_b2d.which_payload =
404
- wippersnapper_signal_BrokerToDevice_ds18x20_add_tag;
405
- msg_signal_b2d.payload .ds18x20_add = msg_DS18X20Add;
406
425
} else {
407
426
// Unknown component API type
408
427
WS_DEBUG_PRINTLN (" [SD] Unknown component API type found: " +
409
428
String (component_api_type));
410
429
return false ;
411
430
}
412
431
413
- // Create a temporary buffer to hold the encoded signal message
414
- std::vector<uint8_t > tempBuf (128 );
415
- size_t tempBufSz;
416
-
417
- // Get the encoded size of the signal message first so we can resize the
418
- // buffer prior to encoding
419
- WS_DEBUG_PRINTLN (" Encoding D2b signal message..." );
420
- if (!pb_get_encoded_size (&tempBufSz,
421
- wippersnapper_signal_BrokerToDevice_fields,
422
- &msg_signal_b2d)) {
423
- WS_DEBUG_PRINTLN (" [SD] ERROR: Unable to get signal message size!" );
432
+ if (!PushSignalToSharedBuffer (msg_signal_b2d)) {
433
+ WS_DEBUG_PRINTLN (" [SD] FATAL Error - Unable to push signal message to "
434
+ " shared buffer!" );
424
435
return false ;
425
436
}
426
- WS_DEBUG_PRINTLN (" Signal message size: " + String (tempBufSz));
427
- // Encode and push the signal message to the shared config buffer
428
- tempBuf.resize (tempBufSz);
429
- pb_ostream_t ostream =
430
- pb_ostream_from_buffer (tempBuf.data (), tempBuf.size ());
431
- if (!ws_pb_encode (&ostream, wippersnapper_signal_BrokerToDevice_fields,
432
- &msg_signal_b2d)) {
433
- WS_DEBUG_PRINTLN (" [SD] ERROR: Unable to encode D2B signal message!" );
434
- return false ;
435
- }
436
- WsV2._sharedConfigBuffers .push_back (std::move (tempBuf));
437
- WS_DEBUG_PRINTLN (" Encoded the D2b signal message" );
438
437
}
439
438
return true ;
440
439
}
441
440
441
+ #ifdef OFFLINE_MODE_DEBUG
442
442
/* *************************************************************************/
443
443
/* !
444
444
@brief Validates a JSON string.
@@ -593,6 +593,7 @@ bool ws_sdcard::waitForSerialConfig() {
593
593
WS_DEBUG_PRINTLN (" [SD] Valid JSON string received!" );
594
594
return true ;
595
595
}
596
+ #endif
596
597
597
598
/* *************************************************************************/
598
599
/* !
0 commit comments