PhotonVision C++ dev-v2025.0.0-beta-8-2-gbd1c5c03
Loading...
Searching...
No Matches
TimeSyncStructs.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#include <stdint.h>
20
21#include <wpi/struct/Struct.h>
22
23namespace wpi {
24namespace tsp {
25
26struct TspPing {
27 uint8_t version;
28 uint8_t message_id;
29 uint64_t client_time;
30};
31
32struct TspPong : public TspPing {
33 TspPong(TspPing ping, uint64_t servertime)
34 : TspPing{ping}, server_time{servertime} {}
35 uint64_t server_time;
36};
37
38} // namespace tsp
39} // namespace wpi
40
41template <>
42struct wpi::Struct<wpi::tsp::TspPing> {
43 static constexpr std::string_view GetTypeName() { return "TspPing"; }
44 static constexpr size_t GetSize() { return 10; }
45 static constexpr std::string_view GetSchema() {
46 return "uint8 version;uint8 message_id;uint64 client_time";
47 }
48
49 static wpi::tsp::TspPing Unpack(std::span<const uint8_t> data) {
50 return wpi::tsp::TspPing{
51 wpi::UnpackStruct<uint8_t, 0>(data),
52 wpi::UnpackStruct<uint8_t, 1>(data),
53 wpi::UnpackStruct<uint64_t, 2>(data),
54 };
55 }
56 static void Pack(std::span<uint8_t> data, const wpi::tsp::TspPing& value) {
57 wpi::PackStruct<0>(data, value.version);
58 wpi::PackStruct<1>(data, value.message_id);
59 wpi::PackStruct<2>(data, value.client_time);
60 }
61};
62
63template <>
64struct wpi::Struct<wpi::tsp::TspPong> {
65 static constexpr std::string_view GetTypeName() { return "TspPong"; }
66 static constexpr size_t GetSize() { return 18; }
67 static constexpr std::string_view GetSchema() {
68 return "uint8 version;uint8 message_id;uint64 client_time;uint64_t "
69 "server_time";
70 }
71
72 static wpi::tsp::TspPong Unpack(std::span<const uint8_t> data) {
73 return wpi::tsp::TspPong{
75 wpi::UnpackStruct<uint8_t, 0>(data),
76 wpi::UnpackStruct<uint8_t, 1>(data),
77 wpi::UnpackStruct<uint64_t, 2>(data),
78 },
79 wpi::UnpackStruct<uint64_t, 10>(data),
80 };
81 }
82 static void Pack(std::span<uint8_t> data, const wpi::tsp::TspPong& value) {
83 wpi::PackStruct<0>(data, value.version);
84 wpi::PackStruct<1>(data, value.message_id);
85 wpi::PackStruct<2>(data, value.client_time);
86 wpi::PackStruct<10>(data, value.server_time);
87 }
88};
89
90static_assert(wpi::StructSerializable<wpi::tsp::TspPong>);
91static_assert(wpi::StructSerializable<wpi::tsp::TspPing>);
Definition TimeSyncServer.h:45
static constexpr std::string_view GetSchema()
Definition TimeSyncStructs.h:45
static constexpr size_t GetSize()
Definition TimeSyncStructs.h:44
static constexpr std::string_view GetTypeName()
Definition TimeSyncStructs.h:43
static void Pack(std::span< uint8_t > data, const wpi::tsp::TspPing &value)
Definition TimeSyncStructs.h:56
static wpi::tsp::TspPing Unpack(std::span< const uint8_t > data)
Definition TimeSyncStructs.h:49
static constexpr std::string_view GetTypeName()
Definition TimeSyncStructs.h:65
static constexpr size_t GetSize()
Definition TimeSyncStructs.h:66
static void Pack(std::span< uint8_t > data, const wpi::tsp::TspPong &value)
Definition TimeSyncStructs.h:82
static wpi::tsp::TspPong Unpack(std::span< const uint8_t > data)
Definition TimeSyncStructs.h:72
static constexpr std::string_view GetSchema()
Definition TimeSyncStructs.h:67
Definition TimeSyncStructs.h:26
uint8_t version
Definition TimeSyncStructs.h:27
uint8_t message_id
Definition TimeSyncStructs.h:28
uint64_t client_time
Definition TimeSyncStructs.h:29
Definition TimeSyncStructs.h:32
TspPong(TspPing ping, uint64_t servertime)
Definition TimeSyncStructs.h:33
uint64_t server_time
Definition TimeSyncStructs.h:35