iCub-main
Loading...
Searching...
No Matches
hostTransceiver.hpp
Go to the documentation of this file.
1/* Copyright (C) 2012 iCub Facility, Istituto Italiano di Tecnologia
2 * Author: Alberto Cardellino, Marco Accame
3 * email: alberto.cardellino@iit.it, marco.accame@iit.it
4 * Permission is granted to copy, distribute, and/or modify this program
5 * under the terms of the GNU General Public License, version 2 or any
6 * later version published by the Free Software Foundation.
7 *
8 * A copy of the license can be found at
9 * http://www.robotcub.org/icub/license/gpl.txt
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 * Public License for more details
15 */
16
17// - include guard ----------------------------------------------------------------------------------------------------
18#ifndef _HOSTTRANSCEIVER_H_
19#define _HOSTTRANSCEIVER_H_
20
21
36// - external dependencies --------------------------------------------------------------------------------------------
37
38//#include "FeatureInterface.h"
39
40#include "EoCommon.h"
41#include "EOhostTransceiver.h"
42//#include "EOtransceiver.h"
43#include "EOnvSet.h"
44#include "EOnv.h"
45//#include "EOpacket.h"
46#include "EoProtocol.h"
47
48#include <mutex>
49
50#include <yarp/os/Searchable.h>
51
52
53using namespace std;
54
55
56// -- class HostTransceiver
57// -- it contains methods for communication with the ETH boards.
58
59namespace eth {
60
61 class AbstractEthResource;
62
64 {
65 public:
66 enum { maxSizeOfRXpacket = 1496 };
68
69 public:
70
73
74
75 bool init2(AbstractEthResource *owner, yarp::os::Searchable &cfgtotal, eOipv4addressing_t& localIPaddressing, eOipv4addr_t remoteIP, uint16_t rxpktsize = maxSizeOfRXpacket);
76
78
79 bool isEPsupported(const eOprot_endpoint_t ep);
80 bool isID32supported(const eOprotID32_t id32);
81
82 // reads locally.
83 bool read(const eOprotID32_t id32, void *data);
84
85 // writes locally
86 bool write(const eOprotID32_t id32, const void* data, bool forcewriteOfReadOnly);
87
88 // adds a set<> ROP to the UDP packet
89 bool addROPset(const eOprotID32_t id32, const void* data, const uint32_t signature = eo_rop_SIGNATUREdummy);
90
91 // adds a ask<> ROP to the UDP packet
92 bool addROPask(const eOprotID32_t id32, const uint32_t signature = eo_rop_SIGNATUREdummy);
93
94 // called inside the thread ethReceiver (by a call to TheEthManager::Reception() which calls ... etc.) to process incoming UDP packet.
95 // this function processes sig<> ROPs and say<> ROPs and:
96 // 1. writes the received values into internal buffered memory,
97 // 2. calls the relevant callback functions.
98 bool parseUDP(const void *data, const uint16_t size);
99
100
101 // returns the pointer of the udp packet formed inside the transceiver. if nullptr then no data to transmit.
102 const void * getUDP(size_t &size, uint16_t &numofrops);
103
104
105 bool getapplconfig(eOmn_appl_config_t &txcfg);
106
108
109 eOipv4addr_t getIPv4();
110
111 private:
112
113 eOprotBRD_t protboardnumber; // the number of board ranging from 0 upwards, in the format that the functions in EoProtocol.h expects.
114 EOhostTransceiver *hosttxrx;
115 EOtransceiver *pc104txrx;
116 eOhosttransceiver_cfg_t hosttxrxcfg;
117 EOnvSet *nvset;
118 eOipv4addr_t localipaddr;
119 eOipv4addr_t remoteipaddr;
120 char remoteipstring[20];
121 eOipv4port_t ipport;
122 EOpacket *p_RxPkt;
123 uint16_t pktsizerx;
124 uint16_t capacityofTXpacket;
125 uint16_t maxSizeOfROP;
126 eOnvset_BRDcfg_t nvsetbrdconfig;
127
128
129 private:
130
131 enum { maxNumberOfROPloadingAttempts = 5 };
132 double delayAfterROPloadingFailure;
133
134
135 private:
136
137 AbstractEthResource *_owner;
138
139 EOnv* getnvhandler(eOprotID32_t id32, EOnv* nv);
140
141 eOprotBRD_t get_protBRDnumber(void); // the number in range [0, max-1]
142
143 bool lock_transceiver(bool on);
144 std::mutex htmtx;
145
146
147 bool lock_nvs(bool on);
148 std::mutex nvmtx;
149
150
151 bool addSetROP__(const eOprotID32_t id32, const void* data, const uint32_t signature, bool writelocalrxcache = false);
152// bool addGetROP__(eOprotID32_t id32, uint32_t signature);
153
154 bool initProtocol();
155
156 void eoprot_override_mn(void);
157 void eoprot_override_mc(void);
158 void eoprot_override_as(void);
159 void eoprot_override_sk(void);
160
161 bool prepareTransceiverConfig2(yarp::os::Searchable &cfgtotal);
162
163 // set user data in the local memory, ready to be loaded by the load_occasional_rop method
164 // bool nvSetData(const EOnv *nv, const void *dat, eObool_t forceset, eOnvUpdate_t upd);
165 bool getNVvalue(EOnv *nv, uint8_t* data, uint16_t* size);
166
167 // the ip address
168 eOipv4addr_t get_remoteIPaddress(void);
169 };
170
171} // namespace eth
172
173#endif // include-guard
174
175
176// - end-of-file (leave a blank line after)----------------------------------------------------------------------------
177
178
179
@ data
bool addROPask(const eOprotID32_t id32, const uint32_t signature=eo_rop_SIGNATUREdummy)
bool write(const eOprotID32_t id32, const void *data, bool forcewriteOfReadOnly)
bool addROPset(const eOprotID32_t id32, const void *data, const uint32_t signature=eo_rop_SIGNATUREdummy)
bool isEPsupported(const eOprot_endpoint_t ep)
bool init2(AbstractEthResource *owner, yarp::os::Searchable &cfgtotal, eOipv4addressing_t &localIPaddressing, eOipv4addr_t remoteIP, uint16_t rxpktsize=maxSizeOfRXpacket)
const void * getUDP(size_t &size, uint16_t &numofrops)
bool getapplconfig(eOmn_appl_config_t &txcfg)
bool parseUDP(const void *data, const uint16_t size)
bool isID32supported(const eOprotID32_t id32)
AbstractEthResource * getResource()
bool read(const eOprotID32_t id32, void *data)
AbstractEthResource * getOwner()
grid on