transceiver.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __NETCOMM_WORLDINFO_TRANSCEIVER_H_
00025 #define __NETCOMM_WORLDINFO_TRANSCEIVER_H_
00026
00027 #include <core/exception.h>
00028 #include <core/utils/lock_list.h>
00029
00030 #include <netcomm/worldinfo/handler.h>
00031 #include <netcomm/worldinfo/defs.h>
00032 #include <netcomm/worldinfo/messages.h>
00033
00034 #include <map>
00035 #include <string>
00036 #include <cstddef>
00037 #include <ctime>
00038
00039 namespace fawkes {
00040
00041 class MulticastDatagramSocket;
00042 class WorldInfoMessageEncryptor;
00043 class WorldInfoMessageDecryptor;
00044 class NetworkNameResolver;
00045
00046 class WorldInfoException : public Exception
00047 {
00048 public:
00049 WorldInfoException(const char *msg);
00050 };
00051
00052 class WorldInfoTransceiver
00053 {
00054 public:
00055 WorldInfoTransceiver(const char *addr, unsigned short port,
00056 const char *key, const char *iv,
00057 NetworkNameResolver *resolver = NULL);
00058 ~WorldInfoTransceiver();
00059
00060 void set_fatmsg_enabled(bool fatmsg_enabled);
00061
00062 void add_handler(WorldInfoHandler *h);
00063 void rem_handler(WorldInfoHandler *h);
00064
00065 void set_pose(float x, float y, float theta, float *covariance);
00066 void set_velocity(float vel_x, float vel_y, float vel_theta, float *covariance);
00067
00068 void set_rel_ball_pos(float dist, float bearing, float slope, float *covariance);
00069 void set_rel_ball_visible(bool visible, int visibility_history);
00070 void set_rel_ball_velocity(float vel_x, float vel_y, float vel_z, float *covariance);
00071
00072 void set_glob_ball_pos(float x, float y, float z, float *covariance);
00073 void set_glob_ball_visible(bool visible, int visibility_history);
00074 void set_glob_ball_velocity(float vel_x, float vel_y, float vel_z, float *covariance);
00075
00076 void set_gamestate(int gamestate, worldinfo_gamestate_team_t state_team);
00077 void set_score(unsigned int score_cyan, unsigned int score_magenta);
00078 void set_team_goal(worldinfo_gamestate_team_t our_color,
00079 worldinfo_gamestate_goalcolor_t goal_color);
00080 void set_half(worldinfo_gamestate_half_t half);
00081 void add_penalty(unsigned int player, unsigned int penalty,
00082 unsigned int seconds_remaining);
00083
00084 void clear_opponents();
00085 void add_opponent(unsigned int uid, float distance, float bearing, float *covariance);
00086 void add_disappeared_opponent(unsigned int uid);
00087
00088 void send();
00089 void recv(bool block = false, unsigned int max_num_msgs = 0);
00090
00091 void set_loop(bool loop);
00092 void flush_sequence_numbers(unsigned int sec);
00093
00094 void * last_sent_plain_buffer();
00095 size_t last_sent_plain_buffer_size();
00096 void * last_sent_crypted_buffer();
00097 size_t last_sent_crypted_buffer_size();
00098
00099 private:
00100 void reset_outbound();
00101 void crypt_outbound();
00102 void append_outbound(uint16_t msg_type, void *msg, uint16_t msg_size);
00103
00104 MulticastDatagramSocket *s;
00105
00106 WorldInfoMessageEncryptor *encryptor;
00107 WorldInfoMessageDecryptor *decryptor;
00108
00109 NetworkNameResolver *resolver;
00110 bool resolver_delete;
00111
00112 void *in_buffer;
00113 void *out_buffer;
00114 void *crypted_out_buffer;
00115 void *crypted_in_buffer;
00116 size_t crypt_buffer_size;
00117
00118 size_t crypted_out_bytes;
00119 size_t crypted_in_bytes;
00120 char * __key;
00121 char * __iv;
00122
00123 bool fatmsg_enabled;
00124 void *fatmsg_buf;
00125 size_t fatmsg_bufsize;
00126 worldinfo_header_t *fatmsg_header;
00127 worldinfo_message_header_t *fatmsg_msgheader;
00128 worldinfo_fat_message_t *fatmsg;
00129
00130 unsigned int out_seq;
00131 unsigned int in_seq;
00132
00133 unsigned char *outbound_buffer;
00134 unsigned int outbound_bytes;
00135 unsigned int outbound_num_msgs;
00136
00137 unsigned char *inbound_buffer;
00138 size_t inbound_bytes;
00139
00140 bool pose_changed;
00141 float pose_x;
00142 float pose_y;
00143 float pose_theta;
00144 float *pose_covariance;
00145
00146 bool vel_changed;
00147 float vel_x;
00148 float vel_y;
00149 float vel_theta;
00150 float *vel_covariance;
00151
00152 bool rel_ball_changed;
00153 bool rel_ball_visible;
00154 int rel_ball_visibility_history;
00155 float rel_ball_dist;
00156 float rel_ball_bearing;
00157 float rel_ball_slope;
00158 float *rel_ball_covariance;
00159
00160 bool rel_ball_vel_changed;
00161 float rel_ball_vel_x;
00162 float rel_ball_vel_y;
00163 float rel_ball_vel_z;
00164 float *rel_ball_vel_covariance;
00165
00166 bool glob_ball_changed;
00167 bool glob_ball_visible;
00168 int glob_ball_visibility_history;
00169 float glob_ball_x;
00170 float glob_ball_y;
00171 float glob_ball_z;
00172 float *glob_ball_covariance;
00173
00174 bool glob_ball_vel_changed;
00175 float glob_ball_vel_x;
00176 float glob_ball_vel_y;
00177 float glob_ball_vel_z;
00178 float *glob_ball_vel_covariance;
00179
00180 bool gamestate_changed;
00181 worldinfo_gamestate_message_t gamestate_msg;
00182
00183 typedef struct {
00184 uint32_t uid;
00185 float distance;
00186 float bearing;
00187 float *covariance;
00188 } opponent_t;
00189 std::list<opponent_t> opponents;
00190 std::list<opponent_t>::iterator oppit;
00191
00192 std::list<unsigned int> disappeared_opponents;
00193 std::list<unsigned int>::iterator doppit;
00194
00195 std::map<unsigned int, worldinfo_penalty_message_t> penalties;
00196 std::map<unsigned int, worldinfo_penalty_message_t>::iterator penit;
00197
00198 LockList<WorldInfoHandler *> handlers;
00199 LockList<WorldInfoHandler *>::iterator hit;
00200
00201
00202 std::map<uint32_t, unsigned int> sequence_numbers;
00203 std::map<uint32_t, time_t> last_received_time;
00204 std::map<uint32_t, time_t>::iterator lrtit;
00205 };
00206
00207 }
00208
00209
00210 #endif