update readme

This commit is contained in:
2023-09-13 15:59:52 -05:00
parent ae962e2cf0
commit 23802f1572
+53 -2
View File
@@ -1,4 +1,55 @@
# psn-js
**!!DISCLAIMER!!**
This library is still a work-in-progress. I have gotten quick proof-of-concept working and complete implementation of the [PosiStageNet](https://github.com/vyv/psn-cpp/blob/master/doc/PosiStageNetprotocol_v2.03_2019_09_09.pdf) protocol is still being worked on. Please report anything you see that is not in compliance with the protocol.
## Install
`npm install --save @jwetzell/posistagenet`
## Usage
### Decode - [example](./examples/psn_client.js)
```
const { Decoder } = require('@jwetzell/posistagenet')
const decoder = new Decoder()
const buffer = Buffer.from('source PSN packets from somewhere')
decoder.decode(buffer)
// data from PSN Info packets
console.log(decoder.info)
// data from PSN Data packets
console.log(decoder.data)
```
### Encode - [example](./examples/psn_server.js)
```
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'))
})
```