Commit 11355aec authored by barnettZQG's avatar barnettZQG

add command send

parent f29a49e8
......@@ -65,6 +65,23 @@ func responseMessage(input []byte) []byte {
return response
}
var num int64 = 200
func createCommandMessage() []byte {
response := Hextob("F1B5FF000000")
num += num
num16 := strconv.FormatInt(num, 16)
if len(num16) < 4 {
for len(num16)-4 < 0 {
num16 = "0" + num16
}
}
response = append(response, Hextob(num16)...)
response = append(response, Hextob(createTime())...)
response = append(response, Hextob("FFFFFF804B9888D3")...)
return response
}
func Hextob(str string) []byte {
slen := len(str)
bHex := make([]byte, len(str)/2)
......
package main
import "testing"
import (
"strconv"
"testing"
)
func TestCreateTime(t *testing.T) {
t.Log(createTime())
......@@ -12,3 +15,9 @@ func TestCRC32(t *testing.T) {
func TestResponseMessage(t *testing.T) {
t.Log(BytetoH(responseMessage(Hextob("F1B000000006000199014C000219100000ED8862120362D81046"))))
}
func TestCreateCommandMessage(t *testing.T) {
t.Log(strconv.FormatInt(201, 16))
t.Log(BytetoH(createCommandMessage()))
}
......@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"os"
"time"
"github.com/sirupsen/logrus"
)
......@@ -35,6 +36,7 @@ func udpProcess(conn *net.UDPConn, index int) {
if len(response) > 0 {
fmt.Printf("response %s: %X\n", requestType, response)
conn.WriteToUDP(response, rAddr)
go sendCommand(conn, rAddr)
}
<-limitChan
}
......@@ -56,8 +58,17 @@ func udpServer(address string) {
}
}
func parseMessage(data []byte) {
func sendCommand(conn *net.UDPConn, addr *net.UDPAddr) {
timer := time.NewTimer(time.Second * 30)
for {
select {
case <-timer.C:
}
command := createCommandMessage()
conn.WriteToUDP(command, addr)
fmt.Printf("send command %X\n", command)
timer.Reset(time.Second * 30)
}
}
func main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment