186 lines
7.6 KiB
C++
186 lines
7.6 KiB
C++
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
*
|
|
* Copyright 2013 - 2020, nymea GmbH
|
|
* Contact: contact@nymea.io
|
|
*
|
|
* This file is part of nymea.
|
|
* This project including source code and documentation is protected by
|
|
* copyright law, and remains the property of nymea GmbH. All rights, including
|
|
* reproduction, publication, editing and translation, are reserved. The use of
|
|
* this project is subject to the terms of a license agreement to be concluded
|
|
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
|
* under https://nymea.io/license
|
|
*
|
|
* GNU Lesser General Public License Usage
|
|
* Alternatively, this project may be redistributed and/or modified under the
|
|
* terms of the GNU Lesser General Public License as published by the Free
|
|
* Software Foundation; version 3. This project is distributed in the hope that
|
|
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this project. If not, see <https://www.gnu.org/licenses/>.
|
|
*
|
|
* For any further details and any questions please contact us under
|
|
* contact@nymea.io or see our FAQ/Licensing Information on
|
|
* https://nymea.io/license/faq
|
|
*
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
#ifndef KECONTACT_H
|
|
#define KECONTACT_H
|
|
|
|
#include <QTimer>
|
|
#include <QObject>
|
|
#include <QHostAddress>
|
|
#include <QByteArray>
|
|
#include <QUdpSocket>
|
|
#include <QUuid>
|
|
|
|
class KeContact : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit KeContact(QHostAddress address, QObject *parent = nullptr);
|
|
~KeContact();
|
|
bool init();
|
|
|
|
enum Model {
|
|
ModelUnkown,
|
|
ModelP20,
|
|
ModelP30,
|
|
ModelBMW
|
|
};
|
|
Q_ENUM(Model)
|
|
|
|
enum State {
|
|
StateStarting = 0,
|
|
StateNotReady,
|
|
StateReady,
|
|
StateCharging,
|
|
StateError,
|
|
StateAuthorizationRejected
|
|
};
|
|
Q_ENUM(State)
|
|
|
|
enum PlugState {
|
|
PlugStateUnplugged = 0,
|
|
PlugStatePluggedOnChargingStation = 1,
|
|
PlugStatePluggedOnChargingStationAndPlugLocked = 3,
|
|
PlugStatePluggedOnChargingStationAndPluggedOnEV = 5,
|
|
PlugStatePluggedOnChargingStationAndPlugLockedAndPluggedOnEV = 7
|
|
};
|
|
Q_ENUM(PlugState)
|
|
|
|
enum BroadcastType {
|
|
BroadcastTypeState = 0,
|
|
BroadcastTypePlug,
|
|
BroadcastTypeInput,
|
|
BroadcastTypeEnableSys,
|
|
BroadcastTypeMaxCurr,
|
|
BroadcastTypeEPres
|
|
};
|
|
|
|
struct ReportOne {
|
|
QString product; // Model name (variant
|
|
QString serialNumber; // Serial number
|
|
QString firmware; // Firmware version
|
|
bool comModule; // Communication module is installed (only P30)
|
|
int seconds; // Current system clock since restart of the charging station.(only P30)
|
|
};
|
|
|
|
struct ReportTwo {
|
|
State state; //Current state of the charging station
|
|
int error1; //Detail code for state 4; exceptions see FAQ on www.kecontact.com
|
|
int error2; //Detail code for state 4 exception #6 see FAQ on www.kecontact.com
|
|
PlugState plugState; //Current condition of the loading connection
|
|
bool enableSys; //Enable state for charging (contains Enable input, RFID, UDP,..).
|
|
bool enableUser; //Enable condition via UDP.
|
|
int maxCurrent; //Current preset value via Control pilot in milliampere.
|
|
int maxCurrentPercentage; //Current preset value via Control pilot in 0,1% of the PWM value
|
|
int currentHardwareLimitation; //Highest possible charging current of the charging connection. Contains device maximum, DIP-switch setting, cable coding and temperature reduction.
|
|
int currentUser; //Current preset value of the user via UDP; Default = 63000mA.
|
|
int currentFailsafe; //Current preset value for the Failsafe function.
|
|
int timeoutFailsafe; //Communication timeout before triggering the Failsafe function.
|
|
int currTimer; //Shows the current preset value of currtime.
|
|
int timeoutCt; //Shows the remaining time until the current value is accepted.
|
|
int setEnergy; //Shows the set energy limit
|
|
bool output; //State of the output X2.
|
|
bool input; //State of the potential free Enable input X1. When using the input, please pay attention to the information in the installation manual.
|
|
QString serialNumber; //Serial number
|
|
int seconds; //Current system clock since restart of the charging station.
|
|
};
|
|
|
|
struct ReportThree {
|
|
int VoltagePhase1; //voltage in V
|
|
int VoltagePhase2; //voltage in V
|
|
int VoltagePhase3; //voltage in V
|
|
int CurrentPhase1; //current in mA
|
|
int CurrentPhase2; //current in mA
|
|
int CurrentPhase3; //current in mA
|
|
int Power; //Current power in mW (Real Power).
|
|
int PowerFactor; //Power factor in 0,1% (cosphi)
|
|
int EnergySession; //Power consumption of the current loading session in 0,1Wh; Reset with new loading session (state = 2).
|
|
int EnergyTotal; //Total power consumption (persistent) without current loading session 0,1Wh; Is summed up after each completed charging session (state = 0).
|
|
QString SerialNumber;
|
|
};
|
|
|
|
QHostAddress address();
|
|
void setAddress(const QHostAddress &address);
|
|
|
|
bool reachable();
|
|
|
|
QUuid start(const QByteArray &rfidToken, const QByteArray &rfidClassifier); // Command “start”
|
|
QUuid stop(const QByteArray &rfidToken); // Command “stop”
|
|
|
|
QUuid enableOutput(bool state); // Command “ena”
|
|
QUuid setMaxAmpere(int milliAmpere); // Command “curr”
|
|
QUuid unlockCharger(); // Command “unlock"
|
|
QUuid displayMessage(const QByteArray &message); // Command “display”
|
|
QUuid chargeWithEnergyLimit(double energy); // Command “setenergy”
|
|
QUuid setFailsafe(int timeout, int current, bool save); // Command “failsafe”
|
|
|
|
void getDeviceInformation(); // Command “i”
|
|
void getReport1(); // Command “report”
|
|
void getReport2();
|
|
void getReport3();
|
|
|
|
// Command “report 1xx”
|
|
|
|
// Command “currtime”
|
|
// Command “output”
|
|
|
|
|
|
|
|
private:
|
|
bool m_reachable = false;
|
|
QUdpSocket *m_udpSocket = nullptr;
|
|
QHostAddress m_address;
|
|
QByteArrayList m_commandList;
|
|
bool m_deviceBlocked = false;
|
|
|
|
QTimer *m_requestTimeoutTimer = nullptr;
|
|
int m_serialNumber;
|
|
QList<QUuid> m_pendingRequests;
|
|
|
|
|
|
void sendCommand(const QByteArray &data, const QUuid &requestId);
|
|
void sendCommand(const QByteArray &data);
|
|
void handleNextCommandInQueue();
|
|
|
|
signals:
|
|
void reachableChanged(bool status);
|
|
void commandExecuted(QUuid requestId, bool success);
|
|
void deviceInformationReceived(const QString &firmware);
|
|
void reportOneReceived(const ReportOne &reportOne);
|
|
void reportTwoReceived(const ReportTwo &reportTwo);
|
|
void reportThreeReceived(const ReportThree &reportThree);
|
|
void broadcastReceived(BroadcastType type, const QVariant &content);
|
|
|
|
private slots:
|
|
void readPendingDatagrams();
|
|
};
|
|
#endif // KECONTACT_H
|
|
|