From 6d960f50f8ae60dd267fcc8c050201a7ba9f50e2 Mon Sep 17 00:00:00 2001 From: fish <gcslyp@gmail.com> Date: Tue, 7 May 2019 15:51:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=97=A8=E7=A3=81=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B,=E5=AE=8C=E5=96=84=E5=9C=B0=E5=9D=80=E8=BF=87?= =?UTF-8?q?=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tcpserver.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/tcpserver.go b/tcpserver.go index bdeeca2..58c8455 100644 --- a/tcpserver.go +++ b/tcpserver.go @@ -96,11 +96,13 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) { continue; } - s := strconv.FormatInt(int64(b&0xff), 16) - if len(s) == 1 { - buffer.WriteString("0") - } - buffer.WriteString(s) + if b!=254{ + s := strconv.FormatInt(int64(b&0xff), 16) + if len(s) == 1 { + buffer.WriteString("0") + } + buffer.WriteString(s) + } // log.Println("========================",data[reqLen-2:reqLen]) @@ -111,6 +113,7 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) { //254为分隔符 if b==254 && i>3{ addrs := data[i-4:i] + //尿布台数据,地址1位 数据2位 dataType := data[i+1] values := make([]byte,0) @@ -168,6 +171,39 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) { if err != nil { log.Println("write msg error!", err) } + }else if dataType ==3{ + continueCount = 2 + end = 3 + + if i+3 >reqLen{ + log.Println("yunhorndeug.push.data.tcp.fq",buffer.String(),addrs,dataType) + continue + } + + // values = data[i+2:i+3] + values := data[i+2] + + //8E 3C 00 00 47 46 + var green []byte = []byte{0x8E,0x3C,0x00,0x00,0x47,0x46} + var red []byte = []byte{0x8E,0x3C,0x00,0x00,0x52,0x46} + + var yellow []byte = []byte{0x8E,0x3C,0x00,0x00,0x59,0x46} + var writedata []byte =[]byte{} + writedata = green + if values == 2{ + writedata = red + }else if values == 1{ + writedata = green + }else if values == 4{ + writedata = yellow + } + log.Println("send.msg.conn.RemoteAddr|writedata",connTest.RemoteAddr(),writedata) + v, err := connTest.Write(writedata) + + log.Println("send.msg.conn.v",v) + if err != nil { + log.Println("write msg error!", err) + } } @@ -176,7 +212,16 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) { // log.Println("yunhorndeug.push.data.tcp.type",dataType) // log.Println("yunhorndeug.push.data.tcp.values",values) - buffer = new(bytes.Buffer) + _,ok := loraNodeMap.Load(buffer.String()) + if !ok{ + log.Println("yunhorndeug.push.data.tcp.dev not exist:",buffer.String()) + buffer = new(bytes.Buffer) + continue + } + + buffer = new(bytes.Buffer) + + if(dataType ==1 || dataType ==2 ){ go dealDatav3(data[i-4:i+end]) }