Skip to content

Commit 0f3f001

Browse files
authored
ver: Roll version to v1.3.4 (#46)
* remove note-c before re-add * Squashed 'src/note-c/' content from commit ceceeb2 git-subtree-dir: src/note-c git-subtree-split: ceceeb2c9a34540c5c3905c548378f00f6c58428 * Support `Notecard::newCommand` API Added tests and syntax highlighting for `Notecard::newCommand` API
1 parent 4025e16 commit 0f3f001

File tree

6 files changed

+110
-18
lines changed

6 files changed

+110
-18
lines changed

keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ FUNCTIONS
99
begin KEYWORD2
1010
setDebugOutputStream KEYWORD2
1111
i2cTest KEYWORD2
12+
newCommand KEYWORD2
1213
newRequest KEYWORD2
1314
sendRequest KEYWORD2
1415
requestAndResponse KEYWORD2

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Blues Wireless Notecard
2-
version=1.3.3
2+
version=1.3.4
33
author=Blues Wireless
44
maintainer=Blues Wireless <[email protected]>
55
sentence=An easy to use Notecard Library for Arduino.

src/note-c/n_i2c.c

+21-16
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ static void _DelayIO(void);
1818

1919
/**************************************************************************/
2020
/*!
21-
@brief We've noticed that there's an instability in some cards'
22-
implementations of I2C, and as a result we introduce an intentional
23-
delay before each and every I2C I/O.The timing was computed
24-
empirically based on a number of commercial devices.
21+
@brief We've noticed that there's an instability in some cards'
22+
implementations of I2C, and as a result we introduce an intentional
23+
delay before each and every I2C I/O.The timing was computed
24+
empirically based on a number of commercial devices.
2525
*/
2626
/**************************************************************************/
2727
static void _DelayIO()
@@ -31,12 +31,12 @@ static void _DelayIO()
3131

3232
/**************************************************************************/
3333
/*!
34-
@brief Given a JSON string, perform an I2C transaction with the Notecard.
35-
@param json
36-
A c-string containing the JSON request object.
37-
@param jsonResponse
38-
An out parameter c-string buffer that will contain the JSON
39-
response from the Notercard.
34+
@brief Given a JSON string, perform an I2C transaction with the Notecard.
35+
@param json
36+
A c-string containing the JSON request object.
37+
@param jsonResponse
38+
An out parameter c-string buffer that will contain the JSON
39+
response from the Notercard.
4040
@returns a c-string with an error, or `NULL` if no error ocurred.
4141
*/
4242
/**************************************************************************/
@@ -193,9 +193,9 @@ const char *i2cNoteTransaction(char *json, char **jsonResponse)
193193

194194
//**************************************************************************/
195195
/*!
196-
@brief Initialize or re-initialize the I2C subsystem, returning false if
197-
anything fails.
198-
@returns a boolean. `true` if the reset was successful, `false`, if not.
196+
@brief Initialize or re-initialize the I2C subsystem, returning false if
197+
anything fails.
198+
@returns a boolean. `true` if the reset was successful, `false`, if not.
199199
*/
200200
/**************************************************************************/
201201
bool i2cNoteReset()
@@ -209,11 +209,16 @@ bool i2cNoteReset()
209209
return false;
210210
}
211211

212-
// Synchronize by guaranteeing not only that I2C works, but that we drain the remainder of any
213-
// pending partial reply from a previously-aborted session. This outer loop does retries on
214-
// I2C error, and is simply here for robustness.
212+
// Synchronize by guaranteeing not only that I2C works, but that after we send \n that we drain
213+
// the remainder of any pending partial reply from a previously-aborted session. This outer loop
214+
// does retries on I2C error, and is simply here for robustness.
215215
bool notecardReady = false;
216216
int retries;
217+
_LockI2C();
218+
_DelayIO();
219+
_I2CTransmit(_I2CAddress(), (uint8_t *)"\n", 1);
220+
_DelayMs(CARD_REQUEST_I2C_SEGMENT_DELAY_MS);
221+
_UnlockI2C();
217222
for (retries=0; !notecardReady && retries<3; retries++) {
218223

219224
// Loop to drain all chunks of data that may be ready to transmit to us

test/Notecard.test.cpp

+64-1
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,67 @@ int test_notecard_begin_serial_default_parameter_for_baud_rate_is_passed_to_note
10171017
return result;
10181018
}
10191019

1020+
int test_notecard_newCommand_does_not_modify_string_parameter_value_before_passing_to_note_c()
1021+
{
1022+
int result;
1023+
Notecard notecard;
1024+
const char *str = "Hello, Test 23!";
1025+
char str_copy[32];
1026+
1027+
// Setup
1028+
strcpy(str_copy, str);
1029+
noteNewCommand_Parameters.request = nullptr;
1030+
noteNewCommand_Parameters.result = nullptr;
1031+
1032+
// Action
1033+
notecard.newCommand(str_copy);
1034+
1035+
// Evaluate Result
1036+
if (0 == strcmp(str, noteNewCommand_Parameters.request))
1037+
{
1038+
result = 0;
1039+
}
1040+
else
1041+
{
1042+
result = 40;
1043+
}
1044+
1045+
return result;
1046+
}
1047+
1048+
int test_notecard_newCommand_does_not_modify_note_c_result_value_before_returning_to_caller()
1049+
{
1050+
int result;
1051+
Notecard notecard;
1052+
J *json_obj = reinterpret_cast<J *>(malloc(sizeof(J))); // JCreateObject();
1053+
assert(nullptr != json_obj);
1054+
1055+
// Setup
1056+
memset(json_obj, 0x55, sizeof(J)); //assert(nullptr != JAddStringToObject(json_obj,"key1", "value1"));
1057+
{
1058+
noteNewCommand_Parameters.result = reinterpret_cast<J *>(malloc(sizeof(J)));
1059+
assert(nullptr != noteNewCommand_Parameters.result);
1060+
memcpy(noteNewCommand_Parameters.result, json_obj, sizeof(J));
1061+
} //assert(nullptr != (noteNewCommand_Parameters.result = JDuplicate(json_obj,true)));
1062+
1063+
// Action
1064+
J *json_result = notecard.newCommand(nullptr);
1065+
1066+
// Evaluate Result
1067+
if (0 == memcmp(json_obj, json_result, sizeof(J)) /*JCompare(json_obj, json_result, false)*/)
1068+
{
1069+
result = 0;
1070+
}
1071+
else
1072+
{
1073+
result = 41;
1074+
}
1075+
1076+
free(noteNewCommand_Parameters.result);
1077+
free(json_obj);
1078+
return result;
1079+
}
1080+
10201081
int main(void)
10211082
{
10221083
TestFunction tests[] = {
@@ -1058,7 +1119,9 @@ int main(void)
10581119
{test_notecard_responseError_does_not_modify_note_c_result_value_before_returning_to_caller, "test_notecard_responseError_does_not_modify_note_c_result_value_before_returning_to_caller"},
10591120
{test_notecard_begin_i2c_default_parameter_for_wirePort_has_begin_method_called, "test_notecard_begin_i2c_default_parameter_for_wirePort_has_begin_method_called"},
10601121
{test_notecard_begin_i2c_parameter_for_wirePort_has_begin_method_called, "test_notecard_begin_i2c_parameter_for_wirePort_has_begin_method_called"},
1061-
{test_notecard_begin_serial_default_parameter_for_baud_rate_is_passed_to_note_c, "test_notecard_begin_serial_default_parameter_for_baud_rate_is_passed_to_note_c"}
1122+
{test_notecard_begin_serial_default_parameter_for_baud_rate_is_passed_to_note_c, "test_notecard_begin_serial_default_parameter_for_baud_rate_is_passed_to_note_c"},
1123+
{test_notecard_newCommand_does_not_modify_string_parameter_value_before_passing_to_note_c, "test_notecard_newRequest_does_not_modify_string_parameter_value_before_passing_to_note_c"},
1124+
{test_notecard_newCommand_does_not_modify_note_c_result_value_before_returning_to_caller, "test_notecard_newRequest_does_not_modify_note_c_result_value_before_returning_to_caller"},
10621125
};
10631126

10641127
return TestFunction::runTests(tests, (sizeof(tests) / sizeof(TestFunction)));

test/mock/mock-note.c

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
NoteDebug_Parameters noteDebug_Parameters;
44
NoteDebugSyncStatus_Parameters noteDebugSyncStatus_Parameters;
55
NoteDeleteResponse_Parameters noteDeleteResponse_Parameters;
6+
NoteNewCommand_Parameters noteNewCommand_Parameters;
67
NoteNewRequest_Parameters noteNewRequest_Parameters;
78
NoteRequest_Parameters noteRequest_Parameters;
89
NoteRequestResponse_Parameters noteRequestResponse_Parameters;
@@ -59,6 +60,16 @@ NoteDebugSyncStatus(
5960
return noteDebugSyncStatus_Parameters.result;
6061
}
6162

63+
J *
64+
NoteNewCommand(
65+
const char *request
66+
) {
67+
// Stash parameter(s)
68+
noteNewCommand_Parameters.request = request;
69+
70+
return noteNewCommand_Parameters.result;
71+
}
72+
6273
J *
6374
NoteNewRequest(
6475
const char *request

test/mock/mock-parameters.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ struct NoteDeleteResponse_Parameters {
4949
J *response;
5050
};
5151

52+
struct NoteNewCommand_Parameters {
53+
NoteNewCommand_Parameters(
54+
void
55+
) :
56+
request(nullptr),
57+
result(nullptr)
58+
{ }
59+
const char *request;
60+
J *result;
61+
};
62+
5263
struct NoteNewRequest_Parameters {
5364
NoteNewRequest_Parameters(
5465
void
@@ -151,6 +162,7 @@ struct NoteSetFnSerial_Parameters {
151162
extern NoteDebug_Parameters noteDebug_Parameters;
152163
extern NoteDebugSyncStatus_Parameters noteDebugSyncStatus_Parameters;
153164
extern NoteDeleteResponse_Parameters noteDeleteResponse_Parameters;
165+
extern NoteNewCommand_Parameters noteNewCommand_Parameters;
154166
extern NoteNewRequest_Parameters noteNewRequest_Parameters;
155167
extern NoteRequest_Parameters noteRequest_Parameters;
156168
extern NoteRequestResponse_Parameters noteRequestResponse_Parameters;

0 commit comments

Comments
 (0)