Merge PR #482: Keba: Rework commands and connection status handling
This commit is contained in:
commit
7d4b8ff2ee
@ -49,19 +49,19 @@ void IntegrationPluginKeba::init()
|
|||||||
void IntegrationPluginKeba::discoverThings(ThingDiscoveryInfo *info)
|
void IntegrationPluginKeba::discoverThings(ThingDiscoveryInfo *info)
|
||||||
{
|
{
|
||||||
if (info->thingClassId() == wallboxThingClassId) {
|
if (info->thingClassId() == wallboxThingClassId) {
|
||||||
qCDebug(dcKebaKeContact()) << "Discovering Keba Wallbox";
|
qCDebug(dcKeba()) << "Discovering Keba Wallbox...";
|
||||||
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
|
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
|
||||||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
||||||
ThingDescriptors descriptors;
|
ThingDescriptors descriptors;
|
||||||
qCDebug(dcKebaKeContact()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
|
qCDebug(dcKeba()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
|
||||||
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
|
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
|
||||||
if (!networkDeviceInfo.macAddressManufacturer().contains("keba", Qt::CaseSensitivity::CaseInsensitive))
|
if (!networkDeviceInfo.macAddressManufacturer().contains("keba", Qt::CaseSensitivity::CaseInsensitive))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
qCDebug(dcKebaKeContact()) << " - Keba Wallbox" << networkDeviceInfo;
|
qCDebug(dcKeba()) << " - Keba Wallbox" << networkDeviceInfo;
|
||||||
QString title = "Wallbox ";
|
QString title = "Keba Wallbox ";
|
||||||
if (networkDeviceInfo.hostName().isEmpty()) {
|
if (networkDeviceInfo.hostName().isEmpty()) {
|
||||||
title += networkDeviceInfo.address().toString();
|
title += "(" + networkDeviceInfo.address().toString() + ")";
|
||||||
} else {
|
} else {
|
||||||
title += networkDeviceInfo.hostName() + " (" + networkDeviceInfo.address().toString() + ")";
|
title += networkDeviceInfo.hostName() + " (" + networkDeviceInfo.address().toString() + ")";
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ void IntegrationPluginKeba::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
// Check if we already have set up this device
|
// Check if we already have set up this device
|
||||||
Things existingThings = myThings().filterByParam(wallboxThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
Things existingThings = myThings().filterByParam(wallboxThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
||||||
if (existingThings.count() == 1) {
|
if (existingThings.count() == 1) {
|
||||||
qCDebug(dcKebaKeContact()) << "This wallbox already exists in the system!" << networkDeviceInfo;
|
qCDebug(dcKeba()) << "This wallbox already exists in the system!" << networkDeviceInfo;
|
||||||
descriptor.setThingId(existingThings.first()->id());
|
descriptor.setThingId(existingThings.first()->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ void IntegrationPluginKeba::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcKebaKeContact()) << "Discover device, unhandled device class" << info->thingClassId();
|
qCWarning(dcKeba()) << "Could not discover things because of unhandled thing class id" << info->thingClassId().toString();
|
||||||
info->finish(Thing::ThingErrorThingClassNotFound);
|
info->finish(Thing::ThingErrorThingClassNotFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,24 +100,34 @@ void IntegrationPluginKeba::discoverThings(ThingDiscoveryInfo *info)
|
|||||||
void IntegrationPluginKeba::setupThing(ThingSetupInfo *info)
|
void IntegrationPluginKeba::setupThing(ThingSetupInfo *info)
|
||||||
{
|
{
|
||||||
Thing *thing = info->thing();
|
Thing *thing = info->thing();
|
||||||
|
|
||||||
qCDebug(dcKebaKeContact()) << "Setting up a new thing:" << thing->name() << thing->params();
|
|
||||||
|
|
||||||
if (thing->thingClassId() == wallboxThingClassId) {
|
if (thing->thingClassId() == wallboxThingClassId) {
|
||||||
|
|
||||||
if(!m_kebaData){
|
// Handle reconfigure
|
||||||
qCDebug(dcKebaKeContact()) << "Creating new Keba data layer";
|
if (myThings().contains(thing)) {
|
||||||
m_kebaData = new KeContactDataLayer(this);
|
KeContact *keba = m_kebaDevices.take(thing->id());
|
||||||
if (!m_kebaData->init()) {
|
if (keba) {
|
||||||
m_kebaData->deleteLater();
|
qCDebug(dcKeba()) << "Reconfigure" << thing->name() << thing->params();
|
||||||
m_kebaData = nullptr;
|
delete keba;
|
||||||
connect(info, &ThingSetupInfo::aborted, m_kebaData, &KeContactDataLayer::deleteLater); // Clean up if the setup fails
|
// Now continue with the normal setup
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qCDebug(dcKeba()) << "Setting up" << thing->name() << thing->params();
|
||||||
|
|
||||||
|
if (!m_kebaDataLayer){
|
||||||
|
qCDebug(dcKeba()) << "Creating new Keba data layer...";
|
||||||
|
m_kebaDataLayer= new KeContactDataLayer(this);
|
||||||
|
if (!m_kebaDataLayer->init()) {
|
||||||
|
m_kebaDataLayer->deleteLater();
|
||||||
|
m_kebaDataLayer = nullptr;
|
||||||
|
connect(info, &ThingSetupInfo::aborted, m_kebaDataLayer, &KeContactDataLayer::deleteLater); // Clean up if the setup fails
|
||||||
return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Error opening network port."));
|
return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Error opening network port."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QHostAddress address = QHostAddress(thing->paramValue(wallboxThingIpAddressParamTypeId).toString());
|
QHostAddress address = QHostAddress(thing->paramValue(wallboxThingIpAddressParamTypeId).toString());
|
||||||
KeContact *keba = new KeContact(address, m_kebaData, m_kebaData);
|
|
||||||
|
KeContact *keba = new KeContact(address, m_kebaDataLayer, this);
|
||||||
connect(keba, &KeContact::reachableChanged, this, &IntegrationPluginKeba::onConnectionChanged);
|
connect(keba, &KeContact::reachableChanged, this, &IntegrationPluginKeba::onConnectionChanged);
|
||||||
connect(keba, &KeContact::commandExecuted, this, &IntegrationPluginKeba::onCommandExecuted);
|
connect(keba, &KeContact::commandExecuted, this, &IntegrationPluginKeba::onCommandExecuted);
|
||||||
connect(keba, &KeContact::reportTwoReceived, this, &IntegrationPluginKeba::onReportTwoReceived);
|
connect(keba, &KeContact::reportTwoReceived, this, &IntegrationPluginKeba::onReportTwoReceived);
|
||||||
@ -125,16 +135,15 @@ void IntegrationPluginKeba::setupThing(ThingSetupInfo *info)
|
|||||||
connect(keba, &KeContact::report1XXReceived, this, &IntegrationPluginKeba::onReport1XXReceived);
|
connect(keba, &KeContact::report1XXReceived, this, &IntegrationPluginKeba::onReport1XXReceived);
|
||||||
connect(keba, &KeContact::broadcastReceived, this, &IntegrationPluginKeba::onBroadcastReceived);
|
connect(keba, &KeContact::broadcastReceived, this, &IntegrationPluginKeba::onBroadcastReceived);
|
||||||
|
|
||||||
keba->getReport1();
|
|
||||||
connect(keba, &KeContact::reportOneReceived, info, [info, this, keba] (const KeContact::ReportOne &report) {
|
connect(keba, &KeContact::reportOneReceived, info, [info, this, keba] (const KeContact::ReportOne &report) {
|
||||||
Thing *thing = info->thing();
|
Thing *thing = info->thing();
|
||||||
|
|
||||||
qCDebug(dcKebaKeContact()) << "Report one received for" << thing->name();
|
qCDebug(dcKeba()) << "Report one received for" << thing->name();
|
||||||
qCDebug(dcKebaKeContact()) << " - Firmware" << report.firmware;
|
qCDebug(dcKeba()) << " - Firmware" << report.firmware;
|
||||||
qCDebug(dcKebaKeContact()) << " - Serial" << report.serialNumber;
|
qCDebug(dcKeba()) << " - Serial" << report.serialNumber;
|
||||||
qCDebug(dcKebaKeContact()) << " - Product" << report.product;
|
qCDebug(dcKeba()) << " - Product" << report.product;
|
||||||
qCDebug(dcKebaKeContact()) << " - Uptime" << report.seconds/60 << "[min]";
|
qCDebug(dcKeba()) << " - Uptime" << report.seconds/60 << "[min]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Com Module" << report.comModule;
|
qCDebug(dcKeba()) << " - Com Module" << report.comModule;
|
||||||
|
|
||||||
thing->setStateValue(wallboxConnectedStateTypeId, true);
|
thing->setStateValue(wallboxConnectedStateTypeId, true);
|
||||||
thing->setStateValue(wallboxFirmwareStateTypeId, report.firmware);
|
thing->setStateValue(wallboxFirmwareStateTypeId, report.firmware);
|
||||||
@ -145,45 +154,49 @@ void IntegrationPluginKeba::setupThing(ThingSetupInfo *info)
|
|||||||
m_kebaDevices.insert(thing->id(), keba);
|
m_kebaDevices.insert(thing->id(), keba);
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
keba->getReport1();
|
||||||
|
|
||||||
connect(info, &ThingSetupInfo::aborted, keba, &KeContact::deleteLater); // Clean up if the setup fails
|
connect(info, &ThingSetupInfo::aborted, keba, &KeContact::deleteLater); // Clean up if the setup fails
|
||||||
connect(keba, &KeContact::destroyed, this, [thing, this]{
|
connect(keba, &KeContact::destroyed, this, [thing, this]{
|
||||||
m_kebaDevices.remove(thing->id());
|
m_kebaDevices.remove(thing->id());
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcKebaKeContact()) << "setupDevice, unhandled device class" << thing->thingClass();
|
qCWarning(dcKeba()) << "Could not setup thing: unhandled device class" << thing->thingClass();
|
||||||
info->finish(Thing::ThingErrorThingClassNotFound);
|
info->finish(Thing::ThingErrorThingClassNotFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginKeba::postSetupThing(Thing *thing)
|
void IntegrationPluginKeba::postSetupThing(Thing *thing)
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "Post setup" << thing->name();
|
qCDebug(dcKeba()) << "Post setup" << thing->name();
|
||||||
if (thing->thingClassId() != wallboxThingClassId) {
|
if (thing->thingClassId() != wallboxThingClassId) {
|
||||||
qCWarning(dcKebaKeContact()) << "Thing class id not supported" << thing->thingClassId();
|
qCWarning(dcKeba()) << "Thing class id not supported" << thing->thingClassId();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
thing->setStateValue(wallboxConnectedStateTypeId, true);
|
|
||||||
KeContact *keba = m_kebaDevices.value(thing->id());
|
KeContact *keba = m_kebaDevices.value(thing->id());
|
||||||
if (!keba) {
|
if (!keba) {
|
||||||
qCWarning(dcKebaKeContact()) << "No Keba connection found for this thing";
|
qCWarning(dcKeba()) << "No Keba connection found for this thing";
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
keba->getReport2();
|
keba->getReport2();
|
||||||
keba->getReport3();
|
keba->getReport3();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thing->paramValue(wallboxThingMacAddressParamTypeId).toString().isEmpty()) {
|
// Try to find the mac address in case the user added the ip manually
|
||||||
|
if (thing->paramValue(wallboxThingMacAddressParamTypeId).toString().isEmpty() || thing->paramValue(wallboxThingMacAddressParamTypeId).toString() == "00:00:00:00:00:00") {
|
||||||
searchNetworkDevices();
|
searchNetworkDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_updateTimer) {
|
if (!m_updateTimer) {
|
||||||
m_updateTimer = hardwareManager()->pluginTimerManager()->registerTimer(60);
|
m_updateTimer = hardwareManager()->pluginTimerManager()->registerTimer(60);
|
||||||
connect(m_updateTimer, &PluginTimer::timeout, this, [this] {
|
connect(m_updateTimer, &PluginTimer::timeout, this, [this]() {
|
||||||
|
|
||||||
foreach (Thing *thing, myThings().filterByThingClassId(wallboxThingClassId)) {
|
foreach (Thing *thing, myThings().filterByThingClassId(wallboxThingClassId)) {
|
||||||
KeContact *keba = m_kebaDevices.value(thing->id());
|
KeContact *keba = m_kebaDevices.value(thing->id());
|
||||||
if (!keba) {
|
if (!keba) {
|
||||||
qCWarning(dcKebaKeContact()) << "No Keba connection found for" << thing->name();
|
qCWarning(dcKeba()) << "No Keba connection found for" << thing->name();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keba->getReport2();
|
keba->getReport2();
|
||||||
@ -193,34 +206,55 @@ void IntegrationPluginKeba::postSetupThing(Thing *thing)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m_updateTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_reconnectTimer) {
|
if (!m_reconnectTimer) {
|
||||||
m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer(60*5);
|
m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer(60*5);
|
||||||
connect(m_reconnectTimer, &PluginTimer::timeout, this, [this] {
|
connect(m_reconnectTimer, &PluginTimer::timeout, this, [this] {
|
||||||
searchNetworkDevices();
|
// Only search for new network devices if there is one keba which is not connected
|
||||||
|
foreach (Thing *thing, myThings().filterByThingClassId(wallboxThingClassId)) {
|
||||||
|
KeContact *keba = m_kebaDevices.value(thing->id());
|
||||||
|
if (!keba) {
|
||||||
|
qCWarning(dcKeba()) << "No Keba connection found for" << thing->name();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keba->reachable()) {
|
||||||
|
searchNetworkDevices();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m_reconnectTimer->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginKeba::thingRemoved(Thing *thing)
|
void IntegrationPluginKeba::thingRemoved(Thing *thing)
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "Deleting" << thing->name();
|
qCDebug(dcKeba()) << "Deleting" << thing->name();
|
||||||
if (thing->thingClassId() == wallboxThingClassId) {
|
if (thing->thingClassId() == wallboxThingClassId) {
|
||||||
KeContact *keba = m_kebaDevices.take(thing->id());
|
KeContact *keba = m_kebaDevices.take(thing->id());
|
||||||
keba->deleteLater();
|
keba->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myThings().empty()) {
|
if (myThings().empty()) {
|
||||||
qCDebug(dcKebaKeContact()) << "Closing UDP Ports";
|
qCDebug(dcKeba()) << "Closing UDP Ports";
|
||||||
m_kebaData->deleteLater();
|
m_kebaDataLayer->deleteLater();
|
||||||
m_kebaData = nullptr;
|
m_kebaDataLayer= nullptr;
|
||||||
|
|
||||||
qCDebug(dcKebaKeContact()) << "Stopping plugin timers";
|
qCDebug(dcKeba()) << "Stopping plugin timers ...";
|
||||||
hardwareManager()->pluginTimerManager()->unregisterTimer(m_reconnectTimer);
|
if (m_reconnectTimer) {
|
||||||
m_reconnectTimer = nullptr;
|
hardwareManager()->pluginTimerManager()->unregisterTimer(m_reconnectTimer);
|
||||||
hardwareManager()->pluginTimerManager()->unregisterTimer(m_updateTimer);
|
m_reconnectTimer = nullptr;
|
||||||
m_updateTimer = nullptr;
|
}
|
||||||
|
|
||||||
|
if (m_updateTimer) {
|
||||||
|
hardwareManager()->pluginTimerManager()->unregisterTimer(m_updateTimer);
|
||||||
|
m_updateTimer = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,11 +311,11 @@ void IntegrationPluginKeba::setDevicePlugState(Thing *thing, KeContact::PlugStat
|
|||||||
|
|
||||||
void IntegrationPluginKeba::searchNetworkDevices()
|
void IntegrationPluginKeba::searchNetworkDevices()
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "Start searching for things...";
|
qCDebug(dcKeba()) << "Start searching for things...";
|
||||||
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
|
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
|
||||||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
||||||
ThingDescriptors descriptors;
|
ThingDescriptors descriptors;
|
||||||
qCDebug(dcKebaKeContact()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
|
qCDebug(dcKeba()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
|
||||||
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
|
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
|
||||||
if (!networkDeviceInfo.hostName().contains("keba", Qt::CaseSensitivity::CaseInsensitive))
|
if (!networkDeviceInfo.hostName().contains("keba", Qt::CaseSensitivity::CaseInsensitive))
|
||||||
continue;
|
continue;
|
||||||
@ -290,21 +324,22 @@ void IntegrationPluginKeba::searchNetworkDevices()
|
|||||||
if (existingThing->paramValue(wallboxThingMacAddressParamTypeId).toString().isEmpty()) {
|
if (existingThing->paramValue(wallboxThingMacAddressParamTypeId).toString().isEmpty()) {
|
||||||
//This device got probably manually setup, to enable auto rediscovery the MAC address needs to setup
|
//This device got probably manually setup, to enable auto rediscovery the MAC address needs to setup
|
||||||
if (existingThing->paramValue(wallboxThingIpAddressParamTypeId).toString() == networkDeviceInfo.address().toString()) {
|
if (existingThing->paramValue(wallboxThingIpAddressParamTypeId).toString() == networkDeviceInfo.address().toString()) {
|
||||||
qCDebug(dcKebaKeContact()) << "Keba Wallbox MAC Address has been discovered" << existingThing->name() << networkDeviceInfo.macAddress();
|
qCDebug(dcKeba()) << "Keba Wallbox MAC Address has been discovered" << existingThing->name() << networkDeviceInfo.macAddress();
|
||||||
existingThing->setParamValue(wallboxThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
existingThing->setParamValue(wallboxThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
||||||
}
|
}
|
||||||
} else if (existingThing->paramValue(wallboxThingMacAddressParamTypeId).toString() == networkDeviceInfo.macAddress()) {
|
} else if (existingThing->paramValue(wallboxThingMacAddressParamTypeId).toString() == networkDeviceInfo.macAddress()) {
|
||||||
|
// We found the existing keba thing, lets check if the ip has changed
|
||||||
if (existingThing->paramValue(wallboxThingIpAddressParamTypeId).toString() != networkDeviceInfo.address().toString()) {
|
if (existingThing->paramValue(wallboxThingIpAddressParamTypeId).toString() != networkDeviceInfo.address().toString()) {
|
||||||
qCDebug(dcKebaKeContact()) << "Keba Wallbox IP Address has changed, from" << existingThing->paramValue(wallboxThingIpAddressParamTypeId).toString() << "to" << networkDeviceInfo.address().toString();
|
qCDebug(dcKeba()) << "Keba Wallbox IP Address has changed, from" << existingThing->paramValue(wallboxThingIpAddressParamTypeId).toString() << "to" << networkDeviceInfo.address().toString();
|
||||||
existingThing->setParamValue(wallboxThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
|
existingThing->setParamValue(wallboxThingIpAddressParamTypeId, networkDeviceInfo.address().toString());
|
||||||
KeContact *keba = m_kebaDevices.value(existingThing->id());
|
KeContact *keba = m_kebaDevices.value(existingThing->id());
|
||||||
if (keba) {
|
if (keba) {
|
||||||
keba->setAddress(QHostAddress(networkDeviceInfo.address()));
|
keba->setAddress(QHostAddress(networkDeviceInfo.address()));
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcKebaKeContact()) << "Could not update IP address, for" << existingThing;
|
qCWarning(dcKeba()) << "Could not update IP address, for" << existingThing;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCDebug(dcKebaKeContact()) << "Keba Wallbox" << existingThing->name() << "IP address has not changed" << networkDeviceInfo.address().toString();
|
qCDebug(dcKeba()) << "Keba Wallbox" << existingThing->name() << "IP address has not changed" << networkDeviceInfo.address().toString();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -318,9 +353,10 @@ void IntegrationPluginKeba::onConnectionChanged(bool status)
|
|||||||
KeContact *keba = static_cast<KeContact *>(sender());
|
KeContact *keba = static_cast<KeContact *>(sender());
|
||||||
Thing *thing = myThings().findById(m_kebaDevices.key(keba));
|
Thing *thing = myThings().findById(m_kebaDevices.key(keba));
|
||||||
if (!thing) {
|
if (!thing) {
|
||||||
qCWarning(dcKebaKeContact()) << "On connection changed: missing device object";
|
qCDebug(dcKeba()) << "Received connected changed but the thing seems not to be setup yet.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
thing->setStateValue(wallboxConnectedStateTypeId, status);
|
thing->setStateValue(wallboxConnectedStateTypeId, status);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
searchNetworkDevices();
|
searchNetworkDevices();
|
||||||
@ -336,9 +372,10 @@ void IntegrationPluginKeba::onCommandExecuted(QUuid requestId, bool success)
|
|||||||
|
|
||||||
Thing *thing = myThings().findById(m_kebaDevices.key(keba));
|
Thing *thing = myThings().findById(m_kebaDevices.key(keba));
|
||||||
if (!thing) {
|
if (!thing) {
|
||||||
qCWarning(dcKebaKeContact()) << "On command executed: missing device object";
|
qCWarning(dcKeba()) << "On command executed: missing device object";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ThingActionInfo *info = m_asyncActions.take(requestId);
|
ThingActionInfo *info = m_asyncActions.take(requestId);
|
||||||
if (success) {
|
if (success) {
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
@ -355,25 +392,25 @@ void IntegrationPluginKeba::onReportTwoReceived(const KeContact::ReportTwo &repo
|
|||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qCDebug(dcKebaKeContact()) << "Report 2 received for" << thing->name() << "Serial number:" << thing->stateValue(wallboxSerialnumberStateTypeId).toString();
|
qCDebug(dcKeba()) << "Report 2 received for" << thing->name() << "Serial number:" << thing->stateValue(wallboxSerialnumberStateTypeId).toString();
|
||||||
qCDebug(dcKebaKeContact()) << " - State:" << reportTwo.state;
|
qCDebug(dcKeba()) << " - State:" << reportTwo.state;
|
||||||
qCDebug(dcKebaKeContact()) << " - Error 1:" << reportTwo.error1;
|
qCDebug(dcKeba()) << " - Error 1:" << reportTwo.error1;
|
||||||
qCDebug(dcKebaKeContact()) << " - Error 2:" << reportTwo.error2;
|
qCDebug(dcKeba()) << " - Error 2:" << reportTwo.error2;
|
||||||
qCDebug(dcKebaKeContact()) << " - Plug:" << reportTwo.plugState;
|
qCDebug(dcKeba()) << " - Plug:" << reportTwo.plugState;
|
||||||
qCDebug(dcKebaKeContact()) << " - Enable sys:" << reportTwo.enableSys;
|
qCDebug(dcKeba()) << " - Enable sys:" << reportTwo.enableSys;
|
||||||
qCDebug(dcKebaKeContact()) << " - Enable user:" << reportTwo.enableUser;
|
qCDebug(dcKeba()) << " - Enable user:" << reportTwo.enableUser;
|
||||||
qCDebug(dcKebaKeContact()) << " - Max curr:" << reportTwo.maxCurrent;
|
qCDebug(dcKeba()) << " - Max curr:" << reportTwo.maxCurrent;
|
||||||
qCDebug(dcKebaKeContact()) << " - Max curr %:" << reportTwo.maxCurrentPercentage;
|
qCDebug(dcKeba()) << " - Max curr %:" << reportTwo.maxCurrentPercentage;
|
||||||
qCDebug(dcKebaKeContact()) << " - Curr HW:" << reportTwo.currentHardwareLimitation;
|
qCDebug(dcKeba()) << " - Curr HW:" << reportTwo.currentHardwareLimitation;
|
||||||
qCDebug(dcKebaKeContact()) << " - Curr User:" << reportTwo.currentUser;
|
qCDebug(dcKeba()) << " - Curr User:" << reportTwo.currentUser;
|
||||||
qCDebug(dcKebaKeContact()) << " - Curr FS:" << reportTwo.currentFailsafe;
|
qCDebug(dcKeba()) << " - Curr FS:" << reportTwo.currentFailsafe;
|
||||||
qCDebug(dcKebaKeContact()) << " - Tmo FS:" << reportTwo.timeoutFailsafe;
|
qCDebug(dcKeba()) << " - Tmo FS:" << reportTwo.timeoutFailsafe;
|
||||||
qCDebug(dcKebaKeContact()) << " - Curr timer:" << reportTwo.currTimer;
|
qCDebug(dcKeba()) << " - Curr timer:" << reportTwo.currTimer;
|
||||||
qCDebug(dcKebaKeContact()) << " - Timeout CT:" << reportTwo.timeoutCt;
|
qCDebug(dcKeba()) << " - Timeout CT:" << reportTwo.timeoutCt;
|
||||||
qCDebug(dcKebaKeContact()) << " - Output:" << reportTwo.output;
|
qCDebug(dcKeba()) << " - Output:" << reportTwo.output;
|
||||||
qCDebug(dcKebaKeContact()) << " - Input:" << reportTwo.input;
|
qCDebug(dcKeba()) << " - Input:" << reportTwo.input;
|
||||||
qCDebug(dcKebaKeContact()) << " - Serial number:" << reportTwo.serialNumber;
|
qCDebug(dcKeba()) << " - Serial number:" << reportTwo.serialNumber;
|
||||||
qCDebug(dcKebaKeContact()) << " - Uptime:" << reportTwo.seconds/60 << "[min]";
|
qCDebug(dcKeba()) << " - Uptime:" << reportTwo.seconds/60 << "[min]";
|
||||||
|
|
||||||
if (reportTwo.serialNumber == thing->stateValue(wallboxSerialnumberStateTypeId).toString()) {
|
if (reportTwo.serialNumber == thing->stateValue(wallboxSerialnumberStateTypeId).toString()) {
|
||||||
setDeviceState(thing, reportTwo.state);
|
setDeviceState(thing, reportTwo.state);
|
||||||
@ -384,16 +421,21 @@ void IntegrationPluginKeba::onReportTwoReceived(const KeContact::ReportTwo &repo
|
|||||||
thing->setStateValue(wallboxError2StateTypeId, reportTwo.error2);
|
thing->setStateValue(wallboxError2StateTypeId, reportTwo.error2);
|
||||||
thing->setStateValue(wallboxSystemEnabledStateTypeId, reportTwo.enableSys);
|
thing->setStateValue(wallboxSystemEnabledStateTypeId, reportTwo.enableSys);
|
||||||
|
|
||||||
thing->setStateValue(wallboxMaxChargingCurrentStateTypeId, reportTwo.currentUser);
|
thing->setStateValue(wallboxMaxChargingCurrentStateTypeId, reportTwo.currTimer);
|
||||||
|
thing->setStateValue(wallboxMaxChargingCurrentGeneralStateTypeId, reportTwo.currentUser);
|
||||||
thing->setStateValue(wallboxMaxChargingCurrentPercentStateTypeId, reportTwo.maxCurrentPercentage);
|
thing->setStateValue(wallboxMaxChargingCurrentPercentStateTypeId, reportTwo.maxCurrentPercentage);
|
||||||
thing->setStateValue(wallboxMaxPossibleChargingCurrentStateTypeId, reportTwo.currentHardwareLimitation);
|
|
||||||
|
// Set the state limits according to the hardware limits
|
||||||
|
// FIXME: enable limits once landed
|
||||||
|
//thing->setStateMaxValue(wallboxMaxChargingCurrentStateTypeId, reportTwo.currentHardwareLimitation);
|
||||||
|
//thing->setStateMaxValue(wallboxMaxChargingCurrentGeneralStateTypeId, reportTwo.currentHardwareLimitation);
|
||||||
|
|
||||||
thing->setStateValue(wallboxOutputX2StateTypeId, reportTwo.output);
|
thing->setStateValue(wallboxOutputX2StateTypeId, reportTwo.output);
|
||||||
thing->setStateValue(wallboxInputStateTypeId, reportTwo.input);
|
thing->setStateValue(wallboxInputStateTypeId, reportTwo.input);
|
||||||
|
|
||||||
thing->setStateValue(wallboxUptimeStateTypeId, reportTwo.seconds/60);
|
thing->setStateValue(wallboxUptimeStateTypeId, reportTwo.seconds / 60);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcKebaKeContact()) << "Received report but the serial number didn't match";
|
qCWarning(dcKeba()) << "Received report but the serial number didn't match";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,23 +446,24 @@ void IntegrationPluginKeba::onReportThreeReceived(const KeContact::ReportThree &
|
|||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qCDebug(dcKebaKeContact()) << "Report 3 received for" << thing->name() << "Serial number:" << thing->stateValue(wallboxSerialnumberStateTypeId).toString();
|
qCDebug(dcKeba()) << "Report 3 received for" << thing->name() << "Serial number:" << thing->stateValue(wallboxSerialnumberStateTypeId).toString();
|
||||||
qCDebug(dcKebaKeContact()) << " - Current phase 1:" << reportThree.currentPhase1 << "[A]";
|
qCDebug(dcKeba()) << " - Current phase 1:" << reportThree.currentPhase1 << "[A]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Current phase 2:" << reportThree.currentPhase2 << "[A]";
|
qCDebug(dcKeba()) << " - Current phase 2:" << reportThree.currentPhase2 << "[A]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Current phase 3:" << reportThree.currentPhase3 << "[A]";
|
qCDebug(dcKeba()) << " - Current phase 3:" << reportThree.currentPhase3 << "[A]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Voltage phase 1:" << reportThree.voltagePhase1 << "[V]";
|
qCDebug(dcKeba()) << " - Voltage phase 1:" << reportThree.voltagePhase1 << "[V]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Voltage phase 2:" << reportThree.voltagePhase2 << "[V]";
|
qCDebug(dcKeba()) << " - Voltage phase 2:" << reportThree.voltagePhase2 << "[V]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Voltage phase 3:" << reportThree.voltagePhase3 << "[V]";
|
qCDebug(dcKeba()) << " - Voltage phase 3:" << reportThree.voltagePhase3 << "[V]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Power consumption:" << reportThree.power << "[kW]";
|
qCDebug(dcKeba()) << " - Power consumption:" << reportThree.power << "[kW]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Energy session" << reportThree.energySession << "[kWh]";
|
qCDebug(dcKeba()) << " - Energy session" << reportThree.energySession << "[kWh]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Energy total" << reportThree.energyTotal << "[kWh]";
|
qCDebug(dcKeba()) << " - Energy total" << reportThree.energyTotal << "[kWh]";
|
||||||
qCDebug(dcKebaKeContact()) << " - Serial number" << reportThree.serialNumber;
|
qCDebug(dcKeba()) << " - Serial number" << reportThree.serialNumber;
|
||||||
qCDebug(dcKebaKeContact()) << " - Uptime" << reportThree.seconds/60 << "[min]";
|
qCDebug(dcKeba()) << " - Uptime" << reportThree.seconds/60 << "[min]";
|
||||||
|
|
||||||
if (reportThree.serialNumber == thing->stateValue(wallboxSerialnumberStateTypeId).toString()) {
|
if (reportThree.serialNumber == thing->stateValue(wallboxSerialnumberStateTypeId).toString()) {
|
||||||
thing->setStateValue(wallboxCurrentPhase1EventTypeId, reportThree.currentPhase1);
|
thing->setStateValue(wallboxCurrentPhase1EventTypeId, reportThree.currentPhase1);
|
||||||
thing->setStateValue(wallboxCurrentPhase2EventTypeId, reportThree.currentPhase2);
|
thing->setStateValue(wallboxCurrentPhase2EventTypeId, reportThree.currentPhase2);
|
||||||
thing->setStateValue(wallboxCurrentPhase3EventTypeId, reportThree.currentPhase3);
|
thing->setStateValue(wallboxCurrentPhase3EventTypeId, reportThree.currentPhase3);
|
||||||
|
thing->setStateValue(wallboxCurrentStateTypeId, reportThree.currentPhase1 + reportThree.currentPhase2 + reportThree.currentPhase3);
|
||||||
thing->setStateValue(wallboxVoltagePhase1EventTypeId, reportThree.voltagePhase1);
|
thing->setStateValue(wallboxVoltagePhase1EventTypeId, reportThree.voltagePhase1);
|
||||||
thing->setStateValue(wallboxVoltagePhase2EventTypeId, reportThree.voltagePhase2);
|
thing->setStateValue(wallboxVoltagePhase2EventTypeId, reportThree.voltagePhase2);
|
||||||
thing->setStateValue(wallboxVoltagePhase3EventTypeId, reportThree.voltagePhase3);
|
thing->setStateValue(wallboxVoltagePhase3EventTypeId, reportThree.voltagePhase3);
|
||||||
@ -429,7 +472,7 @@ void IntegrationPluginKeba::onReportThreeReceived(const KeContact::ReportThree &
|
|||||||
thing->setStateValue(wallboxPowerFactorStateTypeId, reportThree.powerFactor);
|
thing->setStateValue(wallboxPowerFactorStateTypeId, reportThree.powerFactor);
|
||||||
thing->setStateValue(wallboxTotalEnergyConsumedStateTypeId, reportThree.energyTotal);
|
thing->setStateValue(wallboxTotalEnergyConsumedStateTypeId, reportThree.energyTotal);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcKebaKeContact()) << "Received report but the serial number didn't match";
|
qCWarning(dcKeba()) << "Received report but the serial number didn't match";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,18 +483,18 @@ void IntegrationPluginKeba::onReport1XXReceived(int reportNumber, const KeContac
|
|||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qCDebug(dcKebaKeContact()) << "Report" << reportNumber << "received for" << thing->name() << "Serial number:" << thing->stateValue(wallboxSerialnumberStateTypeId).toString();
|
qCDebug(dcKeba()) << "Report" << reportNumber << "received for" << thing->name() << "Serial number:" << thing->stateValue(wallboxSerialnumberStateTypeId).toString();
|
||||||
qCDebug(dcKebaKeContact()) << " - Session Id" << report.sessionId;
|
qCDebug(dcKeba()) << " - Session Id" << report.sessionId;
|
||||||
qCDebug(dcKebaKeContact()) << " - Curr HW" << report.currHW;
|
qCDebug(dcKeba()) << " - Curr HW" << report.currHW;
|
||||||
qCDebug(dcKebaKeContact()) << " - Energy start" << report.startEnergy;
|
qCDebug(dcKeba()) << " - Energy start" << report.startEnergy;
|
||||||
qCDebug(dcKebaKeContact()) << " - Energy present" << report.presentEnergy;
|
qCDebug(dcKeba()) << " - Energy present" << report.presentEnergy;
|
||||||
qCDebug(dcKebaKeContact()) << " - Start time" << report.startTime;
|
qCDebug(dcKeba()) << " - Start time" << report.startTime << QDateTime::fromMSecsSinceEpoch(report.startTime * 1000).toString();
|
||||||
qCDebug(dcKebaKeContact()) << " - End time" << report.endTime;
|
qCDebug(dcKeba()) << " - End time" << report.endTime;
|
||||||
qCDebug(dcKebaKeContact()) << " - Stop reason" << report.stopReason;
|
qCDebug(dcKeba()) << " - Stop reason" << report.stopReason;
|
||||||
qCDebug(dcKebaKeContact()) << " - RFID Tag" << report.rfidTag;
|
qCDebug(dcKeba()) << " - RFID Tag" << report.rfidTag;
|
||||||
qCDebug(dcKebaKeContact()) << " - RFID Class" << report.rfidClass;
|
qCDebug(dcKeba()) << " - RFID Class" << report.rfidClass;
|
||||||
qCDebug(dcKebaKeContact()) << " - Serial number" << report.serialNumber;
|
qCDebug(dcKeba()) << " - Serial number" << report.serialNumber;
|
||||||
qCDebug(dcKebaKeContact()) << " - Uptime" << report.seconds;
|
qCDebug(dcKeba()) << " - Uptime" << report.seconds;
|
||||||
|
|
||||||
if (reportNumber == 100) {
|
if (reportNumber == 100) {
|
||||||
// Report 100 is the current charging session
|
// Report 100 is the current charging session
|
||||||
@ -471,7 +514,7 @@ void IntegrationPluginKeba::onReport1XXReceived(int reportNumber, const KeContac
|
|||||||
m_lastSessionId.insert(thing->id(), report.sessionId);
|
m_lastSessionId.insert(thing->id(), report.sessionId);
|
||||||
} else {
|
} else {
|
||||||
if (m_lastSessionId.value(thing->id()) != report.sessionId) {
|
if (m_lastSessionId.value(thing->id()) != report.sessionId) {
|
||||||
qCDebug(dcKebaKeContact()) << "New session id receivd";
|
qCDebug(dcKeba()) << "New session id receivd";
|
||||||
Event event;
|
Event event;
|
||||||
event.setEventTypeId(wallboxChargingSessionFinishedEventTypeId);
|
event.setEventTypeId(wallboxChargingSessionFinishedEventTypeId);
|
||||||
event.setThingId(thing->id());
|
event.setThingId(thing->id());
|
||||||
@ -484,10 +527,10 @@ void IntegrationPluginKeba::onReport1XXReceived(int reportNumber, const KeContac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcKebaKeContact()) << "Received report but the serial number didn't match";
|
qCWarning(dcKeba()) << "Received report but the serial number didn't match";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcKebaKeContact()) << "Received unhandled report" << reportNumber;
|
qCWarning(dcKeba()) << "Received unhandled report" << reportNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,7 +541,7 @@ void IntegrationPluginKeba::onBroadcastReceived(KeContact::BroadcastType type, c
|
|||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qCDebug(dcKebaKeContact()) << "Broadcast received" << type << "value" << content;
|
qCDebug(dcKeba()) << "Broadcast received" << type << "value" << content;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case KeContact::BroadcastTypePlug:
|
case KeContact::BroadcastTypePlug:
|
||||||
@ -508,7 +551,7 @@ void IntegrationPluginKeba::onBroadcastReceived(KeContact::BroadcastType type, c
|
|||||||
thing->setStateValue(wallboxInputStateTypeId, (content.toInt() == 1));
|
thing->setStateValue(wallboxInputStateTypeId, (content.toInt() == 1));
|
||||||
break;
|
break;
|
||||||
case KeContact::BroadcastTypeEPres:
|
case KeContact::BroadcastTypeEPres:
|
||||||
thing->setStateValue(wallboxSessionEnergyStateTypeId, content.toInt()/10000.00);
|
thing->setStateValue(wallboxSessionEnergyStateTypeId, content.toInt() / 10000.00);
|
||||||
break;
|
break;
|
||||||
case KeContact::BroadcastTypeState:
|
case KeContact::BroadcastTypeState:
|
||||||
setDeviceState(thing, KeContact::State(content.toInt()));
|
setDeviceState(thing, KeContact::State(content.toInt()));
|
||||||
@ -530,38 +573,44 @@ void IntegrationPluginKeba::executeAction(ThingActionInfo *info)
|
|||||||
if (thing->thingClassId() == wallboxThingClassId) {
|
if (thing->thingClassId() == wallboxThingClassId) {
|
||||||
KeContact *keba = m_kebaDevices.value(thing->id());
|
KeContact *keba = m_kebaDevices.value(thing->id());
|
||||||
if (!keba) {
|
if (!keba) {
|
||||||
qCWarning(dcKebaKeContact()) << "Device not properly initialized, Keba object missing";
|
qCWarning(dcKeba()) << "Device not properly initialized, Keba object missing";
|
||||||
return info->finish(Thing::ThingErrorHardwareNotAvailable);
|
return info->finish(Thing::ThingErrorHardwareNotAvailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid requestId;
|
QUuid requestId;
|
||||||
if(action.actionTypeId() == wallboxMaxChargingCurrentActionTypeId){
|
if (action.actionTypeId() == wallboxMaxChargingCurrentActionTypeId) {
|
||||||
int milliAmpere = action.param(wallboxMaxChargingCurrentActionMaxChargingCurrentParamTypeId).value().toDouble()*1000;
|
int milliAmpere = action.param(wallboxMaxChargingCurrentActionMaxChargingCurrentParamTypeId).value().toDouble() * 1000;
|
||||||
requestId = keba->setMaxAmpere(milliAmpere);
|
requestId = keba->setMaxAmpere(milliAmpere);
|
||||||
|
} else if(action.actionTypeId() == wallboxMaxChargingCurrentGeneralActionTypeId) {
|
||||||
} else if(action.actionTypeId() == wallboxPowerActionTypeId){
|
int milliAmpere = action.param(wallboxMaxChargingCurrentGeneralActionMaxChargingCurrentGeneralParamTypeId).value().toDouble() * 1000;
|
||||||
|
requestId = keba->setMaxAmpereGeneral(milliAmpere);
|
||||||
|
} else if(action.actionTypeId() == wallboxPowerActionTypeId) {
|
||||||
requestId = keba->enableOutput(action.param(wallboxPowerActionTypeId).value().toBool());
|
requestId = keba->enableOutput(action.param(wallboxPowerActionTypeId).value().toBool());
|
||||||
|
} else if(action.actionTypeId() == wallboxDisplayActionTypeId) {
|
||||||
} else if(action.actionTypeId() == wallboxDisplayActionTypeId){
|
|
||||||
requestId = keba->displayMessage(action.param(wallboxDisplayActionMessageParamTypeId).value().toByteArray());
|
requestId = keba->displayMessage(action.param(wallboxDisplayActionMessageParamTypeId).value().toByteArray());
|
||||||
|
|
||||||
} else if(action.actionTypeId() == wallboxOutputX2ActionTypeId) {
|
} else if(action.actionTypeId() == wallboxOutputX2ActionTypeId) {
|
||||||
requestId = keba->setOutputX2(action.param(wallboxOutputX2ActionOutputX2ParamTypeId).value().toBool());
|
requestId = keba->setOutputX2(action.param(wallboxOutputX2ActionOutputX2ParamTypeId).value().toBool());
|
||||||
|
} else if(action.actionTypeId() == wallboxFailsafeModeActionTypeId) {
|
||||||
} else if(action.actionTypeId() == wallboxFailsafeModeActionTypeId){
|
|
||||||
int timeout = 0;
|
int timeout = 0;
|
||||||
if (action.param(wallboxFailsafeModeActionFailsafeModeParamTypeId).value().toBool()) {
|
if (action.param(wallboxFailsafeModeActionFailsafeModeParamTypeId).value().toBool()) {
|
||||||
timeout = 60;
|
timeout = 60;
|
||||||
}
|
}
|
||||||
requestId = keba->setFailsafe(timeout, 0, false);
|
requestId = keba->setFailsafe(timeout, 0, false);
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcKebaKeContact()) << "Unhandled ActionTypeId:" << action.actionTypeId();
|
qCWarning(dcKeba()) << "Unhandled ActionTypeId:" << action.actionTypeId();
|
||||||
return info->finish(Thing::ThingErrorActionTypeNotFound);
|
return info->finish(Thing::ThingErrorActionTypeNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the keba returns an invalid uuid, something went wrong
|
||||||
|
if (requestId.isNull()) {
|
||||||
|
info->finish(Thing::ThingErrorHardwareFailure);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_asyncActions.insert(requestId, info);
|
m_asyncActions.insert(requestId, info);
|
||||||
connect(info, &ThingActionInfo::aborted, this, [requestId, this]{m_asyncActions.remove(requestId);});
|
connect(info, &ThingActionInfo::aborted, this, [requestId, this]{ m_asyncActions.remove(requestId); });
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcKebaKeContact()) << "Execute action, unhandled device class" << thing->thingClass();
|
qCWarning(dcKeba()) << "Execute action, unhandled device class" << thing->thingClass();
|
||||||
info->finish(Thing::ThingErrorThingClassNotFound);
|
info->finish(Thing::ThingErrorThingClassNotFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,7 @@ public:
|
|||||||
explicit IntegrationPluginKeba();
|
explicit IntegrationPluginKeba();
|
||||||
|
|
||||||
void init() override;
|
void init() override;
|
||||||
|
|
||||||
void discoverThings(ThingDiscoveryInfo *info) override;
|
void discoverThings(ThingDiscoveryInfo *info) override;
|
||||||
void setupThing(ThingSetupInfo *info) override;
|
void setupThing(ThingSetupInfo *info) override;
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ private:
|
|||||||
PluginTimer *m_updateTimer = nullptr;
|
PluginTimer *m_updateTimer = nullptr;
|
||||||
PluginTimer *m_reconnectTimer = nullptr;
|
PluginTimer *m_reconnectTimer = nullptr;
|
||||||
|
|
||||||
KeContactDataLayer *m_kebaData = nullptr;
|
KeContactDataLayer *m_kebaDataLayer = nullptr;
|
||||||
|
|
||||||
QHash<ThingId, KeContact *> m_kebaDevices;
|
QHash<ThingId, KeContact *> m_kebaDevices;
|
||||||
QHash<ThingId, int> m_lastSessionId;
|
QHash<ThingId, int> m_lastSessionId;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"displayName": "Keba KeContact",
|
"displayName": "Keba KeContact",
|
||||||
"name": "KebaKeContact",
|
"name": "Keba",
|
||||||
"id": "9142b09f-30a9-43d0-9ede-2f8debe075ac",
|
"id": "9142b09f-30a9-43d0-9ede-2f8debe075ac",
|
||||||
"vendors": [
|
"vendors": [
|
||||||
{
|
{
|
||||||
@ -92,7 +92,8 @@
|
|||||||
"displayNameAction": "Set charging enabled",
|
"displayNameAction": "Set charging enabled",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"writable": true,
|
"writable": true,
|
||||||
"defaultValue": false
|
"defaultValue": false,
|
||||||
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "e5631593-f486-47cb-9951-b7597d0b769b",
|
"id": "e5631593-f486-47cb-9951-b7597d0b769b",
|
||||||
@ -133,7 +134,8 @@
|
|||||||
"displayNameEvent": "Current changed",
|
"displayNameEvent": "Current changed",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "Ampere",
|
"unit": "Ampere",
|
||||||
"defaultValue": 0.00
|
"defaultValue": 0.00,
|
||||||
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "593656f0-babf-4308-8767-68f34e10fb15",
|
"id": "593656f0-babf-4308-8767-68f34e10fb15",
|
||||||
@ -143,10 +145,25 @@
|
|||||||
"displayNameAction": "Set maximal charging current",
|
"displayNameAction": "Set maximal charging current",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "Ampere",
|
"unit": "Ampere",
|
||||||
"defaultValue": 6.00,
|
"defaultValue": 6.0,
|
||||||
"minValue": 6.00,
|
"minValue": 6.0,
|
||||||
"maxValue": 63.00,
|
"maxValue": 32.0,
|
||||||
"writable": true
|
"writable": true,
|
||||||
|
"suggestLogging": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "da0cfb97-0b27-4d8f-bdf7-45b1ca727038",
|
||||||
|
"name": "maxChargingCurrentGeneral",
|
||||||
|
"displayName": "Maximal general charging current",
|
||||||
|
"displayNameEvent": "Maximal general charging current changed",
|
||||||
|
"displayNameAction": "Set maximal general charging current",
|
||||||
|
"type": "double",
|
||||||
|
"unit": "Ampere",
|
||||||
|
"defaultValue": 6.0,
|
||||||
|
"minValue": 6.0,
|
||||||
|
"maxValue": 32.0,
|
||||||
|
"writable": true,
|
||||||
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "3c7b83a0-0e42-47bf-9788-dde6aab5ceea",
|
"id": "3c7b83a0-0e42-47bf-9788-dde6aab5ceea",
|
||||||
@ -157,16 +174,8 @@
|
|||||||
"unit": "Percentage",
|
"unit": "Percentage",
|
||||||
"defaultValue": 100,
|
"defaultValue": 100,
|
||||||
"minValue": 0,
|
"minValue": 0,
|
||||||
"maxValue": 100
|
"maxValue": 100,
|
||||||
},
|
"suggestLogging": true
|
||||||
{
|
|
||||||
"id": "08bb9872-8d63-49b0-a8ce-7a449341f13b",
|
|
||||||
"name": "maxPossibleChargingCurrent",
|
|
||||||
"displayName": "Maximum possible charging current",
|
|
||||||
"displayNameEvent": "Maximum possible charging current changed",
|
|
||||||
"type": "double",
|
|
||||||
"unit": "Ampere",
|
|
||||||
"defaultValue": 6.00
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "4a2d75d8-a3a0-4b40-9ca7-e8b6f11d0ef9",
|
"id": "4a2d75d8-a3a0-4b40-9ca7-e8b6f11d0ef9",
|
||||||
@ -202,7 +211,8 @@
|
|||||||
"displayNameEvent": "Current phase 1 changed",
|
"displayNameEvent": "Current phase 1 changed",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "Ampere",
|
"unit": "Ampere",
|
||||||
"defaultValue": 0.00
|
"defaultValue": 0.00,
|
||||||
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "cdc7e10a-0d0a-4e93-ad2c-d34ffca45c97",
|
"id": "cdc7e10a-0d0a-4e93-ad2c-d34ffca45c97",
|
||||||
@ -211,7 +221,8 @@
|
|||||||
"displayNameEvent": "Current phase 2 changed",
|
"displayNameEvent": "Current phase 2 changed",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "Ampere",
|
"unit": "Ampere",
|
||||||
"defaultValue": 0.00
|
"defaultValue": 0.00,
|
||||||
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "da838dc8-85f0-4e55-b4b5-cb93a43b373d",
|
"id": "da838dc8-85f0-4e55-b4b5-cb93a43b373d",
|
||||||
@ -220,7 +231,8 @@
|
|||||||
"displayNameEvent": "Current phase 3 changed",
|
"displayNameEvent": "Current phase 3 changed",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "Ampere",
|
"unit": "Ampere",
|
||||||
"defaultValue": 0.00
|
"defaultValue": 0.00,
|
||||||
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "7af9e93b-099d-4d9d-a480-9c0f66aecd8b",
|
"id": "7af9e93b-099d-4d9d-a480-9c0f66aecd8b",
|
||||||
@ -229,7 +241,8 @@
|
|||||||
"displayNameEvent": "Power consumtion changed",
|
"displayNameEvent": "Power consumtion changed",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "Watt",
|
"unit": "Watt",
|
||||||
"defaultValue": 0.00
|
"defaultValue": 0.00,
|
||||||
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "889c3c9a-96b4-4408-bd9a-d79e36ed9296",
|
"id": "889c3c9a-96b4-4408-bd9a-d79e36ed9296",
|
||||||
@ -264,7 +277,8 @@
|
|||||||
"displayNameEvent": "Session energy changed",
|
"displayNameEvent": "Session energy changed",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "KiloWattHour",
|
"unit": "KiloWattHour",
|
||||||
"defaultValue": 0
|
"defaultValue": 0,
|
||||||
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "41e179b3-29a2-43ec-b537-023a527081e8",
|
"id": "41e179b3-29a2-43ec-b537-023a527081e8",
|
||||||
@ -273,7 +287,8 @@
|
|||||||
"displayNameEvent": "Total energy consumption changed",
|
"displayNameEvent": "Total energy consumption changed",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "KiloWattHour",
|
"unit": "KiloWattHour",
|
||||||
"defaultValue": 0
|
"defaultValue": 0,
|
||||||
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "96b2d176-6460-4109-8824-3af4679c6573",
|
"id": "96b2d176-6460-4109-8824-3af4679c6573",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2021, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -33,21 +33,33 @@
|
|||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
|
||||||
|
|
||||||
KeContact::KeContact(const QHostAddress &address, KeContactDataLayer *dataLayer, QObject *parent) :
|
KeContact::KeContact(const QHostAddress &address, KeContactDataLayer *dataLayer, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_dataLayer(dataLayer),
|
m_dataLayer(dataLayer),
|
||||||
m_address(address)
|
m_address(address)
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "Creating KeContact connection for address" << m_address;
|
qCDebug(dcKeba()) << "Creating KeContact connection for address" << m_address;
|
||||||
m_requestTimeoutTimer = new QTimer(this);
|
m_requestTimeoutTimer = new QTimer(this);
|
||||||
m_requestTimeoutTimer->setSingleShot(true);
|
m_requestTimeoutTimer->setSingleShot(true);
|
||||||
connect(m_requestTimeoutTimer, &QTimer::timeout, this, [this] {
|
connect(m_requestTimeoutTimer, &QTimer::timeout, this, [this]() {
|
||||||
//This timer will be started when a request is sent and stopped or resetted when a response has been received
|
// This timer will be started when a request is sent and stopped or resetted when a response has been received
|
||||||
emit reachableChanged(false);
|
setReachable(false);
|
||||||
//Try to send the next command
|
|
||||||
handleNextCommandInQueue();
|
if (m_currentRequest.isValid()) {
|
||||||
m_deviceBlocked = false;
|
// Schedule pause timer to send next request
|
||||||
|
qCWarning(dcKeba()) << "Command timeouted" << m_currentRequest.command();
|
||||||
|
emit commandExecuted(m_currentRequest.requestId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timeout...send the next request right the way since at least 5 seconds passed since tha last command
|
||||||
|
m_currentRequest = KeContactRequest();
|
||||||
|
sendNextCommand();
|
||||||
|
});
|
||||||
|
|
||||||
|
m_pauseTimer = new QTimer(this);
|
||||||
|
m_pauseTimer->setSingleShot(true);
|
||||||
|
connect(m_pauseTimer, &QTimer::timeout, this, [this](){
|
||||||
|
sendNextCommand();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_dataLayer, &KeContactDataLayer::datagramReceived, this, &KeContact::onReceivedDatagram);
|
connect(m_dataLayer, &KeContactDataLayer::datagramReceived, this, &KeContact::onReceivedDatagram);
|
||||||
@ -55,180 +67,250 @@ KeContact::KeContact(const QHostAddress &address, KeContactDataLayer *dataLayer,
|
|||||||
|
|
||||||
KeContact::~KeContact()
|
KeContact::~KeContact()
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "Deleting KeContact connection for address" << m_address;
|
qCDebug(dcKeba()) << "Deleting KeContact connection for address" << m_address.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHostAddress KeContact::address()
|
QHostAddress KeContact::address() const
|
||||||
{
|
{
|
||||||
return m_address;
|
return m_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid KeContact::start(const QByteArray &rfidToken, const QByteArray &rfidClassifier)
|
QUuid KeContact::start(const QByteArray &rfidToken, const QByteArray &rfidClassifier)
|
||||||
{
|
{
|
||||||
QUuid requestId = QUuid::createUuid();
|
if (!m_dataLayer) {
|
||||||
m_pendingRequests.append(requestId);
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
QByteArray datagram = "start "+rfidToken + " " + rfidClassifier;
|
setReachable(false);
|
||||||
qCDebug(dcKebaKeContact()) << "Datagram : " << datagram;
|
return QUuid();
|
||||||
sendCommand(datagram, requestId);;
|
}
|
||||||
return requestId;
|
|
||||||
|
QByteArray datagram = "start " + rfidToken + " " + rfidClassifier;
|
||||||
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
|
qCDebug(dcKeba()) << "Start: Datagram:" << datagram;
|
||||||
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid KeContact::stop(const QByteArray &rfidToken)
|
QUuid KeContact::stop(const QByteArray &rfidToken)
|
||||||
{
|
{
|
||||||
QUuid requestId = QUuid::createUuid();
|
if (!m_dataLayer) {
|
||||||
m_pendingRequests.append(requestId);
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
QByteArray datagram = "stop "+rfidToken;
|
setReachable(false);
|
||||||
qCDebug(dcKebaKeContact()) << "Datagram : " << datagram;
|
return QUuid();
|
||||||
sendCommand(datagram, requestId);
|
}
|
||||||
return requestId;
|
|
||||||
|
QByteArray datagram = "stop " + rfidToken;
|
||||||
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
|
qCDebug(dcKeba()) << "Stop: Datagram:" << datagram;
|
||||||
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeContact::setAddress(const QHostAddress &address)
|
void KeContact::setAddress(const QHostAddress &address)
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "Updating Keba connection address" << address.toString();
|
if (m_address == address)
|
||||||
|
return;
|
||||||
|
|
||||||
|
qCDebug(dcKeba()) << "Updating Keba connection address from" << m_address.toString() << "to" << address.toString();
|
||||||
m_address = address;
|
m_address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KeContact::reachable() const
|
||||||
void KeContact::sendCommand(const QByteArray &command, const QUuid &requestId)
|
|
||||||
{
|
{
|
||||||
QTimer::singleShot(5000, this, [requestId, this] {
|
return m_reachable;
|
||||||
if (m_pendingRequests.contains(requestId)) {
|
|
||||||
m_pendingRequests.removeOne(requestId);
|
|
||||||
emit commandExecuted(requestId, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
sendCommand(command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeContact::sendCommand(const QByteArray &command)
|
void KeContact::sendCommand(const QByteArray &command)
|
||||||
{
|
{
|
||||||
if (!m_dataLayer) {
|
if (!m_dataLayer) {
|
||||||
qCWarning(dcKebaKeContact()) << "UDP socket not initialized";
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
emit reachableChanged(false);
|
setReachable(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_deviceBlocked) {
|
qCDebug(dcKeba()) << "--> Writing datagram to" << m_address.toString() << command;
|
||||||
//add command to queue
|
m_dataLayer->write(m_address, command);
|
||||||
m_commandList.append(command);
|
m_requestTimeoutTimer->start(5000);
|
||||||
} else {
|
|
||||||
qCDebug(dcKebaKeContact()) << "Writing datagram" << command << m_address;
|
|
||||||
m_dataLayer->write( m_address, command);
|
|
||||||
m_requestTimeoutTimer->start(5000);
|
|
||||||
m_deviceBlocked = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeContact::handleNextCommandInQueue()
|
void KeContact::sendNextCommand()
|
||||||
{
|
{
|
||||||
if (!m_dataLayer) {
|
// No message left, we are done
|
||||||
qCWarning(dcKebaKeContact()) << "Data layer not initialized";
|
if (m_requestQueue.isEmpty())
|
||||||
if (m_reachable == true) {
|
|
||||||
m_reachable = false;
|
|
||||||
emit reachableChanged(false);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
qCDebug(dcKebaKeContact()) << "Handle Command Queue- Pending commands" << m_commandList.length() << "Pending requestIds" << m_pendingRequests.length();
|
// Still a request pending
|
||||||
if (!m_commandList.isEmpty()) {
|
if (m_currentRequest.isValid())
|
||||||
QByteArray command = m_commandList.takeFirst();
|
return;
|
||||||
qCDebug(dcKebaKeContact()) << "Writing datagram" << command << m_address;
|
|
||||||
m_dataLayer->write( m_address, command);
|
m_currentRequest = m_requestQueue.dequeue();
|
||||||
m_requestTimeoutTimer->start(5000);
|
sendCommand(m_currentRequest.command());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KeContact::setReachable(bool reachable)
|
||||||
|
{
|
||||||
|
if (m_reachable == reachable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (reachable) {
|
||||||
|
qCDebug(dcKeba()) << "The keba wallbox on" << m_address.toString() << "is now reachable again.";
|
||||||
|
} else {
|
||||||
|
qCWarning(dcKeba()) << "The keba wallbox on" << m_address.toString() << "is not reachable any more.";
|
||||||
|
}
|
||||||
|
|
||||||
|
m_reachable = reachable;
|
||||||
|
emit reachableChanged(m_reachable);
|
||||||
|
}
|
||||||
|
|
||||||
QUuid KeContact::enableOutput(bool state)
|
QUuid KeContact::enableOutput(bool state)
|
||||||
{
|
{
|
||||||
QUuid requestId = QUuid::createUuid();
|
if (!m_dataLayer) {
|
||||||
m_pendingRequests.append(requestId);
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
|
setReachable(false);
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
// Print information that we are executing now the update action;
|
// Print information that we are executing now the update action;
|
||||||
QByteArray datagram;
|
QByteArray datagram;
|
||||||
if(state){
|
if (state){
|
||||||
datagram.append("ena 1");
|
datagram.append("ena 1");
|
||||||
} else{
|
} else{
|
||||||
datagram.append("ena 0");
|
datagram.append("ena 0");
|
||||||
}
|
}
|
||||||
qCDebug(dcKebaKeContact()) << "Enable output, command:" << datagram;
|
|
||||||
sendCommand(datagram, requestId);
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
return requestId;
|
request.setDelayUntilNextCommand(2000);
|
||||||
|
qCDebug(dcKeba()) << "Enable output: Datagram:" << datagram;
|
||||||
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid KeContact::setMaxAmpere(int milliAmpere)
|
QUuid KeContact::setMaxAmpere(int milliAmpere)
|
||||||
{
|
{
|
||||||
if (milliAmpere < 6000 || milliAmpere > 63000) {
|
if (!m_dataLayer) {
|
||||||
qCWarning(dcKebaKeContact()) << "KeContact: Set max ampere, mA out of range [6000, 63000]" << milliAmpere;
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
return "";
|
setReachable(false);
|
||||||
|
return QUuid();
|
||||||
}
|
}
|
||||||
QUuid requestId = QUuid::createUuid();
|
|
||||||
m_pendingRequests.append(requestId);
|
if (milliAmpere < 6000 || milliAmpere > 63000) {
|
||||||
|
qCWarning(dcKeba()) << "KeContact: Set max ampere, currtime mA out of range [6000, 63000]" << milliAmpere;
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
// Print information that we are executing now the update action
|
// Print information that we are executing now the update action
|
||||||
qCDebug(dcKebaKeContact()) << "Update max current to : " << milliAmpere;
|
qCDebug(dcKeba()) << "Update max current to : " << milliAmpere;
|
||||||
QByteArray data;
|
QString commandLine = QString("currtime %1 1").arg(milliAmpere);
|
||||||
data.append("curr " + QVariant(milliAmpere).toByteArray());
|
QByteArray datagram = commandLine.toUtf8();
|
||||||
qCDebug(dcKebaKeContact()) << "Set max. ampere, command: " << data;
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
sendCommand(data, requestId);
|
request.setDelayUntilNextCommand(1200);
|
||||||
return requestId;
|
qCDebug(dcKeba()) << "Set max charging amps: Datagram:" << datagram;
|
||||||
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid KeContact::setMaxAmpereGeneral(int milliAmpere)
|
||||||
|
{
|
||||||
|
if (!m_dataLayer) {
|
||||||
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
|
setReachable(false);
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (milliAmpere < 6000 || milliAmpere > 63000) {
|
||||||
|
qCWarning(dcKeba()) << "KeContact: Set max ampere curr, mA out of range [6000, 63000]" << milliAmpere;
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print information that we are executing now the update action
|
||||||
|
qCDebug(dcKeba()) << "Update general max current to: " << milliAmpere;
|
||||||
|
QString commandLine = QString("curr %1").arg(milliAmpere);
|
||||||
|
QByteArray datagram = commandLine.toUtf8();
|
||||||
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
|
request.setDelayUntilNextCommand(1200);
|
||||||
|
qCDebug(dcKeba()) << "Set max general charging amps: Datagram:" << datagram;
|
||||||
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid KeContact::displayMessage(const QByteArray &message)
|
QUuid KeContact::displayMessage(const QByteArray &message)
|
||||||
{
|
{
|
||||||
|
if (!m_dataLayer) {
|
||||||
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
|
setReachable(false);
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
/* Text shown on the display. Maximum 23 ASCII characters can be used. 0 .. 23 characters
|
/* Text shown on the display. Maximum 23 ASCII characters can be used. 0 .. 23 characters
|
||||||
~ == Σ
|
~ == Σ
|
||||||
$ == blank
|
$ == blank
|
||||||
, == comma
|
, == comma
|
||||||
*/
|
*/
|
||||||
QUuid requestId = QUuid::createUuid();
|
|
||||||
m_pendingRequests.append(requestId);
|
qCDebug(dcKeba()) << "Set display message: " << message;
|
||||||
qCDebug(dcKebaKeContact()) << "Set display message: " << message;
|
QByteArray datagram;
|
||||||
QByteArray data;
|
|
||||||
QByteArray modifiedMessage = message;
|
QByteArray modifiedMessage = message;
|
||||||
modifiedMessage.replace(" ", "$");
|
modifiedMessage.replace(" ", "$");
|
||||||
if (modifiedMessage.size() > 23) {
|
if (modifiedMessage.size() > 23) {
|
||||||
modifiedMessage.resize(23);
|
modifiedMessage.resize(23);
|
||||||
}
|
}
|
||||||
data.append("display 0 0 0 0 " + modifiedMessage);
|
datagram.append("display 0 0 0 0 " + modifiedMessage);
|
||||||
qCDebug(dcKebaKeContact()) << "Display message, command: " << data;
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
sendCommand(data, requestId);
|
qCDebug(dcKeba()) << "Display message: Datagram:" << datagram;
|
||||||
return requestId;
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid KeContact::chargeWithEnergyLimit(double energy)
|
QUuid KeContact::chargeWithEnergyLimit(double energy)
|
||||||
{
|
{
|
||||||
QUuid requestId = QUuid::createUuid();
|
if (!m_dataLayer) {
|
||||||
m_pendingRequests.append(requestId);
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
|
setReachable(false);
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray data;
|
QByteArray datagram;
|
||||||
data.append("setenergy " + QVariant(static_cast<int>(energy*10000)).toByteArray());
|
datagram.append("setenergy " + QVariant(static_cast<int>(energy*10000)).toByteArray());
|
||||||
qCDebug(dcKebaKeContact()) << "Charge with energy limit, command: " << data;
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
sendCommand(data, requestId);
|
qCDebug(dcKeba()) << "Charge with energy limit: Datagram: " << datagram;
|
||||||
return requestId;
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid KeContact::setFailsafe(int timeout, int current, bool save)
|
QUuid KeContact::setFailsafe(int timeout, int current, bool save)
|
||||||
{
|
{
|
||||||
QUuid requestId = QUuid::createUuid();
|
if (!m_dataLayer) {
|
||||||
m_pendingRequests.append(requestId);
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
|
setReachable(false);
|
||||||
|
return QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
data.append("failsave");
|
data.append("failsave");
|
||||||
data.append(" "+QVariant(timeout).toByteArray());
|
data.append(" "+QVariant(timeout).toByteArray());
|
||||||
data.append(" "+QVariant(current).toByteArray());
|
data.append(" "+QVariant(current).toByteArray());
|
||||||
data.append((save ? " 1":" 0"));
|
data.append((save ? " 1":" 0"));
|
||||||
qCDebug(dcKebaKeContact()) << "Set failsafe mode, command: " << data;
|
KeContactRequest request(QUuid::createUuid(), data);
|
||||||
sendCommand(data, requestId);
|
qCDebug(dcKeba()) << "Set failsafe mode: Datagram: " << data;
|
||||||
return requestId;
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KeContact::getDeviceInformation()
|
void KeContact::getDeviceInformation()
|
||||||
{
|
{
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
data.append("i");
|
data.append("i");
|
||||||
qCDebug(dcKebaKeContact()) << "Get device information, command: " << data;
|
KeContactRequest request(QUuid::createUuid(), data);
|
||||||
sendCommand(data);
|
qCDebug(dcKeba()) << "Get device information: Datagram: " << data;
|
||||||
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeContact::getReport1()
|
void KeContact::getReport1()
|
||||||
@ -253,90 +335,134 @@ void KeContact::getReport1XX(int reportNumber)
|
|||||||
|
|
||||||
QUuid KeContact::setOutputX2(bool state)
|
QUuid KeContact::setOutputX2(bool state)
|
||||||
{
|
{
|
||||||
QUuid requestId = QUuid::createUuid();
|
if (!m_dataLayer) {
|
||||||
m_pendingRequests.append(requestId);
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
QByteArray data;
|
setReachable(false);
|
||||||
data.append("output "+QVariant((state ? 1 : 0)).toByteArray());
|
return QUuid();
|
||||||
qCDebug(dcKebaKeContact()) << "Set Output X2, state:" << state << "Command:" << data;
|
}
|
||||||
sendCommand(data, requestId);
|
|
||||||
return requestId;
|
|
||||||
|
QByteArray datagram;
|
||||||
|
datagram.append("output " + QVariant((state ? 1 : 0)).toByteArray());
|
||||||
|
|
||||||
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
|
qCDebug(dcKeba()) << "Set Output X2, state:" << state << "Datagram:" << datagram;
|
||||||
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeContact::getReport(int reportNumber)
|
void KeContact::getReport(int reportNumber)
|
||||||
{
|
{
|
||||||
QByteArray data;
|
if (!m_dataLayer) {
|
||||||
data.append("report "+QVariant(reportNumber).toByteArray());
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
qCDebug(dcKebaKeContact()) << "Get report" << reportNumber << "Command:" << data;
|
setReachable(false);
|
||||||
sendCommand(data);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray datagram;
|
||||||
|
datagram.append("report " + QVariant(reportNumber).toByteArray());
|
||||||
|
|
||||||
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
|
qCDebug(dcKeba()) << "Get report" << reportNumber << "Datagram:" << datagram;
|
||||||
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid KeContact::unlockCharger()
|
QUuid KeContact::unlockCharger()
|
||||||
{
|
{
|
||||||
QUuid requestId = QUuid::createUuid();
|
if (!m_dataLayer) {
|
||||||
m_pendingRequests.append(requestId);
|
qCWarning(dcKeba()) << "UDP socket not initialized";
|
||||||
QByteArray data;
|
setReachable(false);
|
||||||
data.append("unlock");
|
return QUuid();
|
||||||
qCDebug(dcKebaKeContact()) << "Unlock charger, command: " << data;
|
}
|
||||||
sendCommand(data);
|
|
||||||
return requestId;
|
QByteArray datagram;
|
||||||
|
datagram.append("unlock");
|
||||||
|
|
||||||
|
KeContactRequest request(QUuid::createUuid(), datagram);
|
||||||
|
qCDebug(dcKeba()) << "Unlock charger: Datagram:" << datagram;
|
||||||
|
m_requestQueue.enqueue(request);
|
||||||
|
sendNextCommand();
|
||||||
|
return request.requestId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeContact::onReceivedDatagram(const QHostAddress &address, const QByteArray &datagram)
|
void KeContact::onReceivedDatagram(const QHostAddress &address, const QByteArray &datagram)
|
||||||
{
|
{
|
||||||
|
// Make sure the datagram is for this keba
|
||||||
if (address != m_address) {
|
if (address != m_address) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(datagram.contains("TCH-OK")){
|
qCDebug(dcKeba()) << "<--" << qUtf8Printable(datagram);
|
||||||
|
|
||||||
|
if (datagram.contains("TCH-OK")){
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
|
|
||||||
//Command response has been received, now send the next command
|
//Command response has been received, now send the next command
|
||||||
m_deviceBlocked = false;
|
|
||||||
m_requestTimeoutTimer->stop();
|
m_requestTimeoutTimer->stop();
|
||||||
handleNextCommandInQueue();
|
|
||||||
|
|
||||||
if (!m_pendingRequests.isEmpty()) {
|
if (m_currentRequest.isValid()) {
|
||||||
QUuid requestId = m_pendingRequests.takeFirst();
|
|
||||||
if (datagram.contains("done")) {
|
if (datagram.contains("done")) {
|
||||||
emit commandExecuted(requestId, true);
|
qCDebug(dcKeba()) << "Command" << m_currentRequest.command() << "finished successfully";
|
||||||
|
emit commandExecuted(m_currentRequest.requestId(), true);
|
||||||
} else {
|
} else {
|
||||||
emit commandExecuted(requestId, false);
|
qCWarning(dcKeba()) << "Command" << m_currentRequest.command() << "finished with error" << datagram;
|
||||||
|
emit commandExecuted(m_currentRequest.requestId(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Schedule pause timer to send next request
|
||||||
|
m_pauseTimer->start(m_currentRequest.delayUntilNextCommand());
|
||||||
|
m_currentRequest = KeContactRequest();
|
||||||
} else {
|
} else {
|
||||||
//Probably the response has taken too long and the requestId has been already removed
|
//Probably the response has taken too long and the requestId has been already removed
|
||||||
|
qCWarning(dcKeba()) << "Received command OK response without pending request." << datagram;
|
||||||
}
|
}
|
||||||
} else if(datagram.left(8).contains("Firmware")){
|
} else if (datagram.left(8).contains("Firmware")){
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
|
|
||||||
//Command response has been received, now send the next command
|
// Command response has been received, now send the next command
|
||||||
m_deviceBlocked = false;
|
|
||||||
m_requestTimeoutTimer->stop();
|
m_requestTimeoutTimer->stop();
|
||||||
handleNextCommandInQueue();
|
if (m_currentRequest.isValid()) {
|
||||||
|
// Schedule pause timer to send next request
|
||||||
|
m_pauseTimer->start(m_currentRequest.delayUntilNextCommand());
|
||||||
|
m_currentRequest = KeContactRequest();
|
||||||
|
}
|
||||||
|
|
||||||
qCDebug(dcKebaKeContact()) << "Firmware information received";
|
qCDebug(dcKeba()) << "Firmware information received";
|
||||||
QByteArrayList firmware = datagram.split(':');
|
QByteArrayList firmware = datagram.split(':');
|
||||||
if (firmware.length() >= 2) {
|
if (firmware.length() >= 2) {
|
||||||
emit deviceInformationReceived(firmware[1]);
|
emit deviceInformationReceived(firmware[1]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//Command response has been received, now send the next command
|
//Command response has been received, now send the next command
|
||||||
m_deviceBlocked = false;
|
|
||||||
m_requestTimeoutTimer->stop();
|
m_requestTimeoutTimer->stop();
|
||||||
handleNextCommandInQueue();
|
if (m_currentRequest.isValid()) {
|
||||||
|
// Schedule pause timer to send next request
|
||||||
|
m_pauseTimer->start(m_currentRequest.delayUntilNextCommand());
|
||||||
|
m_currentRequest = KeContactRequest();
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the rawdata to a json document
|
// Convert the rawdata to a json document
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(datagram, &error);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(datagram, &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qCWarning(dcKebaKeContact()) << "Failed to parse JSON data" << datagram << ":" << error.errorString();
|
qCWarning(dcKeba()) << "Failed to parse JSON data" << datagram << ":" << error.errorString();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap data = jsonDoc.toVariant().toMap();
|
QVariantMap data = jsonDoc.toVariant().toMap();
|
||||||
|
|
||||||
if(data.contains("ID")) {
|
if (data.contains("ID")) {
|
||||||
int id = data.value("ID").toInt();
|
int id = data.value("ID").toInt();
|
||||||
if (id == 1) {
|
if (id == 1) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
|
|
||||||
ReportOne reportOne;
|
ReportOne reportOne;
|
||||||
qCDebug(dcKebaKeContact()) << "Report 1 received";
|
qCDebug(dcKeba()) << "Report 1 received";
|
||||||
reportOne.product = data.value("Product").toString();
|
reportOne.product = data.value("Product").toString();
|
||||||
reportOne.firmware = data.value("Firmware").toString();
|
reportOne.firmware = data.value("Firmware").toString();
|
||||||
reportOne.serialNumber = data.value("Serial").toString();
|
reportOne.serialNumber = data.value("Serial").toString();
|
||||||
@ -357,23 +483,27 @@ void KeContact::onReceivedDatagram(const QHostAddress &address, const QByteArray
|
|||||||
emit reportOneReceived(reportOne);
|
emit reportOneReceived(reportOne);
|
||||||
|
|
||||||
} else if (id == 2) {
|
} else if (id == 2) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
|
|
||||||
ReportTwo reportTwo;
|
ReportTwo reportTwo;
|
||||||
qCDebug(dcKebaKeContact()) << "Report 2 received";
|
qCDebug(dcKeba()) << "Report 2 received";
|
||||||
int state = data.value("State").toInt();
|
int state = data.value("State").toInt();
|
||||||
reportTwo.state = State(state);
|
reportTwo.state = State(state);
|
||||||
reportTwo.error1 = data.value("Error1").toInt();
|
reportTwo.error1 = data.value("Error1").toInt();
|
||||||
reportTwo.error2 = data.value("Error2").toInt();
|
reportTwo.error2 = data.value("Error2").toInt();
|
||||||
reportTwo.plugState = PlugState(data.value("Plug").toInt());
|
reportTwo.plugState = PlugState(data.value("Plug").toInt());
|
||||||
reportTwo.enableUser = data.value("Enable user").toBool();
|
reportTwo.enableUser = data.value("Enable user").toBool();
|
||||||
reportTwo.enableSys = data.value("Enable sys").toBool();
|
reportTwo.enableSys = data.value("Enable sys").toBool();
|
||||||
reportTwo.maxCurrent = data.value("Max curr").toInt()/1000.00;
|
reportTwo.maxCurrent = data.value("Max curr").toInt() / 1000.00;
|
||||||
reportTwo.maxCurrentPercentage = data.value("Max curr %").toInt()/10.00;
|
reportTwo.maxCurrentPercentage = data.value("Max curr %").toInt() / 10.00;
|
||||||
reportTwo.currentHardwareLimitation = data.value("Curr HW").toInt()/1000.00;
|
reportTwo.currentHardwareLimitation = data.value("Curr HW").toInt() / 1000.00;
|
||||||
reportTwo.currentUser = data.value("Curr user").toInt()/1000.00;
|
reportTwo.currentUser = data.value("Curr user").toInt() / 1000.00;
|
||||||
reportTwo.currentFailsafe = data.value("Curr FS").toInt()/1000.00;
|
reportTwo.currTimer = data.value("Curr timer").toInt() / 1000.00;
|
||||||
|
reportTwo.timeoutCt = data.value("Tmo CT").toInt();
|
||||||
|
reportTwo.currentFailsafe = data.value("Curr FS").toInt() / 1000.00;
|
||||||
reportTwo.timeoutFailsafe = data.value("Tmo FS").toInt();
|
reportTwo.timeoutFailsafe = data.value("Tmo FS").toInt();
|
||||||
reportTwo.setEnergy = data.value("Setenergy").toInt()/10000.00;
|
reportTwo.setEnergy = data.value("Setenergy").toInt() / 10000.00;
|
||||||
reportTwo.output = data.value("Output").toInt();
|
reportTwo.output = data.value("Output").toInt();
|
||||||
reportTwo.input= data.value("Input").toInt();
|
reportTwo.input= data.value("Input").toInt();
|
||||||
reportTwo.serialNumber = data.value("Serial").toString();
|
reportTwo.serialNumber = data.value("Serial").toString();
|
||||||
@ -384,9 +514,11 @@ void KeContact::onReceivedDatagram(const QHostAddress &address, const QByteArray
|
|||||||
emit reportTwoReceived(reportTwo);
|
emit reportTwoReceived(reportTwo);
|
||||||
|
|
||||||
} else if (id == 3) {
|
} else if (id == 3) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
|
|
||||||
ReportThree reportThree;
|
ReportThree reportThree;
|
||||||
qCDebug(dcKebaKeContact()) << "Report 3 received";
|
qCDebug(dcKeba()) << "Report 3 received";
|
||||||
reportThree.currentPhase1 = data.value("I1").toInt()/1000.00;
|
reportThree.currentPhase1 = data.value("I1").toInt()/1000.00;
|
||||||
reportThree.currentPhase2 = data.value("I2").toInt()/1000.00;
|
reportThree.currentPhase2 = data.value("I2").toInt()/1000.00;
|
||||||
reportThree.currentPhase3 = data.value("I3").toInt()/1000.00;
|
reportThree.currentPhase3 = data.value("I3").toInt()/1000.00;
|
||||||
@ -401,16 +533,18 @@ void KeContact::onReceivedDatagram(const QHostAddress &address, const QByteArray
|
|||||||
reportThree.seconds = data.value("Sec").toInt();
|
reportThree.seconds = data.value("Sec").toInt();
|
||||||
emit reportThreeReceived(reportThree);
|
emit reportThreeReceived(reportThree);
|
||||||
} else if (id >= 100) {
|
} else if (id >= 100) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
|
|
||||||
Report1XX report;
|
Report1XX report;
|
||||||
qCDebug(dcKebaKeContact()) << "Report" << id << "received";
|
qCDebug(dcKeba()) << "Report" << id << "received";
|
||||||
report.sessionId = data.value("Session ID").toInt();
|
report.sessionId = data.value("Session ID").toInt();
|
||||||
report.currHW = data.value("Curr HW").toInt();
|
report.currHW = data.value("Curr HW").toInt();
|
||||||
report.startTime = data.value("E Start ").toInt()/10000.00;
|
report.startEnergy = data.value("E start").toInt() / 10000.00;
|
||||||
report.presentEnergy = data.value("E Pres ").toInt()/10000.00;
|
report.presentEnergy = data.value("E pres").toInt() / 10000.00;
|
||||||
report.startTime = data.value("started[s]").toInt();
|
report.startTime = data.value("started[s]").toInt();
|
||||||
report.endTime = data.value("ended[s] ").toInt();
|
report.endTime = data.value("ended[s]").toInt();
|
||||||
report.stopReason = data.value("reason ").toInt();
|
report.stopReason = data.value("reason").toInt();
|
||||||
report.rfidTag = data.value("RFID tag").toByteArray();
|
report.rfidTag = data.value("RFID tag").toByteArray();
|
||||||
report.rfidClass = data.value("RFID class").toByteArray();
|
report.rfidClass = data.value("RFID class").toByteArray();
|
||||||
report.serialNumber = data.value("Serial").toString();
|
report.serialNumber = data.value("Serial").toString();
|
||||||
@ -419,21 +553,33 @@ void KeContact::onReceivedDatagram(const QHostAddress &address, const QByteArray
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (data.contains("State")) {
|
if (data.contains("State")) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
emit broadcastReceived(BroadcastType::BroadcastTypeState, data.value("State"));
|
emit broadcastReceived(BroadcastType::BroadcastTypeState, data.value("State"));
|
||||||
}
|
}
|
||||||
if (data.contains("Plug")) {
|
if (data.contains("Plug")) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
emit broadcastReceived(BroadcastType::BroadcastTypePlug, data.value("Plug"));
|
emit broadcastReceived(BroadcastType::BroadcastTypePlug, data.value("Plug"));
|
||||||
}
|
}
|
||||||
if (data.contains("Input")) {
|
if (data.contains("Input")) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
emit broadcastReceived(BroadcastType::BroadcastTypeInput, data.value("Input"));
|
emit broadcastReceived(BroadcastType::BroadcastTypeInput, data.value("Input"));
|
||||||
}
|
}
|
||||||
if (data.contains("Enable sys")) {
|
if (data.contains("Enable sys")) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
emit broadcastReceived(BroadcastType::BroadcastTypeEnableSys, data.value("Enable sys"));
|
emit broadcastReceived(BroadcastType::BroadcastTypeEnableSys, data.value("Enable sys"));
|
||||||
}
|
}
|
||||||
if (data.contains("Max curr")) {
|
if (data.contains("Max curr")) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
emit broadcastReceived(BroadcastType::BroadcastTypeMaxCurr, data.value("Max curr"));
|
emit broadcastReceived(BroadcastType::BroadcastTypeMaxCurr, data.value("Max curr"));
|
||||||
}
|
}
|
||||||
if (data.contains("E pres")) {
|
if (data.contains("E pres")) {
|
||||||
|
// We received valid data from the address over the data link, so the wallbox must be reachable
|
||||||
|
setReachable(true);
|
||||||
emit broadcastReceived(BroadcastType::BroadcastTypeEPres, data.value("E pres"));
|
emit broadcastReceived(BroadcastType::BroadcastTypeEPres, data.value("E pres"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2021, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -37,17 +37,36 @@
|
|||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
#include <QQueue>
|
||||||
|
|
||||||
#include "kecontactdatalayer.h"
|
#include "kecontactdatalayer.h"
|
||||||
|
|
||||||
|
class KeContactRequest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KeContactRequest() = default;
|
||||||
|
KeContactRequest(const QUuid &requestId, const QByteArray &command) : m_requestId(requestId), m_command(command) { }
|
||||||
|
|
||||||
|
QUuid requestId() const { return m_requestId; }
|
||||||
|
QByteArray command() const { return m_command; }
|
||||||
|
|
||||||
|
uint delayUntilNextCommand() const { return m_delayUntilNextCommand; }
|
||||||
|
void setDelayUntilNextCommand(uint delayUntilNextCommand) { m_delayUntilNextCommand = delayUntilNextCommand; }
|
||||||
|
|
||||||
|
bool isValid() { return !m_requestId.isNull() && !m_command.isEmpty(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QUuid m_requestId;
|
||||||
|
QByteArray m_command;
|
||||||
|
uint m_delayUntilNextCommand = 200;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class KeContact : public QObject
|
class KeContact : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit KeContact(const QHostAddress &address, KeContactDataLayer *dataLayer, QObject *parent = nullptr);
|
|
||||||
~KeContact();
|
|
||||||
bool init();
|
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
StateStarting = 0,
|
StateStarting = 0,
|
||||||
StateNotReady,
|
StateNotReady,
|
||||||
@ -136,16 +155,20 @@ public:
|
|||||||
int seconds; // current time when the report was generated
|
int seconds; // current time when the report was generated
|
||||||
};
|
};
|
||||||
|
|
||||||
QHostAddress address();
|
explicit KeContact(const QHostAddress &address, KeContactDataLayer *dataLayer, QObject *parent = nullptr);
|
||||||
|
~KeContact();
|
||||||
|
|
||||||
|
QHostAddress address() const;
|
||||||
void setAddress(const QHostAddress &address);
|
void setAddress(const QHostAddress &address);
|
||||||
|
|
||||||
bool reachable();
|
bool reachable() const;
|
||||||
|
|
||||||
QUuid start(const QByteArray &rfidToken, const QByteArray &rfidClassifier); // Command “start”
|
QUuid start(const QByteArray &rfidToken, const QByteArray &rfidClassifier); // Command “start”
|
||||||
QUuid stop(const QByteArray &rfidToken); // Command “stop”
|
QUuid stop(const QByteArray &rfidToken); // Command “stop”
|
||||||
|
|
||||||
QUuid enableOutput(bool state); // Command “ena”
|
QUuid enableOutput(bool state); // Command “ena”
|
||||||
QUuid setMaxAmpere(int milliAmpere); // Command “curr”
|
QUuid setMaxAmpere(int milliAmpere); // Command "currtime"
|
||||||
|
QUuid setMaxAmpereGeneral(int milliAmpere); // Command "curr"
|
||||||
QUuid unlockCharger(); // Command “unlock"
|
QUuid unlockCharger(); // Command “unlock"
|
||||||
QUuid displayMessage(const QByteArray &message); // Command “display”
|
QUuid displayMessage(const QByteArray &message); // Command “display”
|
||||||
QUuid chargeWithEnergyLimit(double energy); // Command “setenergy”
|
QUuid chargeWithEnergyLimit(double energy); // Command “setenergy”
|
||||||
@ -161,21 +184,23 @@ public:
|
|||||||
QUuid setOutputX2(bool state); // Command “output”
|
QUuid setOutputX2(bool state); // Command “output”
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeContactDataLayer *m_dataLayer;
|
KeContactDataLayer *m_dataLayer = nullptr;
|
||||||
bool m_reachable = false;
|
bool m_reachable = false;
|
||||||
|
|
||||||
QHostAddress m_address;
|
QHostAddress m_address;
|
||||||
QByteArrayList m_commandList;
|
|
||||||
bool m_deviceBlocked = false;
|
|
||||||
|
|
||||||
QTimer *m_requestTimeoutTimer = nullptr;
|
QTimer *m_requestTimeoutTimer = nullptr;
|
||||||
int m_serialNumber;
|
QTimer *m_pauseTimer = nullptr;
|
||||||
QList<QUuid> m_pendingRequests;
|
int m_serialNumber = 0;
|
||||||
|
|
||||||
|
KeContactRequest m_currentRequest;
|
||||||
|
QQueue<KeContactRequest> m_requestQueue;
|
||||||
|
|
||||||
void getReport(int reportNumber);
|
void getReport(int reportNumber);
|
||||||
void sendCommand(const QByteArray &command, const QUuid &requestId);
|
|
||||||
void sendCommand(const QByteArray &command);
|
void sendCommand(const QByteArray &command);
|
||||||
void handleNextCommandInQueue();
|
void sendNextCommand();
|
||||||
|
void setReachable(bool reachable);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void reachableChanged(bool status);
|
void reachableChanged(bool status);
|
||||||
@ -189,6 +214,7 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onReceivedDatagram(const QHostAddress &address, const QByteArray &datagram);
|
void onReceivedDatagram(const QHostAddress &address, const QByteArray &datagram);
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // KECONTACT_H
|
#endif // KECONTACT_H
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2021, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
KeContactDataLayer::KeContactDataLayer(QObject *parent) : QObject(parent)
|
KeContactDataLayer::KeContactDataLayer(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "KeContactDataLayer: Creating UDP socket";
|
qCDebug(dcKeba()) << "KeContactDataLayer: Creating UDP socket";
|
||||||
m_udpSocket = new QUdpSocket(this);
|
m_udpSocket = new QUdpSocket(this);
|
||||||
connect(m_udpSocket, &QUdpSocket::readyRead, this, &KeContactDataLayer::readPendingDatagrams);
|
connect(m_udpSocket, &QUdpSocket::readyRead, this, &KeContactDataLayer::readPendingDatagrams);
|
||||||
connect(m_udpSocket, &QUdpSocket::stateChanged, this, &KeContactDataLayer::onSocketStateChanged);
|
connect(m_udpSocket, &QUdpSocket::stateChanged, this, &KeContactDataLayer::onSocketStateChanged);
|
||||||
@ -42,18 +42,28 @@ KeContactDataLayer::KeContactDataLayer(QObject *parent) : QObject(parent)
|
|||||||
|
|
||||||
KeContactDataLayer::~KeContactDataLayer()
|
KeContactDataLayer::~KeContactDataLayer()
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "KeContactDataLayer: Deleting UDP socket";
|
qCDebug(dcKeba()) << "KeContactDataLayer: Deleting UDP socket";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeContactDataLayer::init()
|
bool KeContactDataLayer::init()
|
||||||
{
|
{
|
||||||
|
m_udpSocket->close();
|
||||||
|
m_initialized = false;
|
||||||
|
|
||||||
if (!m_udpSocket->bind(QHostAddress::AnyIPv4, m_port, QAbstractSocket::ShareAddress)) {
|
if (!m_udpSocket->bind(QHostAddress::AnyIPv4, m_port, QAbstractSocket::ShareAddress)) {
|
||||||
qCWarning(dcKebaKeContact()) << "KeContactDataLayer: Cannot bind to port" << m_port;
|
qCWarning(dcKeba()) << "KeContactDataLayer: Cannot bind to port" << m_port;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_initialized = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KeContactDataLayer::initialized() const
|
||||||
|
{
|
||||||
|
return m_initialized;
|
||||||
|
}
|
||||||
|
|
||||||
void KeContactDataLayer::write(const QHostAddress &address, const QByteArray &data)
|
void KeContactDataLayer::write(const QHostAddress &address, const QByteArray &data)
|
||||||
{
|
{
|
||||||
m_udpSocket->writeDatagram(data, address, m_port);
|
m_udpSocket->writeDatagram(data, address, m_port);
|
||||||
@ -68,20 +78,19 @@ void KeContactDataLayer::readPendingDatagrams()
|
|||||||
quint16 senderPort;
|
quint16 senderPort;
|
||||||
|
|
||||||
while (socket->hasPendingDatagrams()) {
|
while (socket->hasPendingDatagrams()) {
|
||||||
|
|
||||||
datagram.resize(socket->pendingDatagramSize());
|
datagram.resize(socket->pendingDatagramSize());
|
||||||
socket->readDatagram(datagram.data(), datagram.size(), &senderAddress, &senderPort);
|
socket->readDatagram(datagram.data(), datagram.size(), &senderAddress, &senderPort);
|
||||||
qCDebug(dcKebaKeContact()) << "KeContactDataLayer: Data received" << datagram << senderAddress;
|
qCDebug(dcKeba()) << "KeContactDataLayer: Data received from" << senderAddress.toString() << datagram ;
|
||||||
emit datagramReceived(senderAddress, datagram);
|
emit datagramReceived(senderAddress, datagram);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeContactDataLayer::onSocketError(QAbstractSocket::SocketError error)
|
void KeContactDataLayer::onSocketError(QAbstractSocket::SocketError error)
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "KeContactDataLayer: Socket error" << error;
|
qCDebug(dcKeba()) << "KeContactDataLayer: Socket error" << error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeContactDataLayer::onSocketStateChanged(QAbstractSocket::SocketState socketState)
|
void KeContactDataLayer::onSocketStateChanged(QAbstractSocket::SocketState socketState)
|
||||||
{
|
{
|
||||||
qCDebug(dcKebaKeContact()) << "KeContactDataLayer: Socket state changed" << socketState;
|
qCDebug(dcKeba()) << "KeContactDataLayer: Socket state changed" << socketState;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2021, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -40,11 +40,14 @@ class KeContactDataLayer : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit KeContactDataLayer(QObject *parent = nullptr);
|
explicit KeContactDataLayer(QObject *parent = nullptr);
|
||||||
~KeContactDataLayer();
|
~KeContactDataLayer();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
|
bool initialized() const;
|
||||||
|
|
||||||
void write(const QHostAddress &address, const QByteArray &data);
|
void write(const QHostAddress &address, const QByteArray &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_initialized = false;
|
||||||
int m_port = 7090;
|
int m_port = 7090;
|
||||||
QUdpSocket *m_udpSocket = nullptr;
|
QUdpSocket *m_udpSocket = nullptr;
|
||||||
|
|
||||||
@ -55,6 +58,7 @@ private slots:
|
|||||||
void readPendingDatagrams();
|
void readPendingDatagrams();
|
||||||
void onSocketError(QAbstractSocket::SocketError error);
|
void onSocketError(QAbstractSocket::SocketError error);
|
||||||
void onSocketStateChanged(QAbstractSocket::SocketState socketState);
|
void onSocketStateChanged(QAbstractSocket::SocketState socketState);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KECONTACTDATALAYER_H
|
#endif // KECONTACTDATALAYER_H
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>KebaKeContact</name>
|
<name>Keba</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../../../build-nymea-plugins-Desktop-Debug/keba/plugininfo.h" line="137"/>
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/keba/plugininfo.h" line="137"/>
|
||||||
<location filename="../../../build-nymea-plugins-Desktop-Debug/keba/plugininfo.h" line="140"/>
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/keba/plugininfo.h" line="140"/>
|
||||||
@ -266,7 +266,7 @@ The name of the StateType ({ba600276-8b36-4404-b8ec-415245e5bc15}) of ThingClass
|
|||||||
<source>Keba KeContact</source>
|
<source>Keba KeContact</source>
|
||||||
<extracomment>The name of the ThingClass ({900dacec-cae7-4a37-95ba-501846368ea2})
|
<extracomment>The name of the ThingClass ({900dacec-cae7-4a37-95ba-501846368ea2})
|
||||||
----------
|
----------
|
||||||
The name of the plugin KebaKeContact ({9142b09f-30a9-43d0-9ede-2f8debe075ac})</extracomment>
|
The name of the plugin Keba ({9142b09f-30a9-43d0-9ede-2f8debe075ac})</extracomment>
|
||||||
<translation>Keba KeContact</translation>
|
<translation>Keba KeContact</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>KebaKeContact</name>
|
<name>Keba</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../../../build-nymea-plugins-Desktop-Debug/keba/plugininfo.h" line="137"/>
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/keba/plugininfo.h" line="137"/>
|
||||||
<location filename="../../../build-nymea-plugins-Desktop-Debug/keba/plugininfo.h" line="140"/>
|
<location filename="../../../build-nymea-plugins-Desktop-Debug/keba/plugininfo.h" line="140"/>
|
||||||
@ -266,7 +266,7 @@ The name of the StateType ({ba600276-8b36-4404-b8ec-415245e5bc15}) of ThingClass
|
|||||||
<source>Keba KeContact</source>
|
<source>Keba KeContact</source>
|
||||||
<extracomment>The name of the ThingClass ({900dacec-cae7-4a37-95ba-501846368ea2})
|
<extracomment>The name of the ThingClass ({900dacec-cae7-4a37-95ba-501846368ea2})
|
||||||
----------
|
----------
|
||||||
The name of the plugin KebaKeContact ({9142b09f-30a9-43d0-9ede-2f8debe075ac})</extracomment>
|
The name of the plugin Keba ({9142b09f-30a9-43d0-9ede-2f8debe075ac})</extracomment>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user