open-dis / open-dis-javascript Goto Github PK
View Code? Open in Web Editor NEWJavascript implementation of the IEEE-1278.1 Distributed Interactive Simulation (DIS) application protocol v6 and v7
License: BSD 2-Clause "Simplified" License
Javascript implementation of the IEEE-1278.1 Distributed Interactive Simulation (DIS) application protocol v6 and v7
License: BSD 2-Clause "Simplified" License
Not really an issue, just a question...
Is there any chance I am overlooking a javascript implementation of the DIS Dead Reckoning algorithms?
I found the Java version (DeadReckoner.java) here:
Edit by @leif81 . Fixed URL.
https://github.com/open-dis/open-dis-javascript/blob/master/src/dis7/EntityMarking.js#L26
The character array length is set to 12, but according to the standard, it should be 11. This is an easy mistake because the total EntityMarking length is 12, but the first byte is a character set byte.
Sidenote: I was interested to submit this, my second issue/codefix for open-dis-javascript. I was a little less excited when I realized that I was the one who introduced this bug -- oops!
With the way functions are declared on a global variable 'dis', it makes it fairly difficult to use both DIS 6 and DIS 7 in the same module. We have a need to support both versions and potentially DIS 8 when it comes along. Instead of declaring everything to one variable 'dis', could each version assign it to 'disX' where 'X' is the version number?
Example of issue:
const dis6 = require('open-dis') // don't need relative import because module 'main' points to dis6.min.js
const dis7 = require("../../../../node_modules/open-dis/dist/dis7.min.js"); // overwrites all 'dis' functions to dis7 version
var entityStatePdu_dis6 = new dis6.EntityStatePdu();
entityStatePdu_dis6.entityID.entity = 1;
var entityStatePdu_dis7 = new dis7.EntityStatePdu();
entityStatePdu_dis6.entityID.entityID = 1;
var ab = new ArrayBuffer(1500);
var outputstream = new dis.OutputStream(ab)
entityStatePdu_dis6.encodeToBinary(outputStream) // would encode pdu.entityID.entityID instead of pdu.entityID.entity
entityStatePdu_dis7.encodeToBinary(outputStream) // encodes pdu.entityID.entityID as expected
A way I got around this was to reset the global dis.EntityID function before any pdu creation but this would get very unwieldy for a more complex pdu.
const dis6 = require('open-dis');
const dis7 = require("../../../../node_modules/open-dis/dist/dis7.min.js");
var pdu; // dummy variable for example, would be an dis.Pdu object
if(pdu.protocolVersion == 7) {
global.dis.EntityID = dis7.EntityID;
pdu = new dis7.EntityStatePdu();
} else {
global.dis.EntityID = dis6.EntityID;
pdu = new dis6.EntityStatePdu();
}
Would definitely appreciate any advice if there is a better way to get around this!
Repeatedly receiving the error:
"Offset is outside the bounds of the DataView" when trying to unpack Data and Event PDUs that have a fixed or variable datum attached to them.
Is there a fix to this that I'm unaware of currently?
Question/issue is the title. Would it be possible to get 1.3.1 onto npm since it has bug fixes for encode?
Hello,
I am currently attempting to implement OpenDIS into a web application, however, the web app is built within and utilizes an Angular framework whereas the available documented projects for the javascript implementation all make use of Node.js. Does anyone have any pointers or direction on how to implement this within Angular?
Thanks!
There are a couple pull requests against the old repository. These should be reviewed and determined if they need to be merged in over here.
Hello!
Our team is looking at integrating this library into a TypeScript frontend project.
We would like to begin building out a TypeScript compliant branch and just wanted to check if any of the maintainers have any comments, questions or suggestions before we begin.
We would like to keep it OS, hosted in this repo if possible!
Thanks!
Noticed a comment in dis7/ElectronicEmissionsPdu that states 'Electronic emmissions systems THIS IS WRONG'. Then the initToBinary uses a Vector3Float instead of a class like DIS 6's ElectronicEmissionSystemData.
Are there any plans to fix this?
Creating an urgent pull request to address an issue that affects all PDUs that leverage the Chunk and the VariableDatum files. Will have it ready shortly, and I would recommend a quick release to be pushed out to NPM to correct this bug.
Hi,
first - thank you very much for this nice little javascript open-dis implementation. It really comes handy and simple to use.
I went into some problems using the DataPDU implementation.
Problem 1 - easy to solve
the dis.DataPdu.prototype.encodeToBinary Function has a problem with
fixed and variableDatums. In the implementation the "this" is missing when calling the encodeBinary Function of the array elements for fixed & variable Datums
The following version works for me:
for(var idx = 0; idx < this.fixedDatums.length; idx++)
{
this.fixedDatums[idx].encodeToBinary(outputStream);
}
for(var idx = 0; idx < this.variableDatums.length; idx++)
{
this.variableDatums[idx].encodeToBinary(outputStream);
}
Problem 2 - decoding VariableDatumRecords
The default code of dis.DataPdu.prototype.initFromBinary crashes with my installation when I try to decode DataPdus with VariableDatums.
I need to investigate that. for the moment I just put a try/catch around, so I can work with Fixed Datums, but this needs some more investigation.
Problem 3 - starting with node-open-dis
I had some troubles finding an entry point for the usage with the library.
At the end I grabbed some JAVA examples and rewrote them to use the javascript version. To make it more user friendly, I would suggest to put some demo implementation including some UDP Packet and also the Buffer-Handling into the README. That would help other potential users, that struggle find the right entrypoint. If you like, I could push the example applications I did for sending and receiving DIS packets with node-js
Thomas
The dis7 EntityMarking.js files implements the marking character string as a single byte, instead of the specified 12 bytes (11 + NULL terminator). I have sample code that I believe will implement this correctly -- I will aim to commit this code to a forked repo (or I could put a patch here) for consideration.
anX.initFromBinary is not a function
. This seems to be because initFromBinary
is not the correct function name.The functions defined on the Chunk object in Chunk.js are initFromBinaryDIS
and encodeToBinaryDIS
. However, the functions used throughout the repository are just initFromBinary
and encodeToBinary
.
This code snippet comes from inside the SignalPdu:
for(var idx = 0; idx < this.dataLength; idx++)
{
var anX = new dis.Chunk(1);
anX.initFromBinary(inputStream);
this.data.push(anX);
}
encodeToBinary
function on the SignalPdu, the line this.data[idx].encodeToBinary(outputStream)
continues to break because encodeToBinary
doesn't exist on the elements inside this.data
. As far as I can tell, this.data
is just an array of 8 bit values, not specific DIS objects so I'm not sure why we're calling encodeToBinary
on the elements of the array instead of doing something like outputStream.writeByte(this.data[idx])
. Can anyone tell me what exactly I should be setting this.data
to?I'm trying to import open-dis into a project that I'm working on to be able to package Pdus clientside, but keep getting the error message in the title when importing as import open-dis;
.
When importing as const dis = require("open-dis");
I instead get an error message that that states:
Uncaught ReferenceError: require is not defined
.
Otherwise, I can import import { Pdu } from 'open-dis/src/dis/Pdu'
. However, in this case, I get an error message in the browser stating:
Uncaught ReferenceError: assignment to undeclared variable dis js SignalPdu.js:11 __require2 chunk-ASBRWZGP.js:15 <anonymous> open-dis_src_dis_SignalPdu:1
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.