annotate include/ClockSync.h @ 135:e77e2e712fbc ClockSync

To work with the ClockSync plugin
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 12 Sep 2015 20:05:55 +0100
parents
children 44d07fa9bd03
rev   line source
giuliomoro@135 1 #ifndef CLOCK_SYNC_H_INCLUDED
giuliomoro@135 2 #define CLOCK_SYNC_H_INCLUDED
giuliomoro@135 3 #include "stats.hpp"
giuliomoro@135 4 #include "UdpServer.h"
giuliomoro@135 5 #include "UdpClient.h"
giuliomoro@135 6 #include "Clock.h"
giuliomoro@135 7 #include "VirtualClock.h"
giuliomoro@135 8
giuliomoro@135 9 enum ptpMessageConsts{
giuliomoro@135 10 kSyncMessageLength=sizeof(myClock_t)+sizeof(int)
giuliomoro@135 11 };
giuliomoro@135 12 enum ptpMessageType{
giuliomoro@135 13 kSync=0,
giuliomoro@135 14 kFollowUp=1,
giuliomoro@135 15 kDelayReq=2,
giuliomoro@135 16 kDelayResp=3,
giuliomoro@135 17 kNone=4
giuliomoro@135 18 };
giuliomoro@135 19
giuliomoro@135 20 enum ptpStatus{
giuliomoro@135 21 kSyncSent,
giuliomoro@135 22 kFollowUpSent,
giuliomoro@135 23 kDelayReqSent,
giuliomoro@135 24 kDelayRespSent
giuliomoro@135 25 };
giuliomoro@135 26
giuliomoro@135 27 class ClockSync{
giuliomoro@135 28 private:
giuliomoro@135 29 MovingAverage<double> movingAverage;
giuliomoro@135 30 UdpServer server;
giuliomoro@135 31 UdpClient client;
giuliomoro@135 32 bool slave;
giuliomoro@135 33 int bufferLength;
giuliomoro@135 34 int clockSyncType;
giuliomoro@135 35 int expectedClockSyncType;
giuliomoro@135 36 myClock_t clockSyncTimestamp;
giuliomoro@135 37 myClock_t localTimestamp;
giuliomoro@135 38 myClock_t T1;
giuliomoro@135 39 myClock_t T1p;
giuliomoro@135 40 myClock_t T2;
giuliomoro@135 41 myClock_t T2p;
giuliomoro@135 42 int receiveLoopSleepUs;
giuliomoro@135 43 int receiveLoopTimeout;
giuliomoro@135 44 char buffer[kSyncMessageLength];
giuliomoro@135 45 VirtualClock *virtualClock;
giuliomoro@135 46 public:
giuliomoro@135 47 ClockSync(){};
giuliomoro@135 48 ClockSync(bool thisIsSlave, int aPort, VirtualClock &aVirtualClock);
giuliomoro@135 49 void init(bool thisIsSlave, int aPort, VirtualClock &aVirtualClock);
giuliomoro@135 50 void* getBuffer();
giuliomoro@135 51 bool isSlave();
giuliomoro@135 52 bool isMaster();
giuliomoro@135 53 int getType();
giuliomoro@135 54 myClock_t getTimestamp();
giuliomoro@135 55 void setVirtualClock(VirtualClock &aVirtualClock);
giuliomoro@135 56 void setPort(int aPort);
giuliomoro@135 57 void setType(int clockSyncType);
giuliomoro@135 58 void setTimestamp(myClock_t timestamp);
giuliomoro@135 59 void print();
giuliomoro@135 60 /**
giuliomoro@135 61 * sends a clockSync without blocking, checks results and returns the timestamp
giuliomoro@135 62 * immediately after the clockSync has been sent or -1 if there was an error or timeout expired.
giuliomoro@135 63 */
giuliomoro@135 64 myClock_t send();
giuliomoro@135 65 /**
giuliomoro@135 66 * receives a clockSync without blocking, checks results and returns the timestamp
giuliomoro@135 67 * immediately after the clockSync has been received, or -1 if there was an error
giuliomoro@135 68 * or 0 if timeout expired.
giuliomoro@135 69 */
giuliomoro@135 70 myClock_t receive();
giuliomoro@135 71 int masterSendSync();
giuliomoro@135 72 int receiveLoop();
giuliomoro@135 73 int slaveHandleMessage();
giuliomoro@135 74 int masterHandleMessage();
giuliomoro@135 75 int sendReceiveLoop();
giuliomoro@135 76 operator void*(){
giuliomoro@135 77 return getBuffer();
giuliomoro@135 78 }
giuliomoro@135 79 };
giuliomoro@135 80
giuliomoro@135 81 #endif /* CLOCK_SYNC_H_INCLUDED */