#ifndef APP_H
#define APP_H

#include "common.h"

//=========================== defines =========================================

//==== APP return codes
#define APP_OK                    0
#define APP_NOUPDATE              1
#define APP_ERROR                 2

//==== common tables HCF_SPEC-183 (the rest is in hart_lib.c)

// Table 2: Unit codes
#define HART2_UNIT_kPa            12
#define HART2_UNIT_Celsius        32
#define HART2_UNIT_mA             39
#define HART2_UNIT_Days           53
#define HART2_UNIT_PerCent        57
#define HART2_UNIT_Volt           58
#define HART2_UNIT_g              170     // gravital acceleration
#define HART2_UNIT_NOT_USED       250
#define HART2_UNIT_NONE           251

// Table 21: Device variable classification codes
#define HART21_CLASS_NONE         0
#define HART21_CLASS_TEMPERATURE  64
#define HART21_CLASS_PRESSURE     65
#define HART21_CLASS_EMF          83 // electromotive force
#define HART21_CLASS_ACCELERATION 96 
#define HART21_CLASS_MISC         111 

// Table 34: Device variable codes
#define HART34_VARCODE_BAT_VOLTAGE   242
#define HART34_VARCODE_BAT_LIFE      243
#define HART34_VARCODE_PERCENT       244
#define HART34_VARCODE_LOOP_CURRENT  245
#define HART34_VARCODE_PRIMARY       246
#define HART34_VARCODE_SECONDARY     247
#define HART34_VARCODE_TERTIARY      248
#define HART34_VARCODE_QUATERNARY    249
#define HART34_VARCODE_NOT_USED      250

// Table A-3: Device variable status
#define HARTA3_PROCESS_GOOD         0xC0
#define HARTA3_PROCESS_FIXED        0x80
#define HARTA3_PROCESS_POOR         0x40
#define HARTA3_PROCESS_BAD          0x00
#define HARTA3_LIMIT_CONSTANT       0x30
#define HARTA3_LIMIT_HIGH           0x20
#define HARTA3_LIMIT_LOW            0x10
#define HARTA3_LIMIT_NO             0x00
#define HARTA3_MORE_STATUS          0x04
#define HARTA3_DEVICE_SPECIFIC      0x00
                                    
//=========================== typedef =========================================

typedef struct
{
		float   value;
	  const float   min;
	  const float   max;
		uint8_t unit;           // HCF_SPEC-183, Table 2
		uint8_t classification;	// HCF_SPEC-183, Table 21
		bool    newData;        // flag
		bool    isOffLimits; 
	  bool    enabled;
	  uint8_t status;         // HCF_SPEC-183, Table A-3
} app_deviceVar_t;

//=========================== prototype =======================================

//==== app
int16_t               app_enableMeasurement(uint8_t varNum, bool enable);
app_deviceVar_t*      app_getDeviceVar(uint8_t varNum);

#endif

