mirror of
https://github.com/jwetzell/artnet-go.git
synced 2026-08-21 06:38:59 +00:00
remove constants from packet structs
This commit is contained in:
@@ -7,24 +7,12 @@ import (
|
||||
)
|
||||
|
||||
type ArtSync struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
Aux1 uint8
|
||||
Aux2 uint8
|
||||
Aux1 uint8
|
||||
Aux2 uint8
|
||||
}
|
||||
|
||||
func (as *ArtSync) GetOpCode() uint16 {
|
||||
return as.OpCode
|
||||
}
|
||||
|
||||
func (as *ArtSync) GetProtVer() uint16 {
|
||||
return uint16(as.ProtVerHi)<<8 + uint16(as.ProtVerLo)
|
||||
}
|
||||
|
||||
func (as *ArtSync) GetID() [8]uint8 {
|
||||
return as.ID
|
||||
return OpSync
|
||||
}
|
||||
|
||||
func (as *ArtSync) UnmarshalBinary(data []byte) error {
|
||||
@@ -33,15 +21,14 @@ func (as *ArtSync) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtSync packet must be at least 14 bytes long")
|
||||
}
|
||||
|
||||
copy(as.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], as.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
as.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
as.ProtVerHi = data[10]
|
||||
as.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpSync {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtSync packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
as.Aux1 = data[offset]
|
||||
@@ -51,10 +38,10 @@ func (as *ArtSync) UnmarshalBinary(data []byte) error {
|
||||
|
||||
func (as *ArtSync) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+6)
|
||||
copy(data[0:8], as.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], as.OpCode)
|
||||
data[10] = as.ProtVerHi
|
||||
data[11] = as.ProtVerLo
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpSync)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
data[12] = as.Aux1
|
||||
data[13] = as.Aux2
|
||||
return data, nil
|
||||
|
||||
Reference in New Issue
Block a user