添加tcp5s心跳

This commit is contained in:
fish 2019-03-21 11:36:09 +08:00
parent 419d1a21a5
commit b10aace99b
3 changed files with 6 additions and 3 deletions

View File

@ -13,9 +13,9 @@ func main() {
go gw_router() go gw_router()
go serial_run() go serial_run()
c := cron.New() c := cron.New()
// send_data(1001) send_data(1001)
c.AddFunc("0, *, *, *, *, *", func() { c.AddFunc("0, *, *, *, *, *", func() {
// send_data(1001) send_data(1001)
}) })
// devices := []Device{} // devices := []Device{}
c.AddFunc("*/10, *, *, *, *, *", func(){ c.AddFunc("*/10, *, *, *, *, *", func(){

View File

@ -33,12 +33,14 @@ func handleConn(conn net.Conn) {
go yunhorn_ys_l_v1(readStr) go yunhorn_ys_l_v1(readStr)
case stop := <-stopChan: case stop := <-stopChan:
if stop { if stop {
log.Println("stop channel")
break break
} }
case <-time.After(5000 * time.Millisecond): case <-time.After(5000 * time.Millisecond):
n,err := conn.Write(heartbeat) n,err := conn.Write(heartbeat)
if err != nil{ if err != nil{
log.Println("write msg error!",err) log.Println("write msg error!",err)
stopChan <- true
}else{ }else{
log.Println("write msg success!",n) log.Println("write msg success!",n)
} }

View File

@ -34,6 +34,7 @@ func yunhorn_ys_l_v1(data_buf []byte){
// log.Println(binary.BigEndian.Uint16(append([]byte{0x00}, k)) // log.Println(binary.BigEndian.Uint16(append([]byte{0x00}, k))
// } // }
log.Println("ys_l_v1_data:",data_buf)
data_int := Bytes2Bits(data_buf[3:4]) data_int := Bytes2Bits(data_buf[3:4])
log.Println("data_int:",data_int[0]) log.Println("data_int:",data_int[0])
@ -53,7 +54,7 @@ func yunhorn_ys_l_v1(data_buf []byte){
if conf.DEBUG { if conf.DEBUG {
log.Println(device) log.Println(device)
} }
// send_data(1005, device) send_data(1005, device)
} }