2023-06-06 10:27:01 +03:00
|
|
|
/*
|
|
|
|
|
* eth_ecat_telegram.hpp
|
|
|
|
|
*
|
|
|
|
|
* Created on: Jun 5, 2023
|
|
|
|
|
* Author: algin
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_TELEGRAM_HPP_
|
|
|
|
|
#define FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_TELEGRAM_HPP_
|
|
|
|
|
|
2023-06-26 18:22:30 +03:00
|
|
|
#include "free_rtos/ethernet/eth.hpp"
|
2023-06-06 10:27:01 +03:00
|
|
|
|
2023-06-26 18:22:30 +03:00
|
|
|
#include "free_rtos/ethernet_industry/eth_ecat_datagram.hpp"
|
2023-06-06 10:27:01 +03:00
|
|
|
|
|
|
|
|
namespace free_rtos {
|
|
|
|
|
|
|
|
|
|
namespace telegram {
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
enum class EcatTelegramResult : uint16_t {
|
|
|
|
|
SUCCESS = 0,
|
|
|
|
|
BUSY,
|
2023-09-07 13:15:47 +03:00
|
|
|
WARNING_TRANSFER_ERROR,
|
2023-09-08 17:37:15 +03:00
|
|
|
WARNING_TIMEOUT_ERROR,
|
2023-09-07 13:15:47 +03:00
|
|
|
WARNING_WKC_ERROR,
|
2023-09-06 18:09:23 +03:00
|
|
|
FATAL_ERROR
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct EcatDescription {
|
|
|
|
|
const char* string;
|
|
|
|
|
const size_t length;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct EcatTelegramStatus {
|
2023-09-18 10:25:47 +03:00
|
|
|
uint16_t transfer_errors{0x0000};
|
|
|
|
|
uint16_t expected_wkc_errors{0x0000};
|
|
|
|
|
uint16_t attempts_exceeded_errors{0x0000};
|
2023-09-08 17:37:15 +03:00
|
|
|
EcatTelegramResult result = EcatTelegramResult::BUSY;
|
2023-09-06 18:09:23 +03:00
|
|
|
|
|
|
|
|
const EcatDescription& get_description() {
|
|
|
|
|
return descriptions[static_cast<size_t>(result)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
static const char SuccessString[];
|
|
|
|
|
static const char BusyString[];
|
2023-09-07 13:15:47 +03:00
|
|
|
static const char WarningTransferErrorString[];
|
2023-09-08 17:37:15 +03:00
|
|
|
static const char WarningTimeoutErrorString[];
|
2023-09-07 13:15:47 +03:00
|
|
|
static const char WarningWkcErrorString[];
|
2023-09-06 18:09:23 +03:00
|
|
|
static const char FatalErrorString[];
|
|
|
|
|
|
|
|
|
|
static const EcatDescription descriptions[];
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-06 10:27:01 +03:00
|
|
|
class EcatTelegram : public Handler {
|
|
|
|
|
public:
|
|
|
|
|
EcatTelegram(Eth& eth)
|
|
|
|
|
: eth_{eth}
|
2023-06-29 13:06:59 +03:00
|
|
|
, tx_flow_{*eth.getTxFlowPtr()}
|
2023-06-08 12:27:49 +03:00
|
|
|
, eth_stack_{*eth.getEthStackPtr()} { }
|
2023-06-06 10:27:01 +03:00
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
const EcatTelegramStatus& get_status() {
|
|
|
|
|
return status_;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 10:27:01 +03:00
|
|
|
virtual int32_t Process(uint8_t *p_data, uint32_t len) override;
|
2023-06-08 12:27:49 +03:00
|
|
|
virtual uint32_t Sender(uint8_t *p_data, size_t scatter_segment) override;
|
2023-06-06 10:27:01 +03:00
|
|
|
|
|
|
|
|
void init(TEthMacPorts port_id) {
|
|
|
|
|
port_id_ = port_id;
|
2023-06-08 12:27:49 +03:00
|
|
|
eth_.getEthStackPtr()->Register(ETH_PROT_ECAT_LE, this);
|
2023-06-06 10:27:01 +03:00
|
|
|
}
|
|
|
|
|
|
2023-09-06 18:09:23 +03:00
|
|
|
bool transfer(datagram::IEcatDatagram& next);
|
|
|
|
|
bool transfer(queue::Queue<datagram::IEcatDatagram>& next);
|
2023-06-06 10:27:01 +03:00
|
|
|
|
|
|
|
|
private:
|
2023-09-20 15:52:57 +03:00
|
|
|
static constexpr uint32_t connection_timeout_ticks_ = 200;
|
2023-09-18 10:25:47 +03:00
|
|
|
static constexpr uint32_t max_transfer_attempts_ = 2;
|
2023-09-06 18:09:23 +03:00
|
|
|
|
2023-06-06 10:27:01 +03:00
|
|
|
Eth& eth_;
|
2023-06-29 13:06:59 +03:00
|
|
|
EthTxFlowIface& tx_flow_;
|
2023-06-08 12:27:49 +03:00
|
|
|
EthStackIface& eth_stack_;
|
2023-06-06 10:27:01 +03:00
|
|
|
TEthMacPorts port_id_;
|
|
|
|
|
|
|
|
|
|
free_rtos::Semaphore rx_sem_;
|
|
|
|
|
|
2023-06-15 15:16:51 +03:00
|
|
|
queue::Queue<datagram::IEcatDatagram> datagram_queue_;
|
2023-06-16 10:18:13 +03:00
|
|
|
//datagram::IEcatDatagram *datagram_queue_{nullptr};
|
2023-06-06 10:27:01 +03:00
|
|
|
|
2023-09-18 10:25:47 +03:00
|
|
|
EcatTelegramStatus status_{0x0000, 0x0000, 0x0000, EcatTelegramResult::BUSY};
|
2023-09-06 18:09:23 +03:00
|
|
|
|
|
|
|
|
bool transfer();
|
2023-06-16 13:01:24 +03:00
|
|
|
|
2023-06-08 12:27:49 +03:00
|
|
|
uint8_t* pack(uint8_t *raw);
|
|
|
|
|
uint8_t* unpack(uint8_t *raw);
|
2023-06-06 10:27:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* FREE_RTOS_ETHERNET_INDUSTRY_ETH_ECAT_TELEGRAM_HPP_ */
|