From 4f954f2daed0cb4f9c522002221a706e01c3e31e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 13 Dec 2017 00:33:03 +0100 Subject: split --- cmd/elegooctl/main.go | 24 ++++++++++++++++++++++++ elegoo.go | 28 ++++++++++++++++++++++++++++ elegoo.pb.go | 46 +++++++++++++++++++++++----------------------- elegoo.proto | 2 +- elegoo/elegoo.pb.c | 2 +- elegoo/elegoo.pb.h | 2 +- fsm.go | 2 +- main.go | 46 ---------------------------------------------- 8 files changed, 79 insertions(+), 73 deletions(-) create mode 100644 cmd/elegooctl/main.go create mode 100644 elegoo.go delete mode 100644 main.go diff --git a/cmd/elegooctl/main.go b/cmd/elegooctl/main.go new file mode 100644 index 0000000..ff0c581 --- /dev/null +++ b/cmd/elegooctl/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "dim13.org/elegoo" + "github.com/tarm/serial" +) + +func main() { + conf := &serial.Config{ + //Name: "/dev/tty.usbmodem1421", + //Name: "/dev/tty.usbmodem1411", + Name: "/dev/tty.Elegoo-DevB", + Baud: 57600, + } + s, err := serial.OpenPort(conf) + if err != nil { + log.Fatal(err) + } + defer s.Close() + + elegoo.NewFSM(s).Start() +} diff --git a/elegoo.go b/elegoo.go new file mode 100644 index 0000000..a7ed182 --- /dev/null +++ b/elegoo.go @@ -0,0 +1,28 @@ +package elegoo + +import ( + "bufio" + "io" + + "github.com/dim13/cobs" + proto "github.com/golang/protobuf/proto" +) + +//go:generate sh -c "protoc --go_out=. --nanopb_out=elegoo/ *.proto" + +func Send(w io.Writer, pb proto.Message) error { + buf := new(proto.Buffer) + if err := buf.EncodeMessage(pb); err != nil { + return err + } + _, err := w.Write(cobs.Encode(buf.Bytes())) + return err +} + +func Recv(buf *bufio.Reader, pb proto.Message) error { + block, err := buf.ReadBytes(0) + if err != nil { + return err + } + return proto.NewBuffer(cobs.Decode(block)).DecodeMessage(pb) +} diff --git a/elegoo.pb.go b/elegoo.pb.go index 847e356..3107e01 100644 --- a/elegoo.pb.go +++ b/elegoo.pb.go @@ -2,7 +2,7 @@ // source: elegoo.proto /* -Package main is a generated protocol buffer package. +Package elegoo is a generated protocol buffer package. It is generated from these files: elegoo.proto @@ -15,7 +15,7 @@ It has these top-level messages: RemoteControl Event */ -package main +package elegoo import proto "github.com/golang/protobuf/proto" import fmt "fmt" @@ -212,25 +212,25 @@ func init() { func init() { proto.RegisterFile("elegoo.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 315 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x51, 0x5d, 0x4b, 0xc3, 0x30, - 0x14, 0x25, 0xae, 0xab, 0xf5, 0x6e, 0x85, 0x19, 0x10, 0x8a, 0xf8, 0x30, 0x2b, 0xc8, 0x5e, 0xdc, - 0xc3, 0xf4, 0x0f, 0x6c, 0x9d, 0xa2, 0xd8, 0xa7, 0x5b, 0x7d, 0xf1, 0x2d, 0x6e, 0x77, 0x52, 0x5c, - 0x73, 0x4b, 0x17, 0x04, 0xff, 0x90, 0xbf, 0x53, 0x9a, 0xa4, 0x16, 0xdf, 0x72, 0x4e, 0x4e, 0xcf, - 0x47, 0x0a, 0x63, 0xda, 0xd3, 0x07, 0xf3, 0xbc, 0x6e, 0xd8, 0xb0, 0x0c, 0x1d, 0x4a, 0x97, 0x30, - 0x2c, 0x6a, 0xa2, 0xad, 0x1c, 0x83, 0xc8, 0x13, 0x31, 0x15, 0xb3, 0x53, 0x14, 0x79, 0x8b, 0x30, - 0x39, 0x72, 0x08, 0xe5, 0x05, 0x9c, 0x14, 0x86, 0xeb, 0xe5, 0xce, 0x50, 0x93, 0x0c, 0xa6, 0x62, - 0x16, 0x63, 0x4f, 0xa4, 0x2b, 0x38, 0xce, 0xb8, 0xaa, 0x94, 0xde, 0xca, 0x2b, 0xef, 0x66, 0x8d, - 0x46, 0x8b, 0x78, 0xee, 0x33, 0x2d, 0x89, 0x3e, 0x49, 0x42, 0x90, 0x33, 0x7f, 0x7a, 0x7b, 0x7b, - 0x4e, 0x1f, 0x00, 0x5e, 0xf7, 0xa6, 0x51, 0x05, 0xeb, 0x72, 0x23, 0xcf, 0x21, 0x5a, 0x97, 0x07, - 0xa3, 0xf4, 0x86, 0xac, 0x53, 0x8c, 0x7f, 0xb8, 0xed, 0xb2, 0x2e, 0x1b, 0xda, 0x98, 0x92, 0xb5, - 0xb7, 0xe8, 0x89, 0xf4, 0x0e, 0xa2, 0x27, 0xbd, 0x6b, 0x14, 0xba, 0x45, 0x68, 0x3f, 0x8f, 0xda, - 0x0d, 0x63, 0x10, 0x99, 0xd5, 0x47, 0x28, 0x32, 0xb7, 0x76, 0xe0, 0x50, 0x9e, 0x5e, 0x42, 0x8c, - 0x54, 0xb1, 0xa1, 0x8c, 0xb5, 0x69, 0x78, 0x2f, 0x27, 0x30, 0x78, 0xa6, 0x6f, 0x9f, 0xdd, 0x1e, - 0xd3, 0x1f, 0x01, 0xc3, 0xfb, 0x2f, 0xd2, 0xa6, 0x2d, 0xf0, 0x52, 0x56, 0x54, 0x18, 0x55, 0xd5, - 0x5e, 0xd1, 0x13, 0xf2, 0x1a, 0x82, 0x47, 0x52, 0x5b, 0x9b, 0x34, 0x5a, 0xc8, 0xee, 0x01, 0xfa, - 0x71, 0x68, 0xef, 0xe5, 0x0c, 0xc2, 0x82, 0xf4, 0x81, 0xdd, 0x7b, 0x8e, 0x16, 0x93, 0x4e, 0xd9, - 0xd5, 0x47, 0x7f, 0x2f, 0x6f, 0x20, 0x74, 0xe5, 0x92, 0xc0, 0x2a, 0xcf, 0x3a, 0xe5, 0xbf, 0xca, - 0xe8, 0x45, 0xab, 0xf0, 0x2d, 0xa8, 0x54, 0xa9, 0xdf, 0x43, 0xfb, 0x9f, 0x6f, 0x7f, 0x03, 0x00, - 0x00, 0xff, 0xff, 0xc8, 0x54, 0x2f, 0x04, 0xf7, 0x01, 0x00, 0x00, + // 314 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x51, 0xcd, 0x4a, 0xc3, 0x40, + 0x10, 0x66, 0x6d, 0x1b, 0xe3, 0xb4, 0x81, 0xba, 0x20, 0x04, 0xf1, 0x50, 0x23, 0x48, 0x2f, 0xf6, + 0x50, 0x7d, 0x81, 0x36, 0x55, 0x14, 0x73, 0x9a, 0xe8, 0xc5, 0x5b, 0x6c, 0xa7, 0x12, 0x4c, 0x76, + 0xc2, 0x76, 0x11, 0x7c, 0x21, 0x9f, 0x53, 0xb2, 0xbb, 0x31, 0x78, 0xdb, 0x6f, 0xf6, 0xdb, 0xef, + 0x67, 0x07, 0x26, 0x54, 0xd1, 0x07, 0xf3, 0xa2, 0xd1, 0x6c, 0x58, 0x06, 0x0e, 0x25, 0x2b, 0x18, + 0xe5, 0x0d, 0xd1, 0x4e, 0x4e, 0x40, 0x64, 0xb1, 0x98, 0x89, 0xf9, 0x29, 0x8a, 0xac, 0x45, 0x18, + 0x1f, 0x39, 0x84, 0xf2, 0x02, 0x4e, 0x72, 0xc3, 0xcd, 0x6a, 0x6f, 0x48, 0xc7, 0x83, 0x99, 0x98, + 0x47, 0xd8, 0x0f, 0x92, 0x35, 0x1c, 0xa7, 0x5c, 0xd7, 0x85, 0xda, 0xc9, 0x2b, 0xaf, 0x66, 0x85, + 0xc6, 0xcb, 0x68, 0xe1, 0x3d, 0xed, 0x10, 0xbd, 0x93, 0x84, 0x61, 0xc6, 0xfc, 0xe9, 0xe5, 0xed, + 0x39, 0x79, 0x00, 0x78, 0xad, 0x8c, 0x2e, 0x72, 0x56, 0xe5, 0x56, 0x9e, 0x43, 0xb8, 0x29, 0x0f, + 0xa6, 0x50, 0x5b, 0xb2, 0x4a, 0x11, 0xfe, 0xe1, 0x36, 0xcb, 0xa6, 0xd4, 0xb4, 0x35, 0x25, 0x2b, + 0x2f, 0xd1, 0x0f, 0x92, 0x3b, 0x08, 0x9f, 0xd4, 0x5e, 0x17, 0xe8, 0x1a, 0xa1, 0x7d, 0x1e, 0xb6, + 0x1d, 0x26, 0x20, 0x52, 0xcb, 0x0f, 0x51, 0xa4, 0xae, 0xed, 0xc0, 0xa1, 0x2c, 0xb9, 0x84, 0x08, + 0xa9, 0x66, 0x43, 0x29, 0x2b, 0xa3, 0xb9, 0x92, 0x53, 0x18, 0x3c, 0xd3, 0xb7, 0xf7, 0x6e, 0x8f, + 0xc9, 0x8f, 0x80, 0xd1, 0xfd, 0x17, 0x29, 0xd3, 0x06, 0x78, 0x29, 0x6b, 0xca, 0x4d, 0x51, 0x37, + 0x9e, 0xd1, 0x0f, 0xe4, 0x35, 0x0c, 0x1f, 0xa9, 0xd8, 0x59, 0xa7, 0xf1, 0x52, 0x76, 0x1f, 0xd0, + 0x97, 0x43, 0x7b, 0x2f, 0xe7, 0x10, 0xe4, 0xa4, 0x0e, 0xec, 0xfe, 0x73, 0xbc, 0x9c, 0x76, 0xcc, + 0x2e, 0x3e, 0xfa, 0x7b, 0x79, 0x03, 0x81, 0x0b, 0x17, 0x0f, 0x2d, 0xf3, 0xac, 0x63, 0xfe, 0x8b, + 0x8c, 0x9e, 0xb4, 0x0e, 0xdf, 0xfc, 0x6a, 0xdf, 0x03, 0xbb, 0xe9, 0xdb, 0xdf, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xc4, 0x2c, 0x4b, 0xbb, 0xf9, 0x01, 0x00, 0x00, } diff --git a/elegoo.proto b/elegoo.proto index 9049893..516ecbb 100644 --- a/elegoo.proto +++ b/elegoo.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package elegoo; -option go_package = "main"; +option go_package = "elegoo"; message Speed { sint32 L = 1; // -255 .. + 255 diff --git a/elegoo/elegoo.pb.c b/elegoo/elegoo.pb.c index 5d9bceb..f6e5c20 100644 --- a/elegoo/elegoo.pb.c +++ b/elegoo/elegoo.pb.c @@ -1,5 +1,5 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.3.9 at Mon Dec 11 23:03:25 2017. */ +/* Generated by nanopb-0.3.9 at Wed Dec 13 00:31:29 2017. */ #include "elegoo.pb.h" diff --git a/elegoo/elegoo.pb.h b/elegoo/elegoo.pb.h index baff818..e0a158b 100644 --- a/elegoo/elegoo.pb.h +++ b/elegoo/elegoo.pb.h @@ -1,5 +1,5 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.3.9 at Mon Dec 11 23:03:25 2017. */ +/* Generated by nanopb-0.3.9 at Wed Dec 13 00:31:29 2017. */ #ifndef PB_ELEGOO_ELEGOO_PB_H_INCLUDED #define PB_ELEGOO_ELEGOO_PB_H_INCLUDED diff --git a/fsm.go b/fsm.go index 9565d5b..a2ec938 100644 --- a/fsm.go +++ b/fsm.go @@ -1,4 +1,4 @@ -package main +package elegoo import ( "bufio" diff --git a/main.go b/main.go deleted file mode 100644 index 166b336..0000000 --- a/main.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -//go:generate sh -c "protoc --go_out=. --nanopb_out=elegoo/ *.proto" - -import ( - "bufio" - "io" - "log" - - "github.com/dim13/cobs" - "github.com/golang/protobuf/proto" - "github.com/tarm/serial" -) - -func Send(w io.Writer, pb proto.Message) error { - buf := new(proto.Buffer) - if err := buf.EncodeMessage(pb); err != nil { - return err - } - _, err := w.Write(cobs.Encode(buf.Bytes())) - return err -} - -func Recv(buf *bufio.Reader, pb proto.Message) error { - block, err := buf.ReadBytes(0) - if err != nil { - return err - } - return proto.NewBuffer(cobs.Decode(block)).DecodeMessage(pb) -} - -func main() { - conf := &serial.Config{ - //Name: "/dev/tty.usbmodem1421", - //Name: "/dev/tty.usbmodem1411", - Name: "/dev/tty.Elegoo-DevB", - Baud: 57600, - } - s, err := serial.OpenPort(conf) - if err != nil { - log.Fatal(err) - } - defer s.Close() - - NewFSM(s).Start() -} -- cgit v1.2.3