Skip to content

Commit

Permalink
Merge pull request #6 from julianneswinoga/bugfix/js/fix-windows-2
Browse files Browse the repository at this point in the history
Bugfix/js/fix windows 2
  • Loading branch information
julianneswinoga authored Mar 13, 2023
2 parents 0884aef + 8e50e3f commit 40f2845
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 86 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ def fdm_callback(fdm_data, event_pipe):
return fdm_data # return the whole structure

"""
Start FlightGear with `--native-fdm=socket,out,30,,5501,udp --native-fdm=socket,in,30,,5502,udp`
Start FlightGear with `--native-fdm=socket,out,30,localhost,5501,udp --native-fdm=socket,in,30,localhost,5502,udp`
(you probably also want `--fdm=null` and `--max-fps=30` to stop the simulation fighting with
these external commands)
"""
fdm_conn = FDMConnection(fdm_version=24) # May need to change version from 24
fdm_event_pipe = fdm_conn.connect_rx('localhost', 5501, fdm_callback)
fdm_conn.connect_tx('localhost', 5502)
fdm_conn.start() # Start the FDM RX/TX loop

phi_rad_parent = 0.0
while True:
phi_rad_parent += 0.1
# could also do `fdm_conn.event_pipe.parent_send` so you just need to pass around `fdm_conn`
fdm_event_pipe.parent_send((phi_rad_parent,)) # send tuple
time.sleep(0.5)
if __name__ == '__main__': # NOTE: This is REQUIRED on Windows!
fdm_conn = FDMConnection(fdm_version=24) # May need to change version from 24
fdm_event_pipe = fdm_conn.connect_rx('localhost', 5501, fdm_callback)
fdm_conn.connect_tx('localhost', 5502)
fdm_conn.start() # Start the FDM RX/TX loop

phi_rad_parent = 0.0
while True:
phi_rad_parent += 0.1
# could also do `fdm_conn.event_pipe.parent_send` so you just need to pass around `fdm_conn`
fdm_event_pipe.parent_send((phi_rad_parent,)) # send tuple
time.sleep(0.5)
```

Supported interfaces:
Expand Down
12 changes: 10 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from typing import Any, Tuple, Optional, Callable
from pprint import pformat
from construct import (Struct, FormatField, Subconstruct, Array, Enum, Const, Padded, Pass, Transformed, Flag, Renamed,
BitsInteger)
BitsInteger, Bytes)
from importlib import import_module
from docutils import nodes
from docutils.parsers.rst import Directive
Expand Down Expand Up @@ -116,7 +116,15 @@ def represent_object(o: Any, ident_level: int = 0, context_str: Optional[str] =
else:
pp_str = f'{type(o).__name__}{special_str}'
elif isinstance(o, BitsInteger):
pp_str = 'Bits'
if o.length == 1:
pp_str = 'Bit'
else:
pp_str = f'{o.length} Bits'
elif isinstance(o, Bytes):
if o.length == 1:
pp_str = 'Byte'
else:
pp_str = f'{o.length} Bytes'
elif isinstance(o, Pass.__class__):
pp_str = '' # Pass is a do-nothing. No information to represent
elif isinstance(o, Flag.__class__):
Expand Down
2 changes: 1 addition & 1 deletion docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Quick-Start

#. If you're using the FDM interface:

* ``--fdm=null --max-fps=30 --native-fdm=socket,out,30,,5501,udp --native-fdm=socket,in,30,,5502,udp``
* ``--fdm=null --max-fps=30 --native-fdm=socket,out,30,localhost,5501,udp --native-fdm=socket,in,30,localhost,5502,udp``

* the ``30`` in the arguments must match, so that the IO and the framerate are the same

Expand Down
25 changes: 13 additions & 12 deletions examples/simple_ctrls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ def ctrls_callback(ctrls_data, event_pipe):
return ctrls_data # return the whole structure

"""
Start FlightGear with `--native-ctrls=socket,out,30,,5503,udp --native-ctrls=socket,in,30,,5504,udp`
Start FlightGear with `--native-ctrls=socket,out,30,localhost,5503,udp --native-ctrls=socket,in,30,localhost,5504,udp`
"""
ctrls_conn = CtrlsConnection(ctrls_version=27)
ctrls_event_pipe = ctrls_conn.connect_rx('localhost', 5503, ctrls_callback)
ctrls_conn.connect_tx('localhost', 5504)
ctrls_conn.start() # Start the Ctrls RX/TX loop
if __name__ == '__main__': # NOTE: This is REQUIRED on Windows!
ctrls_conn = CtrlsConnection(ctrls_version=27)
ctrls_event_pipe = ctrls_conn.connect_rx('localhost', 5503, ctrls_callback)
ctrls_conn.connect_tx('localhost', 5504)
ctrls_conn.start() # Start the Ctrls RX/TX loop

gear_down_parent = True
time.sleep(2)
while True:
# could also do `ctrls_conn.event_pipe.parent_send` so you just need to pass around `ctrls_conn`
ctrls_event_pipe.parent_send((gear_down_parent,)) # send tuple
gear_down_parent = not gear_down_parent # Flip gear state
time.sleep(10)
gear_down_parent = True
time.sleep(2)
while True:
# could also do `ctrls_conn.event_pipe.parent_send` so you just need to pass around `ctrls_conn`
ctrls_event_pipe.parent_send((gear_down_parent,)) # send tuple
gear_down_parent = not gear_down_parent # Flip gear state
time.sleep(10)
23 changes: 12 additions & 11 deletions examples/simple_fdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ def fdm_callback(fdm_data, event_pipe):
return fdm_data # return the whole structure

"""
Start FlightGear with `--native-fdm=socket,out,30,,5501,udp --native-fdm=socket,in,30,,5502,udp`
Start FlightGear with `--native-fdm=socket,out,30,localhost,5501,udp --native-fdm=socket,in,30,localhost,5502,udp`
(you probably also want `--fdm=null` and `--max-fps=30` to stop the simulation fighting with
these external commands)
"""
fdm_conn = FDMConnection(fdm_version=24) # May need to change version from 24
fdm_event_pipe = fdm_conn.connect_rx('localhost', 5501, fdm_callback)
fdm_conn.connect_tx('localhost', 5502)
fdm_conn.start() # Start the FDM RX/TX loop
if __name__ == '__main__': # NOTE: This is REQUIRED on Windows!
fdm_conn = FDMConnection(fdm_version=24) # May need to change version from 24
fdm_event_pipe = fdm_conn.connect_rx('localhost', 5501, fdm_callback)
fdm_conn.connect_tx('localhost', 5502)
fdm_conn.start() # Start the FDM RX/TX loop

phi_rad_parent = 0.0
while True:
phi_rad_parent += 0.1
# could also do `fdm_conn.event_pipe.parent_send` so you just need to pass around `fdm_conn`
fdm_event_pipe.parent_send((phi_rad_parent,)) # send tuple
time.sleep(0.5)
phi_rad_parent = 0.0
while True:
phi_rad_parent += 0.1
# could also do `fdm_conn.event_pipe.parent_send` so you just need to pass around `fdm_conn`
fdm_event_pipe.parent_send((phi_rad_parent,)) # send tuple
time.sleep(0.5)
8 changes: 4 additions & 4 deletions flightgear_python/ctrls_v27.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
See https://github.com/FlightGear/flightgear/blob/619226e9d069d2a3e8ebf8658fb5441ca8a2c233/src/Network/net_ctrls.hxx
"""

from construct import Array, Enum, Const, Bytes, Int32ub, Float64b, BitStruct, Flag, BitsInteger
from construct import Array, Enum, Const, Bytes, Int32ub, Float64b, BitStruct, Bit, BitsInteger

RESERVED_SPACE = 25 #: Constant value from define

Expand Down Expand Up @@ -81,9 +81,9 @@
'speedup': Int32ub, # integer speedup multiplier
'freeze': BitStruct( # Default is big-endian
other=BitsInteger((Int32ub.sizeof() * 8) - 3), # Rest of uint32 minus the 3 flags
fuel=Flag,
position=Flag,
master=Flag,
fuel=Bit,
position=Bit,
master=Bit,
),
'_reserved': Bytes(Int32ub.length * RESERVED_SPACE),
}
6 changes: 3 additions & 3 deletions flightgear_python/fg_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import socket
import sys
import re
import multiprocessing as mp
import multiprocess as mp
from typing import Callable, Optional, Tuple, Any, Dict, Union, ByteString

from construct import ConstError, Struct, Container
Expand Down Expand Up @@ -48,7 +48,7 @@ def connect_rx(self, fg_host: str, fg_port: int, rx_cb: rx_callback_type) -> Eve
:param fg_host: IP address of FG (usually localhost)
:param fg_port: Port of the output socket (i.e. the ``5501`` from\
``--native-fdm=socket,out,30,,5501,udp``)
``--native-fdm=socket,out,30,localhost,5501,udp``)
:param rx_cb: Callback function, called whenever we receive data from FG.\
Function signature should follow :attr:`rx_callback_type`
:return: ``EventPipe`` so that data can be passed from the parent process\
Expand All @@ -72,7 +72,7 @@ def connect_tx(self, fg_host: str, fg_port: int):
:param fg_host: IP address of FG (usually localhost)
:param fg_port: Port of the input socket (i.e. the ``5502`` from\
``--native-fdm=socket,in,,,5502,udp``)
``--native-fdm=socket,in,30,localhost,5502,udp``)
"""
self.fg_tx_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.fg_tx_addr = (fg_host, fg_port)
Expand Down
2 changes: 1 addition & 1 deletion flightgear_python/general_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
non-FlightGear-specific utility functionality
"""
import multiprocessing as mp
import multiprocess as mp
from typing import Any, Union, ByteString


Expand Down
Loading

0 comments on commit 40f2845

Please sign in to comment.