aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-12-28 22:18:13 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-12-28 22:18:13 +0100
commit987606d976bf7004dcbdbbcfb45ac31f5913f477 (patch)
tree48de77846b9c49b964f5b83fa835829c946036ea
parent6cce2f71fe994d33c785541718c16fb235a09768 (diff)
More missing parts
-rw-r--r--cmd/experimental/main.go4
-rw-r--r--id_string.go42
-rw-r--r--protocol.go93
-rw-r--r--protocol2.go19
4 files changed, 112 insertions, 46 deletions
diff --git a/cmd/experimental/main.go b/cmd/experimental/main.go
index d7d8b23..7c9b72a 100644
--- a/cmd/experimental/main.go
+++ b/cmd/experimental/main.go
@@ -2,8 +2,8 @@ package main
import (
"log"
- "mystuff/anki"
+ "dim13.org/anki"
"github.com/currantlabs/gatt"
)
@@ -81,6 +81,8 @@ func onConnect(p gatt.Peripheral, err error) {
func onNotify(c *gatt.Characteristic, b []byte, err error) {
log.Printf("notify: % X | %q\n", b, b)
+ id, payload := anki.SplitMsg(b)
+ log.Printf("ID: %v | % X\n", id, payload)
}
func onDisconnect(p gatt.Peripheral, err error) {
diff --git a/id_string.go b/id_string.go
new file mode 100644
index 0000000..efd0daa
--- /dev/null
+++ b/id_string.go
@@ -0,0 +1,42 @@
+// Code generated by "stringer -type=ID"; DO NOT EDIT
+
+package anki
+
+import "fmt"
+
+const _ID_name = "VehicleMsgC2VDisconnectVehicleMsgC2VPingRequestVehicleMsgV2CPingResponseVehicleMsgC2VVersionRequestVehicleMsgV2CVersionResponseVehicleMsgC2VBatteryLevelRequestVehicleMsgV2CBatteryLevelResponseVehicleMsgC2VSetLightsVehicleMsgC2VSetSpeedVehicleMsgC2VChangeLaneVehicleMsgC2VCancelLaneChangeVehicleMsgV2CLocalizationPositionUpdateVehicleMsgV2CLocalizationTransitionUpdateVehicleMsgV2CLocalizationIntersectionUpdateVehicleMsgV2cVehicleDelocalizedVehicleMsgC2VSetOffsetFromRoadCenterVehicleMsgV2COffsetFromRoadCenterUpdateVehicleMsgC2VTurnVehicleMsgC2VLightsPatternVehicleMsgV2CSpeedUpdateVehicleMsgV2CStatusUpdateVehicleMsgC2VSetConfigParamsVehicleMsgV2CCollisionDetectedVehicleMsgV2CCycleOvertimeVehicleMsgC2VSDKMode"
+
+var _ID_map = map[ID]string{
+ 13: _ID_name[0:23],
+ 22: _ID_name[23:47],
+ 23: _ID_name[47:72],
+ 24: _ID_name[72:99],
+ 25: _ID_name[99:127],
+ 26: _ID_name[127:159],
+ 27: _ID_name[159:192],
+ 29: _ID_name[192:214],
+ 36: _ID_name[214:235],
+ 37: _ID_name[235:258],
+ 38: _ID_name[258:287],
+ 39: _ID_name[287:326],
+ 41: _ID_name[326:367],
+ 42: _ID_name[367:410],
+ 43: _ID_name[410:441],
+ 44: _ID_name[441:477],
+ 45: _ID_name[477:516],
+ 50: _ID_name[516:533],
+ 51: _ID_name[533:559],
+ 54: _ID_name[559:583],
+ 63: _ID_name[583:608],
+ 69: _ID_name[608:636],
+ 77: _ID_name[636:666],
+ 134: _ID_name[666:692],
+ 144: _ID_name[692:712],
+}
+
+func (i ID) String() string {
+ if str, ok := _ID_map[i]; ok {
+ return str
+ }
+ return fmt.Sprintf("ID(%d)", i)
+}
diff --git a/protocol.go b/protocol.go
index 6c87c98..4050574 100644
--- a/protocol.go
+++ b/protocol.go
@@ -2,77 +2,86 @@ package anki
import "encoding/binary"
-const (
- VehicleMsgMaxSize = 20
- VehicleMsgPayloadMaxSize = 18
- VehicleMsgBaseSize = 1
-)
+// VehicleMsgMaxSize = 20
+// VehicleMsgPayloadMaxSize = 18
+// VehicleMsgBaseSize = 1
+
+//go:generate stringer -type=ID
+
+type ID uint8
// Identifier for a vehicle message
const (
// BLE Connection
- VehicleMsgC2VDisconnect = 0x0d
+ VehicleMsgC2VDisconnect ID = 0x0d
// Ping request / response
- VehicleMsgC2VPingRequest = 0x16
- VehicleMsgV2CPingResponse = 0x17
+ VehicleMsgC2VPingRequest ID = 0x16
+ VehicleMsgV2CPingResponse ID = 0x17
// Messages for checking vehicle version info
- VehicleMsgC2VVersionRequest = 0x18
- VehicleMsgV2CVersionResponse = 0x19
+ VehicleMsgC2VVersionRequest ID = 0x18
+ VehicleMsgV2CVersionResponse ID = 0x19
// Baterry level
- VehicleMsgC2VBatteryLevelRequest = 0x1a
- VehicleMsgV2CBatteryLevelResponse = 0x1b
+ VehicleMsgC2VBatteryLevelRequest ID = 0x1a
+ VehicleMsgV2CBatteryLevelResponse ID = 0x1b
// Lights
- VehicleMsgC2VSetLights = 0x1d
+ VehicleMsgC2VSetLights ID = 0x1d
// Driving Commands
- VehicleMsgC2VSetSpeed = 0x24
- VehicleMsgC2VChangeLane = 0x25
- VehicleMsgC2VCancelLaneChange = 0x26
- VehicleMsgC2VTurn = 0x32
+ VehicleMsgC2VSetSpeed ID = 0x24
+ VehicleMsgC2VChangeLane ID = 0x25
+ VehicleMsgC2VCancelLaneChange ID = 0x26
+ VehicleMsgC2VTurn ID = 0x32
// Vehicle position updates
- VehicleMsgV2CLocalizationPositionUpdate = 0x27
- VehicleMsgV2CLocalizationTransitionUpdate = 0x29
- VehicleMsgV2CLocalizationIntersectionUpdate = 0x2a
- VehicleMsgV2cVehicleDelocalized = 0x2b
- VehicleMsgC2VSetOffsetFromRoadCenter = 0x2c
- VehicleMsgV2COffsetFromRoadCenterUpdate = 0x2d
+ VehicleMsgV2CLocalizationPositionUpdate ID = 0x27
+ VehicleMsgV2CLocalizationTransitionUpdate ID = 0x29
+ VehicleMsgV2CLocalizationIntersectionUpdate ID = 0x2a
+ VehicleMsgV2cVehicleDelocalized ID = 0x2b
+ VehicleMsgC2VSetOffsetFromRoadCenter ID = 0x2c
+ VehicleMsgV2COffsetFromRoadCenterUpdate ID = 0x2d
// Light Patterns
- VehicleMsgC2VLightsPattern = 0x33
+ VehicleMsgC2VLightsPattern ID = 0x33
// Vehicle Configuration Prameters
- VehicleMsgC2VSetConfigParams = 0x45
+ VehicleMsgC2VSetConfigParams ID = 0x45
// SDK Mode
- VehicleMsgC2VSDKMode = 0x90
+ VehicleMsgC2VSDKMode ID = 0x90
)
type VehicleMsg struct {
Size uint8
- MsgID uint8
- Payload [VehicleMsgMaxSize]byte
+ MsgID ID
+ Payload []uint8 // MaxSize 18
+}
+
+func SplitMsg(b []byte) (id ID, payload []byte) {
+ if len(b) < 2 {
+ return 0, nil
+ }
+ return ID(b[1]), b[2:]
}
type VehicleMsgVersionResponse struct {
Size uint8
- MsgID uint8
+ MsgID ID
Version uint32
}
type VehicleBatteryLevelResponse struct {
Size uint8
- MsgID uint8
+ MsgID ID
BatteryLevel uint16
}
type VehicleMsgSDKMode struct {
Size uint8
- MsgID uint8
+ MsgID ID
On uint8
Flags uint8
}
@@ -86,7 +95,7 @@ func (v *VehicleMsgSDKMode) Set(on, flags uint8) {
type VehicleMsgSetSpeed struct {
Size uint8
- MsgID uint8
+ MsgID ID
Speed uint16 // mm/sec
Accel uint16 // mm/sec²
SpeedLimit uint8 // respect road piece speed limit
@@ -114,14 +123,14 @@ const (
type VehicleMsgTurn struct {
Size uint8
- MsgID uint8
+ MsgID ID
Type uint8
Trigger uint8
}
type VehicleMsgSetOffsetFromRoadCenter struct {
Size uint8
- MsgID uint8
+ MsgID ID
Offset float32 // mm
}
@@ -133,7 +142,7 @@ func (v *VehicleMsgSetOffsetFromRoadCenter) Set(offset float32) {
type VehicleMsgChangeLane struct {
Size uint8
- MsgID uint8
+ MsgID ID
HorizontalSpeed uint16 // mm/sec
HorizontalAccel uint16 // mm/sec²
Offset float32 // from road center mm
@@ -158,7 +167,7 @@ const (
type VehicleLocalizationPositionUpdate struct {
Size uint8
- MsgID uint8
+ MsgID ID
LocalizationID uint8
RoadPieceID uint8
Offset float32 // from road center mm
@@ -180,7 +189,7 @@ const (
type VehicleMsgLocalizationTransitionUpdate struct {
Size uint8
- MsgID uint8
+ MsgID ID
RoadPieceIDX uint8
RoadPieceIDXPrev uint8
Offset float32 // from road center mm
@@ -211,7 +220,7 @@ const (
type VehicleMsgLocalizationIntersectionUpdate struct {
Size uint8
- MsgID uint8
+ MsgID ID
RoadPieceIDX uint8
Offset float32 // from road center mm
@@ -223,7 +232,7 @@ type VehicleMsgLocalizationIntersectionUpdate struct {
type VehicleMsgOffsetFromRoadCenterUpdate struct {
Size uint8
- MsgID uint8
+ MsgID ID
Offset float32 // from road center mm
LaneChangeID uint8
}
@@ -239,7 +248,7 @@ const (
type VehicleMsgSetLights struct {
Size uint8
- MsgID uint8
+ MsgID ID
LightMask uint8 // valid and value bits for lights
}
@@ -300,7 +309,7 @@ func (v *VehicleLightConfig) Set(channel, effect uint8, start, end uint8, cycles
type VehicleMsgLightsPattern struct {
Size uint8
- MsgID uint8
+ MsgID ID
ChannelCount uint8
ChannelConfig [3]VehicleLightConfig
}
@@ -326,7 +335,7 @@ const (
type VehicleMsgSetConfigParams struct {
Size uint8
- MsgID uint8
+ MsgID ID
SuperCodeParseMask uint8
TrackMaterial uint8
}
diff --git a/protocol2.go b/protocol2.go
index cf8c4c0..dbffd22 100644
--- a/protocol2.go
+++ b/protocol2.go
@@ -1,11 +1,13 @@
package anki
const (
- VehicleMsgV2CSpeedUpdate = 0x36
- VehicleMsgV2CStatusUpdate = 0x3f
- VehicleMsgV2CCollisionDetected = 0x4d
+ VehicleMsgV2CSpeedUpdate ID = 0x36
+ VehicleMsgV2CStatusUpdate ID = 0x3f
+ VehicleMsgV2CCollisionDetected ID = 0x4d
+ VehicleMsgV2CCycleOvertime ID = 0x86
)
+// 07 36 20 03 98 3A 2A 00 cchhh
type VehicleMsgSpeedUpdate struct {
Size uint8
MsgID uint8
@@ -14,6 +16,7 @@ type VehicleMsgSpeedUpdate struct {
CurrentSpeed uint16 // mm/sec
}
+// 05 3F 01 00 01 00
type VehicleMsgStatusUpdate struct {
Size uint8
MsgID uint8
@@ -23,9 +26,19 @@ type VehicleMsgStatusUpdate struct {
HasChargedBattery uint8
}
+// 03 4D 01 00
type VehicleMsgCollisionDetected struct {
Size uint8
MsgID uint8
WasSideOnCollision uint8
WasFrontBackCollision uint8
}
+
+// 0B 86 11 00 26 08 00 00 13 10 00 00 cchii
+type VehicleMsgCycleOvertime struct {
+ Size uint8
+ MsgID ID
+ NumOvertimeCycles uint16
+ AverageCycleTime uint32 // µsec
+ MaxCycleTime uint32 // µsec
+}