C

ptp-book

A comprehensive open-source book on the Precision Time Protocol (IEEE 1588/gPTP). From thought experiments to protocol internals, LinuxPTP source code analysis, and a hands-on ptp-lite implementation (~1000 lines C). A complete guide from theory to running code.

L

Lularible

Dernière activité 23 sept. 2026
Lularible/ptp-book

216

étoiles

16

forks

1

issues ouvertes

automotivebookcembeddedgptpieee1588linuxptpprecision-time-protocolptptime-synchronizationtutorial

Ce README est souvent en anglais.

PTP技术书 — 从思想实验到协议实现

一本从思想实验到源码、从理论到动手实现的开源PTP技术书。

中文   English

🌐 English version: ptp-book (EN)。English chapters live in en/chapters/。

在线阅读

📖 在线浏览本书

实际运行效果

ptp_demo

这本书讲了什么

全书 41 节,分四章:

  • 第一章(4 节):从“你周围的一切都静止了”这个思想实验开始,讲时间的本质与同步的意义
  • 第二章(18 节):逐机制拆解 PTP 协议——BMCA 选举、四个时间戳的数学、透明时钟、硬件时间戳、安全机制
  • 第三章(13 节):走进 LinuxPTP 源码,看工业级实现如何驾驭 9 种端口状态、PI 伺服控制器怎么让时钟“追上”主时钟
  • 第四章(6 节):亲手实现一个轻量级 PTP 程序(ptp-lite,约 1000 行 C),主时钟和从时钟可以实际运行起来做同步

不需要网络协议的先修知识。第一章的四节思想实验足够让你进入状态。

快速开始

在线阅读:直接浏览 chapters/ 目录下的 Markdown 文件,按文件名顺序阅读。

推荐 VS Code + Markdown Preview Enhanced 插件,或者 Typora、Obsidian。

运行示例代码:

git clone https://github.com/Lularible/ptp-book.git
cd ptp-book/ptp_lite
make

# 终端 A
sudo ./ptp_master eth0[替换为实际网卡名]

# 终端 B
sudo ./ptp_slave eth0[替换为实际网卡名]

许可证

书籍内容:CC BY-NC-ND 4.0 · ptp-lite 源码:MIT

姊妹篇

本书是"汽车电子七部曲"系列中的一部。另外六部已发布:

致谢


如果觉得有用,点个 ⭐ 就是最好的支持。当然,如果能顺手转发给身边需要的人,那就更棒了。🚗💨

Projets similaires

Implementation of the Precision Time Protocol (PTP) in Rust

Rustclockieee1588ptp
Ppendulum-project
318 étoiles37

Develop an end-to-end hypothetical reference model, network architectures, precision time tools, performance objectives and the methods to distribute, operate, monitor time synchronization within data center and much more...

Cieee3335ntppcie
TTime-Appliances-Project
1,5 k étoiles122

A full-featured implementation of the Network Time Protocol, including NTS support.

Rustclockntpntp-client
Ppendulum-project
1,1 k étoiles93