aboutsummaryrefslogtreecommitdiff
path: root/car/elegoo
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-08-20 15:27:52 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-08-20 15:27:52 +0200
commit615215d3137d6bd753cbd855928a4dbea105fd05 (patch)
treeeca194596e79592ff48bacebbd0b89ceb4460cbc /car/elegoo
parent0f3a959b2f0bb78b12e404230d4a7a3db79e03e4 (diff)
stream
Diffstat (limited to 'car/elegoo')
-rw-r--r--car/elegoo/main.go15
1 files changed, 7 insertions, 8 deletions
diff --git a/car/elegoo/main.go b/car/elegoo/main.go
index 6f1d945..a17ac2a 100644
--- a/car/elegoo/main.go
+++ b/car/elegoo/main.go
@@ -11,14 +11,13 @@ import (
func Write(w io.Writer, buf []byte) {
sz := proto.EncodeVarint(uint64(len(buf)))
- w.Write(sz)
- w.Write(buf)
+ w.Write(append(sz, buf...))
}
func Read(r io.Reader) []byte {
- buf := [10]byte{}
- r.Read(buf[:])
- sz, n := proto.DecodeVarint(buf[:])
+ buf := make([]byte, 80)
+ n, _ := r.Read(buf)
+ sz, n := proto.DecodeVarint(buf[:n])
nbuf := make([]byte, int(sz))
@@ -58,13 +57,13 @@ func main() {
if err != nil {
log.Fatal(err)
}
- log.Printf("Send: %v", buf)
- Write(s, buf)
+ log.Printf("Send: %x", buf)
+ //Write(s, buf)
go func() {
for {
buf := Read(s)
- log.Printf("Got: %v", buf)
+ log.Printf("Got: %x", buf)
evt := &Event{}
proto.Unmarshal(buf, evt)
log.Println(evt)