From 6b9a64bd4a35615075070c2b9db6de76c5c3673d Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 3 Jul 2019 11:28:33 +0200 Subject: [PATCH] Correct Eui48 length to 8 bytes --- impl/point.go | 14 +++++++++----- sunspec.go | 2 +- typelen/lengths.go | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/impl/point.go b/impl/point.go index 58a3681..d312e9c 100644 --- a/impl/point.go +++ b/impl/point.go @@ -4,13 +4,14 @@ import ( "encoding/binary" "errors" "fmt" - "github.com/crabmusket/gosunspec" + "math" + "strconv" + + sunspec "github.com/crabmusket/gosunspec" "github.com/crabmusket/gosunspec/smdx" "github.com/crabmusket/gosunspec/spi" "github.com/crabmusket/gosunspec/typelabel" "github.com/crabmusket/gosunspec/typelen" - "math" - "strconv" ) var ( @@ -549,7 +550,9 @@ func (p *point) MarshalXML() string { return string(buf) case typelabel.Eui48: buf := []byte{} - for x, b := range p.Eui48() { + eui48 := p.Eui48() + // first word is unused - ignore + for x, b := range eui48[2:] { if x != 0 { buf = append(buf, ':') } @@ -635,7 +638,8 @@ func (p *point) UnmarshalXML(s string) error { } case typelabel.Eui48: var buf sunspec.Eui48 - if _, err := fmt.Sscanf(s, "%02x:%02x:%02x:%02x:%02x:%02x", &buf[0], &buf[1], &buf[2], &buf[3], &buf[4], &buf[5]); err != nil { + // first word is unused - ignore + if _, err := fmt.Sscanf(s, "%02x:%02x:%02x:%02x:%02x:%02x", &buf[2], &buf[3], &buf[4], &buf[5], &buf[6], &buf[7]); err != nil { return err } else { p.SetEui48(buf) diff --git a/sunspec.go b/sunspec.go index 8853303..ffe6357 100644 --- a/sunspec.go +++ b/sunspec.go @@ -66,7 +66,7 @@ type Enum16 uint16 type Enum32 uint32 // An hardware address (like a MAC address) - see https://standards.ieee.org/develop/regauth/tut/eui48.pdf -type Eui48 [6]byte +type Eui48 [8]byte // A 32bit IPv4 address (binary) type Ipaddr [4]byte diff --git a/typelen/lengths.go b/typelen/lengths.go index accb198..dbab107 100644 --- a/typelen/lengths.go +++ b/typelen/lengths.go @@ -13,7 +13,7 @@ const ( Count = 1 Enum16 = 1 Enum32 = 2 - Eui48 = 3 + Eui48 = 4 Float32 = 2 Int16 = 1 Int32 = 2