Stima V4 Slave RAIN  4.2
register_class.hpp
Go to the documentation of this file.
1 
30 #include <stdbool.h>
31 #include <stdint.h>
32 #include <uavcan/_register/Access_1_0.h>
33 #include <uavcan/_register/List_1_0.h>
34 #include "drivers/eeprom.h"
35 
36 #ifndef _REGISTER_CLASS_H
37 #define _REGISTER_CLASS_H
38 
39 // ***************************************************************************************
40 // E2PROM STIMAV4 STM32 REGISTER ACCESS LOCATION AND SIZE CONFIG
41 // ***************************************************************************************
42 
43 // Start Address BASE UAVCAN/CYPAL Register (128 Bytes x Register)
44 #define MEM_UAVCAN_LEN EEPROMSIZE
45 #define MEM_UAVCAN_ADDR_START REGISTER_EEPROM_ADDRESS
46 #define MEM_UAVCAN_MAX_REG 60u
47 #define MEM_UAVCAN_LEN_SIZE_T_REG 1u
48 #define MEM_UAVCAN_LEN_INTEST_REG 60u
49 #define MEM_UAVCAN_LEN_VALUE_REG 66u
50 #define MEM_UAVCAN_POS_LEN_NAME 0u
51 #define MEM_UAVCAN_POS_STR_NAME MEM_UAVCAN_POS_LEN_NAME + MEM_UAVCAN_LEN_SIZE_T_REG
52 #define MEM_UAVCAN_POS_LEN_DATA MEM_UAVCAN_POS_STR_NAME + MEM_UAVCAN_LEN_INTEST_REG
53 #define MEM_UAVCAN_POS_VALUE_DATA MEM_UAVCAN_POS_LEN_DATA + MEM_UAVCAN_LEN_SIZE_T_REG
54 #define MEM_UAVCAN_LEN_NAME_REG (MEM_UAVCAN_LEN_SIZE_T_REG + MEM_UAVCAN_LEN_INTEST_REG)
55 #define MEM_UAVCAN_LEN_DATA_REG (MEM_UAVCAN_LEN_SIZE_T_REG + MEM_UAVCAN_LEN_VALUE_REG)
56 #define MEM_UAVCAN_LEN_REG (MEM_UAVCAN_LEN_NAME_REG + MEM_UAVCAN_LEN_DATA_REG)
57 #define MEM_UAVCAN_START_AREA_REG (MEM_UAVCAN_ADDR_START + MEM_UAVCAN_MAX_REG)
58 #define MEM_UAVCAN_REG_UNDEF 0xFF
59 #define MEM_UAVCAN_GET_ADDR_FLAG() (MEM_UAVCAN_ADDR_START)
60 #define MEM_UAVCAN_GET_ADDR_FLAG_REG(X) (MEM_UAVCAN_ADDR_START + X)
61 #define MEM_UAVCAN_GET_ADDR_NAME_LEN(X) (MEM_UAVCAN_START_AREA_REG + (MEM_UAVCAN_LEN_REG * X))
62 #define MEM_UAVCAN_GET_ADDR_NAME(X) (MEM_UAVCAN_START_AREA_REG + (MEM_UAVCAN_LEN_REG * X) + MEM_UAVCAN_LEN_SIZE_T_REG)
63 #define MEM_UAVCAN_GET_ADDR_VALUE_LEN(X) (MEM_UAVCAN_START_AREA_REG + (MEM_UAVCAN_LEN_REG * X) + MEM_UAVCAN_LEN_NAME_REG)
64 #define MEM_UAVCAN_GET_ADDR_VALUE(X) (MEM_UAVCAN_START_AREA_REG + (MEM_UAVCAN_LEN_REG * X) + MEM_UAVCAN_LEN_NAME_REG + MEM_UAVCAN_LEN_SIZE_T_REG)
65 #define MEM_UAVCAN_GET_ADDR_BASE_REG(X) MEM_UAVCAN_GET_ADDR_NAME_LEN(X)
66 // Start Address Eeprom Application Free usage
67 #define MEM_UAVCAN_ADDR_END (MEM_UAVCAN_START_AREA_REG + (MEM_UAVCAN_LEN_REG * MEM_UAVCAN_MAX_REG))
68 #define MEM_UAVCAN_USED_TOTAL (MEM_UAVCAN_ADDR_END - MEM_UAVCAN_ADDR_START)
69 // Error Size Memory limit
70 #if (MEM_UAVCAN_ADDR_END > MEM_UAVCAN_LEN)
71  #error Uavcan Register limit is more than MAX SIZE (MEM_UAVCAN_LEN). Please check Register configuration
72 #endif
73 
74 // Register base name for metadata
75 #define REGISTER_UAVCAN_MTU "uavcan.can.mtu"
76 #define REGISTER_UAVCAN_BITRATE "uavcan.can.bitrate"
77 #define REGISTER_UAVCAN_NODE_ID "uavcan.node.id"
78 #define REGISTER_UAVCAN_UNIQUE_ID "uavcan.node.unique_id"
79 #define REGISTER_UAVCAN_NODE_DESCR "uavcan.node.description"
80 #define REGISTER_UAVCAN_DATA_PUBLISH "uavcan.pub.rmap.publish.id"
81 #define REGISTER_UAVCAN_DATA_SERVICE "uavcan.srv.rmap.service.id"
82 #define REGISTER_METADATA_LEVEL_L1 "rmap.metadata.Level.L1"
83 #define REGISTER_METADATA_LEVEL_L2 "rmap.metadata.Level.L2"
84 #define REGISTER_METADATA_LEVEL_TYPE1 "rmap.metadata.Level.LevelType1"
85 #define REGISTER_METADATA_LEVEL_TYPE2 "rmap.metadata.Level.LevelType2"
86 #define REGISTER_METADATA_TIME_P1 "rmap.metadata.Timerange.P1"
87 #define REGISTER_METADATA_TIME_PIND "rmap.metadata.Timerange.Pindicator"
88 #define REGISTER_DATA_PUBLISH "rmap.publish"
89 #define REGISTER_DATA_SERVICE "rmap.service"
90 #define REGISTER_RMAP_MASTER_ID "rmap.master.id"
91 
92 // Class EEProm - Register Uavcan
93 class EERegister {
94 
95 public:
96  // Constructor
97  EERegister();
98  EERegister(TwoWire *wire, BinarySemaphore *wireLock, uint8_t i2c_address = EEPROM_AT24C64_DEFAULT_ADDRESS);
99 
100  // Inizializza lo spazio RAM/ROM/FLASH/SD dei registri, ai valori di default
101  // N.B.! Azzera tutti registri e quelli non inizializzati devono essere impostati
102  // nel relativo modulo di utilizzo
103  void setup(void);
104 
109  void read(const char* const register_name, uavcan_register_Value_1_0* const inout_value);
110 
112  void write(const char* const register_name, const uavcan_register_Value_1_0* const value);
113 
117  uavcan_register_Name_1_0 getNameByIndex(const uint16_t index);
118 
120  void doFactoryReset(void);
121 
126  bool assign(uavcan_register_Value_1_0* const dst, const uavcan_register_Value_1_0* const src);
127 
128 protected:
129 private:
130 
131  void _memory_write_block(uint16_t address, uint8_t *data, uint8_t len);
132  void _memory_read_block(uint16_t address, uint8_t *data, uint8_t len);
133  void _memory_write_byte(uint16_t address, uint8_t data);
134  void _memory_read_byte(uint16_t address, uint8_t *data);
135  void _eeprom_register_factory(void);
136  void _eeprom_register_clear(uint8_t reg_numb);
137  size_t _eeprom_register_get_fast(uint8_t reg_numb, uint8_t *reg_name, uint8_t *reg_value);
138  size_t _eeprom_register_get_len_intest_fast(uint8_t reg_numb);
139  void _eeprom_register_get_intest_fast(uint8_t reg_numb, uint8_t *reg_name, uint8_t name_len);
140  bool _eeprom_register_get_name_from_index(uint8_t reg_numb, uint8_t *reg_name);
141  size_t _eeprom_register_get_from_name(uint8_t const *reg_name, uint8_t *reg_numb, uint8_t *data);
142  uint8_t _eeprom_register_get_index_from_name(uint8_t *reg_name);
143  void _eeprom_register_set(uint8_t reg_numb, uint8_t *reg_name, uint8_t *data, size_t len_data);
144  void _eeprom_register_get_next_id(uint8_t *current_register);
145  uint8_t _eeprom_register_add(uint8_t *reg_name, uint8_t *data, size_t data_len);
146 
147  // Private Memory E2prom Object
149 
150 };
151 
152 #endif
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.
Definition: eeprom.h:49
#define EEPROM_AT24C64_DEFAULT_ADDRESS
Definition: eeprom.h:42