WPILibC++ 2024.3.2
Simulator Device Framework

HAL Simulator Device Framework. More...

Enumerations

enum  HAL_SimValueDirection : int32_t { HAL_SimValueInput = 0 , HAL_SimValueOutput , HAL_SimValueBidir }
 Direction of a simulated value (from the perspective of user code). More...
 

Functions

HAL_SimDeviceHandle HAL_CreateSimDevice (const char *name)
 Creates a simulated device. More...
 
void HAL_FreeSimDevice (HAL_SimDeviceHandle handle)
 Frees a simulated device. More...
 
const char * HAL_GetSimDeviceName (HAL_SimDeviceHandle handle)
 Get the name of a simulated device. More...
 
HAL_SimValueHandle HAL_CreateSimValue (HAL_SimDeviceHandle device, const char *name, int32_t direction, const struct HAL_Value *initialValue)
 Creates a value on a simulated device. More...
 
HAL_SimValueHandle HAL_CreateSimValue (HAL_SimDeviceHandle device, const char *name, int32_t direction, const HAL_Value &initialValue)
 
HAL_SimValueHandle HAL_CreateSimValueInt (HAL_SimDeviceHandle device, const char *name, int32_t direction, int32_t initialValue)
 Creates an int value on a simulated device. More...
 
HAL_SimValueHandle HAL_CreateSimValueLong (HAL_SimDeviceHandle device, const char *name, int32_t direction, int64_t initialValue)
 Creates a long value on a simulated device. More...
 
HAL_SimValueHandle HAL_CreateSimValueDouble (HAL_SimDeviceHandle device, const char *name, int32_t direction, double initialValue)
 Creates a double value on a simulated device. More...
 
HAL_SimValueHandle HAL_CreateSimValueEnum (HAL_SimDeviceHandle device, const char *name, int32_t direction, int32_t numOptions, const char **options, int32_t initialValue)
 Creates an enumerated value on a simulated device. More...
 
HAL_SimValueHandle HAL_CreateSimValueEnumDouble (HAL_SimDeviceHandle device, const char *name, int32_t direction, int32_t numOptions, const char **options, const double *optionValues, int32_t initialValue)
 Creates an enumerated value on a simulated device with double values. More...
 
HAL_SimValueHandle HAL_CreateSimValueBoolean (HAL_SimDeviceHandle device, const char *name, int32_t direction, HAL_Bool initialValue)
 Creates a boolean value on a simulated device. More...
 
void HAL_GetSimValue (HAL_SimValueHandle handle, struct HAL_Value *value)
 Gets a simulated value. More...
 
HAL_Value HAL_GetSimValue (HAL_SimValueHandle handle)
 
int32_t HAL_GetSimValueInt (HAL_SimValueHandle handle)
 Gets a simulated value (int). More...
 
int64_t HAL_GetSimValueLong (HAL_SimValueHandle handle)
 Gets a simulated value (long). More...
 
double HAL_GetSimValueDouble (HAL_SimValueHandle handle)
 Gets a simulated value (double). More...
 
int32_t HAL_GetSimValueEnum (HAL_SimValueHandle handle)
 Gets a simulated value (enum). More...
 
HAL_Bool HAL_GetSimValueBoolean (HAL_SimValueHandle handle)
 Gets a simulated value (boolean). More...
 
void HAL_SetSimValue (HAL_SimValueHandle handle, const struct HAL_Value *value)
 Sets a simulated value. More...
 
void HAL_SetSimValue (HAL_SimValueHandle handle, const HAL_Value &value)
 
void HAL_SetSimValueInt (HAL_SimValueHandle handle, int value)
 Sets a simulated value (int). More...
 
void HAL_SetSimValueLong (HAL_SimValueHandle handle, int64_t value)
 Sets a simulated value (long). More...
 
void HAL_SetSimValueDouble (HAL_SimValueHandle handle, double value)
 Sets a simulated value (double). More...
 
void HAL_SetSimValueEnum (HAL_SimValueHandle handle, int32_t value)
 Sets a simulated value (enum). More...
 
void HAL_SetSimValueBoolean (HAL_SimValueHandle handle, HAL_Bool value)
 Sets a simulated value (boolean). More...
 
void HAL_ResetSimValue (HAL_SimValueHandle handle)
 Resets a simulated double or integral value to 0. More...
 

Detailed Description

HAL Simulator Device Framework.

This enables creating simulation-only variables for higher level device access. For example, a device such as a SPI gyro can expose angle and rate variables to enable direct access from simulation extensions or user test code instead of requiring that the SPI bit-level protocol be implemented in simulation code.

Enumeration Type Documentation

◆ HAL_SimValueDirection

enum HAL_SimValueDirection : int32_t

Direction of a simulated value (from the perspective of user code).

Enumerator
HAL_SimValueInput 

input to user code from the simulator

HAL_SimValueOutput 

output from user code to the simulator

HAL_SimValueBidir 

bidirectional between user code and simulator

Function Documentation

◆ HAL_CreateSimDevice()

HAL_SimDeviceHandle HAL_CreateSimDevice ( const char *  name)

Creates a simulated device.

The device name must be unique. 0 is returned if the device name already exists. If multiple instances of the same device are desired, recommend appending the instance/unique identifier in brackets to the base name, e.g. "device[1]".

0 is returned if not in simulation.

Parameters
namedevice name
Returns
simulated device handle

◆ HAL_CreateSimValue() [1/2]

HAL_SimValueHandle HAL_CreateSimValue ( HAL_SimDeviceHandle  device,
const char *  name,
int32_t  direction,
const HAL_Value initialValue 
)
inline

◆ HAL_CreateSimValue() [2/2]

HAL_SimValueHandle HAL_CreateSimValue ( HAL_SimDeviceHandle  device,
const char *  name,
int32_t  direction,
const struct HAL_Value initialValue 
)

Creates a value on a simulated device.

Returns 0 if not in simulation; this can be used to avoid calls to Set/Get functions.

Parameters
devicesimulated device handle
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated value handle

◆ HAL_CreateSimValueBoolean()

HAL_SimValueHandle HAL_CreateSimValueBoolean ( HAL_SimDeviceHandle  device,
const char *  name,
int32_t  direction,
HAL_Bool  initialValue 
)
inline

Creates a boolean value on a simulated device.

Returns 0 if not in simulation; this can be used to avoid calls to Set/Get functions.

Parameters
devicesimulated device handle
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated value handle

◆ HAL_CreateSimValueDouble()

HAL_SimValueHandle HAL_CreateSimValueDouble ( HAL_SimDeviceHandle  device,
const char *  name,
int32_t  direction,
double  initialValue 
)
inline

Creates a double value on a simulated device.

Returns 0 if not in simulation; this can be used to avoid calls to Set/Get functions.

Parameters
devicesimulated device handle
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated value handle

◆ HAL_CreateSimValueEnum()

HAL_SimValueHandle HAL_CreateSimValueEnum ( HAL_SimDeviceHandle  device,
const char *  name,
int32_t  direction,
int32_t  numOptions,
const char **  options,
int32_t  initialValue 
)

Creates an enumerated value on a simulated device.

Enumerated values are always in the range 0 to numOptions-1.

Returns 0 if not in simulation; this can be used to avoid calls to Set/Get functions.

Parameters
devicesimulated device handle
namevalue name
directioninput/output/bidir (from perspective of user code)
numOptionsnumber of enumerated value options (length of options)
optionsarray of option descriptions
initialValueinitial value (selection)
Returns
simulated value handle

◆ HAL_CreateSimValueEnumDouble()

HAL_SimValueHandle HAL_CreateSimValueEnumDouble ( HAL_SimDeviceHandle  device,
const char *  name,
int32_t  direction,
int32_t  numOptions,
const char **  options,
const double *  optionValues,
int32_t  initialValue 
)

Creates an enumerated value on a simulated device with double values.

Enumerated values are always in the range 0 to numOptions-1.

Returns 0 if not in simulation; this can be used to avoid calls to Set/Get functions.

Parameters
devicesimulated device handle
namevalue name
directioninput/output/bidir (from perspective of user code)
numOptionsnumber of enumerated value options (length of options)
optionsarray of option descriptions
optionValuesarray of option double values
initialValueinitial value (selection)
Returns
simulated value handle

◆ HAL_CreateSimValueInt()

HAL_SimValueHandle HAL_CreateSimValueInt ( HAL_SimDeviceHandle  device,
const char *  name,
int32_t  direction,
int32_t  initialValue 
)
inline

Creates an int value on a simulated device.

Returns 0 if not in simulation; this can be used to avoid calls to Set/Get functions.

Parameters
devicesimulated device handle
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated value handle

◆ HAL_CreateSimValueLong()

HAL_SimValueHandle HAL_CreateSimValueLong ( HAL_SimDeviceHandle  device,
const char *  name,
int32_t  direction,
int64_t  initialValue 
)
inline

Creates a long value on a simulated device.

Returns 0 if not in simulation; this can be used to avoid calls to Set/Get functions.

Parameters
devicesimulated device handle
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated value handle

◆ HAL_FreeSimDevice()

void HAL_FreeSimDevice ( HAL_SimDeviceHandle  handle)

Frees a simulated device.

This also allows the same device name to be used again. This also frees all the simulated values created on the device.

Parameters
handlesimulated device handle

◆ HAL_GetSimDeviceName()

const char * HAL_GetSimDeviceName ( HAL_SimDeviceHandle  handle)

Get the name of a simulated device.

Parameters
handlesimulated device handle
Returns
name of the simulated device

◆ HAL_GetSimValue() [1/2]

HAL_Value HAL_GetSimValue ( HAL_SimValueHandle  handle)
inline

◆ HAL_GetSimValue() [2/2]

void HAL_GetSimValue ( HAL_SimValueHandle  handle,
struct HAL_Value value 
)

Gets a simulated value.

Parameters
handlesimulated value handle
valuevalue (output parameter)

◆ HAL_GetSimValueBoolean()

HAL_Bool HAL_GetSimValueBoolean ( HAL_SimValueHandle  handle)
inline

Gets a simulated value (boolean).

Parameters
handlesimulated value handle
Returns
The current value

◆ HAL_GetSimValueDouble()

double HAL_GetSimValueDouble ( HAL_SimValueHandle  handle)
inline

Gets a simulated value (double).

Parameters
handlesimulated value handle
Returns
The current value

◆ HAL_GetSimValueEnum()

int32_t HAL_GetSimValueEnum ( HAL_SimValueHandle  handle)
inline

Gets a simulated value (enum).

Parameters
handlesimulated value handle
Returns
The current value

◆ HAL_GetSimValueInt()

int32_t HAL_GetSimValueInt ( HAL_SimValueHandle  handle)
inline

Gets a simulated value (int).

Parameters
handlesimulated value handle
Returns
The current value

◆ HAL_GetSimValueLong()

int64_t HAL_GetSimValueLong ( HAL_SimValueHandle  handle)
inline

Gets a simulated value (long).

Parameters
handlesimulated value handle
Returns
The current value

◆ HAL_ResetSimValue()

void HAL_ResetSimValue ( HAL_SimValueHandle  handle)

Resets a simulated double or integral value to 0.

Has no effect on other value types. Use this instead of Set(0) for resetting incremental sensor values like encoder counts or gyro accumulated angle to ensure correct behavior in a distributed system (e.g. WebSockets).

Parameters
handlesimulated value handle

◆ HAL_SetSimValue() [1/2]

void HAL_SetSimValue ( HAL_SimValueHandle  handle,
const HAL_Value value 
)
inline

◆ HAL_SetSimValue() [2/2]

void HAL_SetSimValue ( HAL_SimValueHandle  handle,
const struct HAL_Value value 
)

Sets a simulated value.

Parameters
handlesimulated value handle
valuethe value to set

◆ HAL_SetSimValueBoolean()

void HAL_SetSimValueBoolean ( HAL_SimValueHandle  handle,
HAL_Bool  value 
)
inline

Sets a simulated value (boolean).

Parameters
handlesimulated value handle
valuethe value to set

◆ HAL_SetSimValueDouble()

void HAL_SetSimValueDouble ( HAL_SimValueHandle  handle,
double  value 
)
inline

Sets a simulated value (double).

Parameters
handlesimulated value handle
valuethe value to set

◆ HAL_SetSimValueEnum()

void HAL_SetSimValueEnum ( HAL_SimValueHandle  handle,
int32_t  value 
)
inline

Sets a simulated value (enum).

Parameters
handlesimulated value handle
valuethe value to set

◆ HAL_SetSimValueInt()

void HAL_SetSimValueInt ( HAL_SimValueHandle  handle,
int  value 
)
inline

Sets a simulated value (int).

Parameters
handlesimulated value handle
valuethe value to set

◆ HAL_SetSimValueLong()

void HAL_SetSimValueLong ( HAL_SimValueHandle  handle,
int64_t  value 
)
inline

Sets a simulated value (long).

Parameters
handlesimulated value handle
valuethe value to set