1 #ifndef ORG_EEROS_CONTROL_SOCKETDATA_HPP_ 2 #define ORG_EEROS_CONTROL_SOCKETDATA_HPP_ 14 template <
typename SigInType,
typename SigOutType,
typename Enable =
void >
17 template <
typename SigInType,
typename SigOutType>
19 typename
std::enable_if<std::is_compound<SigInType>::value && std::is_compound<SigOutType>::value>::type>
20 :
public Block1i1o<SigInType, SigOutType> {
22 SocketData(std::string serverIP, uint16_t port,
double period = 0.01,
double timeout = 1.0) {
25 isServer = serverIP.empty();
32 ~SocketData() {
if (isServer) server->stop();
else client->stop();}
38 std::array<
SigOutValueType,
sizeof(SigOutType) /
sizeof(SigOutValueType)>& getData = server->getReceiveBuffer();
39 for (
int i = 0; i < bufOutLen; i++) output(i) = getData[i];
41 std::array<
SigOutValueType,
sizeof(SigOutType) /
sizeof(SigOutValueType)>& getData = client->getReceiveBuffer();
42 for (
int i = 0; i < bufOutLen; i++) output(i) = getData[i];
47 if (isServer) server->setSendBuffer(sendData);
48 else client->setSendBuffer(sendData);
57 if (isServer)
return server->newData;
else return client->newData;
61 if (isServer) server->newData =
false;
else client->newData =
false;
64 template <
typename X,
typename Y>
65 friend std::ostream& operator<<(std::ostream& os, SocketData<X,Y>& s);
72 std::array<SigInValueType,
sizeof(SigInType) /
sizeof(SigInValueType)>
sendData;
77 template <
typename SigInType,
typename SigOutType >
79 typename
std::enable_if<std::is_arithmetic<SigInType>::value && std::is_compound<SigOutType>::value>::type>
80 :
public Block1i1o<SigInType, SigOutType> {
82 SocketData(std::string serverIP, uint16_t port,
double period = 0.01,
double timeout = 1.0) {
84 bufOutLen =
sizeof(SigOutType) /
sizeof(SigOutValueType);
85 isServer = serverIP.empty();
87 server =
new eeros::sockets::SocketServer<1, SigInType,
sizeof(SigOutType) /
sizeof(SigOutValueType), SigOutValueType>(port, period, timeout);
89 client =
new eeros::sockets::SocketClient<1, SigInType,
sizeof(SigOutType) /
sizeof(SigOutValueType), SigOutValueType>(serverIP, port, period, timeout);
92 ~SocketData() {
if (isServer) server->stop();
else client->stop();}
98 std::array<SigOutValueType,
sizeof(SigOutType) /
sizeof(SigOutValueType)>& getData = server->getReceiveBuffer();
99 for (
int i = 0; i < bufOutLen; i++) output(i) = getData[i];
101 std::array<SigOutValueType,
sizeof(SigOutType) /
sizeof(SigOutValueType)>& getData = client->getReceiveBuffer();
102 for (
int i = 0; i < bufOutLen; i++) output(i) = getData[i];
108 if (isServer) server->setSendBuffer(sendData);
109 else client->setSendBuffer(sendData);
118 if (isServer)
return server->newData;
else return client->newData;
122 if (isServer) server->newData =
false;
else client->newData =
false;
125 template <
typename X,
typename Y>
126 friend std::ostream& operator<<(std::ostream& os, SocketData<X,Y>& s);
133 uint32_t bufInLen, bufOutLen;
137 template <
typename SigInType,
typename SigOutType >
139 typename
std::enable_if<std::is_compound<SigInType>::value && std::is_arithmetic<SigOutType>::value>::type>
140 :
public Block1i1o<SigInType, SigOutType> {
142 SocketData(std::string serverIP, uint16_t port,
double period = 0.01,
double timeout = 1.0) {
143 bufInLen =
sizeof(SigInType) /
sizeof(SigInValueType);
145 isServer = serverIP.empty();
147 server =
new eeros::sockets::SocketServer<
sizeof(SigInType) /
sizeof(SigInValueType), SigInValueType, 1, SigOutType>(port, period, timeout);
149 client =
new eeros::sockets::SocketClient<
sizeof(SigInType) /
sizeof(SigInValueType), SigInValueType, 1, SigOutType>(serverIP, port, period, timeout);
152 ~SocketData() {
if (isServer) server->stop();
else client->stop();}
158 std::array<SigOutType, 1>& getData = server->getReceiveBuffer();
161 std::array<SigOutType, 1>& getData = client->getReceiveBuffer();
168 if (isServer) server->setSendBuffer(sendData);
169 else client->setSendBuffer(sendData);
178 if (isServer)
return server->newData;
else return client->newData;
182 if (isServer) server->newData =
false;
else client->newData =
false;
185 template <
typename X,
typename Y>
186 friend std::ostream& operator<<(std::ostream& os, SocketData<X,Y>& s);
192 std::array<SigInValueType,
sizeof(SigInType) /
sizeof(SigInValueType)>
sendData;
197 template <
typename SigInType,
typename SigOutType >
199 typename
std::enable_if<std::is_arithmetic<SigInType>::value && std::is_arithmetic<SigOutType>::value>::type>
200 :
public Block1i1o<SigInType, SigOutType> {
202 SocketData(std::string serverIP, uint16_t port,
double period = 0.01,
double timeout = 1.0) {
205 isServer = serverIP.empty();
212 ~SocketData() {
if (isServer) server->stop();
else client->stop();}
218 std::array<SigOutType, 1>& getData = server->getReceiveBuffer();
221 std::array<SigOutType, 1>& getData = client->getReceiveBuffer();
228 if (isServer) server->setSendBuffer(sendData);
229 else client->setSendBuffer(sendData);
238 if (isServer)
return server->newData;
else return client->newData;
242 if (isServer) server->newData =
false;
else client->newData =
false;
245 template <
typename X,
typename Y>
246 friend std::ostream& operator<<(std::ostream& os, SocketData<X,Y>& s);
256 template <
typename SigInType,
typename SigOutType >
258 typename
std::enable_if<std::is_compound<SigInType>::value && std::is_same<SigOutType, std::nullptr_t>::value>::type>
261 SocketData(std::string serverIP, uint16_t port,
double period = 0.01,
double timeout = 1.0) {
262 bufInLen =
sizeof(SigInType) /
sizeof(SigInValueType);
263 isServer = serverIP.empty();
265 server =
new eeros::sockets::SocketServer<
sizeof(SigInType) /
sizeof(SigInValueType), SigInValueType, 0, std::nullptr_t>(port, period, timeout);
267 client =
new eeros::sockets::SocketClient<
sizeof(SigInType) /
sizeof(SigInValueType), SigInValueType, 0, std::nullptr_t>(serverIP, port, period, timeout);
270 ~SocketData() {
if (isServer) server->stop();
else client->stop();}
276 if (isServer) server->setSendBuffer(sendData);
277 else client->setSendBuffer(sendData);
281 template <
typename X,
typename Y>
282 friend std::ostream& operator<<(std::ostream& os, SocketData<X,Y>& s);
288 std::array<SigInValueType,
sizeof(SigInType) /
sizeof(SigInValueType)>
sendData;
293 template <
typename SigInType,
typename SigOutType >
295 typename
std::enable_if<std::is_same<SigInType, std::nullptr_t>::value && std::is_compound<SigOutType>::value>::type>
298 SocketData(std::string serverIP, uint16_t port,
double period = 0.01,
double timeout = 1.0) {
299 bufOutLen =
sizeof(SigOutType) /
sizeof(SigOutValueType);
300 isServer = serverIP.empty();
302 server =
new eeros::sockets::SocketServer<0, std::nullptr_t,
sizeof(SigOutType) /
sizeof(SigOutValueType), SigOutValueType>(port, period, timeout);
304 client =
new eeros::sockets::SocketClient<0, std::nullptr_t,
sizeof(SigOutType) /
sizeof(SigOutValueType), SigOutValueType>(serverIP, port, period, timeout);
307 ~SocketData() {
if (isServer) server->stop();
else client->stop();}
313 std::array<SigOutValueType,
sizeof(SigOutType) /
sizeof(SigOutValueType)>& getData = server->getReceiveBuffer();
314 for (
int i = 0; i < bufOutLen; i++) output(i) = getData[i];
316 std::array<SigOutValueType,
sizeof(SigOutType) /
sizeof(SigOutValueType)>& getData = client->getReceiveBuffer();
317 for (
int i = 0; i < bufOutLen; i++) output(i) = getData[i];
326 if (isServer)
return server->newData;
else return client->newData;
330 if (isServer) server->newData =
false;
else client->newData =
false;
333 template <
typename X,
typename Y>
334 friend std::ostream& operator<<(std::ostream& os, SocketData<X,Y>& s);
344 template <
typename SigInType,
typename SigOutType >
346 typename
std::enable_if<std::is_arithmetic<SigInType>::value && std::is_same<SigOutType, std::nullptr_t>::value>::type>
349 SocketData(std::string serverIP, uint16_t port,
double period = 0.01,
double timeout = 1.0) {
351 isServer = serverIP.empty();
358 ~SocketData() {
if (isServer) server->stop();
else client->stop();}
364 if (isServer) server->setSendBuffer(sendData);
365 else client->setSendBuffer(sendData);
369 template <
typename X,
typename Y>
370 friend std::ostream& operator<<(std::ostream& os, SocketData<X,Y>& s);
380 template <
typename SigInType,
typename SigOutType >
382 typename
std::enable_if<std::is_same<SigInType, std::nullptr_t>::value && std::is_arithmetic<SigOutType>::value>::type>
385 SocketData(std::string serverIP, uint16_t port,
double period = 0.01,
double timeout = 1.0) {
387 isServer = serverIP.empty();
394 ~SocketData() {
if (isServer) server->stop();
else client->stop();}
400 std::array<SigOutType, 1>& getData = server->getReceiveBuffer();
403 std::array<SigOutType, 1>& getData = client->getReceiveBuffer();
413 if (isServer)
return server->newData;
else return client->newData;
417 if (isServer) server->newData =
false;
else client->newData =
false;
420 template <
typename X,
typename Y>
421 friend std::ostream& operator<<(std::ostream& os, SocketData<X,Y>& s);
431 template <
typename X,
typename Y>
432 std::ostream& operator<<(std::ostream& os, SocketData<X,Y>& s) {
433 os <<
"Block socket data: '" << s.getName() <<
"'";
eeros::sockets::SocketClient< 1, SigInType, 0, std::nullptr_t > * client
Definition: SocketData.hpp:374
SigInType::value_type SigInValueType
Definition: SocketData.hpp:68
~SocketData()
Definition: SocketData.hpp:307
eeros::sockets::SocketServer< sizeof(SigInType)/sizeof(SigInValueType), SigInValueType, 0, std::nullptr_t > * server
Definition: SocketData.hpp:286
virtual void run()
Definition: SocketData.hpp:94
virtual void run()
Definition: SocketData.hpp:309
SocketData(std::string serverIP, uint16_t port, double period=0.01, double timeout=1.0)
Definition: SocketData.hpp:261
virtual void resetNew()
Definition: SocketData.hpp:121
virtual bool isNew()
Definition: SocketData.hpp:177
bool isServer
Definition: SocketData.hpp:253
virtual bool isNew()
Definition: SocketData.hpp:56
eeros::sockets::SocketClient< 0, std::nullptr_t, sizeof(SigOutType)/sizeof(SigOutValueType), SigOutValueType > * client
Definition: SocketData.hpp:339
virtual Signal< T > & getSignal()
Definition: Output.hpp:16
SigOutType::value_type SigOutValueType
Definition: SocketData.hpp:337
SocketData(std::string serverIP, uint16_t port, double period=0.01, double timeout=1.0)
Definition: SocketData.hpp:22
eeros::sockets::SocketServer< 0, std::nullptr_t, sizeof(SigOutType)/sizeof(SigOutValueType), SigOutValueType > * server
Definition: SocketData.hpp:338
bool isServer
Definition: SocketData.hpp:194
eeros::sockets::SocketClient< 1, SigInType, sizeof(SigOutType)/sizeof(SigOutValueType), SigOutValueType > * client
Definition: SocketData.hpp:131
uint32_t bufInLen
Definition: SocketData.hpp:376
uint32_t bufOutLen
Definition: SocketData.hpp:193
virtual T getValue() const
Definition: Signal.hpp:49
std::array< SigInType, 1 > sendData
Definition: SocketData.hpp:375
virtual void run()
Definition: SocketData.hpp:34
Definition: SocketData.hpp:15
SocketData(std::string serverIP, uint16_t port, double period=0.01, double timeout=1.0)
Definition: SocketData.hpp:142
virtual bool isNew()
Definition: SocketData.hpp:117
virtual void resetNew()
Definition: SocketData.hpp:181
~SocketData()
Definition: SocketData.hpp:394
SigInType::value_type SigInValueType
Definition: SocketData.hpp:189
std::array< SigInValueType, sizeof(SigInType)/sizeof(SigInValueType)> sendData
Definition: SocketData.hpp:72
Input< SigInType > in
Definition: Block1i1o.hpp:27
virtual void run()
Definition: SocketData.hpp:272
eeros::sockets::SocketServer< sizeof(SigInType)/sizeof(SigInValueType), SigInValueType, sizeof(SigOutType)/sizeof(SigOutValueType), SigOutValueType > * server
Definition: SocketData.hpp:70
uint32_t bufInLen
Definition: SocketData.hpp:289
Definition: Config.hpp:14
~SocketData()
Definition: SocketData.hpp:358
static uint64_t getTimeNs()
Definition: System_POSIX.cpp:41
virtual void run()
Definition: SocketData.hpp:214
std::array< SigInType, 1 > sendData
Definition: SocketData.hpp:132
bool isServer
Definition: SocketData.hpp:377
eeros::sockets::SocketServer< 1, SigInType, 1, SigOutType > * server
Definition: SocketData.hpp:249
eeros::sockets::SocketClient< 1, SigInType, 1, SigOutType > * client
Definition: SocketData.hpp:250
Output< SigOutType > out
Definition: Block1i1o.hpp:28
std::array< SigInValueType, sizeof(SigInType)/sizeof(SigInValueType)> sendData
Definition: SocketData.hpp:192
SocketData(std::string serverIP, uint16_t port, double period=0.01, double timeout=1.0)
Definition: SocketData.hpp:385
~SocketData()
Definition: SocketData.hpp:32
virtual void setValue(T newValue)
Definition: Signal.hpp:53
bool isServer
Definition: SocketData.hpp:74
std::array< SigInValueType, sizeof(SigInType)/sizeof(SigInValueType)> sendData
Definition: SocketData.hpp:288
SocketData(std::string serverIP, uint16_t port, double period=0.01, double timeout=1.0)
Definition: SocketData.hpp:298
bool isServer
Definition: SocketData.hpp:341
virtual bool isNew()
Definition: SocketData.hpp:237
eeros::sockets::SocketClient< 0, std::nullptr_t, 1, SigOutType > * client
Definition: SocketData.hpp:425
SocketData(std::string serverIP, uint16_t port, double period=0.01, double timeout=1.0)
Definition: SocketData.hpp:349
virtual void resetNew()
Definition: SocketData.hpp:241
virtual bool isNew()
Definition: SocketData.hpp:325
std::array< SigInType, 1 > sendData
Definition: SocketData.hpp:251
eeros::sockets::SocketServer< 0, std::nullptr_t, 1, SigOutType > * server
Definition: SocketData.hpp:424
~SocketData()
Definition: SocketData.hpp:270
SocketData(std::string serverIP, uint16_t port, double period=0.01, double timeout=1.0)
Definition: SocketData.hpp:82
uint32_t bufOutLen
Definition: SocketData.hpp:426
bool isServer
Definition: SocketData.hpp:427
virtual void setTimestamp(timestamp_t newTimestamp)
Definition: Signal.hpp:66
eeros::sockets::SocketClient< sizeof(SigInType)/sizeof(SigInValueType), SigInValueType, 0, std::nullptr_t > * client
Definition: SocketData.hpp:287
SigOutType::value_type SigOutValueType
Definition: SocketData.hpp:129
eeros::sockets::SocketServer< 1, SigInType, 0, std::nullptr_t > * server
Definition: SocketData.hpp:373
SigInType::value_type SigInValueType
Definition: SocketData.hpp:285
virtual bool isNew()
Definition: SocketData.hpp:412
bool isServer
Definition: SocketData.hpp:134
virtual void run()
Definition: SocketData.hpp:396
~SocketData()
Definition: SocketData.hpp:212
eeros::sockets::SocketClient< sizeof(SigInType)/sizeof(SigInValueType), SigInValueType, 1, SigOutType > * client
Definition: SocketData.hpp:191
SigOutType::value_type SigOutValueType
Definition: SocketData.hpp:69
Definition: Block1i1o.hpp:12
uint32_t bufOutLen
Definition: SocketData.hpp:340
virtual void resetNew()
Definition: SocketData.hpp:329
uint32_t bufOutLen
Definition: SocketData.hpp:73
virtual void run()
Definition: SocketData.hpp:360
~SocketData()
Definition: SocketData.hpp:152
Definition: SocketClient.hpp:22
~SocketData()
Definition: SocketData.hpp:92
eeros::sockets::SocketServer< 1, SigInType, sizeof(SigOutType)/sizeof(SigOutValueType), SigOutValueType > * server
Definition: SocketData.hpp:130
virtual void resetNew()
Definition: SocketData.hpp:416
virtual void run()
Definition: SocketData.hpp:154
virtual void resetNew()
Definition: SocketData.hpp:60
uint32_t bufOutLen
Definition: SocketData.hpp:252
Definition: SocketServer.hpp:24
eeros::sockets::SocketServer< sizeof(SigInType)/sizeof(SigInValueType), SigInValueType, 1, SigOutType > * server
Definition: SocketData.hpp:190
eeros::sockets::SocketClient< sizeof(SigInType)/sizeof(SigInValueType), SigInValueType, sizeof(SigOutType)/sizeof(SigOutValueType), SigOutValueType > * client
Definition: SocketData.hpp:71
uint64_t timestamp_t
Definition: types.hpp:12
bool isServer
Definition: SocketData.hpp:290
SocketData(std::string serverIP, uint16_t port, double period=0.01, double timeout=1.0)
Definition: SocketData.hpp:202