Skip to content

Commit 86d95ec

Browse files
committed
SDCard - begin parsing UARTadd, needs new PB
1 parent ced98cb commit 86d95ec

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,52 @@ uint32_t ws_sdcard::HexStrToInt(const char *hex_str) {
443443
return std::stoi(hex_str, nullptr, 16);
444444
}
445445

446+
447+
/*!
448+
@brief Parses a Uartadd message from the JSON configuration file.
449+
@param component
450+
The JSON object to parse.
451+
@param msg_uart_add
452+
The UartAdd message to populate.
453+
@returns True if the message was successfully populated, False otherwise.
454+
*/
455+
bool ws_sdcard::ParseUartAdd(JsonObject &component, wippersnapper_uart_UartAdd &msg_uart_add) {
456+
// Configure the Serial
457+
msg_uart_add.has_cfg_serial = true;
458+
strncpy(msg_uart_add.cfg_serial.pin_rx, component["pinRx"] | UNKNOWN_VALUE, sizeof(msg_uart_add.cfg_serial.pin_rx) - 1);
459+
strncpy(msg_uart_add.cfg_serial.pin_tx, component["pinTx"] | UNKNOWN_VALUE, sizeof(msg_uart_add.cfg_serial.pin_tx) - 1);
460+
msg_uart_add.cfg_serial.uart_nbr = component["uartNbr"] | 0;
461+
msg_uart_add.cfg_serial.baud_rate = component["baudRate"] | 9600;
462+
msg_uart_add.cfg_serial.format = wippersnapper_uart_UartPacketFormat_UART_PACKET_FORMAT_8N1; // Stick to default 8N1 for now
463+
msg_uart_add.cfg_serial.timeout = component["timeout"] | 1000; // Use a default UART timeout of 1000ms
464+
msg_uart_add.cfg_serial.use_sw_serial = component["useSwSerial"] | false;
465+
msg_uart_add.cfg_serial.sw_serial_invert = component["swSerialInvert"] | false;
466+
// Configure the UART device
467+
msg_uart_add.has_cfg_device = true;
468+
strncpy(msg_uart_add.cfg_device.device_id, component["deviceId"] | UNKNOWN_VALUE, sizeof(msg_uart_add.cfg_device.device_id) - 1);
469+
// set UartDeviceType
470+
const char *device_type = component["deviceType"] | "UNKNOWN";
471+
if (strcmp(device_type, "GPS") == 0) {
472+
msg_uart_add.cfg_device.device_type = wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_GPS;
473+
// Fill the config field
474+
} else if (strcmp(device_type, "PM25AQI") == 0) {
475+
msg_uart_add.cfg_device.device_type = wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_PM25AQI;
476+
} else if (strcmp(device_type, "GENERIC-INPUT") == 0) {
477+
msg_uart_add.cfg_device.device_type = wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_GENERIC_INPUT;
478+
msg_uart_add.cfg_device.config.generic_uart_input.period = component["period"] | 0.0;
479+
// Fill sensor types
480+
// TODO: Needs new PB!
481+
// msg_uart_add.cfg_device.config.generic_uart_input.i2c_ = 0;
482+
483+
} else {
484+
WS_DEBUG_PRINTLN("[SD] Parsing Error: Unknown UART device type found: " + String(device_type));
485+
return false;
486+
}
487+
488+
489+
return true;
490+
}
491+
446492
/**************************************************************************/
447493
/*!
448494
@brief Parses a DS18x20Add message from the JSON configuration file.
@@ -839,6 +885,15 @@ bool ws_sdcard::ParseComponents(JsonArray &components) {
839885
_cfg_i2c_addresses.push_back(
840886
msg_add.i2c_device_description.i2c_device_address);
841887
}
888+
} else if (strcmp(component_api_type, "uart") ==0) {
889+
WS_DEBUG_PRINTLN("[SD] UART component found in cfg");
890+
wippersnapper_uart_UartAdd msg_uart_add = wippersnapper_uart_UartAdd_init_default;
891+
success = ParseUartAdd(component, msg_uart_add);
892+
if (success) {
893+
WS_DEBUG_PRINTLN("[SD] UART component parsed successfully, adding to shared buffer..");
894+
msg_signal_b2d.which_payload = wippersnapper_signal_BrokerToDevice_uart_add_tag;
895+
msg_signal_b2d.payload.uart_add = msg_uart_add;
896+
}
842897
} else {
843898
WS_DEBUG_PRINTLN("[SD] Error: Unknown Component API: " +
844899
String(component_api_type));

src/provisioning/sdcard/ws_sdcard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class ws_sdcard {
9494
wippersnapper_analogio_AnalogIOAdd &msg_AnalogIOAdd);
9595
bool ParseDS18xAdd(JsonObject &component,
9696
wippersnapper_ds18x20_Ds18x20Add &msg_ds18x20_add);
97+
bool ParseUartAdd(JsonObject &component, wippersnapper_uart_UartAdd &msg_uart_add);
9798
bool ParseI2cDeviceAddReplace(
9899
JsonObject &component,
99100
wippersnapper_i2c_I2cDeviceAddOrReplace &msg_i2c_device_add_replace);

0 commit comments

Comments
 (0)