fixed wallbe plugin
parent
ed3d8ef258
commit
71e51e8337
|
|
@ -38,7 +38,7 @@ ModbusTCPMaster::ModbusTCPMaster(const QHostAddress &hostAddress, uint port, QOb
|
|||
m_modbusTcpClient = new QModbusTcpClient(this);
|
||||
m_modbusTcpClient->setConnectionParameter(QModbusDevice::NetworkPortParameter, port);
|
||||
m_modbusTcpClient->setConnectionParameter(QModbusDevice::NetworkAddressParameter, hostAddress.toString());
|
||||
m_modbusTcpClient->setTimeout(100);
|
||||
m_modbusTcpClient->setTimeout(1000);
|
||||
m_modbusTcpClient->setNumberOfRetries(3);
|
||||
|
||||
connect(m_modbusTcpClient, &QModbusTcpClient::stateChanged, this, &ModbusTCPMaster::onModbusStateChanged);
|
||||
|
|
@ -190,7 +190,7 @@ QUuid ModbusTCPMaster::writeHoldingRegisters(uint slaveAddress, uint registerAdd
|
|||
emit writeRequestError(requestId, reply->errorString());
|
||||
reply->finished(); // To make sure it will be deleted
|
||||
});
|
||||
QTimer::singleShot(200, reply, &QModbusReply::deleteLater);
|
||||
QTimer::singleShot(2000, reply, &QModbusReply::deleteLater);
|
||||
} else {
|
||||
delete reply; // broadcast replies return immediately
|
||||
return "";
|
||||
|
|
@ -234,7 +234,7 @@ QUuid ModbusTCPMaster::readDiscreteInput(uint slaveAddress, uint registerAddress
|
|||
emit writeRequestError(requestId, reply->errorString());
|
||||
reply->finished(); // To make sure it will be deleted
|
||||
});
|
||||
QTimer::singleShot(200, reply, &QModbusReply::deleteLater);
|
||||
QTimer::singleShot(2000, reply, &QModbusReply::deleteLater);
|
||||
} else {
|
||||
delete reply; // broadcast replies return immediately
|
||||
return "";
|
||||
|
|
@ -277,7 +277,7 @@ QUuid ModbusTCPMaster::readInputRegister(uint slaveAddress, uint registerAddress
|
|||
emit writeRequestError(requestId, reply->errorString());
|
||||
reply->finished(); // To make sure it will be deleted
|
||||
});
|
||||
QTimer::singleShot(200, reply, &QModbusReply::deleteLater);
|
||||
QTimer::singleShot(2000, reply, &QModbusReply::deleteLater);
|
||||
} else {
|
||||
delete reply; // broadcast replies return immediately
|
||||
return "";
|
||||
|
|
@ -321,7 +321,7 @@ QUuid ModbusTCPMaster::readHoldingRegister(uint slaveAddress, uint registerAddre
|
|||
emit writeRequestError(requestId, reply->errorString());
|
||||
reply->finished(); // To make sure it will be deleted
|
||||
});
|
||||
QTimer::singleShot(200, reply, &QModbusReply::deleteLater);
|
||||
QTimer::singleShot(2000, reply, &QModbusReply::deleteLater);
|
||||
} else {
|
||||
delete reply; // broadcast replies return immediately
|
||||
return "";
|
||||
|
|
@ -371,7 +371,7 @@ QUuid ModbusTCPMaster::writeCoils(uint slaveAddress, uint registerAddress, const
|
|||
emit writeRequestError(requestId, reply->errorString());
|
||||
reply->finished(); // To make sure it will be deleted
|
||||
});
|
||||
QTimer::singleShot(200, reply, &QModbusReply::deleteLater);
|
||||
QTimer::singleShot(2000, reply, &QModbusReply::deleteLater);
|
||||
} else {
|
||||
delete reply; // broadcast replies return immediately
|
||||
return "";
|
||||
|
|
@ -397,7 +397,7 @@ void ModbusTCPMaster::onModbusErrorOccurred(QModbusDevice::Error error)
|
|||
|
||||
void ModbusTCPMaster::onModbusStateChanged(QModbusDevice::State state)
|
||||
{
|
||||
bool connected = (state != QModbusDevice::UnconnectedState);
|
||||
bool connected = (state == QModbusDevice::ConnectedState);
|
||||
if (!connected) {
|
||||
//try to reconnect in 10 seconds
|
||||
m_reconnectTimer->start(10000);
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ void Discovery::discoveryFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|||
|
||||
if (isUp) {
|
||||
foundHosts++;
|
||||
qCDebug(dcWallbe()) << " - host:" << address;
|
||||
qCDebug(dcWallbe()) << " - host:" << vendor << address << macAddress;
|
||||
|
||||
Host *host = new Host();
|
||||
host->setAddress(address);
|
||||
|
|
@ -157,7 +157,7 @@ void Discovery::discoveryFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|||
arpLookup->start("arp", {"-vn"});
|
||||
}
|
||||
|
||||
host->setHostName(vendor);
|
||||
host->setVendor(vendor);
|
||||
QHostInfo::lookupHost(address, this, SLOT(hostLookupDone(QHostInfo)));
|
||||
m_pendingNameLookups.insert(address, host);
|
||||
|
||||
|
|
@ -32,26 +32,8 @@
|
|||
|
||||
Host::Host()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Host::Host(const QString &hostName, const QString &address, const QString &macAddress, const bool &reachable):
|
||||
m_hostName(hostName),
|
||||
m_address(address),
|
||||
m_macAddress(macAddress),
|
||||
m_reachable(reachable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString Host::hostName() const
|
||||
{
|
||||
return m_hostName;
|
||||
}
|
||||
|
||||
QString Host::address() const
|
||||
{
|
||||
return m_address;
|
||||
qRegisterMetaType<Host>();
|
||||
qRegisterMetaType<QList<Host> >();
|
||||
}
|
||||
|
||||
QString Host::macAddress() const
|
||||
|
|
@ -59,18 +41,64 @@ QString Host::macAddress() const
|
|||
return m_macAddress;
|
||||
}
|
||||
|
||||
void Host::setMacAddress(const QString &macAddress)
|
||||
{
|
||||
m_macAddress = macAddress;
|
||||
}
|
||||
|
||||
QString Host::hostName() const
|
||||
{
|
||||
return m_hostName;
|
||||
}
|
||||
|
||||
void Host::setHostName(const QString &hostName)
|
||||
{
|
||||
m_hostName = hostName;
|
||||
}
|
||||
|
||||
QString Host::vendor() const
|
||||
{
|
||||
return m_vendor;
|
||||
}
|
||||
|
||||
void Host::setVendor(const QString &vendor)
|
||||
{
|
||||
m_vendor = vendor;
|
||||
}
|
||||
|
||||
QString Host::address() const
|
||||
{
|
||||
return m_address;
|
||||
}
|
||||
|
||||
void Host::setAddress(const QString &address)
|
||||
{
|
||||
m_address = address;
|
||||
}
|
||||
|
||||
void Host::seen()
|
||||
{
|
||||
m_lastSeenTime = QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
QDateTime Host::lastSeenTime() const
|
||||
{
|
||||
return m_lastSeenTime;
|
||||
}
|
||||
|
||||
bool Host::reachable() const
|
||||
{
|
||||
return m_reachable;
|
||||
}
|
||||
|
||||
bool Host::isValid() const
|
||||
void Host::setReachable(bool reachable)
|
||||
{
|
||||
return !m_hostName.isEmpty() && !m_address.isEmpty();
|
||||
m_reachable = reachable;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Host &host)
|
||||
{
|
||||
dbg.nospace() << "Host(" << host.hostName() << ", " << host.address() << ", " << (host.reachable() ? "up" : "down") << ")";
|
||||
dbg.nospace() << "Host(" << host.macAddress() << "," << host.hostName() << ", " << host.address() << ", " << (host.reachable() ? "up" : "down") << ")";
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,27 +33,42 @@
|
|||
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
||||
class Host
|
||||
{
|
||||
public:
|
||||
Host();
|
||||
Host(const QString &hostName, const QString &address, const QString &macAddress, const bool &reachable);
|
||||
|
||||
QString macAddress() const;
|
||||
void setMacAddress(const QString &macAddress);
|
||||
|
||||
QString hostName() const;
|
||||
QString address() const;
|
||||
QString macAddress() const;
|
||||
bool reachable() const;
|
||||
void setHostName(const QString &hostName);
|
||||
|
||||
bool isValid() const;
|
||||
QString vendor() const;
|
||||
void setVendor(const QString &vendor);
|
||||
|
||||
QString address() const;
|
||||
void setAddress(const QString &address);
|
||||
|
||||
void seen();
|
||||
QDateTime lastSeenTime() const;
|
||||
|
||||
bool reachable() const;
|
||||
void setReachable(bool reachable);
|
||||
|
||||
private:
|
||||
QString m_macAddress;
|
||||
QString m_hostName;
|
||||
QString m_address;
|
||||
QString m_macAddress;
|
||||
QString m_vendor;
|
||||
QDateTime m_lastSeenTime;
|
||||
bool m_reachable;
|
||||
};
|
||||
Q_DECLARE_METATYPE(Host)
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Host &host);
|
||||
|
||||
#endif // HOST_H
|
||||
|
||||
|
|
|
|||
|
|
@ -45,26 +45,30 @@ IntegrationPluginWallbe::IntegrationPluginWallbe()
|
|||
|
||||
void IntegrationPluginWallbe::init() {
|
||||
|
||||
m_discovery = new Discover(QStringList("-xO" "-p 502"));
|
||||
m_discovery = new Discovery();
|
||||
connect(m_discovery, &Discovery::finished, this, [this](const QList<Host> &hosts) {
|
||||
foreach (const Host &host, hosts) {
|
||||
if (!host.vendor().contains("Phoenix", Qt::CaseSensitivity::CaseInsensitive))
|
||||
continue;
|
||||
|
||||
Q_FOREACH(Thing *existingThing, myThings()) {
|
||||
if (existingThing->paramValue(wallbeEcoThingMacAddressParamTypeId).toString().isEmpty()) {
|
||||
//This device got probably manually setup, to enable auto rediscovery the MAC address needs to setup
|
||||
if (existingThing->paramValue(wallbeEcoThingIpParamTypeId).toString() == host.address()) {
|
||||
qCDebug(dcWallbe()) << "Wallbe Wallbox MAC Address has been discovered" << existingThing->name() << host.macAddress();
|
||||
existingThing->setParamValue(wallbeEcoThingMacParamTypeId, host.macAddress());
|
||||
Q_FOREACH(Thing *existingThing, myThings()) {
|
||||
if (existingThing->paramValue(wallbeEcoThingMacParamTypeId).toString().isEmpty()) {
|
||||
//This device got probably manually setup, to enable auto rediscovery the MAC address needs to setup
|
||||
if (existingThing->paramValue(wallbeEcoThingIpParamTypeId).toString() == host.address()) {
|
||||
qCDebug(dcWallbe()) << "Wallbe Wallbox MAC Address has been discovered" << existingThing->name() << host.macAddress();
|
||||
existingThing->setParamValue(wallbeEcoThingMacParamTypeId, host.macAddress());
|
||||
|
||||
}
|
||||
} else if (existingThing->paramValue(wallbeEcoThingMacParamTypeId).toString() == host.macAddress()) {
|
||||
if (existingThing->paramValue(wallbeEcoThingIpParamTypeId).toString() != host.address()) {
|
||||
qCDebug(dcWallbe()) << "Wallbe Wallbox IP Address has changed, from" << existingThing->paramValue(wallbeEcoThingIpParamTypeId).toString() << "to" << host.address();
|
||||
existingThing->setParamValue(wallbeEcoThingIpParamTypeId, host.address());
|
||||
|
||||
} else {
|
||||
qCDebug(dcWallbe()) << "Wallbe Wallbox" << existingThing->name() << "IP address has not changed" << host.address();
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (existingThing->paramValue(wallbeEcoThingMacParamTypeId).toString() == host.macAddress()) {
|
||||
if (existingThing->paramValue(wallbeEcoThingIpParamTypeId).toString() != host.address()) {
|
||||
qCDebug(dcWallbe()) << "Wallbe Wallbox IP Address has changed, from" << existingThing->paramValue(wallbeEcoThingIpParamTypeId).toString() << "to" << host.address();
|
||||
existingThing->setParamValue(wallbeEcoThingIpParamTypeId, host.address());
|
||||
|
||||
} else {
|
||||
qCDebug(dcWallbe()) << "Wallbe Wallbox" << existingThing->name() << "IP address has not changed" << host.address();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -76,15 +80,24 @@ void IntegrationPluginWallbe::discoverThings(ThingDiscoveryInfo *info)
|
|||
if (info->thingClassId() == wallbeEcoThingClassId){
|
||||
qCDebug(dcWallbe) << "Start Wallbe eco discovery";
|
||||
|
||||
m_discovery->discoverHosts(25);
|
||||
connect(discover, &Discover::devicesDiscovered, this, [info, this](QList<Host> hosts){
|
||||
foreach (Host host, hosts) {
|
||||
ThingDescriptor descriptor;
|
||||
foreach(Thing *thing, myThings().filterByParam(wallbeEcoThingMacParamTypeId, host.macAddress())) {
|
||||
descriptor.setThingId(thing->id());
|
||||
break;
|
||||
m_discovery->discoverHosts(50);
|
||||
connect(m_discovery, &Discovery::finished, info, [this, info] (const QList<Host> &hosts) {
|
||||
|
||||
foreach (const Host &host, hosts) {
|
||||
if (!host.vendor().contains("Phoenix", Qt::CaseSensitivity::CaseInsensitive))
|
||||
continue;
|
||||
|
||||
ThingDescriptor descriptor(wallbeEcoThingClassId);
|
||||
// Rediscovery
|
||||
foreach (Thing *existingThing, myThings()) {
|
||||
if (existingThing->paramValue(wallbeEcoThingMacParamTypeId).toString() == host.macAddress()) {
|
||||
qCDebug(dcWallbe()) << " - Device is already added";
|
||||
descriptor.setThingId(existingThing->id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
descriptor.setTitle(host.hostName());
|
||||
descriptor.setTitle(host.hostName().remove(".localdomain"));
|
||||
descriptor.setDescription(host.address());
|
||||
ParamList params;
|
||||
params.append(Param(wallbeEcoThingIpParamTypeId, host.address()));
|
||||
params.append(Param(wallbeEcoThingMacParamTypeId, host.macAddress()));
|
||||
|
|
@ -104,12 +117,12 @@ void IntegrationPluginWallbe::setupThing(ThingSetupInfo *info)
|
|||
Thing *thing = info->thing();
|
||||
qCDebug(dcWallbe) << "Setting up a new device:" << thing->params();
|
||||
|
||||
if (info->thingClassId() == wallbeEcoThingClassId) {
|
||||
if (thing->thingClassId() == wallbeEcoThingClassId) {
|
||||
QHostAddress address(thing->paramValue(wallbeEcoThingIpParamTypeId).toString());
|
||||
|
||||
if (m_connections.contains(thing)) {
|
||||
qCDebug(dcWallbe()) << "Setup after reconfiguration, cleaning up ...";
|
||||
m_connnections.take(thing).deleteLater();)
|
||||
m_connections.take(thing)->deleteLater();
|
||||
}
|
||||
if (address.isNull()){
|
||||
qCWarning(dcWallbe) << "IP address is not valid";
|
||||
|
|
@ -118,34 +131,43 @@ void IntegrationPluginWallbe::setupThing(ThingSetupInfo *info)
|
|||
}
|
||||
ModbusTCPMaster *modbusTcpMaster = new ModbusTCPMaster(address, 502, this);
|
||||
connect(modbusTcpMaster, &ModbusTCPMaster::connectionStateChanged, this, &IntegrationPluginWallbe::onConnectionStateChanged);
|
||||
connect(modbusTcpMaster, &ModbusTCPMaster::receivedCoil, this, &IntegrationPluginWallbe::onReceivedCoil);
|
||||
connect(modbusTcpMaster, &ModbusTCPMaster::receivedInputRegister, this, &IntegrationPluginWallbe::onReceivedInputRegister);
|
||||
connect(modbusTcpMaster, &ModbusTCPMaster::receivedHoldingRegister, this, &IntegrationPluginWallbe::onReceivedHoldingRegister);
|
||||
connect(modbusTcpMaster, &ModbusTCPMaster::writeRequestExecuted, this, &IntegrationPluginWallbe::onWriteRequestExecuted);
|
||||
connect(modbusTcpMaster, &ModbusTCPMaster::writeRequestError, this, &IntegrationPluginWallbe::onWriteRequestError);
|
||||
connect(info, &ThingSetupInfo::aborted, modbusTcpMaster, &ModbusTCPMaster::deleteLater);
|
||||
|
||||
m_connections.insert(thing, modbusTcpMaster);
|
||||
connect(modbusTcpMaster, &ModbusTCPMaster::connectionStateChanged, info, [this, info, modbusTcpMaster](bool connected) {
|
||||
qCDebug(dcWallbe()) << "Modbus TCP connection changed, connected" << connected;
|
||||
if(connected) {
|
||||
m_connections.insert(info->thing(), modbusTcpMaster);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
} else {
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable);
|
||||
}
|
||||
});
|
||||
if (!modbusTcpMaster->connectDevice()) {
|
||||
qCWarning(dcWallbe()) << "Could not connect device";
|
||||
return info->finish(Thing::ThingErrorHardwareNotAvailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IntegrationPluginWallbe::postSetupThing(Thing *thing)
|
||||
{
|
||||
if (!m_pluginTimer) {
|
||||
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(120);
|
||||
connect(m_pluginTimer, &PluginTimer::timeout, this, [this] {
|
||||
foreach(Thing *thing, m_connections.keys()) {
|
||||
update(thing);
|
||||
}
|
||||
});
|
||||
}
|
||||
qCDebug(dcWallbe()) << "Post setup thing" << thing->name();
|
||||
|
||||
if (thing->thingClassId() == wallbeEcoThingClassId){
|
||||
if (!m_pluginTimer) {
|
||||
qCDebug(dcWallbe()) << "Starting plugin timer";
|
||||
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
|
||||
connect(m_pluginTimer, &PluginTimer::timeout, this, [this] {
|
||||
foreach(Thing *thing, m_connections.keys()) {
|
||||
update(thing);
|
||||
}
|
||||
});
|
||||
}
|
||||
thing->setStateValue(wallbeEcoConnectedStateTypeId, true);
|
||||
update(thing);
|
||||
} else {
|
||||
Q_ASSERT_X(false, "postSetupThing", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
||||
|
|
@ -172,10 +194,8 @@ void IntegrationPluginWallbe::executeAction(ThingActionInfo *info)
|
|||
|
||||
// get the param value of the charging action
|
||||
bool charging = action.param(wallbeEcoPowerActionPowerParamTypeId).value().toBool();
|
||||
qCDebug(dcWallbe) << "start Charging button" << thing->name() << "set power to" << charging;
|
||||
QUuid requestId = modbusTcpMaster->writeCoil(0xff, WallbeRegisterAddress::ChargingStatus, charging);
|
||||
// Set the "power" state
|
||||
thing->setStateValue(wallbeEcoPowerStateTypeId, charging);
|
||||
qCDebug(dcWallbe) << "Start Charging button" << thing->name() << "set power to" << charging;
|
||||
QUuid requestId = modbusTcpMaster->writeCoil(m_slaveAddress, WallbeRegisterAddress::EnableCharging, charging);
|
||||
m_asyncActions.insert(requestId, info);
|
||||
connect(info, &ThingActionInfo::aborted, this, [this, requestId] {m_asyncActions.remove(requestId);});
|
||||
|
||||
|
|
@ -183,8 +203,7 @@ void IntegrationPluginWallbe::executeAction(ThingActionInfo *info)
|
|||
|
||||
uint16_t current = action.param(wallbeEcoMaxChargingCurrentEventMaxChargingCurrentParamTypeId).value().toUInt();
|
||||
qCDebug(dcWallbe) << "Charging power set to" << current;
|
||||
QUuid requestId = modbusTcpMaster->writeCoil(0xff, WallbeRegisterAddress::ChargingCurrent, current);
|
||||
thing->setStateValue(wallbeEcoMaxChargingCurrentStateTypeId, current);
|
||||
QUuid requestId = modbusTcpMaster->writeHoldingRegister(m_slaveAddress, WallbeRegisterAddress::ChargingCurrent, current);
|
||||
m_asyncActions.insert(requestId, info);
|
||||
connect(info, &ThingActionInfo::aborted, this, [this, requestId] {m_asyncActions.remove(requestId);});
|
||||
|
||||
|
|
@ -215,12 +234,16 @@ void IntegrationPluginWallbe::thingRemoved(Thing *thing)
|
|||
void IntegrationPluginWallbe::update(Thing *thing)
|
||||
{
|
||||
ModbusTCPMaster *modbusTCPMaster = m_connections.value(thing);
|
||||
if(!modbusTCPMaster)
|
||||
if(!modbusTCPMaster) {
|
||||
qCWarning(dcWallbe()) << "Modbus TCP connection not found for" << thing->name();
|
||||
return;
|
||||
modbusTCPMaster->readHoldingRegister(0xff, WallbeRegisterAddress::EVStatus);
|
||||
modbusTCPMaster->readHoldingRegister(0xff, WallbeRegisterAddress::ChargingCurrent);
|
||||
modbusTCPMaster->readHoldingRegister(0xff, WallbeRegisterAddress::ChargingStatus);
|
||||
modbusTCPMaster->readHoldingRegister(0xff, WallbeRegisterAddress::ChargingTime);
|
||||
}
|
||||
modbusTCPMaster->readInputRegister(m_slaveAddress, WallbeRegisterAddress::EVStatus, 1);
|
||||
modbusTCPMaster->readInputRegister(m_slaveAddress, WallbeRegisterAddress::FirmwareVersion, 2);
|
||||
modbusTCPMaster->readInputRegister(m_slaveAddress, WallbeRegisterAddress::ChargingTime, 2);
|
||||
|
||||
modbusTCPMaster->readHoldingRegister(m_slaveAddress, WallbeRegisterAddress::ChargingCurrent, 1);
|
||||
modbusTCPMaster->readCoil(m_slaveAddress, WallbeRegisterAddress::EnableCharging, 1);
|
||||
}
|
||||
|
||||
void IntegrationPluginWallbe::onConnectionStateChanged(bool status)
|
||||
|
|
@ -232,16 +255,14 @@ void IntegrationPluginWallbe::onConnectionStateChanged(bool status)
|
|||
thing->setStateValue(wallbeEcoConnectedStateTypeId, status);
|
||||
}
|
||||
|
||||
void IntegrationPluginWallbe::onReceivedHoldingRegister(int slaveAddress, int modbusRegister, const QVector<quint16> &value)
|
||||
void IntegrationPluginWallbe::onReceivedInputRegister(int slaveAddress, int modbusRegister, const QVector<quint16> &value)
|
||||
{
|
||||
Q_UNUSED(slaveAddress)
|
||||
ModbusTCPMaster *modbusTCPMaster = static_cast<ModbusTCPMaster *>(sender());
|
||||
Thing *thing = m_connections.key(modbusTCPMaster);
|
||||
if (!thing)
|
||||
return;
|
||||
|
||||
switch (WallbeRegisterAddress(modbusRegister)) {
|
||||
case WallbeRegisterAddress::EVStatus:
|
||||
if (WallbeRegisterAddress(modbusRegister) == WallbeRegisterAddress::EVStatus) {
|
||||
//EV state - 16 bit ASCII (8bit)
|
||||
switch (value[0]) {
|
||||
case 65:
|
||||
|
|
@ -265,28 +286,64 @@ void IntegrationPluginWallbe::onReceivedHoldingRegister(int slaveAddress, int mo
|
|||
default:
|
||||
thing->setStateValue(wallbeEcoEvStatusStateTypeId, "F - Supply equipment not available");
|
||||
}
|
||||
break;
|
||||
case WallbeRegisterAddress::ChargingStatus:
|
||||
thing->setStateValue(wallbeEcoPowerStateTypeId, value[0]);
|
||||
break;
|
||||
case WallbeRegisterAddress::ChargingTime: {
|
||||
} else if (WallbeRegisterAddress(modbusRegister) == WallbeRegisterAddress::ChargingTime) {
|
||||
// Extract Input Register 102 - load time - 32bit integer
|
||||
int minutes = (((uint32_t)(value[0]<<16)|(uint32_t)(value[1]))/60); //Converts to minutes
|
||||
thing->setStateValue(wallbeEcoChargeTimeStateTypeId, minutes);
|
||||
|
||||
if (value.length() >= 2) {
|
||||
int minutes = (((uint32_t)(value[1]<<16)|(uint32_t)(value[0]))/60); //Converts to minutes
|
||||
qCDebug(dcWallbe()) << " - Charging time:" << minutes << "[min]";
|
||||
thing->setStateValue(wallbeEcoChargeTimeStateTypeId, minutes);
|
||||
}
|
||||
} else if (WallbeRegisterAddress(modbusRegister) == WallbeRegisterAddress::FirmwareVersion) {
|
||||
int firmware = (uint32_t)(value[1]<<16)|(uint32_t)(value[0]);
|
||||
uint major = firmware/10000;
|
||||
uint minor = (firmware%10000)/100;
|
||||
uint patch = firmware%100;
|
||||
QString firmwarestring = QString::number(major)+'.'+QString::number(minor)+'.'+QString::number(patch);
|
||||
thing->setStateValue(wallbeEcoFirmwareVersionStateTypeId, firmwarestring);
|
||||
}
|
||||
break;
|
||||
case WallbeRegisterAddress::ChargingCurrent:
|
||||
}
|
||||
|
||||
void IntegrationPluginWallbe::onReceivedCoil(int slaveAddress, int modbusRegister, const QVector<quint16> &value)
|
||||
{
|
||||
Q_UNUSED(slaveAddress)
|
||||
ModbusTCPMaster *modbusTCPMaster = static_cast<ModbusTCPMaster *>(sender());
|
||||
Thing *thing = m_connections.key(modbusTCPMaster);
|
||||
if (!thing)
|
||||
return;
|
||||
if (WallbeRegisterAddress(modbusRegister) == WallbeRegisterAddress::EnableCharging) {
|
||||
qCDebug(dcWallbe()) << " - Enable charging:" << (value[0] != 0);
|
||||
thing->setStateValue(wallbeEcoPowerStateTypeId, (value[0] != 0));
|
||||
}
|
||||
}
|
||||
|
||||
void IntegrationPluginWallbe::onReceivedHoldingRegister(int slaveAddress, int modbusRegister, const QVector<quint16> &value)
|
||||
{
|
||||
Q_UNUSED(slaveAddress)
|
||||
ModbusTCPMaster *modbusTCPMaster = static_cast<ModbusTCPMaster *>(sender());
|
||||
Thing *thing = m_connections.key(modbusTCPMaster);
|
||||
if (!thing)
|
||||
return;
|
||||
|
||||
switch (WallbeRegisterAddress(modbusRegister)) {
|
||||
|
||||
case WallbeRegisterAddress::ChargingCurrent: {
|
||||
qCDebug(dcWallbe()) << " - Charging current:" << value[0] << "[A]";
|
||||
thing->setStateValue(wallbeEcoMaxChargingCurrentStateTypeId, value[0]);
|
||||
break;
|
||||
case WallbeRegisterAddress::ErrorCode:
|
||||
} break;
|
||||
case WallbeRegisterAddress::ErrorCode: {
|
||||
qCDebug(dcWallbe()) << "Received Error Code modbus register" << value[0];
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void IntegrationPluginWallbe::onWriteRequestExecuted(const QUuid &requestId, bool success)
|
||||
{
|
||||
if (m_asyncActions.contains(requestId)) {
|
||||
qCDebug(dcWallbe()) << "Write request executed" << requestId << success;
|
||||
ThingActionInfo *info = m_asyncActions.value(requestId);
|
||||
if (success) {
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
#include "plugintimer.h"
|
||||
|
||||
#include "host.h"
|
||||
#include "discover.h"
|
||||
#include "discovery.h"
|
||||
#include "../modbus/modbustcpmaster.h"
|
||||
|
||||
#include <QObject>
|
||||
|
|
@ -52,10 +52,16 @@ public:
|
|||
enum WallbeRegisterAddress {
|
||||
EVStatus = 100,
|
||||
ChargingTime = 102,
|
||||
FirmwareVersion = 105,
|
||||
ErrorCode = 107,
|
||||
ChargingCurrent = 300,
|
||||
ChargingStatus = 400,
|
||||
EnableCharging = 400,
|
||||
Output1 = 405,
|
||||
Output2 = 406,
|
||||
Output3 = 407,
|
||||
Output4 = 408
|
||||
};
|
||||
Q_ENUM(WallbeRegisterAddress)
|
||||
|
||||
explicit IntegrationPluginWallbe();
|
||||
void init() override;
|
||||
|
|
@ -66,14 +72,18 @@ public:
|
|||
void thingRemoved(Thing *thing) override;
|
||||
|
||||
private:
|
||||
Discovery *m_discovery = nullptr;
|
||||
QHash<Thing *, ModbusTCPMaster *> m_connections;
|
||||
PluginTimer *m_pluginTimer = nullptr;
|
||||
QHash<QUuid, ThingActionInfo *> m_asyncActions;
|
||||
int m_slaveAddress = 180;
|
||||
|
||||
void update(Thing *thing);
|
||||
|
||||
private slots:
|
||||
void onConnectionStateChanged(bool status);
|
||||
void onReceivedInputRegister(int slaveAddress, int modbusRegister, const QVector<quint16> &value);
|
||||
void onReceivedCoil(int slaveAddress, int modbusRegister, const QVector<quint16> &value);
|
||||
void onReceivedHoldingRegister(int slaveAddress, int modbusRegister, const QVector<quint16> &value);
|
||||
|
||||
void onWriteRequestExecuted(const QUuid &requestId, bool success);
|
||||
|
|
|
|||
|
|
@ -88,6 +88,14 @@
|
|||
"maxValue": 80,
|
||||
"defaultValue": 6,
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"id": "f4c822a0-454b-4782-85d2-8c60bacb4fe8",
|
||||
"displayName": "Firmware version",
|
||||
"displayNameEvent": "Firmware version changed",
|
||||
"name": "firmwareVersion",
|
||||
"type": "QString",
|
||||
"defaultValue": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ QT += \
|
|||
SOURCES += \
|
||||
integrationpluginwallbe.cpp \
|
||||
../modbus/modbustcpmaster.cpp \
|
||||
host.cpp \
|
||||
discover.cpp
|
||||
discovery.cpp \
|
||||
host.cpp
|
||||
|
||||
HEADERS += \
|
||||
integrationpluginwallbe.h \
|
||||
../modbus/modbustcpmaster.h \
|
||||
host.h \
|
||||
discover.h
|
||||
discovery.h \
|
||||
host.h
|
||||
|
|
|
|||
Loading…
Reference in New Issue