From 3c9a8e40a3e1b0f8784f463f25c2cb19eb4c46cf Mon Sep 17 00:00:00 2001 From: algin Date: Fri, 26 May 2023 11:06:54 +0300 Subject: [PATCH] =?UTF-8?q?dev(UML-1462):=20=D0=A3=D0=B1=D1=80=D0=B0=D0=BB?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83=D1=82=D0=BE=D1=87?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BA=D0=BE=D0=BF=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D0=BF=D1=80=D0=B8=D0=B5=D0=BC=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ethernet_industry/eth_ecat_datagram.cpp | 32 ++++++++++++------- .../ethernet_industry/eth_ecat_datagram.hpp | 10 +++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/components/free_rtos/ethernet_industry/eth_ecat_datagram.cpp b/components/free_rtos/ethernet_industry/eth_ecat_datagram.cpp index f8f8396..9834149 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat_datagram.cpp +++ b/components/free_rtos/ethernet_industry/eth_ecat_datagram.cpp @@ -12,16 +12,24 @@ namespace free_rtos { namespace datagram { int32_t EcatTelegram::Process(uint8_t *p_data, uint32_t len) { - buffer_in_.length = len + sizeof(TEthFrameHeader); + //buffer_in_.length = len + sizeof(TEthFrameHeader); - memcpy(buffer_in_.data, p_data - sizeof(TEthFrameHeader), buffer_in_.length); + //memcpy(buffer_in_.data, p_data - sizeof(TEthFrameHeader), buffer_in_.length); + + if(first_ == nullptr) { + return 0; + } + + unpack(p_data); + + first_ = nullptr; rx_sem_.post(); return 0; } -void EcatTelegram::pack(IEcatDatagram& first) { +void EcatTelegram::pack() { TEthFrameHeader *p_eth_hdr = new(buffer_out_.data) TEthFrameHeader{ {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, {0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, ETH_PROT_ECAT_LE}; @@ -30,7 +38,7 @@ void EcatTelegram::pack(IEcatDatagram& first) { .type = static_cast(ec_network::PROTOCOL_TYPE)}}; uint8_t *p_datagram_first = buffer_out_.data + sizeof(TEthFrameHeader) + sizeof(TEcatFrameHeader); uint8_t *p_datagram_last = p_datagram_first; - IEcatDatagram *next = &first; + IEcatDatagram *next = first_; (void)p_eth_hdr; (void)p_hdr; @@ -44,12 +52,12 @@ void EcatTelegram::pack(IEcatDatagram& first) { buffer_out_.length = sizeof(TEthFrameHeader) + sizeof(TEcatFrameHeader) + p_hdr->bits.length; } -void EcatTelegram::unpack(IEcatDatagram& first) { - TEthFrameHeader *p_eth_hdr = reinterpret_cast(buffer_in_.data); - TEcatFrameHeader *p_hdr = reinterpret_cast(buffer_in_.data + sizeof(TEthFrameHeader)); - uint8_t *p_datagram_first = buffer_in_.data + sizeof(TEthFrameHeader) + sizeof(TEcatFrameHeader); +void EcatTelegram::unpack(uint8_t *raw) { + TEthFrameHeader *p_eth_hdr = reinterpret_cast(raw); + TEcatFrameHeader *p_hdr = reinterpret_cast(raw + sizeof(TEthFrameHeader)); + uint8_t *p_datagram_first = raw + sizeof(TEthFrameHeader) + sizeof(TEcatFrameHeader); uint8_t *p_datagram_last = p_datagram_first; - IEcatDatagram *next = &first; + IEcatDatagram *next = first_; (void)p_eth_hdr; (void)p_hdr; @@ -61,7 +69,9 @@ void EcatTelegram::unpack(IEcatDatagram& first) { } void EcatTelegram::transfer(IEcatDatagram& first) { - pack(first); + first_ = &first; + + pack(); bool stat = tx_flow_.send(port_id_, buffer_out_.data, buffer_out_.length); if(stat == false) { @@ -69,7 +79,7 @@ void EcatTelegram::transfer(IEcatDatagram& first) { } rx_sem_.pend(); - unpack(first); + //unpack(first); } } diff --git a/components/free_rtos/ethernet_industry/eth_ecat_datagram.hpp b/components/free_rtos/ethernet_industry/eth_ecat_datagram.hpp index 58fd1e1..32532f6 100644 --- a/components/free_rtos/ethernet_industry/eth_ecat_datagram.hpp +++ b/components/free_rtos/ethernet_industry/eth_ecat_datagram.hpp @@ -182,11 +182,13 @@ private: free_rtos::Semaphore rx_sem_; - TEthPkt buffer_out_; - TEthPkt buffer_in_; + IEcatDatagram *first_{nullptr}; - void pack(IEcatDatagram& first); - void unpack(IEcatDatagram& first); + TEthPkt buffer_out_; + //TEthPkt buffer_in_; + + void pack(); + void unpack(uint8_t *raw); }; }