mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-08-25 08:59:17 +00:00
add crude encoding of PSN chunks
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import "encoding/binary"
|
||||||
|
|
||||||
|
func EncodeChunk(id uint16, chunkData []byte, hasSubchunks bool) []byte {
|
||||||
|
|
||||||
|
header := []byte{}
|
||||||
|
|
||||||
|
header = binary.LittleEndian.AppendUint16(header, id)
|
||||||
|
|
||||||
|
hasSubchunksBit := 0
|
||||||
|
|
||||||
|
if hasSubchunks {
|
||||||
|
hasSubchunksBit = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
hasSubchunksBit = hasSubchunksBit << 15
|
||||||
|
|
||||||
|
header = binary.LittleEndian.AppendUint16(header, uint16(len(chunkData)+hasSubchunksBit))
|
||||||
|
|
||||||
|
bytes := header
|
||||||
|
bytes = append(bytes, chunkData...)
|
||||||
|
|
||||||
|
return bytes
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
func EncodeDataPacketChunk(packetHeaderChunk []byte, trackerListChunk []byte) []byte {
|
||||||
|
chunkData := append(packetHeaderChunk, trackerListChunk...)
|
||||||
|
|
||||||
|
return EncodeChunk(0x6755, chunkData, true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EncodeDataTrackerAccelChunk(x float32, y float32, z float32) []byte {
|
||||||
|
bytes := make([]byte, 12)
|
||||||
|
|
||||||
|
binary.LittleEndian.PutUint32(bytes[0:4], math.Float32bits(x))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[4:8], math.Float32bits(y))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[8:12], math.Float32bits(z))
|
||||||
|
|
||||||
|
return EncodeChunk(0x0004, bytes, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
func EncodeDataTrackerChunk(trackerId uint16, fieldChunks [][]byte) []byte {
|
||||||
|
fieldChunkBytes := []byte{}
|
||||||
|
|
||||||
|
for _, fieldChunk := range fieldChunks {
|
||||||
|
fieldChunkBytes = append(fieldChunkBytes, fieldChunk...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return EncodeChunk(trackerId, fieldChunkBytes, len(fieldChunks) > 0)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
func EncodeDataTrackerListChunk(trackerChunks [][]byte) []byte {
|
||||||
|
trackerChunkBytes := []byte{}
|
||||||
|
|
||||||
|
for _, trackerChunk := range trackerChunks {
|
||||||
|
trackerChunkBytes = append(trackerChunkBytes, trackerChunk...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return EncodeChunk(0x0001, trackerChunkBytes, true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EncodeDataTrackerOriChunk(x float32, y float32, z float32) []byte {
|
||||||
|
bytes := make([]byte, 12)
|
||||||
|
|
||||||
|
binary.LittleEndian.PutUint32(bytes[0:4], math.Float32bits(x))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[4:8], math.Float32bits(y))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[8:12], math.Float32bits(z))
|
||||||
|
|
||||||
|
return EncodeChunk(0x0002, bytes, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EncodeDataTrackerPosChunk(x float32, y float32, z float32) []byte {
|
||||||
|
bytes := make([]byte, 12)
|
||||||
|
|
||||||
|
binary.LittleEndian.PutUint32(bytes[0:4], math.Float32bits(x))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[4:8], math.Float32bits(y))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[8:12], math.Float32bits(z))
|
||||||
|
|
||||||
|
return EncodeChunk(0x0000, bytes, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EncodeDataTrackerSpeedChunk(x float32, y float32, z float32) []byte {
|
||||||
|
bytes := make([]byte, 12)
|
||||||
|
|
||||||
|
binary.LittleEndian.PutUint32(bytes[0:4], math.Float32bits(x))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[4:8], math.Float32bits(y))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[8:12], math.Float32bits(z))
|
||||||
|
|
||||||
|
return EncodeChunk(0x0001, bytes, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EncodeDataTrackerStatusChunk(validity float32) []byte {
|
||||||
|
bytes := make([]byte, 4)
|
||||||
|
|
||||||
|
binary.LittleEndian.PutUint32(bytes, math.Float32bits(validity))
|
||||||
|
|
||||||
|
return EncodeChunk(0x0003, bytes, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EncodeDataTrackerTimestampChunk(timestamp uint64) []byte {
|
||||||
|
bytes := make([]byte, 8)
|
||||||
|
|
||||||
|
binary.LittleEndian.PutUint64(bytes, timestamp)
|
||||||
|
|
||||||
|
return EncodeChunk(0x0006, bytes, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EncodeDataTrackerTrgtPosChunk(x float32, y float32, z float32) []byte {
|
||||||
|
bytes := make([]byte, 12)
|
||||||
|
|
||||||
|
binary.LittleEndian.PutUint32(bytes[0:4], math.Float32bits(x))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[4:8], math.Float32bits(y))
|
||||||
|
binary.LittleEndian.PutUint32(bytes[8:12], math.Float32bits(z))
|
||||||
|
|
||||||
|
return EncodeChunk(0x0005, bytes, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
func EncodeInfoPacketChunk(packetHeaderChunk []byte, systemNameChunk []byte, trackerListChunk []byte) []byte {
|
||||||
|
chunkData := append(packetHeaderChunk, systemNameChunk...)
|
||||||
|
chunkData = append(chunkData, trackerListChunk...)
|
||||||
|
|
||||||
|
return EncodeChunk(0x6756, chunkData, true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
func EncodeInfoSystemNameChunk(systemName string) []byte {
|
||||||
|
nameBytes := []uint8(systemName)
|
||||||
|
|
||||||
|
return EncodeChunk(0x0001, nameBytes, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
func EncodeInfoTrackerChunk(trackerId uint16, trackerNameChunk []byte) []byte {
|
||||||
|
return EncodeChunk(trackerId, trackerNameChunk, true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
func EncodeInfoTrackerListChunk(trackerChunks [][]byte) []byte {
|
||||||
|
trackerChunkBytes := []byte{}
|
||||||
|
|
||||||
|
for _, trackerChunk := range trackerChunks {
|
||||||
|
trackerChunkBytes = append(trackerChunkBytes, trackerChunk...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return EncodeChunk(0x0002, trackerChunkBytes, true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
func EncodeInfoTrackerNameChunk(trackerName string) []byte {
|
||||||
|
nameBytes := []uint8(trackerName)
|
||||||
|
|
||||||
|
return EncodeChunk(0x0000, nameBytes, false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package encoders
|
||||||
|
|
||||||
|
import "encoding/binary"
|
||||||
|
|
||||||
|
func EncodePacketHeaderChunk(timestamp uint64, versionHigh uint8, versionLow uint8, frameId uint8, framePacketCount uint8) []byte {
|
||||||
|
packetHeader := make([]byte, 12)
|
||||||
|
|
||||||
|
binary.LittleEndian.PutUint64(packetHeader, timestamp)
|
||||||
|
packetHeader[8] = versionHigh
|
||||||
|
packetHeader[9] = versionLow
|
||||||
|
packetHeader[10] = frameId
|
||||||
|
packetHeader[11] = framePacketCount
|
||||||
|
return EncodeChunk(0x0000, packetHeader, false)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user