| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #ifndef __MODBUS_H__
- #define __MODBUS_H__
- #include "define.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define MODBUS_DATA_SIZE 512
-
- #define COLL_MAX_COUNT 32
- #define COLL_NOT_READY_STAT (uint16_t)0x0000
- #define COLL_READY_STAT (uint16_t)0x0001
- #define CMD_RD_REG (uint8_t)0x03
- #define CMD_WR_REG (uint8_t)0x06
- #define CMD_WR_MULTI_REG (uint8_t)0x10
- #define REG_DEV_TYPE_ADDR (uint16_t)0x0000
- #define REG_VERSION_ADDR (uint16_t)0x0003
- #define REG_COLL_STAT_ADDR (uint16_t)0x0010
- #define REG_COLL_COUNT_ADDR (uint16_t)0x0011
- #define REG_COLL_SW_HIGH_STAT_ADDR (uint16_t)0x0012
- #define REG_COLL_SW_LOW_STAT_ADDR (uint16_t)0x0013
- typedef struct{
- uint8_t addr;
- uint8_t func;
- uint8_t regAddr[2];
- uint8_t data[MODBUS_DATA_SIZE];
- uint8_t dataSize;
- uint16_t crc;
- }__attribute__((packed))rtu_rec_s;
- typedef struct{
- uint8_t addr;
- uint8_t func;
- uint8_t dataSize;
- uint8_t data[MODBUS_DATA_SIZE];
- uint16_t crc;
- }__attribute__((packed))rtu_rd_s;
- typedef struct{
- uint8_t rtu_addr;
- uint16_t tx_size;
- uint16_t rx_size;
- uint8_t tx_buffer[MODBUS_DATA_SIZE];
- uint8_t rx_buffer[MODBUS_DATA_SIZE];
- rtu_rec_s rtu_rec;
- rtu_rd_s rtu_rd;
- bool modbusRx_stat;
- bool modbusTx_stat;
- }modbus_work_s;
- #ifdef __cplusplus
- }
- #endif
- #endif //__MODBUS_H__
|