添加无线下位机配置,完善本地web数据显示
This commit is contained in:
parent
b557176ceb
commit
bba19a1e4e
|
@ -19,26 +19,26 @@ type Satisfaction struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
GATEWAY_INFO Gateway_info `json:"gateway_info"`
|
GATEWAY_INFO Gateway_info `json:"gateway_info"`
|
||||||
DEVICES_LIST [][]string `json:"devices_list`
|
DEVICES_LIST [][]string `json:"devices_list`
|
||||||
SERIALPORTS_LIST map[string]Serialconf `json:"serialports_list"`
|
SERIALPORTS_LIST map[string]Serialconf `json:"serialports_list"`
|
||||||
RS485DEVICES map[string]Rs485devices `json:"rs485devices"`
|
RS485DEVICES map[string]Rs485devices `json:"rs485devices"`
|
||||||
ICONURL string `json:"iconurl`
|
ICONURL string `json:"iconurl`
|
||||||
WEBSOCKETURL []string `json:"websocketurl"`
|
WEBSOCKETURL []string `json:"websocketurl"`
|
||||||
POST_TO_SERVER string `json:"post_to_server"`
|
POST_TO_SERVER string `json:"post_to_server"`
|
||||||
DEBUG bool `json:"debug"`
|
DEBUG bool `json:"debug"`
|
||||||
OPENSERIAL bool `json:"openserial"`
|
OPENSERIAL bool `json:"openserial"`
|
||||||
WIRELESSSLAVEDEVICES []WirelessSlaveDevice `json:"wireless_slave_devices"`
|
WIRELESSSLAVEDEVICES []WirelessSlaveDevice `json:"wireless_slave_devices"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//无线 下位机
|
//无线 下位机
|
||||||
type WirelessSlaveDevice struct{
|
type WirelessSlaveDevice struct {
|
||||||
ADRH int `json:"adrh"`
|
ADRH int `json:"adrh"`
|
||||||
ADRL int `json:"adrl"`
|
ADRL int `json:"adrl"`
|
||||||
TYPE int `json:"type"`
|
TYPE int `json:"type"`
|
||||||
VERSION string `json:"version"`
|
VERSION string `json:"version"`
|
||||||
FLIP bool `json:"flip"`
|
FLIP bool `json:"flip"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Gateway_info struct {
|
type Gateway_info struct {
|
||||||
|
@ -86,20 +86,21 @@ func init() {
|
||||||
check(err)
|
check(err)
|
||||||
var device Device
|
var device Device
|
||||||
|
|
||||||
log.Println("slaveDevices:",conf.WIRELESSSLAVEDEVICES)
|
log.Println("slaveDevices:", conf.WIRELESSSLAVEDEVICES)
|
||||||
|
|
||||||
// for _,i := range conf.WIRELESSSLAVEDEVICES{
|
// for _,i := range conf.WIRELESSSLAVEDEVICES{
|
||||||
// log.Println(conf.WIRELESSSLAVEDEVICES[k].ID)
|
// log.Println(conf.WIRELESSSLAVEDEVICES[k].ID)
|
||||||
// log.Println(i.ID)
|
// log.Println(i.ID)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
DEVICEDATAS.Lock()
|
DEVICEDATAS.Lock()
|
||||||
DEVICEDATAS.DATA = make(map[string]Device)
|
DEVICEDATAS.DATA = make(map[string]Device)
|
||||||
//初始化设备,目前conf.DEVICES_LIST 指的是lora
|
//初始化设备,目前conf.DEVICES_LIST
|
||||||
for _, i := range conf.DEVICES_LIST {
|
for _, i := range conf.DEVICES_LIST {
|
||||||
device.DATA = make(map[string]interface{})
|
device.DATA = make(map[string]interface{})
|
||||||
device.ID = i[0]
|
device.ID = i[0]
|
||||||
device.VERSION = i[2]
|
device.VERSION = i[2]
|
||||||
|
//版本号+编号
|
||||||
DEVICEDATAS.DATA[i[2]+"_"+i[3]] = device
|
DEVICEDATAS.DATA[i[2]+"_"+i[3]] = device
|
||||||
}
|
}
|
||||||
DEVICEDATAS.Unlock()
|
DEVICEDATAS.Unlock()
|
||||||
|
|
13
router.go
13
router.go
|
@ -202,10 +202,14 @@ func seat_api(c *gin.Context) {
|
||||||
type_id := c.Param("id")
|
type_id := c.Param("id")
|
||||||
var data Seat_data
|
var data Seat_data
|
||||||
var conf_data [][]interface{}
|
var conf_data [][]interface{}
|
||||||
|
//conf.GATEWAY_INFO.CONFIG 采集器配置信息
|
||||||
for _, i := range conf.GATEWAY_INFO.CONFIG {
|
for _, i := range conf.GATEWAY_INFO.CONFIG {
|
||||||
arr := get_seat_device_data(i.ID)
|
arr := get_seat_device_data(i.ID)
|
||||||
|
//获取到设备版本
|
||||||
version, num := arr[0], arr[1]
|
version, num := arr[0], arr[1]
|
||||||
|
|
||||||
log.Println("conf.data:", i.DATA)
|
log.Println("conf.data:", i.DATA)
|
||||||
|
log.Println("devicedatas.data:", DEVICEDATAS.DATA)
|
||||||
for k, j := range i.DATA {
|
for k, j := range i.DATA {
|
||||||
if DEVICEDATAS.DATA[version+"_"+num].DATA != nil {
|
if DEVICEDATAS.DATA[version+"_"+num].DATA != nil {
|
||||||
if DEVICEDATAS.DATA[version+"_"+num].DATA["data"+strconv.Itoa(k+1)] != nil {
|
if DEVICEDATAS.DATA[version+"_"+num].DATA["data"+strconv.Itoa(k+1)] != nil {
|
||||||
|
@ -233,11 +237,13 @@ func seat_api(c *gin.Context) {
|
||||||
|
|
||||||
// 拼凑位置信息的数据
|
// 拼凑位置信息的数据
|
||||||
func get_seat_device_data(id string) []string {
|
func get_seat_device_data(id string) []string {
|
||||||
|
log.Println("begin get_seat_device_data.id:", id)
|
||||||
var data = make([]string, 2)
|
var data = make([]string, 2)
|
||||||
|
//配置表中devices_list
|
||||||
|
//例如["4E5D52DD-EB81-43C0-A2B6-04E432412EBA", "loraport", "yunhorn_kgl_l_v1", "1"],
|
||||||
for _, i := range conf.DEVICES_LIST {
|
for _, i := range conf.DEVICES_LIST {
|
||||||
//[4E5D52DD-EB81-43C0-A2B6-04E432412EBA loraport yunhorn_kgl_l_v1 1]
|
// log.Println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
|
||||||
log.Println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
|
// log.Println(i)
|
||||||
log.Println(i)
|
|
||||||
if id == i[0] {
|
if id == i[0] {
|
||||||
data[0], data[1] = i[2], i[3]
|
data[0], data[1] = i[2], i[3]
|
||||||
log.Println(data)
|
log.Println(data)
|
||||||
|
@ -246,6 +252,7 @@ func get_seat_device_data(id string) []string {
|
||||||
data[0], data[1] = "null", "null"
|
data[0], data[1] = "null", "null"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.Println("get_seat_device_data:", data)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
worker.go
29
worker.go
|
@ -33,7 +33,7 @@ func yunhorn_lora_l_v1(data_buf []byte) {
|
||||||
// log.Println(binary.BigEndian.Uint16(append([]byte{0x00}, k))
|
// log.Println(binary.BigEndian.Uint16(append([]byte{0x00}, k))
|
||||||
// }
|
// }
|
||||||
|
|
||||||
log.Println("ys_l_v1_data:",data_buf)
|
log.Println("ys_l_v1_data:", data_buf)
|
||||||
data_int := Bytes2Bits(data_buf[3:4])
|
data_int := Bytes2Bits(data_buf[3:4])
|
||||||
data_int0 := Bytes2Bits(data_buf[0:1])
|
data_int0 := Bytes2Bits(data_buf[0:1])
|
||||||
data_int1 := Bytes2Bits(data_buf[1:2])
|
data_int1 := Bytes2Bits(data_buf[1:2])
|
||||||
|
@ -42,7 +42,7 @@ func yunhorn_lora_l_v1(data_buf []byte) {
|
||||||
log.Println("data_int:", data_int[0])
|
log.Println("data_int:", data_int[0])
|
||||||
log.Printf("ADRH:%d,ADRL:%d,dataType:%d,", data_int0[0], data_int1[0], data_int2[0])
|
log.Printf("ADRH:%d,ADRL:%d,dataType:%d,", data_int0[0], data_int1[0], data_int2[0])
|
||||||
var device Device
|
var device Device
|
||||||
//TODO 配置device
|
//TODO 配置device
|
||||||
device.ID = demoDevice.ID
|
device.ID = demoDevice.ID
|
||||||
device.VERSION = demoDevice.VERSION
|
device.VERSION = demoDevice.VERSION
|
||||||
device.ONLINE = demoDevice.ONLINE
|
device.ONLINE = demoDevice.ONLINE
|
||||||
|
@ -68,7 +68,7 @@ func yunhorn_ys_l_v1(data_buf []byte) {
|
||||||
// log.Println(binary.BigEndian.Uint16(append([]byte{0x00}, k))
|
// log.Println(binary.BigEndian.Uint16(append([]byte{0x00}, k))
|
||||||
// }
|
// }
|
||||||
|
|
||||||
log.Println("ys_l_v1_data:",data_buf)
|
log.Println("ys_l_v1_data:", data_buf)
|
||||||
data_int := Bytes2Bits(data_buf[3:4])
|
data_int := Bytes2Bits(data_buf[3:4])
|
||||||
data_int0 := Bytes2Bits(data_buf[0:1])
|
data_int0 := Bytes2Bits(data_buf[0:1])
|
||||||
data_int1 := Bytes2Bits(data_buf[1:2])
|
data_int1 := Bytes2Bits(data_buf[1:2])
|
||||||
|
@ -85,12 +85,23 @@ func yunhorn_ys_l_v1(data_buf []byte) {
|
||||||
demoDevice.DATA["data"+strconv.Itoa(2)] = rand.Intn(2)
|
demoDevice.DATA["data"+strconv.Itoa(2)] = rand.Intn(2)
|
||||||
demoDevice.DATA["data"+strconv.Itoa(3)] = rand.Intn(2)
|
demoDevice.DATA["data"+strconv.Itoa(3)] = rand.Intn(2)
|
||||||
|
|
||||||
//485
|
//485
|
||||||
if(data_type[0]==2){
|
if data_type[0] == 2 {
|
||||||
demoDevice.DATA["data"+strconv.Itoa(8)] = rand.Intn(2)
|
demoDevice.DATA["data"+strconv.Itoa(8)] = rand.Intn(2)
|
||||||
}else{
|
} else {
|
||||||
demoDevice.DATA["data"+strconv.Itoa(7)] = data_int[0]
|
demoDevice.DATA["data"+strconv.Itoa(7)] = data_int[0]
|
||||||
}
|
|
||||||
|
var device Device
|
||||||
|
device.Lock()
|
||||||
|
device.ID = demoDevice.ID
|
||||||
|
device.VERSION = demoDevice.VERSION
|
||||||
|
device.ONLINE = demoDevice.ONLINE
|
||||||
|
device.DATA = make(map[string]interface{})
|
||||||
|
device.DATA["data1"] = data_int[0]
|
||||||
|
device.Unlock()
|
||||||
|
DEVICEDATAS.DATA[demoDevice.VERSION+"_1"] = device
|
||||||
|
|
||||||
|
}
|
||||||
device.DATA = demoDevice.DATA
|
device.DATA = demoDevice.DATA
|
||||||
|
|
||||||
if conf.DEBUG {
|
if conf.DEBUG {
|
||||||
|
|
Loading…
Reference in New Issue