Skip to content

Commit

Permalink
Merge pull request #40 from UCSD-E4E/39-create-session-fails
Browse files Browse the repository at this point in the history
fix: Fixes Recorder::putBytes return behavior
  • Loading branch information
ntlhui authored Feb 10, 2024
2 parents 208ab6f + c81aca8 commit 99058cd
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CONTRIBUTING
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ Includes should be organized in the following order:
4. Platform headers

Where C system headers are used, prefer the C style header over the C++ style header (e.g. string.h over cstring)

## Return Values
Prefer returning error codes.

Error codes may be defined by documentation or by enumeration.
2 changes: 1 addition & 1 deletion src/cellular/dataCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void SS_ensemble10Func()

ensData.header.ensembleType = ENS_TEMP_IMU;
int x = pSystemDesc->pRecorder->putBytes(&ensData, sizeof(EnsembleHeader_t) + sizeof(Ensemble10_data_t));
SF_OSAL_printf("Sucsess %d", x);
SF_OSAL_printf("Error code %d", x);

memset(pData, 0, sizeof(Ensemble10_eventData_t));
SF_OSAL_printf("Finished setting up data");
Expand Down
5 changes: 3 additions & 2 deletions src/cellular/recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ int Recorder::putBytes(const void* pData, size_t nBytes)
{
if (nullptr == this->pSession)
{
return 0;
FLOG_AddError(FLOG_REC_SESSION_CLOSED, 0);
return 1;
}
if (nBytes > (REC_MAX_PACKET_SIZE - this->dataIdx))
{
Expand All @@ -491,7 +492,7 @@ int Recorder::putBytes(const void* pData, size_t nBytes)
// SF_OSAL_printf("Putting %u bytes\n", nBytes);
memcpy(&this->dataBuffer[this->dataIdx], pData, nBytes);
this->dataIdx += nBytes;
return 1;
return 0;
}

int Recorder::pop_metadata_entry(void)
Expand Down
2 changes: 1 addition & 1 deletion src/cellular/recorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Recorder
* @param pData data to put
* @param nBytes number of bytes to put
*
* @return 1 on sucsess, otherwise 0
* @return 0 on sucsess, otherwise error code
*/
int putBytes(const void* pData, size_t nBytes);

Expand Down
2 changes: 2 additions & 0 deletions src/cli/flog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ const FLOG_Message_t FLOG_Message[] = {
{FLOG_FS_FTRUNC_FAIL, "file ftrunc fail"},
{FLOG_FS_READ_FAIL, "file ftrunc fail"},
{FLOG_REC_SETUP_FAIL, "Recorder setup failed"},
{FLOG_REC_SESSION_CLOSED, "Write to Closed Session"},

{FLOG_SW_NULLPTR, "Software Null Pointer"},
{FLOG_DEBUG, "debug point"},
{FLOG_NULL, NULL}
};
Expand Down
2 changes: 2 additions & 0 deletions src/cli/flog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ typedef enum FLOG_CODE_
FLOG_FS_READ_FAIL =0x0809,
FLOG_REC_SETUP_FAIL =0x0810,
FLOG_REC_METADATA_BAD =0x0811,
FLOG_REC_SESSION_CLOSED =0x0812,

FLOG_SW_NULLPTR =0xF001,
FLOG_DEBUG =0xFFFF,
}FLOG_CODE_e;

Expand Down
18 changes: 13 additions & 5 deletions src/debug/recorder_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ void REC_testPutBytes(void)
byte_idx++;
}

if (1 != pRecorder->putBytes(user_input, byte_idx))
switch (pRecorder->putBytes(user_input, byte_idx))
{
SF_OSAL_printf("putBytes failed!" __NL__);
case 0:
break;
case 1:
SF_OSAL_printf("Session not opened!" __NL__);
break;
}
}

Expand All @@ -143,12 +147,16 @@ void REC_testCreateBigSession(void)
getline((char*) user_input, REC_MEMORY_BUFFER_SIZE);

input_length = atoi(user_input);
for (hex_idx = 0; hex_idx < input_length; hex_idx ++)
for (hex_idx = 0; hex_idx < input_length; hex_idx++)
{
rand_byte = random(256);
if (1 != pRecorder->putBytes(&rand_byte, 1))
switch (pRecorder->putBytes(&rand_byte, 1))
{
SF_OSAL_printf("putBytes failed!" __NL__);
case 0:
break;
case 1:
SF_OSAL_printf("Session not opened!" __NL__);
break;
}
}

Expand Down

0 comments on commit 99058cd

Please sign in to comment.