fix(UML-1582): Багфиксы

This commit is contained in:
algin 2023-06-16 13:01:24 +03:00
parent 14d7e6b376
commit bd46f29041
8 changed files with 58 additions and 104 deletions

View File

@ -62,7 +62,7 @@ void EthEcatPdoFMMU::wait_op() {
void EthEcatPdoFMMU::process_write_queue(uint8_t* process_data, uint32_t len) { void EthEcatPdoFMMU::process_write_queue(uint8_t* process_data, uint32_t len) {
mutex_write_.lock(); mutex_write_.lock();
queue::Queue<custom_promise::IPromise> queue = queue_write_; auto queue = queue_write_; // Копия очереди
queue_write_.clear(); queue_write_.clear();
mutex_write_.unlock(); mutex_write_.unlock();
@ -78,7 +78,7 @@ void EthEcatPdoFMMU::process_write_queue(uint8_t* process_data, uint32_t len) {
void EthEcatPdoFMMU::process_read_queue(uint8_t* process_data, uint32_t len) { void EthEcatPdoFMMU::process_read_queue(uint8_t* process_data, uint32_t len) {
mutex_read_.lock(); mutex_read_.lock();
queue::Queue<custom_promise::IPromise> queue = queue_read_; auto queue = queue_read_; // Копия очереди
queue_read_.clear(); queue_read_.clear();
mutex_read_.unlock(); mutex_read_.unlock();

View File

@ -28,7 +28,7 @@ void EthEcat::Init(TEthMacPorts port_id) {
.clock_src_mux_addr = 0x430081B0u, // sysconfig .clock_src_mux_addr = 0x430081B0u, // sysconfig
.int_num = 152u, // sysconfig .int_num = 152u, // sysconfig
.int_priority = 4, // sysconfig .int_priority = 4, // sysconfig
.period_us = 400 ///400 microsec .period_us = 1000 ///400 microsec
}; };
ecat_timer_.Init(ecat_tmr_sett); ecat_timer_.Init(ecat_tmr_sett);
@ -97,7 +97,7 @@ void EthEcat::set_slaves_to_default() {
auto queue = a + b + c + d + e + f + g + h + i + j + k + l + m; auto queue = a + b + c + d + e + f + g + h + i + j + k + l + m;
do { do {
telegram_.transfer(a); telegram_.transfer(queue);
} while(a.get_all_wkc() < 0x0001); } while(a.get_all_wkc() < 0x0001);
//telegram_.transfer(b); //telegram_.transfer(b);
@ -154,9 +154,7 @@ void EthEcat::set_addresses_of_slaves(uint16_t number_of_slaves, uint16_t addres
address::SlaveAddresses slave_addresses{position, 0x0000, station, 0x00000000}; address::SlaveAddresses slave_addresses{position, 0x0000, station, 0x00000000};
slaves_.emplace_back(EcatSlave{std::move(slave_addresses)}); slaves_.emplace_back(EcatSlave{std::move(slave_addresses)});
datagrams.emplace_back(TDatagram{ {{position, ECT_REG_STADR}}, slaves_.back().get_slave_address<command::FP>() }); datagrams.emplace_back(TDatagram{ {{position, ECT_REG_STADR}}, slaves_.back().get_slave_address<command::FP>() });
datagrams.back().update();
} }
queue::Queue<datagram::IEcatDatagram> queue; queue::Queue<datagram::IEcatDatagram> queue;
@ -166,7 +164,7 @@ void EthEcat::set_addresses_of_slaves(uint16_t number_of_slaves, uint16_t addres
} }
do { do {
telegram_.transfer(datagrams[0]); telegram_.transfer(queue);
} while(datagrams[0].get_all_wkc() < number_of_slaves); } while(datagrams[0].get_all_wkc() < number_of_slaves);
DebugP_log((char*)"Slave addresses set\r\n"); DebugP_log((char*)"Slave addresses set\r\n");
@ -182,7 +180,6 @@ void EthEcat::get_addresses_of_slaves() {
for(EcatSlave& slave : slaves_) { for(EcatSlave& slave : slaves_) {
datagrams.emplace_back(TDatagram{ {{slave.get_slave_address<command::AP>(), ECT_REG_STADR}}, slave.get_slave_address<command::FP>() }); datagrams.emplace_back(TDatagram{ {{slave.get_slave_address<command::AP>(), ECT_REG_STADR}}, slave.get_slave_address<command::FP>() });
datagrams.back().update();
} }
queue::Queue<datagram::IEcatDatagram> queue; queue::Queue<datagram::IEcatDatagram> queue;
@ -192,7 +189,7 @@ void EthEcat::get_addresses_of_slaves() {
} }
do { do {
telegram_.transfer(datagrams[0]); telegram_.transfer(queue);
} while(datagrams[0].get_all_wkc() < number_of_slaves); } while(datagrams[0].get_all_wkc() < number_of_slaves);
for(EcatSlave& slave : slaves_) { for(EcatSlave& slave : slaves_) {

View File

@ -202,7 +202,7 @@ public:
auto queue = datagram_write + datagram_read; auto queue = datagram_write + datagram_read;
do { do {
telegram.transfer(datagram_write); telegram.transfer(queue);
} while(datagram_write.get_all_wkc() < 0x0002); } while(datagram_write.get_all_wkc() < 0x0002);
/* /*
do { do {

View File

@ -63,24 +63,24 @@ private:
bool ready_{false}; bool ready_{false};
}; };
class IPromise { class IPromise : protected queue::QueueEntity {
public:
friend class queue::Queue<IPromise>; friend class queue::Queue<IPromise>;
public:
IPromise(address::Offset offset = 0) IPromise(address::Offset offset = 0)
: offset_{offset} { } : offset_{offset} { }
/*
queue::Queue<IPromise> operator+(IPromise &next) { queue::Queue<IPromise> operator+(IPromise &next) {
return queue::Queue<IPromise>{queue_entity_, next.queue_entity_}; return queue::Queue<IPromise>{*this, next};
} }
*/
virtual void set_value(uint8_t* process_data, uint32_t len) = 0; virtual void set_value(uint8_t* process_data, uint32_t len) = 0;
protected: protected:
address::Offset offset_{0}; address::Offset offset_{0};
private: private:
queue::QueueEntity<IPromise> queue_entity_{this};
}; };
template<typename... DataTypes> template<typename... DataTypes>

View File

@ -23,36 +23,23 @@ namespace datagram {
using TEcatWkc = uint16_t; using TEcatWkc = uint16_t;
class IEcatDatagram { class IEcatDatagram : protected queue::QueueEntity {
public:
friend class queue::Queue<IEcatDatagram>; friend class queue::Queue<IEcatDatagram>;
public:
IEcatDatagram() IEcatDatagram()
: queue_entity_{this}
{ } { }
virtual ~IEcatDatagram() { }; virtual ~IEcatDatagram() { };
void update() {
queue_entity_.set_data(this);
}
IEcatDatagram* get_next() { IEcatDatagram* get_next() {
queue::QueueEntity<IEcatDatagram>* next = queue_entity_.get_next(); return static_cast<IEcatDatagram*>(get_next());
if(next == nullptr) {
//DebugP_log((char*)"No next datagram\r\n");
return nullptr;
}
return next->get_data();
} }
queue::Queue<IEcatDatagram> operator+(IEcatDatagram &next) { queue::Queue<IEcatDatagram> operator+(IEcatDatagram &next) {
//DebugP_log((char*)"Coupling first pair\r\n"); //DebugP_log((char*)"Coupling first pair\r\n");
return queue::Queue<IEcatDatagram>{queue_entity_, next.queue_entity_}; return queue::Queue<IEcatDatagram>{*this, next};
} }
virtual uint8_t* pack(uint8_t *raw) = 0; virtual uint8_t* pack(uint8_t *raw) = 0;
@ -67,20 +54,19 @@ public:
} }
TEcatWkc get_all_wkc() { TEcatWkc get_all_wkc() {
queue::QueueEntity<IEcatDatagram>* next = queue_entity_.get_next(); IEcatDatagram* next = static_cast<IEcatDatagram*>(get_next());
if(next == nullptr) { if(next == nullptr) {
return wkc_; return wkc_;
} }
return wkc_ + next->get_data()->get_all_wkc(); return wkc_ + next->get_all_wkc();
} }
protected: protected:
TEcatDgHeader header_; TEcatDgHeader header_;
TEcatWkc wkc_{0x0000}; TEcatWkc wkc_{0x0000};
queue::QueueEntity<IEcatDatagram> queue_entity_;
private: private:
}; };
@ -128,25 +114,10 @@ private:
} }
uint8_t* pack_header(uint8_t *raw) { uint8_t* pack_header(uint8_t *raw) {
uint8_t *data_raw = raw + sizeof(TEcatDgHeader);/* uint8_t *data_raw = raw + sizeof(TEcatDgHeader);
address::Station station_0{static_cast<uint16_t>(address_base + 0)};
address::Station station_1{static_cast<uint16_t>(address_base + 1)};
TDatagram datagram_0{ {{address::Position{0}, ECT_REG_STADR}}, station_0};
TDatagram datagram_1{ {{address::Position{-1}, ECT_REG_STADR}}, station_1 };
queue = datagram_0 + datagram_1;
*/
uint8_t *wkc_raw = pack_data(data_raw); // сначала упаковываем все данные для вычисления их размера uint8_t *wkc_raw = pack_data(data_raw); // сначала упаковываем все данные для вычисления их размера
uint16_t len = wkc_raw - data_raw; // вычисляем размер данных uint16_t len = wkc_raw - data_raw; // вычисляем размер данных
ec_moredatagrams more; ec_moredatagrams more = (get_next() != nullptr) ? ec_moredatagrams::EC_MOREDATAGRAMS_MORE : ec_moredatagrams::EC_MOREDATAGRAMS_LAST;
if(queue_entity_.get_next() != nullptr) {
more = ec_moredatagrams::EC_MOREDATAGRAMS_MORE;
}else{
more = ec_moredatagrams::EC_MOREDATAGRAMS_LAST;
}
TEcatDgHeader *header_ = new(raw) TEcatDgHeader{ TEcatDgHeader *header_ = new(raw) TEcatDgHeader{
command_.get_cmd(), command_.get_cmd(),
0x00, 0x00,

View File

@ -14,59 +14,49 @@ namespace free_rtos {
namespace queue { namespace queue {
template<typename DataType>
class Queue;
template<typename DataType>
class QueueEntity { class QueueEntity {
public: public:
friend class Queue<DataType>;
QueueEntity(DataType *data)
: data_{data} { }
void set_data(DataType* data) {
data_ = data;
}
DataType* get_data() {
return data_;
}
protected:
QueueEntity* get_next() { QueueEntity* get_next() {
return next_; return next_;
} }
void set_next(QueueEntity *next) {
next_ = next;
}
private: private:
DataType *data_{nullptr};
QueueEntity *next_{nullptr}; QueueEntity *next_{nullptr};
}; };
template<typename DataType> template<typename DataType>
class Queue { class Queue {
static_assert(std::is_base_of<QueueEntity, DataType>::value == true, "DataType should be derived from QueueEntity and Queue should be a friend class");
public: public:
Queue() { } Queue() { }
explicit Queue(QueueEntity<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); append(&first);
} }
Queue(QueueEntity<DataType>& first, QueueEntity<DataType>& next) { Queue(DataType& first, DataType& next) {
//DebugP_log((char*)"Constructor coupling first and next data\r\n"); //DebugP_log((char*)"Constructor coupling first and next data\r\n");
first.next_ = &next; first.set_next(&next);
append(&first, &next, 2); append(&first, &next, 2);
} }
QueueEntity<DataType>* get_first() { DataType* get_first() {
return first_; return first_;
} }
QueueEntity<DataType>* get_last() { DataType* get_last() {
return last_; return last_;
} }
@ -77,7 +67,7 @@ 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.queue_entity_); return append(&data);
} }
Queue& operator+(Queue& other) { Queue& operator+(Queue& other) {
@ -87,13 +77,13 @@ public:
} }
DataType* dequeue() { DataType* dequeue() {
QueueEntity<DataType>* first = first_; DataType* first = first_;
if(first == nullptr) { if(first == nullptr) {
return nullptr; return nullptr;
} }
first_ = first_->next_; first_ = static_cast<DataType*>(first_->get_next());
if(first_ == nullptr) { if(first_ == nullptr) {
last_ = nullptr; last_ = nullptr;
@ -101,7 +91,7 @@ public:
size_--; size_--;
return first->data_; return first;
} }
bool empty() { bool empty() {
@ -115,17 +105,17 @@ public:
} }
private: private:
QueueEntity<DataType> *first_{nullptr}; DataType *first_{nullptr};
QueueEntity<DataType> *last_{nullptr}; DataType *last_{nullptr};
size_t size_{0}; size_t size_{0};
Queue& append(QueueEntity<DataType> *other_first, QueueEntity<DataType> *other_last = nullptr, size_t other_size = 1) { Queue& append(DataType *other_first, DataType *other_last = nullptr, size_t other_size = 1) {
if(first_ == nullptr) { if(first_ == nullptr) {
first_ = other_first; first_ = other_first;
} }
if(last_ != nullptr) { if(last_ != nullptr) {
last_->next_ = other_first; last_->set_next(other_first);
} }
if(other_last == nullptr) { if(other_last == nullptr) {

View File

@ -50,7 +50,7 @@ uint8_t* EcatTelegram::pack(uint8_t *raw) {
(void)p_eth_hdr; (void)p_eth_hdr;
(void)p_hdr; (void)p_hdr;
queue::Queue<datagram::IEcatDatagram> queue = datagram_queue_; auto queue = datagram_queue_; // Копия очереди
auto next = queue.dequeue(); auto next = queue.dequeue();
/* /*
if(datagram_queue_ == nullptr) { if(datagram_queue_ == nullptr) {
@ -91,7 +91,7 @@ uint8_t* EcatTelegram::unpack(uint8_t *raw) {
return raw; return raw;
} }
queue::Queue<datagram::IEcatDatagram> queue = datagram_queue_; auto queue = datagram_queue_; // Копия очереди
auto next = queue.dequeue(); auto next = queue.dequeue();
/* /*
if(datagram_queue_ == nullptr) { if(datagram_queue_ == nullptr) {
@ -112,10 +112,7 @@ uint8_t* EcatTelegram::unpack(uint8_t *raw) {
return p_datagram_last; return p_datagram_last;
} }
void EcatTelegram::transfer(datagram::IEcatDatagram& next) { void EcatTelegram::transfer() {
datagram_queue_ + next;
//datagram_queue_ = &next;
bool stat = eth_stack_.send_pkt(port_id_, ETH_PROT_ECAT_LE, 1); bool stat = eth_stack_.send_pkt(port_id_, ETH_PROT_ECAT_LE, 1);
if(stat == false) { if(stat == false) {
@ -129,23 +126,20 @@ void EcatTelegram::transfer(datagram::IEcatDatagram& next) {
datagram_queue_.clear(); datagram_queue_.clear();
//datagram_queue_ = nullptr; //datagram_queue_ = nullptr;
} }
/*
void EcatTelegram::transfer(datagram::IEcatDatagram& next) {
datagram_queue_ + next;
//datagram_queue_ = &next;
transfer();
}
void EcatTelegram::transfer(queue::Queue<datagram::IEcatDatagram>& next) { void EcatTelegram::transfer(queue::Queue<datagram::IEcatDatagram>& next) {
datagram_queue_ + next; datagram_queue_ + next;
bool stat = eth_stack_.send_pkt(port_id_, ETH_PROT_ECAT_LE, 1); transfer();
}
if(stat == false) {
DebugP_log((char*)"telegram transfer error !\r\n");
return;
}
rx_sem_.pend();
datagram_queue_.clear();
}
*/
} }
} }

View File

@ -31,7 +31,7 @@ public:
} }
void transfer(datagram::IEcatDatagram& next); void transfer(datagram::IEcatDatagram& next);
//void transfer(queue::Queue<datagram::IEcatDatagram>& next); void transfer(queue::Queue<datagram::IEcatDatagram>& next);
private: private:
Eth& eth_; Eth& eth_;
@ -43,6 +43,8 @@ private:
queue::Queue<datagram::IEcatDatagram> datagram_queue_; queue::Queue<datagram::IEcatDatagram> datagram_queue_;
//datagram::IEcatDatagram *datagram_queue_{nullptr}; //datagram::IEcatDatagram *datagram_queue_{nullptr};
void transfer();
uint8_t* pack(uint8_t *raw); uint8_t* pack(uint8_t *raw);
uint8_t* unpack(uint8_t *raw); uint8_t* unpack(uint8_t *raw);
}; };