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 #ifdef OPENR_ETHERSTAT // se e' attivata la stampa delle statistiche di rete
00018 #include <ERA201D1.h>
00019 #endif
00020
00021 using namespace std;
00023 const char* const AIBONET="/MS/OPEN-R/MW/CONF/AIBONET.CFG";
00027 class Telepati : public OObject {
00028 public:
00029
00031 Telepati();
00033 virtual ~Telepati();
00034
00035 OSubject* subject[numOfSubject];
00036 OObserver* observer[numOfObserver];
00039 virtual OStatus DoInit (const OSystemEvent& event);
00041 virtual OStatus DoStart (const OSystemEvent& event);
00043 virtual OStatus DoStop (const OSystemEvent& event);
00045 virtual OStatus DoDestroy(const OSystemEvent& event);
00046
00047
00048 void SendCont(ANTENVMSG msg);
00050 void ReceiveCont(ANTENVMSG msg);
00051 void TimerEnd(void* msg);
00052 void BoneTimerEnd(void* msg);
00053 void EtherStat(void* msg);
00055 void SendNotify(const ONotifyEvent& event);
00057 static const Port TELEPATI_PORT= 3030;
00058 static const int TELEPATI_BUFFER_SIZE= 512;
00059 static const longword TELEPATI_ACK_TIME= 1200;
00060 static const longword TELEPATI_BONE_TIME= 5;
00062 private:
00063 #ifdef OPENR_DEBUG
00064 unsigned int sendMessage;
00065 unsigned int recvMessage;
00066 #endif
00067 #ifdef OPENR_ETHERSTAT
00068 void PrintWLANStatistics(const EtherDriverGetWLANStatisticsMsg& msg);
00069 void PrintWLANSettings(const EtherDriverGetWLANSettingsMsg& msg);
00070 void PrintEtherStatistics(const EtherDriverGetStatisticsMsg& msg);
00071 #endif
00072 vector<IPAddress> aiboIp;
00073 UDPRecvConnection recvConnection;
00074 UDPSendConnection sendConnection;
00075 aiboState* aiboIpActive;
00076 unsigned short* expectedSerial;
00077 int numaibo;
00078 queue<TelepatiPkg*> sendQueue;
00079 vector<TelepatiPkg*> ackWaitingMsg;
00080
00081 antStackRef ipstackRef;
00082
00083 static const size_t LINEBUFFERSIZE= 256;
00084
00085 struct ackIdentify{
00086 unsigned short serial;
00087 int aibo;
00088 };
00089
00090 OStatus parseIpConfigFile();
00091 OStatus initConnections();
00092 OStatus initRecvBuffer();
00093 OStatus initRecvUdpEndpoint();
00094 OStatus initRecvBind();
00095
00096 OStatus initSendBuffer();
00097 OStatus initSendUdpEndpoint();
00098 OStatus initSendBind();
00099
00100 void send(TelepatiPkg* msg);
00101 void receive();
00102
00103
00104 inline void sendHyMsg(int i){
00105 OSYSDEBUG(("Telepati::sendHyMsg(%d)\n",i));
00106 send(new HyPkg(i));
00107 #ifdef TELEPATI_POLLING
00108 aiboIpActive[i]= (aiboIpActive[i] == ACTIVE ? WAITINGREPLY : aiboIpActive[i]);
00109 #endif
00110 };
00111
00112
00113 inline void sendHyReplyMsg(int i){
00114 OSYSDEBUG(("Telepati::sendHyReplyMsg(%d)\n",i));
00115 send(new HyReplyPkg(i));
00116 };
00117
00118 inline void sendByeMsg(int i){
00119 OSYSDEBUG(("Telepati::sendByeMsg(%d)\n",i));
00120 send(new ByePkg(i));
00121 };
00122
00123 void sendAiboInfoMsg();
00124
00125 int aiboFromIp(const IPAddress& ip) const;
00126 void checkQueue();
00127 IPAddress* retrieveMyIp();
00128 bool setAiboIpActive(int aibo, aiboState newVal);
00129 void eraseFromAckWaitingMsg(unsigned short serial, int aibo);
00130 };
00131
00132 #endif //Telepati_h_DEFINED