mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
auto-formatting
This commit is contained in:
@@ -2091,7 +2091,7 @@ int EMSdevice::modbus_value_to_json(uint8_t tag, const std::string & shortname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t value = 0;
|
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);
|
value += (uint32_t)modbus_data[modbus_data.size() - i - 1] << (i * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ class EMSdevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_modbus_value(uint8_t tag, const std::string & shortname, std::vector<uint16_t> & result);
|
int get_modbus_value(uint8_t tag, const std::string & shortname, std::vector<uint16_t> & result);
|
||||||
int modbus_value_to_json(uint8_t tag, const std::string & shortname, const std::vector<uint8_t> & modbus_data, JsonObject jsonValue);
|
int modbus_value_to_json(uint8_t tag, const std::string & shortname, const std::vector<uint8_t> & modbus_data, JsonObject jsonValue);
|
||||||
|
|
||||||
const char * brand_to_char();
|
const char * brand_to_char();
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ ModbusMessage Modbus::handleRead(const ModbusMessage & request) {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto buf = std::vector<uint16_t>(num_words);
|
auto buf = std::vector<uint16_t>(num_words);
|
||||||
auto error_code = dev->get_modbus_value(tag, modbusInfo->short_name, buf);
|
auto error_code = dev->get_modbus_value(tag, modbusInfo->short_name, buf);
|
||||||
if (error_code) {
|
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);
|
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: {
|
case DeviceValue::CMD: {
|
||||||
// calculate a sensible register size from min, max and numeric_operator
|
// calculate a sensible register size from min, max and numeric_operator
|
||||||
uint32_t num_values = std::max(dv.max, (uint32_t)abs(dv.min));
|
uint32_t num_values = std::max(dv.max, (uint32_t)abs(dv.min));
|
||||||
int num_registers = 0;
|
int num_registers = 0;
|
||||||
|
|
||||||
if (num_values <= (1L << 8)) num_registers = 1;
|
if (num_values <= (1L << 8))
|
||||||
else if(num_values <= (1L << 16)) num_registers = 2;
|
num_registers = 1;
|
||||||
else if(num_values <= (1L << 32)) num_registers = 4;
|
else if (num_values <= (1L << 16))
|
||||||
else LOG_ERROR("num_registers is too big to be encoded with modbus registers");
|
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);
|
LOG_DEBUG("Value for CMD '%s' can take on %ld values and is encoded in %d registers", dv.short_name, num_values, num_registers);
|
||||||
|
|
||||||
|
|||||||
@@ -1878,7 +1878,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto & boiler_dev = *boiler_it;
|
const auto & boiler_dev = *boiler_it;
|
||||||
const auto & thermostat_dev = *thermostat_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.println();
|
||||||
shell.printfln("Testing modbus->handleWrite() for boiler:");
|
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<unsigned char>(reg >> 8), static_cast<unsigned char>(reg & 0xff), 0, 1, 2, 0, 45});
|
ModbusMessage request({boiler_dev->device_type(), 0x06, static_cast<unsigned char>(reg >> 8), static_cast<unsigned char>(reg & 0xff), 0, 1, 2, 0, 45});
|
||||||
auto response = EMSESP::modbus_->handleWrite(request);
|
auto response = EMSESP::modbus_->handleWrite(request);
|
||||||
|
|
||||||
if (response.getError() == SUCCESS) {
|
if (response.getError() == SUCCESS) {
|
||||||
shell.print("selflowtemp MODBUS response:");
|
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:");
|
shell.printfln("Testing modbus->handleWrite() for thermostat:");
|
||||||
|
|
||||||
uint16_t reg = Modbus::REGISTER_BLOCK_SIZE * DeviceValueTAG::TAG_HC1 + 41; // remotetemp
|
uint16_t reg = Modbus::REGISTER_BLOCK_SIZE * DeviceValueTAG::TAG_HC1 + 41; // remotetemp
|
||||||
ModbusMessage request({thermostat_dev->device_type(), 0x06, static_cast<unsigned char>(reg >> 8), static_cast<unsigned char>(reg & 0xff), 0, 1, 2, 0, 45});
|
ModbusMessage request(
|
||||||
auto response = EMSESP::modbus_->handleWrite(request);
|
{thermostat_dev->device_type(), 0x06, static_cast<unsigned char>(reg >> 8), static_cast<unsigned char>(reg & 0xff), 0, 1, 2, 0, 45});
|
||||||
|
auto response = EMSESP::modbus_->handleWrite(request);
|
||||||
|
|
||||||
if (response.getError() == SUCCESS) {
|
if (response.getError() == SUCCESS) {
|
||||||
shell.print("remotetemp MODBUS response:");
|
shell.print("remotetemp MODBUS response:");
|
||||||
|
|||||||
Reference in New Issue
Block a user