commit 1c3c03fa3863f16f6f2c0a3e26df1f81c96140f3 Author: cfif Date: Wed Dec 4 13:10:47 2024 +0300 Init diff --git a/Inc/DeviceStorage.h b/Inc/DeviceStorage.h new file mode 100644 index 0000000..ecf77ce --- /dev/null +++ b/Inc/DeviceStorage.h @@ -0,0 +1,40 @@ +// +// Created by cfif on 07.10.22. +// + +#ifndef STORAGES_H +#define STORAGES_H + +#include "EraGlonassUveos.h" + +#include "DeviceDataNonVolatile.h" +#include "DeviceDataRuntime.h" + +#include "VarsTabDumpObserver.h" + +typedef struct { + tLoggerInterface *logger; + + tDeviceDataRuntime runtime; + tDeviceDataNonVolatile nvm; + + tVariablesTable publicVariablesTable; + + tVarsTabDumpObserver dumpObserver; + + tEraGlonassUveosDumperInterface uveosDumper; + + struct { + tVariableDescriptor vartab[64]; + } mem; + +} tDeviceStorage; + +bool DeviceStorage_Init(tDeviceStorage *env, tStorageInterface *storageInterface); + +//использоввать только для отладки +void DeviceStorage_InitDefaults(tDeviceStorage *env); + +void DeviceStorage_ForceDump(tDeviceStorage *env); + +#endif //STORAGES_H diff --git a/Src/DeviceStorage.c b/Src/DeviceStorage.c new file mode 100644 index 0000000..c9a53e2 --- /dev/null +++ b/Src/DeviceStorage.c @@ -0,0 +1,73 @@ +// +// Created by cfif on 07.10.22. +// + +#include +#include "DeviceStorage.h" +#include "VersionRandID.h" + +#define LOGGER env->logger +#define LOG_SIGN "Хран." + +#define VARIABLE_GROUP_UNTRACKED 0 +#define VARIABLE_GROUP_FLASH (1 << 0) + +void DeviceStorage_InitVariablesTable(tDeviceStorage *env) { + + VariablesTableInitStatic(&env->publicVariablesTable, env->mem.vartab); + + DeviceDataRuntime_InitDefaults(&env->runtime); + + DeviceDataNonVolatile_AddToVarTab(&env->nvm, &env->publicVariablesTable, VARIABLE_GROUP_FLASH); + DeviceDataRuntime_AddToVarTab(&env->runtime, &env->publicVariablesTable, VARIABLE_GROUP_UNTRACKED); +} + +bool DeviceStorage_LoadNonVolatile(tDeviceStorage *env) { + + if (VarsTabDumpObserver_Load(&env->dumpObserver)) { + if (env->nvm.version == DEVICE_DATA_NO_VOLATILE_VERSION) { + return true; + } + } + + DeviceDataNonVolatile_InitDefaults(&env->nvm); + + return VarsTabDumpObserver_Dump(&env->dumpObserver); + +} + +void DeviceStorage_ForceDump(tDeviceStorage *env) { + VarsTabDumpObserver_Dump(&env->dumpObserver); +} + +void DeviceStorage_InitCommon(tDeviceStorage *env, tStorageInterface *storageInterface) { + VarsTabDumpObserver_Init( + &env->dumpObserver, + storageInterface, + 5000, + &env->nvm, + sizeof(env->nvm), + &env->publicVariablesTable, + VARIABLE_GROUP_FLASH + ); + + env->uveosDumper = (tEraGlonassUveosDumperInterface) { + .env = env, + .forceDump = (eraGlonassForceDumpCall) DeviceStorage_ForceDump + }; + + + DeviceStorage_InitVariablesTable(env); +} + +void DeviceStorage_InitDefaults(tDeviceStorage *env) { + DeviceStorage_InitCommon(env, NULL); + DeviceDataNonVolatile_InitDefaults(&env->nvm); +} + +bool DeviceStorage_Init(tDeviceStorage *env, tStorageInterface *storageInterface) { + + DeviceStorage_InitCommon(env, storageInterface); + + return DeviceStorage_LoadNonVolatile(env); +} diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..8b8af70 --- /dev/null +++ b/modular.json @@ -0,0 +1,33 @@ +{ + "dep": [ + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "UveosOnNation_VEGA_DataNonVolatile" + }, + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "UveosOnNation_VEGA_DataRuntime" + }, + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "VarTabDumpObserver" + }, + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "VariablesTable" + } + ], + "cmake": { + "inc_dirs": [ + "Inc/" + ], + "srcs": [ + "Src/**.c", + "Src_InitDefaults/**.c" + ] + } +} \ No newline at end of file