完善本地web数据

This commit is contained in:
fish 2019-03-28 11:46:23 +08:00
parent 2446847ae9
commit 41d2d2d3ee
4 changed files with 55 additions and 46 deletions

View File

@ -75,6 +75,8 @@ var conf Conf
var DEVICEDATAS Devicedatas
var demoDevice Device
var airDevice Device
var db, _ = sql.Open("sqlite3", "./db/gateway.db")
// 加载配置文件
@ -114,6 +116,9 @@ func init() {
demoDevice.ONLINE = true
log.Println("init demoDevice success:", demoDevice)
airDevice.DATA = make(map[string]interface{})
airDevice.DATA["data"]=0
dbdata_init()
}

View File

@ -10,10 +10,12 @@ import (
var err error
func main() {
go gw_router()
go serial_run()
c := cron.New()
send_data(1001)
c.AddFunc("0, *, *, *, *, *", func() {
send_data(1001)
})

3
mq.go
View File

@ -1,3 +1,6 @@
package main
func init() {
//var data []byte = []byte{0x01,0x01,0x01,0x00}
}

View File

@ -23,58 +23,56 @@ type Device struct {
}
//处理通过tcp发送过来的数据
func yunhorn_wireless(data_buf []byte){
//至少5个字节数据
log.Println("wireless.tcp.data.len:",len(data_buf))
if len(data_buf)>4 {
adrh := data_buf[0]
adrl := data_buf[1]
func yunhorn_wireless(data_buf []byte) {
//至少5个字节数据
log.Println("wireless.tcp.data.len:", len(data_buf))
if len(data_buf) > 4 {
adrh := data_buf[0]
adrl := data_buf[1]
if (adrh==0 && adrl==0) || (adrh==0 && adrl==1) {
go yunhorn_ys_l_v1(data_buf)
}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 (adrh == 0 && adrl == 0) || (adrh == 0 && adrl == 1) {
go yunhorn_ys_l_v1(data_buf)
} 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的情况
// log.Println("adrh:%d,adrl:%d,conf.adrh:%d,conf.adrl:%d",int(adrh),int(adrl),item.ADRH,item.ADRL)
if int(adrh)!=item.ADRH || int(adrl) != item.ADRL{
continue;
}
// log.Println("adrh:%d,adrl:%d,conf.adrh:%d,conf.adrl:%d",int(adrh),int(adrl),item.ADRH,item.ADRL)
if int(adrh) != item.ADRH || int(adrl) != item.ADRL {
continue
}
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
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 = make(map[string]interface{})
device.DATA["data"] = data
send_data(1005, device)
}
}
}
}
// if(len(data_buf)>8){
// go yunhorn_wireless(data_buf[4:])
// }
device.DATA = make(map[string]interface{})
device.DATA["data"] = data
send_data(1005, device)
}
}
}
}
// if(len(data_buf)>8){
// go yunhorn_wireless(data_buf[4:])
// }
}
func yunhorn_xdy_l_v1(data_buf []byte){
func yunhorn_xdy_l_v1(data_buf []byte) {
}
@ -142,7 +140,7 @@ func yunhorn_ys_l_v1(data_buf []byte) {
demoDevice.DATA["data"+strconv.Itoa(2)] = 0
demoDevice.DATA["data"+strconv.Itoa(3)] = 0
if data_int0[0]==0 && data_int1[0]==0 {
if data_int0[0] == 0 && data_int1[0] == 0 && data_type[0] == 0 {
demoDevice.DATA["data"+strconv.Itoa(8)] = data_int[0]
var device Device
device.Lock()
@ -225,6 +223,7 @@ func yunhorn_kgl_l_v1(data_buf []byte) {
// 采集并解析水表数据
func yunhorn_sb_c_v1(s *serial.Port, device_id string, command [][]byte, num string) {
_, err = s.Write([]byte(command[0]))
check(err)
if conf.DEBUG {