Skip to content

Commit bf77f85

Browse files
Matthias Akstallermatth-x
authored andcommitted
fix Variables test cases
1 parent 7b68bfd commit bf77f85

3 files changed

Lines changed: 337 additions & 310 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ set(MO_SRC_UNIT
146146
#tests/Reservation.cpp
147147
#tests/Reset.cpp
148148
#tests/LocalAuthList.cpp
149-
#tests/Variables.cpp
149+
tests/Variables.cpp
150150
#tests/Transactions.cpp
151151
#tests/Certificates.cpp
152152
#tests/FirmwareManagement.cpp

src/MicroOcpp.h

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern "C" {
3232
//call mo_setup() to finalize the setup
3333
bool mo_initialize();
3434

35-
//End the lifecycle of MO and free all resources
35+
//End the lifecycle of MO and free all resources. Can be called any time
3636
void mo_deinitialize();
3737

3838
//Returns if library is initialized
@@ -42,7 +42,8 @@ bool mo_isInitialized();
4242
MO_Context *mo_getApiContext();
4343

4444
#if MO_USE_FILEAPI != MO_CUSTOM_FS
45-
//Set if MO can use the filesystem and if it needs to mount it. See "FilesystemAdapter.h" for all options
45+
//Set if MO can use the filesystem and if it needs to mount it. See "FilesystemAdapter.h" for all
46+
//options. Can only set before `mo_setup()`.
4647
void mo_setFilesystemConfig(MO_FilesystemOpt opt);
4748
void mo_setFilesystemConfig2(MO_Context *ctx, MO_FilesystemOpt opt, const char *pathPrefix);
4849
#endif //#if MO_USE_FILEAPI != MO_CUSTOM_FS
@@ -58,6 +59,8 @@ void mo_setFilesystem2(MO_Context *ctx, MO_FilesystemAdapter *filesystem);
5859
* If the connections fails, please refer to
5960
* https://github.com/matth-x/MicroOcpp/issues/36#issuecomment-989716573 for recommendations on
6061
* how to track down the issue with the connection.
62+
*
63+
* Can only set before `mo_setup()`.
6164
*/
6265
bool mo_setWebsocketUrl(
6366
const char *backendUrl, //e.g. "wss://example.com:8443/steve/websocket/CentralSystemService". Must be defined
@@ -96,6 +99,8 @@ bool mo_setWebsocketUrl(
9699
*
97100
* Note: MO v2 does not reset the `Context` pointer in the C++ `Connection` anymore during
98101
* `mo_deinitialize()`. It's recommended to check `ctx` in `MO_Connection`, or `mo_getContext()`.
102+
*
103+
* Can only set before `mo_setup()`.
99104
*/
100105
void mo_setConnection(MO_Connection *connection);
101106
void mo_setConnection2(MO_Context *ctx, MO_Connection *connection);
@@ -124,12 +129,12 @@ void mo_useMockServer();
124129
#endif //MO_ENABLE_MOCK_SERVER
125130

126131
//Set the OCPP version `MO_OCPP_V16` or `MO_OCPP_V201`. Works only if build flags `MO_ENABLE_V16` or
127-
//`MO_ENABLE_V201` are set to 1
132+
//`MO_ENABLE_V201` are set to 1. Can only set before `mo_setup()`.
128133
void mo_setOcppVersion(int ocppVersion);
129134
void mo_setOcppVersion2(MO_Context *ctx, int ocppVersion);
130135

131136
//Set BootNotification fields (for more options, use `mo_setBootNotificationData2()`). For a description of
132-
//the fields, refer to OCPP 1.6 or 2.0.1 specification
137+
//the fields, refer to OCPP 1.6 or 2.0.1 specification. Can only set before `mo_setup()`.
133138
bool mo_setBootNotificationData(
134139
const char *chargePointModel, //model name of this charger, e.g. "Demo Charger"
135140
const char *chargePointVendor); //brand name, e.g. "My Company Ltd."
@@ -161,7 +166,7 @@ bool mo_setBootNotificationData2(MO_Context *ctx, MO_BootNotificationData bnData
161166
* });
162167
* ```
163168
*
164-
* Configure the library with Inputs and Outputs after mo_initialize() and before mo_setup().
169+
* Configure the library with Inputs and Outputs after mo_initialize() and before `mo_setup()`.
165170
*/
166171

167172
void mo_setConnectorPluggedInput(bool (*connectorPlugged)()); //Input about if an EV is plugged to this EVSE
@@ -219,6 +224,8 @@ void mo_loop();
219224
*
220225
* Returns true if it was possible to create the transaction process. Returns
221226
* false if either another transaction process is still active or you need to try it again later.
227+
*
228+
* Transaction management functions can only be called after `mo_setup()`.
222229
*
223230
* OCPP 2.0.1:
224231
* Authorize a transaction. Like the OCPP 1.6 behavior, this should be called when the user swipes the
@@ -437,7 +444,8 @@ void mo_setOnUnlockConnector2(MO_Context *ctx, unsigned int evseId, MO_UnlockCon
437444

438445

439446
/*
440-
* Access further information about the internal state of the library
447+
* Access further information about the internal state of the library. Can only be called
448+
* after `mo_setup()`.
441449
*/
442450

443451
bool mo_isOperative(); //if the charge point is operative (see OCPP1.6 Edit2, p. 45) and ready for transactions
@@ -490,7 +498,7 @@ void mo_v201_setOnResetExecute2(MO_Context *ctx, unsigned int evseId, bool (*onR
490498
#endif //MO_ENABLE_V201
491499

492500
/*
493-
* Further platform configurations (Advanced)
501+
* Further platform configurations (Advanced). Can only set before `mo_setup()`.
494502
*/
495503

496504
//Set custom debug function
@@ -551,7 +559,7 @@ void mo_setDiagnosticsFtpServerCert(MO_Context *ctx, const char *cert); //zero-c
551559
#endif //MO_ENABLE_MBEDTLS
552560

553561
/*
554-
* Transaction management (Advanced)
562+
* Transaction management (Advanced). Can only be called after `mo_setup()`.
555563
*/
556564

557565
bool mo_isTransactionAuthorized();
@@ -625,18 +633,19 @@ bool mo_getConfigurationString(const char *key, const char **valueOut); //need t
625633
//Add new Variable or Config. If running OCPP 2.0.1, `key16` can be NULL. If running OCPP 1.6,
626634
//`component201` and `name201` can be NULL. `component201`, `name201` and `key16` are zero-copy,
627635
//i.e. must outlive the MO lifecycle. Add before `mo_setup()`. At first boot, MO uses `factoryDefault`.
628-
//At subsequent boots, it loads the values from flash during `mo_setup()`
636+
//At subsequent boots, it loads the values from flash during `mo_setup()`. Call before `mo_setup()`.
629637
bool mo_declareVarConfigInt(MO_Context *ctx, const char *component201, const char *name201, const char *key16, int factoryDefault, MO_Mutability mutability, bool persistent, bool rebootRequired);
630638
bool mo_declareVarConfigBool(MO_Context *ctx, const char *component201, const char *name201, const char *key16, bool factoryDefault, MO_Mutability mutability, bool persistent, bool rebootRequired);
631639
bool mo_declareVarConfigString(MO_Context *ctx, const char *component201, const char *name201, const char *key16, const char *factoryDefault, MO_Mutability mutability, bool persistent, bool rebootRequired);
632640

633-
//Set Variable or Config value. Set after `mo_setup()`. If running OCPP 2.0.1, `key16` can be NULL
641+
//Set Variable or Config value. Set after `mo_setup()`. If running OCPP 2.0.1, `key16` can be NULL.
642+
//Call after `mo_setup()`.
634643
bool mo_setVarConfigInt(MO_Context *ctx, const char *component201, const char *name201, const char *key16, int value);
635644
bool mo_setVarConfigBool(MO_Context *ctx, const char *component201, const char *name201, const char *key16, bool value);
636645
bool mo_setVarConfigString(MO_Context *ctx, const char *component201, const char *name201, const char *key16, const char *value);
637646

638647
//Get Config value. MO writes the value into `valueOut`. Call after `mo_setup()`. If running
639-
//OCPP 2.0.1, `key16` can be NULL
648+
//OCPP 2.0.1, `key16` can be NULL. Call after `mo_setup()`.
640649
bool mo_getVarConfigInt(MO_Context *ctx, const char *component201, const char *name201, const char *key16, int *valueOut);
641650
bool mo_getVarConfigBool(MO_Context *ctx, const char *component201, const char *name201, const char *key16, bool *valueOut);
642651
bool mo_getVarConfigString(MO_Context *ctx, const char *component201, const char *name201, const char *key16, const char **valueOut); //need to copy `valueOut` into own buffer. `valueOut` may be invalidated after call
@@ -681,27 +690,28 @@ bool mo_setup2(MO_Context *ctx);
681690
void mo_deinitialize2(MO_Context *ctx);
682691
void mo_loop2(MO_Context *ctx);
683692

684-
//Send operation manually and bypass MO business logic
693+
//Send operation manually and bypass MO business logic. Call after `mo_setup()`.
685694
bool mo_sendRequest(MO_Context *ctx,
686695
const char *operationType, //zero-copy, i.e. must outlive MO
687696
const char *payloadJson, //copied, i.e. can be invalidated
688697
void (*onResponse)(const char *payloadJson, void *userData),
689698
void (*onAbort)(void *userData),
690699
void *userData);
691700

692-
//Set custom operation handler for incoming reqeusts and bypass MO business logic
701+
//Set custom operation handler for incoming reqeusts and bypass MO business logic. Call before
702+
//`mo_setup()`.
693703
bool mo_setRequestHandler(MO_Context *ctx, const char *operationType,
694704
void (*onRequest)(const char *operationType, const char *payloadJson, void **userStatus, void *userData),
695705
int (*writeResponse)(const char *operationType, char *buf, size_t size, void *userStatus, void *userData),
696706
void (*finally)(const char *operationType, void *userStatus, void *userData),
697707
void *userData);
698708

699-
//Sniff incoming requests without control over the response
709+
//Sniff incoming requests without control over the response. Call before `mo_setup()`.
700710
bool mo_setOnReceiveRequest(MO_Context *ctx, const char *operationType,
701711
void (*onRequest)(const char *operationType, const char *payloadJson, void *userData),
702712
void *userData);
703713

704-
//Sniff outgoing responses generated by MO
714+
//Sniff outgoing responses generated by MO. Call before `mo_setup()`.
705715
bool mo_setOnSendConf(MO_Context *ctx, const char *operationType,
706716
void (*onSendConf)(const char *operationType, const char *payloadJson, void *userData),
707717
void *userData);

0 commit comments

Comments
 (0)