9#include "mechanism/protobuf/motor/advrf/advrf_pdo.h"
10#include "mechanism/protobuf/motor/cia402/cia402_pdo.h"
11#include "mechanism/protobuf/imu/imu_pdo.h"
12#include "mechanism/protobuf/ft/ft_pdo.h"
13#include "mechanism/protobuf/pow/pow_pdo.h"
14#include "mechanism/protobuf/valve/valve_pdo.h"
15#include "mechanism/protobuf/pump/pump_pdo.h"
16#include "mechanism/protobuf/gripper/gripper_pdo.h"
18namespace iit::ecat::detail {
19 inline std::map<uint32_t, std::string> build_ec_map(
const std::string& device_type){
20 std::map<uint32_t, std::string> result;
22 for (
const auto& [key, value] : iit::ecat::esc_type_map) {
23 if (value.find(device_type) != std::string::npos) {
24 std::string device = value;
26 if (device ==
"Motor")
27 device =
"ADVRF_Motor";
36inline const std::map<uint32_t,std::string>& ec_motors(){
37 static const auto instance = iit::ecat::detail::build_ec_map(
"Motor");
41inline const std::map<uint32_t,std::string>& ec_valves(){
42 static const auto instance = iit::ecat::detail::build_ec_map(
"Valve");
46inline const std::map<uint32_t,std::string>& ec_pumps(){
47 static const auto instance = iit::ecat::detail::build_ec_map(
"Hpu");
51inline const std::map<uint32_t,std::string>& ec_grippers(){
52 static const auto instance = iit::ecat::detail::build_ec_map(
"Gripper");
56using MotorStatusMap = std::map<int32_t, MotorPdoRx::pdo_t>;
57using MotorStatus= std::vector<MotorPdoRx::pdo_t>;
58using MotorReferenceMap= std::map<int32_t, MotorPdoTx::pdo_t>;
60using PwrStatusMap= std::map<int32_t, PowPdoRx::pdo_t>;
61using PwrStatus= std::vector<PowPdoRx::pdo_t>;
62using PwrReferenceMap= std::map<int32_t, PowPdoTx::pdo_t>;
64using FtStatusMap= std::map<int32_t, FtPdoRx::pdo_t>;
65using FtStatus= std::vector<FtPdoRx::pdo_t>;
67using ImuStatusMap= std::map<int32_t, ImuPdoRx::pdo_t>;
68using ImuStatus= std::vector<ImuPdoRx::pdo_t>;
69using ImuReferenceMap= std::map<int32_t, ImuPdoTx::pdo_t>;
71using ValveStatusMap= std::map<int32_t, ValvePdoRx::pdo_t>;
72using ValveStatus= std::vector<ValvePdoRx::pdo_t>;
73using ValveReferenceMap= std::map<int32_t, ValvePdoTx::pdo_t>;
75using PumpStatusMap = std::map<int32_t, PumpPdoRx::pdo_t>;
76using PumpStatus= std::vector<PumpPdoRx::pdo_t>;
77using PumpReferenceMap= std::map<int32_t, PumpPdoTx::pdo_t >;
79using GripperStatusMap= std::map<int32_t, GripperPdoRx::pdo_t>;
80using GripperStatus= std::vector<GripperPdoRx::pdo_t>;
81using GripperReferenceMap= std::map<int32_t, GripperPdoTx::pdo_t >;
84using DST = std::vector<std::tuple<int32_t, int32_t, std::vector<float>>>;
87using RD_SDO = std::vector<std::string>;
88using WR_SDO = std::vector<std::tuple<std::string, std::string>>;
89using RR_SDOS = std::map<std::string, std::string>;
90using SRD_SDO = std::map<uint32_t, RR_SDOS>;
93using PAC = std::vector<std::tuple<int32_t, int32_t>>;
96using SSI = std::vector<std::tuple<int32_t, int32_t, int32_t>>;
98enum class RefFlags : uint32_t
101 FLAG_MULTI_REF = 1 << 0,
102 FLAG_LAST_REF = 1 << 1,
105enum ClientCmdType { STOP, START};
107enum class ClientStatusEnum : uint32_t
113 DEVICES_MAPPED = 1 << 3,
114 DEVICES_STARTED = 1 << 4,
115 DEVICES_CTRL = 1 << 5,
116 DEVICES_STOPPED = 1 << 6,
121constexpr auto to_underlying_enum(E e)
noexcept
123 return static_cast<std::underlying_type_t<E>
>(e);
127enum class PdoAuxCmdTypeEnum : int32_t
146 static_assert(ATOMIC_INT_LOCK_FREE == 2,
147 "Target must provide always-lock-free integer atomics");
150 SpscValue() =
default;
152 explicit SpscValue(std::size_t size)
160 void resize(std::size_t size)
162 for (
auto& buffer : _buffers)
167 _middle.store(2, std::memory_order_relaxed);
171 void write(
const T& value)
173 _buffers[_writer] = value;
175 const unsigned previous = _middle.exchange(
176 _writer | dirty_bit, std::memory_order_acq_rel);
178 _writer = previous & index_mask;
182 template <
typename Func>
183 bool consume(Func&& callback)
185 if (!(_middle.load(std::memory_order_relaxed) & dirty_bit))
188 const unsigned previous = _middle.exchange(
189 _reader, std::memory_order_acq_rel);
191 _reader = previous & index_mask;
193 const T& value = _buffers[_reader];
202 if (!(_middle.load(std::memory_order_relaxed) & dirty_bit))
205 const unsigned previous = _middle.exchange(
206 _reader, std::memory_order_acq_rel);
208 _reader = previous & index_mask;
209 value = _buffers[_reader];
214 static constexpr unsigned dirty_bit = 4;
215 static constexpr unsigned index_mask = 3;
219 unsigned _writer = 0;
220 unsigned _reader = 1;
221 std::atomic<unsigned> _middle{2};