5 namespace modbus_controller {
7 static const char *
const TAG =
"modbus_controller.switch";
10 optional<bool> initial_state = Switch::get_initial_state_with_restore_mode();
13 if (initial_state.
value()) {
31 value = get_data<uint16_t>(data, this->
offset) & this->
bitmask;
40 if (
val.has_value()) {
41 ESP_LOGV(TAG,
"Value overwritten by lambda");
46 ESP_LOGV(TAG,
"Publish '%s': new value = %s type = %d address = %X offset = %x", this->
get_name().c_str(),
54 std::vector<uint8_t> data;
61 if (
val.has_value()) {
62 ESP_LOGV(TAG,
"Value overwritten by lambda");
65 ESP_LOGV(TAG,
"Communication handled by lambda - exiting control");
77 ESP_LOGV(TAG,
"write_state '%s': new value = %s type = %d address = %X offset = %x", this->
get_name().c_str(),
82 std::vector<bool> states{state};
90 std::vector<uint16_t> bool_states(1, state ? (0xFFFF & this->
bitmask) : 0);
95 state ? 0xFFFF & this->
bitmask : 0u);
value_type const & value() const
ModbusController * parent_
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.
ModbusRegisterType register_type
optional< write_transform_func_t > write_transform_func_
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...
optional< transform_func_t > publish_transform_func_
ModbusRegisterType register_type
bool coil_from_vector(int coil, const std::vector< uint8_t > &data)
Extract coil data from modbus response buffer Responses for coil are packed into bytes ...
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 turn_on()
Turn this switch on.
void parse_and_publish(const std::vector< uint8_t > &data) 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.
void dump_config() override
Implementation of SPI Controller mode.
void publish_state(bool state)
Publish a state to the front-end from the back-end.
bool state
The current reported state of the binary sensor.
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.
const StringRef & get_name() const
void write_state(bool state) override
void turn_off()
Turn this switch off.