Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat enable decoders #27

Merged
merged 6 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions BresserWeatherSensorLWCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
//
// 20240504 Extracted from BresserWeatherSensorLWCfg.h
// 20240507 Added CMD_GET_SENSORS_CFG/CMD_SET_SENSORS_CFG
// 20240508 Updated description of CMD_GET_SENSORS_CFG/CMD_SET_SENSORS_CFG
//
// ToDo:
// -
Expand Down Expand Up @@ -232,7 +233,8 @@

// Uplink (response):
// byte0: max_sensors
// byte1: rx_strategy
// byte1: rx_flags
// byte2: en_decoders

// CMD_SET_SENSORS_CFG
// --------------------
Expand All @@ -241,7 +243,8 @@

// Downlink (command):
// byte0: max_sensors
// byte1: rx_strategy
// byte1: rx_flags
// byte2: en_decoders

// Uplink: n.a.

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ Many software parameters can be defined at compile time, i.e. in [BresserWeather
| <sensors_incX> | Bresser sensor IDs include list; e.g. "0xDEADBEEF"; "0x00000000" => empty list => default values |
| <sensors_excX> | Bresser sensor IDs include list; e.g. "0xDEADBEEF"; "0x00000000" => empty list => default values |
| <max_sensors> | Max. number of Bresser sensors per receive cycle; 1...8 |
| <rx_flags> | Flags for getData(); see [BresserWeatherSensorReceiver](https://github.com/matthias-bs/BresserWeatherSensorReceiver) |
| <rx_flags> | Flags for getData(); see [BresserWeatherSensorReceiver](https://github.com/matthias-bs/BresserWeatherSensorReceiver/blob/627d0c68ee9304acb9ecfb5f226e4d7be99467cb/src/WeatherSensor.h#L130) |
| <en_decoders> | Enabled sensor data decoders; see [BresserWeatherSensorReceiver](https://github.com/matthias-bs/BresserWeatherSensorReceiver/blob/627d0c68ee9304acb9ecfb5f226e4d7be99467cb/src/WeatherSensor.h#L135)
| <ble_active> | BLE active scan; 1 (active scan) / 0 (passive scan) |
| <ble_scantime> | BLE scan time in seconds; 0...255 |
| <ble_addrX> | BLE sensor MAC addresses; e.g. "DE:AD:BE:EF:12:23" |
Expand Down Expand Up @@ -415,8 +416,8 @@ Many software parameters can be defined at compile time, i.e. in [BresserWeather
| CMD_SET_SENSORS_INC | 0xC5 (197) | sensors_inc0[31:24]<br>sensors_inc0[23:15]<br>sensors_inc0[16:8]<br>sensors_inc0[7:0]<br>... | n.a. |
| CMD_GET_SENSORS_EXC | 0xC6 (198) | 0x00 | sensors_exc0[31:24]<br>sensors_exc0[23:15]<br>sensors_exc0[16:8]<br>sensors_exc0[7:0]<br>... |
| CMD_SET_SENSORS_EXC | 0xC7 (199) | sensors_exc0[31:24]<br>sensors_exc0[23:15]<br>sensors_exc0[16:8]<br>sensors_exc0[7:0]<br>... | n.a. |
| CMD_GET_SENSORS_CFG | 0xCC (204) | 0x00 | max_sensors[7:0]<br>rx_flags[7:0] |
| CMD_SET_SENSORS_CFG | 0xCD (205) | max_sensors[7:0]<br>rx_flags[7:0] | n.a. |
| CMD_GET_SENSORS_CFG | 0xCC (204) | 0x00 | max_sensors[7:0]<br>rx_flags[7:0]<br>en_decoders<7:0> |
| CMD_SET_SENSORS_CFG | 0xCD (205) | max_sensors[7:0]<br>rx_flags[7:0]<br>en_decoders<7:0> | n.a. |
| CMD_GET_BLE_ADDR | 0xC8 (200) | 0x00 | ble_addr0[47:40]<br>ble_addr0[39:32]<br>ble_addr0[31:24]<br>ble_addr0[23:15]<br>ble_addr0[16:8]<br>ble_addr0[7:0]<br>... |
| CMD_SET_BLE_ADDR | 0xC9 (201) | ble_addr0[47:40]<br>ble_addr0[39:32]<br>ble_addr0[31:24]<br>ble_addr0[23:15]<br>ble_addr0[16:8]<br>ble_addr0[7:0]<br>... | n.a. |
| CMD_GET_BLE_CONFIG | 0xCA (202) | 0x00 | ble_active[7:0]<br>ble_scantime[7:0] |
Expand Down Expand Up @@ -456,8 +457,8 @@ Many software parameters can be defined at compile time, i.e. in [BresserWeather
| CMD_SET_SENSORS_INC | {"sensors_inc": [<sensors_inc0>, ..., <sensors_incN>]} | n.a. |
| CMD_GET_SENSORS_EXC | {"cmd": "CMD_GET_SENSORS_EXC"} | {"sensors_exc": [<sensors_exc0>, ..., <sensors_excN>]} |
| CMD_SET_SENSORS_EXC | {"sensors_exc": [<sensors_exc0>, ..., <sensors_excN>]} | n.a. |
| CMD_GET_SENSORS_CFG | {"cmd": "CMD_GET_SENSORS_CFG"} | {"max_sensors": <max_sensors>, "rx_flags": <rx_flags>} |
| CMD_SET_SENSORS_CFG | {"max_sensors": <max_sensors>, "rx_flags": <rx_flags>} | n.a. |
| CMD_GET_SENSORS_CFG | {"cmd": "CMD_GET_SENSORS_CFG"} | {"max_sensors": <max_sensors>, "rx_flags": <rx_flags>, "en_decoders": <en_decoders>} |
| CMD_SET_SENSORS_CFG | {"max_sensors": <max_sensors>, "rx_flags": <rx_flags>, "en_decoders": <en_decoders>} | n.a. |
| CMD_GET_BLE_ADDR | {"cmd": "CMD_GET_BLE_ADDR"} | {"ble_addr": [<ble_addr0>, ..., <ble_addrN>]} |
| CMD_SET_BLE_ADDR | {"ble_addr": [<ble_addr0>, ..., <ble_addrN>]} | n.a. |
| CMD_GET_BLE_CONFIG | {"cmd": "CMD_GET_BLE_CONFIG"} | {"ble_active": <ble_active>, "ble_scantime": <ble_scantime>} |
Expand Down
15 changes: 12 additions & 3 deletions scripts/downlink_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
//
// CMD_GET_SENSORS_EXC {"sensors_exc"}: [<sensors_exc0>, ...]}
//
// CMD_GET_SENSORS_CFG {"max_sensors": <max_sensors>, "rx_flags": <rx_flags>, "en_decoders": <en_decoders>}
//
// CMD_GET_BLE_ADDR {"ble_addr": [<ble_addr0>, ...]}
//
// CMD_GET_BLE_CONFIG {"ble_active": <ble_active>, "ble_scantime": <ble_scantime>}
Expand All @@ -56,6 +58,9 @@
// <rtc_source> : 0x00: GPS / 0x01: RTC / 0x02: LORA / 0x03: unsynched / 0x04: set (source unknown)
// <sensors_incN> : e.g. "0xDEADBEEF"
// <sensors_excN> : e.g. "0xDEADBEEF"
// <max_sensors> : max. number of Bresser sensors per receive cycle; 1...8
// <rx_flags> : Flags for getData(); see BresserWeatherSensorReceiver
// <en_decoders> : Enabled decoders; see BresserWeatherSensorReceiver
// <ble_active> : BLE scan mode - 0: passive / 1: active
// <ble_scantime> : BLE scan time in seconds (0...255)
// <ble_addrN> : e.g. "DE:AD:BE:EF:12:23"
Expand Down Expand Up @@ -98,6 +103,7 @@
// 20240427 Added BLE configuration
// 20240507 Added CMD_GET_SENSORS_CFG/CMD_SET_SENSORS_CFG
// 20240508 Fixed decoding of raw data
// Added en_decoders to CMD_GET_SENSORS_CFG/CMD_SET_SENSORS_CFG
//
// ToDo:
// -
Expand Down Expand Up @@ -368,9 +374,11 @@ function encodeDownlink(input) {
warnings: [],
errors: []
};
} else if (input.data.hasOwnProperty('max_sensors') && input.data.hasOwnProperty('rx_flags')) {
} else if (input.data.hasOwnProperty('max_sensors') &&
input.data.hasOwnProperty('rx_flags') &&
input.data.hasOwnProperty('en_decoders')) {
return {
bytes: [input.data.max_sensors, input.data.rx_flags],
bytes: [input.data.max_sensors, input.data.rx_flags, input.data.en_decoders],
fPort: CMD_SET_SENSORS_CFG,
warnings: [],
errors: []
Expand Down Expand Up @@ -471,7 +479,8 @@ function decodeDownlink(input) {
return {
data: {
max_sensors: uint8(input.bytes.slice(0, 1)),
rx_flags: uint8(input.bytes.slice(1, 2))
rx_flags: uint8(input.bytes.slice(1, 2)),
en_decoders: uint8(input.bytes.slice(2, 3))
}
};
case CMD_SET_BLE_ADDR:
Expand Down
10 changes: 8 additions & 2 deletions scripts/uplink_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
//
// CMD_GET_SENSORS_EXC {"sensors_exc"}: [<sensors_exc0>, ...]}
//
// CMD_GET_SENSORS_CFG {"max_sensors": <max_sensors>, "rx_flags": <rx_flags>, "en_decoders": <en_decoders>}
//
// CMD_GET_BLE_ADDR {"ble_addr": [<ble_addr0>, ...]}
//
// CMD_GET_BLE_CONFIG {"ble_active": <ble_active>, "ble_scantime": <ble_scantime>}
Expand All @@ -58,6 +60,9 @@
// <rtc_source> : 0x00: GPS / 0x01: RTC / 0x02: LORA / 0x03: unsynched / 0x04: set (source unknown)
// <sensors_incN> : e.g. "0xDEADBEEF"
// <sensors_excN> : e.g. "0xDEADBEEF"
// <max_sensors> : max. number of Bresser sensors per receive cycle; 1...8
// <rx_flags> : Flags for getData(); see BresserWeatherSensorReceiver
// <en_decoders> : Enabled decoders; see BresserWeatherSensorReceiver
// <ble_active> : BLE scan mode - 0: passive / 1: active
// <ble_scantime> : BLE scan time in seconds (0...255)
// <ble_addrN> : e.g. "DE:AD:BE:EF:12:23"
Expand Down Expand Up @@ -98,6 +103,7 @@
// renamed from ttn_uplink_formatter.js
// 20240427 Added BLE configuration
// 20240507 Added CMD_GET_SENSORS_CFG
// 20240608 Added en_decoders to CMD_GET_SENSORS_CFG
//
// ToDo:
// -
Expand Down Expand Up @@ -460,9 +466,9 @@ function decoder(bytes, port) {
} else if (port === CMD_GET_SENSORS_CFG) {
return decode(
bytes,
[uint8, uint8
[uint8, uint8, uint8
],
['max_sensors', 'rx_flags'
['max_sensors', 'rx_flags', 'en_decoders'
]
);
} else if (port === CMD_GET_BLE_ADDR) {
Expand Down
13 changes: 8 additions & 5 deletions src/AppLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
// 20240426 Added BLE address initialization after updating via downlink
// 20240427 Added BLE configuration/status via LoRaWAN
// 20240507 Added configuration of max_sensors/rx_flags via LoRaWAN
// 20240508 Added configuration of en_decoders via LoRaWAN
//
//
// ToDo:
Expand Down Expand Up @@ -136,11 +137,11 @@ AppLayer::decodeDownlink(uint8_t port, uint8_t *payload, size_t size)
return CMD_GET_SENSORS_CFG;
}

if ((port == CMD_SET_SENSORS_CFG) && (size == 2))
if ((port == CMD_SET_SENSORS_CFG) && (size == 3))
{
log_d("Set sensors configuration - max_sensors: %u, rx_flags: %u",
payload[0], payload[1]);
weatherSensor.setSensorsCfg(payload[0], payload[1]);
log_d("Set sensors configuration - max_sensors: %u, rx_flags: %u, en_decoders: %u",
payload[0], payload[1], payload[2]);
weatherSensor.setSensorsCfg(payload[0], payload[1], payload[2]);
return 0;
}

Expand Down Expand Up @@ -655,9 +656,11 @@ void AppLayer::getConfigPayload(uint8_t cmd, uint8_t &port, LoraEncoder &encoder
{
uint8_t maxSensors;
uint8_t rxFlags;
weatherSensor.getSensorsCfg(maxSensors, rxFlags);
uint8_t enDecoders;
weatherSensor.getSensorsCfg(maxSensors, rxFlags, enDecoders);
encoder.writeUint8(maxSensors);
encoder.writeUint8(rxFlags);
encoder.writeUint8(enDecoders);
port = CMD_GET_SENSORS_CFG;
}
#if defined(MITHERMOMETER_EN) || defined(THEENGSDECODER_EN)
Expand Down
Loading