ESPHome  2024.11.0
Data Structures | Namespaces | Typedefs | Enumerations | Functions
modbus_controller.h File Reference

Go to the source code of this file.

Data Structures

class  esphome::modbus_controller::SensorItem
 
class  esphome::modbus_controller::ServerRegister
 
class  esphome::modbus_controller::SensorItemsComparator
 
struct  esphome::modbus_controller::RegisterRange
 
class  esphome::modbus_controller::ModbusCommandItem
 
class  esphome::modbus_controller::ModbusController
 Modbus controller class. More...
 

Namespaces

 esphome
 Implementation of SPI Controller mode.
 
 esphome::modbus_controller
 

Typedefs

using esphome::modbus_controller::SensorSet = std::set< SensorItem *, SensorItemsComparator >
 

Enumerations

enum  esphome::modbus_controller::ModbusFunctionCode {
  esphome::modbus_controller::ModbusFunctionCode::CUSTOM = 0x00, esphome::modbus_controller::ModbusFunctionCode::READ_COILS = 0x01, esphome::modbus_controller::ModbusFunctionCode::READ_DISCRETE_INPUTS = 0x02, esphome::modbus_controller::ModbusFunctionCode::READ_HOLDING_REGISTERS = 0x03,
  esphome::modbus_controller::ModbusFunctionCode::READ_INPUT_REGISTERS = 0x04, esphome::modbus_controller::ModbusFunctionCode::WRITE_SINGLE_COIL = 0x05, esphome::modbus_controller::ModbusFunctionCode::WRITE_SINGLE_REGISTER = 0x06, esphome::modbus_controller::ModbusFunctionCode::READ_EXCEPTION_STATUS = 0x07,
  esphome::modbus_controller::ModbusFunctionCode::DIAGNOSTICS = 0x08, esphome::modbus_controller::ModbusFunctionCode::GET_COMM_EVENT_COUNTER = 0x0B, esphome::modbus_controller::ModbusFunctionCode::GET_COMM_EVENT_LOG = 0x0C, esphome::modbus_controller::ModbusFunctionCode::WRITE_MULTIPLE_COILS = 0x0F,
  esphome::modbus_controller::ModbusFunctionCode::WRITE_MULTIPLE_REGISTERS = 0x10, esphome::modbus_controller::ModbusFunctionCode::REPORT_SERVER_ID = 0x11, esphome::modbus_controller::ModbusFunctionCode::READ_FILE_RECORD = 0x14, esphome::modbus_controller::ModbusFunctionCode::WRITE_FILE_RECORD = 0x15,
  esphome::modbus_controller::ModbusFunctionCode::MASK_WRITE_REGISTER = 0x16, esphome::modbus_controller::ModbusFunctionCode::READ_WRITE_MULTIPLE_REGISTERS = 0x17, esphome::modbus_controller::ModbusFunctionCode::READ_FIFO_QUEUE = 0x18
}
 
enum  esphome::modbus_controller::ModbusRegisterType : uint8_t {
  esphome::modbus_controller::ModbusRegisterType::CUSTOM = 0x0, esphome::modbus_controller::ModbusRegisterType::COIL = 0x01, esphome::modbus_controller::ModbusRegisterType::DISCRETE_INPUT = 0x02, esphome::modbus_controller::ModbusRegisterType::HOLDING = 0x03,
  esphome::modbus_controller::ModbusRegisterType::READ = 0x04
}
 
enum  esphome::modbus_controller::SensorValueType : uint8_t {
  esphome::modbus_controller::SensorValueType::RAW = 0x00, esphome::modbus_controller::SensorValueType::U_WORD = 0x1, esphome::modbus_controller::SensorValueType::U_DWORD = 0x2, esphome::modbus_controller::SensorValueType::S_WORD = 0x3,
  esphome::modbus_controller::SensorValueType::S_DWORD = 0x4, esphome::modbus_controller::SensorValueType::BIT = 0x5, esphome::modbus_controller::SensorValueType::U_DWORD_R = 0x6, esphome::modbus_controller::SensorValueType::S_DWORD_R = 0x7,
  esphome::modbus_controller::SensorValueType::U_QWORD = 0x8, esphome::modbus_controller::SensorValueType::S_QWORD = 0x9, esphome::modbus_controller::SensorValueType::U_QWORD_R = 0xA, esphome::modbus_controller::SensorValueType::S_QWORD_R = 0xB,
  esphome::modbus_controller::SensorValueType::FP32 = 0xC, esphome::modbus_controller::SensorValueType::FP32_R = 0xD
}
 

Functions

ModbusFunctionCode esphome::modbus_controller::modbus_register_read_function (ModbusRegisterType reg_type)
 
ModbusFunctionCode esphome::modbus_controller::modbus_register_write_function (ModbusRegisterType reg_type)
 
uint8_t esphome::modbus_controller::c_to_hex (char c)
 
uint8_t esphome::modbus_controller::byte_from_hex_str (const std::string &value, uint8_t pos)
 Get a byte from a hex string hex_byte_from_str("1122",1) returns uint_8 value 0x22 == 34 hex_byte_from_str("1122",0) returns 0x11. More...
 
uint16_t esphome::modbus_controller::word_from_hex_str (const std::string &value, uint8_t pos)
 Get a word from a hex string. More...
 
uint32_t esphome::modbus_controller::dword_from_hex_str (const std::string &value, uint8_t pos)
 Get a dword from a hex string. More...
 
uint64_t esphome::modbus_controller::qword_from_hex_str (const std::string &value, uint8_t pos)
 Get a qword from a hex string. More...
 
template<typename T >
esphome::modbus_controller::get_data (const std::vector< uint8_t > &data, size_t buffer_offset)
 Extract data from modbus response buffer. More...
 
bool esphome::modbus_controller::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 . More...
 
template<typename N >
esphome::modbus_controller::mask_and_shift_by_rightbit (N data, uint32_t mask)
 Extract bits from value and shift right according to the bitmask if the bitmask is 0x00F0 we want the values frrom bit 5 - 8. More...
 
void esphome::modbus_controller::number_to_payload (std::vector< uint16_t > &data, int64_t value, SensorValueType value_type)
 Convert float value to vector<uint16_t> suitable for sending. More...
 
int64_t esphome::modbus_controller::payload_to_number (const std::vector< uint8_t > &data, SensorValueType sensor_value_type, uint8_t offset, uint32_t bitmask)
 Convert vector<uint8_t> response payload to number. More...
 
float esphome::modbus_controller::payload_to_float (const std::vector< uint8_t > &data, const SensorItem &item)
 Convert vector<uint8_t> response payload to float. More...
 
std::vector< uint16_t > esphome::modbus_controller::float_to_payload (float value, SensorValueType value_type)