iCub-main
Loading...
Searching...
No Matches
ethSender.cpp
Go to the documentation of this file.
1// -*- Mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3
4/*
5 * Copyright (C) 2017 iCub Facility - Istituto Italiano di Tecnologia
6 * Author: Alberto Cardellino, Marco Accame
7 * email: alberto.cardellino@iit.it, marco.accame@iit.it
8 * website: www.robotcub.org
9 * Permission is granted to copy, distribute, and/or modify this program
10 * under the terms of the GNU General Public License, version 2 or any
11 * later version published by the Free Software Foundation.
12 *
13 * A copy of the license can be found at
14 * http://www.robotcub.org/icub/license/gpl.txt
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 * Public License for more details
20*/
21
22
23// --------------------------------------------------------------------------------------------------------------------
24// - public interface
25// --------------------------------------------------------------------------------------------------------------------
26
27#include "ethSender.h"
28
29
30
31// --------------------------------------------------------------------------------------------------------------------
32// - external dependencies
33// --------------------------------------------------------------------------------------------------------------------
34
35
36//#include <yarp/os/SystemClock.h>
37#include <yarp/os/Log.h>
38#include <yarp/os/LogStream.h>
39using yarp::os::Log;
40
41#include "ethManager.h"
42
43
44// --------------------------------------------------------------------------------------------------------------------
45// - pimpl: private implementation (see scott meyers: item 22 of effective modern c++, item 31 of effective c++
46// --------------------------------------------------------------------------------------------------------------------
47
48
49
50// --------------------------------------------------------------------------------------------------------------------
51// - the class
52// --------------------------------------------------------------------------------------------------------------------
53
54
55// - class eth::EthSender
56
57// -- class EthSender
58// -- here is it code
59
60using namespace eth;
61
62EthSender::EthSender(int txrate) : PeriodicThread((double)txrate/1000.0)
63{
64 rateofthread = txrate;
65 yDebug() << "EthSender is a PeriodicThread with txrate =" << rateofthread << "ms";
66 yTrace();
67
68#ifdef NETWORK_PERFORMANCE_BENCHMARK
69 /* We would like to verify if the receiver thread is ticked(running) every 1 millisecond, with a tollerance of 0.05 millisec.
70 The m_perEvtVerifier object after 1 second, prints an istogram with values from 0 to 3 millisec with a step of 0.1 millisec
71 */
72
73 double txrate_sec=(double)txrate/1000; //txrate is in milliseconds
74 m_perEvtVerifier.init(txrate_sec, 5*txrate_sec/100, 0.0, txrate_sec+0.002, 0.0001, 1, "Sender");
75#endif
76}
77
82
83bool EthSender::config(ACE_SOCK_Dgram *pSocket, TheEthManager* _ethManager)
84{
85 yTrace();
86 send_socket = pSocket;
87 ethManager = _ethManager;
88
89 return true;
90}
91
93{
94 yTrace() << "Do some initialization here if needed";
95
96#if defined(__unix__)
102 struct sched_param thread_param;
103 thread_param.sched_priority = sched_get_priority_max(SCHED_FIFO)/2 - 1; // = 48
104 pthread_setschedparam(pthread_self(), SCHED_FIFO, &thread_param);
105#endif
106
107 return true;
108}
109
110
111
112void EthSender::run()
113{
114 // by calling this metod of ethManager, we put protection vs concurrency internal to the class.
115 // for tx we must protect the EthResource not being changed. they can be changed by a device such as
116 // embObjMotionControl etc which adds or releases its resources.
117 ethManager->Transmission();
118
119#ifdef NETWORK_PERFORMANCE_BENCHMARK
120 m_perEvtVerifier.tick(yarp::os::Time::now());
121#endif
122}
123
124
125// - end-of-file (leave a blank line after)----------------------------------------------------------------------------
126
127
128
129
130
EthSender(int txrate)
Definition ethSender.cpp:62
bool config(ACE_SOCK_Dgram *pSocket, TheEthManager *_ethManager)
Definition ethSender.cpp:83
bool threadInit()
Definition ethSender.cpp:92
bool Transmission(void)