From b10aace99bf8237981bbf29c3e2e32377e7ebb16 Mon Sep 17 00:00:00 2001
From: fish <gcslyp@gmail.com>
Date: Thu, 21 Mar 2019 11:36:09 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0tcp5s=E5=BF=83=E8=B7=B3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 main.go      | 4 ++--
 tcpserver.go | 2 ++
 worker.go    | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/main.go b/main.go
index c912c26..e972dd5 100644
--- a/main.go
+++ b/main.go
@@ -13,9 +13,9 @@ func main() {
 	go gw_router()
 	go serial_run()
 	c := cron.New()
-	// send_data(1001)
+	 send_data(1001)
 	c.AddFunc("0, *, *, *, *, *", func() {
-		// send_data(1001)
+		 send_data(1001)
 	})
 	// devices := []Device{}
 	c.AddFunc("*/10, *, *, *, *, *", func(){
diff --git a/tcpserver.go b/tcpserver.go
index c30284f..f45b0c2 100644
--- a/tcpserver.go
+++ b/tcpserver.go
@@ -33,12 +33,14 @@ func handleConn(conn net.Conn) {
 			go yunhorn_ys_l_v1(readStr)
 		case stop := <-stopChan:
 			if stop {
+				log.Println("stop channel")
 				break
 			}
 		case <-time.After(5000 * time.Millisecond):
 			n,err := conn.Write(heartbeat)
 			if err != nil{
 				log.Println("write msg error!",err)
+				stopChan <- true
 			}else{
 				log.Println("write msg success!",n)
 			}
diff --git a/worker.go b/worker.go
index 4f96f2f..512683e 100644
--- a/worker.go
+++ b/worker.go
@@ -34,6 +34,7 @@ func yunhorn_ys_l_v1(data_buf []byte){
       // log.Println(binary.BigEndian.Uint16(append([]byte{0x00}, k))
   // }
 
+  log.Println("ys_l_v1_data:",data_buf)
   data_int := Bytes2Bits(data_buf[3:4])
 
   log.Println("data_int:",data_int[0])
@@ -53,7 +54,7 @@ func yunhorn_ys_l_v1(data_buf []byte){
 	if conf.DEBUG {
       log.Println(device)
   }
-   // send_data(1005, device)
+    send_data(1005, device)
 
 }