15void delay_ms(uint32_t ms);
18#define VDPWarnf(fmt, ...) printf("WARN: " fmt "\n", ##__VA_ARGS__)
19#define VDPDebugf(fmt, ...) printf("DEBUG: " fmt "\n", ##__VA_ARGS__)
20#define VDPTracef(fmt, ...) printf("TRACE: " fmt "\n", ##__VA_ARGS__)
23constexpr size_t MAX_CHANNELS = 256;
26using ChannelID = uint8_t;
33enum class PacketType : uint8_t {
43enum class PacketFunction : uint8_t {
45 Acknowledge = 0b00000010,
54enum PacketValidity : uint8_t {
71VDP::PacketValidity validate_packet(
const VDP::Packet& packet);
78VDP::Packet checksum_pac(VDP::Packet in);
87Packet checksum_pac(VDP::Packet in);
99 explicit Channel(T& data, ChannelID
id) : id_(id), data_(data), last_received_(0) {}
102 ChannelID
get_id()
const {
return id_; };
113 std::memcpy(&last_received_, data_packet.subspan(0, 4).data(),
sizeof(uint32_t));
114 return data_.apply_update(data_packet.subspan(4));
124 out.push_back((uint8_t)PacketFunction::Send | (uint8_t)pac_type);
125 out.push_back((uint8_t)id_);
128 VDP::Packet packet_body(
sizeof(uint32_t));
129 if (pac_type == PacketType::Data) {
131 uint64_t timestamp = vexSystemHighResTimeGet();
133 VDP::Packet timestamp_pac(
sizeof(uint64_t));
136 std::memcpy(timestamp_pac.data(), ×tamp,
sizeof(uint64_t));
138 out.insert(out.end(), timestamp_pac.begin(), timestamp_pac.end());
140 packet_body = data_.serialize_data();
141 }
else if (pac_type == PacketType::Schema) {
142 packet_body = data_.serialize_schema();
144 out.insert(out.end(), packet_body.begin(), packet_body.end());
147 VDP::Packet checksum = checksum_pac(out);
148 out.insert(out.end(), checksum.begin(), checksum.end());
154 std::string out =
"";
155 out +=
"{\n id : " + std::to_string(id_) +
",\n";
156 out += data_.schema_to_string(1) +
"\n}";
162 std::string out =
"";
163 out +=
"{\n id : " + std::to_string(id_) +
",\n";
164 out +=
" last received: " + std::to_string(id_) +
",\n";
165 out += data_.data_to_string(1) +
"\n}";
174 uint32_t last_received_;
179Channel(ChannelID, T) -> Channel<T>;
std::string schema_to_string() const
Gets the channel's schema as a string.
Definition protocol.h:153
VDP::Packet serialize(PacketType pac_type)
Serializes the channel as a packet to be sent over a wire to the debug board.
Definition protocol.h:121
Channel(T &data, ChannelID id)
Constructs a channel of data to be sent to the debug board.
Definition protocol.h:99
std::string data_to_string() const
Gets the channel's data as a string.
Definition protocol.h:161
T & get_data()
Gets the data stored inside the channel.
Definition protocol.h:105
ChannelID get_id() const
Gets the channel's id.
Definition protocol.h:102
bool apply_update(VDP::PacketSpan data_packet)
Applies an update from a received packet of data to the data held by the channel.
Definition protocol.h:112
Check for if a held field type is a Field.
Definition types.h:198