Skip to content

Commit

Permalink
Merge pull request #238 from wirenboard/feature/34828-precision-rebase2
Browse files Browse the repository at this point in the history
* Support for precision and minimum value in channels
* /meta/precision and /meta/min topics for controls are added
  • Loading branch information
KraPete authored Jul 14, 2021
2 parents b06b578 + b8caa9a commit c8106fa
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 46 deletions.
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
wb-mqtt-serial (2.20.0) experimental; urgency=medium

* Support for minimum value in channels
* /meta/precision and /meta/min topics for controls are added

-- Petr Krasnoshchekov <petr.krasnoshchekov@wirenboard.ru> Wed, 14 Jul 2021 16:34:31 +0500

wb-mqtt-serial (2.19.2) stable; urgency=medium

* Configs with comments are sent to web-interface correctly
Expand Down
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Maintainer: Evgeny Boger <boger@contactless.ru>
Section: misc
Priority: optional
Standards-Version: 3.9.2
Build-Depends: debhelper (>= 10), pkg-config, libwbmqtt1-2-dev (>= 2.2.1), libwbmqtt1-2-test-utils (>= 2.2.1)
Build-Depends: debhelper (>= 10), pkg-config, libwbmqtt1-2-dev (>= 2.2.2), libwbmqtt1-2-test-utils (>= 2.2.2)
Homepage: https://github.com/wirenboard/wb-mqtt-serial

Package: wb-mqtt-serial
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, ucf, bsdutils (>= 2.29), libwbmqtt1-2 (>= 2.2.1)
Depends: ${shlibs:Depends}, ${misc:Depends}, ucf, bsdutils (>= 2.29), libwbmqtt1-2 (>= 2.2.2)
Replaces: wb-homa-modbus (<< 1.14.1)
Breaks: wb-homa-modbus (<< 1.14.1), wb-mqtt-confed (<< 1.2.5), wb-mqtt-homeui (<< 2.1.0)
Description: Wiren Board Smart Home MQTT serial protocol driver
Expand Down
33 changes: 27 additions & 6 deletions src/serial_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ namespace {
return GetIntFromString(v.asString(), title);
}

double ToDouble(const Json::Value& v, const std::string& title)
{
if (v.isNumeric())
return v.asDouble();
if (!v.isString()) {
throw TConfigParserException(title + ": number or '0x..' hex string expected");
}
return GetIntFromString(v.asString(), title);
}

uint64_t ToUint64(const Json::Value& v, const string& title)
{
if (v.isUInt())
Expand Down Expand Up @@ -111,6 +121,11 @@ namespace {
return ToInt(obj[key], key);
}

double GetDouble(const Json::Value& obj, const std::string& key)
{
return ToDouble(obj[key], key);
}

bool ReadChannelsReadonlyProperty(const Json::Value& register_data,
const std::string& key,
bool templateReadonly,
Expand Down Expand Up @@ -255,14 +270,21 @@ namespace {
on_value = std::to_string(GetInt(channel_data, "on_value"));
}

int max = -1;
if (channel_data.isMember("max"))
max = GetInt(channel_data, "max");

int order = device_config->NextOrderValue();
PDeviceChannelConfig channel(new TDeviceChannelConfig(name, type_str, device_config->Id, order,
on_value, max, registers[0]->ReadOnly, mqtt_channel_name,
on_value, registers[0]->ReadOnly, mqtt_channel_name,
registers));
if (channel_data.isMember("max")) {
channel->Max = GetDouble(channel_data, "max");
}
if (channel_data.isMember("min")) {
channel->Min = GetDouble(channel_data, "min");
}
if (registers.size() == 1) {
channel->Precision = registers[0]->RoundTo;
}

device_config->AddChannel(channel);
}

Expand Down Expand Up @@ -824,12 +846,11 @@ TDeviceChannelConfig::TDeviceChannelConfig(const std::string& name,
const std::string& deviceId,
int order,
const std::string& onValue,
int max,
bool readOnly,
const std::string& mqttId,
const std::vector<PRegisterConfig> regs)
: Name(name), MqttId(mqttId), Type(type), DeviceId(deviceId),
Order(order), OnValue(onValue), Max(max),
Order(order), OnValue(onValue),
ReadOnly(readOnly), RegisterConfigs(regs)
{}

Expand Down
5 changes: 3 additions & 2 deletions src/serial_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ struct TDeviceChannelConfig
std::string DeviceId;
int Order = 0;
std::string OnValue;
int Max = -1;
double Max =std::numeric_limits<double>::signaling_NaN();
double Min =std::numeric_limits<double>::signaling_NaN();
double Precision = 0;
bool ReadOnly = false;
std::vector<PRegisterConfig> RegisterConfigs;

Expand All @@ -33,7 +35,6 @@ struct TDeviceChannelConfig
const std::string& deviceId = "",
int order = 0,
const std::string& onValue = "",
int max = - 1,
bool readOnly = false,
const std::string& mqttId = "",
const std::vector<PRegisterConfig> regs = std::vector<PRegisterConfig>());
Expand Down
16 changes: 14 additions & 2 deletions src/serial_port_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,20 @@ TControlArgs TSerialPortDriver::From(const PDeviceChannel & channel)
.SetReadonly(channel->ReadOnly)
.SetUserData(TControlLinkData{ shared_from_this(), channel });

if (channel->Type == "range" || channel->Type == "dimmer") {
args.SetMax(channel->Max < 0 ? 65535 : channel->Max);
if (isnan(channel->Max)) {
if (channel->Type == "range" || channel->Type == "dimmer") {
args.SetMax(65535);
}
} else {
args.SetMax(channel->Max);
}

if (!isnan(channel->Min)) {
args.SetMin(channel->Min);
}

if (channel->Precision != 0.0) {
args.SetPrecision(channel->Precision);
}

return args;
Expand Down
Loading

0 comments on commit c8106fa

Please sign in to comment.