diff options
| author | Kevin Wallace <kevin@pentabarf.net> | 2026-03-05 20:17:40 -0800 |
|---|---|---|
| committer | Kevin Wallace <kevin@pentabarf.net> | 2026-03-05 20:17:40 -0800 |
| commit | 5330acd5616184b91bd89cff56c63a5a4342de29 (patch) | |
| tree | 6e56518a8d3c0af43fa9e230c5e657ec48681178 | |
| parent | add ISOCardReleased (diff) | |
make protocol trace logging optional, default off
| -rw-r--r-- | cmd/cvend-ipp/main.go | 2 | ||||
| -rw-r--r-- | cmd/pic32-ipp/main.go | 2 | ||||
| -rw-r--r-- | ipp/ipp.go | 19 |
3 files changed, 19 insertions, 4 deletions
diff --git a/cmd/cvend-ipp/main.go b/cmd/cvend-ipp/main.go index ce96732..a985dc6 100644 --- a/cmd/cvend-ipp/main.go +++ b/cmd/cvend-ipp/main.go @@ -8,6 +8,7 @@ import ( "time" "pm3.dev/cvend" + "pm3.dev/ipp" ) var wait = flag.Duration("w", 5*time.Second, "how long to wait for a response") @@ -15,6 +16,7 @@ var follow = flag.Bool("f", false, "don't exit after response") func main() { flag.Parse() + *ipp.Trace = true log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime | log.Lmicroseconds) log.Println("cvend-ipp start") wc := make(chan struct{}, 1) diff --git a/cmd/pic32-ipp/main.go b/cmd/pic32-ipp/main.go index 34a1ec8..c6d3d98 100644 --- a/cmd/pic32-ipp/main.go +++ b/cmd/pic32-ipp/main.go @@ -7,6 +7,7 @@ import ( "strconv" "time" + "pm3.dev/ipp" "pm3.dev/pic32" ) @@ -15,6 +16,7 @@ var follow = flag.Bool("f", false, "don't exit after response") func main() { flag.Parse() + *ipp.Trace = true log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime | log.Lmicroseconds) log.Println("pic32-ipp start") wc := make(chan struct{}, 1) @@ -3,6 +3,7 @@ package ipp import ( "encoding/binary" "encoding/hex" + "flag" "hash/crc32" "io" "log" @@ -11,6 +12,8 @@ import ( "golang.org/x/sys/unix" ) +var Trace = flag.Bool("ipp-trace", false, "log IPP protocol traces") + var crc8table = [256]byte{ 0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc, @@ -107,7 +110,9 @@ func (s *session) handleMsg(bs []byte) (nRead int) { } msgType := bs[0] if msgType != 0xbc { - log.Printf("skipping non-IPP message %s", hex.EncodeToString(bs)) + if *Trace { + log.Printf("skipping non-IPP message %s", hex.EncodeToString(bs)) + } nRead = len(bs) return } @@ -148,7 +153,9 @@ func (s *session) handleMsg(bs []byte) (nRead int) { if ippLen > 0 { ellipsis = "..." } - log.Printf("%s < %s%s%s", s.path, hex.EncodeToString(bs[:7]), ellipsis, hex.EncodeToString(bs[7+ippLen:expectedLen])) + if *Trace { + log.Printf("%s < %s%s%s", s.path, hex.EncodeToString(bs[:7]), ellipsis, hex.EncodeToString(bs[7+ippLen:expectedLen])) + } if s.handler != nil { s.handler(ippType, ippData) } @@ -163,7 +170,9 @@ func (s *session) Close() error { } func (s *session) Write(bs []byte) (int, error) { - log.Printf("%s > %s", s.path, hex.EncodeToString(bs)) + if *Trace { + log.Printf("%s > %s", s.path, hex.EncodeToString(bs)) + } return unix.Write(s.fd, bs) } @@ -183,7 +192,9 @@ func (s *session) SendIPP(ippType byte, ippData []byte) error { msgCRC = make([]byte, 4) binary.LittleEndian.PutUint32(msgCRC, ^crc32.ChecksumIEEE(ippData)) } - log.Printf("%s > %s%s%s", s.path, hex.EncodeToString(ippHdr), hex.EncodeToString(ippData), hex.EncodeToString(msgCRC)) + if *Trace { + log.Printf("%s > %s%s%s", s.path, hex.EncodeToString(ippHdr), hex.EncodeToString(ippData), hex.EncodeToString(msgCRC)) + } if _, err := unix.Writev(s.fd, [][]byte{ippHdr, ippData, msgCRC}); err != nil { return err } |