#ifndef PROTOCOLDEFS_H
#define PROTOCOLDEFS_H


#define MODBUS_ZT_WATCHDOG_TIMEOUT 3000
#define MODBUS_CC_WATCHDOG_TIMEOUT 3000

#define MODBUS_SEI_WATCHDOG_TIMEOUT 1000

//ZT - CC modbus table masks

//Flags definitions for HR2000
#define ZT1_PP_INT_FLAG_MASK_1    0x0001
#define ZT1_PP_INT_FLAG_MASK_2    0x0002
#define ZT1_PP_INT_FLAG_MASK_3    0x0004
#define ZT1_PP_INT_FLAG_MASK_4    0x0008
#define ZT1_PP_EXT_FLAG_MASK_1    0x0010
#define ZT1_PP_EXT_FLAG_MASK_2    0x0020
#define ZT1_PP_EXT_FLAG_MASK_3    0x0040
#define ZT1_PP_EXT_FLAG_MASK_4    0x0080
#define ZT1_PG_FLAG_MASK_1        0x0100
#define ZT1_PG_FLAG_MASK_2        0x0200
#define ZT1_PG_FLAG_MASK_3        0x0400
#define ZT1_PG_FLAG_MASK_4        0x0800
#define ZT1_FN_FLAG_MASK_1        0x1000
#define ZT1_FN_FLAG_MASK_2        0x2000
#define ZT1_FN_FLAG_MASK_3        0x4000
#define ZT1_FN_FLAG_MASK_4        0x8000

//Flags definitions for HR2017
#define ZT2_PP_INT_FLAG_MASK_1    0x0001
#define ZT2_PP_INT_FLAG_MASK_2    0x0002
#define ZT2_PP_INT_FLAG_MASK_3    0x0004
#define ZT2_PP_INT_FLAG_MASK_4    0x0008
#define ZT2_PP_EXT_FLAG_MASK_1    0x0010
#define ZT2_PP_EXT_FLAG_MASK_2    0x0020
#define ZT2_PP_EXT_FLAG_MASK_3    0x0040
#define ZT2_PP_EXT_FLAG_MASK_4    0x0080
                                            ///UNUSED FLAGS NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define ZT2_PG_DUMMY_MASK_1       0x0100    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define ZT2_PG_DUMMY_MASK_2       0x0200    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define ZT2_PG_DUMMY_MASK_3       0x0400    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define ZT2_PG_DUMMY_MASK_4       0x0800    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define ZT2_FN_DUMMY_MASK_5       0x1000    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define ZT2_FN_DUMMY_MASK_6       0x2000    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define ZT2_FN_DUMMY_MASK_7       0x4000    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define ZT2_FV_DUMMY_MASK_8       0x8000    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
                                            ////////////////////////////////////////////////////////////////////

//Flags definitions for HR2026
#define ZT1_V00_ALARM_FLAG_MASK   0x0001
#define ZT1_PEQ1_ALARM_FLAG_MASK  0x0002
#define ZT2_V02_ALARM_FLAG_MASK   0x0004
#define ZT2_PEQ2_ALARM_FLAG_MASK  0x0008
#define ZT2_ALARM_ITI_DUMMY_FLAG_MASK   0x4000 //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define ZT1_ALARM_ITI_FLAG_MASK   0x8000

//#define MODBUS_CC_AN1_FLAG_MASK        0x0002
//#define MODBUS_CC_AN2_FLAG_MASK        0x0001
//#define MODBUS_CC_AN_UNUSED_INVALID_MASK 0xFFFC
//#define MODBUS_CC_CLOCK_UPDATE_FLAG_MASK 0x0001
//#define MODBUS_CC_CLK_UNUSED_INV_MASK  0xFFFE



//Register addressing
//incoming
#define MODBUS_ZT_DATA_BASE_REG             2000
#define MODBUS_ZT_TABLE_DATA_SIZE           36      //Taille de la table = 36 registres

#define MODBUS_ZT1_ALARM_DATA_BASE_REG_ADD  2000
#define MODBUS_ZT2_ALARM_DATA_BASE_REG_ADD  2017
#define MODBUS_MISC_DATA_BASE_REG_ADD       2026
#define MODBUS_ZT_WATCHDOG_REG_ADD          2027

#define MODBUS_ZT1_ALARM_RANKS_BASE_ADD     2001
#define MODBUS_ZT1_RANK_PP_INT_1_REG_ADD    2001
#define MODBUS_ZT1_RANK_PP_INT_2_REG_ADD    2002
#define MODBUS_ZT1_RANK_PP_INT_3_REG_ADD    2003
#define MODBUS_ZT1_RANK_PP_INT_4_REG_ADD    2004
#define MODBUS_ZT1_RANK_PP_EXT_1_REG_ADD    2005
#define MODBUS_ZT1_RANK_PP_EXT_2_REG_ADD    2006
#define MODBUS_ZT1_RANK_PP_EXT_3_REG_ADD    2007
#define MODBUS_ZT1_RANK_PP_EXT_4_REG_ADD    2008
#define MODBUS_ZT1_RANK_PG_1_REG_ADD        2009
#define MODBUS_ZT1_RANK_PG_2_REG_ADD        2010
#define MODBUS_ZT1_RANK_PG_3_REG_ADD        2011
#define MODBUS_ZT1_RANK_PG_4_REG_ADD        2012
#define MODBUS_ZT1_RANK_FN_1_REG_ADD        2013
#define MODBUS_ZT1_RANK_FN_2_REG_ADD        2014
#define MODBUS_ZT1_RANK_FN_3_REG_ADD        2015
#define MODBUS_ZT1_RANK_FN_4_REG_ADD        2016

#define MODBUS_ZT2_ALARM_RANKS_BASE_ADD     2018
#define MODBUS_ZT2_RANK_PP_INT_1_REG_ADD    2018
#define MODBUS_ZT2_RANK_PP_INT_2_REG_ADD    2019
#define MODBUS_ZT2_RANK_PP_INT_3_REG_ADD    2020
#define MODBUS_ZT2_RANK_PP_INT_4_REG_ADD    2021
#define MODBUS_ZT2_RANK_PP_EXT_1_REG_ADD    2022
#define MODBUS_ZT2_RANK_PP_EXT_2_REG_ADD    2023
#define MODBUS_ZT2_RANK_PP_EXT_3_REG_ADD    2024
#define MODBUS_ZT2_RANK_PP_EXT_4_REG_ADD    2025
                                                    //UNUSED FLAGS NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define MODBUS_ZT2_DUMMY_RK_PG_1_REG_ADD    2028    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define MODBUS_ZT2_DUMMY_RK_PG_2_REG_ADD    2029    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define MODBUS_ZT2_DUMMY_RK_PG_3_REG_ADD    2030    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define MODBUS_ZT2_DUMMY_RK_PG_4_REG_ADD    2031    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define MODBUS_ZT2_DUMMY_FN_PG_1_REG_ADD    2032    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define MODBUS_ZT2_DUMMY_FN_PG_2_REG_ADD    2033    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define MODBUS_ZT2_DUMMY_FN_PG_3_REG_ADD    2034    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
#define MODBUS_ZT2_DUMMY_FN_PG_4_REG_ADD    2035    //UNUSED FLAG NECESSARY FOR CC IMPLEMENTATION.  MUST ALWAYS BE 0
                                                    ///////////////////////////////////////////////////////////////////



//Outgoing
#define MODBUS_CC_FCYCLE_ZT1_FLAG_MASK     0x0001
#define MODBUS_CC_FCYCLE_ZT2_FLAG_MASK     0x0002
#define MODBUS_CC_INHIBIT_ZT1_FLAG_MASK  0x0004
#define MODBUS_CC_INHIBIT_ZT2_FLAG_MASK  0x0008
#define MODBUS_CC_CLK_UPDATE_FLAG_MASK   0x8000

#define MODBUS_CC_DATA_BASE_REG_ADD         2036
#define MODBUS_CC_TABLE_DATA_SIZE           15      //Taille de la table en écriture = 15 registres (2028 à 2042)


#define MODBUS_CC_WATCHDOG_BASE_REG_ADD     2036 //2028
#define MODBUS_CC_AN_BASE_REG_ADD           2037 //2029
#define MODBUS_CC_ZT1_TRAIN_TYPE_REG_ADD    2038 //2030
#define MODBUS_CC_ZT2_TRAIN_TYPE_REG_ADD    2039 //2031
#define MODBUS_CC_ZT1_TRAIN_ID_1_REG_ADD    2040//2032
#define MODBUS_CC_ZT1_TRAIN_ID_2_REG_ADD    2041 //2033
#define MODBUS_CC_ZT1_TRAIN_ID_3_REG_ADD    2042 //2034
#define MODBUS_CC_ZT2_TRAIN_ID_1_REG_ADD    2043 //2035
#define MODBUS_CC_ZT2_TRAIN_ID_2_REG_ADD    2044 //2036
#define MODBUS_CC_ZT2_TRAIN_ID_3_REG_ADD    2045 //2037
#define MODBUS_CC_CLK_UPDATE_BASE_REG_ADD   2046 //2038
#define MODUBS_CC_CLK_SEC_BASE_REG_ADD      2047 //2039
#define MODUBS_CC_CLK_HR_MIN_BASE_REG_ADD   2048 //2040
#define MODUBS_CC_CLK_MNT_DAY_BASE_REG_ADD  2049 //2041
#define MODUBS_CC_CLK_YEAR_BASE_REG_ADD     2050 //2042



#define SEI_MODBUS_ZT_DATA_BASE_REG  2000
#define SEI_MODBUS_ZT_TABLE_DATA_SIZE 28

#define SEI_MODBUS_SEI_DATA_BASE_REG  2037
#define SEI_MODBUS_SEI_TABLE_DATA_SIZE 2

#define SEI_MODBUS_ZT_WATCHDOG_REG  2027
#define SEI_MODBUS_SEI_WATCHDOG_REG 2038
#define SEI_MODBUS_SEI_WATCHDOG_MASK 0x0001

#define SEI_MODBUS_SEI_ALARMS_RESET_REG 2037
#define SEI_MODBUS_SEI_ZT1_ALARM_RESET_MASK 0X0001
#define SEI_MODBUS_SEI_ZT2_ALARM_RESET_MASK 0X0002



#endif // PROTOCOLDEFS_H
