Python implementation of the IEEE-1278.1 Distributed Interactive Simulation (DIS) application protocol v7

open-dis, updated 🕥 2023-01-10 04:24:39

open-dis-python

Build Status PyPI Version

A Python 3 implementation of the Distributed Interactive Simulation (DIS) 7 standard. Initially generated by xmlpg.

Library installation

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 examples

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.

Documentation

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.

Issues

signed bytes in signal pdu

opened on 2023-03-31 20:29:44 by HalRules

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.

not an issue but a question surrounding performance

opened on 2023-03-29 19:31:35 by rozzrr

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

Will this become a Pip package?

opened on 2023-01-11 09:52:49 by ztolley

Are there any plans to make this a package installable via pip with versioned releases to help reliant projects pickup new fixes?

null() Function Call?

opened on 2020-06-01 17:43:19 by treybgreen

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 object cannot hold negative signed integers

opened on 2020-05-22 17:05:29 by DuffyScottC

VariableDatum objects throw struct.error when you try to store negative signed integers (e.g. -1=b'\xff') in the variableData field, then serialize.

MVP

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()) ```

Expected Behavior

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')

Actual Behavior

The script throws a struct.error when variable_datum tries to serialize.

Full error

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

Possible solutions

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.

Notes

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] ```

DataPdu Not finished - needs example

opened on 2020-05-14 04:43:24 by DuffyScottC

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

  1. Provide an example of creating a DataPdu with a variable length record to send an integer as the payload
  2. Finish the DataPdu section?
Open DIS

An open-source implementation of the IEEE-1278.1 Distributed Interactive Simulation (DIS) application protocol

GitHub Repository

dis python protocol