RIT VEXU Core API
Loading...
Searching...
No Matches
wrapper_device.hpp
1#pragma once
2#include "core/device/cobs_device.h"
3#include "core/device/vdb/protocol.hpp"
4#include "vex.h"
5#include <deque>
6
10namespace VDB {
11class Device : public VDP::AbstractDevice, public COBSSerialDevice {
12 public:
13 static constexpr int32_t NO_ACTIVITY_DELAY = 2; // ms
14 static constexpr std::size_t MAX_OUT_QUEUE_SIZE = 50;
15 static constexpr std::size_t MAX_IN_QUEUE_SIZE = 50;
21 explicit Device(int32_t port, int32_t baud_rate);
22
23 bool send_packet(const VDP::Packet &packet);
28 void register_receive_callback(std::function<void(const VDP::Packet &packet)> callback
29 ) override; // From VDP::AbstractDevice
30
31 private:
36 std::deque<WirePacket> outbound_packets{};
37 vex::mutex outbound_mutex;
42 std::deque<WirePacket> inbound_packets;
43
44 vex::mutex inbound_mutex;
49 WirePacket inbound_buffer;
53 static int decode_thread(void *self);
54
58 static int serial_thread(void *self);
59
60 bool write_packet_if_avail();
61
62 // Task that deals with the low level writing and reading bytes from the wire
63 vex::task serial_task;
64
65 bool write_request();
66 std::function<void(const VDP::Packet &packet)> callback;
67};
68
69} // namespace VDB
Definition protocol.hpp:13