6 namespace modbus_controller {
8 static const char *
const TAG =
"modbus_controller.output";
14 std::vector<uint16_t> data;
15 auto original_value = value;
22 if (
val.has_value()) {
23 ESP_LOGV(TAG,
"Value overwritten by lambda");
26 ESP_LOGV(TAG,
"Communication handled by lambda - exiting control");
37 ESP_LOGD(TAG,
"Updating register: start address=0x%X register count=%d new value=%.02f (val=%.02f)",
53 ESP_LOGCONFIG(TAG,
"Modbus Float Output:");
54 LOG_FLOAT_OUTPUT(
this);
55 ESP_LOGCONFIG(TAG,
" Device start address: 0x%X", this->
start_address);
64 std::vector<uint8_t> data;
72 if (
val.has_value()) {
73 ESP_LOGV(TAG,
"Value overwritten by lambda");
76 ESP_LOGV(TAG,
"Communication handled by lambda - exiting control");
81 ESP_LOGV(TAG,
"Modbus binary output write raw: %s",
format_hex_pretty(data).c_str());
88 ESP_LOGV(TAG,
"Write new state: value is %s, type is %d address = %X, offset = %x", ONOFF(state),
93 std::vector<bool> states{state};
103 ESP_LOGCONFIG(TAG,
"Modbus Binary Output:");
104 LOG_BINARY_OUTPUT(
this);
105 ESP_LOGCONFIG(TAG,
" Device start address: 0x%X", this->
start_address);
107 ESP_LOGCONFIG(TAG,
" Value type: %d", static_cast<int>(this->
sensor_value_type));
SensorValueType sensor_value_type
void queue_command(const ModbusCommandItem &command)
queues a modbus command in the send queue
std::string format_hex_pretty(const uint8_t *data, size_t length)
Format the byte array data of length len in pretty-printed, human-readable hex.
void write_state(bool state) override
ModbusRegisterType register_type
std::vector< uint16_t > float_to_payload(float value, SensorValueType value_type)
void on_write_register_response(ModbusRegisterType register_type, uint16_t start_address, const std::vector< uint8_t > &data)
default delegate called by process_modbus_data when a response for a write response has retrieved fro...
static ModbusCommandItem create_write_single_command(ModbusController *modbusdevice, uint16_t start_address, uint16_t value)
Create modbus write multiple registers command Function 16 (10hex) Write Multiple Registers...
ModbusRegisterType register_type
static ModbusCommandItem create_write_single_coil(ModbusController *modbusdevice, uint16_t address, bool value)
Create modbus write single registers command Function 05 (05hex) Write Single Coil.
void dump_config() override
void write_state(float value) override
Write a value to the device.
optional< write_transform_func_t > write_transform_func_
void dump_config() override
static ModbusCommandItem create_write_multiple_coils(ModbusController *modbusdevice, uint16_t start_address, const std::vector< bool > &values)
Create modbus write multiple registers command Function 15 (0Fhex) Write Multiple Coils...
static ModbusCommandItem create_write_multiple_command(ModbusController *modbusdevice, uint16_t start_address, uint16_t register_count, const std::vector< uint16_t > &values)
Create modbus read command Function code 02-04.
ModbusController * parent_
Implementation of SPI Controller mode.
static ModbusCommandItem create_custom_command(ModbusController *modbusdevice, const std::vector< uint8_t > &values, std::function< void(ModbusRegisterType register_type, uint16_t start_address, const std::vector< uint8_t > &data)> &&handler=nullptr)
Create custom modbus command.