Skip to content

Commit 11062ed

Browse files
committed
SD - Parse UART generic, uart pm25aqi types
1 parent ff5c0f3 commit 11062ed

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

src/protos/uart.pb.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ typedef struct _wippersnapper_uart_GenericUartInputConfig {
8787
pb_callback_t name; /* * The name used to identify the device. */
8888
wippersnapper_uart_GenericDeviceLineEnding line_ending; /* * The line ending used by the device. */
8989
int32_t period; /* * The period to poll the device, in milliseconds */
90-
pb_callback_t sensor_types; /* * SI Types for each sensor on the UART device. */
90+
pb_size_t sensor_types_count;
91+
wippersnapper_sensor_SensorType sensor_types[15]; /* * SI Types for each sensor on the UART device. */
9192
} wippersnapper_uart_GenericUartInputConfig;
9293

9394
/* *
@@ -103,8 +104,8 @@ typedef struct _wippersnapper_uart_TrinamicDynamixelConfig {
103104
typedef struct _wippersnapper_uart_PM25AQIConfig {
104105
bool is_pm1006; /* * True if the device is a PM1006 AQ sensor, Defaults to False. */
105106
int32_t period; /* * The period to poll the device, in milliseconds */
106-
pb_size_t i2c_device_sensor_types_count;
107-
wippersnapper_sensor_SensorType i2c_device_sensor_types[15]; /* * SI Types for each sensor on the I2c device. */
107+
pb_size_t sensor_types_count;
108+
wippersnapper_sensor_SensorType sensor_types[15]; /* * SI Types for each sensor on the I2c device. */
108109
} wippersnapper_uart_PM25AQIConfig;
109110

110111
/* *
@@ -220,7 +221,7 @@ extern "C" {
220221
#define wippersnapper_uart_GenericUartInputConfig_sensor_types_ENUMTYPE wippersnapper_sensor_SensorType
221222

222223

223-
#define wippersnapper_uart_PM25AQIConfig_i2c_device_sensor_types_ENUMTYPE wippersnapper_sensor_SensorType
224+
#define wippersnapper_uart_PM25AQIConfig_sensor_types_ENUMTYPE wippersnapper_sensor_SensorType
224225

225226
#define wippersnapper_uart_UartDeviceConfig_device_type_ENUMTYPE wippersnapper_uart_UartDeviceType
226227

@@ -238,7 +239,7 @@ extern "C" {
238239

239240
/* Initializer values for message structs */
240241
#define wippersnapper_uart_UartSerialConfig_init_default {"", "", 0, 0, _wippersnapper_uart_UartPacketFormat_MIN, 0, 0, 0}
241-
#define wippersnapper_uart_GenericUartInputConfig_init_default {{{NULL}, NULL}, _wippersnapper_uart_GenericDeviceLineEnding_MIN, 0, {{NULL}, NULL}}
242+
#define wippersnapper_uart_GenericUartInputConfig_init_default {{{NULL}, NULL}, _wippersnapper_uart_GenericDeviceLineEnding_MIN, 0, 0, {_wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN}}
242243
#define wippersnapper_uart_TrinamicDynamixelConfig_init_default {0}
243244
#define wippersnapper_uart_PM25AQIConfig_init_default {0, 0, 0, {_wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN}}
244245
#define wippersnapper_uart_UartDeviceConfig_init_default {_wippersnapper_uart_UartDeviceType_MIN, "", 0, {wippersnapper_uart_GenericUartInputConfig_init_default}}
@@ -249,7 +250,7 @@ extern "C" {
249250
#define wippersnapper_uart_UartWritten_init_default {0, _wippersnapper_uart_UartDeviceType_MIN, "", 0}
250251
#define wippersnapper_uart_UartInputEvent_init_default {0, _wippersnapper_uart_UartDeviceType_MIN, "", 0, {wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default, wippersnapper_sensor_SensorEvent_init_default}}
251252
#define wippersnapper_uart_UartSerialConfig_init_zero {"", "", 0, 0, _wippersnapper_uart_UartPacketFormat_MIN, 0, 0, 0}
252-
#define wippersnapper_uart_GenericUartInputConfig_init_zero {{{NULL}, NULL}, _wippersnapper_uart_GenericDeviceLineEnding_MIN, 0, {{NULL}, NULL}}
253+
#define wippersnapper_uart_GenericUartInputConfig_init_zero {{{NULL}, NULL}, _wippersnapper_uart_GenericDeviceLineEnding_MIN, 0, 0, {_wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN}}
253254
#define wippersnapper_uart_TrinamicDynamixelConfig_init_zero {0}
254255
#define wippersnapper_uart_PM25AQIConfig_init_zero {0, 0, 0, {_wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN, _wippersnapper_sensor_SensorType_MIN}}
255256
#define wippersnapper_uart_UartDeviceConfig_init_zero {_wippersnapper_uart_UartDeviceType_MIN, "", 0, {wippersnapper_uart_GenericUartInputConfig_init_zero}}
@@ -276,7 +277,7 @@ extern "C" {
276277
#define wippersnapper_uart_TrinamicDynamixelConfig_device_id_tag 1
277278
#define wippersnapper_uart_PM25AQIConfig_is_pm1006_tag 1
278279
#define wippersnapper_uart_PM25AQIConfig_period_tag 2
279-
#define wippersnapper_uart_PM25AQIConfig_i2c_device_sensor_types_tag 3
280+
#define wippersnapper_uart_PM25AQIConfig_sensor_types_tag 3
280281
#define wippersnapper_uart_UartDeviceConfig_device_type_tag 1
281282
#define wippersnapper_uart_UartDeviceConfig_device_id_tag 2
282283
#define wippersnapper_uart_UartDeviceConfig_generic_uart_input_tag 3
@@ -323,7 +324,7 @@ X(a, STATIC, SINGULAR, BOOL, sw_serial_invert, 8)
323324
X(a, CALLBACK, SINGULAR, STRING, name, 1) \
324325
X(a, STATIC, SINGULAR, UENUM, line_ending, 2) \
325326
X(a, STATIC, SINGULAR, INT32, period, 3) \
326-
X(a, CALLBACK, REPEATED, UENUM, sensor_types, 4)
327+
X(a, STATIC, REPEATED, UENUM, sensor_types, 4)
327328
#define wippersnapper_uart_GenericUartInputConfig_CALLBACK pb_default_field_callback
328329
#define wippersnapper_uart_GenericUartInputConfig_DEFAULT NULL
329330

@@ -335,7 +336,7 @@ X(a, STATIC, SINGULAR, UINT32, device_id, 1)
335336
#define wippersnapper_uart_PM25AQIConfig_FIELDLIST(X, a) \
336337
X(a, STATIC, SINGULAR, BOOL, is_pm1006, 1) \
337338
X(a, STATIC, SINGULAR, INT32, period, 2) \
338-
X(a, STATIC, REPEATED, UENUM, i2c_device_sensor_types, 3)
339+
X(a, STATIC, REPEATED, UENUM, sensor_types, 3)
339340
#define wippersnapper_uart_PM25AQIConfig_CALLBACK NULL
340341
#define wippersnapper_uart_PM25AQIConfig_DEFAULT NULL
341342

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,29 @@ ws_sdcard::ParseSensorType(const char *sensor_type) {
346346
}
347347
}
348348

349+
/*!
350+
@brief Parses a UART device's generic device line ending option
351+
from the JSON configuration file.
352+
@param line_ending
353+
The line ending string to parse.
354+
@returns The corresponding GenericDeviceLineEnding enum value
355+
*/
356+
wippersnapper_uart_GenericDeviceLineEnding
357+
ws_sdcard::ParseUartLineEnding(const char *line_ending) {
358+
if (strcmp(line_ending, "LF") == 0) {
359+
return wippersnapper_uart_GenericDeviceLineEnding_GENERIC_DEVICE_LINE_ENDING_LF;
360+
} else if (strcmp(line_ending, "CRLF") == 0) {
361+
return wippersnapper_uart_GenericDeviceLineEnding_GENERIC_DEVICE_LINE_ENDING_CRLF;
362+
} else if (strcmp(line_ending, "TIMEOUT_100MS") == 0) {
363+
return wippersnapper_uart_GenericDeviceLineEnding_GENERIC_DEVICE_LINE_ENDING_TIMEOUT_100MS;
364+
} else if (strcmp(line_ending, "TIMEOUT_1000MS") == 0) {
365+
return wippersnapper_uart_GenericDeviceLineEnding_GENERIC_DEVICE_LINE_ENDING_TIMEOUT_1000MS;
366+
}
367+
WS_DEBUG_PRINT("[SD] ERROR: Found unspecified LineEnding - ");
368+
WS_DEBUG_PRINTLN(line_ending);
369+
return wippersnapper_uart_GenericDeviceLineEnding_GENERIC_DEVICE_LINE_ENDING_UNSPECIFIED;
370+
}
371+
349372
bool ws_sdcard::ParseDigitalIOAdd(
350373
JsonObject &component,
351374
wippersnapper_digitalio_DigitalIOAdd &msg_DigitalIOAdd) {
@@ -473,13 +496,29 @@ bool ws_sdcard::ParseUartAdd(JsonObject &component, wippersnapper_uart_UartAdd &
473496
// Fill the config field
474497
} else if (strcmp(device_type, "PM25AQI") == 0) {
475498
msg_uart_add.cfg_device.device_type = wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_PM25AQI;
499+
msg_uart_add.cfg_device.which_config = wippersnapper_uart_UartDeviceConfig_pm25aqi_tag;
500+
msg_uart_add.cfg_device.config.pm25aqi.period = component["period"] | 0.0;
501+
msg_uart_add.cfg_device.config.pm25aqi.is_pm1006 = component["isPm1006"] | false;
502+
// Fill sensor types
503+
pb_size_t sensor_type_count = 0;
504+
for (JsonObject sensor_type : component["SensorTypes"].as<JsonArray>()) {
505+
msg_uart_add.cfg_device.config.pm25aqi.sensor_types[sensor_type_count] = ParseSensorType(sensor_type["type"]);
506+
sensor_type_count++;
507+
}
508+
msg_uart_add.cfg_device.config.pm25aqi.sensor_types_count = sensor_type_count;
476509
} else if (strcmp(device_type, "GENERIC-INPUT") == 0) {
510+
// TODO: Fill device name (requires an update to uart.pb.h so it's not a pb_callback field)
477511
msg_uart_add.cfg_device.device_type = wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_GENERIC_INPUT;
512+
msg_uart_add.cfg_device.which_config = wippersnapper_uart_UartDeviceConfig_generic_uart_input_tag;
513+
msg_uart_add.cfg_device.config.generic_uart_input.line_ending = ParseUartLineEnding(component["lineEnding"] | "LF");
478514
msg_uart_add.cfg_device.config.generic_uart_input.period = component["period"] | 0.0;
479515
// Fill sensor types
480-
// TODO: Needs new PB!
481-
// msg_uart_add.cfg_device.config.generic_uart_input.i2c_ = 0;
482-
516+
pb_size_t sensor_type_count = 0;
517+
for (JsonObject sensor_type : component["SensorTypes"].as<JsonArray>()) {
518+
msg_uart_add.cfg_device.config.generic_uart_input.sensor_types[sensor_type_count] = ParseSensorType(sensor_type["type"]);
519+
sensor_type_count++;
520+
}
521+
msg_uart_add.cfg_device.config.generic_uart_input.sensor_types_count = sensor_type_count;
483522
} else {
484523
WS_DEBUG_PRINTLN("[SD] Parsing Error: Unknown UART device type found: " + String(device_type));
485524
return false;

src/provisioning/sdcard/ws_sdcard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class ws_sdcard {
8686
void TickSoftRTC();
8787
uint32_t GetSoftRTCTime();
8888
wippersnapper_sensor_SensorType ParseSensorType(const char *sensor_type);
89+
wippersnapper_uart_GenericDeviceLineEnding ParseUartLineEnding(const char *line_ending);
8990
bool ParseComponents(JsonArray &components);
9091
bool
9192
ParseDigitalIOAdd(JsonObject &component,

0 commit comments

Comments
 (0)