fix(UML-1582): Багфиксы
This commit is contained in:
parent
14d7e6b376
commit
bd46f29041
@ -62,7 +62,7 @@ void EthEcatPdoFMMU::wait_op() {
|
||||
void EthEcatPdoFMMU::process_write_queue(uint8_t* process_data, uint32_t len) {
|
||||
mutex_write_.lock();
|
||||
|
||||
queue::Queue<custom_promise::IPromise> queue = queue_write_;
|
||||
auto queue = queue_write_; // Копия очереди
|
||||
queue_write_.clear();
|
||||
|
||||
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) {
|
||||
mutex_read_.lock();
|
||||
|
||||
queue::Queue<custom_promise::IPromise> queue = queue_read_;
|
||||
auto queue = queue_read_; // Копия очереди
|
||||
queue_read_.clear();
|
||||
|
||||
mutex_read_.unlock();
|
||||
|
@ -28,7 +28,7 @@ void EthEcat::Init(TEthMacPorts port_id) {
|
||||
.clock_src_mux_addr = 0x430081B0u, // sysconfig
|
||||
.int_num = 152u, // sysconfig
|
||||
.int_priority = 4, // sysconfig
|
||||
.period_us = 400 ///400 microsec
|
||||
.period_us = 1000 ///400 microsec
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
do {
|
||||
telegram_.transfer(a);
|
||||
telegram_.transfer(queue);
|
||||
} while(a.get_all_wkc() < 0x0001);
|
||||
|
||||
//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};
|
||||
|
||||
slaves_.emplace_back(EcatSlave{std::move(slave_addresses)});
|
||||
|
||||
datagrams.emplace_back(TDatagram{ {{position, ECT_REG_STADR}}, slaves_.back().get_slave_address<command::FP>() });
|
||||
datagrams.back().update();
|
||||
}
|
||||
|
||||
queue::Queue<datagram::IEcatDatagram> queue;
|
||||
@ -166,7 +164,7 @@ void EthEcat::set_addresses_of_slaves(uint16_t number_of_slaves, uint16_t addres
|
||||
}
|
||||
|
||||
do {
|
||||
telegram_.transfer(datagrams[0]);
|
||||
telegram_.transfer(queue);
|
||||
} while(datagrams[0].get_all_wkc() < number_of_slaves);
|
||||
|
||||
DebugP_log((char*)"Slave addresses set\r\n");
|
||||
@ -182,7 +180,6 @@ void EthEcat::get_addresses_of_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.back().update();
|
||||
}
|
||||
|
||||
queue::Queue<datagram::IEcatDatagram> queue;
|
||||
@ -192,7 +189,7 @@ void EthEcat::get_addresses_of_slaves() {
|
||||
}
|
||||
|
||||
do {
|
||||
telegram_.transfer(datagrams[0]);
|
||||
telegram_.transfer(queue);
|
||||
} while(datagrams[0].get_all_wkc() < number_of_slaves);
|
||||
|
||||
for(EcatSlave& slave : slaves_) {
|
||||
|
@ -202,7 +202,7 @@ public:
|
||||
auto queue = datagram_write + datagram_read;
|
||||
|
||||
do {
|
||||
telegram.transfer(datagram_write);
|
||||
telegram.transfer(queue);
|
||||
} while(datagram_write.get_all_wkc() < 0x0002);
|
||||
/*
|
||||
do {
|
||||
|
@ -63,24 +63,24 @@ private:
|
||||
bool ready_{false};
|
||||
};
|
||||
|
||||
class IPromise {
|
||||
public:
|
||||
class IPromise : protected queue::QueueEntity {
|
||||
friend class queue::Queue<IPromise>;
|
||||
|
||||
public:
|
||||
IPromise(address::Offset offset = 0)
|
||||
: offset_{offset} { }
|
||||
/*
|
||||
|
||||
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;
|
||||
|
||||
protected:
|
||||
address::Offset offset_{0};
|
||||
|
||||
private:
|
||||
queue::QueueEntity<IPromise> queue_entity_{this};
|
||||
|
||||
};
|
||||
|
||||
template<typename... DataTypes>
|
||||
|
@ -23,36 +23,23 @@ namespace datagram {
|
||||
|
||||
using TEcatWkc = uint16_t;
|
||||
|
||||
class IEcatDatagram {
|
||||
public:
|
||||
class IEcatDatagram : protected queue::QueueEntity {
|
||||
friend class queue::Queue<IEcatDatagram>;
|
||||
|
||||
public:
|
||||
IEcatDatagram()
|
||||
: queue_entity_{this}
|
||||
{ }
|
||||
|
||||
virtual ~IEcatDatagram() { };
|
||||
|
||||
void update() {
|
||||
queue_entity_.set_data(this);
|
||||
}
|
||||
|
||||
IEcatDatagram* get_next() {
|
||||
queue::QueueEntity<IEcatDatagram>* next = queue_entity_.get_next();
|
||||
|
||||
if(next == nullptr) {
|
||||
//DebugP_log((char*)"No next datagram\r\n");
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return next->get_data();
|
||||
return static_cast<IEcatDatagram*>(get_next());
|
||||
}
|
||||
|
||||
queue::Queue<IEcatDatagram> operator+(IEcatDatagram &next) {
|
||||
//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;
|
||||
@ -67,20 +54,19 @@ public:
|
||||
}
|
||||
|
||||
TEcatWkc get_all_wkc() {
|
||||
queue::QueueEntity<IEcatDatagram>* next = queue_entity_.get_next();
|
||||
IEcatDatagram* next = static_cast<IEcatDatagram*>(get_next());
|
||||
|
||||
if(next == nullptr) {
|
||||
return wkc_;
|
||||
}
|
||||
|
||||
return wkc_ + next->get_data()->get_all_wkc();
|
||||
return wkc_ + next->get_all_wkc();
|
||||
}
|
||||
|
||||
protected:
|
||||
TEcatDgHeader header_;
|
||||
TEcatWkc wkc_{0x0000};
|
||||
|
||||
queue::QueueEntity<IEcatDatagram> queue_entity_;
|
||||
private:
|
||||
|
||||
};
|
||||
@ -128,25 +114,10 @@ private:
|
||||
}
|
||||
|
||||
uint8_t* pack_header(uint8_t *raw) {
|
||||
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 *data_raw = raw + sizeof(TEcatDgHeader);
|
||||
uint8_t *wkc_raw = pack_data(data_raw); // сначала упаковываем все данные для вычисления их размера
|
||||
uint16_t len = wkc_raw - data_raw; // вычисляем размер данных
|
||||
ec_moredatagrams more;
|
||||
|
||||
if(queue_entity_.get_next() != nullptr) {
|
||||
more = ec_moredatagrams::EC_MOREDATAGRAMS_MORE;
|
||||
}else{
|
||||
more = ec_moredatagrams::EC_MOREDATAGRAMS_LAST;
|
||||
}
|
||||
|
||||
ec_moredatagrams more = (get_next() != nullptr) ? ec_moredatagrams::EC_MOREDATAGRAMS_MORE : ec_moredatagrams::EC_MOREDATAGRAMS_LAST;
|
||||
TEcatDgHeader *header_ = new(raw) TEcatDgHeader{
|
||||
command_.get_cmd(),
|
||||
0x00,
|
||||
|
@ -14,59 +14,49 @@ namespace free_rtos {
|
||||
|
||||
namespace queue {
|
||||
|
||||
template<typename DataType>
|
||||
class Queue;
|
||||
|
||||
template<typename DataType>
|
||||
class QueueEntity {
|
||||
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() {
|
||||
return next_;
|
||||
}
|
||||
|
||||
void set_next(QueueEntity *next) {
|
||||
next_ = next;
|
||||
}
|
||||
|
||||
private:
|
||||
DataType *data_{nullptr};
|
||||
QueueEntity *next_{nullptr};
|
||||
};
|
||||
|
||||
|
||||
template<typename DataType>
|
||||
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:
|
||||
Queue() { }
|
||||
|
||||
explicit Queue(QueueEntity<DataType>& first) {
|
||||
explicit Queue(DataType& first) {
|
||||
//DebugP_log((char*)"Constructor coupling first data\r\n");
|
||||
|
||||
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");
|
||||
|
||||
first.next_ = &next;
|
||||
first.set_next(&next);
|
||||
|
||||
append(&first, &next, 2);
|
||||
}
|
||||
|
||||
QueueEntity<DataType>* get_first() {
|
||||
DataType* get_first() {
|
||||
return first_;
|
||||
}
|
||||
|
||||
QueueEntity<DataType>* get_last() {
|
||||
DataType* get_last() {
|
||||
return last_;
|
||||
}
|
||||
|
||||
@ -77,7 +67,7 @@ public:
|
||||
Queue& operator+(DataType& data) {
|
||||
//DebugP_log((char*)"Coupling next data\r\n");
|
||||
|
||||
return append(&data.queue_entity_);
|
||||
return append(&data);
|
||||
}
|
||||
|
||||
Queue& operator+(Queue& other) {
|
||||
@ -87,13 +77,13 @@ public:
|
||||
}
|
||||
|
||||
DataType* dequeue() {
|
||||
QueueEntity<DataType>* first = first_;
|
||||
DataType* first = first_;
|
||||
|
||||
if(first == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
first_ = first_->next_;
|
||||
first_ = static_cast<DataType*>(first_->get_next());
|
||||
|
||||
if(first_ == nullptr) {
|
||||
last_ = nullptr;
|
||||
@ -101,7 +91,7 @@ public:
|
||||
|
||||
size_--;
|
||||
|
||||
return first->data_;
|
||||
return first;
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
@ -115,17 +105,17 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
QueueEntity<DataType> *first_{nullptr};
|
||||
QueueEntity<DataType> *last_{nullptr};
|
||||
DataType *first_{nullptr};
|
||||
DataType *last_{nullptr};
|
||||
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) {
|
||||
first_ = other_first;
|
||||
}
|
||||
|
||||
if(last_ != nullptr) {
|
||||
last_->next_ = other_first;
|
||||
last_->set_next(other_first);
|
||||
}
|
||||
|
||||
if(other_last == nullptr) {
|
||||
|
@ -50,7 +50,7 @@ uint8_t* EcatTelegram::pack(uint8_t *raw) {
|
||||
(void)p_eth_hdr;
|
||||
(void)p_hdr;
|
||||
|
||||
queue::Queue<datagram::IEcatDatagram> queue = datagram_queue_;
|
||||
auto queue = datagram_queue_; // Копия очереди
|
||||
auto next = queue.dequeue();
|
||||
/*
|
||||
if(datagram_queue_ == nullptr) {
|
||||
@ -91,7 +91,7 @@ uint8_t* EcatTelegram::unpack(uint8_t *raw) {
|
||||
return raw;
|
||||
}
|
||||
|
||||
queue::Queue<datagram::IEcatDatagram> queue = datagram_queue_;
|
||||
auto queue = datagram_queue_; // Копия очереди
|
||||
auto next = queue.dequeue();
|
||||
/*
|
||||
if(datagram_queue_ == nullptr) {
|
||||
@ -112,10 +112,7 @@ uint8_t* EcatTelegram::unpack(uint8_t *raw) {
|
||||
return p_datagram_last;
|
||||
}
|
||||
|
||||
void EcatTelegram::transfer(datagram::IEcatDatagram& next) {
|
||||
datagram_queue_ + next;
|
||||
//datagram_queue_ = &next;
|
||||
|
||||
void EcatTelegram::transfer() {
|
||||
bool stat = eth_stack_.send_pkt(port_id_, ETH_PROT_ECAT_LE, 1);
|
||||
|
||||
if(stat == false) {
|
||||
@ -129,23 +126,20 @@ void EcatTelegram::transfer(datagram::IEcatDatagram& next) {
|
||||
datagram_queue_.clear();
|
||||
//datagram_queue_ = nullptr;
|
||||
}
|
||||
/*
|
||||
|
||||
void EcatTelegram::transfer(datagram::IEcatDatagram& next) {
|
||||
datagram_queue_ + next;
|
||||
//datagram_queue_ = &next;
|
||||
|
||||
transfer();
|
||||
}
|
||||
|
||||
void EcatTelegram::transfer(queue::Queue<datagram::IEcatDatagram>& next) {
|
||||
datagram_queue_ + next;
|
||||
|
||||
bool stat = eth_stack_.send_pkt(port_id_, ETH_PROT_ECAT_LE, 1);
|
||||
|
||||
if(stat == false) {
|
||||
DebugP_log((char*)"telegram transfer error !\r\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
rx_sem_.pend();
|
||||
|
||||
datagram_queue_.clear();
|
||||
}
|
||||
*/
|
||||
transfer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
}
|
||||
|
||||
void transfer(datagram::IEcatDatagram& next);
|
||||
//void transfer(queue::Queue<datagram::IEcatDatagram>& next);
|
||||
void transfer(queue::Queue<datagram::IEcatDatagram>& next);
|
||||
|
||||
private:
|
||||
Eth& eth_;
|
||||
@ -43,6 +43,8 @@ private:
|
||||
queue::Queue<datagram::IEcatDatagram> datagram_queue_;
|
||||
//datagram::IEcatDatagram *datagram_queue_{nullptr};
|
||||
|
||||
void transfer();
|
||||
|
||||
uint8_t* pack(uint8_t *raw);
|
||||
uint8_t* unpack(uint8_t *raw);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user