diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index a2f9c31ff..62d31ad70 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -2091,7 +2091,7 @@ int EMSdevice::modbus_value_to_json(uint8_t tag, const std::string & shortname, } uint32_t value = 0; - for(auto i = 0; i < modbus_data.size(); i++) { + for (auto i = 0; i < modbus_data.size(); i++) { value += (uint32_t)modbus_data[modbus_data.size() - i - 1] << (i * 8); } diff --git a/src/emsdevice.h b/src/emsdevice.h index 97e2f99ef..d226ffbdd 100644 --- a/src/emsdevice.h +++ b/src/emsdevice.h @@ -202,7 +202,7 @@ class EMSdevice { } } - int get_modbus_value(uint8_t tag, const std::string & shortname, std::vector & result); + int get_modbus_value(uint8_t tag, const std::string & shortname, std::vector & result); int modbus_value_to_json(uint8_t tag, const std::string & shortname, const std::vector & modbus_data, JsonObject jsonValue); const char * brand_to_char(); diff --git a/src/modbus.cpp b/src/modbus.cpp index 94c02d155..142135674 100644 --- a/src/modbus.cpp +++ b/src/modbus.cpp @@ -312,7 +312,7 @@ ModbusMessage Modbus::handleRead(const ModbusMessage & request) { return response; } - auto buf = std::vector(num_words); + auto buf = std::vector(num_words); auto error_code = dev->get_modbus_value(tag, modbusInfo->short_name, buf); if (error_code) { LOG_ERROR("Unable to read raw device value %s for tag=%d - error_code = %d", modbusInfo->short_name, (int)tag, error_code); @@ -505,13 +505,17 @@ int Modbus::getRegisterCount(const DeviceValue & dv) { case DeviceValue::CMD: { // calculate a sensible register size from min, max and numeric_operator - uint32_t num_values = std::max(dv.max, (uint32_t)abs(dv.min)); - int num_registers = 0; + uint32_t num_values = std::max(dv.max, (uint32_t)abs(dv.min)); + int num_registers = 0; - if (num_values <= (1L << 8)) num_registers = 1; - else if(num_values <= (1L << 16)) num_registers = 2; - else if(num_values <= (1L << 32)) num_registers = 4; - else LOG_ERROR("num_registers is too big to be encoded with modbus registers"); + if (num_values <= (1L << 8)) + num_registers = 1; + else if (num_values <= (1L << 16)) + num_registers = 2; + else if (num_values <= (1L << 32)) + num_registers = 4; + else + LOG_ERROR("num_registers is too big to be encoded with modbus registers"); LOG_DEBUG("Value for CMD '%s' can take on %ld values and is encoded in %d registers", dv.short_name, num_values, num_registers); diff --git a/src/test/test.cpp b/src/test/test.cpp index ae0357a7f..2594adc49 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -1878,7 +1878,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const return; } - const auto & boiler_dev = *boiler_it; + const auto & boiler_dev = *boiler_it; const auto & thermostat_dev = *thermostat_it; { @@ -2055,9 +2055,9 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const shell.println(); shell.printfln("Testing modbus->handleWrite() for boiler:"); - uint16_t reg = Modbus::REGISTER_BLOCK_SIZE * DeviceValueTAG::TAG_DEVICE_DATA + 4; // selflowtemp + uint16_t reg = Modbus::REGISTER_BLOCK_SIZE * DeviceValueTAG::TAG_DEVICE_DATA + 4; // selflowtemp ModbusMessage request({boiler_dev->device_type(), 0x06, static_cast(reg >> 8), static_cast(reg & 0xff), 0, 1, 2, 0, 45}); - auto response = EMSESP::modbus_->handleWrite(request); + auto response = EMSESP::modbus_->handleWrite(request); if (response.getError() == SUCCESS) { shell.print("selflowtemp MODBUS response:"); @@ -2076,8 +2076,9 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const shell.printfln("Testing modbus->handleWrite() for thermostat:"); uint16_t reg = Modbus::REGISTER_BLOCK_SIZE * DeviceValueTAG::TAG_HC1 + 41; // remotetemp - ModbusMessage request({thermostat_dev->device_type(), 0x06, static_cast(reg >> 8), static_cast(reg & 0xff), 0, 1, 2, 0, 45}); - auto response = EMSESP::modbus_->handleWrite(request); + ModbusMessage request( + {thermostat_dev->device_type(), 0x06, static_cast(reg >> 8), static_cast(reg & 0xff), 0, 1, 2, 0, 45}); + auto response = EMSESP::modbus_->handleWrite(request); if (response.getError() == SUCCESS) { shell.print("remotetemp MODBUS response:");