//
// Created by villuton on 16.09.2025.
//
#include "DataFlashPrivate.h"

#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, group)
#define ADD_VAR_STR_OBJ(TYPE, NAME, VALUE) ADD_VAR_SIZE(TYPE, NAME, &(VALUE).data, &(VALUE).length,group)

//  Добавление переменных в таблицу
void DataFlash_AddToVarTab(
        tDeviceDataNonVolatile *env,
        tVariablesTable *variablesTable,
        uint32_t group
) {
//Devices
    ADD_VAR_STR_OBJ(STRING, DEVICE_ID, env->device.serialNumber.value);
    VariablesTable_GetLast(variablesTable)->writeAttempts = &env->device.serialNumber.writeAccess;

    ADD_VAR(FLOAT32, VOLTAGE_REFERENCE, &env->device.vReference);
    ADD_VAR(FLOAT32, DEVIDER_RATIO, &env->device.dividerRatio);
    ADD_VAR(FLOAT32, VOLTAGE_BAT_CONNECT, &env->device.voltageBatteryConnectThreshold);
    ADD_VAR(FLOAT32, VOLTAGE_BAT_LOADED, &env->device.voltageBatteryLoadedThreshold);

    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH1, &env->device.chanelCalibrationFactor[CHRG_Ch1]);
    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH2, &env->device.chanelCalibrationFactor[CHRG_Ch2]);
    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH3, &env->device.chanelCalibrationFactor[CHRG_Ch3]);
    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH4, &env->device.chanelCalibrationFactor[CHRG_Ch4]);
    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH5, &env->device.chanelCalibrationFactor[CHRG_Ch5]);
    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH6, &env->device.chanelCalibrationFactor[CHRG_Ch6]);
    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH7, &env->device.chanelCalibrationFactor[CHRG_Ch7]);
    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH8, &env->device.chanelCalibrationFactor[CHRG_Ch8]);
    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH9, &env->device.chanelCalibrationFactor[CHRG_Ch9]);
    ADD_VAR(FLOAT32, CALIBRAION_FACTOR_CH10, &env->device.chanelCalibrationFactor[CHRG_Ch10]);

}



#undef ADD_VAR_SIZE
#undef ADD_VAR
#undef ADD_VAR_STR_OBJ
