aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-08-20 16:48:07 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-08-20 16:48:07 +0200
commit0cb37a1ceda90b439ffc23083aa8d8802fe9df26 (patch)
tree823c88429033df8b8cfef5ac483063b1c20e348e
parent8daa93b55c3d05adb951f1f494eaf29ba5caec38 (diff)
codegen
-rw-r--r--car/car.ino24
-rw-r--r--car/elegoo.pb.c39
-rw-r--r--car/elegoo.pb.h47
-rw-r--r--car/elegoo/elegoo.pb.go68
-rw-r--r--car/elegoo/elegoo.proto (renamed from car/elegoo.proto)10
-rw-r--r--car/elegoo/main.go18
6 files changed, 72 insertions, 134 deletions
diff --git a/car/car.ino b/car/car.ino
index b99dd43..b87a3d4 100644
--- a/car/car.ino
+++ b/car/car.ino
@@ -141,16 +141,24 @@ void setup() {
}
void loop() {
- //Command cmd = Cmd_init_zero;
- //pb_decode_delimited(&istream, Command_fields, &cmd);
+ Command cmd = Command_init_zero;
+ pb_decode_delimited(&istream, Command_fields, &cmd);
Event evt = Event_init_zero;
- int d = distance();
- if (d > 0) {
- evt.Distance = d;
- evt.has_Distance = true;
- pb_encode_delimited(&ostream, Event_fields, &evt);
- }
+
+ evt.Distance = distance();
+ evt.has_Distance = evt.Distance > 0;
+
+ evt.SensorA = digitalRead(S1);
+ evt.has_SensorA = true;
+
+ evt.SensorB = digitalRead(S2);
+ evt.has_SensorB = true;
+
+ evt.SensorC = digitalRead(S3);
+ evt.has_SensorC = true;
+
+ pb_encode_delimited(&ostream, Event_fields, &evt);
delay(1000);
//ultra();
diff --git a/car/elegoo.pb.c b/car/elegoo.pb.c
index 1a268f4..e968fc9 100644
--- a/car/elegoo.pb.c
+++ b/car/elegoo.pb.c
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
-/* Generated by nanopb-0.3.6 at Tue Jan 24 21:09:08 2017. */
+/* Generated by nanopb-0.3.6 at Sun Aug 20 16:43:10 2017. */
#include "elegoo.pb.h"
@@ -10,15 +10,10 @@
-const pb_field_t Command_fields[3] = {
- PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, Command, SetSpeed, SetSpeed, &Speed_fields),
- PB_FIELD( 2, BOOL , OPTIONAL, STATIC , OTHER, Command, Stop, SetSpeed, 0),
- PB_LAST_FIELD
-};
-
-const pb_field_t Speed_fields[3] = {
- PB_FIELD( 1, INT32 , OPTIONAL, STATIC , FIRST, Speed, Left, Left, 0),
- PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, Speed, Right, Left, 0),
+const pb_field_t Command_fields[4] = {
+ PB_FIELD( 1, INT32 , OPTIONAL, STATIC , FIRST, Command, LeftSpeed, LeftSpeed, 0),
+ PB_FIELD( 2, INT32 , OPTIONAL, STATIC , OTHER, Command, RightSpeed, LeftSpeed, 0),
+ PB_FIELD( 3, INT32 , OPTIONAL, STATIC , OTHER, Command, TurnHead, RightSpeed, 0),
PB_LAST_FIELD
};
@@ -31,28 +26,4 @@ const pb_field_t Event_fields[5] = {
};
-/* Check that field information fits in pb_field_t */
-#if !defined(PB_FIELD_32BIT)
-/* If you get an error here, it means that you need to define PB_FIELD_32BIT
- * compile-time option. You can do that in pb.h or on compiler command line.
- *
- * The reason you need to do this is that some of your messages contain tag
- * numbers or field sizes that are larger than what can fit in 8 or 16 bit
- * field descriptors.
- */
-PB_STATIC_ASSERT((pb_membersize(Command, SetSpeed) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Command_Speed_Event)
-#endif
-
-#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)
-/* If you get an error here, it means that you need to define PB_FIELD_16BIT
- * compile-time option. You can do that in pb.h or on compiler command line.
- *
- * The reason you need to do this is that some of your messages contain tag
- * numbers or field sizes that are larger than what can fit in the default
- * 8 bit descriptors.
- */
-PB_STATIC_ASSERT((pb_membersize(Command, SetSpeed) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_Command_Speed_Event)
-#endif
-
-
/* @@protoc_insertion_point(eof) */
diff --git a/car/elegoo.pb.h b/car/elegoo.pb.h
index c162007..5ce84f4 100644
--- a/car/elegoo.pb.h
+++ b/car/elegoo.pb.h
@@ -1,5 +1,5 @@
/* Automatically generated nanopb header */
-/* Generated by nanopb-0.3.6 at Tue Jan 24 21:09:08 2017. */
+/* Generated by nanopb-0.3.6 at Sun Aug 20 16:43:10 2017. */
#ifndef PB_ELEGOO_PB_H_INCLUDED
#define PB_ELEGOO_PB_H_INCLUDED
@@ -15,6 +15,16 @@ extern "C" {
#endif
/* Struct definitions */
+typedef struct _Command {
+ bool has_LeftSpeed;
+ int32_t LeftSpeed;
+ bool has_RightSpeed;
+ int32_t RightSpeed;
+ bool has_TurnHead;
+ int32_t TurnHead;
+/* @@protoc_insertion_point(struct:Command) */
+} Command;
+
typedef struct _Event {
bool has_Distance;
int32_t Distance;
@@ -27,50 +37,29 @@ typedef struct _Event {
/* @@protoc_insertion_point(struct:Event) */
} Event;
-typedef struct _Speed {
- bool has_Left;
- int32_t Left;
- bool has_Right;
- int32_t Right;
-/* @@protoc_insertion_point(struct:Speed) */
-} Speed;
-
-typedef struct _Command {
- bool has_SetSpeed;
- Speed SetSpeed;
- bool has_Stop;
- bool Stop;
-/* @@protoc_insertion_point(struct:Command) */
-} Command;
-
/* Default values for struct fields */
/* Initializer values for message structs */
-#define Command_init_default {false, Speed_init_default, false, 0}
-#define Speed_init_default {false, 0, false, 0}
+#define Command_init_default {false, 0, false, 0, false, 0}
#define Event_init_default {false, 0, false, 0, false, 0, false, 0}
-#define Command_init_zero {false, Speed_init_zero, false, 0}
-#define Speed_init_zero {false, 0, false, 0}
+#define Command_init_zero {false, 0, false, 0, false, 0}
#define Event_init_zero {false, 0, false, 0, false, 0, false, 0}
/* Field tags (for use in manual encoding/decoding) */
+#define Command_LeftSpeed_tag 1
+#define Command_RightSpeed_tag 2
+#define Command_TurnHead_tag 3
#define Event_Distance_tag 1
#define Event_SensorA_tag 2
#define Event_SensorB_tag 3
#define Event_SensorC_tag 4
-#define Speed_Left_tag 1
-#define Speed_Right_tag 2
-#define Command_SetSpeed_tag 1
-#define Command_Stop_tag 2
/* Struct field encoding specification for nanopb */
-extern const pb_field_t Command_fields[3];
-extern const pb_field_t Speed_fields[3];
+extern const pb_field_t Command_fields[4];
extern const pb_field_t Event_fields[5];
/* Maximum encoded size of messages (where known) */
-#define Command_size 26
-#define Speed_size 22
+#define Command_size 33
#define Event_size 17
/* Message IDs (where set with "msgid" option) */
diff --git a/car/elegoo/elegoo.pb.go b/car/elegoo/elegoo.pb.go
index 5854d75..01de1cf 100644
--- a/car/elegoo/elegoo.pb.go
+++ b/car/elegoo/elegoo.pb.go
@@ -1,6 +1,5 @@
-// Code generated by protoc-gen-go.
+// Code generated by protoc-gen-go. DO NOT EDIT.
// source: elegoo.proto
-// DO NOT EDIT!
/*
Package main is a generated protocol buffer package.
@@ -10,7 +9,6 @@ It is generated from these files:
It has these top-level messages:
Command
- Speed
Event
*/
package main
@@ -31,8 +29,9 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Command struct {
- SetSpeed *Speed `protobuf:"bytes,1,opt,name=SetSpeed" json:"SetSpeed,omitempty"`
- Stop bool `protobuf:"varint,2,opt,name=Stop" json:"Stop,omitempty"`
+ LeftSpeed int32 `protobuf:"varint,1,opt,name=LeftSpeed" json:"LeftSpeed,omitempty"`
+ RightSpeed int32 `protobuf:"varint,2,opt,name=RightSpeed" json:"RightSpeed,omitempty"`
+ TurnHead int32 `protobuf:"varint,3,opt,name=TurnHead" json:"TurnHead,omitempty"`
}
func (m *Command) Reset() { *m = Command{} }
@@ -40,40 +39,23 @@ func (m *Command) String() string { return proto.CompactTextString(m)
func (*Command) ProtoMessage() {}
func (*Command) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
-func (m *Command) GetSetSpeed() *Speed {
+func (m *Command) GetLeftSpeed() int32 {
if m != nil {
- return m.SetSpeed
+ return m.LeftSpeed
}
- return nil
-}
-
-func (m *Command) GetStop() bool {
- if m != nil {
- return m.Stop
- }
- return false
-}
-
-type Speed struct {
- Left int32 `protobuf:"varint,1,opt,name=Left" json:"Left,omitempty"`
- Right int32 `protobuf:"varint,2,opt,name=Right" json:"Right,omitempty"`
+ return 0
}
-func (m *Speed) Reset() { *m = Speed{} }
-func (m *Speed) String() string { return proto.CompactTextString(m) }
-func (*Speed) ProtoMessage() {}
-func (*Speed) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
-
-func (m *Speed) GetLeft() int32 {
+func (m *Command) GetRightSpeed() int32 {
if m != nil {
- return m.Left
+ return m.RightSpeed
}
return 0
}
-func (m *Speed) GetRight() int32 {
+func (m *Command) GetTurnHead() int32 {
if m != nil {
- return m.Right
+ return m.TurnHead
}
return 0
}
@@ -88,7 +70,7 @@ type Event struct {
func (m *Event) Reset() { *m = Event{} }
func (m *Event) String() string { return proto.CompactTextString(m) }
func (*Event) ProtoMessage() {}
-func (*Event) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
+func (*Event) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *Event) GetDistance() int32 {
if m != nil {
@@ -120,24 +102,22 @@ func (m *Event) GetSensorC() bool {
func init() {
proto.RegisterType((*Command)(nil), "Command")
- proto.RegisterType((*Speed)(nil), "Speed")
proto.RegisterType((*Event)(nil), "Event")
}
func init() { proto.RegisterFile("elegoo.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
- // 186 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x8f, 0xb1, 0xce, 0x82, 0x30,
- 0x14, 0x46, 0xc3, 0xff, 0x53, 0x20, 0x57, 0xa7, 0xc6, 0xa1, 0x71, 0x22, 0x9d, 0x98, 0x48, 0xd4,
- 0x27, 0x00, 0x74, 0x73, 0x6a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xe6, 0x62, 0x77, 0xce, 0xcf, 0xcd,
+ 0x4d, 0xcc, 0x4b, 0x11, 0x92, 0xe1, 0xe2, 0xf4, 0x49, 0x4d, 0x2b, 0x09, 0x2e, 0x48, 0x4d, 0x4d,
+ 0x91, 0x60, 0x54, 0x60, 0xd4, 0x60, 0x0d, 0x42, 0x08, 0x08, 0xc9, 0x71, 0x71, 0x05, 0x65, 0xa6,
+ 0x67, 0x40, 0xa5, 0x99, 0xc0, 0xd2, 0x48, 0x22, 0x42, 0x52, 0x5c, 0x1c, 0x21, 0xa5, 0x45, 0x79,
+ 0x1e, 0xa9, 0x89, 0x29, 0x12, 0xcc, 0x60, 0x59, 0x38, 0x5f, 0xa9, 0x90, 0x8b, 0xd5, 0xb5, 0x2c,
+ 0x35, 0xaf, 0x04, 0xa4, 0xc8, 0x25, 0xb3, 0xb8, 0x24, 0x31, 0x2f, 0x39, 0x15, 0x6a, 0x03, 0x9c,
+ 0x2f, 0x24, 0xc1, 0xc5, 0x1e, 0x9c, 0x9a, 0x57, 0x9c, 0x5f, 0xe4, 0x08, 0x36, 0x9d, 0x23, 0x08,
+ 0xc6, 0x45, 0xc8, 0x38, 0x81, 0x4d, 0x86, 0xcb, 0x38, 0x21, 0x64, 0x9c, 0x25, 0x58, 0x90, 0x65,
+ 0x9c, 0x9d, 0xd8, 0xa2, 0x58, 0x72, 0x13, 0x33, 0xf3, 0x92, 0xd8, 0xc0, 0xde, 0x34, 0x06, 0x04,
+ 0x00, 0x00, 0xff, 0xff, 0xdc, 0x14, 0x3e, 0x06, 0xf6, 0x00, 0x00, 0x00,
}
diff --git a/car/elegoo.proto b/car/elegoo/elegoo.proto
index 0e56d17..703ac71 100644
--- a/car/elegoo.proto
+++ b/car/elegoo/elegoo.proto
@@ -3,13 +3,9 @@ syntax = "proto3";
option go_package = "main";
message Command {
- Speed SetSpeed = 1;
- bool Stop = 2;
-}
-
-message Speed {
- int32 Left = 1;
- int32 Right = 2;
+ int32 LeftSpeed = 1;
+ int32 RightSpeed = 2;
+ int32 TurnHead = 3;
}
message Event {
diff --git a/car/elegoo/main.go b/car/elegoo/main.go
index 4ef6799..e44fb6a 100644
--- a/car/elegoo/main.go
+++ b/car/elegoo/main.go
@@ -1,7 +1,7 @@
package main
-//go:generate sh -c "protoc -I.. --go_out=. ../*.proto"
-//go:generate sh -c "protoc -I.. --nanopb_out=.. ../*.proto"
+//go:generate sh -c "protoc --go_out=. *.proto"
+//go:generate sh -c "protoc --nanopb_out=.. *.proto"
import (
"io"
@@ -18,17 +18,11 @@ func Write(w io.Writer, buf []byte) {
}
func Read(r io.Reader) []byte {
- buf := make([]byte, 80)
- n, _ := r.Read(buf)
- sz, n := proto.DecodeVarint(buf[:n])
-
+ buf := make([]byte, 1)
+ r.Read(buf)
+ sz, _ := proto.DecodeVarint(buf)
nbuf := make([]byte, int(sz))
-
- copy(nbuf, buf[int(n):])
-
- if int(sz) > int(80-n) {
- io.ReadFull(r, nbuf[int(80-n):])
- }
+ io.ReadFull(r, nbuf)
return nbuf
}