GithubHelp home page GithubHelp logo

null() Function Call? about open-dis-python HOT 21 OPEN

open-dis avatar open-dis commented on June 26, 2024
null() Function Call?

from open-dis-python.

Comments (21)

pulsebreaker avatar pulsebreaker commented on June 26, 2024 1

Wonderful. Works like a charm.

Thanks a lot for the effort.

from open-dis-python.

pulsebreaker avatar pulsebreaker commented on June 26, 2024 1

This is a pcap with the emission pdu's and a couple of entity state pdu's. Unfortunately that's all I have right now that is releasable to the internet. It's made by an outside company.

pdus.zip

I have to figure out a way to create pdu's which I can share. Let met think about that.

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024 1

@ztolley Yes there are still many null's in the code base left over from the auto generated code tool. Over time I've been fixing the most obvious ones. The most commonly used pdu's have been fixed and don't have nulls anymore (e.g. Entity State, Signal, Transmitter, Fire, Detonation, Electronic Emission, etc). If there's a specific pdu you're trying to use that has a null in it let me know. And better yet, you're welcome to submit a PR for a particular fix to get things going in a hurry.

from open-dis-python.

DuffyScottC avatar DuffyScottC commented on June 26, 2024

I've had this issue before multiple times. All instances of null should be changed to None to match python3

from open-dis-python.

treybgreen avatar treybgreen commented on June 26, 2024

I've had this issue before multiple times. All instances of null should be changed to None to match python3

Previous versions of python did not support null() either. Python2 has also reached end of life as of January 2020.

I have made this change in my own code. I do not support these messages in my application currently nor have a need for them, so I have not tested the results thoroughly.

I am willing to submit a pull request but I believe this may be an issue with the tool used to generate this code (I believe similar to the unneeded semi colons but have not looked for the cause of either). I do not have time to fix all of these issues right now, but may be able to contribute a little bit if needed.

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024

A while back I fixed a number of occurences of null() in the code base that were causing issues.

99b7938
10f241e

It looks like this one was missed.

from open-dis-python.

treybgreen avatar treybgreen commented on June 26, 2024

@leif81 Shall I submit a pull request?

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024

Sure though I'm not sure None is the right replacement. Comparing this with the fix to the other null() fixes it looks like element needs to be initialized to a the expected object type so that the right parse() method is called.

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024

If the java implementation is right then iffData is an array of bytes.

https://github.com/open-dis/open-dis-java/blob/master/src/main/java/edu/nps/moves/dis7/IFFData.java#L127

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024

My hunch is it may need to be changed to this

for idx in range(0, self.recordLength):
    val = inputStream.read_byte()
    self.iffData[  idx  ] = val

from open-dis-python.

treybgreen avatar treybgreen commented on June 26, 2024

Sure though I'm not sure None is the right replacement. Comparing this with the fix to the other null() fixes it looks like element needs to be initialized to a the expected object type so that the right parse() method is called.

I agree with not changing them to None.

My hunch is it may need to be changed to this

for idx in range(0, self.recordLength):
    val = inputStream.read_byte()
    self.iffData[  idx  ] = val

Based on the 2 previous commits referenced (99b7938, 10f241e), I believe we should be doing something more like this:

        for idx in range(0, self.recordLength):
            element = IffData()
            element.parse(inputStream)
            self.iffData.append(element)

There are still 31 different instances of null() which will need different versions of this. Another null() Example

from open-dis-python.

treybgreen avatar treybgreen commented on June 26, 2024

Edited Original post to reference

element = null()

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024

Any of us happen to have a sample IFF Data PDU to use as reference to confirm ?

from open-dis-python.

pulsebreaker avatar pulsebreaker commented on June 26, 2024

So I stumbled upon this bug with the Electronic Emissions PDU. Does anyone have an indication when it will be solved? I understand everybody is busy but I need this fixed for specifically the EM PDU before march next year and I'm not sure I can do that myself.

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024

Hi @pulsebreaker thanks for the comment. Originally there were many instances of nulls in the code. There were more than I had time to fix all at once. So I've been fixing them in batches based on demand for particular pdus.

Electronic emission pdu is probably one I didn't do yet.

Could you share a sample electronic emission pdu packet from Wireshark? That would be very helpful to know if the change I make will work or not.

from open-dis-python.

pulsebreaker avatar pulsebreaker commented on June 26, 2024

Thanks for the quick response!

Here is a single EM system PDU. I might also have multiple EM systems PDU's if that's easier but I have to dig a little.

EM_PDU_single_system.zip

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024

@pulsebreaker thank-you for the sample. This was very helpful. I made a large change to the Electromagnetic Emission Pdu parser/serializer and used your sample packet in a unit test. Can you give it a try the latest code on master branch and let me know if it fixed the issue?

from open-dis-python.

pulsebreaker avatar pulsebreaker commented on June 26, 2024

It certainly is a very big step forward for me, thanks a lot!

However I'm receiving a new error:

aPdu = createPdu(data)
File "C:\Users...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\PduFactory.py", line 92, in createPdu
return getPdu(inputStream)
File "C:\Users\s...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\PduFactory.py", line 75, in getPdu
pdu.parse(inputStream)
File "C:\Users...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\dis7.py", line 5382, in parse
element.parse(inputStream)
File "C:\Users...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\dis7.py", line 5441, in parse
self.trackJamRecord.parse(inputStream);
File "C:\Users...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\dis7.py", line 2136, in parse
self.entityID.parse(inputStream)
File "C:\Users...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\dis7.py", line 3302, in parse
self.siteID = inputStream.read_unsigned_short();
File "C:\Users...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\opendis\DataInputStream.py", line 35, in read_unsigned_short
return struct.unpack('>H', self.stream.read(2))[0]
struct.error: unpack requires a buffer of 2 bytes

It looks like it has to do with self.trackJamRecord.parse(inputStream).

Apparently it is possible for this PDU to have no targets in the Track or Jam field. If that's the case than the value self.numberOfTargetsInTrackJam = 0 and self.trackJamRecord.parse(inputStream) causes the struct unpack error.

I made a very cheap and dirty little change in dis7.py just to check my theory:

5441 if self.numberOfTargetsInTrackJam > 0:
5442 self.trackJamRecord.parse(inputStream);

With this ugly little addition the error is gone and on first sight it looks like it parses everything correctly.

Hope this helps.

Again, thanks a lot for all the work! Looks like I can proceed and finish my project in time after all.

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024

@pulsebreaker Ah Ok, I understand it now. Try it now I pushed a fix.

from open-dis-python.

leif81 avatar leif81 commented on June 26, 2024

Great news @pulsebreaker

Unrelated....Do you have other sample dis 7 packets you could share? I would add them to make our unit test coverage better.Any and all pdu types would be useful. But in particular entity state, fire, detonate, signal, transmitter, receiver would be really useful.

from open-dis-python.

ztolley avatar ztolley commented on June 26, 2024

I tried checking the code out and looking at dis7.py and it still has a bunch of null() calls, is this meant to be working?

from open-dis-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.