//#############################################################################################################################################################################################################
#ifndef _INC_IDIBUS_DEFS_H_
#define _INC_IDIBUS_DEFS_H_
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <inttypes.h>

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define F_CPU 16000000UL
#define	MODBUS_CRC16_SIZE			2
#define	CRC32_SIZE					4
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define IDIBUS_BAUDRATE_DSW_CODE_19200B						0x00
#define IDIBUS_BAUDRATE_DSW_CODE_500K						0x01
#define IDIBUS_BAUDRATE_DSW_CODE_2400B						0x02
#define IDIBUS_BAUDRATE_DSW_CODE_9600B						0x03
#define IDIBUS_BAUDRATE_DSW_CODE_115200B					0x04
#define IDIBUS_BAUDRATE_DSW_CODE_250K						0x05
#define IDIBUS_BAUDRATE_DSW_CODE_1M							0x06
#define IDIBUS_BAUDRATE_DSW_CODE_10M						0x07

// Full timeout will be (InterframeTimeout + ResponseTimeout) for request(Write + Read) or InterframeTimeout for write(Write only)
#define IDIBUS_2400B_INTERFRAME_TIMEOUT_US					16042ULL		//11 * 3.5 / Baudrate
#define IDIBUS_9600B_INTERFRAME_TIMEOUT_US					4011ULL
#define IDIBUS_19200B_INTERFRAME_TIMEOUT_US					2006ULL
#define IDIBUS_115200B_INTERFRAME_TIMEOUT_US				1750ULL
#define IDIBUS_250K_INTERFRAME_TIMEOUT_US					1750ULL
#define IDIBUS_500K_INTERFRAME_TIMEOUT_US					1750ULL
#define IDIBUS_1M_INTERFRAME_TIMEOUT_US						1750ULL
#define IDIBUS_10M_INTERFRAME_TIMEOUT_US					1750ULL

#define IDIBUS_2400B_ALARM_TIMEOUT_US						34375ULL		//11 * 3.5 / Baudrate
#define IDIBUS_9600B_ALARM_TIMEOUT_US						8594ULL
#define IDIBUS_19200B_ALARM_TIMEOUT_US						4297ULL
#define IDIBUS_115200B_ALARM_TIMEOUT_US						1750ULL
#define IDIBUS_250K_ALARM_TIMEOUT_US						1750ULL
#define IDIBUS_500K_ALARM_TIMEOUT_US						1750ULL
#define IDIBUS_1M_ALARM_TIMEOUT_US							1750ULL
#define IDIBUS_10M_ALARM_TIMEOUT_US							1750ULL

#define IDIBUS_2400B_MASTER_RESPONSE_TIMEOUT_US				(IDIBUS_2400B_INTERFRAME_TIMEOUT_US   * 3 / 2 )
#define IDIBUS_9600B_MASTER_RESPONSE_TIMEOUT_US				(IDIBUS_9600B_INTERFRAME_TIMEOUT_US   * 3 / 2 )
#define IDIBUS_19200B_MASTER_RESPONSE_TIMEOUT_US			(IDIBUS_19200B_INTERFRAME_TIMEOUT_US  * 3 / 2 )
#define IDIBUS_115200B_MASTER_RESPONSE_TIMEOUT_US			(IDIBUS_115200B_INTERFRAME_TIMEOUT_US * 3 / 2 )
#define IDIBUS_250K_MASTER_RESPONSE_TIMEOUT_US				(IDIBUS_250K_INTERFRAME_TIMEOUT_US    * 3 / 2 )
#define IDIBUS_500K_MASTER_RESPONSE_TIMEOUT_US				(IDIBUS_500K_INTERFRAME_TIMEOUT_US    * 3 / 2 )
#define IDIBUS_1M_MASTER_RESPONSE_TIMEOUT_US				(IDIBUS_1M_INTERFRAME_TIMEOUT_US      * 3 / 2 )
#define IDIBUS_10M_MASTER_RESPONSE_TIMEOUT_US				(IDIBUS_10M_INTERFRAME_TIMEOUT_US     * 3 / 2 )

#define IDIBUS_2400B_SLAVE_RESPONSE_TIMEOUT_US				(IDIBUS_2400B_INTERFRAME_TIMEOUT_US  )
#define IDIBUS_9600B_SLAVE_RESPONSE_TIMEOUT_US				(IDIBUS_9600B_INTERFRAME_TIMEOUT_US  )
#define IDIBUS_19200B_SLAVE_RESPONSE_TIMEOUT_US				(IDIBUS_19200B_INTERFRAME_TIMEOUT_US )
#define IDIBUS_115200B_SLAVE_RESPONSE_TIMEOUT_US			(IDIBUS_115200B_INTERFRAME_TIMEOUT_US)
#define IDIBUS_250K_SLAVE_RESPONSE_TIMEOUT_US				(IDIBUS_250K_INTERFRAME_TIMEOUT_US   )
#define IDIBUS_500K_SLAVE_RESPONSE_TIMEOUT_US				(IDIBUS_500K_INTERFRAME_TIMEOUT_US   )
#define IDIBUS_1M_SLAVE_RESPONSE_TIMEOUT_US					(IDIBUS_1M_INTERFRAME_TIMEOUT_US     )
#define IDIBUS_10M_SLAVE_RESPONSE_TIMEOUT_US				(IDIBUS_10M_INTERFRAME_TIMEOUT_US    )


enum IDIBUS_SERIAL_BAUDRATE {
	IDIBUS_BAUDRATE_2400   = IDIBUS_BAUDRATE_DSW_CODE_2400B,
	IDIBUS_BAUDRATE_9600   = IDIBUS_BAUDRATE_DSW_CODE_9600B,
	IDIBUS_BAUDRATE_19200  = IDIBUS_BAUDRATE_DSW_CODE_19200B,
	IDIBUS_BAUDRATE_115200 = IDIBUS_BAUDRATE_DSW_CODE_115200B,
	IDIBUS_BAUDRATE_250K   = IDIBUS_BAUDRATE_DSW_CODE_250K,
	IDIBUS_BAUDRATE_500K   = IDIBUS_BAUDRATE_DSW_CODE_500K,
	IDIBUS_BAUDRATE_1M     = IDIBUS_BAUDRATE_DSW_CODE_1M,
	IDIBUS_BAUDRATE_10M    = IDIBUS_BAUDRATE_DSW_CODE_10M
	};

#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_SEC				60U
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_MS				( IDIBUS_LINK_LED_NO_MMES_TIMEOUT_0_SEC * 1000U )
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_SEC				15U
#define IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_MS				( IDIBUS_LINK_LED_NO_MMES_TIMEOUT_1_SEC * 1000U )

enum IDIBUS_RXTIMER_TIMEOUT_MODE {
	IDIBUS_TIMER_MODE_RX_TIMEOUT = 0x00,
	IDIBUS_TIMER_MODE_ALARM_TIMEOUT,
	IDIBUS_TIMER_MODE_RESPONSE_TIMEOUT
};
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
#define IDISN_FIXP_Pos										1U	//Internal padding
#define IDISN_FIXP_GS1_COUNTRY_Pos							( IDISN_FIXP_Pos + 0U)
#define IDISN_FIXP_GS1_COUNTRY_Length						3
#define IDISN_FIXP_GS1_COMPANY_Pos							( IDISN_FIXP_GS1_COUNTRY_Pos + IDISN_FIXP_GS1_COUNTRY_Length )
#define IDISN_FIXP_GS1_COMPANY_Length						6
#define IDISN_FIXP_MODULE_TYPE_Pos							( IDISN_FIXP_GS1_COMPANY_Pos + IDISN_FIXP_GS1_COMPANY_Length )
#define IDISN_FIXP_MODULE_TYPE_Length						3
#define IDISN_FIXP_HW_REV_Pos								( IDISN_FIXP_MODULE_TYPE_Pos + IDISN_FIXP_MODULE_TYPE_Length )
#define IDISN_FIXP_HW_REV_Length							2
#define IDISN_FIXP_SERIAL_Pos								( IDISN_FIXP_HW_REV_Pos + IDISN_FIXP_HW_REV_Length )
#define IDISN_FIXP_SERIAL_Length							7
#define IDISN_FIXP_MAC_Pos									( IDISN_FIXP_SERIAL_Pos + IDISN_FIXP_SERIAL_Length )
#define IDISN_FIXP_MAC_Length								6
#define IDISN_FIXP_SW_REV_Pos								( IDISN_FIXP_MAC_Pos + IDISN_FIXP_MAC_Length )
#define IDISN_FIXP_SW_REV_Length							2	
#define IDISN_FIXP_LENGTH									( IDISN_FIXP_GS1_COUNTRY_Length + IDISN_FIXP_GS1_COMPANY_Length + IDISN_FIXP_MODULE_TYPE_Length + \
															  IDISN_FIXP_HW_REV_Length + IDISN_FIXP_SERIAL_Length + IDISN_FIXP_MAC_Length + IDISN_FIXP_SW_REV_Length )

#define IDISN_VARP_Pos										0	//IDISN_FIXP_LENGTH
#define IDISN_VARP_VERIF_DATE_Pos							( IDISN_VARP_Pos )
#define IDISN_VARP_VERIF_DATE_Length						4U
#define IDISN_VARP_EXPIR_DATE_Pos							( IDISN_VARP_VERIF_DATE_Pos + IDISN_VARP_VERIF_DATE_Length )
#define IDISN_VARP_EXPIR_DATE_Length						4U
#define IDISN_VARP_IPv4_Pos									( IDISN_VARP_EXPIR_DATE_Pos + IDISN_VARP_EXPIR_DATE_Length )
#define IDISN_VARP_IPv4_Length								4U
#define IDISN_VARP_IPv6_Pos									( IDISN_VARP_IPv4_Pos + IDISN_VARP_IPv4_Length )
#define IDISN_VARP_IPv6_Length								16U
#define IDISN_VARP_AES256_Pos								( IDISN_VARP_IPv6_Pos + IDISN_VARP_IPv6_Length )
#define IDISN_VARP_AES256_Length							32U
#define IDISN_VARP_LENGTH									( IDISN_VARP_VERIF_DATE_Length + IDISN_VARP_EXPIR_DATE_Length + \
														  	  IDISN_VARP_IPv4_Length + IDISN_VARP_IPv6_Length + IDISN_VARP_AES256_Length )

#define IDISN_FULL_LENGTH									( IDISN_FIXP_LENGTH + IDISN_VARP_LENGTH )
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
#define ISIBUS_MASTER_MAIN_ADDR								255U
#define ISIBUS_MASTER_SPARE_ADDR							254U
#define IDIBUS_SLAVE_ADDR_MIN								1U
#define IDIBUS_SLAVE_ADDR_MAX								229U
#define IDIBUS_DEVELOPER_ADDR_0								250U
#define IDIBUS_DEVELOPER_ADDR_1								251U
#define IDIBUS_DEVELOPER_ADDR_2								252U
#define IDIBUS_DEVELOPER_ADDR_3								253U
#define IDIBUS_GROUP_0_ADDR									230U
#define IDIBUS_GROUP_1_ADDR									231U
#define IDIBUS_GROUP_2_ADDR									232U
#define IDIBUS_GROUP_3_ADDR									233U
#define IDIBUS_GROUP_4_ADDR									234U
#define IDIBUS_GROUP_5_ADDR									235U
#define IDIBUS_GROUP_6_ADDR									236U
#define IDIBUS_GROUP_7_ADDR									237U
#define IDIBUS_GROUP_8_ADDR									238U
#define IDIBUS_GROUP_9_ADDR									239U
#define IDIBUS_GROUP_10_ADDR								240U
#define IDIBUS_GROUP_11_ADDR								241U
#define IDIBUS_GROUP_12_ADDR								242U
#define IDIBUS_GROUP_13_ADDR								243U
#define IDIBUS_GROUP_14_ADDR								244U
#define IDIBUS_GROUP_15_ADDR								245U

#define IDIBUS_GROUPS_NUMBER								16U
#define IDIBUS_GROUP_FIRST_NUMBER							0U
#define IDIBUS_GROUP_LAST_NUMBER							15U
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
#define IDIMMES_ADDR_Pos									00U
#define IDIMMES_MMPS_Pos									01U
#define IDIMMES_MMPS_LONG_MES_Pos							0U
#define IDIMMES_MMPS_LONG_MES_Msk							0x01U
#define IDIMMES_MMPS_MES_TYPE_Pos							1U
#define IDIMMES_MMPS_MES_TYPE_Msk							0x02U
#define IDIMMES_MMPS_MES_TYPE_MMES							0x00U
#define IDIMMES_MMPS_MES_TYPE_MMESG							0x01U
#define IDIMMES_MMPS_FAST_FUNC_Pos							2U
#define IDIMMES_MMPS_FAST_FUNC_Msk							0x3CU
#define IDIMMES_MMPS_ALARM_FRAME_Pos						6U
#define IDIMMES_MMPS_ALARM_FRAME_Msk						0x40U
#define IDIMMES_MMPS_ENCRYPTED_AES_Pos						7U
#define IDIMMES_MMPS_ENCRYPTED_AES_Msk						0x80U
#define IDIMMES_DEV_Pos										02U
#define IDIMMES_DEV_NUM_Pos									0U
#define IDIMMES_DEV_NUM_Msk									0x1FU
#define IDIMMES_DEV_ALLCH_Pos								5U
#define IDIMMES_DEV_ALLCH_Msk								0x20U
#define IDIMMES_CHNL_Pos									03U
#define IDIMMES_CHNL_NUM_Pos								0U
#define IDIMMES_CHNL_NUM_Msk								0x7FU
#define IDIMMES_CHNL_ALLSAME_Pos							7U
#define IDIMMES_CHNL_ALLSAME_Msk							0x80U
#define IDIMMES_DATA_FUNC_COM_DATA_Pos						04U
#define IDIMMES_MAX_HEADER_LENGTH							(IDIMMES_DATA_FUNC_COM_DATA_Pos + 1)
#define IDIMMES_MAX_DATA_SIZE								256U
#define IDIMMES_MAX_MES_SIZE								(IDIMMES_MAX_DATA_SIZE + IDIMMES_MAX_HEADER_LENGTH + MODBUS_CRC16_SIZE)
#define IDIMMES_MIN_MES_SIZE								(IDIMMES_DATA_FUNC_COM_DATA_Pos + MODBUS_CRC16_SIZE)

#define IDIMMESG_DATA_COM_FUNC_Pos							02U
#define IDIMMESG_MAX_HEADER_LENGTH							(IDIMMESG_DATA_COM_FUNC_Pos + 1)
#define IDIMMESG_MAX_DATA_SIZE								IDIMMES_MAX_DATA_SIZE
#define IDIMMESG_MAX_MES_SIZE								(IDIMMESG_MAX_DATA_SIZE + IDIMMESG_MAX_HEADER_LENGTH + MODBUS_CRC16_SIZE)
#define IDIMMESG_MODULE_MIN_MES_SIZE						(IDIMMESG_DATA_COM_FUNC_Pos + 1 + MODBUS_CRC16_SIZE)
#define IDIMMESG_GROUP_MIN_MES_SIZE							(IDIMMESG_DATA_COM_FUNC_Pos + MODBUS_CRC16_SIZE)

#define IDIMMES_LMES_MSIZE_Pos								0U
#define IDIMMES_LMES_BSIZE_Pos								(IDIMMES_LMES_MSIZE_Pos + 4U)
#define IDIMMES_LMES_IDENTIFIER_LENGTH						(IDIMMES_LMES_BSIZE_Pos + 1U)
#define IDIMMES_LMES_BSIZE_256B								0U
#define IDIMMES_LMES_BSIZE_1K								1U
#define IDIMMES_LMES_BSIZE_4K								2U
#define IDIMMES_LMES_BSIZE_8K								3U
#define IDIMMES_LMES_BSIZE_16K								4U
#define IDIMMES_LMES_BSIZE_32K								5U
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
#define IDISMES_ADDR_Pos									00U
#define IDISMES_SMPS_Pos									01U
#define IDISMES_SMPS_ERROR_BIT_Pos							0U
#define IDISMES_SMPS_LONG_MES_Pos							1U
#define IDISMES_SMPS_LONG_OP_Pos							2U
#define IDISMES_ERROR_Pos									02U
#define IDISMES_DATA_Pos									03U
#define IDISMES_MAX_DATA_SIZE								256U
#define IDISMES_MIN_MES_SIZE								(IDISMES_DATA_Pos + MODBUS_CRC16_SIZE)
#define IDISMES_MAX_MES_SIZE								(IDISMES_DATA_Pos + IDISMES_MAX_DATA_SIZE + MODBUS_CRC16_SIZE)
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
#define IDILONGOP_STATE_COMPLETE_NO_ERR						0x00U
#define IDILONGOP_STATE_IN_PROC								0x01U
#define IDILONGOP_STATE_COMPLETE_WITH_ERR					0x02U
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define IDILONGOP_MES_DATA_LENGTH							5U
#define IDILONGOP_STATE_Pos									0U
#define IDILONGOP_REMAIN_TIME_Pos							1U
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
#define IDISTATUS_B0S_Pos									00U
#define IDISTATUS_B0S_ST_ERROR_Pos							0U
#define IDISTATUS_B0S_ST_STATE_Pos							1U
#define IDISTATUS_B0S_ST_STATE_Msk							0x07U
#define IDISTATUS_B0S_ST_STATE_StNoInit						0x00U
#define IDISTATUS_B0S_ST_STATE_StOperate					0x01U
#define IDISTATUS_B0S_ST_STATE_StFreeze						0x02U
#define IDISTATUS_B0S_ST_STATE_StVirtual					0x03U
#define IDISTATUS_B0S_ST_STATE_StFirmwareUpd				0x04U
#define IDISTATUS_B0S_ST_STATE_StReservedMaster				0x05U
#define IDISTATUS_B0S_ST_STATE_StBroken						0x06U
#define IDISTATUS_B0S_ST_STATE_StReserved0					0x07U
#define IDISTATUS_B0S_AES_SUPPORTED_Pos						4U
#define IDISTATUS_B0S_AES_INSTALLED_Pos						5U
#define IDISTATUS_B0S_SEND_ALARM_L0_Pos						6U
#define IDISTATUS_B0S_SEND_ALARM_L1_Pos						7U

#define IDISTATUS_B1S_Pos									01U
#define IDISTATUS_B1S_MODULE_TYPE_Pos						0U
#define IDISTATUS_B1S_MODULE_TYPE_Msk						0x03U
#define IDISTATUS_B1S_MODULE_TYPE_Master					0x00U
#define IDISTATUS_B1S_MODULE_TYPE_SpareMaster				0x01U
#define IDISTATUS_B1S_MODULE_TYPE_Slave						0x02U
#define IDISTATUS_B1S_MODULE_TYPE_Bridge					0x03U
#define IDISTATUS_B1S_BRIDGE_CONNECTED_Pos					2U
#define IDISTATUS_B1S_SELF_INIT_Pos							3U
#define IDISTATUS_B1S_TIMEOUT_LED_Pos						4U
#define IDISTATUS_B1S_NO_MMES_TIMEOUT_Pos					5U
#define IDISTATUS_B1S_CATCH_ALARM_L0_Pos					6U
#define IDISTATUS_B1S_CATCH_ALARM_L1_Pos					7U

#define IDISTATUS_SN_Pos									02U
#define IDISTATUS_LENGTH									( IDISTATUS_SN_Pos + IDISN_FULL_LENGTH )
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
#define IDIMMES_NOT_FAST_FUNC								0U
#define IDIMMES_MAX_FAST_FUNC_NUM							15U
#define IDIMMES_COM_START_NUM								220U
#define IDIMMES_COM_C_Init									220U
#define IDIMMES_COM_C_ShtDown								221U
#define IDIMMES_COM_C_Freeze								222U
#define IDIMMES_COM_C_Resume								223U
#define IDIMMES_COM_C_Dummy									224U
#define IDIMMES_COM_C_AssignGroup							225U
#define IDIMMES_COM_C_SetAlarmL12							226U
#define IDIMMES_COM_C_SetAlarmL								227U
#define IDIMMES_COM_C_Virtual								228U
#define IDIMMES_COM_C_SyncReadChnl							229U
#define IDIMMES_COM_C_SyncRead								230U
#define IDIMMES_COM_C_SyncDoChnl							231U
#define IDIMMES_COM_C_SyncDo								232U
#define IDIMMES_COM_C_SyncClear								233U
#define IDIMMES_COM_C_BurstReadCnt							234U
#define IDIMMES_COM_C_BurstReadTime							235U
#define IDIMMES_COM_C_SendTimeDate							236U
#define IDIMMES_COM_C_MkTimedMaster							237U
#define IDIMMES_COM_C_EnterBootloader						238U	//OUT OF SPEC !!!
//#define IDIMMES_COM_C_EndFmwUpd								239U
//#define IDIMMES_COM_C_FmwWrite								240U
#define IDIMMES_COM_C_ReadDevFullSN_MS						241U
#define IDIMMES_COM_C_WriteSnIPv4IPv6						242U
#define IDIMMES_COM_C_WriteSnVerifyDates					243U
#define IDIMMES_COM_C_WriteSnAES256							244U
#define IDIMMES_COM_C_SendLongMessage						245U
#define IDIMMES_COM_C_GetLondMessage						246U
#define IDIMMES_COM_C_DummyModule							247U
#define IDIMMES_COM_C_CheckModuleLongOp						248U
#define IDIMMES_COM_C_CheckChannelLongOp					249U
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
#define IDIER_MODBUS_NUM_START								1U
#define IDIER_MODBUS_NUM_END								9U
#define IDIER_MODULE_MASTER_NUM_START						10U
#define IDIER_MODULE_MASTER_NUM_END							32U
#define IDIER_MODULE_SLAVE_NUM_START						33U
#define IDIER_MODULE_SLAVE_NUM_END							71U
#define IDIER_MODULE_NUM_START								IDIER_MODULE_MASTER_NUM_START
#define IDIER_MODULE_NUM_END								IDIER_MODULE_SLAVE_NUM_END
#define IDIER_DEVICE_NUM_START								72U
#define IDIER_DEVICE_NUM_END								89U

#define IDIER_NOPE											0U
#define MODBUSER_WRONGFUNC									1U
#define MODBUSER_WRONGADDR									2U
#define MODBUSER_WRONGDATA									3U
#define MODBUSER_BROKE										4U
#define MODBUSER_LONGCOMMAND								5U
#define MODBUSER_BUSY										6U
#define MODBUSER_CANTDOFUNC									7U
#define MODBUSER_EXTMEMORYERROR								8U
#define MODBUSER_RESERVED									9U
#define IDIERMST_INVALID_ADDR_NUM							10U
#define IDIERMST_INVALID_DEV_NUM							11U
#define IDIERMST_INVALID_CHN_NUM							12U
#define IDIERMST_INVALID_FUNC_NUM							13U
#define IDIERMST_INVALID_TX_REQUEST_FORMAT					14U
#define IDIERMST_INVALID_TX_PARAM							15U
#define IDIERMST_TX_MES										16U
#define IDIERMST_RCV_TIMEOUT								17U
#define IDIERMST_MES_RX_INTEGRITY							18U
#define IDIERMST_CRC										19U
#define IDIERMST_MULTIPLE_CRC								20U
#define IDIERMST_INVALID_RX_REQUEST_FORMAT					21U
#define IDIERMST_INVALID_RX_PARAM							22U
#define IDIERMST_RESEVED_23									23U
#define IDIERMST_RESEVED_24									24U
#define IDIERMST_RESEVED_25									25U
#define IDIERMST_RESEVED_26									26U
#define IDIERMST_RESEVED_27									27U
#define IDIERMST_EXTRA_28									28U
#define IDIERMST_EXTRA_29									29U
#define IDIERMST_EXTRA_30									30U
#define IDIERMST_EXTRA_31									31U
#define IDIERMST_EXTRA_32									32U
#define IDIERSLV_RESEVED_33									33U
#define IDIERSLV_ENCRYPTION_NOT_SUPPORTED					34U
#define IDIERSLV_ENCRYPTION_NOT_INSTALLED					35U
#define IDIERSLV_JUMBO_NOT_SUPPORTED						36U
#define IDIERSLV_UNSUPPORTED_FUNC_NUM						37U
#define IDIERSLV_INVALID_RX_REQUEST_FORMAT					38U
#define IDIERSLV_INVALID_RX_PARAM							39U
#define IDIERSLV_IN_FREEZE									40U
#define IDIERSLV_RESERVED_41								41U
#define IDIERSLV_RESERVED_42								42U
#define IDIERSLV_RESERVED_43								43U
#define IDIERSLV_RESERVED_44								44U
#define IDIERSLV_RESERVED_45								45U
#define IDIERSLV_EXTRA_46									46U
#define IDIERSLV_EXTRA_47									47U
#define IDIERSLV_EXTRA_48									48U
#define IDIERSLV_EXTRA_49									49U
#define IDIERSLV_EXTRA_50									50U
#define IDIERSLV_BROKE										51U
#define IDIERSLV_NO_FIRMWARE								52U
#define IDIERSLV_NO_INIT									53U
#define IDIERSLV_OVERHEAT									54U
#define IDIERSLV_INP_VOLTAGE								55U
#define IDIERSLV_BRIDGE_OVERFLOW							56U
#define IDIERSLV_BRIDGE_NOT_CONF							57U
#define IDIERSLV_VERIF_DATE									58U
#define IDIERSLV_RTC										59U
#define IDIERSLV_LONG_OP_IN_PROC							60U
#define IDIERSLV_RESERVED_61								61U
#define IDIERSLV_RESERVED_62								62U
#define IDIERSLV_RESERVED_63								63U
#define IDIERSLV_RESERVED_64								64U
#define IDIERSLV_RESERVED_65								65U
#define IDIERSLV_RESERVED_66								66U
#define IDIERSLV_EXTRA_67									67U
#define IDIERSLV_EXTRA_68									68U
#define IDIERSLV_EXTRA_69									69U
#define IDIERSLV_EXTRA_70									70U
#define IDIERSLV_EXTRA_71									71U
#define IDIERDEV_INVALID_DEV_NUM							72U
#define IDIERDEV_INVALID_CHN_NUM							73U
#define IDIERDEV_INVALID_FUNC_NUM							74U
#define IDIERDEV_LONG_OP_IN_PROC							75U
#define IDIERDEV_RESERVED_76								76U
#define IDIERDEV_PARAM_LOW_ST_TIMEOUT						77U
#define IDIERDEV_PARAM_HIGH_ST_TIMEOUT						78U
#define IDIERDEV_PARAM_NOT_CHANGE_TIMEOUT					79U
#define IDIERDEV_RESERVED_80								80U
#define IDIERDEV_RESERVED_81								81U
#define IDIERDEV_RESERVED_82								82U
#define IDIERDEV_RESERVED_83								83U
#define IDIERDEV_RESERVED_84								84U
#define IDIERDEV_RESERVED_85								85U
#define IDIERDEV_RESERVED_86								86U
#define IDIERDEV_RESERVED_87								87U
#define IDIERDEV_RESERVED_88								88U
#define IDIERDEV_RESERVED_89								89U

#define IDIER_MULTIPLE_CRC_AVRBUF_SIZE						16U
#define IDIER_MULTIPLE_CRC_AVRBUF_THR						5U
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
#define IDIDATE_FORMAT_DAY_Pos								0U
#define IDIDATE_FORMAT_MONTH_Pos							1U
#define IDIDATE_FORMAT_CENTURY_Pos							2U
#define IDIDATE_FORMAT_YEAR99_Pos							3U
#define IDIDATE_FORMAT_LENGTH								4U

#define IDITIME_FORMAT_SECONDS_Pos							0U
#define IDITIME_FORMAT_MINUTES_Pos							1U
#define IDITIME_FORMAT_HOURS_Pos							2U
#define IDITIME_FORMAT_TIMEZONE_Pos							3U
#define IDITIME_FORMAT_LENGTH								4U

#define IDITIME_FORMAT_TIMEZONE_MIN							(-12)
#define IDITIME_FORMAT_TIMEZONE_MAX							14

#define IDIMMES_C_DATETIME_TIME_Pos							0
#define IDIMMES_C_DATETIME_DATE_Pos							(IDIMMES_C_DATETIME_TIME_Pos + IDIDATE_FORMAT_LENGTH)
#define IDIMMES_C_DATETIME_LENGTH							(IDIDATE_FORMAT_LENGTH + IDITIME_FORMAT_LENGTH)
//=============================================================================================================================================================================================================
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//=============================================================================================================================================================================================================
typedef struct {
	struct {
		uint8_t StError   	    : 1;
		uint8_t StState   	    : 3;
		uint8_t AesSupported    : 1;
		uint8_t AesInstalled    : 1;
		uint8_t SendAlarmL0     : 1;
		uint8_t SendAlarmL1     : 1;
		} B0S;
	struct {
		uint8_t ModuleType      : 2;
		uint8_t BridgeConnected : 1;
		uint8_t SelfInit 	    : 1;
		uint8_t TimeoutLed 	    : 1;
		uint8_t NoMMESTimeout   : 1;
		uint8_t CatchAlarmL0    : 1;
		uint8_t CatchAlarmL1    : 1;
		} B1S;
	} IDISTATUS_STATE_TYPE;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
typedef struct {
	IDISTATUS_STATE_TYPE STATE;
	#ifdef _LONG_ADDR_SPACE_
		volatile uint_farptr_t SNfix;
	#else
		volatile uint8_t *SNfix;
	#endif
	volatile uint8_t *SNvar;
	//uint8_t              SN[IDISN_FULL_LENGTH];
} IDISTATUS_SLAVE_TYPE;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#endif //_INC_IDIBUS_DEFS_H_
//#############################################################################################################################################################################################################
