-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #2358, adds TIME module command to set CFE_TIME_Print() format #2370
Conversation
@@ -98,6 +98,8 @@ | |||
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TIME_INVALID_MID = {.MsgId = CFE_SB_MSGID_RESERVED, .CommandCode = 0}; | |||
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TIME_CMD_INVALID_CC = { | |||
.MsgId = CFE_SB_MSGID_WRAP_VALUE(CFE_TIME_CMD_MID), .CommandCode = 0x7F}; | |||
static const UT_TaskPipeDispatchId_t UT_TPID_CFE_TIME_SET_PRINT_CC = { |
Check notice
Code scanning / CodeQL
Variable scope too large
@@ -240,6 +240,13 @@ | |||
} | |||
break; | |||
|
|||
case CFE_TIME_SET_PRINT_CC: | |||
if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetPrintCmd_t))) |
Check warning
Code scanning / CodeQL
Side effect in a Boolean expression
while(*FmtPtr != '\0' && OutChrs < CFE_TIME_PRINTED_STRING_SIZE) | ||
{ | ||
/* if we have "%f", call strftime for string before and string after */ | ||
PctF = strstr(FmtBuf, "%f"); | ||
if (PctF) | ||
{ | ||
*PctF = '\0'; /* blot out "%f", for now */ | ||
} | ||
|
||
TimeSz = strftime(PrintBuffer + OutChrs, CFE_TIME_PRINTED_STRING_SIZE - OutChrs, FmtPtr, &tm); | ||
|
||
if (*FmtPtr && TimeSz == 0) | ||
{ | ||
/* strftime returns 0 if the buffer is too small */ | ||
return CFE_TIME_FORMAT_TOO_LONG; | ||
} | ||
|
||
OutChrs += TimeSz; | ||
|
||
/* we found/blotted %f above */ | ||
if (PctF) | ||
{ | ||
/* write %f value */ | ||
if (OutChrs < CFE_TIME_PRINTED_STRING_SIZE - 5) | ||
{ | ||
OutChrs += snprintf(PrintBuffer + OutChrs, CFE_TIME_PRINTED_STRING_SIZE - OutChrs, "%05d", mic); | ||
} | ||
else | ||
{ | ||
return CFE_TIME_FORMAT_TOO_LONG; | ||
} | ||
|
||
/* go back through the loop with the remaining format */ | ||
FmtPtr = PctF + 2; | ||
} | ||
else | ||
{ | ||
PrintBuffer[OutChrs] = '\0'; /* just in case, null-terminate the string */ | ||
break; /* break while */ | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Unbounded loop
switch (CFE_TIME_Global.PrintState) | ||
{ | ||
case CFE_TIME_PrintState_DateTime: | ||
gmtime_r(&sec, &tm); | ||
|
||
strncpy(FmtPtr, CFE_TIME_Global.PrintFormat, CFE_TIME_FORMAT_SIZE); | ||
|
||
while(*FmtPtr != '\0' && OutChrs < CFE_TIME_PRINTED_STRING_SIZE) | ||
{ | ||
/* if we have "%f", call strftime for string before and string after */ | ||
PctF = strstr(FmtBuf, "%f"); | ||
if (PctF) | ||
{ | ||
*PctF = '\0'; /* blot out "%f", for now */ | ||
} | ||
|
||
TimeSz = strftime(PrintBuffer + OutChrs, CFE_TIME_PRINTED_STRING_SIZE - OutChrs, FmtPtr, &tm); | ||
|
||
if (*FmtPtr && TimeSz == 0) | ||
{ | ||
/* strftime returns 0 if the buffer is too small */ | ||
return CFE_TIME_FORMAT_TOO_LONG; | ||
} | ||
|
||
OutChrs += TimeSz; | ||
|
||
/* we found/blotted %f above */ | ||
if (PctF) | ||
{ | ||
/* write %f value */ | ||
if (OutChrs < CFE_TIME_PRINTED_STRING_SIZE - 5) | ||
{ | ||
OutChrs += snprintf(PrintBuffer + OutChrs, CFE_TIME_PRINTED_STRING_SIZE - OutChrs, "%05d", mic); | ||
} | ||
else | ||
{ | ||
return CFE_TIME_FORMAT_TOO_LONG; | ||
} | ||
|
||
/* go back through the loop with the remaining format */ | ||
FmtPtr = PctF + 2; | ||
} | ||
else | ||
{ | ||
PrintBuffer[OutChrs] = '\0'; /* just in case, null-terminate the string */ | ||
break; /* break while */ | ||
} | ||
} | ||
break; | ||
case CFE_TIME_PrintState_SecsSinceStart: | ||
OutChrs += snprintf(PrintBuffer, CFE_TIME_PRINTED_STRING_SIZE, "%ld.%06d", (long int)sec, mic); | ||
PrintBuffer[OutChrs] = '\0'; | ||
break; | ||
default: | ||
PrintBuffer[0] = '\0'; | ||
break; | ||
} |
Check notice
Code scanning / CodeQL
Long switch case
5a7b8a8
to
55b71cf
Compare
55b71cf
to
10c81ea
Compare
Two issues raised in the CCB:
|
CCB 09/07/2023: Dan plans to run tests and this pr will be considered to be merged next week |
I was able to perform some initial testing and think we are on track to merge into Equuleus-rc2. I did run into a couple issues that I would like to resolve prior to merging:
|
CCB: 11-9-2023: put on hold |
CCB 30 November 2023: Going to run performance tests to make sure that changes don't result in a performance hit. Afterwards, backwards compatibility issues will be fixed. |
@CDKnightNASA - I set up a test to benchmark this against a GR712 running RTEMS 5. During the test, I called CFE_TIME_Print 10,000 times to see how long it takes with and without the patch. I ran the test three times to get an average. Without patch: With patch: Against the GR712, the time to execute CFE_TIME_Print is 28% slower with the patch - which i do not believe is cause for concern. In this case, the enhanced functionality is most likely worth the performance trade. In practice the performance loss will be negligible as CFE_TIME_Print should never be called at a rate where this loss would be noticeable/impactful. Lets plan to discuss/get concurrence at the next CCB. |
As mentioned in the Teams chat, I think that the performance impact is significant enough to pull this PR. Missions can, instead, just modify the code so that they get the output format they prefer with less/zero impact. But I will await the CCB's decision and will implement suggested changes if the consensus is that the PR is worthwhile even with the performance impact. |
CCB 4 January 2024: Determined that formatting can be applied at compile-time. |
Checklist (Please check before submitting)
Describe the contribution
Adds a CFE TIME command to configure how to print time information, mostly used by CFE_EVS to print to stdout, and CFE ES for writing to syslog.
Testing performed
Build and test using standard cFE coverage tests which have been updated to test different formats and error conditions.
Expected behavior changes
Enhances CFE_TIME_Print() function and allows for more concise and helpful timestamps.
System(s) tested on
Ubuntu 23 desktop VM.
Contributor Info - All information REQUIRED for consideration of pull request
[email protected]