Skip to content

Commit

Permalink
Block RAPI commands that will mess with the EVSE manager operation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypoulter committed Jul 5, 2021
1 parent 82e52c4 commit 8142002
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/evse_man.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,8 @@ uint32_t EvseManager::getTimeLimit(EvseClient client)
{
return getClaimProperties(client).getTimeLimit();
}

bool EvseManager::isRapiCommandBlocked(String rapi)
{
return rapi.startsWith("$ST");
}
2 changes: 2 additions & 0 deletions src/evse_man.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ class EvseManager : public MicroTasks::Task
void onSessionComplete(MicroTasks::EventListener *listner) {
_monitor.onSessionComplete(listner);
}

bool isRapiCommandBlocked(String rapi);
};

#endif // !_OPENEVSE_EVSE_MAN_H
19 changes: 11 additions & 8 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,19 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) {
cmd += " "+payload_str;
}

rapiSender.sendCmd(cmd, [](int ret)
if(!evse.isRapiCommandBlocked(cmd))
{
if (RAPI_RESPONSE_OK == ret || RAPI_RESPONSE_NK == ret)
rapiSender.sendCmd(cmd, [](int ret)
{
String rapiString = rapiSender.getResponse();
String mqtt_data = rapiString;
String mqtt_sub_topic = mqtt_topic + "/rapi/out";
mqttclient.publish(mqtt_sub_topic, mqtt_data);
}
});
if (RAPI_RESPONSE_OK == ret || RAPI_RESPONSE_NK == ret)
{
String rapiString = rapiSender.getResponse();
String mqtt_data = rapiString;
String mqtt_sub_topic = mqtt_topic + "/rapi/out";
mqttclient.publish(mqtt_sub_topic, mqtt_data);
}
});
}
}
}
} //end call back
Expand Down
21 changes: 15 additions & 6 deletions src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const char _CONTENT_TYPE_JPEG[] PROGMEM = "image/jpeg";
const char _CONTENT_TYPE_PNG[] PROGMEM = "image/png";
const char _CONTENT_TYPE_SVG[] PROGMEM = "image/svg+xml";

#define RAPI_RESPONSE_BLOCKED -300

void dumpRequest(MongooseHttpServerRequest *request)
{
#ifdef ENABLE_DEBUG_WEB_REQUEST
Expand Down Expand Up @@ -1093,12 +1095,18 @@ handleRapi(MongooseHttpServerRequest *request) {
if (request->hasParam("rapi"))
{
String rapi = request->getParam("rapi");
int ret = RAPI_RESPONSE_NK;

// BUG: Really we should do this in the main loop not here...
RAPI_PORT.flush();
DBUGVAR(rapi);
int ret = rapiSender.sendCmdSync(rapi);
DBUGVAR(ret);
if(!evse.isRapiCommandBlocked(rapi))
{
// BUG: Really we should do this in the main loop not here...
RAPI_PORT.flush();
DBUGVAR(rapi);
ret = rapiSender.sendCmdSync(rapi);
DBUGVAR(ret);
} else {
ret = RAPI_RESPONSE_BLOCKED;
}

if(RAPI_RESPONSE_OK == ret ||
RAPI_RESPONSE_NK == ret)
Expand Down Expand Up @@ -1154,6 +1162,7 @@ handleRapi(MongooseHttpServerRequest *request) {
RAPI_RESPONSE_BAD_CHECKSUM == ret ? F("RAPI_RESPONSE_BAD_CHECKSUM") :
RAPI_RESPONSE_BAD_SEQUENCE_ID == ret ? F("RAPI_RESPONSE_BAD_SEQUENCE_ID") :
RAPI_RESPONSE_ASYNC_EVENT == ret ? F("RAPI_RESPONSE_ASYNC_EVENT") :
RAPI_RESPONSE_BLOCKED == ret ? F("RAPI_RESPONSE_BLOCKED") :
F("UNKNOWN");

if (json) {
Expand All @@ -1164,7 +1173,7 @@ handleRapi(MongooseHttpServerRequest *request) {
s += errorString;
}

code = 500;
code = RAPI_RESPONSE_BLOCKED == ret ? 400 : 500;
}
}
if (false == json) {
Expand Down

0 comments on commit 8142002

Please sign in to comment.