modbus_controller: remove hard coded register size (#2654)

This commit is contained in:
Martin 2021-11-10 04:24:44 +01:00 committed by GitHub
parent 875b803483
commit 662773b075
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 35 deletions

View file

@ -260,35 +260,11 @@ struct SensorItem {
virtual void parse_and_publish(const std::vector<uint8_t> &data) = 0;
uint64_t getkey() const { return calc_key(register_type, start_address, offset, bitmask); }
size_t virtual get_register_size() const {
size_t size = 0;
switch (sensor_value_type) {
case SensorValueType::BIT:
size = 1;
break;
case SensorValueType::U_WORD:
case SensorValueType::S_WORD:
size = 2;
break;
case SensorValueType::U_DWORD:
case SensorValueType::S_DWORD:
case SensorValueType::U_DWORD_R:
case SensorValueType::S_DWORD_R:
case SensorValueType::FP32:
case SensorValueType::FP32_R:
size = 4;
break;
case SensorValueType::U_QWORD:
case SensorValueType::U_QWORD_R:
case SensorValueType::S_QWORD:
case SensorValueType::S_QWORD_R:
size = 8;
break;
case SensorValueType::RAW:
size = this->register_count * 2;
}
return size;
if (register_type == ModbusRegisterType::COIL || register_type == ModbusRegisterType::DISCRETE_INPUT)
return 1;
else
return register_count * 2;
}
};

View file

@ -25,13 +25,6 @@ class ModbusTextSensor : public Component, public text_sensor::TextSensor, publi
this->sensor_value_type = SensorValueType::RAW;
this->force_new_range = force_new_range;
}
size_t get_register_size() const override {
if (sensor_value_type == SensorValueType::RAW) {
return this->response_bytes_;
} else {
return SensorItem::get_register_size();
}
}
void dump_config() override;