Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ECSS Services
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AcubeSat-OBC
ECSS Services
Commits
d6612d8b
Commit
d6612d8b
authored
6 years ago
by
kongr45gpen
Browse files
Options
Downloads
Patches
Plain Diff
Add assertions for expected message types
parent
38fbf745
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inc/ErrorHandler.hpp
+5
-4
5 additions, 4 deletions
inc/ErrorHandler.hpp
inc/Message.hpp
+33
-2
33 additions, 2 deletions
inc/Message.hpp
with
38 additions
and
6 deletions
inc/ErrorHandler.hpp
+
5
−
4
View file @
d6612d8b
...
@@ -52,7 +52,6 @@ public:
...
@@ -52,7 +52,6 @@ public:
* An error in the header of a packet makes it unable to be parsed
* An error in the header of a packet makes it unable to be parsed
*/
*/
UnacceptablePacket
=
5
,
UnacceptablePacket
=
5
,
/**
/**
* A date that isn't valid according to the Gregorian calendar or cannot be parsed by the
* A date that isn't valid according to the Gregorian calendar or cannot be parsed by the
* TimeHelper
* TimeHelper
...
@@ -62,6 +61,10 @@ public:
...
@@ -62,6 +61,10 @@ public:
* Asked a Message type that doesn't exist
* Asked a Message type that doesn't exist
*/
*/
UnknownMessageType
=
7
,
UnknownMessageType
=
7
,
/**
* A function received a Message that was not of the correct type
*/
OtherMessageType
=
8
,
};
};
/**
/**
...
@@ -222,9 +225,7 @@ public:
...
@@ -222,9 +225,7 @@ public:
*/
*/
template
<
typename
ErrorType
>
template
<
typename
ErrorType
>
inline
static
ErrorSource
findErrorSource
(
ErrorType
error
)
{
inline
static
ErrorSource
findErrorSource
(
ErrorType
error
)
{
// While this may seem like a "hacky" way to convert enums to ErrorSource, it should be
// Static type checking
// optimised by the compiler to constant time.
if
(
std
::
is_same
<
ErrorType
,
AcceptanceErrorType
>
())
{
if
(
std
::
is_same
<
ErrorType
,
AcceptanceErrorType
>
())
{
return
Acceptance
;
return
Acceptance
;
}
}
...
...
This diff is collapsed.
Click to expand it.
inc/Message.hpp
+
33
−
2
View file @
d6612d8b
...
@@ -7,7 +7,6 @@ class Message;
...
@@ -7,7 +7,6 @@ class Message;
#include
"ECSS_Definitions.hpp"
#include
"ECSS_Definitions.hpp"
#include
<cstdint>
#include
<cstdint>
#include
<cassert>
#include
<etl/String.hpp>
#include
<etl/String.hpp>
#include
<etl/wstring.h>
#include
<etl/wstring.h>
#include
"ErrorHandler.hpp"
#include
"ErrorHandler.hpp"
...
@@ -430,6 +429,39 @@ public:
...
@@ -430,6 +429,39 @@ public:
* Reset the message reading status, and start reading data from it again
* Reset the message reading status, and start reading data from it again
*/
*/
void
resetRead
();
void
resetRead
();
/**
* Compare the message type to an expected one. An unexpected message type will throw an
* OtherMessageType error.
*
* @return True if the message is of correct type, false if not
*/
bool
assertType
(
Message
::
PacketType
expectedPacketType
,
uint8_t
expectedServiceType
,
uint8_t
expectedMessageType
)
{
if
(
packetType
!=
expectedPacketType
||
serviceType
!=
expectedServiceType
||
messageType
!=
expectedMessageType
)
{
ErrorHandler
::
reportInternalError
(
ErrorHandler
::
OtherMessageType
);
return
false
;
}
return
true
;
}
/**
* Alias for Message::assertType(Message::TC, \p expectedServiceType, \p
* expectedMessageType)
*/
bool
assertTC
(
uint8_t
expectedServiceType
,
uint8_t
expectedMessageType
)
{
return
assertType
(
TC
,
expectedServiceType
,
expectedMessageType
);
}
/**
* Alias for Message::assertType(Message::TM, \p expectedServiceType, \p
* expectedMessageType)
*/
bool
assertTM
(
uint8_t
expectedServiceType
,
uint8_t
expectedMessageType
)
{
return
assertType
(
TM
,
expectedServiceType
,
expectedMessageType
);
}
};
};
template
<
const
size_t
SIZE
>
template
<
const
size_t
SIZE
>
...
@@ -443,5 +475,4 @@ inline void Message::appendString(const String<SIZE> & string) {
...
@@ -443,5 +475,4 @@ inline void Message::appendString(const String<SIZE> & string) {
dataSize
+=
string
.
size
();
dataSize
+=
string
.
size
();
}
}
#endif //ECSS_SERVICES_PACKET_H
#endif //ECSS_SERVICES_PACKET_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment