// matth-x/MicroOcpp // Copyright Matthias Akstaller 2019 - 2024 // MIT License #include #include #include using MicroOcpp::Ocpp16::ClearCache; using MicroOcpp::JsonDoc; ClearCache::ClearCache(std::shared_ptr filesystem) : MemoryManaged("v16.Operation.", "ClearCache"), filesystem(filesystem) { } const char* ClearCache::getOperationType(){ return "ClearCache"; } void ClearCache::processReq(JsonObject payload) { MO_DBG_WARN("Clear transaction log (Authorization Cache not supported)"); if (!filesystem) { //no persistency - nothing to do return; } success = FilesystemUtils::remove_if(filesystem, [] (const char *fname) -> bool { return !strncmp(fname, "sd", strlen("sd")) || !strncmp(fname, "tx", strlen("tx")) || !strncmp(fname, "op", strlen("op")); }); } std::unique_ptr ClearCache::createConf(){ auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(1)); JsonObject payload = doc->to(); if (success) { payload["status"] = "Accepted"; //"Accepted", because the intended postcondition is true } else { payload["status"] = "Rejected"; } return doc; }