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
22749839
Unverified
Commit
22749839
authored
5 years ago
by
Grigoris Pavlakis
Browse files
Options
Downloads
Patches
Plain Diff
Add safeguard for overwriting a parameter using an already-existing ID
parent
7f7c18bc
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inc/Services/ParameterService.hpp
+10
-8
10 additions, 8 deletions
inc/Services/ParameterService.hpp
src/Services/ParameterService.cpp
+14
-8
14 additions, 8 deletions
src/Services/ParameterService.cpp
test/Services/ParameterService.cpp
+7
-3
7 additions, 3 deletions
test/Services/ParameterService.cpp
with
31 additions
and
19 deletions
inc/Services/ParameterService.hpp
+
10
−
8
View file @
22749839
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
// Number of stored parameters. MAX_PARAMS is just a dummy number for now.
// Number of stored parameters. MAX_PARAMS is just a dummy number for now.
#define MAX_PARAMS 5
#define MAX_PARAMS 5
// TODO: 1) Rework the parameter setting and report functions
// TODO: 2) Implement flags and use them above
// TODO: 2) Implement flags and use them above
// TODO: 3) Write more and better tests
// TODO: 3) Write more and better tests
// TODO: 4) Make sure that docs are up to date
// TODO: 4) Make sure that docs are up to date
...
@@ -28,7 +27,7 @@
...
@@ -28,7 +27,7 @@
* for parameter reporting and modification.
* for parameter reporting and modification.
*
*
* The parameter list is stored in a map with the parameter IDs as keys and values
* The parameter list is stored in a map with the parameter IDs as keys and values
* corresponding Parameter
struct
s containing the PTC, PFC and the parameter's value.
* corresponding Parameter
classe
s containing the PTC, PFC and the parameter's value.
*/
*/
...
@@ -38,16 +37,18 @@ private:
...
@@ -38,16 +37,18 @@ private:
public:
public:
/**
/**
* Initializes the parameter list.
*
@brief
Initializes the parameter list.
*/
*/
ParameterService
();
ParameterService
();
/**
/**
* Adds a new parameter. If the parameter has not been added (either because the map is full or because it already
* @brief Adds a new parameter. Returns false if the parameter has not been added
* exists in it) then returns false.
* (either because the map is full or because it already exists in it).
* The parameter IDs are given sequentially, starting from 0.
* @param id: the desired ID for this parameter
* @param param: the parameter field to be included
* @param flags: the flags to be set for this field (see Parameter.hpp)
*/
*/
bool
addNewParameter
(
uint
8
_t
id
,
Parameter
param
,
const
char
*
flags
=
"110"
);
bool
addNewParameter
(
uint
16
_t
id
,
Parameter
param
,
const
char
*
flags
=
"110"
);
/**
/**
* This function receives a TC[20, 1] packet and returns a TM[20, 2] packet
* This function receives a TC[20, 1] packet and returns a TM[20, 2] packet
...
@@ -70,7 +71,8 @@ public:
...
@@ -70,7 +71,8 @@ public:
/**
/**
* This function receives a TC[20, 3] message and after checking whether its type is correct,
* This function receives a TC[20, 3] message and after checking whether its type is correct,
* iterates over all contained parameter IDs and replaces the settings for each valid parameter,
* iterates over all contained parameter IDs and replaces the settings for each valid parameter,
* while ignoring all invalid IDs.
* while ignoring all invalid IDs. If the manual update flag is not set, the parameter's value should
* not change.
*
*
* @param newParamValues: a valid TC[20, 3] message carrying parameter ID and replacement value
* @param newParamValues: a valid TC[20, 3] message carrying parameter ID and replacement value
* @return None
* @return None
...
...
This diff is collapsed.
Click to expand it.
src/Services/ParameterService.cpp
+
14
−
8
View file @
22749839
...
@@ -7,21 +7,29 @@ ParameterService::ParameterService() {
...
@@ -7,21 +7,29 @@ ParameterService::ParameterService() {
// addNewParameter(3, 14);
// addNewParameter(3, 14);
}
}
bool
ParameterService
::
addNewParameter
(
uint
8
_t
id
,
Parameter
param
,
const
char
*
flags
)
{
bool
ParameterService
::
addNewParameter
(
uint
16
_t
id
,
Parameter
param
,
const
char
*
flags
)
{
try
{
try
{
// second element of the returned std::pair is whether the given item was inserted or not
try
{
param
.
setFlag
(
flags
);
paramsList
.
at
(
id
);
paramsList
.
insert
(
std
::
make_pair
(
id
,
param
));
return
false
;
return
true
;
// if it exists, an iterator will be returned with no exception thrown,
// so the function should return false
// todo: is it a better idea to use find() and if instead of an exception here?
}
catch
(
etl
::
map_out_of_bounds
&
mapOutOfBounds
)
{
param
.
setFlag
(
flags
);
paramsList
.
insert
(
std
::
make_pair
(
id
,
param
));
return
true
;
}
}
}
catch
(
etl
::
map_full
&
mapFull
)
{
catch
(
etl
::
map_full
&
mapFull
)
{
return
false
;
return
false
;
// if the map is full, return false
}
}
}
}
void
ParameterService
::
reportParameterIds
(
Message
&
paramIds
)
{
void
ParameterService
::
reportParameterIds
(
Message
&
paramIds
)
{
etl
::
vector
<
std
::
pair
<
uint16_t
,
ValueType
>
,
MAX_PARAMS
>
validParams
;
etl
::
vector
<
std
::
pair
<
uint16_t
,
ValueType
>
,
MAX_PARAMS
>
validParams
;
// paramIds.assertTC(20, 1);
Message
reqParam
(
20
,
2
,
Message
::
TM
,
1
);
Message
reqParam
(
20
,
2
,
Message
::
TM
,
1
);
// empty TM[20, 2] parameter report message
// empty TM[20, 2] parameter report message
...
@@ -66,8 +74,6 @@ void ParameterService::reportParameterIds(Message& paramIds) {
...
@@ -66,8 +74,6 @@ void ParameterService::reportParameterIds(Message& paramIds) {
}
}
void
ParameterService
::
setParameterIds
(
Message
&
newParamValues
)
{
void
ParameterService
::
setParameterIds
(
Message
&
newParamValues
)
{
//newParamValues.assertTC(20, 3);
// assertion: correct message, packet and service type (at failure throws an
// assertion: correct message, packet and service type (at failure throws an
// InternalError::UnacceptablePacket which gets logged)
// InternalError::UnacceptablePacket which gets logged)
...
...
This diff is collapsed.
Click to expand it.
test/Services/ParameterService.cpp
+
7
−
3
View file @
22749839
...
@@ -36,9 +36,13 @@ TEST_CASE("Parameter Service - General") {
...
@@ -36,9 +36,13 @@ TEST_CASE("Parameter Service - General") {
Services
.
reset
();
// reset all services
Services
.
reset
();
// reset all services
}
}
// SECTION("Addition of already existing parameter") {
SECTION
(
"Addition of already existing parameter"
)
{
//
Parameter
param0
=
Parameter
(
1
,
3
);
// }
pserv
.
addNewParameter
(
0
,
param0
);
CHECK_FALSE
(
pserv
.
addNewParameter
(
0
,
param0
));
Services
.
reset
();
}
//SECTION("Passing of null-pointer as update function on construction")
//SECTION("Passing of null-pointer as update function on construction")
...
...
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