libcyberradio 22.01.24
RadioTransport.h
1/***************************************************************************
2 * \file RadioTransport.h
3 * \brief Defines an interface for transporting data to and from a radio.
4 * \author DA
5 * \author NH
6 * \author MN
7 * \copyright (c) 2017 CyberRadio Solutions, Inc. All rights reserved.
8 *
9 ***************************************************************************/
10
11#ifndef INCLUDED_LIBCYBERRADIO_DRIVER_RADIOTRANSPORT_H
12#define INCLUDED_LIBCYBERRADIO_DRIVER_RADIOTRANSPORT_H
13
14#include "LibCyberRadio/Common/BasicList.h"
15#include "LibCyberRadio/Common/Debuggable.h"
16#include "LibCyberRadio/Common/HttpsSession.h"
17#include "LibCyberRadio/Common/SerialPort.h"
18#include <string>
19
20
24namespace LibCyberRadio
25{
29 namespace Driver
30 {
39 {
40 public:
48 bool json = false,
49 bool debug = false
50 );
54 virtual ~RadioTransport();
59 RadioTransport(const RadioTransport& other);
76 virtual bool connect(
77 const std::string& mode,
78 const std::string& host_or_dev,
79 const int port_or_baudrate
80 );
84 virtual void disconnect();
89 virtual bool isConnected() const;
94 void setJson( bool json );
102 virtual bool sendCommand(
103 const std::string& cmdString,
104 bool clearRx = true
105 );
113 virtual BasicStringList receive(
114 double timeout = -1
115 );
120 virtual std::string getLastCommandErrorInfo() const;
121
122 protected:
129 virtual bool connectTcp(
130 const std::string& host,
131 int port
132 );
139 virtual bool connectUdp(
140 const std::string& host,
141 int port
142 );
149 virtual bool connectHttps(
150 const std::string& host,
151 int port
152 );
159 virtual bool connectTty(
160 const std::string& dev,
161 int baudrate
162 );
170 virtual bool sendCommandTcp(
171 const std::string& cmdString,
172 bool clearRx = true
173 );
181 virtual bool sendCommandUdp(
182 const std::string& cmdString,
183 bool clearRx = true
184 );
192 virtual bool sendCommandHttps(
193 const std::string& cmdString,
194 bool clearRx = true
195 );
203 virtual bool sendCommandTty(
204 const std::string& cmdString,
205 bool clearRx = true
206 );
214 double timeout = -1
215 );
216 // receiveJsonTcp()
217 // receiveJsonTty()
218 // receiveJsonUdp()
227 double timeout = -1
228 );
229
230 virtual BasicStringList receiveJsonUdp(
231 double timeout = -1
232 );
241 double timeout = -1
242 );
250 double timeout = -1
251 );
259 double timeout = -1
260 );
268 double timeout = -1
269 );
273 virtual void translateErrno();
274
275 protected:
276 // Is this transport using JSON?
277 bool _isJson;
278 // TCP socket descriptor
279 int _tcpSocket;
280 // UDP socket descriptor
281 int _udpSocket;
282 // TTY (serial) link object
284 // HTTPS session variables
285 HttpsSession* _httpsSession;
286 // -- Connection test and API command URLs
287 std::string _httpsConnTestUrl;
288 std::string _httpsApiCmdUrl;
289 // Error message from the last command executed
290 std::string _lastCmdErrInfo;
291
292 };
293
294
295 } /* namespace Driver */
296
297} /* namespace LibCyberRadio */
298
299#endif /* INCLUDED_LIBCYBERRADIO_DRIVER_RADIOTRANSPORT_H */
virtual int debug(const char *format,...)
Outputs debug information.
Debuggable(bool debug=false, const std::string &debug_name="", FILE *debug_fp=DEBUG_FP, const std::string &debug_timefmt=DEBUG_TIME_FMT)
Constructs a Debuggable object.
virtual BasicStringList receiveCliUdp(double timeout=-1)
Receives a client (AT-command-style) command response over UDP.
virtual bool sendCommandTty(const std::string &cmdString, bool clearRx=true)
Sends a command to the radio over TTY.
virtual BasicStringList receiveCliTcp(double timeout=-1)
Receives a client (AT-command-style) command response over TCP.
virtual bool connectTcp(const std::string &host, int port)
Connects to the radio using TCP.
virtual bool sendCommand(const std::string &cmdString, bool clearRx=true)
Sends a command to the radio over the transport.
virtual ~RadioTransport()
Destroys a RadioTransport object.
virtual bool sendCommandUdp(const std::string &cmdString, bool clearRx=true)
Sends a command to the radio over UDP.
virtual bool connect(const std::string &mode, const std::string &host_or_dev, const int port_or_baudrate)
Connects to the radio.
RadioTransport(bool json=false, bool debug=false)
Constructs a RadioTransport object.
virtual std::string getLastCommandErrorInfo() const
Gets the error information for the last command.
virtual bool connectUdp(const std::string &host, int port)
Connects to the radio using UDP.
virtual bool connectTty(const std::string &dev, int baudrate)
Connects to the radio using a serial link.
virtual BasicStringList receive(double timeout=-1)
Receives a command response from the radio.
virtual bool isConnected() const
Gets whether the transport is connected.
virtual BasicStringList receiveCliTty(double timeout=-1)
Receives a client (AT-command-style) command response over TTY.
virtual BasicStringList receiveCli(double timeout=-1)
Receives a client (AT-command-style) command response from the radio.
virtual bool sendCommandTcp(const std::string &cmdString, bool clearRx=true)
Sends a command to the radio over TCP.
void setJson(bool json)
Allows user to set JSON.
virtual BasicStringList receiveJson(double timeout=-1)
Receives a JSON-formatted command response from the radio.
virtual void disconnect()
Disconnects from the radio.
virtual BasicStringList receiveJsonHttps(double timeout=-1)
Receives a JSON-formatted command response from the radio using HTTPS.
virtual void translateErrno()
Translates an errno value into an error message.
virtual bool connectHttps(const std::string &host, int port)
Connects to the radio using HTTPS.
virtual bool sendCommandHttps(const std::string &cmdString, bool clearRx=true)
Sends a command to the radio over HTTPS.
RadioTransport & operator=(const RadioTransport &other)
Assignment operator for RadioTransport objects.
Class that encapsulates an HTTPS session.
Class that manages communications with a serial port.
Definition SerialPort.h:29
Provides programming elements for driving CRS NDR-class radios.
Defines functionality for LibCyberRadio applications.
Definition App.h:24
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Definition BasicList.h:25