summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorKevin Wallace <kevin@pentabarf.net>2026-02-27 00:44:08 -0800
committerKevin Wallace <kevin@pentabarf.net>2026-02-27 00:56:16 -0800
commit5840192fecbd9f1398e46f03f30729f70e37224a (patch)
treedf3989089035c78004a2033536bfbb91a3ca0566 /cmd
initial commit
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ipp/main.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/cmd/ipp/main.go b/cmd/ipp/main.go
new file mode 100644
index 0000000..85207a8
--- /dev/null
+++ b/cmd/ipp/main.go
@@ -0,0 +1,62 @@
+package main
+
+import (
+ "encoding/hex"
+ "flag"
+ "log"
+ "strconv"
+ "time"
+
+ "pm3.dev/cvend"
+)
+
+var wait = flag.Duration("w", 5*time.Second, "how long to wait for a response")
+var follow = flag.Bool("f", false, "don't exit after response")
+
+func main() {
+ flag.Parse()
+ log.SetFlags(log.Lshortfile)
+ wc := make(chan struct{}, 1)
+ cv, err := cvend.Open(cvend.Path, func(msgType byte, msgData []byte) {
+ log.Printf("ipp %02x\n%s", msgType, hex.Dump(msgData))
+ select {
+ case wc <- struct{}{}:
+ default:
+ }
+ })
+ if err != nil {
+ panic(err)
+ }
+ defer cv.Close()
+ if flag.NArg() == 0 {
+ select {}
+ }
+ for i := 0; i < flag.NArg(); i += 2 {
+ var msgType byte
+ var msgData []byte
+ if n, err := strconv.ParseUint(flag.Arg(i), 0, 8); err != nil {
+ panic(err)
+ } else {
+ msgType = byte(n)
+ }
+ if flag.NArg() >= i {
+ if bs, err := hex.DecodeString(flag.Arg(i + 1)); err != nil {
+ panic(err)
+ } else {
+ msgData = bs
+ }
+ }
+ if err := cv.SendIPP(msgType, msgData); err != nil {
+ panic(err)
+ }
+ if *wait > 0 {
+ select {
+ case <-wc:
+ case <-time.After(*wait):
+ }
+ }
+ }
+ if *follow {
+ select {}
+ }
+}