Compare commits

...

2 Commits

6 changed files with 101 additions and 52 deletions

4
go.mod
View File

@ -1,10 +1,10 @@
module github.com/cyrilix/robocar-recorder-store
go 1.18
go 1.19
require (
github.com/cyrilix/robocar-base v0.1.7
github.com/cyrilix/robocar-protobuf/go v1.0.5
github.com/cyrilix/robocar-protobuf/go v1.2.0
github.com/eclipse/paho.mqtt.golang v1.4.1
github.com/golang/protobuf v1.5.2
go.uber.org/zap v1.21.0

4
go.sum
View File

@ -2,8 +2,8 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/cyrilix/robocar-base v0.1.7 h1:EVzZ0KjigSFpke5f3A/PybEH3WFUEIrYSc3z/dhOZ48=
github.com/cyrilix/robocar-base v0.1.7/go.mod h1:4E11HQSNy2NT8e7MW188y6ST9C0RzarKyn7sK/3V/Lk=
github.com/cyrilix/robocar-protobuf/go v1.0.5 h1:PX1At+pf6G7gJwT4LzJLQu3/LPFTTNNlZmZSYtnSELY=
github.com/cyrilix/robocar-protobuf/go v1.0.5/go.mod h1:Y3AE28K5V7EZxMXp/6A8RhkRz15VOfFy4CjST35FbtQ=
github.com/cyrilix/robocar-protobuf/go v1.2.0 h1:qxTm7X72rizaR8lO5ZpCMOoZv+ix24piiAv8w9Bh5tE=
github.com/cyrilix/robocar-protobuf/go v1.2.0/go.mod h1:Y3AE28K5V7EZxMXp/6A8RhkRz15VOfFy4CjST35FbtQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

@ -8,7 +8,6 @@ import (
mqtt "github.com/eclipse/paho.mqtt.golang"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
"io/ioutil"
"os"
)
@ -69,7 +68,7 @@ func (r *Recorder) onRecordMsg(_ mqtt.Client, message mqtt.Message) {
l.Errorf("unable to create %v directory: %v", imgDir, err)
return
}
err = ioutil.WriteFile(imgName, msg.GetFrame().GetFrame(), os.FileMode(0755))
err = os.WriteFile(imgName, msg.GetFrame().GetFrame(), os.FileMode(0755))
if err != nil {
l.Errorf("unable to write img file %v: %v", imgName, err)
return
@ -83,15 +82,17 @@ func (r *Recorder) onRecordMsg(_ mqtt.Client, message mqtt.Message) {
return
}
record := Record{
UserAngle: msg.GetSteering().GetSteering(),
CamImageArray: imgRef,
UserAngle: msg.GetSteering().GetSteering(),
CamImageArray: imgRef,
AutopilotAngle: msg.GetAutopilotSteering().GetSteering(),
DriveMode: msg.GetDriveMode().GetDriveMode().String(),
}
jsonBytes, err := json.Marshal(&record)
if err != nil {
l.Errorf("unable to marshal json content: %v", err)
return
}
err = ioutil.WriteFile(recordName, jsonBytes, 0755)
err = os.WriteFile(recordName, jsonBytes, 0755)
if err != nil {
l.Errorf("unable to write json file %v: %v", recordName, err)
}
@ -99,6 +100,8 @@ func (r *Recorder) onRecordMsg(_ mqtt.Client, message mqtt.Message) {
}
type Record struct {
UserAngle float32 `json:"user/angle,"`
CamImageArray string `json:"cam/image_array,"`
UserAngle float32 `json:"user/angle,"`
AutopilotAngle float32 `json:"autopilot/angle,"`
CamImageArray string `json:"cam/image_array,"`
DriveMode string `json:"drive/mode,omitempty"`
}

View File

@ -8,6 +8,7 @@ import (
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/golang/protobuf/ptypes/timestamp"
"io/ioutil"
"os"
"path"
"testing"
"time"
@ -35,12 +36,14 @@ func TestRecorder_onRecordMsg(t *testing.T) {
recordSet: "default",
},
args: args{
message: generateMessage("1", "default", -0.5),
message: generateMessage("1", "default", -0.5, 0.6, events.DriveMode_PILOT),
},
wantJsonFileName: "record_1.json",
wantRecord: Record{
UserAngle: -0.5,
CamImageArray: "cam/cam-image_array_1.jpg",
UserAngle: -0.5,
CamImageArray: "cam/cam-image_array_1.jpg",
AutopilotAngle: 0.6,
DriveMode: events.DriveMode_PILOT.String(),
},
},
}
@ -50,7 +53,7 @@ func TestRecorder_onRecordMsg(t *testing.T) {
recordsDir: tt.fields.recordsDir,
}
r.onRecordMsg(nil, tt.args.message)
fis, err := ioutil.ReadDir(tt.fields.recordsDir)
fis, err := os.ReadDir(tt.fields.recordsDir)
if err != nil {
t.Errorf("unable to list files: %v", err)
return
@ -64,7 +67,7 @@ func TestRecorder_onRecordMsg(t *testing.T) {
if fis[0].Name() != tt.name {
t.Errorf("bad directory name '%v', want '%v'", fis[0].Name(), tt.fields.recordSet)
}
records, err := ioutil.ReadDir(path.Join(tt.fields.recordsDir, fis[0].Name()))
records, err := os.ReadDir(path.Join(tt.fields.recordsDir, fis[0].Name()))
if err != nil {
t.Errorf("unable to list record files")
return
@ -113,7 +116,8 @@ func TestRecorder_onRecordMsg(t *testing.T) {
}
}
func generateMessage(id string, recordSet string, userAngle float32) mqtt.Message {
func generateMessage(id string, recordSet string, userAngle float32, autopilotAngle float32,
driveMode events.DriveMode) mqtt.Message {
now := time.Now()
msg := events.RecordMessage{
Frame: &events.FrameMessage{
@ -139,6 +143,21 @@ func generateMessage(id string, recordSet string, userAngle float32) mqtt.Messag
},
},
},
DriveMode: &events.DriveModeMessage{
DriveMode: driveMode,
},
AutopilotSteering: &events.SteeringMessage{
Steering: autopilotAngle,
Confidence: 0.8,
FrameRef: &events.FrameRef{
Name: fmt.Sprintf("framie-%s", id),
Id: id,
CreatedAt: &timestamp.Timestamp{
Seconds: now.Unix(),
Nanos: int32(now.Nanosecond()),
},
},
},
RecordSet: recordSet,
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.12.4
// protoc-gen-go v1.28.1
// protoc v3.21.4
// source: events/events.proto
package events
@ -468,17 +468,17 @@ func (x *ObjectsMessage) GetFrameRef() *FrameRef {
return nil
}
// BoundingBox that contains an object
// BoundingBox that contains an object, coordinates as percent
type Object struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Type TypeObject `protobuf:"varint,1,opt,name=type,proto3,enum=robocar.events.TypeObject" json:"type,omitempty"`
Left int32 `protobuf:"varint,2,opt,name=left,proto3" json:"left,omitempty"`
Top int32 `protobuf:"varint,3,opt,name=top,proto3" json:"top,omitempty"`
Right int32 `protobuf:"varint,4,opt,name=right,proto3" json:"right,omitempty"`
Bottom int32 `protobuf:"varint,5,opt,name=bottom,proto3" json:"bottom,omitempty"`
Left float32 `protobuf:"fixed32,2,opt,name=left,proto3" json:"left,omitempty"`
Top float32 `protobuf:"fixed32,3,opt,name=top,proto3" json:"top,omitempty"`
Right float32 `protobuf:"fixed32,4,opt,name=right,proto3" json:"right,omitempty"`
Bottom float32 `protobuf:"fixed32,5,opt,name=bottom,proto3" json:"bottom,omitempty"`
Confidence float32 `protobuf:"fixed32,6,opt,name=confidence,proto3" json:"confidence,omitempty"`
}
@ -521,28 +521,28 @@ func (x *Object) GetType() TypeObject {
return TypeObject_ANY
}
func (x *Object) GetLeft() int32 {
func (x *Object) GetLeft() float32 {
if x != nil {
return x.Left
}
return 0
}
func (x *Object) GetTop() int32 {
func (x *Object) GetTop() float32 {
if x != nil {
return x.Top
}
return 0
}
func (x *Object) GetRight() int32 {
func (x *Object) GetRight() float32 {
if x != nil {
return x.Right
}
return 0
}
func (x *Object) GetBottom() int32 {
func (x *Object) GetBottom() float32 {
if x != nil {
return x.Bottom
}
@ -807,9 +807,11 @@ type RecordMessage struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Frame *FrameMessage `protobuf:"bytes,1,opt,name=frame,proto3" json:"frame,omitempty"`
Steering *SteeringMessage `protobuf:"bytes,2,opt,name=steering,proto3" json:"steering,omitempty"`
RecordSet string `protobuf:"bytes,3,opt,name=recordSet,proto3" json:"recordSet,omitempty"` // Record set name
Frame *FrameMessage `protobuf:"bytes,1,opt,name=frame,proto3" json:"frame,omitempty"`
Steering *SteeringMessage `protobuf:"bytes,2,opt,name=steering,proto3" json:"steering,omitempty"`
AutopilotSteering *SteeringMessage `protobuf:"bytes,4,opt,name=autopilot_steering,json=autopilotSteering,proto3" json:"autopilot_steering,omitempty"`
DriveMode *DriveModeMessage `protobuf:"bytes,5,opt,name=drive_mode,json=driveMode,proto3" json:"drive_mode,omitempty"`
RecordSet string `protobuf:"bytes,3,opt,name=recordSet,proto3" json:"recordSet,omitempty"` // Record set name
}
func (x *RecordMessage) Reset() {
@ -858,6 +860,20 @@ func (x *RecordMessage) GetSteering() *SteeringMessage {
return nil
}
func (x *RecordMessage) GetAutopilotSteering() *SteeringMessage {
if x != nil {
return x.AutopilotSteering
}
return nil
}
func (x *RecordMessage) GetDriveMode() *DriveModeMessage {
if x != nil {
return x.DriveMode
}
return nil
}
func (x *RecordMessage) GetRecordSet() string {
if x != nil {
return x.RecordSet
@ -918,10 +934,10 @@ var file_events_events_proto_rawDesc = []byte{
0x0e, 0x32, 0x1a, 0x2e, 0x72, 0x6f, 0x62, 0x6f, 0x63, 0x61, 0x72, 0x2e, 0x65, 0x76, 0x65, 0x6e,
0x74, 0x73, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x04, 0x74,
0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x65, 0x66, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28,
0x05, 0x52, 0x04, 0x6c, 0x65, 0x66, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6f, 0x70, 0x18, 0x03,
0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x74, 0x6f, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x69, 0x67,
0x68, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x72, 0x69, 0x67, 0x68, 0x74, 0x12,
0x16, 0x0a, 0x06, 0x62, 0x6f, 0x74, 0x74, 0x6f, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52,
0x02, 0x52, 0x04, 0x6c, 0x65, 0x66, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x6f, 0x70, 0x18, 0x03,
0x20, 0x01, 0x28, 0x02, 0x52, 0x03, 0x74, 0x6f, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x69, 0x67,
0x68, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, 0x72, 0x69, 0x67, 0x68, 0x74, 0x12,
0x16, 0x0a, 0x06, 0x62, 0x6f, 0x74, 0x74, 0x6f, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x02, 0x52,
0x06, 0x62, 0x6f, 0x74, 0x74, 0x6f, 0x6d, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x69,
0x64, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0a, 0x63, 0x6f, 0x6e,
0x66, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x2f, 0x0a, 0x13, 0x53, 0x77, 0x69, 0x74, 0x63,
@ -950,7 +966,7 @@ var file_events_events_proto_rawDesc = []byte{
0x74, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x6e, 0x67, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x02,
0x52, 0x05, 0x61, 0x6e, 0x67, 0x6c, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x69,
0x64, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x02, 0x52, 0x0a, 0x63, 0x6f, 0x6e,
0x66, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x9e, 0x01, 0x0a, 0x0d, 0x52, 0x65, 0x63, 0x6f,
0x66, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x22, 0xaf, 0x02, 0x0a, 0x0d, 0x52, 0x65, 0x63, 0x6f,
0x72, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x32, 0x0a, 0x05, 0x66, 0x72, 0x61,
0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x72, 0x6f, 0x62, 0x6f, 0x63,
0x61, 0x72, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x4d,
@ -958,16 +974,25 @@ var file_events_events_proto_rawDesc = []byte{
0x08, 0x73, 0x74, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x1f, 0x2e, 0x72, 0x6f, 0x62, 0x6f, 0x63, 0x61, 0x72, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73,
0x2e, 0x53, 0x74, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x52, 0x08, 0x73, 0x74, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65,
0x63, 0x6f, 0x72, 0x64, 0x53, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72,
0x65, 0x63, 0x6f, 0x72, 0x64, 0x53, 0x65, 0x74, 0x2a, 0x2d, 0x0a, 0x09, 0x44, 0x72, 0x69, 0x76,
0x65, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x49, 0x4e, 0x56, 0x41, 0x4c, 0x49, 0x44,
0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x55, 0x53, 0x45, 0x52, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05,
0x50, 0x49, 0x4c, 0x4f, 0x54, 0x10, 0x02, 0x2a, 0x32, 0x0a, 0x0a, 0x54, 0x79, 0x70, 0x65, 0x4f,
0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x4e, 0x59, 0x10, 0x00, 0x12, 0x07,
0x0a, 0x03, 0x43, 0x41, 0x52, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x42, 0x55, 0x4d, 0x50, 0x10,
0x02, 0x12, 0x08, 0x0a, 0x04, 0x50, 0x4c, 0x4f, 0x54, 0x10, 0x03, 0x42, 0x0a, 0x5a, 0x08, 0x2e,
0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x52, 0x08, 0x73, 0x74, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x12, 0x4e, 0x0a, 0x12, 0x61, 0x75,
0x74, 0x6f, 0x70, 0x69, 0x6c, 0x6f, 0x74, 0x5f, 0x73, 0x74, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67,
0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x72, 0x6f, 0x62, 0x6f, 0x63, 0x61, 0x72,
0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x53, 0x74, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x11, 0x61, 0x75, 0x74, 0x6f, 0x70, 0x69, 0x6c,
0x6f, 0x74, 0x53, 0x74, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x12, 0x3f, 0x0a, 0x0a, 0x64, 0x72,
0x69, 0x76, 0x65, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20,
0x2e, 0x72, 0x6f, 0x62, 0x6f, 0x63, 0x61, 0x72, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e,
0x44, 0x72, 0x69, 0x76, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x52, 0x09, 0x64, 0x72, 0x69, 0x76, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x72,
0x65, 0x63, 0x6f, 0x72, 0x64, 0x53, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09,
0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x53, 0x65, 0x74, 0x2a, 0x2d, 0x0a, 0x09, 0x44, 0x72, 0x69,
0x76, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x49, 0x4e, 0x56, 0x41, 0x4c, 0x49,
0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x55, 0x53, 0x45, 0x52, 0x10, 0x01, 0x12, 0x09, 0x0a,
0x05, 0x50, 0x49, 0x4c, 0x4f, 0x54, 0x10, 0x02, 0x2a, 0x32, 0x0a, 0x0a, 0x54, 0x79, 0x70, 0x65,
0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x4e, 0x59, 0x10, 0x00, 0x12,
0x07, 0x0a, 0x03, 0x43, 0x41, 0x52, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x42, 0x55, 0x4d, 0x50,
0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x50, 0x4c, 0x4f, 0x54, 0x10, 0x03, 0x42, 0x0a, 0x5a, 0x08,
0x2e, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -1016,11 +1041,13 @@ var file_events_events_proto_depIdxs = []int32{
11, // 11: robocar.events.Ellipse.center:type_name -> robocar.events.Point
3, // 12: robocar.events.RecordMessage.frame:type_name -> robocar.events.FrameMessage
4, // 13: robocar.events.RecordMessage.steering:type_name -> robocar.events.SteeringMessage
14, // [14:14] is the sub-list for method output_type
14, // [14:14] is the sub-list for method input_type
14, // [14:14] is the sub-list for extension type_name
14, // [14:14] is the sub-list for extension extendee
0, // [0:14] is the sub-list for field type_name
4, // 14: robocar.events.RecordMessage.autopilot_steering:type_name -> robocar.events.SteeringMessage
6, // 15: robocar.events.RecordMessage.drive_mode:type_name -> robocar.events.DriveModeMessage
16, // [16:16] is the sub-list for method output_type
16, // [16:16] is the sub-list for method input_type
16, // [16:16] is the sub-list for extension type_name
16, // [16:16] is the sub-list for extension extendee
0, // [0:16] is the sub-list for field type_name
}
func init() { file_events_events_proto_init() }

2
vendor/modules.txt vendored
View File

@ -3,7 +3,7 @@
github.com/cyrilix/robocar-base/cli
github.com/cyrilix/robocar-base/service
github.com/cyrilix/robocar-base/testtools
# github.com/cyrilix/robocar-protobuf/go v1.0.5
# github.com/cyrilix/robocar-protobuf/go v1.2.0
## explicit; go 1.18
github.com/cyrilix/robocar-protobuf/go/events
# github.com/eclipse/paho.mqtt.golang v1.4.1