-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (46 loc) · 975 Bytes
/
main.go
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
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"net"
)
func createMsg(cmd []byte, payload []byte) []byte {
hdr := []byte("\xff\xff")
size := []byte{byte(3 + len(payload))}
msg := hdr
msg = append(msg, cmd...)
msg = append(msg, size...)
msg = append(msg, payload...)
cs := CalcChecksum(msg[len(hdr):])
msg = append(msg, cs)
return msg
}
func sendMsg(msg []byte, ip string, port string) ([]byte, error) {
conn, _ := net.Dial("tcp", ip+":"+port)
defer conn.Close()
_, err := conn.Write(msg)
if err != nil {
return nil, err
}
buf := make([]byte, 1024)
_, err = conn.Read(buf)
return buf, err
}
func getWxData(cmd []byte) {
msg := createMsg(cmd, nil)
ip := "192.168.4.77"
port := "45000"
response, err := sendMsg(msg, ip, port)
if err != nil {
fmt.Println(err)
}
results, err := ParseResponse(response)
if err != nil {
fmt.Println(err)
}
results.Display()
}
func main() {
// w := WeatherDB{}
getWxData([]byte("\x27"))
getWxData([]byte("\x57"))
}