@@ -75,6 +75,23 @@ J *NoteNewRequest(const char *request) {
75
75
return reqdoc ;
76
76
}
77
77
78
+ /**************************************************************************/
79
+ /*!
80
+ @brief Create a new command object to populate before sending to the Notecard.
81
+ Lock for mutual exclusion, not only because access to the card must be serialized, but also because
82
+ both C++ and ArduinoJSON call malloc() which is not a thread-safe operation.
83
+ @param request
84
+ The name of the command, for example `hub.set`.
85
+ @returns a `J` cJSON object with the request name pre-populated.
86
+ */
87
+ /**************************************************************************/
88
+ J * NoteNewCommand (const char * request ) {
89
+ J * reqdoc = JCreateObject ();
90
+ if (reqdoc != NULL )
91
+ JAddStringToObject (reqdoc , c_cmd , request );
92
+ return reqdoc ;
93
+ }
94
+
78
95
/**************************************************************************/
79
96
/*!
80
97
@brief Send a request to the Notecard.
@@ -174,6 +191,13 @@ char *NoteRequestResponseJSON(char *reqJSON) {
174
191
/**************************************************************************/
175
192
J * NoteTransaction (J * req ) {
176
193
194
+ // Validate in case of memory failure of the requestor
195
+ if (req == NULL )
196
+ return NULL ;
197
+
198
+ // Determine whether or not a response will be expected, by virtue of "cmd" being present
199
+ bool noResponseExpected = (JGetString (req , "req" )[0 ] == '\0' && JGetString (req , "cmd" )[0 ] != '\0' );
200
+
177
201
// If a reset of the module is required for any reason, do it now.
178
202
// We must do this before acquiring lock.
179
203
if (resetRequired ) {
@@ -198,7 +222,11 @@ J *NoteTransaction(J *req) {
198
222
199
223
// Pertform the transaction
200
224
char * responseJSON ;
201
- const char * errStr = _Transaction (json , & responseJSON );
225
+ const char * errStr ;
226
+ if (noResponseExpected )
227
+ errStr = _Transaction (json , NULL );
228
+ else
229
+ errStr = _Transaction (json , & responseJSON );
202
230
203
231
// Free the json
204
232
JFree (json );
@@ -211,6 +239,12 @@ J *NoteTransaction(J *req) {
211
239
return rsp ;
212
240
}
213
241
242
+ // Exit with a blank object (with no err field) if no response expected
243
+ if (noResponseExpected ) {
244
+ _UnlockNote ();
245
+ return JCreateObject ();
246
+ }
247
+
214
248
// Parse the reply from the card on the input stream
215
249
J * rspdoc = JParse (responseJSON );
216
250
if (rspdoc == NULL ) {
0 commit comments