EVBox: Better debug info and fix a double action finish() call
parent
7c07245358
commit
77d5d486fa
|
|
@ -41,7 +41,6 @@
|
||||||
#define ETX 0x03
|
#define ETX 0x03
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EVBoxPort::EVBoxPort(const QString &portName, QObject *parent)
|
EVBoxPort::EVBoxPort(const QString &portName, QObject *parent)
|
||||||
: QObject{parent}
|
: QObject{parent}
|
||||||
{
|
{
|
||||||
|
|
@ -109,7 +108,10 @@ void EVBoxPort::onReadyRead()
|
||||||
{
|
{
|
||||||
m_waitTimer.start();
|
m_waitTimer.start();
|
||||||
|
|
||||||
m_inputBuffer.append(m_serialPort->readAll());
|
QByteArray data = m_serialPort->readAll();
|
||||||
|
qCDebug(dcEVBox()) << "<--" << data;
|
||||||
|
|
||||||
|
m_inputBuffer.append(data);
|
||||||
|
|
||||||
QByteArray packet;
|
QByteArray packet;
|
||||||
QDataStream inputStream(m_inputBuffer);
|
QDataStream inputStream(m_inputBuffer);
|
||||||
|
|
@ -124,7 +126,15 @@ void EVBoxPort::onReadyRead()
|
||||||
startFound = true;
|
startFound = true;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcEVBox()) << "Discarding byte not matching start of frame 0x" + QString::number(byte, 16);
|
qCWarning(dcEVBox()) << "Discarding byte 0x" + QString::number(byte, 16) + " which is not matching start of frame 0x" + QString::number(STX, 16);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Sometimes the wallbox seems to stumble and restart packet transmission before a previous packet is finished...
|
||||||
|
// If we detect another STX before an ETX, let's discard it
|
||||||
|
if (byte == STX) {
|
||||||
|
qCWarning(dcEVBox()) << "Bogus data from wallbox detected. Discarding input buffers.";
|
||||||
|
m_inputBuffer.clear();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -139,6 +149,8 @@ void EVBoxPort::onReadyRead()
|
||||||
|
|
||||||
if (startFound && endFound) {
|
if (startFound && endFound) {
|
||||||
m_inputBuffer.remove(0, packet.length() + 2);
|
m_inputBuffer.remove(0, packet.length() + 2);
|
||||||
|
} else if (!startFound) {
|
||||||
|
qCDebug(dcEVBox()) << "End of data but no start of frame header received.";
|
||||||
} else {
|
} else {
|
||||||
qCDebug(dcEVBox()) << "Data is incomplete... Waiting for more...";
|
qCDebug(dcEVBox()) << "Data is incomplete... Waiting for more...";
|
||||||
return;
|
return;
|
||||||
|
|
@ -149,7 +161,7 @@ void EVBoxPort::onReadyRead()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(dcEVBox()) << "<--" << packet;
|
qCDebug(dcEVBox()) << "Data packet received:" << packet;
|
||||||
|
|
||||||
processDataPacket(packet);
|
processDataPacket(packet);
|
||||||
|
|
||||||
|
|
@ -220,7 +232,7 @@ void EVBoxPort::processDataPacket(const QByteArray &packet)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(dcEVBox()) << "Data packet received: From:" << from
|
qCDebug(dcEVBox()) << "Parsed data packet: From:" << from
|
||||||
<< "To:" << to
|
<< "To:" << to
|
||||||
<< "Command:" << command
|
<< "Command:" << command
|
||||||
<< "Serial:" << serial
|
<< "Serial:" << serial
|
||||||
|
|
|
||||||
|
|
@ -141,14 +141,14 @@ void IntegrationPluginEVBox::setupThing(ThingSetupInfo *info)
|
||||||
// Setup routine: Try to set the max charging current to 6A and see if we get a valid answer
|
// Setup routine: Try to set the max charging current to 6A and see if we get a valid answer
|
||||||
port->sendCommand(EVBoxPort::Command68, 60, 6, serialNumber);
|
port->sendCommand(EVBoxPort::Command68, 60, 6, serialNumber);
|
||||||
connect(port, &EVBoxPort::closed, info, [info](){
|
connect(port, &EVBoxPort::closed, info, [info](){
|
||||||
info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("The EVBox is not responding."));
|
info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("The EVBox is has closed the connection."));
|
||||||
});
|
});
|
||||||
connect(port, &EVBoxPort::responseReceived, info, [info, serialNumber](EVBoxPort::Command /*command*/, const QString &serial){
|
connect(port, &EVBoxPort::responseReceived, info, [info, serialNumber](EVBoxPort::Command /*command*/, const QString &serial){
|
||||||
if (serial == serialNumber) {
|
if (serial == serialNumber) {
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
QTimer::singleShot(3000, info, [info](){
|
QTimer::singleShot(5000, info, [info](){
|
||||||
info->finish(Thing::ThingErrorTimeout, QT_TR_NOOP("The EVBox is not responding."));
|
info->finish(Thing::ThingErrorTimeout, QT_TR_NOOP("The EVBox is not responding."));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -272,7 +272,7 @@ void IntegrationPluginEVBox::executeAction(ThingActionInfo *info)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pendingActions[thing].append(info);
|
m_pendingActions[thing].append(info);
|
||||||
connect(info, &ThingActionInfo::finished, this, [=](){
|
connect(info, &ThingActionInfo::aborted, this, [=](){
|
||||||
m_pendingActions[thing].removeAll(info);
|
m_pendingActions[thing].removeAll(info);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -281,7 +281,7 @@ void IntegrationPluginEVBox::executeAction(ThingActionInfo *info)
|
||||||
void IntegrationPluginEVBox::finishPendingAction(Thing *thing)
|
void IntegrationPluginEVBox::finishPendingAction(Thing *thing)
|
||||||
{
|
{
|
||||||
if (!m_pendingActions.value(thing).isEmpty()) {
|
if (!m_pendingActions.value(thing).isEmpty()) {
|
||||||
ThingActionInfo *info = m_pendingActions.value(thing).first();
|
ThingActionInfo *info = m_pendingActions[thing].takeFirst();
|
||||||
qCDebug(dcEVBox()) << "Finishing action:" << info->action().actionTypeId().toString();
|
qCDebug(dcEVBox()) << "Finishing action:" << info->action().actionTypeId().toString();
|
||||||
ActionType actionType = thing->thingClass().actionTypes().findById(info->action().actionTypeId());
|
ActionType actionType = thing->thingClass().actionTypes().findById(info->action().actionTypeId());
|
||||||
if (actionType.name() == "power") {
|
if (actionType.name() == "power") {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue