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);
//ClockP_usleep(3000000ul);
if(success == true) {
ecat_timer_.Start();

View File

@ -151,51 +151,6 @@ public:
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:
address::SlaveAddresses slave_addresses_;
};
@ -271,8 +226,6 @@ private:
e_pktTotal
};
//Mutex mut_;
free_rtos::Timer ecat_timer_;
free_rtos::Semaphore rx_sem_;

View File

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

View File

@ -387,15 +387,13 @@ class EthEcatBuffer {
public:
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_;
}
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_;
}

View File

@ -109,8 +109,8 @@ public:
EcatCommand() { }
static constexpr TYPE_INDEX type = TypeT::type;
static constexpr DIR_INDEX dir = DirT::dir;
using TType = TypeT;
using TDir = DirT;
static constexpr uint8_t get_cmd() {
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_ */

View File

@ -41,7 +41,7 @@ public:
explicit Queue(DataType& first) {
//DebugP_log((char*)"Constructor coupling first data\r\n");
append(&first);
queue(&first);
}
Queue(DataType& first, DataType& next) {
@ -49,7 +49,7 @@ public:
first.set_next(&next);
append(&first, &next, 2);
queue(&first, &next, 2);
}
DataType* get_first() {
@ -67,13 +67,13 @@ public:
Queue& operator+(DataType& data) {
//DebugP_log((char*)"Coupling next data\r\n");
return append(&data);
return queue(&data);
}
Queue& operator+(Queue& other) {
//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() {
@ -109,7 +109,7 @@ private:
DataType *last_{nullptr};
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) {
first_ = other_first;
}

View File

@ -52,20 +52,12 @@ uint8_t* EcatTelegram::pack(uint8_t *raw) {
auto queue = datagram_queue_; // Копия очереди
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) {
//DebugP_log((char*)"Packet packed\r\n");
p_datagram_last = next->pack(p_datagram_last);
next = queue.dequeue();
//next = next->get_next();
}
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 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) {
//DebugP_log((char*)"Packet unpacked\r\n");
p_datagram_last = next->unpack(p_datagram_last);
next = queue.dequeue();
//next = next->get_next();
}
return p_datagram_last;
@ -124,12 +108,10 @@ void EcatTelegram::transfer() {
rx_sem_.pend();
datagram_queue_.clear();
//datagram_queue_ = nullptr;
}
void EcatTelegram::transfer(datagram::IEcatDatagram& next) {
datagram_queue_ + next;
//datagram_queue_ = &next;
transfer();
}