Skip to content

Commit

Permalink
Standardize private function naming. (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenroche5 authored Oct 27, 2023
1 parent 0c34d67 commit 2b31718
Show file tree
Hide file tree
Showing 25 changed files with 488 additions and 488 deletions.
8 changes: 4 additions & 4 deletions n_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static const char *daynames[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
// Forwards
NOTE_C_STATIC void setTime(JTIME seconds);
NOTE_C_STATIC bool timerExpiredSecs(uint32_t *timer, uint32_t periodSecs);
NOTE_C_STATIC int ytodays(int year);
NOTE_C_STATIC int yToDays(int year);

static const char NOTE_C_BINARY_EOP = '\n';

Expand Down Expand Up @@ -823,7 +823,7 @@ bool NotePrint(const char *text)
{
bool success = false;

if (NoteIsDebugOutputActive()) {
if (noteIsDebugOutputActive()) {
NoteDebug(text);
return true;
}
Expand Down Expand Up @@ -1042,7 +1042,7 @@ bool NoteLocalTimeST(uint16_t *retYear, uint8_t *retMonth, uint8_t *retDay,
if (retWeekday != NULL) {
*retWeekday = (char *) daynames[(days + 1) % 7];
}
for (year = days / 365; days < (i = ytodays(year) + 365L * year); ) {
for (year = days / 365; days < (i = yToDays(year) + 365L * year); ) {
--year;
}
days -= i;
Expand Down Expand Up @@ -1091,7 +1091,7 @@ bool NoteLocalTimeST(uint16_t *retYear, uint8_t *retMonth, uint8_t *retDay,
}

// Figure out how many days at start of the year
NOTE_C_STATIC int ytodays(int year)
NOTE_C_STATIC int yToDays(int year)
{
int days = 0;
if (0 < year) {
Expand Down
34 changes: 17 additions & 17 deletions n_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void NoteSetFnDebugOutput(debugOutputFn fn)
provided.
*/
/**************************************************************************/
bool NoteIsDebugOutputActive(void)
bool noteIsDebugOutputActive(void)
{
return hookDebugOutput != NULL;
}
Expand Down Expand Up @@ -607,7 +607,7 @@ void NoteUnlockI2C(void)
@brief Lock the Notecard using the platform-specific hook.
*/
/**************************************************************************/
void NoteLockNote(void)
void noteLockNote(void)
{
if (hookLockNote != NULL) {
hookLockNote();
Expand All @@ -619,7 +619,7 @@ void NoteLockNote(void)
@brief Unlock the Notecard using the platform-specific hook.
*/
/**************************************************************************/
void NoteUnlockNote(void)
void noteUnlockNote(void)
{
if (hookUnlockNote != NULL) {
hookUnlockNote();
Expand All @@ -631,7 +631,7 @@ void NoteUnlockNote(void)
@brief Indicate that we're initiating a transaction using the platform-specific hook.
*/
/**************************************************************************/
bool NoteTransactionStart(uint32_t timeoutMs)
bool noteTransactionStart(uint32_t timeoutMs)
{
if (hookTransactionStart != NULL) {
return hookTransactionStart(timeoutMs);
Expand All @@ -644,7 +644,7 @@ bool NoteTransactionStart(uint32_t timeoutMs)
@brief Indicate that we've completed a transaction using the platform-specific hook.
*/
/**************************************************************************/
void NoteTransactionStop(void)
void noteTransactionStop(void)
{
if (hookTransactionStop != NULL) {
hookTransactionStop();
Expand All @@ -657,7 +657,7 @@ void NoteTransactionStop(void)
@returns A string
*/
/**************************************************************************/
const char *NoteActiveInterface(void)
const char *noteActiveInterface(void)
{
switch (hookActiveInterface) {
case interfaceSerial:
Expand All @@ -674,7 +674,7 @@ const char *NoteActiveInterface(void)
@returns A boolean indicating whether the Serial bus was reset successfully.
*/
/**************************************************************************/
bool NoteSerialReset(void)
bool noteSerialReset(void)
{
if (hookActiveInterface == interfaceSerial && hookSerialReset != NULL) {
return hookSerialReset();
Expand All @@ -690,7 +690,7 @@ bool NoteSerialReset(void)
@param flush `true` to flush the bytes upon transmit.
*/
/**************************************************************************/
void NoteSerialTransmit(uint8_t *text, size_t len, bool flush)
void noteSerialTransmit(uint8_t *text, size_t len, bool flush)
{
if (hookActiveInterface == interfaceSerial && hookSerialTransmit != NULL) {
hookSerialTransmit(text, len, flush);
Expand All @@ -704,7 +704,7 @@ void NoteSerialTransmit(uint8_t *text, size_t len, bool flush)
@returns A boolean indicating whether the Serial bus is available to read.
*/
/**************************************************************************/
bool NoteSerialAvailable(void)
bool noteSerialAvailable(void)
{
if (hookActiveInterface == interfaceSerial && hookSerialAvailable != NULL) {
return hookSerialAvailable();
Expand All @@ -719,7 +719,7 @@ bool NoteSerialAvailable(void)
@returns A character from the Serial bus.
*/
/**************************************************************************/
char NoteSerialReceive(void)
char noteSerialReceive(void)
{
if (hookActiveInterface == interfaceSerial && hookSerialReceive != NULL) {
return hookSerialReceive();
Expand All @@ -733,7 +733,7 @@ char NoteSerialReceive(void)
@returns A boolean indicating whether the I2C bus was reset successfully.
*/
/**************************************************************************/
bool NoteI2CReset(uint16_t DevAddress)
bool noteI2CReset(uint16_t DevAddress)
{
if (hookActiveInterface == interfaceI2C && hookI2CReset != NULL) {
return hookI2CReset(DevAddress);
Expand All @@ -751,7 +751,7 @@ bool NoteI2CReset(uint16_t DevAddress)
if the bus is not active.
*/
/**************************************************************************/
const char *NoteI2CTransmit(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size)
const char *noteI2CTransmit(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size)
{
if (hookActiveInterface == interfaceI2C && hookI2CTransmit != NULL) {
return hookI2CTransmit(DevAddress, pBuffer, Size);
Expand All @@ -770,7 +770,7 @@ const char *NoteI2CTransmit(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size
if the bus is not active.
*/
/**************************************************************************/
const char *NoteI2CReceive(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size, uint32_t *available)
const char *noteI2CReceive(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size, uint32_t *available)
{
if (hookActiveInterface == interfaceI2C && hookI2CReceive != NULL) {
return hookI2CReceive(DevAddress, pBuffer, Size, available);
Expand Down Expand Up @@ -832,7 +832,7 @@ uint32_t NoteI2CMax(void)
@returns A boolean indicating whether the Notecard has been reset successfully.
*/
/**************************************************************************/
bool NoteHardReset(void)
bool noteHardReset(void)
{
if (notecardReset == NULL) {
return true;
Expand All @@ -859,7 +859,7 @@ bool NoteHardReset(void)
or the hook has not been set.
*/
/**************************************************************************/
const char *NoteJSONTransaction(const char *request, size_t reqLen, char **response, size_t timeoutMs)
const char *noteJSONTransaction(const char *request, size_t reqLen, char **response, size_t timeoutMs)
{
if (notecardTransaction == NULL || hookActiveInterface == interfaceNone) {
return "i2c or serial interface must be selected";
Expand All @@ -885,7 +885,7 @@ const char *NoteJSONTransaction(const char *request, size_t reqLen, char **respo
@returns A c-string with an error, or `NULL` if no error ocurred.
*/
/**************************************************************************/
const char *NoteChunkedReceive(uint8_t *buffer, uint32_t *size, bool delay,
const char *noteChunkedReceive(uint8_t *buffer, uint32_t *size, bool delay,
size_t timeoutMs, uint32_t *available)
{
if (notecardChunkedReceive == NULL || hookActiveInterface == interfaceNone) {
Expand All @@ -904,7 +904,7 @@ const char *NoteChunkedReceive(uint8_t *buffer, uint32_t *size, bool delay,
@returns A c-string with an error, or `NULL` if no error ocurred.
*/
/**************************************************************************/
const char *NoteChunkedTransmit(uint8_t *buffer, uint32_t size, bool delay)
const char *noteChunkedTransmit(uint8_t *buffer, uint32_t size, bool delay)
{
if (notecardChunkedTransmit == NULL || hookActiveInterface == interfaceNone) {
return "i2c or serial interface must be selected";
Expand Down
64 changes: 32 additions & 32 deletions n_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ const char *serialChunkedReceive(uint8_t *buffer, uint32_t *size, bool delay, si
const char *serialChunkedTransmit(uint8_t *buffer, uint32_t size, bool delay);

// Hooks
void NoteLockNote(void);
void NoteUnlockNote(void);
bool NoteTransactionStart(uint32_t timeoutMs);
void NoteTransactionStop(void);
const char *NoteActiveInterface(void);
bool NoteSerialReset(void);
void NoteSerialTransmit(uint8_t *, size_t, bool);
bool NoteSerialAvailable(void);
char NoteSerialReceive(void);
bool NoteI2CReset(uint16_t DevAddress);
const char *NoteI2CTransmit(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size);
const char *NoteI2CReceive(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size, uint32_t *avail);
bool NoteHardReset(void);
const char *NoteJSONTransaction(const char *request, size_t reqLen, char **response, size_t timeoutMs);
const char *NoteChunkedReceive(uint8_t *buffer, uint32_t *size, bool delay, size_t timeoutMs, uint32_t *available);
const char *NoteChunkedTransmit(uint8_t *buffer, uint32_t size, bool delay);
bool NoteIsDebugOutputActive(void);
void noteLockNote(void);
void noteUnlockNote(void);
bool noteTransactionStart(uint32_t timeoutMs);
void noteTransactionStop(void);
const char *noteActiveInterface(void);
bool noteSerialReset(void);
void noteSerialTransmit(uint8_t *, size_t, bool);
bool noteSerialAvailable(void);
char noteSerialReceive(void);
bool noteI2CReset(uint16_t DevAddress);
const char *noteI2CTransmit(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size);
const char *noteI2CReceive(uint16_t DevAddress, uint8_t* pBuffer, uint16_t Size, uint32_t *avail);
bool noteHardReset(void);
const char *noteJSONTransaction(const char *request, size_t reqLen, char **response, size_t timeoutMs);
const char *noteChunkedReceive(uint8_t *buffer, uint32_t *size, bool delay, size_t timeoutMs, uint32_t *available);
const char *noteChunkedTransmit(uint8_t *buffer, uint32_t size, bool delay);
bool noteIsDebugOutputActive(void);

// Utilities
void n_htoa32(uint32_t n, char *p);
Expand Down Expand Up @@ -190,21 +190,21 @@ extern const char *c_badbinerr;

// Readability wrappers. Anything starting with _ is simply calling the wrapper
// function.
#define _LockNote NoteLockNote
#define _UnlockNote NoteUnlockNote
#define _TransactionStart NoteTransactionStart
#define _TransactionStop NoteTransactionStop
#define _SerialReset NoteSerialReset
#define _SerialTransmit NoteSerialTransmit
#define _SerialAvailable NoteSerialAvailable
#define _SerialReceive NoteSerialReceive
#define _I2CReset NoteI2CReset
#define _I2CTransmit NoteI2CTransmit
#define _I2CReceive NoteI2CReceive
#define _Reset NoteHardReset
#define _Transaction NoteJSONTransaction
#define _ChunkedReceive NoteChunkedReceive
#define _ChunkedTransmit NoteChunkedTransmit
#define _LockNote noteLockNote
#define _UnlockNote noteUnlockNote
#define _TransactionStart noteTransactionStart
#define _TransactionStop noteTransactionStop
#define _SerialReset noteSerialReset
#define _SerialTransmit noteSerialTransmit
#define _SerialAvailable noteSerialAvailable
#define _SerialReceive noteSerialReceive
#define _I2CReset noteI2CReset
#define _I2CTransmit noteI2CTransmit
#define _I2CReceive noteI2CReceive
#define _Reset noteHardReset
#define _Transaction noteJSONTransaction
#define _ChunkedReceive noteChunkedReceive
#define _ChunkedTransmit noteChunkedTransmit
#define _Malloc NoteMalloc
#define _Free NoteFree
#define _GetMs NoteGetMs
Expand Down
2 changes: 1 addition & 1 deletion n_ua.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ __attribute__((weak)) J *NoteUserAgent()

JAddStringToObject(ua, "agent", n_agent);
JAddStringToObject(ua, "compiler", compiler);
JAddStringToObject(ua, "req_interface", NoteActiveInterface());
JAddStringToObject(ua, "req_interface", noteActiveInterface());

// Add CPU Details
if (n_cpu_cores != 0) {
Expand Down
34 changes: 17 additions & 17 deletions test/src/NoteBinaryStoreReceive_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ FAKE_VALUE_FUNC(uint32_t, NoteBinaryCodecDecode, const uint8_t *, uint32_t, uint
uint32_t)
FAKE_VALUE_FUNC(const char *, NoteBinaryStoreEncodedLength, uint32_t *)
FAKE_VALUE_FUNC(J *, noteTransactionShouldLock, J *, bool)
FAKE_VALUE_FUNC(const char *, NoteChunkedReceive, uint8_t *, uint32_t *, bool,
FAKE_VALUE_FUNC(const char *, noteChunkedReceive, uint8_t *, uint32_t *, bool,
size_t, uint32_t *)
FAKE_VOID_FUNC(NoteLockNote)
FAKE_VOID_FUNC(NoteUnlockNote)
FAKE_VOID_FUNC(noteLockNote)
FAKE_VOID_FUNC(noteUnlockNote)

// Most of these variables have to be global because they're accessed in
// lambda functions used as fakes for various note-c functions. They can't be
Expand Down Expand Up @@ -127,22 +127,22 @@ SCENARIO("NoteBinaryStoreReceive")
}
}

GIVEN("NoteChunkedReceive returns an error") {
NoteChunkedReceive_fake.return_val = "some error";
GIVEN("noteChunkedReceive returns an error") {
noteChunkedReceive_fake.return_val = "some error";

WHEN("NoteBinaryStoreReceive is called") {
const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen);

REQUIRE(NoteChunkedReceive_fake.call_count > 0);
REQUIRE(noteChunkedReceive_fake.call_count > 0);
THEN("An error is returned") {
CHECK(err != NULL);
}
}
}

GIVEN("NoteChunkedReceive indicates there's unexpectedly more data "
GIVEN("noteChunkedReceive indicates there's unexpectedly more data "
"available") {
NoteChunkedReceive_fake.custom_fake = [](uint8_t *, uint32_t *, bool,
noteChunkedReceive_fake.custom_fake = [](uint8_t *, uint32_t *, bool,
size_t, uint32_t *available) -> const char* {
*available = 1;

Expand All @@ -152,7 +152,7 @@ SCENARIO("NoteBinaryStoreReceive")
WHEN("NoteBinaryStoreReceive is called") {
const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen);

REQUIRE(NoteChunkedReceive_fake.call_count > 0);
REQUIRE(noteChunkedReceive_fake.call_count > 0);
THEN("An error is returned") {
CHECK(err != NULL);
}
Expand All @@ -163,7 +163,7 @@ SCENARIO("NoteBinaryStoreReceive")
NoteBinaryCodecDecode_fake.custom_fake = [](const uint8_t *encData, uint32_t encDataLen, uint8_t *decBuf, uint32_t) -> uint32_t {
return cobsDecode((uint8_t *)encData, encDataLen, '\n', decBuf);
};
NoteChunkedReceive_fake.custom_fake = [](uint8_t *buffer, uint32_t *size,
noteChunkedReceive_fake.custom_fake = [](uint8_t *buffer, uint32_t *size,
bool, size_t, uint32_t *available) -> const char* {
uint32_t outLen = NoteBinaryCodecEncode((uint8_t *)rawMsg, rawMsgLen, buffer, *size);

Expand All @@ -186,7 +186,7 @@ SCENARIO("NoteBinaryStoreReceive")
WHEN("NoteBinaryStoreReceive is called") {
const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen);

REQUIRE(NoteChunkedReceive_fake.call_count > 0);
REQUIRE(noteChunkedReceive_fake.call_count > 0);
REQUIRE(noteTransactionShouldLock_fake.call_count > 0);
THEN("An error is returned") {
CHECK(err != NULL);
Expand All @@ -203,7 +203,7 @@ SCENARIO("NoteBinaryStoreReceive")
WHEN("NoteBinaryStoreReceive is called") {
const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen);

REQUIRE(NoteChunkedReceive_fake.call_count > 0);
REQUIRE(noteChunkedReceive_fake.call_count > 0);
REQUIRE(noteTransactionShouldLock_fake.call_count > 0);
THEN("An error is returned") {
CHECK(err != NULL);
Expand All @@ -216,7 +216,7 @@ SCENARIO("NoteBinaryStoreReceive")
uint32_t decodedLen = rawMsgLen;
const char *err = NoteBinaryStoreReceive(buf, bufLen, decodedOffset, decodedLen);

REQUIRE(NoteChunkedReceive_fake.call_count > 0);
REQUIRE(noteChunkedReceive_fake.call_count > 0);
THEN("No error is returned") {
CHECK(err == NULL);
}
Expand All @@ -229,15 +229,15 @@ SCENARIO("NoteBinaryStoreReceive")
}
}

CHECK(NoteLockNote_fake.call_count == NoteUnlockNote_fake.call_count);
CHECK(noteLockNote_fake.call_count == noteUnlockNote_fake.call_count);

RESET_FAKE(noteTransactionShouldLock);
RESET_FAKE(NoteBinaryCodecDecode);
RESET_FAKE(NoteBinaryStoreEncodedLength);
RESET_FAKE(NoteChunkedReceive);
RESET_FAKE(NoteLockNote);
RESET_FAKE(noteChunkedReceive);
RESET_FAKE(noteLockNote);
RESET_FAKE(NoteNewRequest);
RESET_FAKE(NoteUnlockNote);
RESET_FAKE(noteUnlockNote);
}

}
Expand Down
Loading

0 comments on commit 2b31718

Please sign in to comment.