Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
terminal_serial.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_TERMINAL_SERIAL_HPP_
25#define TAPROOT_TERMINAL_SERIAL_HPP_
26
27#include <cstring>
28#include <map>
29
30#ifdef PLATFORM_HOSTED
31#ifdef ENV_UNIT_TESTS
32#include "tap/stub/terminal_device_stub.hpp"
33#else
35#endif // ENV_UNIT_TESTS
36#else
38#endif
39
41#include "tap/board/board.hpp"
43#include "tap/util_macros.hpp"
44
45#include "modm/io.hpp"
46
47namespace tap
48{
49class Drivers;
50}
51
53{
59{
60public:
70 char *inputLine,
71 modm::IOStream &outputStream,
72 bool streamingEnabled) = 0;
73
77 virtual void terminalSerialStreamCallback(modm::IOStream &outputStream) = 0;
78}; // class TerminalSerialCallbackInterface
79
104{
105public:
106 static constexpr char DELIMITERS[] = " \t";
107 static constexpr int MAX_LINE_LENGTH = 256;
108 static constexpr int STREAMING_PERIOD = 500;
109
110 explicit TerminalSerial(Drivers *drivers);
111
113
114 virtual ~TerminalSerial() = default;
115
116 mockable void initialize();
117
118 mockable void update();
119
120 mockable void addHeader(const char *header, TerminalSerialCallbackInterface *callback);
121
122private:
123 // Use either an IO device that interacts with UART or with stdin/stdout.
124#ifdef PLATFORM_HOSTED
125#ifdef ENV_UNIT_TESTS
126public:
127 stub::TerminalDeviceStub device;
128
129private:
130#else
131 HostedTerminalDevice device;
132#endif // ENV_UNIT_TESTS
133#else
134 UartTerminalDevice device;
135#endif
136
140 modm::IOStream stream;
141
145 char rxBuff[MAX_LINE_LENGTH];
146
150 uint8_t currLineSize = 0;
151
156 TerminalSerialCallbackInterface *currStreamer = nullptr;
157
158 tap::arch::PeriodicMilliTimer streamingTimer;
159
160 struct cmpByStringEquality
161 {
162 bool operator()(const char *c1, const char *c2) const { return strcmp(c1, c2) < 0; }
163 };
164
165 std::map<const char *, TerminalSerialCallbackInterface *, cmpByStringEquality>
166 headerCallbackMap;
167
168 Drivers *drivers;
169
170 bool prevCharSpace = false;
171
172 void printUsage();
173}; // class TerminalSerial
174} // namespace tap::communication::serial
175
176#endif // TAPROOT_TERMINAL_SERIAL_HPP_
Definition drivers.hpp:70
Definition periodic_timer.hpp:42
virtual bool terminalSerialCallback(char *inputLine, modm::IOStream &outputStream, bool streamingEnabled)=0
virtual void terminalSerialStreamCallback(modm::IOStream &outputStream)=0
Definition terminal_serial.hpp:104
mockable void initialize()
Definition terminal_serial.cpp:41
static constexpr int MAX_LINE_LENGTH
Definition terminal_serial.hpp:107
mockable void addHeader(const char *header, TerminalSerialCallbackInterface *callback)
Definition terminal_serial.cpp:118
static constexpr int STREAMING_PERIOD
Definition terminal_serial.hpp:108
static constexpr char DELIMITERS[]
Definition terminal_serial.hpp:106
mockable void update()
Definition terminal_serial.cpp:43
Definition uart_terminal_device.hpp:46
Definition dji_serial.cpp:41
Definition ballistics.cpp:29
tap::Drivers Drivers
Definition drivers.hpp:11
#define mockable
Wrap class functions that are not already virtual in this function if you wish to mock them.
Definition util_macros.hpp:38