aboutsummaryrefslogtreecommitdiff
path: root/protocol.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-12-29 21:08:59 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-12-29 21:08:59 +0100
commitfc3669937463b329a815f148106241883020388e (patch)
tree67b930bff78c7d6ba6b6fc555bf92d03ab7abd1d /protocol.go
parent948173c40d4b0d445d8dba091ea0fbb36b01b669 (diff)
Lights
Diffstat (limited to 'protocol.go')
-rw-r--r--protocol.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/protocol.go b/protocol.go
index 273967f..5c39db4 100644
--- a/protocol.go
+++ b/protocol.go
@@ -1,6 +1,9 @@
package anki
-import "encoding/binary"
+import (
+ "bytes"
+ "encoding/binary"
+)
// VehicleMsgMaxSize = 20
// VehicleMsgPayloadMaxSize = 18
@@ -67,6 +70,15 @@ func SplitMsg(b []byte) (id ID, payload []byte) {
return ID(b[1]), b[2:]
}
+func Encode(v interface{}) []byte {
+ buf := new(bytes.Buffer)
+ binary.Write(buf, binary.LittleEndian, v)
+ b := buf.Bytes()[:]
+ z := make([]byte, len(b))
+ copy(z, b) // FIXME workaround "cgo argument has Go pointer to Go pointer"
+ return z
+}
+
type VehicleMsgVersionResponse struct {
Size uint8
MsgID ID
@@ -304,7 +316,7 @@ func (v *VehicleLightConfig) Set(channel, effect uint8, start, end uint8, cycles
if cpm > VehicleMaxLightTime {
cpm = VehicleMaxLightTime
}
- v.Cycles = uint8(cpm / 6)
+ v.Cycles = uint8(cpm / 6) // BUG integer division
}
type VehicleMsgLightsPattern struct {