A Python 3 implementation of the Distributed Interactive Simulation (DIS) 7 standard. Initially generated by xmlpg.
From source:
bash
pip install .
For developers of this library (This installs a symlink to the sources so they can be edited and referenced in tests
and examples
without a reinstall):
bash
pip install -e .
Run a receiver:
bash
cd examples
python3 dis_receiver.py
In another terminal, run the sender:
bash
python3 dis_sender.py
You should also see the traffic on the net in Wireshark on your localhost interface.
Press Ctrl+\
to stop the process.
You can auto generate API docs from the project source code:
bash
pip install pdoc
pdoc --html --html-dir docs opendis
The docs will be generated in the docs/opendis
folder.
I had issues properly reading data from a signal pdu, and tracked it down to code in the SignalPDu and VariableDatum classes. Specifically, the write_byte method defaults to a signed byte. I was able to successfully use the library after changing instances of "write_byte" to "write_unsigned_byte" and "read_byte" to "read_byte_unsinged".
Specifically on lines: 3605,3609,3618,3623,7144,7160
I also modified line 7141 to "write_unsigned_short" and line 7157 to "read_unsigned_short" The unsigned shorts were specifically required to get the proper value for larger data lengths.
I suspect all bytes should be unsigned, but have only tested those required for the signal pud.
awesome library guys and i am enjoying the flexibility that you have offered in higher level programming languages in python/chsarp.
is there any performance metrics between using python vs using c++ for this tool? i am currently developing a poc dis packet converter for testing purposes using this tool (which has been excellent.). my concern is throughput and latency - i will be testing the latency down the line but i was enquiring about if you have any known data/ advice about best methods for focusing on low latency tool when using this? - for development process i would rather stick with python/csharp opposed to c++ if i could but if there is a large impact then i may have to go down that route.
thanks guys
Are there any plans to make this a package installable via pip with versioned releases to help reliant projects pickup new fixes?
Python doesn't recognize the null()
function call.
Line 129 of dis7.py is 1st example.
python
for idx in range(0, self.recordLength):
element = null()
element.parse(inputStream)
self.iffData.append(element)
Is this supposed to be None?
VariableDatum
objects throw struct.error
when you try to store negative signed integers (e.g. -1
=b'\xff'
) in the variableData
field, then serialize.
This is the minimum viable product to reproduce the error
```py from opendis.dis7 import VariableDatum from opendis.DataOutputStream import DataOutputStream from io import BytesIO import struct
variable_datum = VariableDatum() data = list((b'\x00'4)+struct.pack('>i',-1)) variable_datum.variableData = data variable_datum.variableDatumLength = len(data)8 memoryStream = BytesIO() outputStream = DataOutputStream(memoryStream) variable_datum.serialize(outputStream) print(memoryStream.getvalue()) ```
I expect variable_datum
to serialize without an error, and for the final print
to display the serialized object (should be b'\x00\x00\x00\x00\x00\x00\[email protected]\x00\x00\x00\x00\xff\xff\xff\xff'
)
The script throws a struct.error
when variable_datum
tries to serialize.
This is the full error that is thrown when variable_datum
tries to serialize.
Traceback (most recent call last):
File "test.py", line 12, in <module>
variable_datum.serialize(outputStream)
File "C:\Users\e389403\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\dis7.py", line 3586, in serialize
outputStream.write_byte(self.variableData[x])
File "C:\Users\e389403\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\DataOutputStream.py", line 17, in write_byte
self.stream.write(struct.pack('b', val))
struct.error: byte format requires -128 <= number <= 127
From what I can gather, when serialize
is called:
- serialize()
is called
- for each byte in the variableData
bytes
object, it calls outputStream.write_byte()
)
This means that when it reaches b'\xff'
s, it tries to write 255
as a signed byte to outputStream
.
- thus it tries to call struct.pack('b', 255)
which results in an error, rightly so because it's out of range(0, 256)
.
When I changed dis7.py
line 3586 to outputStream.write_unsigned_byte(self.variableData[x])
, then I got the expected behavior.
Signed integers actually parse without error. This makes sense, since inputStream.read_byte()
is used to parse the bytes when forming the variableData
list.
```py from opendis.dis7 import VariableDatum from opendis.DataInputStream import DataInputStream from io import BytesIO
memoryStream = BytesIO(b'\x00\x00\x00\x00\x00\x00\[email protected]\x00\x00\x00\x00\xff\xff\xff\xff') inputStream = DataInputStream(memoryStream) new_variable_datum = VariableDatum() new_variable_datum.parse(inputStream) print(new_variable_datum.variableData) # [0, 0, 0, 0, -1, -1, -1, -1] ```
I am struggling to find an example of how to use a DataPdu. The nature of python makes it difficult to read your code and decipher how to create a simple DataPdu to send a simple integer as the variable length data.
This may be because DataPdu
is unfinished. Could you
DataPdu
with a variable length record to send an integer as the payloadAn open-source implementation of the IEEE-1278.1 Distributed Interactive Simulation (DIS) application protocol
GitHub Repositorydis python protocol