mirror of
https://github.com/jwetzell/artnet-go.git
synced 2026-08-16 04:23:23 +00:00
remove constants from packet structs
This commit is contained in:
+11
-25
@@ -85,10 +85,6 @@ const (
|
||||
)
|
||||
|
||||
type ArtAddress struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
NetSwitch uint8
|
||||
BindIndex uint8
|
||||
PortName [18]uint8
|
||||
@@ -101,15 +97,7 @@ type ArtAddress struct {
|
||||
}
|
||||
|
||||
func (aa *ArtAddress) GetOpCode() uint16 {
|
||||
return aa.OpCode
|
||||
}
|
||||
|
||||
func (aa *ArtAddress) GetProtVer() uint16 {
|
||||
return uint16(aa.ProtVerHi)<<8 + uint16(aa.ProtVerLo)
|
||||
}
|
||||
|
||||
func (aa *ArtAddress) GetID() [8]uint8 {
|
||||
return aa.ID
|
||||
return OpAddress
|
||||
}
|
||||
|
||||
func (aa *ArtAddress) UnmarshalBinary(data []byte) error {
|
||||
@@ -117,16 +105,14 @@ func (aa *ArtAddress) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtAddress packet must be at least 107 bytes long")
|
||||
}
|
||||
|
||||
copy(aa.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], aa.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
aa.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
aa.ProtVerHi = data[10]
|
||||
aa.ProtVerLo = data[11]
|
||||
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpAddress {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtAddress packet")
|
||||
}
|
||||
offset := 12
|
||||
aa.NetSwitch = data[offset]
|
||||
aa.BindIndex = data[offset+1]
|
||||
@@ -141,11 +127,11 @@ func (aa *ArtAddress) UnmarshalBinary(data []byte) error {
|
||||
}
|
||||
|
||||
func (aa *ArtAddress) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+11)
|
||||
copy(data[0:8], aa.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], aa.OpCode)
|
||||
data[10] = aa.ProtVerHi
|
||||
data[11] = aa.ProtVerLo
|
||||
data := make([]byte, 8+99)
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpAddress)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
offset := 12
|
||||
data[offset] = aa.NetSwitch
|
||||
data[offset+1] = aa.BindIndex
|
||||
|
||||
+12
-29
@@ -14,28 +14,12 @@ const (
|
||||
)
|
||||
|
||||
type ArtCommand struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
EstaMan uint16
|
||||
Data []uint8
|
||||
EstaMan uint16
|
||||
Data []uint8
|
||||
}
|
||||
|
||||
func (ac *ArtCommand) GetOpCode() uint16 {
|
||||
return ac.OpCode
|
||||
}
|
||||
|
||||
func (ac *ArtCommand) GetProtVer() uint16 {
|
||||
return uint16(ac.ProtVerHi)<<8 + uint16(ac.ProtVerLo)
|
||||
}
|
||||
|
||||
func (ac *ArtCommand) GetID() [8]uint8 {
|
||||
return ac.ID
|
||||
}
|
||||
|
||||
func (ac *ArtCommand) Length() uint16 {
|
||||
return uint16(len(ac.Data))
|
||||
return OpCommand
|
||||
}
|
||||
|
||||
func (ac *ArtCommand) UnmarshalBinary(data []byte) error {
|
||||
@@ -44,15 +28,14 @@ func (ac *ArtCommand) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtCommand packet must be at least 16 bytes long")
|
||||
}
|
||||
|
||||
copy(ac.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], ac.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
ac.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
ac.ProtVerHi = data[10]
|
||||
ac.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpCommand {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtCommand packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
ac.EstaMan = binary.BigEndian.Uint16(data[offset : offset+2])
|
||||
@@ -69,10 +52,10 @@ func (ac *ArtCommand) UnmarshalBinary(data []byte) error {
|
||||
|
||||
func (ac *ArtCommand) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+8)
|
||||
copy(data[0:8], ac.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], ac.OpCode)
|
||||
data[10] = ac.ProtVerHi
|
||||
data[11] = ac.ProtVerLo
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpCommand)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
binary.BigEndian.PutUint16(data[12:14], ac.EstaMan)
|
||||
dataLength := uint16(len(ac.Data))
|
||||
if dataLength > 512 {
|
||||
|
||||
+14
-27
@@ -18,26 +18,14 @@ const (
|
||||
)
|
||||
|
||||
type ArtDataRequest struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
EstaMan uint16
|
||||
Oem uint16
|
||||
Request DataRequest
|
||||
spare [22]byte
|
||||
EstaMan uint16
|
||||
Oem uint16
|
||||
Request DataRequest
|
||||
spare [22]byte
|
||||
}
|
||||
|
||||
func (adr *ArtDataRequest) GetOpCode() uint16 {
|
||||
return adr.OpCode
|
||||
}
|
||||
|
||||
func (adr *ArtDataRequest) GetProtVer() uint16 {
|
||||
return uint16(adr.ProtVerHi)<<8 + uint16(adr.ProtVerLo)
|
||||
}
|
||||
|
||||
func (adr *ArtDataRequest) GetID() [8]uint8 {
|
||||
return adr.ID
|
||||
return OpDataRequest
|
||||
}
|
||||
|
||||
func (adr *ArtDataRequest) UnmarshalBinary(data []byte) error {
|
||||
@@ -46,15 +34,14 @@ func (adr *ArtDataRequest) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtDataRequest packet must be at least 40 bytes long")
|
||||
}
|
||||
|
||||
copy(adr.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], adr.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
adr.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
adr.ProtVerHi = data[10]
|
||||
adr.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpDataRequest {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtDataRequest packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
adr.EstaMan = binary.BigEndian.Uint16(data[offset : offset+2])
|
||||
@@ -66,10 +53,10 @@ func (adr *ArtDataRequest) UnmarshalBinary(data []byte) error {
|
||||
|
||||
func (adr *ArtDataRequest) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+32)
|
||||
copy(data[0:8], adr.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], adr.OpCode)
|
||||
data[10] = adr.ProtVerHi
|
||||
data[11] = adr.ProtVerLo
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpDataRequest)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
binary.BigEndian.PutUint16(data[12:14], adr.EstaMan)
|
||||
binary.BigEndian.PutUint16(data[14:16], adr.Oem)
|
||||
binary.BigEndian.PutUint16(data[16:18], uint16(adr.Request))
|
||||
|
||||
+10
-27
@@ -17,10 +17,6 @@ const (
|
||||
)
|
||||
|
||||
type ArtDiagData struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
filler1 uint8
|
||||
DiagPriority DiagPriority
|
||||
LogicalPort uint8
|
||||
@@ -29,19 +25,7 @@ type ArtDiagData struct {
|
||||
}
|
||||
|
||||
func (add *ArtDiagData) GetOpCode() uint16 {
|
||||
return add.OpCode
|
||||
}
|
||||
|
||||
func (add *ArtDiagData) GetProtVer() uint16 {
|
||||
return uint16(add.ProtVerHi)<<8 + uint16(add.ProtVerLo)
|
||||
}
|
||||
|
||||
func (add *ArtDiagData) GetID() [8]uint8 {
|
||||
return add.ID
|
||||
}
|
||||
|
||||
func (add *ArtDiagData) Length() uint16 {
|
||||
return uint16(len(add.Data))
|
||||
return OpDiagData
|
||||
}
|
||||
|
||||
func (add *ArtDiagData) UnmarshalBinary(data []byte) error {
|
||||
@@ -50,15 +34,14 @@ func (add *ArtDiagData) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtDiagData packet must be at least 18 bytes long")
|
||||
}
|
||||
|
||||
copy(add.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], add.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
add.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
add.ProtVerHi = data[10]
|
||||
add.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpDiagData {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtDiagData packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
add.filler1 = data[offset]
|
||||
@@ -77,10 +60,10 @@ func (add *ArtDiagData) UnmarshalBinary(data []byte) error {
|
||||
|
||||
func (add *ArtDiagData) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+10)
|
||||
copy(data[0:8], add.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], add.OpCode)
|
||||
data[10] = add.ProtVerHi
|
||||
data[11] = add.ProtVerLo
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpDiagData)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
data[12] = add.filler1
|
||||
data[13] = uint8(add.DiagPriority)
|
||||
data[14] = add.LogicalPort
|
||||
|
||||
@@ -7,31 +7,15 @@ import (
|
||||
)
|
||||
|
||||
type ArtDmx struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
Sequence uint8
|
||||
Physical uint8
|
||||
SubUni uint8
|
||||
Net uint8
|
||||
Data []uint8
|
||||
Sequence uint8
|
||||
Physical uint8
|
||||
SubUni uint8
|
||||
Net uint8
|
||||
Data []uint8
|
||||
}
|
||||
|
||||
func (ad *ArtDmx) GetOpCode() uint16 {
|
||||
return ad.OpCode
|
||||
}
|
||||
|
||||
func (ad *ArtDmx) GetProtVer() uint16 {
|
||||
return uint16(ad.ProtVerHi)<<8 + uint16(ad.ProtVerLo)
|
||||
}
|
||||
|
||||
func (ad *ArtDmx) GetID() [8]uint8 {
|
||||
return ad.ID
|
||||
}
|
||||
|
||||
func (ad *ArtDmx) Length() uint16 {
|
||||
return uint16(len(ad.Data))
|
||||
return OpDmx
|
||||
}
|
||||
|
||||
func (ad *ArtDmx) UnmarshalBinary(data []byte) error {
|
||||
@@ -39,15 +23,14 @@ func (ad *ArtDmx) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtDmx packet must be at least 18 bytes long")
|
||||
}
|
||||
|
||||
copy(ad.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], ad.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
ad.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
ad.ProtVerHi = data[10]
|
||||
ad.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpDmx {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtDmx packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
|
||||
@@ -70,16 +53,17 @@ func (ad *ArtDmx) UnmarshalBinary(data []byte) error {
|
||||
}
|
||||
|
||||
func (ad *ArtDmx) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+10+ad.Length())
|
||||
copy(data[0:8], ad.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], ad.OpCode)
|
||||
data[10] = ad.ProtVerHi
|
||||
data[11] = ad.ProtVerLo
|
||||
// TODO(jwetzell): check max data length
|
||||
data := make([]byte, 8+10+len(ad.Data))
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpDmx)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
data[12] = ad.Sequence
|
||||
data[13] = ad.Physical
|
||||
data[14] = ad.SubUni
|
||||
data[15] = ad.Net
|
||||
binary.BigEndian.PutUint16(data[16:18], ad.Length())
|
||||
binary.BigEndian.PutUint16(data[16:18], uint16(len(ad.Data)))
|
||||
copy(data[18:], ad.Data)
|
||||
return data, nil
|
||||
}
|
||||
|
||||
+20
-56
@@ -17,45 +17,33 @@ func TestGoodArtDmx(t *testing.T) {
|
||||
Name: "512 All Zeroes",
|
||||
Data: []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14, 237, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
Expected: &artnet.ArtDmx{
|
||||
ID: [8]byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
|
||||
OpCode: artnet.OpDmx,
|
||||
ProtVerHi: 0,
|
||||
ProtVerLo: 14,
|
||||
Sequence: 237,
|
||||
Physical: 0,
|
||||
SubUni: 1,
|
||||
Net: 0,
|
||||
Data: make([]uint8, 512),
|
||||
Sequence: 237,
|
||||
Physical: 0,
|
||||
SubUni: 1,
|
||||
Net: 0,
|
||||
Data: make([]uint8, 512),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 1",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x50, 0x00, 0x0e, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtDmx{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpDmx,
|
||||
ProtVerHi: 0,
|
||||
ProtVerLo: 14,
|
||||
Sequence: 0,
|
||||
Physical: 0,
|
||||
SubUni: 1,
|
||||
Net: 0,
|
||||
Data: make([]uint8, 512),
|
||||
Sequence: 0,
|
||||
Physical: 0,
|
||||
SubUni: 1,
|
||||
Net: 0,
|
||||
Data: make([]uint8, 512),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 2",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x50, 0x00, 0x0e, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtDmx{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpDmx,
|
||||
ProtVerHi: 0,
|
||||
ProtVerLo: 14,
|
||||
Sequence: 0,
|
||||
Physical: 0,
|
||||
SubUni: 1,
|
||||
Net: 0,
|
||||
Data: append([]uint8{0xff, 0x7f}, make([]uint8, 510)...),
|
||||
Sequence: 0,
|
||||
Physical: 0,
|
||||
SubUni: 1,
|
||||
Net: 0,
|
||||
Data: append([]uint8{0xff, 0x7f}, make([]uint8, 510)...),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -69,22 +57,6 @@ func TestGoodArtDmx(t *testing.T) {
|
||||
t.Fatalf("failed to decode ArtDmx: %s", err)
|
||||
}
|
||||
|
||||
if got.OpCode != test.Expected.OpCode {
|
||||
t.Fatalf("ArtDmx OpCode does not match got: %d expected: %d", got.OpCode, test.Expected.OpCode)
|
||||
}
|
||||
|
||||
if !slices.Equal(got.ID[:], test.Expected.ID[:]) {
|
||||
t.Fatalf("ArtDmx ID does not match got: %+v expected: %+v", got.ID, test.Expected.ID)
|
||||
}
|
||||
|
||||
if got.ProtVerHi != test.Expected.ProtVerHi {
|
||||
t.Fatalf("ArtDmx ProtVerHi does not match got: %d expected: %d", got.ProtVerHi, test.Expected.ProtVerHi)
|
||||
}
|
||||
|
||||
if got.ProtVerLo != test.Expected.ProtVerLo {
|
||||
t.Fatalf("ArtDmx ProtVerLo does not match got: %d expected: %d", got.ProtVerLo, test.Expected.ProtVerLo)
|
||||
}
|
||||
|
||||
if got.Sequence != test.Expected.Sequence {
|
||||
t.Fatalf("ArtDmx Sequence does not match got: %d expected: %d", got.Sequence, test.Expected.Sequence)
|
||||
}
|
||||
@@ -101,10 +73,6 @@ func TestGoodArtDmx(t *testing.T) {
|
||||
t.Fatalf("ArtDmx Net does not match got: %d expected: %d", got.Net, test.Expected.Net)
|
||||
}
|
||||
|
||||
if got.Length() != test.Expected.Length() {
|
||||
t.Fatalf("ArtDmx Length does not match got: %d expected: %d", got.Length(), test.Expected.Length())
|
||||
}
|
||||
|
||||
if !slices.Equal(got.Data, test.Expected.Data) {
|
||||
t.Fatalf("ArtDmx Data does not match got: %+v expected: %+v", got.Data, test.Expected.Data)
|
||||
}
|
||||
@@ -127,15 +95,11 @@ func BenchmarkArtDmxUnmarshalBinary(b *testing.B) {
|
||||
|
||||
func BenchmarkArtDmxMarshalBinary(b *testing.B) {
|
||||
data := artnet.ArtDmx{
|
||||
ID: [8]byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
|
||||
OpCode: artnet.OpDmx,
|
||||
ProtVerHi: 0,
|
||||
ProtVerLo: 14,
|
||||
Sequence: 237,
|
||||
Physical: 0,
|
||||
SubUni: 1,
|
||||
Net: 0,
|
||||
Data: make([]uint8, 512),
|
||||
Sequence: 237,
|
||||
Physical: 0,
|
||||
SubUni: 1,
|
||||
Net: 0,
|
||||
Data: make([]uint8, 512),
|
||||
}
|
||||
|
||||
for b.Loop() {
|
||||
|
||||
@@ -7,10 +7,6 @@ import (
|
||||
)
|
||||
|
||||
type ArtIpProg struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
filler1 uint8
|
||||
filler2 uint8
|
||||
Command uint8
|
||||
@@ -36,15 +32,7 @@ type ArtIpProg struct {
|
||||
}
|
||||
|
||||
func (aip *ArtIpProg) GetOpCode() uint16 {
|
||||
return aip.OpCode
|
||||
}
|
||||
|
||||
func (aip *ArtIpProg) GetProtVer() uint16 {
|
||||
return uint16(aip.ProtVerHi)<<8 + uint16(aip.ProtVerLo)
|
||||
}
|
||||
|
||||
func (aip *ArtIpProg) GetID() [8]uint8 {
|
||||
return aip.ID
|
||||
return OpIpProg
|
||||
}
|
||||
|
||||
func (aip *ArtIpProg) UnmarshalBinary(data []byte) error {
|
||||
@@ -52,15 +40,14 @@ func (aip *ArtIpProg) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtIpProg packet must be at least 18 bytes long")
|
||||
}
|
||||
|
||||
copy(aip.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], aip.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
aip.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
aip.ProtVerHi = data[10]
|
||||
aip.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpIpProg {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtIpProg packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
|
||||
@@ -97,10 +84,10 @@ func (aip *ArtIpProg) UnmarshalBinary(data []byte) error {
|
||||
|
||||
func (aip *ArtIpProg) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+26)
|
||||
copy(data[0:8], aip.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], aip.OpCode)
|
||||
data[10] = aip.ProtVerHi
|
||||
data[11] = aip.ProtVerLo
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpIpProg)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
data[12] = aip.filler1
|
||||
data[13] = aip.filler2
|
||||
data[14] = aip.Command
|
||||
|
||||
@@ -17,10 +17,6 @@ func TestGoodArtIpProgUnmarshal(t *testing.T) {
|
||||
Name: "ACT Packet 1",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0xf8, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtIpProg{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpIpProg,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: 0x00,
|
||||
ProgIpHi: 0x00,
|
||||
ProgIp2: 0x00,
|
||||
|
||||
+10
-23
@@ -7,10 +7,6 @@ import (
|
||||
)
|
||||
|
||||
type ArtIpProgReply struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
filler1 uint8
|
||||
filler2 uint8
|
||||
filler3 uint8
|
||||
@@ -36,15 +32,7 @@ type ArtIpProgReply struct {
|
||||
}
|
||||
|
||||
func (aipr *ArtIpProgReply) GetOpCode() uint16 {
|
||||
return aipr.OpCode
|
||||
}
|
||||
|
||||
func (aipr *ArtIpProgReply) GetProtVer() uint16 {
|
||||
return uint16(aipr.ProtVerHi)<<8 + uint16(aipr.ProtVerLo)
|
||||
}
|
||||
|
||||
func (aipr *ArtIpProgReply) GetID() [8]uint8 {
|
||||
return aipr.ID
|
||||
return OpIpProgReply
|
||||
}
|
||||
|
||||
func (aipr *ArtIpProgReply) UnmarshalBinary(data []byte) error {
|
||||
@@ -52,15 +40,14 @@ func (aipr *ArtIpProgReply) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtIpProgReply packet must be at least 18 bytes long")
|
||||
}
|
||||
|
||||
copy(aipr.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], aipr.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
aipr.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
aipr.ProtVerHi = data[10]
|
||||
aipr.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpIpProgReply {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtIpProgReply packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
|
||||
@@ -98,10 +85,10 @@ func (aipr *ArtIpProgReply) UnmarshalBinary(data []byte) error {
|
||||
|
||||
func (aipr *ArtIpProgReply) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+26)
|
||||
copy(data[0:8], aipr.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], aipr.OpCode)
|
||||
data[10] = aipr.ProtVerHi
|
||||
data[11] = aipr.ProtVerLo
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpIpProgReply)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
data[12] = aipr.filler1
|
||||
data[13] = aipr.filler2
|
||||
data[14] = aipr.filler3
|
||||
|
||||
@@ -7,10 +7,6 @@ import (
|
||||
)
|
||||
|
||||
type ArtNzs struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
Sequence uint8
|
||||
StartCode uint8
|
||||
SubUni uint8
|
||||
@@ -19,19 +15,7 @@ type ArtNzs struct {
|
||||
}
|
||||
|
||||
func (an *ArtNzs) GetOpCode() uint16 {
|
||||
return an.OpCode
|
||||
}
|
||||
|
||||
func (an *ArtNzs) GetProtVer() uint16 {
|
||||
return uint16(an.ProtVerHi)<<8 + uint16(an.ProtVerLo)
|
||||
}
|
||||
|
||||
func (an *ArtNzs) GetID() [8]uint8 {
|
||||
return an.ID
|
||||
}
|
||||
|
||||
func (an *ArtNzs) Length() uint16 {
|
||||
return uint16(len(an.Data))
|
||||
return OpNzs
|
||||
}
|
||||
|
||||
func (an *ArtNzs) UnmarshalBinary(data []byte) error {
|
||||
@@ -40,15 +24,14 @@ func (an *ArtNzs) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtNzs packet must be at least 18 bytes long")
|
||||
}
|
||||
|
||||
copy(an.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], an.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
an.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
an.ProtVerHi = data[10]
|
||||
an.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpNzs {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtNzs packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
an.Sequence = data[offset]
|
||||
@@ -68,10 +51,10 @@ func (an *ArtNzs) UnmarshalBinary(data []byte) error {
|
||||
|
||||
func (an *ArtNzs) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+8)
|
||||
copy(data[0:8], an.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], an.OpCode)
|
||||
data[10] = an.ProtVerHi
|
||||
data[11] = an.ProtVerLo
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpNzs)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
data[12] = an.Sequence
|
||||
data[13] = an.StartCode
|
||||
data[14] = an.SubUni
|
||||
|
||||
@@ -8,5 +8,4 @@ type ArtNetPacket interface {
|
||||
encoding.BinaryUnmarshaler
|
||||
encoding.BinaryMarshaler
|
||||
GetOpCode() uint16
|
||||
GetID() [8]uint8
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ import (
|
||||
)
|
||||
|
||||
type ArtPoll struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
Flags uint8
|
||||
DiagPriority uint8
|
||||
// TODO(jwetzell): support extended poll fields
|
||||
@@ -21,15 +17,7 @@ type ArtPoll struct {
|
||||
}
|
||||
|
||||
func (ap *ArtPoll) GetOpCode() uint16 {
|
||||
return ap.OpCode
|
||||
}
|
||||
|
||||
func (ap *ArtPoll) GetProtVer() uint16 {
|
||||
return uint16(ap.ProtVerHi)<<8 + uint16(ap.ProtVerLo)
|
||||
}
|
||||
|
||||
func (ap *ArtPoll) GetID() [8]uint8 {
|
||||
return ap.ID
|
||||
return OpPoll
|
||||
}
|
||||
|
||||
func (ap *ArtPoll) UnmarshalBinary(data []byte) error {
|
||||
@@ -38,15 +26,14 @@ func (ap *ArtPoll) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtPoll packet must be at least 14 bytes long")
|
||||
}
|
||||
|
||||
copy(ap.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], ap.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
ap.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
ap.ProtVerHi = data[10]
|
||||
ap.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpPoll {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtPoll packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
ap.Flags = data[offset]
|
||||
@@ -69,10 +56,10 @@ func (ap *ArtPoll) UnmarshalBinary(data []byte) error {
|
||||
|
||||
func (ap *ArtPoll) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+14)
|
||||
copy(data[0:8], ap.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], ap.OpCode)
|
||||
data[10] = ap.ProtVerHi
|
||||
data[11] = ap.ProtVerLo
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpPoll)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
data[12] = ap.Flags
|
||||
data[13] = ap.DiagPriority
|
||||
binary.BigEndian.PutUint16(data[14:16], ap.TargetPortAddressTop)
|
||||
|
||||
+125
-110
@@ -17,170 +17,185 @@ func TestGoodArtPollUnmarshal(t *testing.T) {
|
||||
Name: "ACT Packet 1",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x00,
|
||||
DiagPriority: 0x00,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 2",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x00,
|
||||
DiagPriority: 0x00,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 3",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x00,
|
||||
DiagPriority: 0x00,
|
||||
TargetPortAddressTop: 0x7fff,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 4",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x00,
|
||||
DiagPriority: 0x00,
|
||||
TargetPortAddressTop: 0x7fff,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 5",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x00,
|
||||
DiagPriority: 0x00,
|
||||
TargetPortAddressTop: 0x7fff,
|
||||
TargetPortAddressBottom: 0x0000,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 6",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x00,
|
||||
DiagPriority: 0x00,
|
||||
TargetPortAddressTop: 0x7fff,
|
||||
TargetPortAddressBottom: 0x0000,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 7",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x00,
|
||||
DiagPriority: 0x00,
|
||||
TargetPortAddressTop: 0x7fff,
|
||||
TargetPortAddressBottom: 0x0000,
|
||||
EstaMan: 0x5379,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 8",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x00,
|
||||
DiagPriority: 0x00,
|
||||
TargetPortAddressTop: 0x7fff,
|
||||
TargetPortAddressBottom: 0x0000,
|
||||
EstaMan: 0x5379,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 9",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 10",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 11",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 12",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 13",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 14",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 15",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 16",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x21, 0x0a, 0x00, 0x00, 0x3e, 0x36, 0x19, 0x07, 0x33, 0x00, 0x06, 0x22, 0x69, 0x00, 0x00, 0x79, 0x53, 0x41, 0x43, 0x54, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x43, 0x54, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x00,
|
||||
DiagPriority: 0x00,
|
||||
TargetPortAddressTop: 0x7fff,
|
||||
TargetPortAddressBottom: 0x0000,
|
||||
EstaMan: 0x5379,
|
||||
Oem: 0x2269,
|
||||
},
|
||||
},
|
||||
// TODO(jwetzell): uncomment when extend field parsing is done
|
||||
// {
|
||||
// Name: "ACT Packet 10",
|
||||
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00},
|
||||
// Expected: &artnet.ArtPoll{
|
||||
// Flags: 0x00,
|
||||
// DiagPriority: 0x00,
|
||||
// TargetPortAddressTop: 0x7fff,
|
||||
// TargetPortAddressBottom: 0x0000,
|
||||
// EstaMan: 0x5379,
|
||||
// Oem: 0x2269,
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Name: "ACT Packet 11",
|
||||
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00},
|
||||
// Expected: &artnet.ArtPoll{
|
||||
// Flags: 0x00,
|
||||
// DiagPriority: 0x00,
|
||||
// TargetPortAddressTop: 0x7fff,
|
||||
// TargetPortAddressBottom: 0x0000,
|
||||
// EstaMan: 0x5379,
|
||||
// Oem: 0x2269,
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Name: "ACT Packet 12",
|
||||
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00},
|
||||
// Expected: &artnet.ArtPoll{
|
||||
// Flags: 0x00,
|
||||
// DiagPriority: 0x00,
|
||||
// TargetPortAddressTop: 0x7fff,
|
||||
// TargetPortAddressBottom: 0x0000,
|
||||
// EstaMan: 0x5379,
|
||||
// Oem: 0x2269,
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Name: "ACT Packet 13",
|
||||
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00},
|
||||
// Expected: &artnet.ArtPoll{
|
||||
// Flags: 0x00,
|
||||
// DiagPriority: 0x00,
|
||||
// TargetPortAddressTop: 0x7fff,
|
||||
// TargetPortAddressBottom: 0x0000,
|
||||
// EstaMan: 0x5379,
|
||||
// Oem: 0x2269,
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Name: "ACT Packet 14",
|
||||
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
// Expected: &artnet.ArtPoll{
|
||||
// Flags: 0x00,
|
||||
// DiagPriority: 0x00,
|
||||
// TargetPortAddressTop: 0x7fff,
|
||||
// TargetPortAddressBottom: 0x0000,
|
||||
// EstaMan: 0x5379,
|
||||
// Oem: 0x2269,
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Name: "ACT Packet 15",
|
||||
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
// Expected: &artnet.ArtPoll{
|
||||
// Flags: 0x00,
|
||||
// DiagPriority: 0x00,
|
||||
// TargetPortAddressTop: 0x7fff,
|
||||
// TargetPortAddressBottom: 0x0000,
|
||||
// EstaMan: 0x5379,
|
||||
// Oem: 0x2269,
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Name: "ACT Packet 16",
|
||||
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x21, 0x0a, 0x00, 0x00, 0x3e, 0x36, 0x19, 0x07, 0x33, 0x00, 0x06, 0x22, 0x69, 0x00, 0x00, 0x79, 0x53, 0x41, 0x43, 0x54, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x43, 0x54, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
// Expected: &artnet.ArtPoll{
|
||||
// Flags: 0x00,
|
||||
// DiagPriority: 0x00,
|
||||
// TargetPortAddressTop: 0x7fff,
|
||||
// TargetPortAddressBottom: 0x0000,
|
||||
// EstaMan: 0x5379,
|
||||
// Oem: 0x2269,
|
||||
// },
|
||||
// },
|
||||
{
|
||||
Name: "ACT Packet 17",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x06, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69},
|
||||
Expected: &artnet.ArtPoll{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: 0x2000,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Flags: 0x06,
|
||||
DiagPriority: 0x00,
|
||||
TargetPortAddressTop: 0x7fff,
|
||||
TargetPortAddressBottom: 0x0000,
|
||||
EstaMan: 0x5379,
|
||||
Oem: 0x2269,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
+9
-13
@@ -7,8 +7,6 @@ import (
|
||||
)
|
||||
|
||||
type ArtPollReply struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
IPAddress [4]uint8
|
||||
Port uint16
|
||||
VersInfo uint16
|
||||
@@ -49,11 +47,7 @@ type ArtPollReply struct {
|
||||
}
|
||||
|
||||
func (ap *ArtPollReply) GetOpCode() uint16 {
|
||||
return ap.OpCode
|
||||
}
|
||||
|
||||
func (ap *ArtPollReply) GetID() [8]uint8 {
|
||||
return ap.ID
|
||||
return OpPollReply
|
||||
}
|
||||
|
||||
func (ap *ArtPollReply) UnmarshalBinary(data []byte) error {
|
||||
@@ -62,13 +56,15 @@ func (ap *ArtPollReply) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtPollReply packet must be at least 207 bytes long")
|
||||
}
|
||||
|
||||
copy(ap.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], ap.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
ap.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpPollReply {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtPollReply packet")
|
||||
}
|
||||
|
||||
ap.IPAddress[0] = data[10]
|
||||
ap.IPAddress[1] = data[11]
|
||||
ap.IPAddress[2] = data[12]
|
||||
@@ -106,8 +102,8 @@ func (ap *ArtPollReply) MarshalBinary() ([]byte, error) {
|
||||
return nil, errors.New("DefaultRespUID must not be greater than 281474976710655")
|
||||
}
|
||||
data := make([]byte, 8+230)
|
||||
copy(data[0:8], ap.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], ap.OpCode)
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpPollReply)
|
||||
data[10] = ap.IPAddress[0]
|
||||
data[11] = ap.IPAddress[1]
|
||||
data[12] = ap.IPAddress[2]
|
||||
|
||||
@@ -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
|
||||
|
||||
+19
-32
@@ -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
|
||||
|
||||
+12
-22
@@ -17,17 +17,12 @@ func TestGoodArtTimeCodeUnmarshal(t *testing.T) {
|
||||
Name: "Basic timecode",
|
||||
Data: []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 151, 0, 14, 0, 0, 11, 17, 3, 0, 0},
|
||||
Expected: &artnet.ArtTimeCode{
|
||||
ID: [8]uint8{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
|
||||
OpCode: artnet.OpTimeCode,
|
||||
ProtVerHi: 0,
|
||||
ProtVerLo: 14,
|
||||
Filler1: 0,
|
||||
StreamId: 0,
|
||||
Frames: 11,
|
||||
Seconds: 17,
|
||||
Minutes: 3,
|
||||
Hours: 0,
|
||||
Type: 0,
|
||||
StreamId: 0,
|
||||
Frames: 11,
|
||||
Seconds: 17,
|
||||
Minutes: 3,
|
||||
Hours: 0,
|
||||
Type: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -63,17 +58,12 @@ func BenchmarkArtTimeCodeUnmarshalBinary(b *testing.B) {
|
||||
|
||||
func BenchmarkArtTimeCodeMarshalBinary(b *testing.B) {
|
||||
data := artnet.ArtTimeCode{
|
||||
ID: [8]uint8{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
|
||||
OpCode: artnet.OpTimeCode,
|
||||
ProtVerHi: 0,
|
||||
ProtVerLo: 14,
|
||||
Filler1: 0,
|
||||
StreamId: 0,
|
||||
Frames: 11,
|
||||
Seconds: 17,
|
||||
Minutes: 3,
|
||||
Hours: 0,
|
||||
Type: 0,
|
||||
StreamId: 0,
|
||||
Frames: 11,
|
||||
Seconds: 17,
|
||||
Minutes: 3,
|
||||
Hours: 0,
|
||||
Type: 0,
|
||||
}
|
||||
|
||||
for b.Loop() {
|
||||
|
||||
+22
-35
@@ -13,34 +13,22 @@ const (
|
||||
)
|
||||
|
||||
type ArtTodRequest struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
filler1 uint8
|
||||
filler2 uint8
|
||||
spare1 uint8
|
||||
spare2 uint8
|
||||
spare3 uint8
|
||||
spare4 uint8
|
||||
spare5 uint8
|
||||
spare6 uint8
|
||||
spare7 uint8
|
||||
Net uint8
|
||||
Command TodRequestCommand
|
||||
Address []uint8
|
||||
filler1 uint8
|
||||
filler2 uint8
|
||||
spare1 uint8
|
||||
spare2 uint8
|
||||
spare3 uint8
|
||||
spare4 uint8
|
||||
spare5 uint8
|
||||
spare6 uint8
|
||||
spare7 uint8
|
||||
Net uint8
|
||||
Command TodRequestCommand
|
||||
Address []uint8
|
||||
}
|
||||
|
||||
func (adr *ArtTodRequest) GetOpCode() uint16 {
|
||||
return adr.OpCode
|
||||
}
|
||||
|
||||
func (adr *ArtTodRequest) GetProtVer() uint16 {
|
||||
return uint16(adr.ProtVerHi)<<8 + uint16(adr.ProtVerLo)
|
||||
}
|
||||
|
||||
func (adr *ArtTodRequest) GetID() [8]uint8 {
|
||||
return adr.ID
|
||||
return OpTodRequest
|
||||
}
|
||||
|
||||
func (adr *ArtTodRequest) UnmarshalBinary(data []byte) error {
|
||||
@@ -49,15 +37,14 @@ func (adr *ArtTodRequest) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtTodRequest packet must be at least 32 bytes long")
|
||||
}
|
||||
|
||||
copy(adr.ID[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], adr.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], data[0:8]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
adr.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
adr.ProtVerHi = data[10]
|
||||
adr.ProtVerLo = data[11]
|
||||
opCode := binary.LittleEndian.Uint16(data[8:10])
|
||||
if opCode != OpTodRequest {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtTodRequest packet")
|
||||
}
|
||||
|
||||
offset := 12
|
||||
adr.filler1 = data[offset]
|
||||
@@ -85,10 +72,10 @@ func (adr *ArtTodRequest) MarshalBinary() ([]byte, error) {
|
||||
return nil, errors.New("address count must not be greater than 32")
|
||||
}
|
||||
data := make([]byte, 8+16+len(adr.Address))
|
||||
copy(data[0:8], adr.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], adr.OpCode)
|
||||
data[10] = adr.ProtVerHi
|
||||
data[11] = adr.ProtVerLo
|
||||
copy(data[0:8], ArtNetID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], OpTodRequest)
|
||||
data[10] = 0
|
||||
data[11] = 14
|
||||
data[12] = adr.filler1
|
||||
data[13] = adr.filler2
|
||||
data[14] = adr.spare1
|
||||
|
||||
+54
-126
@@ -17,234 +17,162 @@ func TestGoodArtTodRequestUnmarshal(t *testing.T) {
|
||||
Name: "ACT Packet 1",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x00},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x00},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 2",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 3",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 4",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 5",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 6",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 7",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 8",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 9",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 10",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 11",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 12",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 13",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 14",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 15",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 16",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 17",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "ACT Packet 18",
|
||||
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
Expected: &artnet.ArtTodRequest{
|
||||
ID: artnet.ArtNetID,
|
||||
OpCode: artnet.OpTodRequest,
|
||||
ProtVerHi: 0x00,
|
||||
ProtVerLo: 0x0e,
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
+11
-16
@@ -16,8 +16,8 @@ const (
|
||||
)
|
||||
|
||||
type ArtTrigger struct {
|
||||
ID [8]uint8
|
||||
OpCode uint16
|
||||
id [8]uint8
|
||||
opCode uint16
|
||||
ProtVerHi uint8
|
||||
ProtVerLo uint8
|
||||
filler1 uint8
|
||||
@@ -29,15 +29,7 @@ type ArtTrigger struct {
|
||||
}
|
||||
|
||||
func (at *ArtTrigger) GetOpCode() uint16 {
|
||||
return at.OpCode
|
||||
}
|
||||
|
||||
func (at *ArtTrigger) GetProtVer() uint16 {
|
||||
return uint16(at.ProtVerHi)<<8 + uint16(at.ProtVerLo)
|
||||
}
|
||||
|
||||
func (at *ArtTrigger) GetID() [8]uint8 {
|
||||
return at.ID
|
||||
return OpTrigger
|
||||
}
|
||||
|
||||
func (at *ArtTrigger) UnmarshalBinary(data []byte) error {
|
||||
@@ -46,13 +38,16 @@ func (at *ArtTrigger) UnmarshalBinary(data []byte) error {
|
||||
return errors.New("ArtTrigger packet must be at least 18 bytes long")
|
||||
}
|
||||
|
||||
copy(at.ID[:], data[0:8])
|
||||
copy(at.id[:], data[0:8])
|
||||
|
||||
if !slices.Equal(ArtNetID[:], at.ID[:]) {
|
||||
if !slices.Equal(ArtNetID[:], at.id[:]) {
|
||||
return errors.New("ID does not match Art-Net ID")
|
||||
}
|
||||
|
||||
at.OpCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
at.opCode = binary.LittleEndian.Uint16(data[8:10])
|
||||
if at.opCode != OpTrigger {
|
||||
return errors.New("packet does not have the correct OpCode for an ArtTrigger packet")
|
||||
}
|
||||
at.ProtVerHi = data[10]
|
||||
at.ProtVerLo = data[11]
|
||||
|
||||
@@ -69,8 +64,8 @@ func (at *ArtTrigger) UnmarshalBinary(data []byte) error {
|
||||
|
||||
func (at *ArtTrigger) MarshalBinary() ([]byte, error) {
|
||||
data := make([]byte, 8+10)
|
||||
copy(data[0:8], at.ID[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], at.OpCode)
|
||||
copy(data[0:8], at.id[:])
|
||||
binary.LittleEndian.PutUint16(data[8:10], at.opCode)
|
||||
data[10] = at.ProtVerHi
|
||||
data[11] = at.ProtVerLo
|
||||
data[12] = at.filler1
|
||||
|
||||
Reference in New Issue
Block a user