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
using InputStatus = struct _InputStatus {
char PtName[100]{};
char PtName[80]{};
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
_InputStatus& operator=(const _InputStatus& rhs)

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

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

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

Loading…
Cancel
Save