Apply go fix modernizations
This commit is contained in:
44
protocol.go
44
protocol.go
@@ -13,15 +13,15 @@ const (
|
||||
Port = 6454
|
||||
ProtocolVersion = 14
|
||||
|
||||
OpPoll uint16 = 0x2000
|
||||
OpPollReply uint16 = 0x2100
|
||||
OpDmx uint16 = 0x5000
|
||||
OpSync uint16 = 0x5200
|
||||
OpAddress uint16 = 0x6000
|
||||
OpInput uint16 = 0x7000
|
||||
OpTodData uint16 = 0x8100
|
||||
OpPoll uint16 = 0x2000
|
||||
OpPollReply uint16 = 0x2100
|
||||
OpDmx uint16 = 0x5000
|
||||
OpSync uint16 = 0x5200
|
||||
OpAddress uint16 = 0x6000
|
||||
OpInput uint16 = 0x7000
|
||||
OpTodData uint16 = 0x8100
|
||||
OpTodControl uint16 = 0x8200
|
||||
OpRdm uint16 = 0x8300
|
||||
OpRdm uint16 = 0x8300
|
||||
|
||||
PortTypeOutput uint8 = 0x80
|
||||
PortTypeInput uint8 = 0x40
|
||||
@@ -51,10 +51,10 @@ func NewUniverse(netVal, subnet, universe uint8) Universe {
|
||||
return Universe((uint16(netVal&0x7F) << 8) | (uint16(subnet&0x0F) << 4) | uint16(universe&0x0F))
|
||||
}
|
||||
|
||||
func (u Universe) Net() uint8 { return uint8((u >> 8) & 0x7F) }
|
||||
func (u Universe) SubNet() uint8 { return uint8((u >> 4) & 0x0F) }
|
||||
func (u Universe) Net() uint8 { return uint8((u >> 8) & 0x7F) }
|
||||
func (u Universe) SubNet() uint8 { return uint8((u >> 4) & 0x0F) }
|
||||
func (u Universe) Universe() uint8 { return uint8(u & 0x0F) }
|
||||
func (u Universe) String() string { return fmt.Sprintf("%d.%d.%d", u.Net(), u.SubNet(), u.Universe()) }
|
||||
func (u Universe) String() string { return fmt.Sprintf("%d.%d.%d", u.Net(), u.SubNet(), u.Universe()) }
|
||||
|
||||
type DMXPacket struct {
|
||||
ProtocolVersion uint16
|
||||
@@ -119,10 +119,7 @@ func (p *PollReplyPacket) GetLongName() string {
|
||||
}
|
||||
|
||||
func (p *PollReplyPacket) NumPorts() int {
|
||||
n := int(p.NumPortsLo)
|
||||
if n > 4 {
|
||||
n = 4
|
||||
}
|
||||
n := min(int(p.NumPortsLo), 4)
|
||||
return n
|
||||
}
|
||||
|
||||
@@ -148,7 +145,7 @@ func (p *PollReplyPacket) OutputUniverses() []Universe {
|
||||
return result
|
||||
}
|
||||
|
||||
func ParsePacket(data []byte) (uint16, interface{}, error) {
|
||||
func ParsePacket(data []byte) (uint16, any, error) {
|
||||
if len(data) < 10 {
|
||||
return 0, nil, ErrPacketTooShort
|
||||
}
|
||||
@@ -187,10 +184,7 @@ func parseDMXPacket(data []byte) (*DMXPacket, error) {
|
||||
Length: binary.BigEndian.Uint16(data[16:18]),
|
||||
}
|
||||
|
||||
dataLen := int(pkt.Length)
|
||||
if dataLen > 512 {
|
||||
dataLen = 512
|
||||
}
|
||||
dataLen := min(int(pkt.Length), 512)
|
||||
if len(data) >= 18+dataLen {
|
||||
copy(pkt.Data[:], data[18:18+dataLen])
|
||||
}
|
||||
@@ -248,10 +242,7 @@ func parsePollReplyPacket(data []byte) (*PollReplyPacket, error) {
|
||||
}
|
||||
|
||||
func BuildDMXPacket(universe Universe, sequence uint8, data []byte) []byte {
|
||||
dataLen := len(data)
|
||||
if dataLen > 512 {
|
||||
dataLen = 512
|
||||
}
|
||||
dataLen := min(len(data), 512)
|
||||
if dataLen%2 != 0 {
|
||||
dataLen++
|
||||
}
|
||||
@@ -295,10 +286,7 @@ func BuildPollReplyPacket(ip [4]byte, mac [6]byte, shortName, longName string, u
|
||||
copy(buf[26:44], shortName)
|
||||
copy(buf[44:108], longName)
|
||||
|
||||
numPorts := len(universes)
|
||||
if numPorts > 4 {
|
||||
numPorts = 4
|
||||
}
|
||||
numPorts := min(len(universes), 4)
|
||||
buf[173] = byte(numPorts)
|
||||
|
||||
for i := 0; i < numPorts; i++ {
|
||||
|
||||
Reference in New Issue
Block a user