forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnlockConnector.cpp
More file actions
69 lines (53 loc) · 1.89 KB
/
Copy pathUnlockConnector.cpp
File metadata and controls
69 lines (53 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2023
// MIT License
#include <ArduinoOcpp/Operations/UnlockConnector.h>
#include <ArduinoOcpp/Model/Model.h>
#include <ArduinoOcpp/Debug.h>
using ArduinoOcpp::Ocpp16::UnlockConnector;
#define AO_UNLOCK_TIMEOUT 10000
UnlockConnector::UnlockConnector(Model& model) : model(model) {
}
const char* UnlockConnector::getOperationType(){
return "UnlockConnector";
}
void UnlockConnector::processReq(JsonObject payload) {
auto connectorId = payload["connectorId"] | -1;
auto connector = model.getConnector(connectorId);
if (!connector) {
err = true;
return;
}
connector->endTransaction(nullptr, "UnlockCommand");
connector->updateTxNotification(TxNotification::RemoteStop);
unlockConnector = connector->getOnUnlockConnector();
if (unlockConnector != nullptr) {
cbUnlockResult = unlockConnector();
} else {
AO_DBG_WARN("Unlock CB undefined");
}
timerStart = ao_tick_ms();
}
std::unique_ptr<DynamicJsonDocument> UnlockConnector::createConf() {
if (!err && ao_tick_ms() - timerStart < AO_UNLOCK_TIMEOUT) {
//do poll and if more time is needed, delay creation of conf msg
if (unlockConnector) {
if (!cbUnlockResult) {
cbUnlockResult = unlockConnector();
if (!cbUnlockResult) {
return nullptr; //no result yet - delay confirmation response
}
}
}
}
auto doc = std::unique_ptr<DynamicJsonDocument>(new DynamicJsonDocument(JSON_OBJECT_SIZE(1)));
JsonObject payload = doc->to<JsonObject>();
if (err || !unlockConnector) {
payload["status"] = "NotSupported";
} else if (cbUnlockResult && cbUnlockResult.toValue()) {
payload["status"] = "Unlocked";
} else {
payload["status"] = "UnlockFailed";
}
return doc;
}