main.go 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "encoding/hex"
  4. "flag"
  5. "fmt"
  6. "os"
  7. "prod2u6400-uartkit/internal/protocol"
  8. )
  9. func main() {
  10. mode := flag.String("mode", "set-all", "set-all, get-snapshot, or i2c-set-all")
  11. preset := flag.String("preset", "channel4", "channel4 or safe")
  12. flag.Parse()
  13. s := protocol.SetAll{}
  14. for i := range s.Front {
  15. s.Front[i] = 20
  16. }
  17. for i := range s.Rear {
  18. s.Rear[i] = 20
  19. }
  20. if *preset == "channel4" {
  21. for i := 18; i < 24; i++ {
  22. s.PTC[i] = 100
  23. }
  24. s.Front[3], s.Rear[3] = 30, 10
  25. } else if *preset != "safe" {
  26. fmt.Fprintln(os.Stderr, "unknown preset")
  27. os.Exit(2)
  28. }
  29. if *mode == "set-all" {
  30. b, _ := protocol.EncodeSetAll(s)
  31. fmt.Println(hex.EncodeToString(b))
  32. return
  33. }
  34. if *mode == "get-snapshot" {
  35. fmt.Println(hex.EncodeToString(protocol.EncodeGetSnapshot()))
  36. return
  37. }
  38. if *mode == "i2c-set-all" {
  39. p, _ := s.Payload()
  40. fmt.Printf("addr=0x%02X staging=0100%s command=001001\n", 0x2A, hex.EncodeToString(p))
  41. return
  42. }
  43. fmt.Fprintln(os.Stderr, "unknown mode")
  44. os.Exit(2)
  45. }