Update to ThingSet library v0.4

This includes mostly renaming of functions and data structure.

See thingset.io for details of protocol changes.
This commit is contained in:
Martin Jäger
2021-08-29 09:54:59 +02:00
parent 51e0a3ae82
commit cc1d4267fa
6 changed files with 255 additions and 248 deletions
+215 -214
View File
File diff suppressed because it is too large Load Diff
+16 -16
View File
@@ -19,26 +19,26 @@
* Categories / first layer node IDs
*/
#define ID_ROOT 0x00
#define ID_INFO 0x18 // read-only device information (e.g. manufacturer, device ID)
#define ID_CONF 0x30 // configurable settings
#define ID_INPUT 0x60 // input data (e.g. set-points)
#define ID_OUTPUT 0x70 // output data (e.g. measurement values)
#define ID_REC 0xA0 // recorded data (history-dependent)
#define ID_CAL 0xD0 // calibration
#define ID_EXEC 0xE0 // function call
#define ID_AUTH 0xEA
#define ID_PUB 0xF0 // publication setup
#define ID_SUB 0xF1 // subscription setup
#define ID_LOG 0x100 // access log data
#define ID_INFO 0x01 // read-only device information (e.g. manufacturer, device ID)
#define ID_MEAS 0x02 // output data (e.g. measurement values)
#define ID_STATE 0x03 // recorded data (history-dependent)
#define ID_REC 0x04 // recorded data (history-dependent)
#define ID_INPUT 0x05 // input data (e.g. set-points)
#define ID_CONF 0x06 // configurable settings
#define ID_CAL 0x07 // calibration
#define ID_REPORT 0x0A // reports
#define ID_DFU 0x0D // device firmware upgrade
#define ID_RPC 0x0E // remote procedure calls
#define ID_PUB 0x0F // publication setup
#define ID_CTRL 0x8000 // control functions
/*
* Publish/subscribe channels
* Subset definitions for statements and publish/subscribe
*/
#define PUB_SER (1U << 0) // UART serial
#define PUB_CAN (1U << 1) // CAN bus
#define PUB_NVM (1U << 2) // data that should be stored in EEPROM
#define PUBSUB_CTRL (1U << 3) // control data sent and received via CAN
#define SUBSET_SER (1U << 0) // UART serial
#define SUBSET_CAN (1U << 1) // CAN bus
#define SUBSET_NVM (1U << 2) // data that should be stored in EEPROM
#define SUBSET_CTRL (1U << 3) // control data sent and received via CAN
/*
* Data object versioning for EEPROM
+5 -5
View File
@@ -98,7 +98,7 @@ void data_storage_read()
//for (int i = 0; i < len; i++) printf("%.2x ", buf[i]);
if (_calc_crc(buf, len) == crc) {
int status = ts.bin_sub(buf, sizeof(buf), TS_WRITE_MASK, PUB_NVM);
int status = ts.bin_import(buf, sizeof(buf), TS_WRITE_MASK, SUBSET_NVM);
LOG_INF("EEPROM read and data objects updated, ThingSet result: 0x%x", status);
}
else {
@@ -120,7 +120,7 @@ void data_storage_write()
k_mutex_lock(&data_buf_lock, K_FOREVER);
int len = ts.bin_pub(buf + EEPROM_HEADER_SIZE, sizeof(buf) - EEPROM_HEADER_SIZE, PUB_NVM);
int len = ts.bin_export(buf + EEPROM_HEADER_SIZE, sizeof(buf) - EEPROM_HEADER_SIZE, SUBSET_NVM);
uint32_t crc = _calc_crc(buf + EEPROM_HEADER_SIZE, len);
*((uint16_t*)&buf[0]) = (uint16_t)DATA_OBJECTS_VERSION;
@@ -211,8 +211,8 @@ void data_storage_read()
if (version == DATA_OBJECTS_VERSION) {
k_mutex_lock(&data_buf_lock, K_FOREVER);
int status = ts.bin_sub(buf + NVS_HEADER_SIZE, num_bytes - NVS_HEADER_SIZE,
TS_WRITE_MASK, PUB_NVM);
int status = ts.bin_import(buf + NVS_HEADER_SIZE, num_bytes - NVS_HEADER_SIZE,
TS_WRITE_MASK, SUBSET_NVM);
LOG_INF("NVS read and data objects updated, ThingSet result: 0x%x", status);
k_mutex_unlock(&data_buf_lock);
@@ -232,7 +232,7 @@ void data_storage_write()
*((uint16_t*)&buf[0]) = (uint16_t)DATA_OBJECTS_VERSION;
int len = ts.bin_pub(buf + NVS_HEADER_SIZE, sizeof(buf) - NVS_HEADER_SIZE, PUB_NVM);
int len = ts.bin_export(buf + NVS_HEADER_SIZE, sizeof(buf) - NVS_HEADER_SIZE, SUBSET_NVM);
if (len == 0) {
LOG_ERR("NVS data could not be stored. ThingSet error (len = %d)", len);
+9 -10
View File
@@ -208,7 +208,7 @@ void can_pubsub_thread()
int start_pos = 0;
while (count % 10 == 0) {
// normal objects: only every second
data_len = ts.bin_pub_can(start_pos, PUB_CAN, can_node_addr, can_id, can_data);
data_len = ts.bin_pub_can(start_pos, SUBSET_CAN, can_node_addr, can_id, can_data);
if (data_len < 0) {
// finished with all IDs
break;
@@ -222,7 +222,7 @@ void can_pubsub_thread()
start_pos = 0;
while (true) {
// control objects: every 100 ms
data_len = ts.bin_pub_can(start_pos, PUBSUB_CTRL, can_node_addr, can_id, can_data);
data_len = ts.bin_pub_can(start_pos, SUBSET_CTRL, can_node_addr, can_id, can_data);
if (data_len < 0) {
break;
}
@@ -240,15 +240,14 @@ void can_pubsub_thread()
// control message received?
if (data_id > 0x8000 && sender_addr < can_node_addr) {
uint8_t buf[5 + 8]; // ThingSet bin headers + CAN frame payload
buf[0] = 0x1F; // ThingSet pub message
buf[1] = 0xA1; // CBOR: map with 1 element
buf[2] = 0x19; // CBOR: uint16 follows
buf[3] = data_id >> 8;
buf[4] = data_id;
memcpy(&buf[5], rx_frame.data, 8);
uint8_t buf[4 + 8]; // ThingSet bin headers + CAN frame payload
buf[0] = 0xA1; // CBOR: map with 1 element
buf[1] = 0x19; // CBOR: uint16 follows
buf[2] = data_id >> 8;
buf[3] = data_id;
memcpy(&buf[4], rx_frame.data, 8);
int status = ts.bin_sub(buf, 5 + rx_frame.dlc, TS_WRITE_MASK, PUBSUB_CTRL);
int status = ts.bin_import(buf, 4 + rx_frame.dlc, TS_WRITE_MASK, SUBSET_CTRL);
if (status == TS_STATUS_CHANGED) {
charger.time_last_ctrl_msg = uptime();
}
+6 -1
View File
@@ -37,10 +37,13 @@ static volatile bool command_flag = false;
extern ThingSet ts;
const char serial_subset_path[] = "serial";
static ThingSetDataObject *serial_subset;
void process_1s()
{
if (pub_serial_enable) {
int len = ts.txt_pub(buf_resp, sizeof(buf_resp), PUB_SER);
int len = ts.txt_statement(buf_resp, sizeof(buf_resp), serial_subset);
for (int i = 0; i < len; i++) {
uart_poll_out(uart_dev, buf_resp[i]);
}
@@ -120,6 +123,8 @@ void serial_thread()
uart_irq_callback_user_data_set(uart_dev, process_input, NULL);
uart_irq_rx_enable(uart_dev);
serial_subset = ts.get_endpoint(serial_subset_path, strlen(serial_subset_path));
while (true) {
task_wdt_feed(wdt_channel);
+4 -2
View File
@@ -4,6 +4,8 @@ manifest:
url-base: https://github.com/zephyrproject-rtos
- name: libresolar
url-base: https://github.com/LibreSolar
- name: thingset
url-base: https://github.com/ThingSet
projects:
- name: zephyr
remote: libresolar
@@ -19,6 +21,6 @@ manifest:
- edtt
- hal_stm32
- name: thingset-device-library
remote: libresolar
revision: 0e695f719bb8cf10de212b2b9f41fba65d9327df
remote: thingset
revision: 1eaa305a9f1873f676b77b8dd0f9d34f1944ecd1
path: zephyr/modules/thingset