forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateFirmware.cpp
More file actions
51 lines (40 loc) · 1.49 KB
/
UpdateFirmware.cpp
File metadata and controls
51 lines (40 loc) · 1.49 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#include <MicroOcpp/Operations/UpdateFirmware.h>
#include <MicroOcpp/Model/Model.h>
#include <MicroOcpp/Model/FirmwareManagement/FirmwareService.h>
#include <MicroOcpp/Debug.h>
using MicroOcpp::Ocpp16::UpdateFirmware;
using MicroOcpp::JsonDoc;
UpdateFirmware::UpdateFirmware(FirmwareService& fwService) : MemoryManaged("v16.Operation.", "UpdateFirmware"), fwService(fwService) {
}
void UpdateFirmware::processReq(JsonObject payload) {
const char *location = payload["location"] | "";
//check location URL. Maybe introduce Same-Origin-Policy?
if (!*location) {
errorCode = "FormationViolation";
return;
}
int retries = payload["retries"] | 1;
int retryInterval = payload["retryInterval"] | 180;
if (retries < 0 || retryInterval < 0) {
errorCode = "PropertyConstraintViolation";
return;
}
//check the integrity of retrieveDate
if (!payload.containsKey("retrieveDate")) {
errorCode = "FormationViolation";
return;
}
Timestamp retrieveDate;
if (!retrieveDate.setTime(payload["retrieveDate"] | "Invalid")) {
errorCode = "PropertyConstraintViolation";
MO_DBG_WARN("bad time format");
return;
}
fwService.scheduleFirmwareUpdate(location, retrieveDate, (unsigned int) retries, (unsigned int) retryInterval);
}
std::unique_ptr<JsonDoc> UpdateFirmware::createConf(){
return createEmptyDocument();
}