refactor(UML-1462): Небольшой рефакторинг

This commit is contained in:
algin 2023-06-29 11:39:26 +03:00
parent 0415a6e63a
commit 892b8dfe12
8 changed files with 11 additions and 83 deletions

View File

@ -272,7 +272,6 @@ bool EthEcat::safeop_to_op() {
} }
success = (stat.state == EC_STATE_OPERATIONAL) && (stat.fault == 0); success = (stat.state == EC_STATE_OPERATIONAL) && (stat.fault == 0);
//ClockP_usleep(3000000ul);
if(success == true) { if(success == true) {
ecat_timer_.Start(); ecat_timer_.Start();

View File

@ -151,51 +151,6 @@ public:
return (stat.state == EC_STATE_SAFE_OP) && (stat.fault == 0); return (stat.state == EC_STATE_SAFE_OP) && (stat.fault == 0);
} }
template<typename TypeT>
bool safeop_to_op(telegram::EcatTelegram& telegram) {
auto slave_address = get_slave_address<TypeT>();
ALSTAT stat{0x0000, 0x0000};
uint16_t zero{0x00000000};
{
using TCommand = command::EcatCommand<TypeT, command::WR>;
uint16_t data{EC_STATE_OPERATIONAL};
datagram::EcatDatagram<TCommand, uint16_t> datagram{ {{slave_address, ECT_REG_ALCTL}}, data };
do {
telegram.transfer(datagram);
} while(datagram.get_wkc() < 0x0001);
}
//ClockP_usleep(3000000ul);
{
using TCommand = command::EcatCommand<TypeT, command::RD>;
datagram::EcatDatagram<TCommand, ALSTAT, uint16_t> datagram{ {{slave_address, ECT_REG_ALSTAT}}, stat, zero };
do {
telegram.transfer(datagram);
} while(datagram.get_wkc() < 0x0001);
}
DebugP_log((char*)"stat.state = %d, stat.fault = %d\r\n", stat.state, stat.fault);
if((stat.state & 0x0010) != 0) {
using TCommand = command::EcatCommand<TypeT, command::RD>;
uint16_t stat_code{0x0000};
datagram::EcatDatagram<TCommand, uint16_t> datagram{ {{slave_address, ECT_REG_ALSTATCODE}}, stat_code};
do {
telegram.transfer(datagram);
} while(datagram.get_wkc() < 0x0001);
DebugP_log((char*)"stat_code = 0x%02x\r\n", stat_code);
}
return (stat.state == EC_STATE_OPERATIONAL) && (stat.fault == 0);
}
private: private:
address::SlaveAddresses slave_addresses_; address::SlaveAddresses slave_addresses_;
}; };
@ -271,8 +226,6 @@ private:
e_pktTotal e_pktTotal
}; };
//Mutex mut_;
free_rtos::Timer ecat_timer_; free_rtos::Timer ecat_timer_;
free_rtos::Semaphore rx_sem_; free_rtos::Semaphore rx_sem_;

View File

@ -9,7 +9,6 @@
#define FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_API_HPP_ #define FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_API_HPP_
#define COMX 1 #define COMX 1
//#define PROCESS_FAKE 1
#include "ethernet/eth.hpp" #include "ethernet/eth.hpp"
#include "ethernet_industry/eth_ecat.hpp" #include "ethernet_industry/eth_ecat.hpp"

View File

@ -387,15 +387,13 @@ class EthEcatBuffer {
public: public:
EthEcatBuffer(EthEcat& ecat): ecat_{ecat} { } EthEcatBuffer(EthEcat& ecat): ecat_{ecat} { }
EthEcat& get_ecat() void init(uint16_t rx_eeprom_addr, uint16_t tx_eeprom_addr);
{
EthEcat& get_ecat() {
return ecat_; return ecat_;
} }
void init(uint16_t rx_eeprom_addr, uint16_t tx_eeprom_addr); std::vector<EcatBufferSlave>& get_buffer_slaves() {
std::vector<EcatBufferSlave>& get_buffer_slaves()
{
return buffer_slaves_; return buffer_slaves_;
} }

View File

@ -109,8 +109,8 @@ public:
EcatCommand() { } EcatCommand() { }
static constexpr TYPE_INDEX type = TypeT::type; using TType = TypeT;
static constexpr DIR_INDEX dir = DirT::dir; using TDir = DirT;
static constexpr uint8_t get_cmd() { static constexpr uint8_t get_cmd() {
std::array<std::array<uint8_t, 4>, 4> commands = {{ std::array<std::array<uint8_t, 4>, 4> commands = {{

View File

@ -159,9 +159,6 @@ private:
} }
} }
#endif /* FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_DATAGRAM_HPP_ */ #endif /* FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_DATAGRAM_HPP_ */

View File

@ -41,7 +41,7 @@ public:
explicit Queue(DataType& first) { explicit Queue(DataType& first) {
//DebugP_log((char*)"Constructor coupling first data\r\n"); //DebugP_log((char*)"Constructor coupling first data\r\n");
append(&first); queue(&first);
} }
Queue(DataType& first, DataType& next) { Queue(DataType& first, DataType& next) {
@ -49,7 +49,7 @@ public:
first.set_next(&next); first.set_next(&next);
append(&first, &next, 2); queue(&first, &next, 2);
} }
DataType* get_first() { DataType* get_first() {
@ -67,13 +67,13 @@ public:
Queue& operator+(DataType& data) { Queue& operator+(DataType& data) {
//DebugP_log((char*)"Coupling next data\r\n"); //DebugP_log((char*)"Coupling next data\r\n");
return append(&data); return queue(&data);
} }
Queue& operator+(Queue& other) { Queue& operator+(Queue& other) {
//DebugP_log((char*)"Coupling with other queue\r\n"); //DebugP_log((char*)"Coupling with other queue\r\n");
return append(other.get_first(), other.get_last(), other.get_size()); return queue(other.get_first(), other.get_last(), other.get_size());
} }
DataType* dequeue() { DataType* dequeue() {
@ -109,7 +109,7 @@ private:
DataType *last_{nullptr}; DataType *last_{nullptr};
size_t size_{0}; size_t size_{0};
Queue& append(DataType *other_first, DataType *other_last = nullptr, size_t other_size = 1) { Queue& queue(DataType *other_first, DataType *other_last = nullptr, size_t other_size = 1) {
if(first_ == nullptr) { if(first_ == nullptr) {
first_ = other_first; first_ = other_first;
} }

View File

@ -52,20 +52,12 @@ uint8_t* EcatTelegram::pack(uint8_t *raw) {
auto queue = datagram_queue_; // Копия очереди auto queue = datagram_queue_; // Копия очереди
auto next = queue.dequeue(); auto next = queue.dequeue();
/*
if(datagram_queue_ == nullptr) {
DebugP_log((char*)"Warning ! Empty queue !\r\n");
return p_datagram_last;
}
auto next = datagram_queue_;
*/
while(next != nullptr) { while(next != nullptr) {
//DebugP_log((char*)"Packet packed\r\n"); //DebugP_log((char*)"Packet packed\r\n");
p_datagram_last = next->pack(p_datagram_last); p_datagram_last = next->pack(p_datagram_last);
next = queue.dequeue(); next = queue.dequeue();
//next = next->get_next();
} }
p_hdr->bits.length = p_datagram_last - p_datagram_first; p_hdr->bits.length = p_datagram_last - p_datagram_first;
@ -93,20 +85,12 @@ uint8_t* EcatTelegram::unpack(uint8_t *raw) {
auto queue = datagram_queue_; // Копия очереди auto queue = datagram_queue_; // Копия очереди
auto next = queue.dequeue(); auto next = queue.dequeue();
/*
if(datagram_queue_ == nullptr) {
DebugP_log((char*)"Warning ! Empty queue !\r\n");
return p_datagram_last;
}
auto next = datagram_queue_;
*/
while(next != nullptr) { while(next != nullptr) {
//DebugP_log((char*)"Packet unpacked\r\n"); //DebugP_log((char*)"Packet unpacked\r\n");
p_datagram_last = next->unpack(p_datagram_last); p_datagram_last = next->unpack(p_datagram_last);
next = queue.dequeue(); next = queue.dequeue();
//next = next->get_next();
} }
return p_datagram_last; return p_datagram_last;
@ -124,12 +108,10 @@ void EcatTelegram::transfer() {
rx_sem_.pend(); rx_sem_.pend();
datagram_queue_.clear(); datagram_queue_.clear();
//datagram_queue_ = nullptr;
} }
void EcatTelegram::transfer(datagram::IEcatDatagram& next) { void EcatTelegram::transfer(datagram::IEcatDatagram& next) {
datagram_queue_ + next; datagram_queue_ + next;
//datagram_queue_ = &next;
transfer(); transfer();
} }