Skip to content

Commit 6446d76

Browse files
Bump note-c to latest master. (#102)
Co-authored-by: Zachary J. Fields <[email protected]>
1 parent 1a78d8e commit 6446d76

File tree

98 files changed

+239
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+239
-165
lines changed

examples/Example1_NotecardBasics/Example1_NotecardBasics.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,12 @@ void loop()
165165
if (req != NULL)
166166
{
167167
JAddBoolToObject(req, "sync", true);
168-
J *body = JCreateObject();
168+
J *body = JAddObjectToObject(req, "body");
169169
if (body != NULL)
170170
{
171171
JAddNumberToObject(body, "temp", temperature);
172172
JAddNumberToObject(body, "voltage", voltage);
173173
JAddNumberToObject(body, "count", eventCounter);
174-
JAddItemToObject(req, "body", body);
175174
}
176175
notecard.sendRequest(req);
177176
}

examples/Example2_PeriodicCommunications/Example2_PeriodicCommunications.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,12 @@ void loop()
199199
J *req = notecard.newRequest("note.add");
200200
if (req != NULL)
201201
{
202-
J *body = JCreateObject();
202+
J *body = JAddObjectToObject(req, "body");
203203
if (body != NULL)
204204
{
205205
JAddNumberToObject(body, "temp", temperature);
206206
JAddNumberToObject(body, "voltage", voltage);
207207
JAddNumberToObject(body, "count", eventCounter);
208-
JAddItemToObject(req, "body", body);
209208
}
210209
notecard.sendRequest(req);
211210
}

examples/Example5_UsingTemplates/Example5_UsingTemplates.ino

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,18 @@ void setup()
122122
// look "similar" to the Notes that will later be added with note.add, in
123123
// that the data types are used to intuit what the ultimate field data types
124124
// will be, and their maximum length.
125-
req = notecard.newRequest("note.add");
125+
req = notecard.newRequest("note.template");
126126
if (req != NULL)
127127
{
128128
// Create the body for a template that will be used to send notes below
129-
J *body = JCreateObject();
129+
J *body = JAddObjectToObject(req, "body");
130130
if (body != NULL)
131131
{
132132
// Define the JSON template
133-
JAddStringToObject(body, "status", "AAAAAAAAAAAA"); // maximum string length
134-
JAddNumberToObject(body, "temp", 1.1); // floating point (double)
135-
JAddNumberToObject(body, "voltage", 1.1); // floating point (double)
136-
JAddNumberToObject(body, "count", 1); // integer
137-
138-
// Add the body to the request
139-
JAddItemToObject(req, "body", body);
133+
JAddStringToObject(body, "status", TSTRING(12)); // maximum string length
134+
JAddNumberToObject(body, "temp", TFLOAT64); // floating point (double)
135+
JAddNumberToObject(body, "voltage", TFLOAT64); // floating point (double)
136+
JAddNumberToObject(body, "count", TUINT32); // 32-bit unsigned integer
140137
}
141138

142139
// Create a template of the payload that will be used to send
@@ -145,7 +142,6 @@ void setup()
145142

146143
// Register the template in the output queue notefile
147144
JAddStringToObject(req, "file", "sensors.qo");
148-
JAddBoolToObject(req, "template", true);
149145
notecard.sendRequest(req);
150146
}
151147
}
@@ -199,14 +195,13 @@ void loop()
199195
if (req != NULL)
200196
{
201197
JAddStringToObject(req, "file", "sensors.qo");
202-
J *body = JCreateObject();
198+
J *body = JAddObjectToObject(req, "body");
203199
if (body != NULL)
204200
{
205201
JAddStringToObject(body, "status", temperature > 26.67 ? "hot" : "normal"); // 80F
206202
JAddNumberToObject(body, "temp", temperature);
207203
JAddNumberToObject(body, "voltage", voltage);
208204
JAddNumberToObject(body, "count", eventCounter);
209-
JAddItemToObject(req, "body", body);
210205
}
211206
JAddBinaryToObject(req, "payload", &binaryData, sizeof(binaryData));
212207
notecard.sendRequest(req);

examples/Example7_PowerControl/Example7_PowerControl.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,14 @@ void loop()
166166
if (req != NULL)
167167
{
168168
JAddStringToObject(req, "file", "example.qo");
169-
J *body = JCreateObject();
169+
J *body = JAddObjectToObject(req, "body");
170170
if (body != NULL)
171171
{
172172
JAddNumberToObject(body, "cycles", globalState.cycles);
173173
JAddNumberToObject(body, "temperature", currentTemperature);
174174
JAddNumberToObject(body, "temperature_measurements", tempSensorState.measurements);
175175
JAddNumberToObject(body, "voltage", currentVoltage);
176176
JAddNumberToObject(body, "voltage_measurements", voltSensorState.measurements);
177-
JAddItemToObject(req, "body", body);
178177
}
179178
notecard.sendRequest(req);
180179
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Blues Wireless Notecard
2-
version=1.4.0
2+
version=1.4.1
33
author=Blues Wireless
44
maintainer=Blues Wireless <[email protected]>
55
sentence=An easy to use Notecard Library for Arduino.

src/note-c/CMakeLists.txt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
1414
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
1515
endif()
1616

17-
option(BUILD_TESTS "Build tests." OFF)
18-
option(BUILD_SHARED_LIBS "Build note-c as a shared library." OFF)
19-
option(COVERAGE "Compile for test coverage reporting." OFF)
20-
option(MEM_CHECK "Run tests with Valgrind." OFF)
17+
option(NOTE_C_BUILD_TESTS "Build tests." OFF)
18+
option(BUILD_SHARED_LIBS "Build shared libraries instead of static." OFF)
19+
option(NOTE_C_COVERAGE "Compile for test NOTE_C_COVERAGE reporting." OFF)
20+
option(NOTE_C_MEM_CHECK "Run tests with Valgrind." OFF)
2121

2222
set(NOTE_C_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2323
add_library(
@@ -51,22 +51,26 @@ target_include_directories(
5151
PUBLIC ${NOTE_C_SRC_DIR}
5252
)
5353

54-
if(BUILD_TESTS)
54+
if(NOTE_C_BUILD_TESTS)
5555
# Including CTest here rather than in test/CMakeLists.txt allows us to run
5656
# ctest from the root build directory (e.g. build/ instead of build/test/).
5757
# We also need to set MEMORYCHECK_COMMAND_OPTIONS before including this.
5858
# See: https://stackoverflow.com/a/60741757
59-
if(MEM_CHECK)
59+
if(NOTE_C_MEM_CHECK)
6060
# Go ahead and make sure we can find valgrind while we're here.
6161
find_program(VALGRIND valgrind REQUIRED)
6262
message(STATUS "Found valgrind: ${VALGRIND}")
6363
set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1")
64-
endif(MEM_CHECK)
64+
endif(NOTE_C_MEM_CHECK)
6565
include(CTest)
6666

6767
target_compile_definitions(
6868
note_c
69-
PUBLIC TEST
69+
PUBLIC NOTE_C_TEST
70+
)
71+
target_include_directories(
72+
note_c
73+
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/test/include
7074
)
7175

7276
# If we don't weaken the functions we're mocking in the tests, the linker
@@ -124,4 +128,4 @@ if(BUILD_TESTS)
124128
)
125129

126130
add_subdirectory(test)
127-
endif(BUILD_TESTS)
131+
endif(NOTE_C_BUILD_TESTS)

src/note-c/n_cjson.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@
6767

6868
#include "n_lib.h"
6969

70-
#define STRINGIFY(x) STRINGIFY_(x)
71-
#define STRINGIFY_(x) #x
72-
7370
#ifdef ENABLE_LOCALES
7471
#include <locale.h>
7572
#endif
@@ -112,7 +109,7 @@ N_CJSON_PUBLIC(char *) JGetStringValue(J *item)
112109

113110
N_CJSON_PUBLIC(const char*) JVersion(void)
114111
{
115-
return STRINGIFY(N_CJSON_VERSION_MAJOR) "." STRINGIFY(N_CJSON_VERSION_MINOR) "." STRINGIFY(N_CJSON_VERSION_PATCH);
112+
return NOTE_C_STRINGIZE(N_CJSON_VERSION_MAJOR) "." NOTE_C_STRINGIZE(N_CJSON_VERSION_MINOR) "." NOTE_C_STRINGIZE(N_CJSON_VERSION_PATCH);
116113
}
117114

118115
/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */

src/note-c/n_helpers.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
#include <stdarg.h>
1717
#include "n_lib.h"
1818

19+
#ifdef NOTE_C_TEST
20+
#include "test_static.h"
21+
#else
22+
#define NOTE_C_STATIC static
23+
#endif
24+
1925
// When interfacing with the Notecard, it is generally encouraged that the JSON object manipulation and
2026
// calls to the note-arduino library are done directly at point of need. However, there are cases in which
2127
// it's convenient to have a wrapper. The most common reason is when it's best to have a suppression timer
@@ -68,8 +74,8 @@ static short normalYearDaysByMonth[] = {0, 31, 59, 90, 120, 151, 181, 212, 243,
6874
static const char *daynames[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
6975

7076
// Forwards
71-
STATIC bool timerExpiredSecs(uint32_t *timer, uint32_t periodSecs);
72-
STATIC int ytodays(int year);
77+
NOTE_C_STATIC bool timerExpiredSecs(uint32_t *timer, uint32_t periodSecs);
78+
NOTE_C_STATIC int ytodays(int year);
7379

7480
//**************************************************************************/
7581
/*!
@@ -127,7 +133,7 @@ void NoteTimeRefreshMins(uint32_t mins)
127133
@param seconds The UNIX Epoch time.
128134
*/
129135
/**************************************************************************/
130-
STATIC void setTime(JTIME seconds)
136+
NOTE_C_STATIC void setTime(JTIME seconds)
131137
{
132138
timeBaseSec = seconds;
133139
timeBaseSetAtMs = _GetMs();
@@ -444,7 +450,7 @@ bool NoteLocalTimeST(uint16_t *retYear, uint8_t *retMonth, uint8_t *retDay, uint
444450
}
445451

446452
// Figure out how many days at start of the year
447-
STATIC int ytodays(int year)
453+
NOTE_C_STATIC int ytodays(int year)
448454
{
449455
int days = 0;
450456
if (0 < year) {
@@ -1621,7 +1627,7 @@ bool NoteSetContact(char *nameBuf, char *orgBuf, char *roleBuf, char *emailBuf)
16211627
// A simple suppression timer based on a millisecond system clock. This clock is reset to 0
16221628
// after boot and every wake. This returns true if the specified interval has elapsed, in seconds,
16231629
// and it updates the timer if it expires so that we will go another period.
1624-
STATIC bool timerExpiredSecs(uint32_t *timer, uint32_t periodSecs)
1630+
NOTE_C_STATIC bool timerExpiredSecs(uint32_t *timer, uint32_t periodSecs)
16251631
{
16261632
bool expired = false;
16271633

src/note-c/n_hooks.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,29 @@ void NoteDebug(const char *line)
418418
#endif
419419
}
420420

421+
//**************************************************************************/
422+
/*!
423+
@brief Write the message to the debug stream, if the level is less than
424+
or equal to NOTE_C_LOG_LEVEL_MAX. Otherwise, the message is
425+
dropped.
426+
@param level The log level of the message. See the NOTE_C_LOG_LEVEL_* macros
427+
in note.h for possible values.
428+
@param msg The debug message.
429+
*/
430+
/**************************************************************************/
431+
void NoteDebugWithLevel(uint8_t level, const char *msg)
432+
{
433+
#ifndef NOTE_NODEBUG
434+
435+
if (level > NOTE_C_LOG_LEVEL_MAX) {
436+
return;
437+
}
438+
439+
NoteDebug(msg);
440+
441+
#endif // !NOTE_NODEBUG
442+
}
443+
421444
//**************************************************************************/
422445
/*!
423446
@brief Get the current milliseconds value from the platform-specific

src/note-c/n_ua.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,10 @@ __attribute__((weak)) J *NoteUserAgent()
109109
#define PLUS ""
110110
#endif
111111

112-
#define STRINGIFY(x) STRINGIFY_(x)
113-
#define STRINGIFY_(x) #x
114-
115112
#if defined(__ICCARM__)
116-
char *compiler = (char *) ("iar arm" PLUS " " STRINGIFY(__VER__));
113+
char *compiler = (char *) ("iar arm" PLUS " " NOTE_C_STRINGIZE(__VER__));
117114
#elif defined(__IAR_SYSTEMS_ICC__)
118-
char *compiler = (char *) ("iar" PLUS " " STRINGIFY(__VER__));
115+
char *compiler = (char *) ("iar" PLUS " " NOTE_C_STRINGIZE(__VER__));
119116
#elif defined(__clang__)
120117
char *compiler = (char *) ("clang" PLUS " " __VERSION__);
121118
#elif defined(__ATOLLIC__) && defined(__GNUC__)

src/note-c/note.h

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,6 @@
7373
// originates from the Notecard, which synchronizes the time from both the cell network and GPS.
7474
typedef unsigned long int JTIME;
7575

76-
// If we're building the tests, STATIC is defined to nothing. This allows the
77-
// tests to access the static functions in note-c. Among other things, this
78-
// let's us mock these normally static functions.
79-
#ifdef TEST
80-
#define STATIC
81-
#else
82-
#define STATIC static
83-
#endif
84-
8576
// C-callable functions
8677
#ifdef __cplusplus
8778
extern "C" {
@@ -169,6 +160,47 @@ void NoteDebug(const char *message);
169160
void NoteDebugln(const char *message);
170161
void NoteDebugIntln(const char *message, int n);
171162
void NoteDebugf(const char *format, ...);
163+
164+
#define NOTE_C_LOG_LEVEL_ERROR 0
165+
#define NOTE_C_LOG_LEVEL_WARN 1
166+
#define NOTE_C_LOG_LEVEL_INFO 2
167+
#define NOTE_C_LOG_LEVEL_DEBUG 3
168+
169+
void NoteDebugWithLevel(uint8_t level, const char *msg);
170+
171+
#define _NOTE_C_STRINGIZE(x) #x
172+
#define NOTE_C_STRINGIZE(x) _NOTE_C_STRINGIZE(x)
173+
174+
#define NOTE_C_LOG_ERROR(msg) do { \
175+
NoteDebugWithLevel(NOTE_C_LOG_LEVEL_ERROR, __FILE__ ":" \
176+
NOTE_C_STRINGIZE(__LINE__) " (ERROR) "); \
177+
NoteDebugWithLevel(NOTE_C_LOG_LEVEL_ERROR, msg); \
178+
} while (0);
179+
180+
#define NOTE_C_LOG_WARN(msg) do { \
181+
NoteDebugWithLevel(NOTE_C_LOG_LEVEL_WARN, __FILE__ ":" \
182+
NOTE_C_STRINGIZE(__LINE__) " (WARN) "); \
183+
NoteDebugWithLevel(NOTE_C_LOG_LEVEL_WARN, msg); \
184+
} while (0);
185+
186+
#define NOTE_C_LOG_INFO(msg) do { \
187+
NoteDebugWithLevel(NOTE_C_LOG_LEVEL_INFO, __FILE__ ":" \
188+
NOTE_C_STRINGIZE(__LINE__) " (INFO) "); \
189+
NoteDebugWithLevel(NOTE_C_LOG_LEVEL_INFO, msg); \
190+
} while (0);
191+
192+
#define NOTE_C_LOG_DEBUG(msg) do { \
193+
NoteDebugWithLevel(NOTE_C_LOG_LEVEL_DEBUG, __FILE__ ":" \
194+
NOTE_C_STRINGIZE(__LINE__) " (DEBUG) "); \
195+
NoteDebugWithLevel(NOTE_C_LOG_LEVEL_DEBUG, msg); \
196+
} while (0);
197+
198+
// The max log level for NoteDebugWithLevel is only configurable at
199+
// compile-time, via NOTE_C_LOG_LEVEL_MAX.
200+
#ifndef NOTE_C_LOG_LEVEL_MAX
201+
#define NOTE_C_LOG_LEVEL_MAX NOTE_C_LOG_LEVEL_ERROR
202+
#endif
203+
172204
void *NoteMalloc(size_t size);
173205
void NoteFree(void *);
174206
long unsigned int NoteGetMs(void);
@@ -316,33 +348,24 @@ bool NotePayloadAddSegment(NotePayloadDesc *desc, const char segtype[NP_SEGTYPE_
316348
bool NotePayloadFindSegment(NotePayloadDesc *desc, const char segtype[NP_SEGTYPE_LEN], void *pdata, uint32_t *plen);
317349
bool NotePayloadGetSegment(NotePayloadDesc *desc, const char segtype[NP_SEGTYPE_LEN], void *pdata, uint32_t len);
318350

319-
// C macro to convert a number to a string for use below
320-
#define _tstring(x) #x
321-
322351
// Hard-wired constants used to specify field types when creating note templates
323-
#define TBOOL true // bool
324-
#define TINT8 11 // 1-byte signed integer
325-
#define TINT16 12 // 2-byte signed integer
326-
#define TINT24 13 // 3-byte signed integer
327-
#define TINT32 14 // 4-byte signed integer
328-
#define TINT64 18 // 8-byte signed integer (note-c support depends upon platform)
329-
#define TUINT8 21 // 1-byte unsigned integer (requires notecard firmware >= build 14444)
330-
#define TUINT16 22 // 2-byte unsigned integer (requires notecard firmware >= build 14444)
331-
#define TUINT24 23 // 3-byte unsigned integer (requires notecard firmware >= build 14444)
332-
#define TUINT32 24 // 4-byte unsigned integer (requires notecard firmware >= build 14444)
333-
#define TFLOAT16 12.1 // 2-byte IEEE 754 floating point
334-
#define TFLOAT32 14.1 // 4-byte IEEE 754 floating point (a.k.a. "float")
335-
#define TFLOAT64 18.1 // 8-byte IEEE 754 floating point (a.k.a. "double")
336-
#define TSTRING(N) _tstring(N) // UTF-8 text of N bytes maximum (fixed-length reserved buffer)
337-
#define TSTRINGV _tstring(0) // variable-length string
352+
#define TBOOL true // bool
353+
#define TINT8 11 // 1-byte signed integer
354+
#define TINT16 12 // 2-byte signed integer
355+
#define TINT24 13 // 3-byte signed integer
356+
#define TINT32 14 // 4-byte signed integer
357+
#define TINT64 18 // 8-byte signed integer (note-c support depends upon platform)
358+
#define TUINT8 21 // 1-byte unsigned integer (requires notecard firmware >= build 14444)
359+
#define TUINT16 22 // 2-byte unsigned integer (requires notecard firmware >= build 14444)
360+
#define TUINT24 23 // 3-byte unsigned integer (requires notecard firmware >= build 14444)
361+
#define TUINT32 24 // 4-byte unsigned integer (requires notecard firmware >= build 14444)
362+
#define TFLOAT16 12.1 // 2-byte IEEE 754 floating point
363+
#define TFLOAT32 14.1 // 4-byte IEEE 754 floating point (a.k.a. "float")
364+
#define TFLOAT64 18.1 // 8-byte IEEE 754 floating point (a.k.a. "double")
365+
#define TSTRING(N) _NOTE_C_STRINGIZE(N) // UTF-8 text of N bytes maximum (fixed-length reserved buffer)
366+
#define TSTRINGV _NOTE_C_STRINGIZE(0) // variable-length string
338367
bool NoteTemplate(const char *notefileID, J *templateBody);
339368

340-
// Make these normally static functions externally visible if building tests.
341-
#ifdef TEST
342-
bool timerExpiredSecs(uint32_t *timer, uint32_t periodSecs);
343-
void setTime(JTIME seconds);
344-
#endif
345-
346369
// End of C-callable functions
347370
#ifdef __cplusplus
348371
}

0 commit comments

Comments
 (0)