libcyberradio  22.01.24
RadioTransport Class Reference

Generic radio transport class. More...

#include <RadioTransport.h>

Inheritance diagram for RadioTransport:
Debuggable

Public Member Functions

 RadioTransport (bool json=false, bool debug=false)
 Constructs a RadioTransport object. More...
 
virtual ~RadioTransport ()
 Destroys a RadioTransport object.
 
 RadioTransport (const RadioTransport &other)
 Copies a RadioTransport object. More...
 
RadioTransportoperator= (const RadioTransport &other)
 Assignment operator for RadioTransport objects. More...
 
virtual bool connect (const std::string &mode, const std::string &host_or_dev, const int port_or_baudrate)
 Connects to the radio. More...
 
virtual void disconnect ()
 Disconnects from the radio.
 
virtual bool isConnected () const
 Gets whether the transport is connected. More...
 
void setJson (bool json)
 Allows user to set JSON. More...
 
virtual bool sendCommand (const std::string &cmdString, bool clearRx=true)
 Sends a command to the radio over the transport. More...
 
virtual BasicStringList receive (double timeout=-1)
 Receives a command response from the radio. More...
 
virtual std::string getLastCommandErrorInfo () const
 Gets the error information for the last command. More...
 
virtual void setDebugName (const std::string &debug_name)
 Sets the debug name for this object. More...
 
virtual void setDebugFile (FILE *debug_fp)
 Sets the debug file pointer for this object. More...
 
virtual void setDebugTimeFormat (const std::string &debug_timefmt)
 Sets the debug time format for this object. More...
 
virtual int debug (const char *format,...)
 Outputs debug information. More...
 
virtual const char * debugBool (bool x)
 Gets a debug output string for a Boolean value. More...
 
virtual bool isDebug () const
 Gets whether this object produces debug output. More...
 
virtual std::string getDebugName () const
 Gets the debug name for this object. More...
 
virtual std::string rawString (const std::string &data)
 Gets a "raw" string representation of a given data string. More...
 

Protected Member Functions

virtual bool connectTcp (const std::string &host, int port)
 Connects to the radio using TCP. More...
 
virtual bool connectUdp (const std::string &host, int port)
 Connects to the radio using UDP. More...
 
virtual bool connectHttps (const std::string &host, int port)
 Connects to the radio using HTTPS. More...
 
virtual bool connectTty (const std::string &dev, int baudrate)
 Connects to the radio using a serial link. More...
 
virtual bool sendCommandTcp (const std::string &cmdString, bool clearRx=true)
 Sends a command to the radio over TCP. More...
 
virtual bool sendCommandUdp (const std::string &cmdString, bool clearRx=true)
 Sends a command to the radio over UDP. More...
 
virtual bool sendCommandHttps (const std::string &cmdString, bool clearRx=true)
 Sends a command to the radio over HTTPS. More...
 
virtual bool sendCommandTty (const std::string &cmdString, bool clearRx=true)
 Sends a command to the radio over TTY. More...
 
virtual BasicStringList receiveJson (double timeout=-1)
 Receives a JSON-formatted command response from the radio. More...
 
virtual BasicStringList receiveJsonHttps (double timeout=-1)
 Receives a JSON-formatted command response from the radio using HTTPS. More...
 
virtual BasicStringList receiveCli (double timeout=-1)
 Receives a client (AT-command-style) command response from the radio. More...
 
virtual BasicStringList receiveCliTcp (double timeout=-1)
 Receives a client (AT-command-style) command response over TCP. More...
 
virtual BasicStringList receiveCliUdp (double timeout=-1)
 Receives a client (AT-command-style) command response over UDP. More...
 
virtual BasicStringList receiveCliTty (double timeout=-1)
 Receives a client (AT-command-style) command response over TTY. More...
 
virtual void translateErrno ()
 Translates an errno value into an error message.
 

Detailed Description

Generic radio transport class.

The radio transport class provides a unified interface for transmitting data to and from the radio, regardless of the connection method used (serial/TTY, TCP, UDP, or HTTPS).

Definition at line 38 of file RadioTransport.h.

Constructor & Destructor Documentation

◆ RadioTransport() [1/2]

RadioTransport ( bool  json = false,
bool  debug = false 
)

Constructs a RadioTransport object.

Parameters
jsonWhether the transport should expect JSON-formatted commands and responses (Boolean).
debugWhether the transport emits debug output (Boolean).

Definition at line 32 of file RadioTransport.cpp.

◆ RadioTransport() [2/2]

RadioTransport ( const RadioTransport other)

Copies a RadioTransport object.

Parameters
otherThe RadioTransport object to copy.

Definition at line 66 of file RadioTransport.cpp.

Member Function Documentation

◆ connect()

bool connect ( const std::string &  mode,
const std::string &  host_or_dev,
const int  port_or_baudrate 
)
virtual

Connects to the radio.

Parameters
modeThe connection mode. One of "tty", "tcp", "udp", or "https".
host_or_devEither the host name or IP address (for TCP or UDP) or the serial device name (for TTY).
port_or_baudrateEither the port number (for TCP or UDP) or the serial baud rate (for TTY).TCP
Returns
True if the connection succeeds, false otherwise.

Definition at line 104 of file RadioTransport.cpp.

◆ connectHttps()

bool connectHttps ( const std::string &  host,
int  port 
)
protectedvirtual

Connects to the radio using HTTPS.

Parameters
hostThe host name or IP address.
portThe port number.
Returns
True if the connection succeeds, false otherwise.

Definition at line 297 of file RadioTransport.cpp.

◆ connectTcp()

bool connectTcp ( const std::string &  host,
int  port 
)
protectedvirtual

Connects to the radio using TCP.

Parameters
hostThe host name or IP address.
portThe port number.
Returns
True if the connection succeeds, false otherwise.

Definition at line 226 of file RadioTransport.cpp.

◆ connectTty()

bool connectTty ( const std::string &  dev,
int  baudrate 
)
protectedvirtual

Connects to the radio using a serial link.

Parameters
devThe device name for the serial port.
baudrateThe serial baud rate.
Returns
True if the connection succeeds, false otherwise.

Definition at line 334 of file RadioTransport.cpp.

◆ connectUdp()

bool connectUdp ( const std::string &  host,
int  port 
)
protectedvirtual

Connects to the radio using UDP.

Parameters
hostThe host name or IP address.
portThe port number.
Returns
True if the connection succeeds, false otherwise.

Definition at line 261 of file RadioTransport.cpp.

◆ debug()

int debug ( const char *  format,
  ... 
)
virtualinherited

Outputs debug information.

This method follows the same semantics as printf(). Output is preceded by a timestamp and the name of the object, if provided.

Parameters
formatThe printf()-style format string.
...Comma-separated list of arguments to print. Note that these need to be arguments that can be supported natively through printf().
Returns
The number of characters outputted.

Definition at line 95 of file Debuggable.cpp.

◆ debugBool()

const char * debugBool ( bool  x)
virtualinherited

Gets a debug output string for a Boolean value.

Parameters
xBoolean value
Returns
A constant string, either "true" or "false".

Definition at line 126 of file Debuggable.cpp.

◆ getDebugName()

std::string getDebugName ( ) const
virtualinherited

Gets the debug name for this object.

Returns
The debug name, as a string.

Definition at line 138 of file Debuggable.cpp.

◆ getLastCommandErrorInfo()

std::string getLastCommandErrorInfo ( ) const
virtual

Gets the error information for the last command.

Returns
A string containing the error message.

Definition at line 221 of file RadioTransport.cpp.

◆ isConnected()

bool isConnected ( ) const
virtual

Gets whether the transport is connected.

Returns
True if connected, false otherwise.

Definition at line 161 of file RadioTransport.cpp.

◆ isDebug()

bool isDebug ( ) const
virtualinherited

Gets whether this object produces debug output.

Returns
True if producing debug, false otherwise.

Definition at line 133 of file Debuggable.cpp.

◆ operator=()

RadioTransport & operator= ( const RadioTransport other)

Assignment operator for RadioTransport objects.

Parameters
otherThe RadioTransport object to copy.
Returns
A reference to the assigned object.

Definition at line 79 of file RadioTransport.cpp.

◆ rawString()

std::string rawString ( const std::string &  data)
virtualinherited

Gets a "raw" string representation of a given data string.

"Raw" string representations mimic Python string representations. Whitespace characters are denoted by backslash representations ("\\r", "\\n", "\\t", "\\v", "\\f"), while other non-printable characters are represented with hex representation ("\\x00", etc.)

Parameters
dataData string
Returns
The data's "raw" representation.

Definition at line 143 of file Debuggable.cpp.

◆ receive()

BasicStringList receive ( double  timeout = -1)
virtual

Receives a command response from the radio.

Parameters
timeoutThe timeout value to use for receiving data. If -1, use the default timeout value for the transport.
Returns
If the transport is using JSON, this is a JSON-formatted string; if not, this is a list of received data strings.

Definition at line 202 of file RadioTransport.cpp.

◆ receiveCli()

BasicStringList receiveCli ( double  timeout = -1)
protectedvirtual

Receives a client (AT-command-style) command response from the radio.

Parameters
timeoutThe timeout value to use for receiving data. If -1, use the default timeout value for the transport.
Returns
A list of received data strings.

Definition at line 559 of file RadioTransport.cpp.

◆ receiveCliTcp()

BasicStringList receiveCliTcp ( double  timeout = -1)
protectedvirtual

Receives a client (AT-command-style) command response over TCP.

Parameters
timeoutThe timeout value to use for receiving data. If -1, use the default timeout value for the transport.
Returns
A list of received data strings.

Definition at line 573 of file RadioTransport.cpp.

◆ receiveCliTty()

BasicStringList receiveCliTty ( double  timeout = -1)
protectedvirtual

Receives a client (AT-command-style) command response over TTY.

Parameters
timeoutThe timeout value to use for receiving data. If -1, use the default timeout value for the transport.
Returns
A list of received data strings.

Definition at line 645 of file RadioTransport.cpp.

◆ receiveCliUdp()

BasicStringList receiveCliUdp ( double  timeout = -1)
protectedvirtual

Receives a client (AT-command-style) command response over UDP.

Parameters
timeoutThe timeout value to use for receiving data. If -1, use the default timeout value for the transport.
Returns
A list of received data strings.

Definition at line 637 of file RadioTransport.cpp.

◆ receiveJson()

BasicStringList receiveJson ( double  timeout = -1)
protectedvirtual

Receives a JSON-formatted command response from the radio.

Parameters
timeoutThe timeout value to use for receiving data. If -1, use the default timeout value for the transport.
Returns
A list of received data strings.

Definition at line 491 of file RadioTransport.cpp.

◆ receiveJsonHttps()

BasicStringList receiveJsonHttps ( double  timeout = -1)
protectedvirtual

Receives a JSON-formatted command response from the radio using HTTPS.

Parameters
timeoutThe timeout value to use for receiving data. If -1, use the default timeout value for the transport.
Returns
A list of received data strings.

Definition at line 539 of file RadioTransport.cpp.

◆ sendCommand()

bool sendCommand ( const std::string &  cmdString,
bool  clearRx = true 
)
virtual

Sends a command to the radio over the transport.

Parameters
cmdStringThe command to send.
clearRxWhether or not to clear the receive buffer before sending the command.
Returns
True if the command was sent successfully, false otherwise.

Definition at line 172 of file RadioTransport.cpp.

◆ sendCommandHttps()

bool sendCommandHttps ( const std::string &  cmdString,
bool  clearRx = true 
)
protectedvirtual

Sends a command to the radio over HTTPS.

Parameters
cmdStringThe command to send.
clearRxWhether or not to clear the receive buffer before sending the command.
Returns
True if the command was sent successfully, false otherwise.

Definition at line 424 of file RadioTransport.cpp.

◆ sendCommandTcp()

bool sendCommandTcp ( const std::string &  cmdString,
bool  clearRx = true 
)
protectedvirtual

Sends a command to the radio over TCP.

Parameters
cmdStringThe command to send.
clearRxWhether or not to clear the receive buffer before sending the command.
Returns
True if the command was sent successfully, false otherwise.

Definition at line 382 of file RadioTransport.cpp.

◆ sendCommandTty()

bool sendCommandTty ( const std::string &  cmdString,
bool  clearRx = true 
)
protectedvirtual

Sends a command to the radio over TTY.

Parameters
cmdStringThe command to send.
clearRxWhether or not to clear the receive buffer before sending the command.
Returns
True if the command was sent successfully, false otherwise.

Definition at line 471 of file RadioTransport.cpp.

◆ sendCommandUdp()

bool sendCommandUdp ( const std::string &  cmdString,
bool  clearRx = true 
)
protectedvirtual

Sends a command to the radio over UDP.

Parameters
cmdStringThe command to send.
clearRxWhether or not to clear the receive buffer before sending the command.
Returns
True if the command was sent successfully, false otherwise.

Definition at line 403 of file RadioTransport.cpp.

◆ setDebugFile()

void setDebugFile ( FILE *  debug_fp)
virtualinherited

Sets the debug file pointer for this object.

Parameters
debug_fpFile to send debug output to.

Definition at line 81 of file Debuggable.cpp.

◆ setDebugName()

void setDebugName ( const std::string &  debug_name)
virtualinherited

Sets the debug name for this object.

Use this method to set unique debug names for objects of the same class for easy differentiation.

Parameters
debug_nameName for identifying this object in debug output.

Definition at line 74 of file Debuggable.cpp.

◆ setDebugTimeFormat()

void setDebugTimeFormat ( const std::string &  debug_timefmt)
virtualinherited

Sets the debug time format for this object.

Parameters
debug_timefmtFormat string for displaying timestamp, as compatible with strftime(). If this is an empty string, don't display a timestamp.

Definition at line 88 of file Debuggable.cpp.

◆ setJson()

void setJson ( bool  json)

Allows user to set JSON.

Parameters
jsonTrue if Radio Uses JSON

Definition at line 97 of file RadioTransport.cpp.


The documentation for this class was generated from the following files: