iCub-main
boardTransceiver.hpp
Go to the documentation of this file.
1 /* Copyright (C) 2014 iCub Facility, Istituto Italiano di Tecnologia
2  * Author: Alberto Cardellino
3  * email: alberto.cardellino@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 
35 // - external dependencies --------------------------------------
36 
37 #include "FeatureInterface.h"
38 
39 #include "EoCommon.h"
40 #include "EOdeviceTransceiver.h"
41 #include "EOtransceiver.h"
42 #include "EOnvSet.h"
43 #include "EOnv.h"
44 #include "EOpacket.h"
45 #include "EoProtocol.h"
46 
47 // Boards configurations
48 
49 // ACE includes
50 #include <ace/ACE.h>
51 #include <ace/config.h>
52 #include <ace/Thread.h>
53 #include <ace/SOCK_Dgram_Bcast.h>
54 
55 #include <yarp/os/RFModule.h>
56 #include <yarp/dev/DeviceDriver.h>
57 
58 using namespace yarp::dev;
59 
60 #define RECV_BUFFER_SIZE 4000
61 
62 
63 // debug
64 void checkDataForDebug(uint8_t *data, uint16_t size);
65 void fromDouble(ACE_Time_Value &v, double x,int unit=1);
66 
67 class BoardTransceiver : public yarp::os::RFModule
68 {
69 protected:
70  eOprotBRD_t protboardnumber;
71  EOdeviceTransceiver* devtxrx;
72  EOtransceiver* transceiver;
73  eOdevicetransceiver_cfg_t devtxrxcfg;
74  EOnvSet* nvset;
75  uint32_t localipaddr;
76  uint32_t remoteipaddr;
77  uint16_t remoteipport;
78  EOpacket *p_RxPkt;
79 
81  ACE_SOCK_Dgram* UDP_socket;
82  ACE_INET_Addr pc104Addr;
83 
84  eOmn_appl_status_t* pApplStatus;
85  EOnv* oneNV;
86 
87 public:
90 
91  // yarp module methods
92  bool createSocket(ACE_INET_Addr local_addr);
93  bool configure(yarp::os::ResourceFinder &rf);
94  bool updateModule();
95 
96  // Transceiver class
97  bool init(yarp::os::Searchable &config, uint32_t localipaddr, uint32_t remoteipaddr, uint16_t ipport, uint16_t pktsize, FEAT_boardnumber_t board_n);
98 
99 
100  // and Processes it
101  virtual void onMsgReception(uint8_t *data, uint16_t size);
102 
103 protected:
104 
105  /* Ask the transceiver to get the ropframe to be sent
106  * This pointer will be modified by the getPack function to point to the TX buffer.
107  * No need to allocate memory here */
108  void getTransmit(uint8_t **data, uint16_t *size);
109 
110 
111 private:
112 
113  bool initProtocol(yarp::os::Searchable &config);
114 
115  void eoprot_override_mn(void);
116  void eoprot_override_mc(void);
117  void eoprot_override_as(void);
118  void eoprot_override_sk(void);
119 
120  bool prepareTransceiverConfig(yarp::os::Searchable &config);
121 
122 
123  const eOnvset_DEVcfg_t * getNVset_DEVcfg(yarp::os::Searchable &config);
124 
125 public:
126 
127  eOprotBRD_t get_protBRDnumber(void); // the number in range [0, max-1]
128 };
129 
130 #endif // include-guard
131 
132 
133 // - end-of-file (leave a blank line after)----------------------------------------------------------------------------
134 
135 
136 
@ data
EOtransceiver * transceiver
eOmn_appl_status_t * pApplStatus
ACE_INET_Addr pc104Addr
EOdeviceTransceiver * devtxrx
void fromDouble(ACE_Time_Value &v, double x, int unit=1)
ACE_SOCK_Dgram * UDP_socket
eOdevicetransceiver_cfg_t devtxrxcfg
eOprotBRD_t protboardnumber
void checkDataForDebug(uint8_t *data, uint16_t size)
uint8_t FEAT_boardnumber_t