dev(UML-1780): Добавлен тест соединения с помощью NOP пакетов. Относительно стабильный.

This commit is contained in:
algin 2023-10-04 10:33:21 +03:00
parent d2c09001a2
commit d496671282
5 changed files with 42 additions and 15 deletions

View File

@ -50,18 +50,18 @@ bool EthEcat::set_slaves_to_default() {
/* reset CRC counters */
std::array<uint8_t, 8> c_data_out;
c_data_out.fill(0x00);
datagram::EcatDatagram<command::BWR, std::array<uint8_t, 8>> c{ {{broadcast, ECT_REG_RXERR}}, expected_wkc, c_data_out };
c_data_out.fill(0x00);
/* reset FMMU's */
std::array<uint8_t, 16*3> d_data_out;
d_data_out.fill(0x00);
datagram::EcatDatagram<command::BWR, std::array<uint8_t, 16*3>> d{ {{broadcast, ECT_REG_FMMU0}}, expected_wkc, d_data_out };
d_data_out.fill(0x00);
/* reset SyncM */
std::array<uint8_t, 8*4> e_data_out;
e_data_out.fill(0x00);
datagram::EcatDatagram<command::BWR, std::array<uint8_t, 8*4>> e{ {{broadcast, ECT_REG_SM0}}, expected_wkc, e_data_out };
e_data_out.fill(0x00);
/* reset activation register */
uint8_t f_data_out{0x00};
@ -69,8 +69,8 @@ bool EthEcat::set_slaves_to_default() {
/* reset system time+ofs */
std::array<uint8_t, 4> g_data_out;
g_data_out.fill(0x00);
datagram::EcatDatagram<command::BWR, std::array<uint8_t, 4>> g{ {{broadcast, ECT_REG_DCSYSTIME}}, expected_wkc, g_data_out };
g_data_out.fill(0x00);
/* DC speedstart */
uint16_t h_data_out{0x1000};
@ -214,6 +214,25 @@ bool EthEcat::get_addresses_of_slaves() {
return status;
}
bool EthEcat::connection_test() {
const datagram::TEcatWkc expected_wkc = 0;
bool status;
std::array<uint8_t, 110> test_data_out;
datagram::EcatDatagram<command::NOP, std::array<uint8_t, 110>> datagram{ {{0x0000, 0x0000}}, expected_wkc, test_data_out };
test_data_out.fill(0x00);
while(1) {
status = telegram_.transfer(datagram);
if(status != true) {
break;
}
}
return status;
}
bool EthEcat::config_init(uint16_t address_base) {
uint16_t number_of_slaves;
bool status;
@ -247,7 +266,15 @@ bool EthEcat::config_init(uint16_t address_base) {
if(status != true) {
return status;
}
/*
DebugP_log((char*)"Starting connection test...\r\n");
status = connection_test();
if(status != true) {
return status;
}
*/
return status;
}
@ -295,8 +322,6 @@ bool EthEcat::safeop_to_op() {
uint16_t zero{0x00000000};
bool status;
ecat_timer_.Start();
process_sem_.post();
if(init_sem_.pend(process_timeout_ticks_) != SystemP_SUCCESS) {
DebugP_log((char*)"Process task timeout !\r\n");

View File

@ -188,6 +188,7 @@ public:
uint16_t slaves_detecting();
bool set_addresses_of_slaves(uint16_t number_of_slaves, uint16_t address_base);
bool get_addresses_of_slaves();
bool connection_test();
bool config_init(uint16_t address_base);

View File

@ -104,14 +104,15 @@ class EcatCommand : public EcatCommandBase {
static_assert(std::is_base_of<DirBase, DirT>::value == true, "DirT should be derived from command::DirBase");
public:
EcatCommand(typename TypeT::TAddress&& address)
using TType = TypeT;
using TDir = DirT;
using TAddress = typename TypeT::TAddress;
EcatCommand(TAddress&& address)
: address_{address} { }
EcatCommand() { }
using TType = TypeT;
using TDir = DirT;
static constexpr uint8_t get_cmd() {
std::array<std::array<uint8_t, 4>, 4> commands = {{
{{EC_CMD_APRD, EC_CMD_APWR, EC_CMD_APRW, EC_CMD_ARMW}},
@ -137,7 +138,7 @@ public:
static constexpr bool get_skip_unpack() {
std::array<std::array<bool, 4>, 4> commands = {{
{{false, true, false, false}},
{{false, false, false, true}},
{{false, false, false, true}},
{{false, true, false, false}},
{{false, true, false, true}}
}};
@ -155,7 +156,7 @@ public:
}
private:
typename TypeT::TAddress address_;
TAddress address_;
};
/*

View File

@ -128,7 +128,7 @@ public:
~EcatDatagram() { }
virtual uint8_t* pack(uint8_t *raw, uint8_t idx) override {
if(as_expected() == true) {
if((as_expected() == true) && (command_.get_cmd() != EC_CMD_NOP)) {
return raw;
}
@ -136,7 +136,7 @@ public:
}
virtual uint8_t* unpack(uint8_t *raw, uint8_t idx) override {
if(as_expected() == true) {
if((as_expected() == true) && (command_.get_cmd() != EC_CMD_NOP)) {
return raw;
}

View File

@ -77,7 +77,7 @@ public:
private:
static constexpr uint32_t connection_timeout_ticks_ = 70;
static constexpr uint32_t max_transfer_attempts_ = 8;
static constexpr uint32_t max_transfer_attempts_ = 6;
Eth& eth_;
Timer& ecat_timer_;