Skip to content

Commit

Permalink
1 sec read timeout & 0x60 for c & s
Browse files Browse the repository at this point in the history
  • Loading branch information
rokath committed Feb 21, 2020
1 parent d4ba5a5 commit 4ce7275
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions pkg/com/readPacket.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2020 Thomas.Hoehenleitner [at] seerose.net
// All rights reserved.
// Use of this source code is governed by a
// license that can be found in the LICENSE file.
// Use of this source code is governed by a license that can be found in the LICENSE file.

package com

Expand All @@ -13,23 +11,38 @@ import (
"github.com/tarm/serial"
)

func readHeader(s *serial.Port) []byte {
b := readAtLeastBytes(s, 8)
for b[1] != 0x60 || // only one receiver now
b[2] != 0x60 || // only one transmitter now
var locAddr = byte(0x60) // local address
var remAddr = byte(0x60) // remote address
var toMs = 1000

func readHeader(s *serial.Port) ([]byte, error) {
b, err := readAtLeastBytes(s, 8, toMs)
if nil != err {
return b, err
}
for b[1] != remAddr ||
b[2] != locAddr ||
b[0]^b[1]^b[2]^b[4]^b[5]^b[6]^b[7] != b[3] { // crc8 check
fmt.Println("discarding", b[0])
b = append(b[1:], readAtLeastBytes(s, 1)...) // try to sync
x, err := readAtLeastBytes(s, 1, toMs)
if nil != err {
return b, err
}
b = append(b[1:], x...) // try to sync
}
//fmt.Print(b)
return b
return b, nil
}

// ReadEndless expects a pointer to a filled COM port configuration
func ReadEndless(s *serial.Port, l id.List, color string) {
for {
b := readHeader(s)
if 0xeb == b[0] { // trice startbyte, no further data
b, err := readHeader(s)
if nil != err {
fmt.Println(err)
continue
}
if 0xeb == b[0] { // traceLog startbyte, no further data
err := emit.Trace(b, l, color)
if nil != err {
fmt.Println("trace.Log error", err, b)
Expand Down

0 comments on commit 4ce7275

Please sign in to comment.