2 /***************************************************************************
3 * backend_thread.cpp - World Info Viewer backend thread
5 * Created: Thu April 10 22:00:08 2008
6 * Copyright 2008 Daniel Beck
8 ****************************************************************************/
10 /* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
20 * Read the full text in the LICENSE.GPL file in the doc directory.
23 #include "backend_thread.h"
24 #include <worldinfo_utils/data_container.h>
25 #include <netcomm/worldinfo/transceiver.h>
27 using namespace fawkes;
29 /** @class WorldInfoViewerBackendThread backend_thread.h <tools/worldinfo_viewer/backend_thread.h>
30 * The backend thread of the worldinfo viewer application.
35 * @param data_container pointer to the central instance of the
36 * WorldInfoDataContainer
37 * @param addr multicast address to use for worldinfo communication
39 * @param key de-/encryption key
40 * @param iv initialization vector for de-/encryption
42 WorldInfoViewerBackendThread::WorldInfoViewerBackendThread( WorldInfoDataContainer* data_container,
47 : Thread("WorldInfoViewerBackendThread")
49 m_data_container = data_container;
56 m_avahi = new AvahiThread();
59 m_resolver = new NetworkNameResolver( m_avahi );
61 m_transceiver = new WorldInfoTransceiver( WorldInfoTransceiver::MULTICAST,
67 m_transceiver->add_handler(this);
71 WorldInfoViewerBackendThread::~WorldInfoViewerBackendThread()
81 /** Access the dispatcher that is emitted whenever new data has
83 * @return reference to the dispatcher
86 WorldInfoViewerBackendThread::new_worldinfo_data()
88 return m_signal_new_worldinfo_data;
91 /** Access the dispatcher that is emitted whenever new game state data
93 * @return reference to the dispatcher
96 WorldInfoViewerBackendThread::new_gamestate_data()
98 return m_signal_new_gamestate_data;
102 WorldInfoViewerBackendThread::loop()
104 m_transceiver->flush_sequence_numbers( 10 );
105 m_transceiver->recv(true, 100);
110 WorldInfoViewerBackendThread::pose_rcvd( const char* from_host,
117 printf( "Received pose data from host %s: x=%.3f y=%.3f theta=%.3f\n",
118 from_host, x, y, theta );
119 #endif /* DEBUG_PRING */
121 m_data_container->set_robot_pose( from_host, x, y, theta, covariance );
122 m_signal_new_worldinfo_data();
126 WorldInfoViewerBackendThread::velocity_rcvd( const char* from_host,
133 printf( "Received velocity data from host %s: vx=%.3f vy=%.3f vtheta=%.3f\n",
134 from_host, vel_x, vel_y, vel_theta );
135 #endif /* DEBUG_PRINT */
137 m_data_container->set_robot_velocity( from_host, vel_x, vel_y, vel_theta,
139 m_signal_new_worldinfo_data();
143 WorldInfoViewerBackendThread::ball_pos_rcvd( const char* from_host,
145 int visibility_history,
153 { printf( "Received ball data from host %s: dist=%.3f bearing=%.3f\n",
154 from_host, dist, bearing ); }
156 { printf( "Received ball not visible from host %s\n", from_host ); }
157 #endif /* DEBUG_PRINT */
159 m_data_container->set_ball_pos( from_host, visible, visibility_history,
160 dist, bearing, slope, covariance );
161 m_signal_new_worldinfo_data();
165 WorldInfoViewerBackendThread::global_ball_pos_rcvd( const char* from_host,
167 int visibility_history,
175 { printf( "Received global ball data from host %s: x=%.3f y=%.3f\n",
178 { printf( "Received global ball not visible from host %s\n", from_host ); }
179 #endif /* DEBUG_PRINT */
180 m_data_container->set_ball_pos_global( from_host, visible,
182 x, y, z, covariance );
183 m_signal_new_worldinfo_data();
187 WorldInfoViewerBackendThread::ball_velocity_rcvd( const char* from_host,
193 m_data_container->set_ball_velocity( from_host, vel_x, vel_y, vel_z,
195 m_signal_new_worldinfo_data();
199 WorldInfoViewerBackendThread::global_ball_velocity_rcvd( const char *from_host,
207 // m_data_container->set_global_ball_velocity( from_host, vel_x, vel_y, vel_z,
209 // m_signal_new_worldinfo_data();
214 WorldInfoViewerBackendThread::opponent_pose_rcvd( const char* from_host,
220 // #ifdef DEBUG_PRINT
221 // printf("Received opponent pose data form host %s\n", from_host );
222 // #endif /* DEBUG_PRINT */
224 m_data_container->set_opponent_pos( from_host, uid, distance, angle,
226 m_signal_new_worldinfo_data();
231 WorldInfoViewerBackendThread::opponent_disapp_rcvd( const char *from_host,
234 m_data_container->opponent_disappeared( from_host, uid );
235 m_signal_new_worldinfo_data();
240 WorldInfoViewerBackendThread::gamestate_rcvd( const char* from_host,
241 unsigned int game_state,
242 worldinfo_gamestate_team_t state_team,
243 unsigned int score_cyan,
244 unsigned int score_magenta,
245 worldinfo_gamestate_team_t own_team,
246 worldinfo_gamestate_goalcolor_t own_goal_color,
247 worldinfo_gamestate_half_t half )
250 printf( "Received gamestate data from host %s\n", from_host );
251 #endif /* DEBUG_PRINT */
253 m_data_container->set_game_state( game_state, state_team,
254 score_cyan, score_magenta,
255 own_team, own_goal_color, half );
256 m_signal_new_gamestate_data();
260 WorldInfoViewerBackendThread::penalty_rcvd(const char *from_host,
262 unsigned int penalty,
263 unsigned int seconds_remaining)