Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues calling DISPduToBuffer on TransmitterPDU #5

Closed
Klumze opened this issue Jan 8, 2020 · 4 comments
Closed

Issues calling DISPduToBuffer on TransmitterPDU #5

Klumze opened this issue Jan 8, 2020 · 4 comments

Comments

@Klumze
Copy link

Klumze commented Jan 8, 2020

I cloned a copy of the example server to see if I could get something going for some kind of test server that could sit in a network running a SIM that uses Open DIS protocol and create report based on incoming PDU's and evaluating the responses and such. I ended up grabbing this repo as it is a great starting point. However when I went to call utils.DISPduToBuffer on my newly created TransmitterPDU object, it called the OutputStream.writeLong for some reason which states that Javascript can't handle 64 bit integers natively even though the way I'm setting my variables in the entityId object for my TransmitterPDU is the same as the example EntityStatePDU that was already included. I tried updating the open-dis-javascript to the latest release (1.3.1, was 1.3.0) however now I'm getting some other issues and I'm thinking of just going back to try and resolve this one as it may be simpler.

Here is my source code (more or less identical to the available example):

const dgram = require('dgram');
const dis = require("open-dis");
const argv = require('yargs').argv;
const DISUtils = require('./DISUtils');

var utils = new DISUtils();

var DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = 3000;

/**
 * Read host & port as commandline arguments - or take the default if not given:
 */
var host = argv.host || DEFAULT_HOST
var port = argv.port || DEFAULT_PORT


var client = dgram.createSocket('udp4');        /** Open a UDP-Client */
var client2 = dgram.createSocket('udp4'); 

/**
 * Create a Dummy EntityState-PDU and fill it with dummy data - just for testing:
 */
var disEntityStatePDU= new dis.EntityStatePdu()
disEntityStatePDU.entityID.site = 11;
disEntityStatePDU.entityID.application = 22;
disEntityStatePDU.entityID.entity = 33;
disEntityStatePDU.marking.setMarking("Example Entity");

var disTransmitterPDU= new dis.TransmitterPdu();
disTransmitterPDU.entityId.site = 12;
disTransmitterPDU.entityId.application = 23;
disTransmitterPDU.entityId.entity = 34;

var ePDUentityID = disEntityStatePDU.entityID;
var ePDUlocation = disEntityStatePDU.entityLocation;
var ePDUmarking  = disEntityStatePDU.marking.getMarking();
console.log("Sending EntityState:", ePDUentityID, "Location", ePDUlocation, "Marking: \'" + ePDUmarking + "\'" );

var tPDUentityID = disTransmitterPDU.entityId;
var tPDUtype = disTransmitterPDU.pduType;
console.log("Sending Transmitter:", tPDUentityID, "Type", tPDUtype);


/**
 * Encode the PDU intoto networkbuffer:
 */
var message = utils.DISPduToBuffer(disEntityStatePDU);
var message2 = utils.DISPduToBuffer(disTransmitterPDU);

/**
 * Send the message on network and finish
 */
client.send(message, 0, message.length, port, host, function(err, bytes) {
    if (err) throw err;
    console.log('UDP message sent to ' + host +':'+ port);
	client.close();
});

client2.send(message2, 0, message2.length, port, host, function(err, bytes) {
    if (err) throw err;
    console.log('UDP message sent to ' + host +':'+ port);
	client2.close();
});

If there is any additional info I can provide to help move things along let me know and I'd be glad to provide the necessary info ASAP.

@Klumze Klumze changed the title Issues calling DISPduToBuffer on Transmitter PDU Issues calling DISPduToBuffer on TransmitterPDU Jan 8, 2020
@Klumze
Copy link
Author

Klumze commented Jan 8, 2020

I've realized that 1.3.0 has some missing code versus the 1.3.1 version in the writeLong method, however 1.3.1's OutputStream.writeLong() method is causing str.indexOf('-') to fail in the Long 4.0.0 library. I believe there is something wrong with the method itself but I'm investigating further.

@Klumze
Copy link
Author

Klumze commented Jan 8, 2020

As a work around for the time being I went to the path_to_server/node_modules/open-dis/src/TransmitterPdu.js and I commented out the reference for writeLong that was only used for the Frequency and re-ran the prepublish script. This is not the best workaround as it means you will always get the default Frequency which is set to 0 but allows things to continue working for the time being. If I can find the exact cause for the WriteLong function causing issues I'll be sure to update this.

@leif81
Copy link
Member

leif81 commented Jan 17, 2020

@Klumze Was this the one that had something to do with a typo related to "EntityId" vs "EntityID"?

@Klumze
Copy link
Author

Klumze commented Jan 17, 2020

@leif81 Hey, no this one I'm now realizing is actually me just being an idiot and providing an int to a method that expects a string. I thought in my head that Frequency would be a numeric value but it does not appear to be so haha. I'm closing this one now and I can open a new issue for the .min.js issue and the "EntityID" vs "EntityId".

@Klumze Klumze closed this as completed Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants