0.4.6 • Published 8 months ago
@jwetzell/posistagenet v0.4.6
psn-js
js implementation of the PosiStageNet protocol
Install
npm install --save @jwetzell/posistagenet
Usage
Decode - example
const { Decoder } = require('@jwetzell/posistagenet')
const decoder = new Decoder()
const infoPacketBuffer = Buffer.from('5667348000000c0001000000000000000203010101000b00536572766572204e616d650200118001000d8000000900547261636b65722031','hex')
const dataPacketBuffer = Buffer.from('5567288000000c00010000000000000002030101010014800100108000000c000000803f0000803f0000803f','hex')
decoder.decode(infoPacketBuffer)
decoder.decode(dataPacketBuffer)
// the system_name from info packets if available
console.log(decoder.system_name)
// map of trackers populated with any data that has been received
// this merges both info and data packet properties into one
console.log(decoder.trackers)
Encode - example
const { Encoder, Tracker } = require('@jwetzell/posistagenet')
const encoder = new Encoder('Server Name', 2,3) //server name, version high, version low
const trackers = []
const tracker = new Tracker(1,'Tracker 1') // id, name
tracker.setPos(1.0,1.0,1.0) // x, y, z
trackers.push(tracker)
const timestamp = 1;
// these two calls return an array of Buffers due to potential splitting that might take place because of max UDP packet size
const dataPackets = encoder.getDataPackets(timestamp, trackers)
const infoPackets = encoder.getInfoPackets(timestamp, trackers)
dataPackets.forEach((dataPacket)=>{
console.log('send packet somehow')
console.log(dataPacket.toString('hex'))
})
infoPackets.forEach((infoPacket)=>{
console.log('send packet somehow')
console.log(infoPacket.toString('hex'))
})
Notes
- UInt64
- PosiStageNet uses 64 bit UInt's for timestamp values make sure to use
BigInt
if using values overNumber.MAX_SAFE_INTEGER
- PosiStageNet uses 64 bit UInt's for timestamp values make sure to use