Skip to content

Commit 3282db9

Browse files
committed
change MOCPP_ to MO_
1 parent 7e13005 commit 3282db9

File tree

7 files changed

+133
-133
lines changed

7 files changed

+133
-133
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
cmake_minimum_required(VERSION 3.15)
66

7-
set(MOCPP_MG_SRC
7+
set(MO_MG_SRC
88
src/MicroOcppMongooseClient_c.cpp
99
src/MicroOcppMongooseClient.cpp
1010
src/MicroOcppMongooseFtp.cpp
1111
)
1212

1313
if(ESP_PLATFORM)
1414

15-
idf_component_register(SRCS ${MOCPP_MG_SRC}
15+
idf_component_register(SRCS ${MO_MG_SRC}
1616
INCLUDE_DIRS "src"
1717
REQUIRES esp_timer mbedtls mongoose MicroOcpp)
1818

@@ -22,7 +22,7 @@ if(ESP_PLATFORM)
2222
return()
2323
endif()
2424

25-
add_library(MicroOcppMongoose ${MOCPP_MG_SRC})
25+
add_library(MicroOcppMongoose ${MO_MG_SRC})
2626

2727
target_include_directories(MicroOcppMongoose PUBLIC
2828
"./src"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Mongoose WebSocket adapter for MicroOcpp
77

88
The following projects must be available on the include path:
99

10-
- [Mongoose Embedded Networking Library v6.14 / v7.8](https://github.com/cesanta/mongoose/tree/76e6b23a4f0261dd534d33632f42ea1bba99dc85): The MicroOcppMongoose adapter works with the amalgamated files `mongoose.h` and `mongoose.c`. You may need to copy them from the Mongoose-repository into the `src` folder of your project. To use the backwards-compatibility mode with v6.14, set the build flag `MOCPP_MG_VERSION_614`.
10+
- [Mongoose Embedded Networking Library v6.14 / v7.8](https://github.com/cesanta/mongoose/tree/76e6b23a4f0261dd534d33632f42ea1bba99dc85): The MicroOcppMongoose adapter works with the amalgamated files `mongoose.h` and `mongoose.c`. You may need to copy them from the Mongoose-repository into the `src` folder of your project. To use the backwards-compatibility mode with v6.14, set the build flag `MO_MG_VERSION_614`.
1111
- [ArduinoJson v6.19.1](https://github.com/bblanchon/ArduinoJson/tree/079ccadbee4100ad0b2d06f11de8c412b95853c1)
1212
- [MicroOcpp](https://github.com/matth-x/MicroOcpp)
1313

src/MicroOcppMongooseClient.cpp

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#define DEBUG_MSG_INTERVAL 5000UL
1111
#define WS_UNRESPONSIVE_THRESHOLD_MS 15000UL
1212

13-
#if defined(MOCPP_MG_VERSION_614)
14-
#define MOCPP_MG_F_IS_MOcppMongooseClient MG_F_USER_2
13+
#if defined(MO_MG_VERSION_614)
14+
#define MO_MG_F_IS_MOcppMongooseClient MG_F_USER_2
1515
#endif
1616

1717
using namespace MicroOcpp;
@@ -34,49 +34,49 @@ MOcppMongooseClient::MOcppMongooseClient(struct mg_mgr *mgr,
3434
readonly = false;
3535
} else {
3636
//make the credentials non-persistent
37-
MOCPP_DBG_WARN("Credentials non-persistent. Use MicroOcpp::makeDefaultFilesystemAdapter(...) for persistency");
37+
MO_DBG_WARN("Credentials non-persistent. Use MicroOcpp::makeDefaultFilesystemAdapter(...) for persistency");
3838
readonly = true;
3939
}
4040

4141
setting_backend_url_str = declareConfiguration<const char*>(
42-
MOCPP_CONFIG_EXT_PREFIX "BackendUrl", backend_url_factory, MOCPP_WSCONN_FN, readonly, true);
42+
MO_CONFIG_EXT_PREFIX "BackendUrl", backend_url_factory, MO_WSCONN_FN, readonly, true);
4343
setting_cb_id_str = declareConfiguration<const char*>(
44-
MOCPP_CONFIG_EXT_PREFIX "ChargeBoxId", charge_box_id_factory, MOCPP_WSCONN_FN, readonly, true);
44+
MO_CONFIG_EXT_PREFIX "ChargeBoxId", charge_box_id_factory, MO_WSCONN_FN, readonly, true);
4545
setting_auth_key_str = declareConfiguration<const char*>(
46-
"AuthorizationKey", auth_key_factory, MOCPP_WSCONN_FN, readonly, true);
47-
#if !MOCPP_CA_CERT_LOCAL
46+
"AuthorizationKey", auth_key_factory, MO_WSCONN_FN, readonly, true);
47+
#if !MO_CA_CERT_LOCAL
4848
setting_ca_cert_str = declareConfiguration<const char*>(
49-
MOCPP_CONFIG_EXT_PREFIX "CaCert", CA_cert_factory, MOCPP_WSCONN_FN, readonly, true);
49+
MO_CONFIG_EXT_PREFIX "CaCert", CA_cert_factory, MO_WSCONN_FN, readonly, true);
5050
#else
5151
ca_cert = CA_cert_factory ? CA_cert_factory : "";
5252
#endif
5353

5454
ws_ping_interval_int = declareConfiguration<int>(
55-
"WebSocketPingInterval", 5, MOCPP_WSCONN_FN);
55+
"WebSocketPingInterval", 5, MO_WSCONN_FN);
5656
reconnect_interval_int = declareConfiguration<int>(
57-
MOCPP_CONFIG_EXT_PREFIX "ReconnectInterval", 10, MOCPP_WSCONN_FN);
57+
MO_CONFIG_EXT_PREFIX "ReconnectInterval", 10, MO_WSCONN_FN);
5858
stale_timeout_int = declareConfiguration<int>(
59-
MOCPP_CONFIG_EXT_PREFIX "StaleTimeout", 300, MOCPP_WSCONN_FN);
59+
MO_CONFIG_EXT_PREFIX "StaleTimeout", 300, MO_WSCONN_FN);
6060

61-
configuration_load(MOCPP_WSCONN_FN); //load configs with values stored on flash
61+
configuration_load(MO_WSCONN_FN); //load configs with values stored on flash
6262

6363
reloadConfigs(); //load WS creds with configs values
6464

65-
#if defined(MOCPP_MG_VERSION_614)
66-
MOCPP_DBG_DEBUG("use MG version %s (tested with 6.14)", MG_VERSION);
65+
#if defined(MO_MG_VERSION_614)
66+
MO_DBG_DEBUG("use MG version %s (tested with 6.14)", MG_VERSION);
6767
#else
68-
MOCPP_DBG_DEBUG("use MG version %s (tested with 7.8)", MG_VERSION);
68+
MO_DBG_DEBUG("use MG version %s (tested with 7.8)", MG_VERSION);
6969
#endif
7070

7171
maintainWsConn();
7272
}
7373

7474
MOcppMongooseClient::~MOcppMongooseClient() {
75-
MOCPP_DBG_DEBUG("destruct MOcppMongooseClient");
75+
MO_DBG_DEBUG("destruct MOcppMongooseClient");
7676
if (websocket) {
7777
reconnect(); //close WS connection, won't be reopened
78-
#if defined(MOCPP_MG_VERSION_614)
79-
websocket->flags &= ~MOCPP_MG_F_IS_MOcppMongooseClient;
78+
#if defined(MO_MG_VERSION_614)
79+
websocket->flags &= ~MO_MG_F_IS_MOcppMongooseClient;
8080
websocket->user_data = nullptr;
8181
#else
8282
websocket->fn_data = nullptr;
@@ -93,7 +93,7 @@ bool MOcppMongooseClient::sendTXT(const char *msg, size_t length) {
9393
return false;
9494
}
9595
size_t sent;
96-
#if defined(MOCPP_MG_VERSION_614)
96+
#if defined(MO_MG_VERSION_614)
9797
if (websocket->send_mbuf.len > 0) {
9898
sent = 0;
9999
return false;
@@ -105,7 +105,7 @@ bool MOcppMongooseClient::sendTXT(const char *msg, size_t length) {
105105
sent = mg_ws_send(websocket, msg, length, WEBSOCKET_OP_TEXT);
106106
#endif
107107
if (sent < length) {
108-
MOCPP_DBG_WARN("mg_ws_send did only accept %zu out of %zu bytes", sent, length);
108+
MO_DBG_WARN("mg_ws_send did only accept %zu out of %zu bytes", sent, length);
109109
//flush broken package and wait for next retry
110110
(void)0;
111111
}
@@ -119,24 +119,24 @@ void MOcppMongooseClient::maintainWsConn() {
119119

120120
//WS successfully connected?
121121
if (!isConnectionOpen()) {
122-
MOCPP_DBG_DEBUG("WS unconnected");
122+
MO_DBG_DEBUG("WS unconnected");
123123
} else if (mocpp_tick_ms() - last_recv >= (ws_ping_interval_int && ws_ping_interval_int->getInt() > 0 ? (ws_ping_interval_int->getInt() * 1000UL) : 0UL) + WS_UNRESPONSIVE_THRESHOLD_MS) {
124124
//WS connected but unresponsive
125-
MOCPP_DBG_DEBUG("WS unresponsive");
125+
MO_DBG_DEBUG("WS unresponsive");
126126
}
127127
}
128128

129129
if (websocket && isConnectionOpen() &&
130130
stale_timeout_int && stale_timeout_int->getInt() > 0 && mocpp_tick_ms() - last_recv >= (stale_timeout_int->getInt() * 1000UL)) {
131-
MOCPP_DBG_INFO("connection %s -- stale, reconnect", url.c_str());
131+
MO_DBG_INFO("connection %s -- stale, reconnect", url.c_str());
132132
reconnect();
133133
return;
134134
}
135135

136136
if (websocket && isConnectionOpen() &&
137137
ws_ping_interval_int && ws_ping_interval_int->getInt() > 0 && mocpp_tick_ms() - last_hb >= (ws_ping_interval_int->getInt() * 1000UL)) {
138138
last_hb = mocpp_tick_ms();
139-
#if defined(MOCPP_MG_VERSION_614)
139+
#if defined(MO_MG_VERSION_614)
140140
mg_send_websocket_frame(websocket, WEBSOCKET_OP_PING, "", 0);
141141
#else
142142
mg_ws_send(websocket, "", 0, WEBSOCKET_OP_PING);
@@ -156,11 +156,11 @@ void MOcppMongooseClient::maintainWsConn() {
156156
return;
157157
}
158158

159-
MOCPP_DBG_DEBUG("(re-)connect to %s", url.c_str());
159+
MO_DBG_DEBUG("(re-)connect to %s", url.c_str());
160160

161161
last_reconnection_attempt = mocpp_tick_ms();
162162

163-
#if defined(MOCPP_MG_VERSION_614)
163+
#if defined(MO_MG_VERSION_614)
164164

165165
struct mg_connect_opts opts;
166166
memset(&opts, 0, sizeof(opts));
@@ -174,7 +174,7 @@ void MOcppMongooseClient::maintainWsConn() {
174174
url.c_str()[2] == ':') {
175175
//yes, disable SSL
176176
ca_string = nullptr;
177-
MOCPP_DBG_WARN("Insecure connection (WS)");
177+
MO_DBG_WARN("Insecure connection (WS)");
178178
}
179179

180180
opts.ssl_ca_cert = ca_string;
@@ -184,7 +184,7 @@ void MOcppMongooseClient::maintainWsConn() {
184184
if (!auth_key.empty()) {
185185
auto ret = snprintf(extra_headers, 128, "Authorization: Basic %s\r\n", basic_auth64.c_str());
186186
if (ret < 0 || ret >= 128) {
187-
MOCPP_DBG_ERR("Basic Authentication failed: %d", ret);
187+
MO_DBG_ERR("Basic Authentication failed: %d", ret);
188188
(void)0;
189189
}
190190
}
@@ -199,7 +199,7 @@ void MOcppMongooseClient::maintainWsConn() {
199199
*extra_headers ? extra_headers : nullptr);
200200

201201
if (websocket) {
202-
websocket->flags |= MOCPP_MG_F_IS_MOcppMongooseClient;
202+
websocket->flags |= MO_MG_F_IS_MOcppMongooseClient;
203203
}
204204

205205
#else
@@ -220,7 +220,7 @@ void MOcppMongooseClient::reconnect() {
220220
if (!websocket) {
221221
return;
222222
}
223-
#if defined(MOCPP_MG_VERSION_614)
223+
#if defined(MO_MG_VERSION_614)
224224
if (!connection_closing) {
225225
const char *msg = "socket closed by client";
226226
mg_send_websocket_frame(websocket, WEBSOCKET_OP_CLOSE, msg, strlen(msg));
@@ -233,7 +233,7 @@ void MOcppMongooseClient::reconnect() {
233233

234234
void MOcppMongooseClient::setBackendUrl(const char *backend_url_cstr) {
235235
if (!backend_url_cstr) {
236-
MOCPP_DBG_ERR("invalid argument");
236+
MO_DBG_ERR("invalid argument");
237237
return;
238238
}
239239

@@ -245,7 +245,7 @@ void MOcppMongooseClient::setBackendUrl(const char *backend_url_cstr) {
245245

246246
void MOcppMongooseClient::setChargeBoxId(const char *cb_id_cstr) {
247247
if (!cb_id_cstr) {
248-
MOCPP_DBG_ERR("invalid argument");
248+
MO_DBG_ERR("invalid argument");
249249
return;
250250
}
251251

@@ -257,7 +257,7 @@ void MOcppMongooseClient::setChargeBoxId(const char *cb_id_cstr) {
257257

258258
void MOcppMongooseClient::setAuthKey(const char *auth_key_cstr) {
259259
if (!auth_key_cstr) {
260-
MOCPP_DBG_ERR("invalid argument");
260+
MO_DBG_ERR("invalid argument");
261261
return;
262262
}
263263

@@ -269,11 +269,11 @@ void MOcppMongooseClient::setAuthKey(const char *auth_key_cstr) {
269269

270270
void MOcppMongooseClient::setCaCert(const char *ca_cert_cstr) {
271271
if (!ca_cert_cstr) {
272-
MOCPP_DBG_ERR("invalid argument");
272+
MO_DBG_ERR("invalid argument");
273273
return;
274274
}
275275

276-
#if !MOCPP_CA_CERT_LOCAL
276+
#if !MO_CA_CERT_LOCAL
277277
if (setting_ca_cert_str) {
278278
setting_ca_cert_str->setString(ca_cert_cstr);
279279
configuration_save();
@@ -302,7 +302,7 @@ void MOcppMongooseClient::reloadConfigs() {
302302
auth_key = setting_auth_key_str->getString();
303303
}
304304

305-
#if !MOCPP_CA_CERT_LOCAL
305+
#if !MO_CA_CERT_LOCAL
306306
if (setting_ca_cert_str) {
307307
ca_cert = setting_ca_cert_str->getString();
308308
}
@@ -316,7 +316,7 @@ void MOcppMongooseClient::reloadConfigs() {
316316
basic_auth64.clear();
317317

318318
if (backend_url.empty()) {
319-
MOCPP_DBG_DEBUG("empty URL closes connection");
319+
MO_DBG_DEBUG("empty URL closes connection");
320320
return;
321321
} else {
322322
url = backend_url;
@@ -331,19 +331,19 @@ void MOcppMongooseClient::reloadConfigs() {
331331
if (!auth_key.empty()) {
332332
std::string token = cb_id + ":" + auth_key;
333333

334-
MOCPP_DBG_DEBUG("auth Token=%s", token.c_str());
334+
MO_DBG_DEBUG("auth Token=%s", token.c_str());
335335

336336
unsigned int base64_length = encode_base64_length(token.length());
337337
std::vector<unsigned char> base64 (base64_length + 1);
338338

339339
// encode_base64() places a null terminator automatically, because the output is a string
340340
base64_length = encode_base64((const unsigned char*) token.c_str(), token.length(), &base64[0]);
341341

342-
MOCPP_DBG_DEBUG("auth64 len=%u, auth64 Token=%s", base64_length, &base64[0]);
342+
MO_DBG_DEBUG("auth64 len=%u, auth64 Token=%s", base64_length, &base64[0]);
343343

344344
basic_auth64 = (const char*) &base64[0];
345345
} else {
346-
MOCPP_DBG_DEBUG("no authentication");
346+
MO_DBG_DEBUG("no authentication");
347347
(void) 0;
348348
}
349349
}
@@ -375,13 +375,13 @@ unsigned long MOcppMongooseClient::getLastConnected() {
375375
return last_connection_established;
376376
}
377377

378-
#if defined(MOCPP_MG_VERSION_614)
378+
#if defined(MO_MG_VERSION_614)
379379

380380
void ws_cb(struct mg_connection *nc, int ev, void *ev_data, void *user_data) {
381381

382382
MOcppMongooseClient *osock = nullptr;
383383

384-
if (user_data && nc->flags & MG_F_IS_WEBSOCKET && nc->flags & MOCPP_MG_F_IS_MOcppMongooseClient) {
384+
if (user_data && nc->flags & MG_F_IS_WEBSOCKET && nc->flags & MO_MG_F_IS_MOcppMongooseClient) {
385385
osock = reinterpret_cast<MOcppMongooseClient*>(user_data);
386386
} else {
387387
return;
@@ -391,18 +391,18 @@ void ws_cb(struct mg_connection *nc, int ev, void *ev_data, void *user_data) {
391391
case MG_EV_CONNECT: {
392392
int status = *((int *) ev_data);
393393
if (status != 0) {
394-
MOCPP_DBG_WARN("connection %s -- error %d", osock->getUrl(), status);
394+
MO_DBG_WARN("connection %s -- error %d", osock->getUrl(), status);
395395
(void)0;
396396
}
397397
break;
398398
}
399399
case MG_EV_WEBSOCKET_HANDSHAKE_DONE: {
400400
struct http_message *hm = (struct http_message *) ev_data;
401401
if (hm->resp_code == 101) {
402-
MOCPP_DBG_INFO("connection %s -- connected!", osock->getUrl());
402+
MO_DBG_INFO("connection %s -- connected!", osock->getUrl());
403403
osock->setConnectionOpen(true);
404404
} else {
405-
MOCPP_DBG_WARN("connection %s -- HTTP error %d", osock->getUrl(), hm->resp_code);
405+
MO_DBG_WARN("connection %s -- HTTP error %d", osock->getUrl(), hm->resp_code);
406406
(void)0;
407407
/* Connection will be closed after this. */
408408
}
@@ -417,7 +417,7 @@ void ws_cb(struct mg_connection *nc, int ev, void *ev_data, void *user_data) {
417417
struct websocket_message *wm = (struct websocket_message *) ev_data;
418418

419419
if (!osock->getReceiveTXTcallback()((const char *) wm->data, wm->size)) { //forward message to Context
420-
MOCPP_DBG_ERR("processing WS input failed");
420+
MO_DBG_ERR("processing WS input failed");
421421
(void)0;
422422
}
423423
osock->updateRcvTimer();
@@ -428,7 +428,7 @@ void ws_cb(struct mg_connection *nc, int ev, void *ev_data, void *user_data) {
428428
break;
429429
}
430430
case MG_EV_CLOSE: {
431-
MOCPP_DBG_INFO("connection %s -- closed", osock->getUrl());
431+
MO_DBG_INFO("connection %s -- closed", osock->getUrl());
432432
osock->cleanConnection();
433433
break;
434434
}
@@ -439,17 +439,17 @@ void ws_cb(struct mg_connection *nc, int ev, void *ev_data, void *user_data) {
439439

440440
void ws_cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
441441
if (ev != 2) {
442-
MOCPP_DBG_VERBOSE("Cb fn with event: %d\n", ev);
442+
MO_DBG_VERBOSE("Cb fn with event: %d\n", ev);
443443
(void)0;
444444
}
445445

446446
MOcppMongooseClient *osock = reinterpret_cast<MOcppMongooseClient*>(fn_data);
447447
if (!osock) {
448448
if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE) {
449-
MOCPP_DBG_INFO("connection %s", ev == MG_EV_CLOSE ? "closed" : "error");
449+
MO_DBG_INFO("connection %s", ev == MG_EV_CLOSE ? "closed" : "error");
450450
(void)0;
451451
} else {
452-
MOCPP_DBG_ERR("invalid state %d", ev);
452+
MO_DBG_ERR("invalid state %d", ev);
453453
(void)0;
454454
}
455455
return;
@@ -469,25 +469,25 @@ void ws_cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
469469
struct mg_tls_opts opts = {.ca = ca_string};
470470
mg_tls_init(c, &opts);
471471
} else {
472-
MOCPP_DBG_WARN("Insecure connection (WS)");
472+
MO_DBG_WARN("Insecure connection (WS)");
473473
}
474474
} else if (ev == MG_EV_WS_OPEN) {
475475
// WS connection established. Perform MQTT login
476-
MOCPP_DBG_INFO("connection %s -- connected!", osock->getUrl());
476+
MO_DBG_INFO("connection %s -- connected!", osock->getUrl());
477477
osock->setConnectionOpen(true);
478478
osock->updateRcvTimer();
479479
} else if (ev == MG_EV_WS_MSG) {
480480
struct mg_ws_message *wm = (struct mg_ws_message *) ev_data;
481481
if (!osock->getReceiveTXTcallback()((const char*) wm->data.ptr, wm->data.len)) {
482-
MOCPP_DBG_WARN("processing input message failed");
482+
MO_DBG_WARN("processing input message failed");
483483
}
484484
osock->updateRcvTimer();
485485
} else if (ev == MG_EV_WS_CTL) {
486486
osock->updateRcvTimer();
487487
}
488488

489489
if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE) {
490-
MOCPP_DBG_INFO("connection %s -- %s", osock->getUrl(), ev == MG_EV_CLOSE ? "closed" : "error");
490+
MO_DBG_INFO("connection %s -- %s", osock->getUrl(), ev == MG_EV_CLOSE ? "closed" : "error");
491491
osock->cleanConnection();
492492
}
493493
}

0 commit comments

Comments
 (0)