-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
54 lines (44 loc) · 1.06 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package gobuki
import (
"encoding/binary"
"errors"
"fmt"
)
// Version represents kobuki hardware version
type Version struct {
Minor uint8
Major uint8
}
func (v *Version) String() string {
return fmt.Sprintf("%d-%d", v.Major, v.Minor)
}
// FromBytes reads version from bytes
func (v *Version) FromBytes(b []byte) error {
if len(b) < 2 {
return fmt.Errorf("length missmatch (%d)", len(b))
}
v.Major = b[0]
v.Minor = b[1]
return nil
}
// UniqueID Contains Unique Device IDentifier of robot.
// This value is unique for all robot in the world.
// It can be represented by triplet form: <UDID0>-<UDID1>-<UDID2>
type UniqueID struct {
UDID0 uint32
UDID1 uint32
UDID2 uint32
}
// FromBytes reads UID from bytes
func (u *UniqueID) FromBytes(b []byte) error {
if len(b) < 3 {
return errors.New("length missmatch")
}
u.UDID0 = binary.LittleEndian.Uint32(b[:4])
u.UDID1 = binary.LittleEndian.Uint32(b[4:8])
u.UDID2 = binary.LittleEndian.Uint32(b[8:12])
return nil
}
func (u *UniqueID) String() string {
return fmt.Sprintf("%d-%d-%d", u.UDID0, u.UDID1, u.UDID2)
}