remove constants from packet structs

This commit is contained in:
Joel Wetzell
2026-05-30 08:56:07 -05:00
parent f3b6a6ef1b
commit c0701537b6
20 changed files with 389 additions and 678 deletions
+19 -32
View File
@@ -7,29 +7,17 @@ import (
)
type ArtTimeCode struct {
ID [8]uint8
OpCode uint16
ProtVerHi uint8
ProtVerLo uint8
Filler1 uint8
StreamId uint8
Frames uint8
Seconds uint8
Minutes uint8
Hours uint8
Type uint8
filler1 uint8
StreamId uint8
Frames uint8
Seconds uint8
Minutes uint8
Hours uint8
Type uint8
}
func (atc *ArtTimeCode) GetOpCode() uint16 {
return atc.OpCode
}
func (atc *ArtTimeCode) GetProtVer() uint16 {
return uint16(atc.ProtVerHi)<<8 + uint16(atc.ProtVerLo)
}
func (atc *ArtTimeCode) GetID() [8]uint8 {
return atc.ID
return OpTimeCode
}
func (atc *ArtTimeCode) UnmarshalBinary(data []byte) error {
@@ -37,18 +25,17 @@ func (atc *ArtTimeCode) UnmarshalBinary(data []byte) error {
return errors.New("ArtTimeCode packet must be at least 14 bytes long")
}
copy(atc.ID[:], data[0:8])
if !slices.Equal(ArtNetID[:], atc.ID[:]) {
if !slices.Equal(ArtNetID[:], data[0:8]) {
return errors.New("ID does not match Art-Net ID")
}
atc.OpCode = binary.LittleEndian.Uint16(data[8:10])
atc.ProtVerHi = data[10]
atc.ProtVerLo = data[11]
opCode := binary.LittleEndian.Uint16(data[8:10])
if opCode != OpTimeCode {
return errors.New("packet does not have the correct OpCode for an ArtTimeCode packet")
}
offset := 12
atc.Filler1 = data[offset]
atc.filler1 = data[offset]
atc.StreamId = data[offset+1]
atc.Frames = data[offset+2]
atc.Seconds = data[offset+3]
@@ -60,12 +47,12 @@ func (atc *ArtTimeCode) UnmarshalBinary(data []byte) error {
func (atc *ArtTimeCode) MarshalBinary() ([]byte, error) {
data := make([]byte, 8+11)
copy(data[0:8], atc.ID[:])
binary.LittleEndian.PutUint16(data[8:10], atc.OpCode)
data[10] = atc.ProtVerHi
data[11] = atc.ProtVerLo
copy(data[0:8], ArtNetID[:])
binary.LittleEndian.PutUint16(data[8:10], OpTimeCode)
data[10] = 0
data[11] = 14
offset := 12
data[offset] = atc.Filler1
data[offset] = atc.filler1
data[offset+1] = atc.StreamId
data[offset+2] = atc.Frames
data[offset+3] = atc.Seconds