Skip to content
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

secure OD struct to not compile in case of access violation. fix #295 #421

Merged
merged 22 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6dc9c46
secure angular_od structs to generate error at compilation in case of…
nicolas-rabault Feb 3, 2023
0e4c5e5
secure electric_od structs to generate error at compilation in case o…
nicolas-rabault Feb 6, 2023
c043886
secure force_od structs to generate error at compilation in case of m…
nicolas-rabault Feb 6, 2023
984a6d0
secure illuminance_od structs to generate error at compilation in cas…
nicolas-rabault Feb 6, 2023
baca80e
secure linear_od structs to generate error at compilation in case of …
nicolas-rabault Feb 6, 2023
9b63a30
secure pressure_od structs to generate error at compilation in case o…
nicolas-rabault Feb 6, 2023
222c947
secure ratio_od structs to generate error at compilation in case of m…
nicolas-rabault Feb 6, 2023
da14663
secure temperature_od structs to generate error at compilation in cas…
nicolas-rabault Feb 6, 2023
561051e
secure time_od structs to generate error at compilation in case of mi…
nicolas-rabault Feb 6, 2023
593d6d3
Secure control_OD
nicolas-rabault Feb 10, 2023
3594422
Secure pid_od
nicolas-rabault Feb 10, 2023
6584dbc
Add Angular_od test
nicolas-rabault Feb 9, 2023
ec45e20
Add Electric_od test
nicolas-rabault Feb 10, 2023
7aa8db9
Add Force_od test
nicolas-rabault Feb 10, 2023
b01fb5b
Add Illuminance_od test
nicolas-rabault Feb 10, 2023
d54a61e
Add Linear_od test
nicolas-rabault Feb 9, 2023
297af68
Add pressure_od test
nicolas-rabault Feb 10, 2023
0729afd
Add ratio_od test
nicolas-rabault Feb 10, 2023
a56bef5
Add temperature_od test
nicolas-rabault Feb 10, 2023
5b05db3
Add time_od test
nicolas-rabault Feb 10, 2023
9094311
Add Control_od test
nicolas-rabault Feb 10, 2023
9762166
Add pid_od test
nicolas-rabault Feb 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions engine/OD/od_angular.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
/*******************************************************************************
* Definitions
******************************************************************************/
typedef float angular_position_t;
typedef struct
{
float _private;
} angular_position_t;

typedef struct
{
float _private;
} angular_speed_t;

/*******************************************************************************
* Variables
Expand All @@ -26,108 +34,128 @@ typedef float angular_position_t;
// deg
static inline float AngularOD_PositionTo_deg(angular_position_t self)
{
return self;
return self._private;
}

static inline angular_position_t AngularOD_PositionFrom_deg(float deg)
{
return deg;
angular_position_t self;
self._private = deg;
return self;
}

// rev
static inline float AngularOD_PositionTo_rev(angular_position_t self)
{
return self / 360.0f;
return self._private / 360.0f;
}

static inline angular_position_t AngularOD_PositionFrom_rev(float rev)
{
return rev * 360.0f;
angular_position_t self;
self._private = rev * 360.0f;
return self;
}

// rad
static inline float AngularOD_PositionTo_rad(angular_position_t self)
{
return (self * 2.0f * 3.141592653589793f) / 360.0f;
return (self._private * 2.0f * 3.141592653589793f) / 360.0f;
}

static inline angular_position_t AngularOD_PositionFrom_rad(float rad)
{
return (rad * 360.0f) / (2.0f * 3.141592653589793f);
angular_position_t self;
self._private = (rad * 360.0f) / (2.0f * 3.141592653589793f);
return self;
}

//******** Messages management ***********
static inline void AngularOD_PositionToMsg(const angular_position_t *const self, msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
msg->header.cmd = ANGULAR_POSITION;
memcpy(msg->data, self, sizeof(angular_position_t));
msg->header.size = sizeof(angular_position_t);
}

static inline void AngularOD_PositionFromMsg(angular_position_t *const self, const msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
memcpy(self, msg->data, msg->header.size);
}

typedef float angular_speed_t;

// angular_speed are stored in degree/s (deg/s)
//******** Conversions ***********
//******************************** Conversions *******************************

// deg_s
static inline float AngularOD_SpeedTo_deg_s(angular_speed_t self)
{
return self;
return self._private;
}

static inline angular_speed_t AngularOD_SpeedFrom_deg_s(float deg)
{
return deg;
angular_speed_t self;
self._private = deg;
return self;
}

// rev_s
static inline float AngularOD_SpeedTo_rev_s(angular_speed_t self)
{
return self / 360.0f;
return self._private / 360.0f;
}

static inline angular_speed_t AngularOD_SpeedFrom_rev_s(float rev_s)
{
return rev_s * 360.0f;
angular_speed_t self;
self._private = rev_s * 360.0f;
return self;
}

// rev_min
static inline float AngularOD_SpeedTo_rev_min(angular_speed_t self)
{
return self * 60.0f / 360.0f;
return self._private * 60.0f / 360.0f;
}

static inline angular_speed_t AngularOD_SpeedFrom_rev_min(float rev_min)
{
return rev_min * 360.0f / 60.0f;
angular_speed_t self;
self._private = rev_min * 360.0f / 60.0f;
return self;
}

// rad_s
static inline float AngularOD_SpeedTo_rad_s(angular_speed_t self)
{
return (self * 2.0f * 3.141592653589793f) / 360.0f;
return (self._private * 2.0f * 3.141592653589793f) / 360.0f;
}

static inline angular_speed_t AngularOD_SpeedFrom_rad_s(float rad_s)
{
return (rad_s * 360.0f) / (2.0f * 3.141592653589793f);
angular_speed_t self;
self._private = (rad_s * 360.0f) / (2.0f * 3.141592653589793f);
return self;
}

//******** Messages management ***********
static inline void AngularOD_SpeedToMsg(const angular_speed_t *const self, msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
msg->header.cmd = ANGULAR_SPEED;
memcpy(msg->data, self, sizeof(angular_speed_t));
msg->header.size = sizeof(angular_speed_t);
}

static inline void AngularOD_SpeedFromMsg(angular_speed_t *const self, const msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
memcpy(self, msg->data, msg->header.size);
}

Expand Down
4 changes: 4 additions & 0 deletions engine/OD/od_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ typedef struct __attribute__((__packed__))
//******** Messages management ***********
static inline void ControlOD_ControlToMsg(const control_t *const self, msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
msg->header.cmd = CONTROL;
memcpy(msg->data, self, sizeof(control_t));
msg->header.size = sizeof(control_t);
}

static inline void ControlOD_ControlFromMsg(control_t *const self, const msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
LUOS_ASSERT(msg->header.size == sizeof(control_t));
memcpy(self, msg->data, sizeof(control_t));
// check data validity
Expand Down
73 changes: 53 additions & 20 deletions engine/OD/od_electric.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@
/*******************************************************************************
* Definitions
******************************************************************************/
typedef float voltage_t;
typedef struct
{
float _private;
} voltage_t;

typedef struct
{
float _private;
} current_t;

typedef struct
{
float _private;
} power_t;
/*******************************************************************************
* Variables
******************************************************************************/
Expand All @@ -25,115 +38,135 @@ typedef float voltage_t;
// mv
static inline float ElectricOD_VoltageTo_mV(voltage_t self)
{
return self * 1000.0f;
return self._private * 1000.0f;
}

static inline voltage_t ElectricOD_VoltageFrom_mV(float mv)
{
return mv / 1000.0f;
voltage_t self;
self._private = mv / 1000.0f;
return self;
}

// v
static inline float ElectricOD_VoltageTo_V(voltage_t self)
{
return self;
return self._private;
}

static inline voltage_t ElectricOD_VoltageFrom_V(float v)
{
return v;
voltage_t self;
self._private = v;
return self;
}

//******** Messages management ***********
static inline void ElectricOD_VoltageToMsg(const voltage_t *const self, msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
msg->header.cmd = VOLTAGE;
memcpy(msg->data, self, sizeof(voltage_t));
msg->header.size = sizeof(voltage_t);
}

static inline void ElectricOD_VoltageFromMsg(voltage_t *const self, const msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
memcpy(self, msg->data, msg->header.size);
}

typedef float current_t;

// current are stored in Ampere (A)
//******** Conversions ***********
//******************************** Conversions *******************************

// ma
static inline float ElectricOD_CurrentTo_mA(current_t self)
{
return self * 1000.0f;
return self._private * 1000.0f;
}

static inline current_t ElectricOD_CurrentFrom_mA(float ma)
{
return ma / 1000.0f;
current_t self;
self._private = ma / 1000.0f;
return self;
}

// A
static inline float ElectricOD_CurrentTo_A(current_t self)
{
return self;
return self._private;
}

static inline current_t ElectricOD_CurrentFrom_A(float a)
{
return a;
current_t self;
self._private = a;
return self;
}

//******** Messages management ***********
static inline void ElectricOD_CurrentToMsg(const current_t *const self, msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
msg->header.cmd = CURRENT;
memcpy(msg->data, self, sizeof(current_t));
msg->header.size = sizeof(current_t);
}

static inline void ElectricOD_CurrentFromMsg(current_t *const self, const msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
memcpy(self, msg->data, msg->header.size);
}

typedef float power_t;

// power are stored in Watt (W)
//******** Conversions ***********
//******************************** Conversions *******************************

// mw
static inline float ElectricOD_PowerTo_mW(power_t self)
{
return self * 1000.0f;
return self._private * 1000.0f;
}

static inline power_t ElectricOD_PowerFrom_mW(float mw)
{
return mw / 1000.0f;
power_t self;
self._private = mw / 1000.0f;
return self;
}

// A
static inline float ElectricOD_PowerTo_W(power_t self)
{
return self;
return self._private;
}

static inline power_t ElectricOD_PowerFrom_W(float w)
{
return w;
power_t self;
self._private = w;
return self;
}

//******** Messages management ***********
static inline void ElectricOD_PowerToMsg(const power_t *const self, msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
msg->header.cmd = POWER;
memcpy(msg->data, self, sizeof(power_t));
msg->header.size = sizeof(power_t);
}

static inline void ElectricOD_PowerFromMsg(current_t *const self, const msg_t *const msg)
static inline void ElectricOD_PowerFromMsg(power_t *const self, const msg_t *const msg)
{
LUOS_ASSERT(self);
LUOS_ASSERT(msg);
memcpy(self, msg->data, msg->header.size);
}

Expand Down
Loading