3 #ifndef __SDO_CLIENT_HPP__
4 #define __SDO_CLIENT_HPP__
12 #include "ICanSenderDelegate.hpp"
13 #include "StateObserver.hpp"
36 : id(id), cobRx(cobRx), cobTx(cobTx), logId(
"ID" + std::to_string(id)), sender(sender), stateObserver(timeout)
41 {
return cobRx + id; }
45 {
return cobTx + id; }
49 { this->sender = sender; }
52 bool notify(
const std::uint8_t * raw)
53 {
return stateObserver.
notify(raw, 8); }
69 bool upload(
const std::string & name, T * data, std::uint16_t index, std::uint8_t subindex = 0x00)
71 static_assert(std::is_integral_v<T>,
"Integral required.");
72 return uploadInternal(name, data,
sizeof(T), index, subindex);
86 template<
typename T,
typename Fn>
87 bool upload(
const std::string & name, Fn && fn, std::uint16_t index, std::uint8_t subindex = 0x00)
90 return upload(name, &data, index, subindex) && (std::forward<Fn>(fn)(data),
true);
103 bool download(
const std::string & name, T data, std::uint16_t index, std::uint8_t subindex = 0x00)
105 static_assert(std::is_integral_v<T>,
"Integral required.");
106 return downloadInternal(name, &data,
sizeof(T), index, subindex);
117 bool upload(
const std::string & name, std::string & s, std::uint16_t index, std::uint8_t subindex = 0x00);
129 template<
typename Fn>
130 bool upload(
const std::string & name, Fn && fn, std::uint16_t index, std::uint8_t subindex = 0x00)
133 return upload(name, s, index, subindex) && (std::forward<Fn>(fn)(s),
true);
144 bool download(
const std::string & name,
const std::string & s, std::uint16_t index, std::uint8_t subindex = 0x00);
147 bool download(
const std::string & name,
const char * s, std::uint16_t index, std::uint8_t subindex = 0x00)
148 {
return download(name, std::string(s), index, subindex); }
151 bool send(
const std::uint8_t * msg);
152 bool uploadInternal(
const std::string & name,
void * data, std::uint32_t size, std::uint16_t index, std::uint8_t subindex);
153 bool downloadInternal(
const std::string & name,
const void * data, std::uint32_t size, std::uint16_t index, std::uint8_t subindex);
154 bool performTransfer(
const std::string & name,
const std::uint8_t * req, std::uint8_t * resp);
Implementation-agnostic consumer for TX CAN transfers.
Definition: ICanSenderDelegate.hpp:22
Representation of SDO client protocol.
Definition: SdoClient.hpp:32
std::uint16_t getCobIdRx() const
Retrieve COB ID of SDO packages received by the drive.
Definition: SdoClient.hpp:40
std::uint16_t getCobIdTx() const
Retrieve COB ID of SDO packages sent by the drive.
Definition: SdoClient.hpp:44
bool download(const std::string &name, const char *s, std::uint16_t index, std::uint8_t subindex=0x00)
String literal overload, overrides templated variant.
Definition: SdoClient.hpp:147
void configureSender(ICanSenderDelegate *sender)
Configure CAN sender delegate handle.
Definition: SdoClient.hpp:48
bool upload(const std::string &name, Fn &&fn, std::uint16_t index, std::uint8_t subindex=0x00)
Request an SDO package from the drive with callback, only integral types.
Definition: SdoClient.hpp:87
bool download(const std::string &name, T data, std::uint16_t index, std::uint8_t subindex=0x00)
Send an SDO package to the drive, only integral types.
Definition: SdoClient.hpp:103
bool notify(const std::uint8_t *raw)
Notify observers on an SDO package sent by the drive.
Definition: SdoClient.hpp:52
bool ping()
Test whether the node is available or not.
Definition: SdoClient.cpp:103
bool upload(const std::string &name, T *data, std::uint16_t index, std::uint8_t subindex=0x00)
Request an SDO package from the drive, only integral types.
Definition: SdoClient.hpp:69
SdoClient(std::uint8_t id, std::uint16_t cobRx, std::uint16_t cobTx, double timeout, ICanSenderDelegate *sender=nullptr)
Constructor, registers CAN sender handle.
Definition: SdoClient.hpp:35
bool upload(const std::string &name, Fn &&fn, std::uint16_t index, std::uint8_t subindex=0x00)
Request an SDO package from the drive with callback, only string type.
Definition: SdoClient.hpp:130
Type state observer for unsigned char arrays.
Definition: StateObserver.hpp:142
bool notify(const std::uint8_t *raw, std::size_t len)
Wakes up a waiting thread.
Definition: StateObserver.hpp:151
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6