PhotonVision C++
dev-v2025.0.0-beta-8-2-gbd1c5c03
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 <wpinet/EventLoopRunner.h>
21
#include <wpinet/UDPClient.h>
22
#include <wpinet/uv/Buffer.h>
23
#include <wpinet/uv/Timer.h>
24
#include <wpinet/uv/Udp.h>
25
26
#include <atomic>
27
#include <chrono>
28
#include <cstdlib>
29
#include <cstring>
30
#include <ctime>
31
#include <functional>
32
#include <iostream>
33
#include <memory>
34
#include <mutex>
35
#include <string>
36
#include <thread>
37
38
#include <wpi/Logger.h>
39
#include <wpi/print.h>
40
#include <wpi/struct/Struct.h>
41
42
#include "
TimeSyncStructs.h
"
43
#include "ntcore_cpp.h"
44
45
namespace
wpi
{
46
namespace
tsp {
47
48
class
TimeSyncServer
{
49
using
SharedUdpPtr = std::shared_ptr<uv::Udp>;
50
51
EventLoopRunner m_loopRunner{};
52
53
wpi::Logger m_logger;
54
std::function<uint64_t()> m_timeProvider;
55
SharedUdpPtr m_udp;
56
int
m_port;
57
58
std::thread m_listener;
59
60
private
:
61
void
UdpCallback(uv::Buffer& buf,
size_t
nbytes,
const
sockaddr& sender,
62
unsigned
flags);
63
64
public
:
65
explicit
TimeSyncServer
(
int
port = 5810);
66
67
/**
68
* Start listening for pings
69
*/
70
void
Start
();
71
/**
72
* Stop our loop runner. After stopping, we cannot restart.
73
*/
74
void
Stop
();
75
};
76
77
}
// namespace tsp
78
}
// namespace wpi
TimeSyncStructs.h
wpi::tsp::TimeSyncServer
Definition
TimeSyncServer.h:48
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:45
net
TimeSyncServer.h
Generated by
1.12.0