PhotonVision C++
v2026.0.1-beta
Loading...
Searching...
No Matches
TimeSyncServer.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) Photon Vision.
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16
*/
17
18
#pragma once
19
20
#include <atomic>
21
#include <chrono>
22
#include <cstdlib>
23
#include <cstring>
24
#include <ctime>
25
#include <functional>
26
#include <iostream>
27
#include <memory>
28
#include <mutex>
29
#include <string>
30
#include <thread>
31
32
#include <wpi/Logger.h>
33
#include <wpi/print.h>
34
#include <wpi/struct/Struct.h>
35
#include <wpinet/EventLoopRunner.h>
36
#include <wpinet/UDPClient.h>
37
#include <wpinet/uv/Buffer.h>
38
#include <wpinet/uv/Timer.h>
39
#include <wpinet/uv/Udp.h>
40
41
#include "
TimeSyncStructs.h
"
42
#include "ntcore_cpp.h"
43
44
namespace
wpi
{
45
namespace
tsp {
46
47
class
TimeSyncServer
{
48
using
SharedUdpPtr = std::shared_ptr<uv::Udp>;
49
50
EventLoopRunner m_loopRunner{};
51
52
wpi::Logger m_logger;
53
std::function<uint64_t()> m_timeProvider;
54
SharedUdpPtr m_udp;
55
int
m_port;
56
57
std::thread m_listener;
58
59
private
:
60
void
UdpCallback(uv::Buffer& buf,
size_t
nbytes,
const
sockaddr& sender,
61
unsigned
flags);
62
63
public
:
64
explicit
TimeSyncServer
(
int
port = 5810);
65
66
/**
67
* Start listening for pings
68
*/
69
void
Start
();
70
/**
71
* Stop our loop runner. After stopping, we cannot restart.
72
*/
73
void
Stop
();
74
};
75
76
}
// namespace tsp
77
}
// namespace wpi
TimeSyncStructs.h
wpi::tsp::TimeSyncServer
Definition
TimeSyncServer.h:47
wpi::tsp::TimeSyncServer::Stop
void Stop()
Stop our loop runner.
wpi::tsp::TimeSyncServer::TimeSyncServer
TimeSyncServer(int port=5810)
wpi::tsp::TimeSyncServer::Start
void Start()
Start listening for pings.
wpi
Definition
TimeSyncServer.h:44
net
TimeSyncServer.h
Generated by
1.12.0