diff --git a/conf/gateway.conf b/conf/gateway.conf index 132736b..4039a53 100644 --- a/conf/gateway.conf +++ b/conf/gateway.conf @@ -101,7 +101,7 @@ }, { "adrh":0, - "adrl":0, + "adrl":1, "type":1, "version":"yunhorn_ys_l_v1", "flip":true, @@ -110,7 +110,8 @@ ], "devices_list": [ ["4E5D52DD-EB81-43C0-A2B6-04E432412EBA", "loraport", "yunhorn_kgl_l_v1", "1"], - ["EB5B0798-9B7F-474E-AAB8-467FD5FE1293", "loraport", "yunhorn_kgl_l_v1", "2"] + ["EB5B0798-9B7F-474E-AAB8-467FD5FE1293", "loraport", "yunhorn_kgl_l_v1", "2"], + ["deb03e28-ddcb-4e5d-aa31-d870a1f0f09b", "loraport", "yunhorn_kgl_c8_v1", "1"] ], "serialports_list": { "loraport": { @@ -124,13 +125,6 @@ } }, "rs485devices": { - "deb03e28-ddcb-4e5d-aa31-d870a1f0f09b": { - "version": "yunhorn_ys_l_v1", - "num": "1", - "command": [ - [8, 3, 0, 1, 0, 2, 149, 82] - ] - }, "15394892-E8B0-4FF2-BC35-1BF380BD1B68": { "version": "yunhorn_xsy_c_v1", "num": "1", diff --git a/tcpserver.go b/tcpserver.go index 606feec..dbd53a9 100644 --- a/tcpserver.go +++ b/tcpserver.go @@ -32,7 +32,9 @@ func handleConn(conn net.Conn) { //log.Println("readStr:",readStr) //upper := strings.ToUpper(readStr) //writeChan <- upper - go yunhorn_ys_l_v1(readStr) + + // go yunhorn_ys_l_v1(readStr) + go yunhorn_wireless(readStr) case stop := <-stopChan: if stop { log.Println("stop channel") @@ -62,7 +64,7 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) { //log.Println("kkdata:",kkdata) case <-time.After(50 * time.Millisecond): //上面的ch如果一直没数据会阻塞,那么select也会检测其他case条件,检测到后3秒超时 // log.Println("超时") - if len(Rdata) > 3 { + if len(Rdata) > 4 { readChan <- Rdata Rdata = make([]byte, 0) } diff --git a/worker.go b/worker.go index cdd2d52..a9cc069 100644 --- a/worker.go +++ b/worker.go @@ -22,6 +22,50 @@ type Device struct { DATA map[string]interface{} `json:"data"` } +//处理通过tcp发送过来的数据 +func yunhorn_wireless(data_buf []byte){ + //至少5个字节数据 + if len(data_buf)>4 { + adrh := data_buf[0] + adrl := data_buf[1] + + if adrh==0 && adrl==0 { + go yunhorn_ys_l_v1(readStr) + }else{ + dataType := data_buf[2] + data_int := Bytes2Bits(data_buf[3:4]) + data := data_int[0] + //第3个字节表示本数据帧的类型,00表示NPN数据类型,01表示磁开关数据类型,02表示485传感器上报数据类型,03表示485传感器数据采集类型 + if dataType !=3 { + for _,item range conf.WIRELESSSLAVEDEVICES{ + //数据是否需要反转,检测到有信号是1的情况 + if item.flip{ + if data==0{ + data = 1 + }else{ + data = 0 + } + } + + var device Device + //TODO 配置device + device.ID = item.id + device.VERSION = item.VERSION + device.ONLINE = true + + device.DATA = data + send_data(1005, device) + } + } + } + + } +} + +func yunhorn_xdy_l_v1(data_buf []byte){ + +} + func yunhorn_lora_l_v1(data_buf []byte) { // for _, i := range conf.RS485DEVICES {