//
// Created by villuton on 16.09.2025.
//
//
// Created by ilya on 18.10.23.
//

#include "DataRuntime.h"
#include "FirmwareMetadataSection.h"

void DataRuntime_InitDefaults(tDeviceDataRuntime *env) {
    env->debugMode = false;
    env->calibration = false;
    env->disallowWrite = 0;
}


#define ADD_VAR_SIZE(TYPE, NAME, VALUE, LEN, GROUP)                         \
    VariablesTableAdd(                                                      \
        variablesTable,                                                     \
        #NAME,                                                              \
        sizeof (#NAME)-1,                                                   \
        VARIABLE_TYPE_##TYPE,                                               \
        (VALUE),                                                            \
        (LEN),                                                              \
        0,                                                                  \
        GROUP                                                               \
    )

#define ADD_VAR(TYPE, NAME, VALUE) ADD_VAR_SIZE(TYPE, NAME, VALUE, 0, VARIABLES_GROUP)
#define ADD_VAR_STR_OBJ(TYPE, NAME, VALUE) ADD_VAR_SIZE(TYPE, NAME, &(VALUE).data, &(VALUE).length,VARIABLES_GROUP)

//  Добавление переменных в таблицу
void DataRuntime_AddToVarTab(
        tDeviceDataRuntime *env,
        tVariablesTable *variablesTable,
        uint32_t VARIABLES_GROUP
) {
    ADD_VAR(BOOL, DEBUG_MODE, &env->debugMode);
    ADD_VAR(BOOL, DEBUG_MODE, &env->calibration);

    VariablesTable_GetLast(variablesTable)->writeAttempts = &env->disallowWrite;
}

#undef ADD_VAR_SIZE
#undef ADD_VAR
#undef ADD_VAR_STR_OBJ