ESPHome 2026.4.0-dev
Loading...
Searching...
No Matches
modbus_helpers.h File Reference

Go to the source code of this file.

Namespaces

namespace  esphome
 Providing packet encoding functions for exchanging data with a remote host.
 
namespace  esphome::modbus
 
namespace  esphome::modbus::helpers
 

Enumerations

enum class  esphome::modbus::helpers::SensorValueType : uint8_t {
  esphome::modbus::helpers::RAW = 0x00 , esphome::modbus::helpers::U_WORD = 0x1 , esphome::modbus::helpers::U_DWORD = 0x2 , esphome::modbus::helpers::S_WORD = 0x3 ,
  esphome::modbus::helpers::S_DWORD = 0x4 , esphome::modbus::helpers::BIT = 0x5 , esphome::modbus::helpers::U_DWORD_R = 0x6 , esphome::modbus::helpers::S_DWORD_R = 0x7 ,
  esphome::modbus::helpers::U_QWORD = 0x8 , esphome::modbus::helpers::S_QWORD = 0x9 , esphome::modbus::helpers::U_QWORD_R = 0xA , esphome::modbus::helpers::S_QWORD_R = 0xB ,
  esphome::modbus::helpers::FP32 = 0xC , esphome::modbus::helpers::FP32_R = 0xD
}
 

Functions

bool esphome::modbus::helpers::value_type_is_float (SensorValueType v)
 
ModbusFunctionCode esphome::modbus::helpers::modbus_register_read_function (ModbusRegisterType reg_type)
 
ModbusFunctionCode esphome::modbus::helpers::modbus_register_write_function (ModbusRegisterType reg_type)
 
uint8_t esphome::modbus::helpers::c_to_hex (char c)
 
uint8_t esphome::modbus::helpers::byte_from_hex_str (const std::string &value, uint8_t pos)
 Get a byte from a hex string byte_from_hex_str("1122", 1) returns uint_8 value 0x22 == 34 byte_from_hex_str("1122", 0) returns 0x11.
 
uint16_t esphome::modbus::helpers::word_from_hex_str (const std::string &value, uint8_t pos)
 Get a word from a hex string.
 
uint32_t esphome::modbus::helpers::dword_from_hex_str (const std::string &value, uint8_t pos)
 Get a dword from a hex string.
 
uint64_t esphome::modbus::helpers::qword_from_hex_str (const std::string &value, uint8_t pos)
 Get a qword from a hex string.
 
template<typename T >
esphome::modbus::helpers::get_data (const std::vector< uint8_t > &data, size_t buffer_offset)
 Extract data from modbus response buffer.
 
bool esphome::modbus::helpers::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 .
 
template<typename N >
esphome::modbus::helpers::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.
 
void esphome::modbus::helpers::number_to_payload (std::vector< uint16_t > &data, int64_t value, SensorValueType value_type)
 Convert float value to vector<uint16_t> suitable for sending.
 
int64_t esphome::modbus::helpers::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.
 
std::vector< uint16_t > esphome::modbus::helpers::float_to_payload (float value, SensorValueType value_type)