RIT VEXU Core API
Toggle main menu visibility
Loading...
Searching...
No Matches
registry-controller.hpp
1
#pragma once
2
#include "core/device/vdb/protocol.hpp"
3
#include "vex.h"
4
#include <functional>
5
#include "core/device/vdb/visitor.hpp"
6
#include "core/device/vdb/builtins.hpp"
7
8
namespace
VDP {
9
class
RegistryController {
10
public
:
11
int
num_bad = 0;
12
int
num_small = 0;
13
using
CallbackFn = std::function<void(
const
VDP::Channel &)>;
19
RegistryController(AbstractDevice *device);
24
void
take_packet(
const
Packet &pac);
30
PartPtr get_data(ChannelID
id
);
31
41
ChannelID open_channel(PartPtr &for_data);
47
bool
send_data(ChannelID
id
);
48
53
bool
negotiate();
54
int
rec_switch_time = 1000;
55
56
private
:
57
std::vector<Channel> channels;
58
ChannelID new_channel_id() {
59
ChannelID
id
= next_channel_id;
60
next_channel_id++;
61
return
id;
62
}
63
64
int
responses_in_queue;
65
bool
needs_ack =
false
;
66
vex::timer timer;
67
bool
rec_mode =
false
;
68
static
constexpr
size_t
ack_ms = 500;
69
70
AbstractDevice *device;
71
// Our channels (us -> them)
72
73
ChannelID next_channel_id = 0;
77
CallbackFn on_broadcast = [&](VDP::Channel chan) {
78
std::string schema_str = chan.data->pretty_print();
79
printf(
80
"VDB-Controller: No Broadcast Callback installed: Received broadcast "
81
"for channel id "
82
"%d:\n%s\n"
,
83
int
(chan.getID()), schema_str.c_str()
84
);
85
};
90
CallbackFn on_data = [&](VDP::Channel new_data) {
91
ResponsePacketVisitor RV(new_data.data);
92
PartPtr original_data = channels[new_data.id].data;
93
original_data->Visit(&RV);
94
original_data->response();
95
};
96
};
97
}
// namespace VDP
include
core
device
vdb
registry-controller.hpp
Generated by
1.17.0