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

Base class for implementing communication protocols. More...

#include <Protocol.h>

Inheritance diagram for Protocol:
FRC_2014 FRC_2015 FRC_2016

Public Member Functions

virtual QString name ()
 
virtual int fmsFrequency ()
 
virtual int radioFrequency ()
 
virtual int robotFrequency ()
 
virtual int maxJoystickCount ()
 
virtual int maxPOVCount ()
 
virtual int maxAxisCount ()
 
virtual int maxButtonCount ()
 
virtual int fmsInputPort ()
 
virtual int fmsOutputPort ()
 
virtual int radioInputPort ()
 
virtual int robotInputPort ()
 
virtual int radioOutputPort ()
 
virtual int robotOutputPort ()
 
virtual int netconsoleInputPort ()
 
virtual int netconsoleOutputPort ()
 
virtual qreal nominalBatteryVOltage ()
 
virtual qreal nominalBatteryAmperage ()
 
virtual void rebootRobot ()
 
virtual void restartRobotCode ()
 
virtual void onFMSWatchdogExpired ()
 
virtual void onRadioWatchdogExpired ()
 
virtual void onRobotWatchdogExpired ()
 
virtual DS::SocketType fmsSocketType ()
 
virtual DS::SocketType radioSocketType ()
 
virtual DS::SocketType robotSocketType ()
 
virtual QString fmsAddress ()
 
virtual QString radioAddress ()
 
virtual QString robotAddress ()
 
QByteArray generateFMSPacket ()
 
QByteArray generateRadioPacket ()
 
QByteArray generateRobotPacket ()
 
bool readFMSPacket (const QByteArray &data)
 
bool readRadioPacket (const QByteArray &data)
 
bool readRobotPacket (const QByteArray &data)
 
void resetLossCounter ()
 
int sentFMSPackets ()
 
int sentRadioPackets ()
 
int sentRobotPackets ()
 
int receivedFMSPackets ()
 
int receivedRadioPackets ()
 
int receivedRobotPackets ()
 
int recvRobotPacketsSinceConnect ()
 
int sentRobotPacketsSinceConnect ()
 

Protected Member Functions

DS_Configconfig ()
 
DS_Joysticks * joysticks ()
 
virtual QByteArray getFMSPacket ()
 
virtual QByteArray getRadioPacket ()
 
virtual QByteArray getRobotPacket ()
 
virtual bool interpretFMSPacket (const QByteArray &data)
 
virtual bool interpretRadioPacket (const QByteArray &data)
 
virtual bool interpretRobotPacket (const QByteArray &data)
 

Private Attributes

int m_sentFmsPackets
 
int m_sentRadioPackets
 
int m_sentRobotPackets
 
int m_receivedFmsPackets
 
int m_receivedRadioPackets
 
int m_receivedRobotPackets
 
int m_recvRobotPacketsSinceConnect
 
int m_sentRobotPacketsSinceConnect
 

Detailed Description

Base class for implementing communication protocols.

The protocol class allows developers to create their own communication protocols for use with applications that support the LibDS.

Member Function Documentation

DS_Config* Protocol::config ( )
inlineprotected
virtual QString Protocol::fmsAddress ( )
inlinevirtual

Returns the IP address in which we should be able to find the FMS. Contrary to how the radio and the robot protocols work, we will not send FMS packets until we have received a packet from the FMS.

The address is set to empty by default, the DS will set the appropriate FMS IP once it receives a packet from it.

Referenced by DriverStation::defaultFMSAddress().

virtual int Protocol::fmsFrequency ( )
inlinevirtual

Returns the number of packets that we send to the FMS per second. For example, if we want to send 50 packets/second, the frequency should be set to 50.

Note
If you do not re-implement this function, then the Driver Station will not send data to the FMS.

Reimplemented in FRC_2014, and FRC_2015.

Referenced by DriverStation::setProtocol().

virtual int Protocol::fmsInputPort ( )
inlinevirtual

Returns the port in which we receive data from the FMS.

Note
If you do not re-implement this function, the protocol will not be able to receive data from the FMS.

Reimplemented in FRC_2014, and FRC_2015.

Referenced by DriverStation::setProtocol().

virtual int Protocol::fmsOutputPort ( )
inlinevirtual

Returns the port in which we send data to the FMS.

Note
If you do not re-implement this function, the protocol will not be able to send data to the FMS.

Reimplemented in FRC_2014, and FRC_2015.

Referenced by DriverStation::setProtocol().

virtual DS::SocketType Protocol::fmsSocketType ( )
inlinevirtual

Returns the socket type (UDP or TCP) used for client/FMS interacion.

Note
If you do not re-implement this function, the Driver Station will asume that the FMS uses UDP communications.
We recommend you to redefine this function in your protocol to avoid breaking it if the core library is changed.

Reimplemented in FRC_2015, and FRC_2014.

References DS::kSocketTypeUDP.

Referenced by DriverStation::setProtocol().

QByteArray Protocol::generateFMSPacket ( )
inline

Updates the sent FMS packets counter and generates a client-to-FMS packet using the protocol implementation code.

References getFMSPacket().

QByteArray Protocol::generateRadioPacket ( )
inline

Updates the sent radio packets counter and generates a client-to-radio packet using the protocol implementation code.

References getRadioPacket().

QByteArray Protocol::generateRobotPacket ( )
inline

Updates the sent robot packets counter and generates a client-to-robot packet using the protocol implementation code.

References getRobotPacket().

virtual QByteArray Protocol::getFMSPacket ( )
inlineprotectedvirtual

Returns a packet that is sent to the FMS.

Note
If you do not re-implement this function, it will generate an empty packet. Empty packets are ignored by the Driver Station.

Reimplemented in FRC_2015, and FRC_2014.

Referenced by generateFMSPacket().

virtual QByteArray Protocol::getRadioPacket ( )
inlineprotectedvirtual

Returns a packet that is sent to the robot radio.

Note
If you do not re-implement this function, it will generate an empty packet. Empty packets are ignored by the Driver Station.

Referenced by generateRadioPacket().

virtual QByteArray Protocol::getRobotPacket ( )
inlineprotectedvirtual

Returns a packet that is sent to the robot.

Note
If you do not re-implement this function, it will generate an empty packet. Empty packets are ignored by the Driver Station.

Reimplemented in FRC_2015, and FRC_2014.

Referenced by generateRobotPacket().

virtual bool Protocol::interpretFMSPacket ( const QByteArray &  data)
inlineprotectedvirtual

Interprets the data received from the FMS and adjusts the Driver Station properties accordingly.

Reimplemented in FRC_2015, and FRC_2014.

Referenced by readFMSPacket().

virtual bool Protocol::interpretRadioPacket ( const QByteArray &  data)
inlineprotectedvirtual

Interprets the data received from the radio and adjusts the Driver Station properties accordingly.

Referenced by readRadioPacket().

virtual bool Protocol::interpretRobotPacket ( const QByteArray &  data)
inlineprotectedvirtual

Interprets the data received from the robot and adjusts the Driver Station properties accordingly.

Reimplemented in FRC_2015, and FRC_2014.

Referenced by readRobotPacket().

DS_Joysticks* Protocol::joysticks ( )
inlineprotected

Gives direct access to the registered joysticks of the DS

References DriverStation::getInstance(), and DriverStation::joysticks().

Referenced by FRC_2014::getJoystickData(), and FRC_2014::getRobotPacket().

virtual int Protocol::maxAxisCount ( )
inlinevirtual

Returns the maximum ammount of axes supported by the protocol

Reimplemented in FRC_2015, and FRC_2014.

Referenced by DriverStation::maxAxisCount().

virtual int Protocol::maxButtonCount ( )
inlinevirtual

Returns the maximum ammount of buttons supported by the protocol

Reimplemented in FRC_2015, and FRC_2014.

Referenced by DriverStation::maxButtonCount().

virtual int Protocol::maxJoystickCount ( )
inlinevirtual

Returns the maximum number of joysticks supported

Reimplemented in FRC_2015, and FRC_2014.

Referenced by DriverStation::maxJoystickCount().

virtual int Protocol::maxPOVCount ( )
inlinevirtual

Returns the maximum ammount of POVs supported by the protocol

Reimplemented in FRC_2015, and FRC_2014.

Referenced by DriverStation::maxPOVCount().

virtual QString Protocol::name ( )
inlinevirtual

Returns the name of the protocol. This is used by the DriverStation to notify the user when the protocol is loaded.

Reimplemented in FRC_2014, FRC_2015, and FRC_2016.

Referenced by DriverStation::reconfigureJoysticks(), and DriverStation::setProtocol().

virtual int Protocol::netconsoleInputPort ( )
inlinevirtual

Returns the port in which we receive broadcasted messages from the robot.

Note
If you do not re-implement this function, the protocol will not be able to receive broadcasted messages from the robot.

Reimplemented in FRC_2015.

Referenced by DriverStation::setProtocol().

virtual int Protocol::netconsoleOutputPort ( )
inlinevirtual

Returns the port in which we send broadcasted messages to the robot.

Note
If you do not re-implement this function, the protocol will not be able to send broadcasted commands to the robot.

Referenced by DriverStation::setProtocol().

virtual qreal Protocol::nominalBatteryAmperage ( )
inlinevirtual

Returns the maximum amperage given by the battery. This value can be used by the client to draw graphs, calculate current power output (in watts), do car-like dashboards and other cool things.

Reimplemented in FRC_2015, and FRC_2014.

Referenced by DriverStation::nominalBatteryAmperage().

virtual qreal Protocol::nominalBatteryVOltage ( )
inlinevirtual

Returns the nominal voltage given by the battery. This value can be used by the client to draw graphs, create car-like dashboards and other cool things.

It is also used to avoid reporting 37.00 V or 16'674'591 V. Trust me, it happened: http://imgur.com/a/6ibog

Referenced by DriverStation::maxBatteryVoltage().

virtual void Protocol::onFMSWatchdogExpired ( )
inlinevirtual

Called when the FMS watchdog expires

Referenced by DriverStation::resetFMS().

virtual void Protocol::onRadioWatchdogExpired ( )
inlinevirtual

Called when the radio watchdog expires

Referenced by DriverStation::resetRadio().

virtual void Protocol::onRobotWatchdogExpired ( )
inlinevirtual

Called when the robot watchdog expires

Reimplemented in FRC_2015, and FRC_2014.

Referenced by DriverStation::resetRobot().

virtual QString Protocol::radioAddress ( )
inlinevirtual

Returns the IP address in which we should be able to find the radio.

If the returned address is invalid, unresolved (e.g. mDNS) or empty, the Driver Station will lookup the address, while broadcasting the generated radio packages until the lookup receives a response.

The default value that this function returns is 10.xx.yy.1

Reimplemented in FRC_2015, and FRC_2014.

References config(), and DS::getStaticIP().

Referenced by DriverStation::defaultRadioAddress().

virtual int Protocol::radioFrequency ( )
inlinevirtual

Returns the number of packets that we send to the robot per second. For example, if we want to send 50 packets/second, the frequency should be set to 50.

Note
If you do not re-implement this function, then the Driver Station will not send data to the radio.

Referenced by DriverStation::setProtocol().

virtual int Protocol::radioInputPort ( )
inlinevirtual

Returns the port in which we receive data from the radio.

Note
If you do not re-implement this function, the protocol will not be able to receive data from the radio.

Referenced by DriverStation::setProtocol().

virtual int Protocol::radioOutputPort ( )
inlinevirtual

Returns the port in which we send data to the radio.

Note
If you do not re-implement this function, the protocol will not be able to send data to the robot radio.

Referenced by DriverStation::setProtocol().

virtual DS::SocketType Protocol::radioSocketType ( )
inlinevirtual

Returns the socket type (UDP or TCP) used for client/radio interaction.

Note
If you do not re-implement this function, the Driver Station will asume that the radio uses UDP communications.
We recommend you to redefine this function in your protocol to avoid breaking it if the core library is changed.

References DS::kSocketTypeUDP.

Referenced by DriverStation::setProtocol().

bool Protocol::readFMSPacket ( const QByteArray &  data)
inline

Lets the protocol implementation interpret the given data and updates the received FMS packets counter.

References config(), interpretFMSPacket(), DS::kCommsWorking, and DS_Config::updateFMSCommStatus().

bool Protocol::readRadioPacket ( const QByteArray &  data)
inline

Lets the protocol implementation interpret the given data and updates the received radio packets counter.

References config(), interpretRadioPacket(), DS::kCommsWorking, and DS_Config::updateRadioCommStatus().

bool Protocol::readRobotPacket ( const QByteArray &  data)
inline

Lets the protocol implementation interpret the given data and updates the received robot packets counter.

References config(), interpretRobotPacket(), DS::kCommsWorking, resetLossCounter(), and DS_Config::updateRobotCommStatus().

virtual void Protocol::rebootRobot ( )
inlinevirtual

Reboots the robot controller

Reimplemented in FRC_2015, and FRC_2014.

Referenced by DriverStation::rebootRobot().

int Protocol::receivedFMSPackets ( )
inline

Returns the number of packets received from the FMS

int Protocol::receivedRadioPackets ( )
inline

Returns the number of packets received from the radio

int Protocol::receivedRobotPackets ( )
inline

Returns the number of packets received from the robot

Referenced by FRC_2014::interpretRobotPacket().

int Protocol::recvRobotPacketsSinceConnect ( )
inline

Returns the number of packets received since robot connection. This is used to get an real-time packet loss percentage. If we use the receivedRobotPackets() to do that, we risk having an unreal packet-loss ratio, since we would take into account the number of packets received before a reset or something.

Referenced by DriverStation::updatePacketLoss().

void Protocol::resetLossCounter ( )
inline

Ensures that the packet loss is calculated based on current values and not on previous robot packet loss data.

Referenced by readRobotPacket(), and DriverStation::resetRobot().

virtual void Protocol::restartRobotCode ( )
inlinevirtual

Restarts the robot code

Reimplemented in FRC_2015, and FRC_2014.

Referenced by DriverStation::restartRobotCode().

virtual QString Protocol::robotAddress ( )
inlinevirtual

Returns the IP address in which we should be able to find the robot.

If the returned address is invalid, unresolved (e.g. mDNS) or empty, the Driver Station will lookup the address, while broadcasting the generated robot packages until the lookup receives a response.

The default value that this function returns is 10.xx.yy.2

Reimplemented in FRC_2015, FRC_2014, and FRC_2016.

References config(), and DS::getStaticIP().

Referenced by DriverStation::defaultRobotAddress().

virtual int Protocol::robotFrequency ( )
inlinevirtual

Returns the number of packets that we send to the robot per second. For example, if we want to send 50 packets/second, the frequency should be set to 50.

Note
If you do not re-implement this function, then the Driver Station will not send data to the robot.

Reimplemented in FRC_2014, and FRC_2015.

Referenced by DriverStation::setProtocol().

virtual int Protocol::robotInputPort ( )
inlinevirtual

Returns the port in which we receive data from the robot.

Note
If you do not re-implement this function, the protocol will not be able to receive data from the robot.

Reimplemented in FRC_2014, and FRC_2015.

Referenced by DriverStation::setProtocol().

virtual int Protocol::robotOutputPort ( )
inlinevirtual

Returns the port in which we send data to the robot.

Note
If you do not re-implement this function, the protocol will not be able to send data to the robot.

Reimplemented in FRC_2014, and FRC_2015.

Referenced by DriverStation::setProtocol().

virtual DS::SocketType Protocol::robotSocketType ( )
inlinevirtual

Returns the socket type (UDP or TCP) used for client/robot interacion.

Note
If you do not re-implement this function, the Driver Station will asume that the robot uses UDP communications.
We recommend you to redefine this function in your protocol to avoid breaking it if the core library is changed.

Reimplemented in FRC_2015, and FRC_2014.

References DS::kSocketTypeUDP.

Referenced by DriverStation::setProtocol().

int Protocol::sentFMSPackets ( )
inline

Returns the number of packets sent to the FMS

int Protocol::sentRadioPackets ( )
inline

Returns the number of packets sent to the radio

int Protocol::sentRobotPackets ( )
inline

Returns the number of packets sent to the robot

Referenced by FRC_2014::getRobotPacket().

int Protocol::sentRobotPacketsSinceConnect ( )
inline

Returns the number of packets sent since robot connection. This is used to get an real-time packet loss percentage. If we use the sentRobotPackets() to do that, we risk having an unreal packet-loss ratio, since we would take into account the number of packets sent before robot connection (which can be a lot).

Referenced by DriverStation::updatePacketLoss().


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