Generate DeviceID from hwinfo
This commit is contained in:
@@ -24,6 +24,11 @@ config CONTROL_FREQUENCY
|
||||
Frequencies higher than 10 Hz caused issues with MPPT control during lab test with
|
||||
PV simulator. Might be different with actual solar panel.
|
||||
|
||||
config LIBRE_SOLAR_TYPE_ID
|
||||
int
|
||||
help
|
||||
Numeric Libre Solar hardware type ID
|
||||
|
||||
|
||||
#
|
||||
# Visible (user-configurable) Kconfig symbols
|
||||
|
||||
@@ -6,6 +6,9 @@ if BOARD_MPPT_1210_HUS
|
||||
config BOARD
|
||||
default "mppt_1210_hus"
|
||||
|
||||
config LIBRE_SOLAR_TYPE_ID
|
||||
default 4
|
||||
|
||||
if UART_CONSOLE
|
||||
|
||||
config UART_2
|
||||
|
||||
@@ -6,6 +6,9 @@ if BOARD_MPPT_2420_HPX
|
||||
config BOARD
|
||||
default "mppt_2420_hpx"
|
||||
|
||||
config LIBRE_SOLAR_TYPE_ID
|
||||
default 7
|
||||
|
||||
if UART_CONSOLE
|
||||
|
||||
config UART_1
|
||||
|
||||
@@ -6,6 +6,9 @@ if BOARD_MPPT_2420_LC
|
||||
config BOARD
|
||||
default "mppt_2420_lc"
|
||||
|
||||
config LIBRE_SOLAR_TYPE_ID
|
||||
default 1
|
||||
|
||||
if UART_CONSOLE
|
||||
|
||||
config UART_2
|
||||
|
||||
@@ -6,6 +6,9 @@ if BOARD_PWM_2420_LUS
|
||||
config BOARD
|
||||
default "pwm_2420_lus"
|
||||
|
||||
config LIBRE_SOLAR_TYPE_ID
|
||||
default 5
|
||||
|
||||
if UART_CONSOLE
|
||||
|
||||
config UART_2
|
||||
|
||||
+37
-5
@@ -8,6 +8,8 @@
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#include <zephyr.h>
|
||||
#include <drivers/hwinfo.h>
|
||||
#include <sys/crc.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -32,7 +34,7 @@ const char* const device_type = DT_CHARGE_CONTROLLER_PCB_TYPE;
|
||||
const char* const hardware_version = DT_CHARGE_CONTROLLER_PCB_VERSION_STR;
|
||||
const char* const firmware_version = "0.1";
|
||||
const char* const firmware_commit = COMMIT_HASH;
|
||||
uint32_t device_id = CONFIG_DEVICE_ID;
|
||||
char device_id[9];
|
||||
|
||||
static char auth_password[11];
|
||||
|
||||
@@ -66,7 +68,7 @@ static DataNode data_nodes[] = {
|
||||
|
||||
TS_NODE_PATH(ID_INFO, "info", 0, NULL),
|
||||
|
||||
TS_NODE_UINT32(0x19, "DeviceID", &(device_id),
|
||||
TS_NODE_STRING(0x19, "DeviceID", device_id, sizeof(device_id),
|
||||
ID_INFO, TS_ANY_R | TS_MKR_W, PUB_NVM),
|
||||
|
||||
TS_NODE_STRING(0x1A, "Manufacturer", manufacturer, 0,
|
||||
@@ -90,7 +92,7 @@ static DataNode data_nodes[] = {
|
||||
// CONFIGURATION //////////////////////////////////////////////////////////
|
||||
// using IDs >= 0x30 except for high priority data objects
|
||||
|
||||
TS_NODE_PATH(ID_CONF, "conf", 0, &data_objects_update_conf),
|
||||
TS_NODE_PATH(ID_CONF, "conf", 0, &data_nodes_update_conf),
|
||||
|
||||
// battery settings
|
||||
|
||||
@@ -441,7 +443,7 @@ static DataNode data_nodes[] = {
|
||||
|
||||
ThingSet ts(data_nodes, sizeof(data_nodes)/sizeof(DataNode));
|
||||
|
||||
void data_objects_update_conf()
|
||||
void data_nodes_update_conf()
|
||||
{
|
||||
bool changed;
|
||||
if (battery_conf_check(&bat_conf_user)) {
|
||||
@@ -464,8 +466,18 @@ void data_objects_update_conf()
|
||||
eeprom_store_data();
|
||||
}
|
||||
|
||||
void data_objects_read_eeprom()
|
||||
void data_nodes_init()
|
||||
{
|
||||
#ifndef UNIT_TEST
|
||||
uint8_t buf[12];
|
||||
hwinfo_get_device_id(buf, sizeof(buf));
|
||||
|
||||
uint64_t id64 = crc32_ieee(buf, sizeof(buf));
|
||||
id64 += ((uint64_t)CONFIG_LIBRE_SOLAR_TYPE_ID) << 32;
|
||||
|
||||
uint64_to_base32(id64, device_id, sizeof(device_id), alphabet_crockford);
|
||||
#endif
|
||||
|
||||
eeprom_restore_data();
|
||||
if (battery_conf_check(&bat_conf_user)) {
|
||||
battery_conf_overwrite(&bat_conf_user, &bat_conf, &charger);
|
||||
@@ -498,4 +510,24 @@ void thingset_auth()
|
||||
}
|
||||
}
|
||||
|
||||
void uint64_to_base32(uint64_t in, char *out, size_t size, const char *alphabet)
|
||||
{
|
||||
// 13 is the maximum number of characters needed to encode 64-bit variable to base32
|
||||
int len = (size > 13) ? 13 : size;
|
||||
|
||||
// find out actual length of output string
|
||||
for (int i = 0; i < len; i++) {
|
||||
if ((in >> (i * 5)) == 0) {
|
||||
len = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
out[len-i-1] = alphabet[(in >> (i * 5)) % 32];
|
||||
}
|
||||
out[len] = '\0';
|
||||
}
|
||||
|
||||
|
||||
#endif /* CUSTOM_DATA_NODES_FILE */
|
||||
|
||||
+27
-2
@@ -12,6 +12,9 @@
|
||||
* @brief Handling of ThingSet data nodes
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Categories / first layer node IDs
|
||||
*/
|
||||
@@ -46,9 +49,31 @@
|
||||
extern bool pub_serial_enable;
|
||||
extern bool pub_can_enable;
|
||||
|
||||
void data_objects_update_conf();
|
||||
void data_objects_read_eeprom();
|
||||
/**
|
||||
* Callback function to be called when conf values were changed
|
||||
*/
|
||||
void data_nodes_update_conf();
|
||||
|
||||
/**
|
||||
* Initializes and reads data nodes from EEPROM
|
||||
*/
|
||||
void data_nodes_init();
|
||||
|
||||
/**
|
||||
* Callback to provide authentication mechanism via ThingSet
|
||||
*/
|
||||
void thingset_auth();
|
||||
|
||||
/**
|
||||
* Alphabet used for base32 encoding
|
||||
*
|
||||
* https://en.wikipedia.org/wiki/Base32#Crockford's_Base32
|
||||
*/
|
||||
const char alphabet_crockford[] = "0123456789abcdefghjkmnpqrstvwxyz";
|
||||
|
||||
/**
|
||||
* Convert numeric device ID to base32 string
|
||||
*/
|
||||
void uint64_to_base32(uint64_t in, char *out, size_t size, const char *alphabet);
|
||||
|
||||
#endif /* DATA_OBJECTS_H */
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ void main(void)
|
||||
battery_conf_overwrite(&bat_conf, &bat_conf_user); // initialize conf_user with same values
|
||||
|
||||
// read custom configuration from EEPROM
|
||||
data_objects_read_eeprom();
|
||||
data_nodes_init();
|
||||
|
||||
// Data Acquisition (DAQ) setup
|
||||
daq_setup();
|
||||
|
||||
@@ -23,6 +23,8 @@ CONFIG_CONSOLE_GETCHAR=y
|
||||
|
||||
CONFIG_CPLUSPLUS=y
|
||||
|
||||
CONFIG_HWINFO=y
|
||||
|
||||
CONFIG_BUILD_OUTPUT_BIN=y
|
||||
|
||||
# ThingSet protocol interface at UART serial
|
||||
|
||||
Reference in New Issue
Block a user