135 lines
3.9 KiB
C
135 lines
3.9 KiB
C
//
|
|
// Created by zemon on 02.06.2022.
|
|
//
|
|
|
|
#ifndef TERMINAL_MOTO_0_0_1_PUBLICVARIABLESTABLE_H
|
|
#define TERMINAL_MOTO_0_0_1_PUBLICVARIABLESTABLE_H
|
|
|
|
#include "stdint.h"
|
|
#include <stdbool.h>
|
|
#include <cmsis_os.h>
|
|
|
|
typedef enum {
|
|
VARIABLE_TYPE_UINT8 = 0x01,
|
|
VARIABLE_TYPE_UINT16 = 0x02,
|
|
VARIABLE_TYPE_STRING = 0x03,
|
|
VARIABLE_TYPE_BOOL = 0x04,
|
|
VARIABLE_TYPE_FLOAT32 = 0x05,
|
|
VARIABLE_TYPE_INT32 = 0x06,
|
|
VARIABLE_TYPE_UINT32 = 0x07,
|
|
VARIABLE_TYPE_INT16 = 0x08,
|
|
VARIABLE_TYPE_INT64 = 0x09,
|
|
VARIABLE_TYPE_ARR_U8_STATIC = 0x0,
|
|
} eVariableTypeId;
|
|
|
|
extern uint8_t variablesTypeLength[];
|
|
|
|
#define VARIABLE_NAME_LENGTH 64
|
|
|
|
typedef struct {
|
|
char *str;
|
|
uint8_t length;
|
|
} tVariableName;
|
|
|
|
#define VARIABLE_NAME(STR) {.str=(STR), .length=sizeof(STR)-1}
|
|
|
|
typedef struct {
|
|
tVariableName name;
|
|
eVariableTypeId typeId;
|
|
void *addr;
|
|
void *len;
|
|
|
|
#ifdef VARIABLE_TABLE_WITH_ID
|
|
uint16_t id;
|
|
uint16_t idUDS;
|
|
uint8_t lenUds;
|
|
uint8_t limit;
|
|
uint32_t begin;
|
|
uint32_t end;
|
|
#endif
|
|
|
|
uint16_t *writeAttempts;
|
|
uint32_t groupMask;//это маска группы изменений (см tVariablesTable)
|
|
} tVariableDescriptor;
|
|
|
|
typedef struct {
|
|
tVariableDescriptor *items;
|
|
uint16_t limit;
|
|
uint16_t count;
|
|
|
|
//все изменени разбиты на группы
|
|
//всего возможно 32 группы соответственно
|
|
//при изменении переменной поднимаеться бит соответствующей группы
|
|
//и изменение можно обработать
|
|
uint32_t changes;
|
|
osMutexId_t writeAccess;
|
|
} tVariablesTable;
|
|
|
|
void VariablesTableInit(tVariablesTable *env, tVariableDescriptor *memAlloc, uint16_t memAllocLimit);
|
|
|
|
#define VariablesTableInitStatic(ENV, MEM) VariablesTableInit(ENV,MEM, sizeof(MEM)/sizeof(tVariableDescriptor))
|
|
|
|
bool VariablesTableAdd(
|
|
tVariablesTable *env,
|
|
char *nameStatic,
|
|
uint8_t nameLength,
|
|
eVariableTypeId type,
|
|
void *addr,
|
|
void *len,
|
|
uint16_t *writeAttempts,
|
|
uint32_t groupMask
|
|
);
|
|
|
|
#ifdef VARIABLE_TABLE_WITH_ID
|
|
|
|
bool VariablesTableWithIdAdd(
|
|
tVariablesTable *env,
|
|
char *nameStatic,
|
|
uint8_t nameLength,
|
|
eVariableTypeId type,
|
|
void *addr,
|
|
void *len,
|
|
uint16_t id,
|
|
uint8_t limit,
|
|
uint16_t *writeAttempts,
|
|
uint32_t groupMask
|
|
);
|
|
|
|
#endif
|
|
|
|
tVariableDescriptor *VariablesTable_GetLast(tVariablesTable *env);
|
|
|
|
tVariableDescriptor *VariablesTable_GetByName(tVariablesTable *env, char *name, uint8_t nameLen);
|
|
|
|
#define VariablesTable_GetByNameStatic(ENV, NAME) VariablesTable_GetByName(ENV, NAME, sizeof(NAME)-1)
|
|
|
|
uint8_t VariablesTable_GetVarLength(tVariableDescriptor *descriptor);
|
|
|
|
uint8_t VariablesTable_GetVarTypeLength(tVariableDescriptor *var);
|
|
|
|
bool VariablesTable_IsVariableChangeAllowed(tVariableDescriptor *var);
|
|
|
|
void VariablesTable_VariableChanged(tVariablesTable *env, tVariableDescriptor *var);
|
|
|
|
bool VariablesTable_RequireChange(tVariablesTable *env, uint32_t timeout);
|
|
|
|
void VariablesTable_ReleaseChange(tVariablesTable *env);
|
|
|
|
bool VariablesTable_TakeChange(tVariablesTable *env, uint32_t groupMask);
|
|
|
|
#ifdef VARIABLE_TABLE_WITH_ID
|
|
bool VariablesTable_SetId_ByName(tVariablesTable *env, char *name, uint8_t nameLen, uint16_t id);
|
|
tVariableDescriptor *VariablesTable_GetById(tVariablesTable *env, uint16_t id);
|
|
|
|
|
|
bool VariablesTable_CheckUDS_ByName(tVariablesTable *env, char *name, uint8_t nameLen);
|
|
#define VariablesTable_CheckUDS_ByNameStatic(ENV, NAME) VariablesTable_CheckUDS_ByName(ENV, NAME, sizeof(NAME)-1)
|
|
|
|
bool VariablesTable_SetIdUDS_ByName(tVariablesTable *env, char *name, uint8_t nameLen, uint16_t id, uint16_t len);
|
|
#define VariablesTable_SetIdUDS_ByNameStatic(ENV, NAME, ID, LEN) VariablesTable_SetIdUDS_ByName(ENV, NAME, sizeof(NAME)-1, ID, LEN)
|
|
|
|
tVariableDescriptor *VariablesTable_GetByIdUDS(tVariablesTable *env, uint16_t id);
|
|
#endif
|
|
|
|
#endif //TERMINAL_MOTO_0_0_1_PUBLICVARIABLESTABLE_H
|