feat(UML-1462): Оптимизированна упаковка датаграмм
This commit is contained in:
parent
7f00744ba1
commit
0415a6e63a
@ -50,6 +50,7 @@ void EthEcatPdoFMMU::wait_op() {
|
||||
process_sem.pend();
|
||||
|
||||
for(uint32_t i = 0; i < 250; i++) {
|
||||
//ClockP_usleep(125);
|
||||
read_write(0, data_tuple_read, 0, data_tuple_write);
|
||||
|
||||
//read(0, process_data);
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_API_HPP_
|
||||
|
||||
#define COMX 1
|
||||
#define PROCESS_FAKE 1
|
||||
//#define PROCESS_FAKE 1
|
||||
|
||||
#include "ethernet/eth.hpp"
|
||||
#include "ethernet_industry/eth_ecat.hpp"
|
||||
|
@ -93,29 +93,9 @@ using L = Type<TYPE_INDEX::L>;
|
||||
|
||||
class EcatCommandBase {
|
||||
public:
|
||||
EcatCommandBase(TYPE_INDEX type, DIR_INDEX dir)
|
||||
: cmd_{get_cmd_from_table(type, dir)} { }
|
||||
|
||||
EcatCommandBase()
|
||||
: cmd_{ec_cmdtype::EC_CMD_NOP} { }
|
||||
|
||||
uint8_t get_cmd() {
|
||||
return cmd_;
|
||||
}
|
||||
|
||||
private:
|
||||
ec_cmdtype cmd_;
|
||||
|
||||
static constexpr ec_cmdtype get_cmd_from_table(TYPE_INDEX type, DIR_INDEX dir) {
|
||||
std::array<std::array<ec_cmdtype, 4>, 4> commands = {{
|
||||
{{EC_CMD_APRD, EC_CMD_APWR, EC_CMD_APRW, EC_CMD_ARMW}},
|
||||
{{EC_CMD_BRD, EC_CMD_BWR, EC_CMD_BRW, EC_CMD_NOP}},
|
||||
{{EC_CMD_FPRD, EC_CMD_FPWR, EC_CMD_FPRW, EC_CMD_FRMW}},
|
||||
{{EC_CMD_LRD, EC_CMD_LWR, EC_CMD_LRW, EC_CMD_NOP}}
|
||||
}};
|
||||
|
||||
return commands[static_cast<uint16_t>(type)][static_cast<uint16_t>(dir)];
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TypeT, typename DirT>
|
||||
@ -125,11 +105,46 @@ class EcatCommand : public EcatCommandBase {
|
||||
|
||||
public:
|
||||
EcatCommand(typename TypeT::TAddress&& address)
|
||||
: EcatCommandBase{TypeT::type, DirT::dir}
|
||||
, address_{address} { }
|
||||
: address_{address} { }
|
||||
|
||||
EcatCommand() { }
|
||||
|
||||
static constexpr TYPE_INDEX type = TypeT::type;
|
||||
static constexpr DIR_INDEX dir = DirT::dir;
|
||||
|
||||
static constexpr uint8_t get_cmd() {
|
||||
std::array<std::array<uint8_t, 4>, 4> commands = {{
|
||||
{{EC_CMD_APRD, EC_CMD_APWR, EC_CMD_APRW, EC_CMD_ARMW}},
|
||||
{{EC_CMD_BRD, EC_CMD_BWR, EC_CMD_BRW, EC_CMD_NOP}},
|
||||
{{EC_CMD_FPRD, EC_CMD_FPWR, EC_CMD_FPRW, EC_CMD_FRMW}},
|
||||
{{EC_CMD_LRD, EC_CMD_LWR, EC_CMD_LRW, EC_CMD_NOP}}
|
||||
}};
|
||||
|
||||
return commands[static_cast<uint16_t>(TypeT::type)][static_cast<uint16_t>(DirT::dir)];
|
||||
}
|
||||
|
||||
static constexpr bool get_skip_pack() {
|
||||
std::array<std::array<bool, 4>, 4> commands = {{
|
||||
{{true, false, false, false}},
|
||||
{{false, false, false, true}},
|
||||
{{true, false, false, false}},
|
||||
{{true, false, false, true}}
|
||||
}};
|
||||
|
||||
return commands[static_cast<uint16_t>(TypeT::type)][static_cast<uint16_t>(DirT::dir)];
|
||||
}
|
||||
|
||||
static constexpr bool get_skip_unpack() {
|
||||
std::array<std::array<bool, 4>, 4> commands = {{
|
||||
{{false, true, false, false}},
|
||||
{{false, false, false, true}},
|
||||
{{false, true, false, false}},
|
||||
{{false, true, false, true}}
|
||||
}};
|
||||
|
||||
return commands[static_cast<uint16_t>(TypeT::type)][static_cast<uint16_t>(DirT::dir)];
|
||||
}
|
||||
|
||||
uint32_t get_address() {
|
||||
uint32_t address{0x00000000};
|
||||
PackFunctor functor{reinterpret_cast<uint8_t*>(&address)};
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
}
|
||||
|
||||
void pack(uint8_t* raw) {
|
||||
PackFunctor functor{raw};
|
||||
PackFunctor functor{raw, false};
|
||||
|
||||
for_each(data_tuple_, functor);
|
||||
|
||||
@ -54,7 +54,7 @@ public:
|
||||
}
|
||||
|
||||
void unpack(uint8_t* raw) {
|
||||
UnpackFunctor functor{raw};
|
||||
UnpackFunctor functor{raw, false};
|
||||
|
||||
for_each(data_tuple_, functor);
|
||||
|
||||
|
@ -105,7 +105,7 @@ private:
|
||||
}
|
||||
|
||||
uint8_t* pack_data(uint8_t *raw) {
|
||||
PackFunctor functor{raw};
|
||||
PackFunctor functor{raw, command_.get_skip_pack()};
|
||||
|
||||
for_each(data_tuple_, functor);
|
||||
|
||||
@ -141,7 +141,7 @@ private:
|
||||
}
|
||||
|
||||
uint8_t* unpack_data(uint8_t *raw) {
|
||||
UnpackFunctor functor{raw};
|
||||
UnpackFunctor functor{raw, command_.get_skip_unpack()};
|
||||
|
||||
for_each(data_tuple_, functor);
|
||||
|
||||
|
@ -23,12 +23,14 @@ struct Padding {
|
||||
|
||||
struct PackFunctorBase {
|
||||
uint8_t *raw;
|
||||
bool skip;
|
||||
|
||||
template<typename DataT>
|
||||
void operator()(DataT& data) {
|
||||
DataT *data_p = new(raw) DataT{data};
|
||||
|
||||
(void)data_p;
|
||||
if(skip == false) {
|
||||
DataT *data_p = new(raw) DataT{data};
|
||||
(void)data_p;
|
||||
}
|
||||
|
||||
raw += sizeof(DataT);
|
||||
|
||||
@ -38,8 +40,8 @@ struct PackFunctorBase {
|
||||
|
||||
// Функтор для обхода и упаковки элементов custom_tuple
|
||||
struct PackFunctor : public PackFunctorBase {
|
||||
PackFunctor(uint8_t *raw)
|
||||
: PackFunctorBase{raw} { }
|
||||
PackFunctor(uint8_t *raw, bool skip = false)
|
||||
: PackFunctorBase{raw, skip} { }
|
||||
|
||||
using PackFunctorBase::operator ();
|
||||
|
||||
@ -47,7 +49,9 @@ struct PackFunctor : public PackFunctorBase {
|
||||
void operator()(std::vector<DataT>& data) {
|
||||
size_t size = data.size() * sizeof(DataT);
|
||||
|
||||
memcpy(raw, data.data(), size);
|
||||
if(skip == false) {
|
||||
memcpy(raw, data.data(), size);
|
||||
}
|
||||
|
||||
raw += size;
|
||||
}
|
||||
@ -57,7 +61,9 @@ struct PackFunctor : public PackFunctorBase {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(raw, data.data, data.size);
|
||||
if(skip == false) {
|
||||
memcpy(raw, data.data, data.size);
|
||||
}
|
||||
|
||||
raw += data.size;
|
||||
}
|
||||
@ -69,12 +75,14 @@ struct PackFunctor : public PackFunctorBase {
|
||||
|
||||
struct UnpackFunctorBase {
|
||||
uint8_t *raw;
|
||||
bool skip;
|
||||
|
||||
template<typename DataT>
|
||||
void operator()(DataT& data) {
|
||||
DataT *p_data = reinterpret_cast<DataT*>(raw);
|
||||
|
||||
data = *p_data;
|
||||
if(skip == false) {
|
||||
DataT *p_data = reinterpret_cast<DataT*>(raw);
|
||||
data = *p_data;
|
||||
}
|
||||
|
||||
raw += sizeof(DataT);
|
||||
|
||||
@ -86,8 +94,8 @@ struct UnpackFunctorBase {
|
||||
|
||||
// Функтор для обхода и распаковки элементов custom_tuple
|
||||
struct UnpackFunctor : public UnpackFunctorBase {
|
||||
UnpackFunctor(uint8_t *raw)
|
||||
: UnpackFunctorBase{raw} { }
|
||||
UnpackFunctor(uint8_t *raw, bool skip)
|
||||
: UnpackFunctorBase{raw, skip} { }
|
||||
|
||||
using UnpackFunctorBase::operator ();
|
||||
|
||||
@ -95,7 +103,9 @@ struct UnpackFunctor : public UnpackFunctorBase {
|
||||
void operator()(std::vector<DataT>& data) {
|
||||
size_t size = data.size() * sizeof(DataT);
|
||||
|
||||
memcpy(data.data(), raw, size);
|
||||
if(skip == false) {
|
||||
memcpy(data.data(), raw, size);
|
||||
}
|
||||
|
||||
raw += size;
|
||||
}
|
||||
@ -105,7 +115,9 @@ struct UnpackFunctor : public UnpackFunctorBase {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(data.data, raw, data.size);
|
||||
if(skip == false) {
|
||||
memcpy(data.data, raw, data.size);
|
||||
}
|
||||
|
||||
raw += data.size;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user