Update 1.2 verion handling and update states and debug information
Signed-off-by: Simon Stürz <simon.stuerz@nymea.io>master
parent
0488683cba
commit
b52d1e99c1
|
|
@ -321,7 +321,13 @@ void IntegrationPluginInro::setupConnection(ThingSetupInfo *info)
|
||||||
// Reset energy live values on disconnected
|
// Reset energy live values on disconnected
|
||||||
thing->setStateValue(pantaboxCurrentPowerStateTypeId, 0);
|
thing->setStateValue(pantaboxCurrentPowerStateTypeId, 0);
|
||||||
} else {
|
} else {
|
||||||
thing->setStateValue(pantaboxModbusTcpVersionStateTypeId, PantaboxDiscovery::modbusVersionToString(connection->modbusTcpVersion()));
|
connection->initialize();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(connection, &Pantabox::initializationFinished, thing, [thing, connection](bool success){
|
||||||
|
if (success) {
|
||||||
|
thing->setStateValue(pantaboxModbusTcpVersionStateTypeId, Pantabox::modbusVersionToString(connection->modbusTcpVersion()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -360,7 +366,7 @@ void IntegrationPluginInro::setupConnection(ThingSetupInfo *info)
|
||||||
thing->setStateValue(pantaboxPluggedInStateTypeId, connection->chargingState() >= Pantabox::ChargingStateB);
|
thing->setStateValue(pantaboxPluggedInStateTypeId, connection->chargingState() >= Pantabox::ChargingStateB);
|
||||||
thing->setStateValue(pantaboxChargingStateTypeId, connection->chargingState() >= Pantabox::ChargingStateC);
|
thing->setStateValue(pantaboxChargingStateTypeId, connection->chargingState() >= Pantabox::ChargingStateC);
|
||||||
thing->setStateValue(pantaboxCurrentPowerStateTypeId, connection->currentPower()); // W
|
thing->setStateValue(pantaboxCurrentPowerStateTypeId, connection->currentPower()); // W
|
||||||
thing->setStateValue(pantaboxTotalEnergyConsumedStateTypeId, connection->chargedEnergy() / 1000.0); // Wh
|
thing->setStateValue(pantaboxSessionEnergyStateTypeId, connection->chargedEnergy() / 1000.0); // Wh
|
||||||
thing->setStateMaxValue(pantaboxMaxChargingCurrentActionTypeId, connection->maxPossibleChargingCurrent());
|
thing->setStateMaxValue(pantaboxMaxChargingCurrentActionTypeId, connection->maxPossibleChargingCurrent());
|
||||||
|
|
||||||
// Phase count is a setting, since we don't get the information from the device.
|
// Phase count is a setting, since we don't get the information from the device.
|
||||||
|
|
@ -371,6 +377,10 @@ void IntegrationPluginInro::setupConnection(ThingSetupInfo *info)
|
||||||
thing->setStateValue(pantaboxPhaseCountStateTypeId, Electricity::getPhaseCount(phases));
|
thing->setStateValue(pantaboxPhaseCountStateTypeId, Electricity::getPhaseCount(phases));
|
||||||
thing->setStateValue(pantaboxUsedPhasesStateTypeId, thing->setting(pantaboxSettingsPhasesParamTypeId).toString());
|
thing->setStateValue(pantaboxUsedPhasesStateTypeId, thing->setting(pantaboxSettingsPhasesParamTypeId).toString());
|
||||||
|
|
||||||
|
// Following states depend on the modbus TCP version, default they will be reset.
|
||||||
|
thing->setStateValue(pantaboxFirmwareVersionStateTypeId, connection->firmwareVersion());
|
||||||
|
thing->setStateValue(pantaboxTotalEnergyConsumedStateTypeId, connection->absoluteEnergy() / 1000.0); // Wh
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
m_connections.insert(thing, connection);
|
m_connections.insert(thing, connection);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
"className": "Pantabox",
|
"className": "Pantabox",
|
||||||
"protocol": "TCP",
|
"protocol": "TCP",
|
||||||
"endianness": "LittleEndian",
|
"endianness": "LittleEndian",
|
||||||
|
"stringEndianness": "LittleEndian",
|
||||||
"errorLimitUntilNotReachable": 2,
|
"errorLimitUntilNotReachable": 2,
|
||||||
"checkReachableRegister": "chargingState",
|
"checkReachableRegister": "chargingState",
|
||||||
"blocks": [ ],
|
"blocks": [ ],
|
||||||
|
|
@ -81,7 +82,7 @@
|
||||||
"id": "firmwareVersion",
|
"id": "firmwareVersion",
|
||||||
"address": 266,
|
"address": 266,
|
||||||
"size": 16,
|
"size": 16,
|
||||||
"type": "uint32",
|
"type": "string",
|
||||||
"registerType": "inputRegister",
|
"registerType": "inputRegister",
|
||||||
"description": "Firmware version",
|
"description": "Firmware version",
|
||||||
"readSchedule": "update",
|
"readSchedule": "update",
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "pantabox.h"
|
#include "pantabox.h"
|
||||||
#include "loggingcategories.h"
|
|
||||||
#include "pantaboxmodbustcpconnection.cpp"
|
#include "pantaboxmodbustcpconnection.cpp"
|
||||||
|
|
||||||
Pantabox::Pantabox(const QHostAddress &hostAddress, uint port, quint16 slaveId, QObject *parent) :
|
Pantabox::Pantabox(const QHostAddress &hostAddress, uint port, quint16 slaveId, QObject *parent) :
|
||||||
|
|
@ -38,6 +37,13 @@ Pantabox::Pantabox(const QHostAddress &hostAddress, uint port, quint16 slaveId,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Pantabox::modbusVersionToString(quint32 value)
|
||||||
|
{
|
||||||
|
quint16 modbusVersionMinor = (value >> 16) & 0xffff;
|
||||||
|
quint16 modbusVersionMajor = value & 0xffff;
|
||||||
|
return QString("%1.%2").arg(modbusVersionMajor).arg(modbusVersionMinor);
|
||||||
|
}
|
||||||
|
|
||||||
bool Pantabox::update() {
|
bool Pantabox::update() {
|
||||||
if (!m_modbusTcpMaster->connected())
|
if (!m_modbusTcpMaster->connected())
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -308,45 +314,11 @@ bool Pantabox::update() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// The Modbus register for absolute charged energy is available since Modbusversion 1.1
|
|
||||||
if (m_modbusTcpVersion > 65536) {
|
|
||||||
|
|
||||||
// Read Absolute charged energy
|
// Following Modbus registers depend on the modbus TCP protocol version and require compatibility checks
|
||||||
qCDebug(dcPantaboxModbusTcpConnection()) << "--> Read \"Absolute charged energy\" register:" << 519 << "size:" << 2;
|
|
||||||
reply = readAbsoluteEnergy();
|
|
||||||
if (!reply) {
|
|
||||||
qCWarning(dcPantaboxModbusTcpConnection()) << "Error occurred while reading \"Absolute charged energy\" registers from" << m_modbusTcpMaster->hostAddress().toString() << m_modbusTcpMaster->errorString();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reply->isFinished()) {
|
// Firmware version registers are available since modbus TCP version 1.1 (0x0001 0x0001) 0x10001 = 65537
|
||||||
reply->deleteLater(); // Broadcast reply returns immediatly
|
if (m_modbusTcpVersion >= 65537) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pendingUpdateReplies.append(reply);
|
|
||||||
connect(reply, &QModbusReply::finished, reply, &QModbusReply::deleteLater);
|
|
||||||
connect(reply, &QModbusReply::finished, this, [this, reply](){
|
|
||||||
m_pendingUpdateReplies.removeAll(reply);
|
|
||||||
handleModbusError(reply->error());
|
|
||||||
if (reply->error() != QModbusDevice::NoError) {
|
|
||||||
verifyUpdateFinished();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QModbusDataUnit unit = reply->result();
|
|
||||||
processAbsoluteEnergyRegisterValues(unit.values());
|
|
||||||
verifyUpdateFinished();
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(reply, &QModbusReply::errorOccurred, this, [this, reply] (QModbusDevice::Error error){
|
|
||||||
QModbusResponse response = reply->rawResult();
|
|
||||||
if (reply->error() == QModbusDevice::ProtocolError && response.isException()) {
|
|
||||||
qCWarning(dcPantaboxModbusTcpConnection()) << "Modbus reply error occurred while reading \"Absolute charged energy\" registers from" << m_modbusTcpMaster->hostAddress().toString() << error << reply->errorString() << ModbusDataUtils::exceptionCodeToString(response.exceptionCode());
|
|
||||||
} else {
|
|
||||||
qCWarning(dcPantaboxModbusTcpConnection()) << "Modbus reply error occurred while reading \"Absolute charged energy\" registers from" << m_modbusTcpMaster->hostAddress().toString() << error << reply->errorString();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Read Firmware version
|
// Read Firmware version
|
||||||
qCDebug(dcPantaboxModbusTcpConnection()) << "--> Read \"Firmware version\" register:" << 266 << "size:" << 16;
|
qCDebug(dcPantaboxModbusTcpConnection()) << "--> Read \"Firmware version\" register:" << 266 << "size:" << 16;
|
||||||
|
|
@ -385,5 +357,47 @@ bool Pantabox::update() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Absolute charged energy is available since modbus TCP version 1.2 (0x0001 0x0002) 0x10002 = 65538
|
||||||
|
if (m_modbusTcpVersion >= 65538) {
|
||||||
|
|
||||||
|
// Read Absolute charged energy
|
||||||
|
qCDebug(dcPantaboxModbusTcpConnection()) << "--> Read \"Absolute charged energy\" register:" << 519 << "size:" << 2;
|
||||||
|
reply = readAbsoluteEnergy();
|
||||||
|
if (!reply) {
|
||||||
|
qCWarning(dcPantaboxModbusTcpConnection()) << "Error occurred while reading \"Absolute charged energy\" registers from" << m_modbusTcpMaster->hostAddress().toString() << m_modbusTcpMaster->errorString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reply->isFinished()) {
|
||||||
|
reply->deleteLater(); // Broadcast reply returns immediatly
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pendingUpdateReplies.append(reply);
|
||||||
|
connect(reply, &QModbusReply::finished, reply, &QModbusReply::deleteLater);
|
||||||
|
connect(reply, &QModbusReply::finished, this, [this, reply](){
|
||||||
|
m_pendingUpdateReplies.removeAll(reply);
|
||||||
|
handleModbusError(reply->error());
|
||||||
|
if (reply->error() != QModbusDevice::NoError) {
|
||||||
|
verifyUpdateFinished();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QModbusDataUnit unit = reply->result();
|
||||||
|
processAbsoluteEnergyRegisterValues(unit.values());
|
||||||
|
verifyUpdateFinished();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(reply, &QModbusReply::errorOccurred, this, [this, reply] (QModbusDevice::Error error){
|
||||||
|
QModbusResponse response = reply->rawResult();
|
||||||
|
if (reply->error() == QModbusDevice::ProtocolError && response.isException()) {
|
||||||
|
qCWarning(dcPantaboxModbusTcpConnection()) << "Modbus reply error occurred while reading \"Absolute charged energy\" registers from" << m_modbusTcpMaster->hostAddress().toString() << error << reply->errorString() << ModbusDataUtils::exceptionCodeToString(response.exceptionCode());
|
||||||
|
} else {
|
||||||
|
qCWarning(dcPantaboxModbusTcpConnection()) << "Modbus reply error occurred while reading \"Absolute charged energy\" registers from" << m_modbusTcpMaster->hostAddress().toString() << error << reply->errorString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,11 @@ class Pantabox : public PantaboxModbusTcpConnection
|
||||||
public:
|
public:
|
||||||
explicit Pantabox(const QHostAddress &hostAddress, uint port, quint16 slaveId, QObject *parent = nullptr);
|
explicit Pantabox(const QHostAddress &hostAddress, uint port, quint16 slaveId, QObject *parent = nullptr);
|
||||||
explicit Pantabox(ModbusTcpMaster *modbusTcpMaster, quint16 slaveId, QObject *parent = nullptr);
|
explicit Pantabox(ModbusTcpMaster *modbusTcpMaster, quint16 slaveId, QObject *parent = nullptr);
|
||||||
~Pantabox() = default;
|
~Pantabox() override = default ;
|
||||||
|
|
||||||
virtual bool update() override;
|
static QString modbusVersionToString(quint32 value);
|
||||||
|
|
||||||
|
bool update() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PANTABOX_H
|
#endif // PANTABOX_H
|
||||||
|
|
|
||||||
|
|
@ -43,13 +43,6 @@ QList<PantaboxDiscovery::Result> PantaboxDiscovery::results() const
|
||||||
return m_results;
|
return m_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PantaboxDiscovery::modbusVersionToString(quint32 value)
|
|
||||||
{
|
|
||||||
quint16 modbusVersionMinor = (value >> 8) & 0xffff;
|
|
||||||
quint16 modbusVersionMajor = value & 0xffff;
|
|
||||||
return QString("%1.%2").arg(modbusVersionMajor).arg(modbusVersionMinor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PantaboxDiscovery::startDiscovery()
|
void PantaboxDiscovery::startDiscovery()
|
||||||
{
|
{
|
||||||
qCInfo(dcInro()) << "Discovery: Start searching for PANTABOX wallboxes in the network...";
|
qCInfo(dcInro()) << "Discovery: Start searching for PANTABOX wallboxes in the network...";
|
||||||
|
|
@ -87,8 +80,8 @@ void PantaboxDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevic
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modbus registers for vendor and product name are available since Modbus version 1.1
|
// Vendor and product name registers are available since modbus TCP version 1.1 (0x0001 0x0001) 0x10001 = 65537
|
||||||
if (connection->modbusTcpVersion() > 65536) {
|
if (connection->modbusTcpVersion() >= 65537) {
|
||||||
|
|
||||||
QModbusReply *reply = connection->readProductName();
|
QModbusReply *reply = connection->readProductName();
|
||||||
if (!reply) {
|
if (!reply) {
|
||||||
|
|
@ -111,7 +104,6 @@ void PantaboxDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevic
|
||||||
}
|
}
|
||||||
|
|
||||||
const QModbusDataUnit unit = reply->result();
|
const QModbusDataUnit unit = reply->result();
|
||||||
qCDebug(dcInro()) << "<-- Response from \"Name of product\" register" << 262 << "size:" << 4 << unit.values();
|
|
||||||
if (unit.values().size() == 4) {
|
if (unit.values().size() == 4) {
|
||||||
QString receivedProductName = ModbusDataUtils::convertToString(unit.values(), connection->stringEndianness());
|
QString receivedProductName = ModbusDataUtils::convertToString(unit.values(), connection->stringEndianness());
|
||||||
if (receivedProductName.toUpper().contains("PANTABOX")) {
|
if (receivedProductName.toUpper().contains("PANTABOX")) {
|
||||||
|
|
@ -127,7 +119,8 @@ void PantaboxDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevic
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
qCDebug(dcInro()) << "Discovery: Device not added to result because of wrong ModbusTcpVersion" << modbusVersionToString(connection->modbusTcpVersion());
|
qCDebug(dcInro()) << "Discovery: Adding connection to results even tough the result is not precise due to modbus TCP protocol version:"
|
||||||
|
<< connection->modbusTcpVersion() << Pantabox::modbusVersionToString(connection->modbusTcpVersion());
|
||||||
addResult(connection, networkDeviceInfo);
|
addResult(connection, networkDeviceInfo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -183,7 +176,7 @@ void PantaboxDiscovery::addResult(Pantabox *connection, const NetworkDeviceInfo
|
||||||
|
|
||||||
Result result;
|
Result result;
|
||||||
result.serialNumber = QString::number(connection->serialNumber(), 16).toUpper();
|
result.serialNumber = QString::number(connection->serialNumber(), 16).toUpper();
|
||||||
result.modbusTcpVersion = modbusVersionToString(connection->modbusTcpVersion());
|
result.modbusTcpVersion = Pantabox::modbusVersionToString(connection->modbusTcpVersion());
|
||||||
result.networkDeviceInfo = networkDeviceInfo;
|
result.networkDeviceInfo = networkDeviceInfo;
|
||||||
m_results.append(result);
|
m_results.append(result);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,6 @@ public:
|
||||||
|
|
||||||
QList<PantaboxDiscovery::Result> results() const;
|
QList<PantaboxDiscovery::Result> results() const;
|
||||||
|
|
||||||
static QString modbusVersionToString(quint32 value);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void startDiscovery();
|
void startDiscovery();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue