UDP
udp
X-Plane access through UDP messages
UDP interface is limited to 1. Asking for dataref values, one at a time, returned as a float number. 2. Setting single dataref value in simulator ("write"). 3. Asking for execution of a command.
Classes:
-
XPUDPAPI–Get data from XPlane via network.
XPUDPAPI
XPUDPAPI(**kwargs)
flowchart TD
xpwebapi.udp.XPUDPAPI[XPUDPAPI]
xpwebapi.api.API[API]
xpwebapi.api.API --> xpwebapi.udp.XPUDPAPI
click xpwebapi.udp.XPUDPAPI href "" "xpwebapi.udp.XPUDPAPI"
click xpwebapi.api.API href "" "xpwebapi.api.API"
Get data from XPlane via network. Use a class to implement RAI Pattern for the UDP socket.
Methods:
-
abort–Signal the listener before immediately closing its socket.
-
add_callback–Add callback function to set of callback functions
-
beacon_callback–Callback waits a little bit before shutting down websocket handler on beacon miss.
-
changed–If rounding applies, determine if value has changed according to its rounding.
-
close–Stop monitored datarefs and close the UDP socket.
-
command–Create Command with current API
-
dataref–Create Dataref with current API
-
dataref_value–Returns Dataref value from simulator
-
execute_callbacks–Execute list of callback functions, all with same arguments passed as keyword arguments
-
execute_command–Execute command
-
monitor_dataref–Starts monitoring single dataref.
-
read_monitored_dataref_values–Do a single read and populate dataref with values.
-
set_network–Set network and API parameters for connection
-
set_roundings–Add rounding to simulator variable value.
-
simple_connection_probe–Exeprimental
-
start–Start UDP monitoring
-
stop–Stop UDP monitoring
-
unmonitor_datarefs–Stops monitoring supplied datarefs.
-
write_dataref–Write Dataref value to X-Plane if Dataref is writable
Attributes:
-
connected(bool) –Whether X-Plane API is reachable through this API
-
rest_url(str) –URL for the REST API
-
status(CONNECTION_STATUS) –Connection status
-
status_str(str) –Connection status as a string
-
use_rest(bool) –Should use REST API for some purpose
connected
property
connected: bool
Whether X-Plane API is reachable through this API
rest_url
property
rest_url: str
URL for the REST API
status_str
property
status_str: str
Connection status as a string
use_rest
property
writable
use_rest: bool
Should use REST API for some purpose
abort
abort() -> None
Signal the listener before immediately closing its socket.
add_callback
add_callback(callback: Callable)
Add callback function to set of callback functions
Please note that in the case of UDP, callback is called for each value it received, whether the value has changed or not.
Parameters:
-
(callbackCallable) –Callback function
beacon_callback
beacon_callback(connected: bool, beacon_data: BeaconData, same_host: bool)
Callback waits a little bit before shutting down websocket handler on beacon miss. Starts or make sure it is running on beacon hit.
Parameters:
-
(connectedbool) –Whether beacon is received
-
(beacon_dataBeaconData) –Beacon data
-
(same_hostbool) –Whether beacon is issued from same host as host running the monitor
changed
changed(dataref, value) -> bool
If rounding applies, determine if value has changed according to its rounding.
close
close() -> None
Stop monitored datarefs and close the UDP socket.
command
Create Command with current API
Parameters:
-
(pathstr) –Command "path"
Returns:
-
Command(Command) –Created command
dataref
Create Dataref with current API
Parameters:
-
(pathstr) –Dataref "path"
-
(auto_savebool, default:False) –Save dataref back to X-Plane if value has changed and writable (default:
False)
Returns:
-
Dataref(Dataref) –Created dataref
dataref_value
Returns Dataref value from simulator
Parameters:
-
(datarefDataref) –Dataref to get the value from
Returns:
-
DatarefReadResult(DatarefReadResult) –Value of dataref.
execute_callbacks
execute_callbacks(**kwargs) -> bool
Execute list of callback functions, all with same arguments passed as keyword arguments
returns
bool: Whether error reported during execution
execute_command
Execute command
Parameters:
-
(commandCommand) –Command to execute
-
(durationfloat, default:0.0) –Duration of execution for long commands (default:
0.0)
Returns:
-
bool(bool) –[description]
monitor_dataref
Starts monitoring single dataref.
[description]
Parameters:
-
(datarefDataref) –Dataref to monitor
Returns:
-
bool | int–bool if fails
-
bool | int–request id if succeeded
read_monitored_dataref_values
read_monitored_dataref_values() -> dict
Do a single read and populate dataref with values.
This function should be called at regular intervals to collect all requested datarefs. (A single read returns about 15 values.)
Returns:
-
dict(dict) –{path: value} for received datarefs so far.
Raises:
-
XPlaneTimeout–[description]
set_network
set_network(host: str, port: int, api: str, api_version: str) -> bool
Set network and API parameters for connection
Parameters:
-
(hoststr) –Host name or IP address
-
(portint) –TCP port number for API
-
(apistr) –API root path, starts with /.
-
(api_versionstr) –API version string, starts with /, appended to api string to form full path to API.
Returns:
-
bool(bool) –True if some network parameter has changed
set_roundings
set_roundings(roundings)
Add rounding to simulator variable value. Rounding is applied to value before it is sent to callback function.
simple_connection_probe
simple_connection_probe() -> bool
Exeprimental
Do we receive a UPD message within TIMEOUT seconds?
returns:
(bool) UPD message recieved
start
start(release: bool = True)
Start UDP monitoring
stop
stop(timeout_seconds: float | None = None)
Stop UDP monitoring
unmonitor_datarefs
Stops monitoring supplied datarefs.
[description]
Parameters:
-
(datarefsdict) –{path: Dataref} dictionary of datarefs
-
(reasonstr | None, default:None) –Documentation only string to identify call to function.
Returns:
-
tuple[int | bool, dict]–tuple[int | bool, dict]: [description]