34 #include "stima_utility.h"
40 #define PASTE3_IMPL(x, y, z) x##y##z
41 #define PASTE3(x, y, z) PASTE3_IMPL(x, y, z)
125 return (
size_t)data_len;
136 return (
size_t)name_len;
160 if(reg_valid == reg_numb) {
178 uint8_t _len_name = strlen((
char*)reg_name);
179 size_t _len_data = 0;
194 if(memcmp(reg_name, _reg_name, _len_name) == 0) {
196 memcpy(data, _reg_data, _len_data);
197 *reg_numb = reg_index;
213 uint8_t _len_name = strlen((
char*)reg_name);
228 if(memcmp(reg_name, _reg_name, _len_name) == 0) {
246 uint8_t name_len = strlen((
char*)reg_name);
252 if(reg_valid != reg_numb) {
277 *current_register = 0;
279 (*current_register)++;
281 if(register_index[*current_register] == *current_register) {
314 static uavcan_register_Value_1_0 val = {0};
315 uavcan_register_Value_1_0_select_natural16_(&val);
316 val.natural16.value.count = 1;
322 uavcan_register_Value_1_0_select_natural32_(&val);
323 val.natural32.value.count = 2;
325 val.natural32.value.elements[1] = 0ul;
331 #ifndef USE_NODE_SLAVE_ID_FIXED
332 uavcan_register_Value_1_0_select_natural16_(&val);
333 val.natural16.value.count = 1;
339 #ifdef NODE_MASTER_ID
340 uavcan_register_Value_1_0_select_natural16_(&val);
341 val.natural16.value.count = 1;
347 #ifdef PORT_SERVICE_RMAP
348 uavcan_register_Value_1_0_select_natural16_(&val);
349 val.natural16.value.count = 1;
355 #ifdef SUBJECTID_PUBLISH_RMAP
356 uavcan_register_Value_1_0_select_natural16_(&val);
357 val.natural16.value.count = 1;
364 char stima_description[STIMA_MODULE_DESCRIPTION_LENGTH] = {0};
365 getStimaDescriptionByType(stima_description,
MODULE_TYPE);
366 uavcan_register_Value_1_0_select_string_(&val);
367 val._string.value.count = strlen(stima_description);
368 memcpy(val._string.value.elements, stima_description, val._string.value.count);
376 void EERegister::read(
const char*
const register_name, uavcan_register_Value_1_0*
const inout_value) {
379 uint8_t register_number;
380 bool init_required = !uavcan_register_Value_1_0_is_empty_(inout_value);
381 uint8_t serialized[uavcan_register_Value_1_0_EXTENT_BYTES_] = {0};
384 static uavcan_register_Value_1_0 out = {0};
385 const int8_t err = uavcan_register_Value_1_0_deserialize_(&out, serialized, &sr_size);
386 if (err >= 0) init_required = !
assign(inout_value, &out);
387 if (init_required)
write(register_name, inout_value);
393 void EERegister::write(
const char*
const register_name,
const uavcan_register_Value_1_0*
const value) {
394 uint8_t serialized[uavcan_register_Value_1_0_EXTENT_BYTES_] = {0};
395 size_t sr_size = uavcan_register_Value_1_0_EXTENT_BYTES_;
396 const int8_t err = uavcan_register_Value_1_0_serialize_(value, serialized, &sr_size);
399 printf(
"Init register: %s\n", register_name);
413 uavcan_register_Name_1_0 out = {0};
414 uavcan_register_Name_1_0_initialize_(&out);
421 uint8_t reg_index = 0;
424 if(reg_index==index) {
427 out.name.count = nunavutChooseMin(strlen((
char*)_reg_name), uavcan_register_Name_1_0_name_ARRAY_CAPACITY_);
428 memcpy(out.name.elements, _reg_name, out.name.count);
448 bool EERegister::assign(uavcan_register_Value_1_0*
const dst,
const uavcan_register_Value_1_0*
const src) {
449 if (uavcan_register_Value_1_0_is_empty_(dst)) {
453 if ((uavcan_register_Value_1_0_is_string_(dst) && uavcan_register_Value_1_0_is_string_(src)) ||
454 (uavcan_register_Value_1_0_is_unstructured_(dst) && uavcan_register_Value_1_0_is_unstructured_(src))) {
458 if (uavcan_register_Value_1_0_is_bit_(dst) && uavcan_register_Value_1_0_is_bit_(src)) {
459 nunavutCopyBits(dst->bit.value.bitpacked,
461 nunavutChooseMin(dst->bit.value.count, src->bit.value.count),
462 src->bit.value.bitpacked,
467 #define REGISTER_CASE_SAME_TYPE(TYPE) \
468 if (PASTE3(uavcan_register_Value_1_0_is_, TYPE, _)(dst) && PASTE3(uavcan_register_Value_1_0_is_, TYPE, _)(src)) { \
469 for (size_t i = 0; i < nunavutChooseMin(dst->TYPE.value.count, src->TYPE.value.count); ++i) { \
470 dst->TYPE.value.elements[i] = src->TYPE.value.elements[i]; \
Uavcan Canard Configuration file.
#define SUBJECTID_PUBLISH_RMAP
#define PORT_SERVICE_RMAP
void _eeprom_register_get_intest_fast(uint8_t reg_numb, uint8_t *reg_name, uint8_t name_len)
Legge un registro CYPAL/STIMAV4 dalla memoria (per indice) (fast=senza controlli validità) la procedu...
size_t _eeprom_register_get_fast(uint8_t reg_numb, uint8_t *reg_name, uint8_t *reg_value)
Legge un registro CYPAL/STIMAV4 dalla memoria (per indice) (fast=senza controlli validità) la procedu...
bool _eeprom_register_get_name_from_index(uint8_t reg_numb, uint8_t *reg_name)
Legge un registro CYPAL/STIMAV4 dalla EEprom (per indice)
void _memory_write_block(uint16_t address, uint8_t *data, uint8_t len)
Wrapper memory_write_block.
void setup(void)
Check if exist or create space register with init default value.
void _eeprom_register_clear(uint8_t reg_numb)
Inizializza/Elimina un registro CYPAL/STIMAV4 dalla memoria.
uavcan_register_Name_1_0 getNameByIndex(const uint16_t index)
Scroll degli indici dal primo all'ultimo e return ID UavCAN Nel passaggio di un eventuale INDICE vuot...
void _eeprom_register_set(uint8_t reg_numb, uint8_t *reg_name, uint8_t *data, size_t len_data)
Scrive/edita un registro CYPAL/STIMAV4 sulla memoria.
bool assign(uavcan_register_Value_1_0 *const dst, const uavcan_register_Value_1_0 *const src)
Register type Assign UAVCAN.
void doFactoryReset(void)
Erase all registers such that the defaults are used at the next launch.
void _memory_write_byte(uint16_t address, uint8_t data)
Wrapper memory_write_byte.
void read(const char *const register_name, uavcan_register_Value_1_0 *const inout_value)
Legge un registro Cypal/Uavcan wrapper UAVCAN (Imposta Default su Set inout_value su value se non esi...
EERegister()
Constructor Class.
uint8_t _eeprom_register_add(uint8_t *reg_name, uint8_t *data, size_t data_len)
Aggiunge un registro alla configurazione CYPAL/STIMAV4.
void _memory_read_block(uint16_t address, uint8_t *data, uint8_t len)
Wrapper memory_read_block.
size_t _eeprom_register_get_from_name(uint8_t const *reg_name, uint8_t *reg_numb, uint8_t *data)
Legge un registro CYPAL/STIMAV4 dalla memoria (per Nome)
void _memory_read_byte(uint16_t address, uint8_t *data)
Wrapper memory_read_byte.
void write(const char *const register_name, const uavcan_register_Value_1_0 *const value)
Store the given register value into the persistent storage.
size_t _eeprom_register_get_len_intest_fast(uint8_t reg_numb)
Legge un registro CYPAL/STIMAV4 dalla memoria (per indice) (fast=senza controlli validità) la procedu...
uint8_t _eeprom_register_get_index_from_name(uint8_t *reg_name)
Legge un indiced di registro CYPAL/STIMAV4 dalla memoria (per Nome)
void _eeprom_register_get_next_id(uint8_t *current_register)
Ritorna il prossimo indice (se esiste) valido nella sezione memoria Cypal dedicata.
void _eeprom_register_factory(void)
Inizializza l'area memory (indice) dedicata a REGISTER.
bool Read(uint16_t address, uint8_t *buffer, uint16_t length)
Read a number of data byte from EEPROM.
bool Write(uint16_t address, uint8_t *buffer, uint16_t length)
Write a number of data byte into EEPROM.
#define MODULE_TYPE
Type of module. It is defined in registers.h.
#define REGISTER_CASE_SAME_TYPE(TYPE)
Register class (Uavcan/Other) header file.
#define MEM_UAVCAN_LEN_REG
#define MEM_UAVCAN_MAX_REG
#define REGISTER_RMAP_MASTER_ID
#define MEM_UAVCAN_POS_LEN_DATA
#define MEM_UAVCAN_POS_VALUE_DATA
#define REGISTER_UAVCAN_NODE_DESCR
#define MEM_UAVCAN_POS_LEN_NAME
#define REGISTER_UAVCAN_BITRATE
#define REGISTER_UAVCAN_NODE_ID
#define MEM_UAVCAN_LEN_VALUE_REG
#define MEM_UAVCAN_POS_STR_NAME
#define REGISTER_UAVCAN_DATA_PUBLISH
#define MEM_UAVCAN_GET_ADDR_NAME(X)
#define MEM_UAVCAN_LEN_NAME_REG
#define REGISTER_UAVCAN_DATA_SERVICE
#define MEM_UAVCAN_REG_UNDEF
#define MEM_UAVCAN_GET_ADDR_FLAG_REG(X)
#define MEM_UAVCAN_GET_ADDR_NAME_LEN(X)
#define REGISTER_UAVCAN_MTU
#define MEM_UAVCAN_GET_ADDR_BASE_REG(X)
#define MEM_UAVCAN_GET_ADDR_FLAG()