2 /***************************************************************************
3 * transceiver.h - World Info Transceiver
5 * Created: Sun Jan 14 17:56:54 2007
6 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
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. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
24 #ifndef __NETCOMM_WORLDINFO_TRANSCEIVER_H_
25 #define __NETCOMM_WORLDINFO_TRANSCEIVER_H_
27 #include <core/exception.h>
28 #include <core/utils/lock_list.h>
30 #include <netcomm/worldinfo/handler.h>
31 #include <netcomm/worldinfo/defs.h>
32 #include <netcomm/worldinfo/messages.h>
42 class WorldInfoMessageEncryptor;
43 class WorldInfoMessageDecryptor;
44 class NetworkNameResolver;
46 class WorldInfoException : public Exception
49 WorldInfoException(const char *msg);
52 class WorldInfoTransceiver
57 MULTICAST, /**< Use multicast socket for communication */
58 BROADCAST /**< Use broadcase socket for communication */
61 WorldInfoTransceiver(SocketType socket_type,
62 const char *addr, unsigned short port,
63 const char *key, const char *iv,
64 NetworkNameResolver *resolver = NULL);
65 ~WorldInfoTransceiver();
67 void set_fatmsg_enabled(bool fatmsg_enabled);
69 void add_handler(WorldInfoHandler *h);
70 void rem_handler(WorldInfoHandler *h);
72 void set_pose(float x, float y, float theta, float *covariance);
73 void set_velocity(float vel_x, float vel_y, float vel_theta, float *covariance);
75 void set_rel_ball_pos(float dist, float bearing, float slope, float *covariance);
76 void set_rel_ball_visible(bool visible, int visibility_history);
77 void set_rel_ball_velocity(float vel_x, float vel_y, float vel_z, float *covariance);
79 void set_glob_ball_pos(float x, float y, float z, float *covariance);
80 void set_glob_ball_visible(bool visible, int visibility_history);
81 void set_glob_ball_velocity(float vel_x, float vel_y, float vel_z, float *covariance);
83 void set_gamestate(int gamestate, worldinfo_gamestate_team_t state_team);
84 void set_score(unsigned int score_cyan, unsigned int score_magenta);
85 void set_team_goal(worldinfo_gamestate_team_t our_color,
86 worldinfo_gamestate_goalcolor_t goal_color);
87 void set_half(worldinfo_gamestate_half_t half);
88 void add_penalty(unsigned int player, unsigned int penalty,
89 unsigned int seconds_remaining);
91 void clear_opponents();
92 void add_opponent(unsigned int uid, float distance, float bearing, float *covariance);
93 void add_disappeared_opponent(unsigned int uid);
96 void recv(bool block = false, unsigned int max_num_msgs = 0);
98 void set_loop(bool loop);
99 void flush_sequence_numbers(unsigned int sec);
101 void * last_sent_plain_buffer();
102 size_t last_sent_plain_buffer_size();
103 void * last_sent_crypted_buffer();
104 size_t last_sent_crypted_buffer_size();
107 void reset_outbound();
108 void crypt_outbound();
109 void append_outbound(uint16_t msg_type, void *msg, uint16_t msg_size);
114 WorldInfoMessageEncryptor *encryptor;
115 WorldInfoMessageDecryptor *decryptor;
117 NetworkNameResolver *resolver;
118 bool resolver_delete;
122 void *crypted_out_buffer;
123 void *crypted_in_buffer;
124 size_t crypt_buffer_size;
126 size_t crypted_out_bytes;
127 size_t crypted_in_bytes;
133 size_t fatmsg_bufsize;
134 worldinfo_header_t *fatmsg_header;
135 worldinfo_message_header_t *fatmsg_msgheader;
136 worldinfo_fat_message_t *fatmsg;
138 unsigned int out_seq;
141 unsigned char *outbound_buffer;
142 unsigned int outbound_bytes;
143 unsigned int outbound_num_msgs;
145 unsigned char *inbound_buffer;
146 size_t inbound_bytes;
152 float *pose_covariance;
158 float *vel_covariance;
160 bool rel_ball_changed;
161 bool rel_ball_visible;
162 int rel_ball_visibility_history;
164 float rel_ball_bearing;
165 float rel_ball_slope;
166 float *rel_ball_covariance;
168 bool rel_ball_vel_changed;
169 float rel_ball_vel_x;
170 float rel_ball_vel_y;
171 float rel_ball_vel_z;
172 float *rel_ball_vel_covariance;
174 bool glob_ball_changed;
175 bool glob_ball_visible;
176 int glob_ball_visibility_history;
180 float *glob_ball_covariance;
182 bool glob_ball_vel_changed;
183 float glob_ball_vel_x;
184 float glob_ball_vel_y;
185 float glob_ball_vel_z;
186 float *glob_ball_vel_covariance;
188 bool gamestate_changed;
189 worldinfo_gamestate_message_t gamestate_msg;
197 std::list<opponent_t> opponents;
198 std::list<opponent_t>::iterator oppit;
200 std::list<unsigned int> disappeared_opponents;
201 std::list<unsigned int>::iterator doppit;
203 std::map<unsigned int, worldinfo_penalty_message_t> penalties;
204 std::map<unsigned int, worldinfo_penalty_message_t>::iterator penit;
206 LockList<WorldInfoHandler *> handlers;
207 LockList<WorldInfoHandler *>::iterator hit;
209 // Currently we only support IPv4
210 std::map<uint32_t, unsigned int> sequence_numbers;
211 std::map<uint32_t, time_t> last_received_time;
212 std::map<uint32_t, time_t>::iterator lrtit;
215 } // end namespace fawkes