简体   繁体   English

跨网络同步计数器

[英]Synchronizing a counter across a network

I have two computers that can talk to each other over a serial connection. 我有两台可以通过串行连接相互通信的计算机。 The connection is made over a wireless network. 连接是通过无线网络进行的。 There is a variable, changing delay in communications between the two systems. 这两个系统之间的通信存在可变,变化的延迟。 On both systems I have a counter runtime that increments by 1 every ms. 在两个系统上,我都有一个计数器运行时间,该运行时间每毫秒增加1。 They both start as soon as the applications start. 它们都在应用程序启动后立即启动。 Say each computer is started at different times. 假设每台计算机在不同的时间启动。 How can I with with the serial connection synchronize the counters so that systemA.counter will equal systemB.counter and so that both counters increment at the same time (or as close as possible). 如何通过串行连接同步计数器,以使systemA.counter等于systemB.counter,并使两个计数器同时(或尽可能接近)递增。

Ideally once synchronized the counters would drift only slowly apart so that once every 3 or 4 thousand incs I could re-synchronize. 理想情况下,一旦同步,计数器将仅缓慢地漂移,以使每3或4000个incs可以重新同步一次。

I'm looking for good resources on the topic, example algorythms, example code (c/c++), anything to point me in the right direction. 我正在寻找有关该主题的良好资源,例如算法算法,示例代码(c / c ++),以及任何可以使我朝正确方向发展的方法。

Update 更新资料

This is a closed system, no internet. 这是一个封闭的系统,没有互联网。 For all intents and purposes no real protocol at all besides and open serial line over the wireless link. 出于所有目的和目的,除了通过无线链路打开串行线外,根本没有真正的协议。 That link at the moment is bluetooth, but I'm thinking over moving it to a ZigBee Mesh. 目前该链接是蓝牙,但我正在考虑将其移至ZigBee Mesh。 There are currently 2 nodes, but if I have 30 nodes all running this same application I would want them all to synchronize. 当前有2个节点,但是如果我有30个节点都在运行同一应用程序,则希望它们全部同步。 There is not client/server designation, just a couple of devices running the same program with a counter. 没有客户端/服务器名称,只有几个运行带有计数器的相同程序的设备。 I don't have access to anything like time, just this counter that increments once a millisecond and whatever algorithm I can put in place. 我无法访问任何类似时间的信息,只是该计数器每毫秒增加一次,无论我采用哪种算法都可以。

Once I can get this working, I would like to put in place a propositioning and mapping system, but to figure out distances between nodes, I need actuate timing synchronized on the devices. 一旦可以完成这项工作,我想建立一个定位和映射系统,但是要弄清楚节点之间的距离,我需要在设备上同步启动时序。

The obvious resource is NTP, which is documented for example at http://www.eecis.udel.edu/~mills/ntp.html and with links off there. 显而易见的资源是NTP,例如在http://www.eecis.udel.edu/~mills/ntp.html上有记录,并带有链接。 Basically, this uses timestamps to adjust the frequency at which local clocks run. 基本上,这使用时间戳来调整本地时钟运行的频率。 The protocol has been around for years and been the subject of continuous research - I can't see any pack of slides there which immediately makes it clear how it works. 该协议已经存在多年了,并且是不断研究的主题-我看不到那里的任何幻灯片都可以立即阐明其工作原理。 You might be better to see if there is already an NTP implementation available than to try and re-implement it yourself. 您可能会想看看是否已经有NTP实现,而不是自己尝试重新实现。

It appears (eg from searching) that there is a small industry of people working on time synchronisation algorithms, especially in the context of wireless sensor networks. 看起来(例如,通过搜索),在时间同步算法方面工作的人很少,特别是在无线传感器网络的情况下。 One jumping-off point, apart from searches, is the survey paper at http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.85.2012 - Time synchronization in sensor networks: A survey (2004) 除搜索外,一个跳出的起点是http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.85.2012上的调查论文-传感器网络中的时间同步:一项调查(2004年)

如果使用此计数器对系统中的事件进行排序,则应查看矢量时钟Lamport时间戳

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM