2022-07-09 09:08:46 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2022-07-10 08:47:12 +00:00
|
|
|
"git.netflux.io/rob/goodwe-go/command"
|
2022-07-09 09:08:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var ipAddr string
|
|
|
|
flag.StringVar(&ipAddr, "ipaddr", "", "IP address/port")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if ipAddr == "" {
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("ipAddr", ipAddr)
|
|
|
|
|
|
|
|
conn, err := net.Dial("udp", ipAddr)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error dialing: %s", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
2022-07-10 08:47:12 +00:00
|
|
|
infoCmd, err := command.NewAA55("010200", "0182")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error building command: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := command.Send(infoCmd, conn)
|
2022-07-09 09:08:46 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error sending command: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
modelName := strings.TrimSpace(string(resp[12:22]))
|
|
|
|
serialNum := string(resp[38:54])
|
|
|
|
|
|
|
|
log.Printf("modelName = %q, serialNum = %q\n", modelName, serialNum)
|
|
|
|
|
2022-07-10 08:47:12 +00:00
|
|
|
dataCmd := command.NewModbus(command.ModbusCommandTypeRead, 0x891c, 0x007d)
|
|
|
|
resp, err = command.Send(dataCmd, conn)
|
2022-07-09 09:08:46 +00:00
|
|
|
if err != nil {
|
2022-07-10 08:47:12 +00:00
|
|
|
log.Fatalf("error sending command: %s", err)
|
2022-07-09 09:08:46 +00:00
|
|
|
}
|
|
|
|
|
2022-07-10 08:47:12 +00:00
|
|
|
log.Printf("rcvd modbus resp = %X", resp)
|
2022-07-09 09:08:46 +00:00
|
|
|
}
|