This commit is contained in:
suguo.yao 2023-10-27 20:42:57 +08:00
parent d9b33b0e0b
commit 0577845838
2 changed files with 17 additions and 16 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module myschools.me/suguo/device-k9l
go 1.21.1

30
main.go
View File

@ -73,7 +73,7 @@ func processClient(conn net.Conn) {
for {
reader := bufio.NewReader(conn)
var buf [128]byte
var buf [1024]byte
n, err := reader.Read(buf[:])
if err != nil {
fmt.Println("read from client failed, err: ", err)
@ -102,6 +102,7 @@ func messageWrite() {
fmt.Printf("%s[%s] reply write[%d]: %s\n", msg.DeviceID, msg.Conn.RemoteAddr(), n, msg.Payload)
}
case msg := <-platfromChan:
// fmt.Println(msg.pack())
n, err := msg.Conn.Write([]byte(msg.pack()))
if err != nil {
fmt.Printf("%s[%s] platfrom write[%d]: %v\n", msg.DeviceID, msg.Conn.RemoteAddr(), n, err)
@ -125,6 +126,8 @@ func processContent(c *client) bool {
c.Payload = "LK"
reply = true
case "TKQ":
c.Payload = "TKQ"
reply = true
case "VERNO":
c.ver = content[1]
case "MESSAGE":
@ -156,6 +159,16 @@ func processPlatfrom() {
continue
}
//计步通不过
if !c.step {
platfromChan <- &client{
Conn: c.Conn,
DeviceID: c.DeviceID,
Payload: "WALKTIME,00:00-23:59",
}
continue
}
//定位
if c.cr == "" {
platfromChan <- &client{
@ -194,21 +207,6 @@ func processPlatfrom() {
}
continue
}
//计步通不过
if !c.step {
platfromChan <- &client{
Conn: c.Conn,
DeviceID: c.DeviceID,
Payload: "PEDO,1",
}
platfromChan <- &client{
Conn: c.Conn,
DeviceID: c.DeviceID,
Payload: "WALKTIME,00:00-23:59",
}
continue
}
}
time.Sleep(5 * time.Second)
}