F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
fputs_assert_hook.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title fputs_assert_hook.cpp
3 // \author Andrei Tumbar
4 // \brief cpp file for assert hook functions using fputs implementation
5 // ======================================================================
7 #include <Fw/Types/format.hpp>
8 #include <cassert>
9 #include <cstdio>
10 
11 #if FW_ASSERT_LEVEL == FW_FILEID_ASSERT
12 #define fileIdFs "Assert: 0x%08" PRIx32 ":%" PRI_FwSizeType ""
13 #else
14 #define fileIdFs "Assert: \"%s:%" PRI_FwSizeType "\""
15 #endif
16 
18  assert(false);
19 }
20 
21 void Fw::printAssertMessage(const CHAR* msg) {
22  // Write to stderr w/o formatting
23  (void)fputs(msg, stderr);
24  (void)fputs("\n", stderr);
25 }
26 
28  FwSizeType lineNo,
29  FwSizeType numArgs,
30  FwAssertArgType arg1,
31  FwAssertArgType arg2,
32  FwAssertArgType arg3,
33  FwAssertArgType arg4,
34  FwAssertArgType arg5,
35  FwAssertArgType arg6,
36  CHAR* destBuffer,
37  FwSizeType buffSize) {
38  // Format status is discarded: a truncated assert message is still useful and there is no better recourse here
39  switch (numArgs) {
40  case 0:
41  (void)stringFormat(destBuffer, buffSize, fileIdFs, file, lineNo);
42  break;
43  case 1:
44  (void)stringFormat(destBuffer, buffSize, fileIdFs " %" PRI_FwAssertArgType, file, lineNo, arg1);
45  break;
46  case 2:
47  (void)stringFormat(destBuffer, buffSize, fileIdFs " %" PRI_FwAssertArgType " %" PRI_FwAssertArgType, file,
48  lineNo, arg1, arg2);
49  break;
50  case 3:
51  (void)stringFormat(destBuffer, buffSize,
53  file, lineNo, arg1, arg2, arg3);
54  break;
55  case 4:
56  (void)stringFormat(destBuffer, buffSize,
59  file, lineNo, arg1, arg2, arg3, arg4);
60  break;
61  case 5:
62  (void)stringFormat(destBuffer, buffSize,
65  file, lineNo, arg1, arg2, arg3, arg4, arg5);
66  break;
67  case 6:
68  (void)stringFormat(destBuffer, buffSize,
71  file, lineNo, arg1, arg2, arg3, arg4, arg5, arg6);
72  break;
73  default: // in an assert already, what can we do?
74  if (buffSize > 0) {
75  destBuffer[0] = '\0';
76  }
77  break;
78  }
79 }
void formatAssertMessage(FILE_NAME_ARG file, FwSizeType lineNo, FwSizeType numArgs, FwAssertArgType arg1, FwAssertArgType arg2, FwAssertArgType arg3, FwAssertArgType arg4, FwAssertArgType arg5, FwAssertArgType arg6, CHAR *destBuffer, FwSizeType buffSize)
format an assert message
PlatformSizeType FwSizeType
#define fileIdFs
char CHAR
Definition: BasicTypes.h:60
#define PRI_FwAssertArgType
#define FILE_NAME_ARG
Definition: Assert.hpp:16
void printAssertMessage(const CHAR *msg)
print an assert message
FormatStatus stringFormat(char *destination, const FwSizeType maximumSize, const char *formatString,...)
format a c-string
void terminateOnAssert()
terminate after a failed assertion
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.