1414from time import sleep
1515from typing import Tuple , Dict , Callable
1616
17- from .api import API , DatarefValueType , Dataref , Command
17+ from .api import API , CONNECTION_STATUS , DatarefValueType , Dataref , Command
1818
1919# local logging
2020logger = logging .getLogger (__name__ )
@@ -218,9 +218,13 @@ def read_monitored_dataref_values(self):
218218 Raises:
219219 XPlaneTimeout: [description]
220220 """
221+ if self .status not in [CONNECTION_STATUS .LISTENING_FOR_DATA , CONNECTION_STATUS .RECEIVING_DATA ]:
222+ self .status = CONNECTION_STATUS .LISTENING_FOR_DATA
221223 try :
222224 # Receive packet
223225 data , addr = self .socket .recvfrom (1472 ) # maximum bytes of an RREF answer X-Plane will send (Ethernet MTU - IP hdr - UDP hdr)
226+ if self .status != CONNECTION_STATUS .RECEIVING_DATA :
227+ self .status = CONNECTION_STATUS .RECEIVING_DATA
224228 # Decode Packet
225229 retvalues = {}
226230 # * Read the Header "RREFO".
@@ -244,6 +248,8 @@ def read_monitored_dataref_values(self):
244248 self .execute_callbacks (dataref = self .datarefs [idx ], value = value )
245249 self .xplaneValues .update (retvalues )
246250 except :
251+ if self .status != CONNECTION_STATUS .LISTENING_FOR_DATA :
252+ self .status = CONNECTION_STATUS .LISTENING_FOR_DATA
247253 raise XPlaneTimeout
248254 return self .xplaneValues
249255
@@ -254,6 +260,7 @@ def udp_listener_running(self) -> bool:
254260 def udp_listener (self ):
255261 logger .info ("starting udp listener.." )
256262
263+ self .status = CONNECTION_STATUS .UDP_LISTENER_RUNNING
257264 while self .udp_listener_running :
258265 try :
259266 data = self .read_monitored_dataref_values ()
0 commit comments