For fetching configuration files from the original project, do
cd xml; make fetch_from_original_nbfc
For translating them to JSON, do
cd xml; make transform_to_json
For chaining error messages, there is a Error error_stack[16];
.
Errors can be strings, integers or error codes belonging to an error system.
enum ErrorSystem {
ErrorSystem_String,
ErrorSystem_Integer,
ErrorSystem_Stdlib,
ErrorSystem_NxJson,
#ifdef HAVE_SENSORS
ErrorSystem_Sensors,
#endif
};
typedef struct Error Error;
struct Error {
enum ErrorSystem system;
union {
int code;
const char* message;
} value;
};
The return value of functions is either an poiinter to error_stack
or NULL
(no error).
There are two memory pools:
Memory MemoryMain;
Memory MemoryTemp;
Two kinds of macros are defined in memory.h:
#define Mem_AddPool(BUF, SIZE) Memory_AddPool(&MemoryMain, BUF, SIZE)
#define Mem_Malloc(NMEMB, SIZE) Memory_Malloc(&MemoryMain, NMEMB, SIZE)
#define Mem_Calloc(NMEMB, SIZE) Memory_Calloc(&MemoryMain, NMEMB, SIZE)
#define Mem_Strdup(CHARS) Memory_Strdup(&MemoryMain, CHARS)
#define Temp_Reset() Memory_Reset(&MemoryTemp)
#define Temp_AddPool(BUF, SIZE) Memory_AddPool(&MemoryTemp, BUF, SIZE)
#define Temp_Malloc(NMEMB, SIZE) Memory_Malloc(&MemoryTemp, NMEMB, SIZE)
#define Temp_Calloc(NMEMB, SIZE) Memory_Calloc(&MemoryTemp, NMEMB, SIZE)
#define Temp_Strdup(CHARS) Memory_Strdup(&MemoryTemp, CHARS)
The Mem_-functions are for persistent allocations, the Temp_-functions are for
temporary allocations. Those allocations are reset by Temp_Reset
in the Service_Loop
.
We use the my
macro defined in macros.h
as a shortcut for (*self)
.
static Error* Fan_ECWriteValue(Fan* self, int value) {
return my.readWriteWords
? ec->WriteWord(my.fanConfig->WriteRegister, value)
: ec->WriteByte(my.fanConfig->WriteRegister, value);
}
The code for parsing JSON and validating the configuration values is generated by tools/config.py
.
src/generated/model_config.generated.c
src/generated/model_config.generated.h