1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
package pactor
import (
"log"
"os"
"strconv"
"sync"
)
// SerialTimeout: Timeout for read operations on serial bus
// PactorChannel: Pactor channel, 31 should work for both, PTC-IIex and P4 Dragon
// MaxSendData: Pactor internal command buffer is 256 byte
// MaxFrameNotTX: Max. number of frames not transmitted at time.
const (
SerialTimeout = 1
PactorChannel = 31
MaxSendData = 256
MaxFrameNotTX = 2
)
// Pactor states
const (
Unknown State = iota
LinkSetup
Connected
DisconnectReq
Disconnected
)
type State uint8
var debugMux sync.Mutex
func debugEnabled() int {
if value, ok := os.LookupEnv("PACTOR_DEBUG"); ok {
level, err := strconv.Atoi(value)
if err == nil {
return level
}
}
return 0
}
func writeDebug(message string, level int) {
debugMux.Lock()
defer debugMux.Unlock()
if debugEnabled() >= level {
log.Println(message)
}
return
}
|