first commit of files
This commit is contained in:
29
models/package.go
Normal file
29
models/package.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
// Art-Net constants
|
||||
const (
|
||||
opCode = 0x5000 // OpDmx (low byte first)
|
||||
protocolID = "Art-Net\x00"
|
||||
)
|
||||
|
||||
type Package []byte
|
||||
|
||||
func NewArtNetPackage(data *DMX) Package {
|
||||
// Build ArtDMX packet
|
||||
packet := &bytes.Buffer{}
|
||||
packet.WriteString(protocolID) // Art-Net ID
|
||||
binary.Write(packet, binary.LittleEndian, uint16(opCode)) // OpCode (OpDmx)
|
||||
packet.WriteByte(0x00) // Protocol Version High
|
||||
packet.WriteByte(14) // Protocol Version Low (14 for Art-Net 4)
|
||||
packet.WriteByte(0x00) // Sequence
|
||||
packet.WriteByte(0x00) // Physical
|
||||
binary.Write(packet, binary.BigEndian, uint16(0)) // Universe (net:subuni, usually 0)
|
||||
binary.Write(packet, binary.BigEndian, uint16(len(*data))) // Length
|
||||
packet.Write(*data)
|
||||
return packet.Bytes()
|
||||
}
|
Reference in New Issue
Block a user