LibDS
Qt-based library for controlling FRC robots
Public Slots | Signals | Public Member Functions | Private Slots | Private Attributes | List of all members
Sockets Class Reference

Sends and receives data from the FMS, radio and robot targets. More...

#include <Sockets.h>

Inheritance diagram for Sockets:

Public Slots

void performLookups ()
 
void setFMSInputPort (int port)
 
void setFMSOutputPort (int port)
 
void setRadioInputPort (int port)
 
void setRobotInputPort (int port)
 
void setRadioOutputPort (int port)
 
void setRobotOutputPort (int port)
 
void sendToFMS (const QByteArray &data)
 
void sendToRobot (const QByteArray &data)
 
void sendToRadio (const QByteArray &data)
 
void setFMSSocketType (DS::SocketType type)
 
void setRadioSocketType (DS::SocketType type)
 
void setRobotSocketType (DS::SocketType type)
 
void setFMSAddress (const QString &address)
 
void setRadioAddress (const QString &address)
 
void setRobotAddress (const QString &address)
 
void setFMSAddress (const QHostAddress &address)
 
void setRadioAddress (const QHostAddress &address)
 
void setRobotAddress (const QHostAddress &address)
 

Signals

void fmsPacketReceived (const QByteArray &data)
 
void radioPacketReceived (const QByteArray &data)
 
void robotPacketReceived (const QByteArray &data)
 

Public Member Functions

QHostAddress fmsAddress () const
 
QHostAddress radioAddress () const
 
QHostAddress robotAddress () const
 

Private Slots

void readFMSSocket ()
 
void readRadioSocket ()
 
void readRobotSocket ()
 
void onFMSLookupFinished (const QString &name, const QHostAddress &address)
 
void onRadioLookupFinished (const QString &name, const QHostAddress &address)
 
void onRobotLookupFinished (const QString &name, const QHostAddress &address)
 

Private Attributes

int m_robotIterator
 
int m_fmsOutputPort
 
int m_radioOutputPort
 
int m_robotOutputPort
 
int m_fmsLookupId
 
int m_radioLookupId
 
int m_robotLookupId
 
QHostAddress m_fmsAddress
 
QHostAddress m_robotAddress
 
QHostAddress m_radioAddress
 
Lookupm_fmsLookup
 
Lookupm_radioLookup
 
Lookupm_robotLookup
 
DriverStationm_driverStation
 
QUdpSocket * m_udpFmsSender
 
QTcpSocket * m_tcpFmsSender
 
QUdpSocket * m_udpRadioSender
 
QTcpSocket * m_tcpRadioSender
 
QUdpSocket * m_udpRobotSender
 
QTcpSocket * m_tcpRobotSender
 
QUdpSocket * m_udpFmsReceiver
 
QTcpSocket * m_tcpFmsReceiver
 
QUdpSocket * m_udpRadioReceiver
 
QTcpSocket * m_tcpRadioReceiver
 
QUdpSocket * m_udpRobotReceiver
 
QTcpSocket * m_tcpRobotReceiver
 

Detailed Description

Sends and receives data from the FMS, radio and robot targets.

This class also performs the host lookup processes for each target if it is required (for example, when using mDNS targets). As a rule of thumb, this class will broadcast generated packets if we do not know the target IP.

This class is controlled directly by the DriverStation, which acts as a man-in-the-middle between the loaded Protocol and the Sockets class.

Note
The packets can be sent either with UDP or TCP packets (as defined by the DS/protocol)

Member Function Documentation

QHostAddress Sockets::fmsAddress ( ) const

Returns the FMS address.

Referenced by sendToFMS().

void Sockets::onFMSLookupFinished ( const QString &  name,
const QHostAddress &  address 
)
privateslot

Assigns the found FMS IP

References DriverStation::fmsAddress(), and setFMSAddress().

void Sockets::onRadioLookupFinished ( const QString &  name,
const QHostAddress &  address 
)
privateslot

Assigns the found radio IP

References DriverStation::radioAddress(), and setRadioAddress().

void Sockets::onRobotLookupFinished ( const QString &  name,
const QHostAddress &  address 
)
privateslot

Assigns the found robot IP

References DriverStation::robotAddress(), and setRobotAddress().

void Sockets::performLookups ( )
slot

If any of the IPs used during the communications is not known, this function will ensure that the DS performs a lookup periodically until all addresses are known.

This is especially useful when we are dealing with dynamic IPs, such as when the robot uses a mDNS address.

References DriverStation::fmsAddress(), DriverStation::getInstance(), DriverStation::isConnectedToFMS(), DriverStation::isConnectedToRadio(), DriverStation::isConnectedToRobot(), Lookup::lookup(), DriverStation::radioAddress(), and DriverStation::robotAddress().

QHostAddress Sockets::radioAddress ( ) const

Returns the radio address.

Referenced by sendToRadio().

void Sockets::readFMSSocket ( )
privateslot

Called when we receive data from the FMS

References DS::readSocket(), and setFMSAddress().

Referenced by setFMSSocketType().

void Sockets::readRadioSocket ( )
privateslot

Called when we receive data from the radio

References DS::readSocket(), and setRadioAddress().

Referenced by setRadioSocketType().

void Sockets::readRobotSocket ( )
privateslot

Called when we receive data from the robot

References DS::readSocket(), and setRobotAddress().

Referenced by setRobotSocketType().

QHostAddress Sockets::robotAddress ( ) const

Returns the robot address. If the robot address is not known, this function will return the local IP of the computer (e.g for simulations).

Referenced by sendToRobot().

void Sockets::sendToFMS ( const QByteArray &  data)
slot

Sends the given data to the FMS

References fmsAddress().

Referenced by DriverStation::sendFMSPacket().

void Sockets::sendToRadio ( const QByteArray &  data)
slot

Sends the given data to the radio

References radioAddress().

Referenced by DriverStation::sendRadioPacket().

void Sockets::sendToRobot ( const QByteArray &  data)
slot

Sends the given data to the robot

References robotAddress().

Referenced by DriverStation::sendRobotPacket().

void Sockets::setFMSAddress ( const QString &  address)
slot

Changes the FMS address. If the FMS address is set to an invalid value, then this class will broadcast the data.

Referenced by onFMSLookupFinished(), readFMSSocket(), DriverStation::setCustomFMSAddress(), and DriverStation::updateAddresses().

void Sockets::setFMSAddress ( const QHostAddress &  address)
slot

Changes the FMS address to the given address

void Sockets::setFMSInputPort ( int  port)
slot

Changes the port in which we receive data from the FMS

Referenced by DriverStation::setProtocol().

void Sockets::setFMSOutputPort ( int  port)
slot

Changes the FMS destination port

Referenced by DriverStation::setProtocol().

void Sockets::setFMSSocketType ( DS::SocketType  type)
slot

Changes the set of sockets that will be used for FMS communications

References DS::kSocketTypeTCP, and readFMSSocket().

Referenced by DriverStation::setProtocol().

void Sockets::setRadioAddress ( const QString &  address)
slot

Changes the radio address. If the radio address is set to an invalid value, then this class will broadcast the data.

Referenced by onRadioLookupFinished(), readRadioSocket(), DriverStation::setCustomRadioAddress(), and DriverStation::updateAddresses().

void Sockets::setRadioAddress ( const QHostAddress &  address)
slot

Changes the radio address to the given address

void Sockets::setRadioInputPort ( int  port)
slot

Changes the port in which we receive data from the radio

Referenced by DriverStation::setProtocol().

void Sockets::setRadioOutputPort ( int  port)
slot

Changes the radio destination robot

Referenced by DriverStation::setProtocol().

void Sockets::setRadioSocketType ( DS::SocketType  type)
slot

Changes the set of sockets that will be used for radio communications

References DS::kSocketTypeTCP, and readRadioSocket().

Referenced by DriverStation::setProtocol().

void Sockets::setRobotAddress ( const QString &  address)
slot

Changes the robot address. If the robot address is set to an invalid value, then this class will broadcast the data.

Referenced by onRobotLookupFinished(), readRobotSocket(), DriverStation::setCustomRobotAddress(), and DriverStation::updateAddresses().

void Sockets::setRobotAddress ( const QHostAddress &  address)
slot

Changes the robot address to the given address

void Sockets::setRobotInputPort ( int  port)
slot

Changes the port in which we receive data from the robot

Referenced by DriverStation::setProtocol().

void Sockets::setRobotOutputPort ( int  port)
slot

Changes the robot destination robot

Referenced by DriverStation::setProtocol().

void Sockets::setRobotSocketType ( DS::SocketType  type)
slot

Changes the set of sockets that will be used for robot communications

References DS::kSocketTypeTCP, and readRobotSocket().

Referenced by DriverStation::setProtocol().


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