view include/ClockSynchronizer.h @ 149:134bff10e561 ClockSync

Added simple one-variable one-measurement Kalman filter, Pid controller(which output is not used). Virtual clock is now much more precise and reactive for period. Still it is lagging behind a bit on the overall offset.
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 21 Sep 2015 03:12:21 +0100
parents e24c531220ee
children
line wrap: on
line source
/*
 * ClockSynchronizer.h
 *
 *  Created on: 26 Aug 2015
 *      Author: giulio
 */

#ifndef CLOCKSYNCHRONIZER_H_
#define CLOCKSYNCHRONIZER_H_

#include <BeagleRT.h>
#include <I2c_Codec.h>
#include <NetworkSend.h>
#include <native/timer.h>
extern I2c_Codec *gAudioCodec;

class ClockSynchronizer {
private:
	int localOffset;
	int remoteOffset;
	RTIME timeOffset;
	int localCounter;
	int remoteCounter;
	RTIME lastTime;
	void reset();
	static bool staticConstructed;
	static void staticConstructor();
	static float currentSamplingRate;
	static float targetSamplingRate;
	static bool threadRunning;
	static int threadWasRunning;
	static AuxiliaryTask setClockTask;
public:
	ClockSynchronizer();
	~ClockSynchronizer();
	void setup();
	void update(int aLocalCounter, int aRemoteCounter, RTIME aLastTime);
	void adjustClock();
	static void setClock();
};

#endif /* CLOCKSYNCHRONIZER_H_ */