optimize memory alignment to multiple of 8 bytes

* update MOTION_STATUS enum
main
Yik Teng Hie 1 year ago
parent b37fb36266
commit 11dd9b2e77

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -8,8 +8,16 @@ namespace nsMMF
{ {
// !!! Do Not change the order to support MMF use case // !!! Do Not change the order to support MMF use case
using InputStatus = struct _InputStatus { using InputStatus = struct _InputStatus {
char PtName[100]{}; char PtName[80]{};
bool On{ false }; bool On{ false };
// Padding
bool Padding1{ false };
bool Padding2{ false };
bool Padding3{ false };
bool Padding4{ false };
bool Padding5{ false };
bool Padding6{ false };
bool Padding7{ false };
// Assignment operator overload // Assignment operator overload
_InputStatus& operator=(const _InputStatus& rhs) _InputStatus& operator=(const _InputStatus& rhs)

@ -118,9 +118,9 @@
enum MOTION_STATUS enum MOTION_STATUS
{ {
MOTION_END,
MOTION_HOMING, MOTION_HOMING,
MOTION_MOVING, MOTION_MOVING,
MOTION_END,
MOTION_LIMIT_POS_HIT, MOTION_LIMIT_POS_HIT,
MOTION_LIMIT_NEG_HIT, MOTION_LIMIT_NEG_HIT,
MOTION_LIMIT_HIT, MOTION_LIMIT_HIT,

@ -7,44 +7,47 @@
namespace nsMMF namespace nsMMF
{ {
// !!! Do Not change the order to support MMF use case // !!! Do Not change the order to support MMF use case
using MotorStatus = struct _MotorStatus { using MotorStatus = struct _MotorStatus
bool NegLimHit{ false }; // 0 {
bool PosLimHit{ false }; // 1 char MotorName[80]{}; // offset 0 : 80 byte to align to 8 bytes
bool Homed{ false }; // 2
bool ServoReady{ false }; // 3 bool NegLimHit{ false }; // 80
bool ServoAlarm{ false }; // 4 bool PosLimHit{ false }; // 81
bool InPosition{ false }; // 5 bool Homed{ false }; // 82
bool MtrOn{ false }; // 6 bool ServoReady{ false }; // 83
bool MtrCurOnOff{ false }; // 7 // array to store motor On/Off States before maintenance mode bool ServoAlarm{ false }; // 84
double MtrPos{ 0. }; // 8 bool InPosition{ false }; // 85
double PosErr{ 0. }; // 16 bool MtrOn{ false }; // 86
unsigned short MotionStatus{ 0 }; // 24 bool MtrCurOnOff{ false }; // 87 // array to store motor On/Off States before maintenance mode
unsigned short Status{ 0 }; // 26 double MtrPos{ 0. }; // 88
int MtrNo{ 0 }; // 28 // motor no wrt the type of card used double PosErr{ 0. }; // 96
int MtrType{ 0 }; // 32 // servo or stepper, with or without encoder feedback unsigned short MotionStatus{ 0 }; // 104
int MtrCurPos{ 0 }; // 36 // array to store motor position before maintenance mode unsigned short Status{ 0 }; // 106
char MotorName[104]{ "AACC" }; // 40~ 144 (original size 4 bytes - but has to end on a 8-byte align address) int MtrNo{ 0 }; // 108 // motor no wrt the type of card used
int MtrType{ 0 }; // 112 // servo or stepper, with or without encoder feedback
int MtrCurPos{ 0 }; // 116 // array to store motor position before maintenance mode
// Assignment operator overload // Assignment operator overload
_MotorStatus& operator=(const _MotorStatus& rhs) _MotorStatus& operator=(const _MotorStatus& rhs)
{ {
NegLimHit = rhs.NegLimHit;
PosLimHit = rhs.PosLimHit;
Homed = rhs.Homed;
ServoReady = rhs.ServoReady;
ServoAlarm = rhs.ServoAlarm;
InPosition = rhs.InPosition;
MtrOn = rhs.MtrOn;
MtrCurOnOff = rhs.MtrCurOnOff;
MtrPos = rhs.MtrPos;
PosErr = rhs.PosErr;
MotionStatus = rhs.MotionStatus;
Status = rhs.Status;
MtrNo = rhs.MtrNo;
MtrType = rhs.MtrType;
MtrCurPos = rhs.MtrCurPos;
// //
strcpy_s(MotorName, rhs.MotorName); strcpy_s(MotorName, rhs.MotorName);
//
NegLimHit = rhs.NegLimHit;
PosLimHit = rhs.PosLimHit;
Homed = rhs.Homed;
ServoReady = rhs.ServoReady;
ServoAlarm = rhs.ServoAlarm;
InPosition = rhs.InPosition;
MtrOn = rhs.MtrOn;
MtrCurOnOff = rhs.MtrCurOnOff;
MtrPos = rhs.MtrPos;
PosErr = rhs.PosErr;
MotionStatus = rhs.MotionStatus;
Status = rhs.Status;
MtrNo = rhs.MtrNo;
MtrType = rhs.MtrType;
MtrCurPos = rhs.MtrCurPos;
return *this; return *this;
} }
@ -61,6 +64,9 @@ namespace nsMMF
inline void from_json(const json& j, MotorStatus& x) inline void from_json(const json& j, MotorStatus& x)
{ {
std::string name = j.at("MotorName").get<std::string>();
strcpy_s(x.MotorName, name.c_str());
getValue(j, "NegLimHit", x.NegLimHit); getValue(j, "NegLimHit", x.NegLimHit);
getValue(j, "PosLimHit", x.PosLimHit); getValue(j, "PosLimHit", x.PosLimHit);
getValue(j, "Homed", x.Homed); getValue(j, "Homed", x.Homed);
@ -76,31 +82,27 @@ namespace nsMMF
getValue(j, "MtrNo", x.MtrNo); getValue(j, "MtrNo", x.MtrNo);
getValue(j, "MtrType", x.MtrType); getValue(j, "MtrType", x.MtrType);
getValue(j, "MtrCurPos", x.MtrCurPos); getValue(j, "MtrCurPos", x.MtrCurPos);
//getValue(j, "MotorName", x.MotorName);
std::string name = j.at("MotorName").get<std::string>();
strcpy_s(x.MotorName, name.c_str());
} }
inline void to_json(json& j, const MotorStatus& x) inline void to_json(json& j, const MotorStatus& x)
{ {
j = nlohmann::json{ j = nlohmann::json{
{ "NegLimHit", x.NegLimHit }, { "MotorName", x.MotorName },
{ "PosLimHit", x.PosLimHit }, { "NegLimHit", x.NegLimHit },
{ "Homed", x.Homed }, { "PosLimHit", x.PosLimHit },
{ "ServoReady", x.ServoReady }, { "Homed", x.Homed },
{ "ServoAlarm", x.ServoAlarm }, { "ServoReady", x.ServoReady },
{ "InPosition", x.InPosition }, { "ServoAlarm", x.ServoAlarm },
{ "MtrOn", x.MtrOn }, { "InPosition", x.InPosition },
{ "MtrCurOnOff", x.MtrCurOnOff }, { "MtrOn", x.MtrOn },
{ "MtrPos", x.MtrPos }, { "MtrCurOnOff", x.MtrCurOnOff },
{ "PosErr", x.PosErr }, { "MtrPos", x.MtrPos },
{ "MotionStatus", x.MotionStatus }, { "PosErr", x.PosErr },
{ "Status", x.Status }, { "MotionStatus", x.MotionStatus },
{ "MtrNo", x.MtrNo }, { "Status", x.Status },
{ "MtrType", x.MtrType }, { "MtrNo", x.MtrNo },
{ "MtrCurPos", x.MtrCurPos }, { "MtrType", x.MtrType },
{ "MotorName", x.MotorName } { "MtrCurPos", x.MtrCurPos }
}; };
} }

@ -8,10 +8,16 @@ namespace nsMMF
{ {
// !!! Do Not change the order to support MMF use case // !!! Do Not change the order to support MMF use case
using OutputStatus = struct _OutputStatus { using OutputStatus = struct _OutputStatus {
char PtName[100]{}; char PtName[80]{};
bool On{ false }; bool On{ false };
bool RequestChgState{ false }; bool RequestChgState{ false };
bool ChgStateOn{ false }; bool ChgStateOn{ false };
// Padding
bool Padding1{ false };
bool Padding2{ false };
bool Padding3{ false };
bool Padding4{ false };
bool Padding5{ false };
// Assignment operator overload // Assignment operator overload
_OutputStatus& operator=(const _OutputStatus& rhs) _OutputStatus& operator=(const _OutputStatus& rhs)
@ -22,6 +28,13 @@ namespace nsMMF
On = rhs.On; On = rhs.On;
RequestChgState = rhs.RequestChgState; RequestChgState = rhs.RequestChgState;
ChgStateOn = rhs.ChgStateOn; ChgStateOn = rhs.ChgStateOn;
//
Padding1 = rhs.Padding1;
Padding2 = rhs.Padding2;
Padding3 = rhs.Padding3;
Padding4 = rhs.Padding4;
Padding5 = rhs.Padding5;
//
return *this; return *this;
} }
}; };

Loading…
Cancel
Save