#ifndef __MODBUS_H__
#define __MODBUS_H__

/* Includes ------------------------------------------------------------------*/

/* Define --------------------------------------------------------------------*/
/*Read multiple registers*/
/*Read a single register*/

/*function commond*/
#define MB_FUNC_MULIT_RD    0x03
#define MB_FUNC_SINGLE_WR   0x06
#define MB_FUNC_MULIT_WR    0x10
#define MB_FUNC_FILE_RD     0x14
/*factory address */
#define MB_FAC_PARAM        0x0
#define MB_CALI_PARAM       0x10
/*user parameter address */
#define MB_USER_PARAM       0x1000
/*measurement parameter address */
#define MB_MEAS_PARAM       0x2000
#define MB_MEAS_VALUE       0x2010
/* Exported types ------------------------------------------------------------*/
typedef struct
{
    unsigned char slave;
    unsigned char cmd;
} modbus_head_t;

/* Exported macro ------------------------------------------------------------*/

/* Extern global variables ---------------------------------------------------*/

/* Extern functions ----------------------------------------------------------*/
extern int _modbus_packet(unsigned char *pkt, unsigned char cmd, unsigned short regAddr, unsigned short regCnt, unsigned char data[]);
extern int _modbus_write_head(unsigned char *pkt, unsigned char cmd, unsigned short regAddr, unsigned short regCnt);
extern void _modbus_add_float(unsigned char *hex,float val);
extern void _modbus_checksum(unsigned char *buf, int len);
extern int _modbus_verify_crc(unsigned char *buf, int len);
#endif

