Skip to content

Commit

Permalink
Correct Eui48 length to 8 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 3, 2019
1 parent 4c2adf6 commit 6b9a64b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions impl/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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, ':')
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sunspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion typelen/lengths.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
Count = 1
Enum16 = 1
Enum32 = 2
Eui48 = 3
Eui48 = 4
Float32 = 2
Int16 = 1
Int32 = 2
Expand Down

0 comments on commit 6b9a64b

Please sign in to comment.