1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- /**
- * @Author: 李建
- * @Date: 2025/4/27 15:35
- * Description: 485主站
- * Copyright: Copyright (©) 2025 永续绿建. All rights reserved.
- */
- #ifndef WIRE_CONTROLLER_MODBUS_MASTER_H
- #define WIRE_CONTROLLER_MODBUS_MASTER_H
- #include "esp_err.h"
- #include "esp_modbus_master.h"
- #define MB_PORT_NUM 2 // Number of UART port used for Modbus connection
- #define MB_DEV_SPEED 9600 // The communication speed of the UART
- #define MB_GPIO_RX 2 // uart rx gpio port
- #define MB_GPIO_TX 1 // uart tx gpio port
- #define HP_SET_MODE_REG_ADDRESS 0x01 // 热泵设置模式
- #define HP_COOL_SET_TEMP_REG_ADDRESS 0x02 // 制冷水温设定
- #define HP_HEAT_SET_TEMP_REG_ADDRESS 0x03 // 制热水温设定
- #define HP_OUTDOOR_TEMP_REG_ADDRESS 46
- #define HP_OUT_WATER_TEMP_REG_ADDRESS 67
- #define HP_IN_WATER_TEMP_REG_ADDRESS 68
- #define RELAY_1_STATUS_REG_ADDRESS 0x01 // 第一路继电器状态
- #define RELAY_2_STATUS_REG_ADDRESS 0x02 // 第二路继电器状态
- #define RELAY_3_STATUS_REG_ADDRESS 0x03 // 第三路继电器状态
- #define RELAY_4_STATUS_REG_ADDRESS 0x04 // 第四路继电器状态
- #define RELAY_5_STATUS_REG_ADDRESS 0x05 // 第五路继电器状态
- #define RELAY_6_STATUS_REG_ADDRESS 0x06 // 第六路继电器状态
- #define RELAY_7_STATUS_REG_ADDRESS 0x07 // 第七路继电器状态
- #define RELAY_8_STATUS_REG_ADDRESS 0x08 // 第八路继电器状态
- #define MODIFY_COMMUNICATION_ADDRESS_REGISTER 0x09 // 修改通讯地址码
- // 定义协议 CID 表
- enum {
- CID_HP_SET_MODE,
- CID_HP_COOL_SET_TEMP,
- CID_HP_HEAT_SET_TEMP,
- CID_HP_OUTDOOR_TEMP,
- CID_HP_OUT_WATER_TEMP,
- CID_HP_IN_WATER_TEMP,
- CID_HP_POWER,
- CID_HP_ERROR,
- CID_RELAY_1_STATUS,
- CID_RELAY_2_STATUS,
- CID_RELAY_3_STATUS,
- CID_RELAY_4_STATUS,
- CID_RELAY_5_STATUS,
- CID_RELAY_6_STATUS,
- CID_RELAY_7_STATUS,
- CID_RELAY_8_STATUS,
- CID_MODIFY_COMMUNICATION_ADDRESS,
- };
- void modbus_master_init();
- esp_err_t mm_set_param(uint16_t cid, uint8_t *value);
- /**
- * 发送 modbus 请求
- * @param request
- * @param data_prt
- * @return
- */
- esp_err_t send_request(mb_param_request_t *request, void *data_prt);
- void modbus_master_destroy();
- #endif //WIRE_CONTROLLER_MODBUS_MASTER_H
|