From a0c041c122294084edeb9eb67574dafb4c8c78e6 Mon Sep 17 00:00:00 2001
From: fish <gcslyp@gmail.com>
Date: Thu, 21 Mar 2019 17:56:20 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=97=A5=E5=BF=97=E6=89=93?=
 =?UTF-8?q?=E5=8D=B0=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=97=A0=E7=BA=BF=E8=AE=BE?=
 =?UTF-8?q?=E5=A4=87=E6=95=B0=E6=8D=AE=E5=87=BD=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 conf/gateway.conf |  8 ++++----
 tcpserver.go      | 11 +++++------
 worker.go         | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/conf/gateway.conf b/conf/gateway.conf
index 9bbbbac..9f830e7 100644
--- a/conf/gateway.conf
+++ b/conf/gateway.conf
@@ -16,16 +16,16 @@
 					["女厕位", 4],
 					["女厕位", 5],
 					["女厕位", 6],
-					["男厕位", 7],
-					["男厕位", 8]
+					["男厕位", 1],
+					["男厕位", 2]
 				]
 			},
 		{
 				"id": "EC13C2D9-6A93-4894-BB5B-89BDAA786D8A",
 				"version": "yunhorn_kgl_c8_v1",
 				"data": [
-					["男厕位", 1],
-					["男厕位", 2],
+					["男厕位", 7],
+					["男厕位", 8],
 					["男厕位", 3],
 					["男厕位", 4],
 					["男厕位", 5],
diff --git a/tcpserver.go b/tcpserver.go
index 7731a49..606feec 100644
--- a/tcpserver.go
+++ b/tcpserver.go
@@ -13,7 +13,7 @@ import (
 
 func handleConn(conn net.Conn) {
 
-	log.Println("begin handleConn,cliendAddr:%s", conn.LocalAddr())
+	log.Println("begin handleConn,cliendAddr:", conn.RemoteAddr())
 
 	defer conn.Close()
 
@@ -39,12 +39,12 @@ func handleConn(conn net.Conn) {
 				break
 			}
 		case <-time.After(5000 * time.Millisecond):
-			n, err := conn.Write(heartbeat)
+			_, err := conn.Write(heartbeat)
 			if err != nil {
 				log.Println("write msg error!", err)
 				stopChan <- true
 			} else {
-				log.Println("write msg success!", n)
+				log.Println("write msg success!", conn.RemoteAddr())
 			}
 		}
 	}
@@ -84,9 +84,8 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) {
 			log.Println(err)
 			break
 		}
-		log.Println(DEVICEDATAS)
-
-		log.Println("read.data:", Bytes2Bits(data[3:4]))
+		// log.Println(DEVICEDATAS)
+		log.Println("read.data:%d,%s", Bytes2Bits(data[3:4])[0],conn.RemoteAddr())
 
 		data_buf <- data
 	}
diff --git a/worker.go b/worker.go
index 7b7eed1..54ef0fa 100644
--- a/worker.go
+++ b/worker.go
@@ -22,6 +22,41 @@ type Device struct {
 	DATA    map[string]interface{} `json:"data"`
 }
 
+func yunhorn_lora_l_v1(data_buf []byte) {
+
+	// for _, i := range conf.RS485DEVICES {
+	// log.Println("################################",i)
+	// }
+
+	//log.Println(data_buf)
+	// for i, k := range b_buf {
+	// 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_int0 := Bytes2Bits(data_buf[0:1])
+	data_int1 := Bytes2Bits(data_buf[1:2])
+	data_int2 := Bytes2Bits(data_buf[2:3])
+
+	log.Println("data_int:", data_int[0])
+	log.Printf("ADRH:%d,ADRL:%d,dataType:%d,", data_int0[0], data_int1[0], data_int2[0])
+	var device Device
+  //TODO 配置device
+	device.ID = demoDevice.ID
+	device.VERSION = demoDevice.VERSION
+	device.ONLINE = demoDevice.ONLINE
+
+	demoDevice.DATA["data"] = data_int[0]
+	device.DATA = demoDevice.DATA
+
+	if conf.DEBUG {
+		log.Println(device)
+	}
+	// send_data(1005, device)
+
+}
+
 func yunhorn_ys_l_v1(data_buf []byte) {
 
 	// for _, i := range conf.RS485DEVICES {