00001 #ifndef Telepati_h_DEFINED
00002 #define Telepati_h_DEFINED
00003
00004 #include <OPENR/OObject.h>
00005 #include <OPENR/OSubject.h>
00006 #include <OPENR/OObserver.h>
00007
00008 #include "UDPConnection.h"
00009 #include <ant.h>
00010 #include <EndpointTypes.h>
00011 #include "./Packages/Packages.h"
00012
00013 #include <vector>
00014 #include <queue>
00015 #include "def.h"
00016
00017 #include "EtherStat.h"
00018
00019 using namespace std;
00021 const char* const AIBONET="/MS/OPEN-R/MW/CONF/AIBONET.CFG";
00025 class Telepati : public OObject {
00026 public:
00027
00029 Telepati();
00031 virtual ~Telepati();
00032
00033 OSubject* subject[numOfSubject];
00034 OObserver* observer[numOfObserver];
00037 virtual OStatus DoInit (const OSystemEvent& event);
00039 virtual OStatus DoStart (const OSystemEvent& event);
00041 virtual OStatus DoStop (const OSystemEvent& event);
00043 virtual OStatus DoDestroy(const OSystemEvent& event);
00044
00046 void SendCont(ANTENVMSG msg);
00048 void ReceiveCont(ANTENVMSG msg);
00050 inline void TimerEnd(void* msg){
00051 OSYSDEBUG(("#"));
00052 if(ackWaitingMsg != 0)
00053 sendViaCtrl(ackWaitingMsg);
00054 return;};
00056 void BoneTimerEnd(void* msg);
00058 void EtherStat(void* msg);
00059
00061 void SendNotify(const ONotifyEvent& event);
00062
00063 static const Port TELEPATI_PORT= 3030;
00064 static const int TELEPATI_BUFFER_SIZE= 1024;
00065 static const longword TELEPATI_ACK_TIME= 500;
00066 static const longword TELEPATI_BONE_TIME= 8;
00068 enum {
00069 DATA_CONNECTION=0,
00070 CTRL_CONNECTION=1
00071 };
00072
00073 private:
00074
00075 unsigned int sendMessage;
00076 unsigned int totalRecvMessage;
00077 unsigned int dataRecvMessage;
00078
00079 vector<IPAddress> aiboIp;
00080 UDPRecvConnection recvConnection;
00081 UDPSendConnection* sendConnection;
00082 aiboState* aiboIpActive;
00083 unsigned short* expectedSerial;
00084 int numaibo;
00085 queue<TelepatiPkg*> sendQueue;
00086 queue<TelepatiPkg*> sendCtrlQueue;
00087 TelepatiPkg* ackWaitingMsg;
00088
00089
00090 antStackRef ipstackRef;
00091 EventID ackEvent;
00092
00093 static const size_t LINEBUFFERSIZE= 256;
00094
00095 struct ackIdentify{
00096 unsigned short serial;
00097 int aibo;
00098 };
00099
00100 OStatus parseIpConfigFile();
00101 OStatus initConnections();
00102 OStatus initRecvBuffer();
00103 OStatus initRecvUdpEndpoint();
00104 OStatus initRecvBind();
00105
00106 OStatus initSendBuffer(int i);
00107 OStatus initSendUdpEndpoint(int i);
00108 OStatus initSendBind(int i);
00109
00110 void send(TelepatiPkg* msg);
00111 void sendViaCtrl(TelepatiPkg* msg);
00112 void sendViaData(TelepatiPkg* msg);
00113 void receive();
00114
00115
00116 inline void sendHiMsg(int i){
00117 OSYSDEBUG(("Telepati::sendHiMsg(%d)\n",i));
00118 send(new HiPkg(i));
00119 #ifdef TELEPATI_POLLING
00120 aiboIpActive[i]= (aiboIpActive[i] == ACTIVE ? WAITINGREPLY : aiboIpActive[i]);
00121 #endif
00122 };
00123
00124
00125 inline void sendHiReplyMsg(int i){
00126 OSYSDEBUG(("Telepati::sendHiReplyMsg(%d)\n",i));
00127 send(new HiReplyPkg(i));
00128 };
00129
00130 inline void sendByeMsg(int i){
00131 OSYSDEBUG(("Telepati::sendByeMsg(%d)\n",i));
00132 send(new ByePkg(i));
00133 };
00134
00135 void sendAiboInfoMsg();
00136
00137 int aiboFromIp(const IPAddress& ip) const;
00138 void checkQueue();
00139 void checkCtrlQueue();
00140 IPAddress* retrieveMyIp();
00141 bool setAiboIpActive(int aibo, aiboState newVal);
00142 void eraseFromAckWaitingMsg(unsigned short serial, int aibo);
00143 };
00144
00145 #endif //Telepati_h_DEFINED