* introduced identifiers (include shell commands to get and set)
* introduced a system wide configurationdev/timer
parent
5ebbd2c92e
commit
a46cdf189a
@ -0,0 +1,8 @@
|
||||
#include <stdint.h>
|
||||
#include <config.h>
|
||||
#include <flashrom.h>
|
||||
|
||||
uint8_t config_save(void) {
|
||||
configmem_t mem = { CONFIG_KEY, sysconfig };
|
||||
return (flashrom_erase((uint32_t) configmem) && flashrom_write((uint32_t) configmem, (char*) &mem, sizeof(mem)));
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define CONFIG_KEY (0x1701)
|
||||
|
||||
extern char configmem[];
|
||||
|
||||
/* @brief: Stores configuration data of the node */
|
||||
typedef struct {
|
||||
uint16_t id; ///< unique node identifier
|
||||
uint8_t radio_address; ///< address for radio communication
|
||||
uint8_t radio_channel; ///< current frequency
|
||||
} config_t;
|
||||
|
||||
/* @brief: Element to store in flashrom */
|
||||
typedef struct {
|
||||
uint16_t magic_key; ///< validity check
|
||||
config_t config; ///< the node's configuration
|
||||
} configmem_t;
|
||||
|
||||
extern config_t sysconfig;
|
||||
|
||||
uint8_t config_save(void);
|
||||
|
||||
#endif /* CONFIG_H */
|
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <config.h>
|
||||
|
||||
void _id_handler(char *id) {
|
||||
uint16_t newid;
|
||||
|
||||
if (sscanf(id, "id %hu", &newid) == 1) {
|
||||
printf("Setting new id %u\n", newid);
|
||||
sysconfig.id = newid;
|
||||
if (!config_save()) {
|
||||
puts("ERROR setting new id");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Current id: %u\n", sysconfig.id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue