Skip to content

Commit 8142002

Browse files
committed
Block RAPI commands that will mess with the EVSE manager operation
1 parent 82e52c4 commit 8142002

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

src/evse_man.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,8 @@ uint32_t EvseManager::getTimeLimit(EvseClient client)
524524
{
525525
return getClaimProperties(client).getTimeLimit();
526526
}
527+
528+
bool EvseManager::isRapiCommandBlocked(String rapi)
529+
{
530+
return rapi.startsWith("$ST");
531+
}

src/evse_man.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ class EvseManager : public MicroTasks::Task
393393
void onSessionComplete(MicroTasks::EventListener *listner) {
394394
_monitor.onSessionComplete(listner);
395395
}
396+
397+
bool isRapiCommandBlocked(String rapi);
396398
};
397399

398400
#endif // !_OPENEVSE_EVSE_MAN_H

src/mqtt.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,19 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) {
9595
cmd += " "+payload_str;
9696
}
9797

98-
rapiSender.sendCmd(cmd, [](int ret)
98+
if(!evse.isRapiCommandBlocked(cmd))
9999
{
100-
if (RAPI_RESPONSE_OK == ret || RAPI_RESPONSE_NK == ret)
100+
rapiSender.sendCmd(cmd, [](int ret)
101101
{
102-
String rapiString = rapiSender.getResponse();
103-
String mqtt_data = rapiString;
104-
String mqtt_sub_topic = mqtt_topic + "/rapi/out";
105-
mqttclient.publish(mqtt_sub_topic, mqtt_data);
106-
}
107-
});
102+
if (RAPI_RESPONSE_OK == ret || RAPI_RESPONSE_NK == ret)
103+
{
104+
String rapiString = rapiSender.getResponse();
105+
String mqtt_data = rapiString;
106+
String mqtt_sub_topic = mqtt_topic + "/rapi/out";
107+
mqttclient.publish(mqtt_sub_topic, mqtt_data);
108+
}
109+
});
110+
}
108111
}
109112
}
110113
} //end call back

src/web_server.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const char _CONTENT_TYPE_JPEG[] PROGMEM = "image/jpeg";
5656
const char _CONTENT_TYPE_PNG[] PROGMEM = "image/png";
5757
const char _CONTENT_TYPE_SVG[] PROGMEM = "image/svg+xml";
5858

59+
#define RAPI_RESPONSE_BLOCKED -300
60+
5961
void dumpRequest(MongooseHttpServerRequest *request)
6062
{
6163
#ifdef ENABLE_DEBUG_WEB_REQUEST
@@ -1093,12 +1095,18 @@ handleRapi(MongooseHttpServerRequest *request) {
10931095
if (request->hasParam("rapi"))
10941096
{
10951097
String rapi = request->getParam("rapi");
1098+
int ret = RAPI_RESPONSE_NK;
10961099

1097-
// BUG: Really we should do this in the main loop not here...
1098-
RAPI_PORT.flush();
1099-
DBUGVAR(rapi);
1100-
int ret = rapiSender.sendCmdSync(rapi);
1101-
DBUGVAR(ret);
1100+
if(!evse.isRapiCommandBlocked(rapi))
1101+
{
1102+
// BUG: Really we should do this in the main loop not here...
1103+
RAPI_PORT.flush();
1104+
DBUGVAR(rapi);
1105+
ret = rapiSender.sendCmdSync(rapi);
1106+
DBUGVAR(ret);
1107+
} else {
1108+
ret = RAPI_RESPONSE_BLOCKED;
1109+
}
11021110

11031111
if(RAPI_RESPONSE_OK == ret ||
11041112
RAPI_RESPONSE_NK == ret)
@@ -1154,6 +1162,7 @@ handleRapi(MongooseHttpServerRequest *request) {
11541162
RAPI_RESPONSE_BAD_CHECKSUM == ret ? F("RAPI_RESPONSE_BAD_CHECKSUM") :
11551163
RAPI_RESPONSE_BAD_SEQUENCE_ID == ret ? F("RAPI_RESPONSE_BAD_SEQUENCE_ID") :
11561164
RAPI_RESPONSE_ASYNC_EVENT == ret ? F("RAPI_RESPONSE_ASYNC_EVENT") :
1165+
RAPI_RESPONSE_BLOCKED == ret ? F("RAPI_RESPONSE_BLOCKED") :
11571166
F("UNKNOWN");
11581167

11591168
if (json) {
@@ -1164,7 +1173,7 @@ handleRapi(MongooseHttpServerRequest *request) {
11641173
s += errorString;
11651174
}
11661175

1167-
code = 500;
1176+
code = RAPI_RESPONSE_BLOCKED == ret ? 400 : 500;
11681177
}
11691178
}
11701179
if (false == json) {

0 commit comments

Comments
 (0)