xrp style wpilib comms
Loading...
Searching...
No Matches
XSWC Class Reference

top level class for the XRP-style WPILib communications This class handles the UDP communication, message parsing, and data retrieval/sending. More...

#include <xrp-style-wpilib-comms.h>

Classes

class  MessageTypeFactory
 Factory class to create message types based on their tag. This is only used internally by the XSWC class. More...
 

Public Member Functions

bool getData_xrp_motor (xrp_motor_t &data, const uint8_t id)
 Retrieves data for a specific motor by ID.
 
float getValue_xrp_motor (const uint8_t id)
 Retrieves the value of a specific motor by ID.
 
bool getData_xrp_servo (xrp_servo_t &data, const uint8_t id)
 Retrieves data for a specific servo by ID.
 
float getValue_xrp_servo (const uint8_t id)
 Retrieves the value of a specific servo by ID.
 
bool getData_xrp_dio (xrp_dio_t &data, const uint8_t id)
 Retrieves data for a specific digital input/output by ID.
 
bool getValue_xrp_dio (const uint8_t id)
 Retrieves the value of a specific digital input/output by ID.
 
bool getData_xrp_analog (xrp_analog_t &data, const uint8_t id)
 Retrieves data for a specific analog input by ID.
 
float getValue_xrp_analog (const uint8_t id)
 Retrieves the value of a specific analog input by ID.
 
bool sendData_xrp_dio (const xrp_dio_t &data, bool checkUniqueness=false)
 Sends data for a specific digital input by ID.
 
bool sendValue_xrp_dio (const uint8_t id, bool value, bool checkUniqueness=false)
 Send a boolean value for a specific digital input/output by ID.
 
bool sendData_xrp_analog (const xrp_analog_t &data, bool checkUniqueness=false)
 Sends data for a specific analog input by ID.
 
bool sendValue_xrp_analog (const uint8_t id, float value, bool checkUniqueness=false)
 Sends a float value for a specific analog input by ID.
 
bool sendData_xrp_encoder (const xrp_encoder_t &data, bool checkUniqueness=false)
 Sends data for a specific encoder by ID.
 
bool sendValue_xrp_encoder (const uint8_t id, int32_t count, int32_t period=0, int32_t divisor=1, bool checkUniqueness=false)
 Sends values for a specific encoder by ID.
 
bool sendData_xrp_gyro (const xrp_gyro_t &data, bool checkUniqueness=false)
 Sends gyroscope data.
 
bool sendValue_xrp_gyro (float xRate, float yRate, float zRate, float roll, float pitch, float yaw, bool checkUniqueness=false)
 Sends gyroscope values.
 
bool sendData_xrp_accel (const xrp_accel_t &data, bool checkUniqueness=false)
 Sends accelerometer data.
 
bool sendValue_xrp_accel (const uint8_t id, float xAccel, float yAccel, float zAccel, bool checkUniqueness=false)
 Sends accelerometer values.
 
 XSWC ()
 constructor of XSWC class, use the global xswc instance to access this class
 
bool begin (void(*_receiveCallback)(void), void(*_sendCallback)(void), uint16_t port=3540)
 begin udp communication on given port
 
bool begin (const char *ssid, const char *password, void(*_receiveCallback)(void), void(*_sendCallback)(void), const char *hostname="XRP-XSWC", uint16_t port=3540)
 connect to a WiFi network and begin udp communication on given port
 
bool update ()
 call this in void loop()
 
bool isConnected ()
 
bool isEnabled ()
 
bool isConnectedAndEnabled ()
 

Public Attributes

unsigned long TIMEOUT_MS = 1000
 
unsigned long MIN_UPDATE_TIME_MS = 50
 
bool useAP = false
 set to true before calling begin() to skip straight to creating an Access Point
 

Protected Member Functions

template<typename T >
bool getData (T &data, const uint8_t id)
 
template<typename T >
bool sendData (T data, bool checkUniqueness)
 
boolean processReceivedBufferIntoMessages (char *buffer, int length)
 
int processMessagesIntoBufferToSend (char *buffer, int length)
 

Protected Attributes

WiFiUDP udp
 
std::vector< MessageType * > receivedMessages
 
std::vector< MessageType * > sentMessages
 
boolean cmdEnable = false
 
unsigned long millisWhenLastMessageReceived = -TIMEOUT_MS
 
unsigned long millisWhenLastSent = -MIN_UPDATE_TIME_MS
 
uint16_t txSeq = 0
 
char rxBuf [UDP_PACKET_MAX_SIZE_XRP+1]
 
char txBuf [UDP_PACKET_MAX_SIZE_XRP+1]
 
bool connectedToRemote = false
 
IPAddress udpRemoteAddr = IPAddress()
 
int32_t udpRemotePort = -1
 
void(* sendCallback )(void)
 
void(* receiveCallback )(void)
 

Detailed Description

top level class for the XRP-style WPILib communications This class handles the UDP communication, message parsing, and data retrieval/sending.

Constructor & Destructor Documentation

◆ XSWC()

XSWC::XSWC ( )

constructor of XSWC class, use the global xswc instance to access this class

Member Function Documentation

◆ begin() [1/2]

bool XSWC::begin ( const char * ssid,
const char * password,
void(* _receiveCallback )(void),
void(* _sendCallback )(void),
const char * hostname = "XRP-XSWC",
uint16_t port = 3540 )

connect to a WiFi network and begin udp communication on given port

Note
if connection fails, it will create a WiFi network named "XRP-XSWC-AP" with password "password"
Parameters
ssidthe SSID of the WiFi network to connect to
passwordthe password for the WiFi network
_receiveCallbacka function to call when data is received (add getData methods to the function to retrieve the data)
_sendCallbacka function to call to collect data to send (add sendData methods to the function to send the data)
hostnamethe hostname to use for the WiFi connection, default "XRP-XSWC"
portthe UDP port to use for communication, default 3540
Return values
(bool)true if connection was successful, false otherwise

◆ begin() [2/2]

bool XSWC::begin ( void(* _receiveCallback )(void),
void(* _sendCallback )(void),
uint16_t port = 3540 )

begin udp communication on given port

Note
YOU PROBABLY DO NOT WANT TO USE THIS FUNCTION begin() without a network name and password will not connect to a WiFi network, if you use this method, you must connect to a WiFi network before calling this method.
Parameters
_receiveCallbacka function to call when data is received (add getData methods to the function to retrieve the data)
_sendCallbacka function to call to collect data to send (add sendData methods to the function to send the data)
portudp port, default 3540
Return values
(bool)true if connection was successful, false otherwise

◆ getData()

template<typename T >
bool XSWC::getData ( T & data,
const uint8_t id )
inlineprotected

◆ getData_xrp_analog()

bool XSWC::getData_xrp_analog ( xrp_analog_t & data,
const uint8_t id )
inline

Retrieves data for a specific analog input by ID.

Parameters
dataa reference to an xrp_analog_t structure to fill with data
idthe ID of the analog input
Return values
(bool)true if data was found, false otherwise

◆ getData_xrp_dio()

bool XSWC::getData_xrp_dio ( xrp_dio_t & data,
const uint8_t id )
inline

Retrieves data for a specific digital input/output by ID.

Parameters
dataa reference to an xrp_dio_t structure to fill with data
idthe ID of the digital input/output
Return values
(bool)true if data was found, false otherwise

◆ getData_xrp_motor()

bool XSWC::getData_xrp_motor ( xrp_motor_t & data,
const uint8_t id )
inline

Retrieves data for a specific motor by ID.

Parameters
dataa reference to an xrp_motor_t structure to fill with data
idthe ID of the motor
Return values
(bool)true if data was found, false otherwise

◆ getData_xrp_servo()

bool XSWC::getData_xrp_servo ( xrp_servo_t & data,
const uint8_t id )
inline

Retrieves data for a specific servo by ID.

Parameters
dataa reference to an xrp_servo_t structure to fill with data
idthe ID of the servo
Return values
(bool)true if data was found, false otherwise

◆ getValue_xrp_analog()

float XSWC::getValue_xrp_analog ( const uint8_t id)
inline

Retrieves the value of a specific analog input by ID.

Note
If the analog input is not found, it returns 0.0.
Parameters
idthe ID of the analog input
Return values
(float)the value of the analog input, or 0.0 if not found

◆ getValue_xrp_dio()

bool XSWC::getValue_xrp_dio ( const uint8_t id)
inline

Retrieves the value of a specific digital input/output by ID.

Note
If the digital input/output is not found, it returns false.
Parameters
idthe ID of the digital input/output
Return values
(bool)true if the value is 1 (true), false if the value is 0 (false) or not found

◆ getValue_xrp_motor()

float XSWC::getValue_xrp_motor ( const uint8_t id)
inline

Retrieves the value of a specific motor by ID.

Note
If the motor is not found, it returns 0.0.
Parameters
idthe ID of the motor
Return values
(float)the value of the motor, or 0.0 if not found

◆ getValue_xrp_servo()

float XSWC::getValue_xrp_servo ( const uint8_t id)
inline

Retrieves the value of a specific servo by ID.

Note
If the servo is not found, it returns 0.0.
Parameters
idthe ID of the servo
Return values
(float)the value of the servo, or 0.0 if not found

◆ isConnected()

bool XSWC::isConnected ( )

◆ isConnectedAndEnabled()

bool XSWC::isConnectedAndEnabled ( )

◆ isEnabled()

bool XSWC::isEnabled ( )

◆ processMessagesIntoBufferToSend()

int XSWC::processMessagesIntoBufferToSend ( char * buffer,
int length )
protected

◆ processReceivedBufferIntoMessages()

boolean XSWC::processReceivedBufferIntoMessages ( char * buffer,
int length )
protected

◆ sendData()

template<typename T >
bool XSWC::sendData ( T data,
bool checkUniqueness )
inlineprotected

◆ sendData_xrp_accel()

bool XSWC::sendData_xrp_accel ( const xrp_accel_t & data,
bool checkUniqueness = false )
inline

Sends accelerometer data.

Note
XRP accelerometer data doesn't have an ID, so only one accelerometer can be transmitted
Parameters
datathe xrp_accel_t structure containing the accelerometer data
checkUniquenessIf true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ sendData_xrp_analog()

bool XSWC::sendData_xrp_analog ( const xrp_analog_t & data,
bool checkUniqueness = false )
inline

Sends data for a specific analog input by ID.

Parameters
datathe xrp_analog_t structure containing the data to send (including ID)
checkUniquenessIf true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ sendData_xrp_dio()

bool XSWC::sendData_xrp_dio ( const xrp_dio_t & data,
bool checkUniqueness = false )
inline

Sends data for a specific digital input by ID.

Parameters
datathe xrp_dio_t structure containing the data to send (including ID)
checkUniquenessif true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ sendData_xrp_encoder()

bool XSWC::sendData_xrp_encoder ( const xrp_encoder_t & data,
bool checkUniqueness = false )
inline

Sends data for a specific encoder by ID.

Parameters
datathe xrp_encoder_t structure containing the data to send (including ID)
checkUniquenessIf true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ sendData_xrp_gyro()

bool XSWC::sendData_xrp_gyro ( const xrp_gyro_t & data,
bool checkUniqueness = false )
inline

Sends gyroscope data.

Note
XRP gyroscope data doesn't have an ID, so only one gyroscope can be transmitted
Parameters
datathe xrp_gyro_t structure containing the gyroscope data
checkUniquenessIf true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ sendValue_xrp_accel()

bool XSWC::sendValue_xrp_accel ( const uint8_t id,
float xAccel,
float yAccel,
float zAccel,
bool checkUniqueness = false )
inline

Sends accelerometer values.

Note
XRP accelerometer data doesn't have an ID, so only one accelerometer can be transmitted
Parameters
xAccel(float) acceleration in X/forward direction
yAccel(float) acceleration in Y/left direction
zAccel(float) acceleration in Z/up direction
checkUniquenessIf true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ sendValue_xrp_analog()

bool XSWC::sendValue_xrp_analog ( const uint8_t id,
float value,
bool checkUniqueness = false )
inline

Sends a float value for a specific analog input by ID.

Parameters
idthe ID of the analog input
value(float) the value to send
checkUniquenessIf true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ sendValue_xrp_dio()

bool XSWC::sendValue_xrp_dio ( const uint8_t id,
bool value,
bool checkUniqueness = false )
inline

Send a boolean value for a specific digital input/output by ID.

Parameters
idthe ID of the digital input/output
value(bool) the boolean value to send (true or false)
checkUniquenessIf true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ sendValue_xrp_encoder()

bool XSWC::sendValue_xrp_encoder ( const uint8_t id,
int32_t count,
int32_t period = 0,
int32_t divisor = 1,
bool checkUniqueness = false )
inline

Sends values for a specific encoder by ID.

Parameters
idthe ID of the encoder
count(int32_t) count of encoder ticks
period(int32_t) encoder period
divisor(int32_t) encoder divisor
checkUniquenessIf true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ sendValue_xrp_gyro()

bool XSWC::sendValue_xrp_gyro ( float xRate,
float yRate,
float zRate,
float roll,
float pitch,
float yaw,
bool checkUniqueness = false )
inline

Sends gyroscope values.

Note
XRP gyroscope data doesn't have an ID, so only one gyroscope can be transmitted
Parameters
xRate(float) gyro rate around X/roll axis
yRate(float) gyro rate around Y/pitch axis
zRate(float) gyro rate around Z/yaw axis
roll(float) angle around X axis
pitch(float) angle around Y axis
yaw(float) angle around Z axis
checkUniquenessIf true, it checks if a message with the same ID already exists in the sent messages, default false
Return values
(bool)true if data was queued successfully, false otherwise

◆ update()

bool XSWC::update ( )

call this in void loop()

Return values
trueif data was just received

Member Data Documentation

◆ cmdEnable

boolean XSWC::cmdEnable = false
protected

◆ connectedToRemote

bool XSWC::connectedToRemote = false
protected

◆ millisWhenLastMessageReceived

unsigned long XSWC::millisWhenLastMessageReceived = -TIMEOUT_MS
protected

◆ millisWhenLastSent

unsigned long XSWC::millisWhenLastSent = -MIN_UPDATE_TIME_MS
protected

◆ MIN_UPDATE_TIME_MS

unsigned long XSWC::MIN_UPDATE_TIME_MS = 50

◆ receiveCallback

void(* XSWC::receiveCallback) (void)
protected

◆ receivedMessages

std::vector<MessageType*> XSWC::receivedMessages
protected

◆ rxBuf

char XSWC::rxBuf[UDP_PACKET_MAX_SIZE_XRP+1]
protected

◆ sendCallback

void(* XSWC::sendCallback) (void)
protected

◆ sentMessages

std::vector<MessageType*> XSWC::sentMessages
protected

◆ TIMEOUT_MS

unsigned long XSWC::TIMEOUT_MS = 1000

◆ txBuf

char XSWC::txBuf[UDP_PACKET_MAX_SIZE_XRP+1]
protected

◆ txSeq

uint16_t XSWC::txSeq = 0
protected

◆ udp

WiFiUDP XSWC::udp
protected

◆ udpRemoteAddr

IPAddress XSWC::udpRemoteAddr = IPAddress()
protected

◆ udpRemotePort

int32_t XSWC::udpRemotePort = -1
protected

◆ useAP

bool XSWC::useAP = false

set to true before calling begin() to skip straight to creating an Access Point


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