/*
 * vtable.h
 *
 *  Created on: Jun 25, 2025
 *      Author: jim
 */

#ifndef VTABLE_H_
#define VTABLE_H_

// JLD-TGM  string variables - user defined max length is assumed to be low.  128 is a guess.
#define MAX_STRING_VAR_LEN  128

typedef enum eVarType
{
    eNone,
    eInt8,
    eInt16,
    eInt32,
    eUInt32,
    eFloat,
    eFloatA,
    eDouble,
    eString
} eVarType;

extern char *typeNameStrs[];
typedef union uVDataPtr
{
    void        *v;
    uint8_t     *i8;
    int16_t     *i16;
    int32_t     *i32;
    int32_t     *u32;
    float       *flt;
    double      *dbl;
    char        *str;
} uVDataPtr;

typedef union uDataPtr
{
    void        *v;
    uint8_t     *i8;
    int16_t     *i16;
    int32_t     *i32;
    uint32_t    *u32;
    float       *flt;
    double      *dbl;
    char        *str;
    int        (*func)(void *);    // verify function
} uDataPtr;

typedef union uValue
{
    uint8_t     B8;
    int16_t     I16;
    int32_t     I32;
    uint32_t    U32;
    float       Flt;
    double      Dbl;
    char *      Str;
} uValue;

typedef enum eVarFlags
{
    fACKRequired = 1,
    fACKStart = 2,
    fACKAdd = 4,
    fACKEnd = 8,
    fSetIfHigh = 16,
    fEEPStore = 32,
    fAEEPStore = 64,
    fAArrayStore = 128,
    fAVarsStore = 256,
    fVerifyFn = 512
} eVarFlags;

typedef struct tVarEntry
{
    char        *symbol;
    char        fieldVar;
    eVarType    type;
    uValue      min;
    uValue      max;
    uDataPtr    dP;
    int         gap;
    uDataPtr    dP2;
    int         flag;
}tVarEntry;

#define MINRTC      1727464426
#define MAXRTC      4000000000
#define MIN_TEMP    -10.0
#define MAX_TEMP    35.0
#define MIN_SALT    -0.25
#define MAX_SALT    40.0
#define MIN_PRES    -200.0
#define MAX_PRES    5000

#define FLT_MIN     -1.0E24
#define FLT_MAX     +1.0E24

#define MIN_TINT    100
#define MAX_TINT    2500
#define MAX_K2_IDX  MAX_NUMOF_K2_CAL_FIELDS
#define MAX_FP_IDX  MAX_NUMOF_FP_CAL_FIELDS

// For additive calls to varValueSet
extern char ackAccumulatorStr [64];
extern uint32_t tempUInt;


extern int varValueSet(tVarEntry *var, char *strptr);

extern int setDataVar(void);
// serial command calls
extern void cmd_set_var(void);
extern void cmd_get_var(void);
extern void cmd_show_vars(void);

extern void showVar(tVarEntry *varP);
extern tVarEntry *findVar(char *lookup);
extern tVarEntry *findVarField(char *lookup, char fieldLookup);

#endif /* VTABLE_H_ */
