Skip to content

Commit

Permalink
Make more fixes to number handling and NOTE_C_LOW_MEM code.
Browse files Browse the repository at this point in the history
- Remove #ifdef ERRDBG guard in i2cNoteReset. This was causing us to not call
_I2CReset when we should have been.
- Make JTIME a typedef for JUINTEGER.
- Fix run_unit_tests.sh script so that it actually runs the tests with
NOTE_C_LOW_MEM defined.
- Use JAddIntToObject to add Unix timestamps to J objects in unit tests. This is
necessary to avoid loss of precision when using JAddNumberToObject.
  • Loading branch information
haydenroche5 committed Jan 24, 2024
1 parent 2e89700 commit 93e5eca
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if(NOTE_C_LOW_MEM)
NOTE_C_LOW_MEM
)
else()
# This file is empty if NOTE_LOWMEM is defined, which leads to a warning
# This file is empty if NOTE_C_LOW_MEM is defined, which leads to a warning
# about an empty translation unit, so we only add it to the build if
# NOTE_C_LOW_MEM is false.
target_sources(
Expand Down
2 changes: 0 additions & 2 deletions n_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ bool i2cNoteReset(void)
// then the Notecard has been successfully reset.
if (!somethingFound || nonControlCharFound) {
notecardReady = false;
#ifdef ERRDBG
if (somethingFound) {
NOTE_C_LOG_WARN(ERRSTR("unrecognized data from notecard", c_iobad));
} else {
Expand All @@ -315,7 +314,6 @@ bool i2cNoteReset(void)
}
delayIO();
}
#endif
} else {
notecardReady = true;
break;
Expand Down
6 changes: 5 additions & 1 deletion note.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
#define NOTE_LOWMEM
#define NOTE_FLOAT
#endif
// If a user defined NOTE_LOWMEM, define NOTE_C_LOW_MEM.
#if defined(NOTE_LOWMEM) && !defined(NOTE_C_LOW_MEM)
#define NOTE_C_LOW_MEM
#endif

#ifdef NOTE_C_LOW_MEM
#define ERRSTR(x,y) (y)
Expand All @@ -66,7 +70,7 @@ typedef uint64_t JUINTEGER;
// UNIX Epoch time (also known as POSIX time) is the number of seconds that have elapsed since
// 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC). In this project, it always
// originates from the Notecard, which synchronizes the time from both the cell network and GPS.
typedef unsigned long int JTIME;
typedef JUINTEGER JTIME;

// C-callable functions
#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if [[ $MEM_CHECK -eq 1 ]]; then
# host machine is running Fedora. See https://stackoverflow.com/a/75293014.
ulimit -n 1024
fi
if [[ $NOTE_C_LOW_MEM -eq 1 ]]; then
if [[ $LOW_MEM -eq 1 ]]; then
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DNOTE_C_LOW_MEM=1"
fi

Expand Down
4 changes: 2 additions & 2 deletions test/src/NoteGetLocation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ SCENARIO("NoteGetLocation")
"{gps-active} {gps-signal} {gps-sats} {gps}";
const float respLat = 42.577600;
const float respLon = -70.871340;
const uint32_t respTime = 1598554399;
const JTIME respTime = 1598554399;

J* resp = JCreateObject();
REQUIRE(resp != NULL);
JAddStringToObject(resp, "status", respStatus);
JAddNumberToObject(resp, "lat", respLat);
JAddNumberToObject(resp, "lon", respLon);
JAddNumberToObject(resp, "time", respTime);
JAddIntToObject(resp, "time", respTime);
NoteRequestResponse_fake.return_val = resp;

CHECK(NoteGetLocation(&lat, &lon, &time, statusBuf, sizeof(statusBuf)));
Expand Down
2 changes: 1 addition & 1 deletion test/src/NoteGetStatus_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SCENARIO("NoteGetStatus")
J* resp = JCreateObject();
REQUIRE(resp != NULL);
JAddStringToObject(resp, "status", respStatus);
JAddNumberToObject(resp, "time", respBootTime);
JAddIntToObject(resp, "time", respBootTime);
JAddBoolToObject(resp, "usb", respUsb);
JAddBoolToObject(resp, "connected", respConnected);
JAddNumberToObject(resp, "signals", respSignals);
Expand Down

0 comments on commit 93e5eca

Please sign in to comment.