00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033
00034
00052 #ifndef _PHANTOMMIDDLEWARESINK_H
00053 #define _PHANTOMMIDDLEWARESINK_H
00054
00055 #include <cmath>
00056
00057 #include <OpenTracker/OpenTracker.h>
00058 #include <OpenTracker/tool/OT_ACE_Log.h>
00059 #include <phantom/MulticastSocket.hh>
00060 #include <phantom/PhantomMessageV1.hh>
00061
00070 namespace ot {
00071
00072 class PhantomMiddlewareModule;
00073
00074 class OPENTRACKER_API PhantomMiddlewareSink : public Node
00075 {
00076
00077 public:
00079
00081 int frequency;
00082 int cycle;
00083 int pid;
00084 unsigned char seq;
00085 short eid;
00086 std::string src;
00087 Phantom::Utils::MulticastSocketSender* mss;
00088
00089
00090
00091 protected:
00096 PhantomMiddlewareSink( const char* multicast_group, int frequency_, int pid_, short eid_, const std::string& src_) :
00097 Node(),
00098 frequency( frequency_ ),
00099 pid( pid_ ),
00100 cycle ( 0 ),
00101 seq ( 0 ),
00102 eid ( eid_ )
00103 {
00104 mss = new Phantom::Utils::MulticastSocketSender(multicast_group);
00105 src = src_;
00106 }
00107
00108 PhantomMiddlewareSink( const char* multicast_group, int frequency_, int pid_, short eid_):
00109 Node(),
00110 frequency( frequency_ ),
00111 pid( pid_ ),
00112 cycle ( 0 ),
00113 seq ( 0 ),
00114 eid ( eid_ )
00115 {
00116 mss = new Phantom::Utils::MulticastSocketSender(multicast_group);
00117 src = "";
00118 }
00119
00120 virtual ~PhantomMiddlewareSink() {
00121 delete mss;
00122 logPrintE("PhantomMiddlewareSink destructor\n");
00123 }
00124
00125 public:
00129 virtual int isEventGenerator()
00130 {
00131 return 1;
00132
00133 }
00134
00135 int getEventId() {
00136 return eid;
00137 }
00138
00148 virtual void onEventGenerated( Event& event, Node& generator)
00149 {
00150 cycle++;
00151 if ((cycle % frequency) == 0) {
00152 seq++;
00153 try {
00154 Phantom::PhantomMessageV1 pm(eid, seq);
00155 std::vector<float> position = event.getPosition();
00156 std::vector<float> orientation = event.getOrientation();
00157 float theta = 2.0f *atan2(orientation[1], orientation[3]);
00158 float alpha = MathUtils::Pi - theta;
00159 pm << pid;
00160 pm << (float) position[0];
00161 pm << (float) -position[2];
00162 pm << (float) position[1];
00163 pm << (float) (alpha / MathUtils::GradToRad);
00164
00165
00166
00167 (*mss) << pm;
00168 }
00169 catch (...) {}
00170 updateObservers( event );
00171 }
00172 }
00173
00174 friend class PhantomMiddlewareModule;
00175 };
00176
00177 }
00178
00179 #endif