完善配置以及日志

This commit is contained in:
fish 2019-04-17 11:17:45 +08:00
parent 612ed4b281
commit cb86495fb4
3 changed files with 44 additions and 10 deletions

View File

@ -123,14 +123,14 @@
],
"serialports_list": {
"loraport": {
"com": "/dev/cu.wchusbserial141420",
"bauds": 115200,
"size": 8,
"parity": "E",
"stopbits": 1,
"readtimeout": 100,
"note": "lorawan"
}
"com": "/dev/cu.wchusbserial141420",
"bauds": 115200,
"size": 8,
"parity": "E",
"stopbits": 1,
"readtimeout": 100,
"note": "lorawan"
}
},
"rs485devices": {
"15394892-E8B0-4FF2-BC35-1BF380BD1B68": {
@ -211,5 +211,6 @@
"post_to_server": "https://smartoilets.cn/socketServer/statis/push",
"debug": true,
"openserial":false,
"open_tcp_server":false
"open_tcp_server":false,
"check_serial":true
}

View File

@ -33,6 +33,7 @@ type Conf struct {
WIRELESSSLAVEDEVICES []WirelessSlaveDevice `json:"wireless_slave_devices"`
//是否启动tcpserver
OPENTCPSETVER bool `json:"open_tcp_server"`
CHECKSERIAL bool `json:"check_serial"`
}
//无线 下位机
@ -92,6 +93,24 @@ func init() {
check(err)
var device Device
//var serialPort = make(map[string]int)
//for k, i := range conf.SERIALPORTS_LIST {
// log.Println(k)
// log.Println(i)
// if v, c := serialPort[k]; c {
// log.Println("repeatd serial port:", v)
// os.Exit(3)
// } else {
// serialPort[k] = 0
// }
//}
//log.Println("begin print serialPort")
//for k, i := range serialPort {
// log.Println(k)
// log.Println(i)
//}
log.Println("slaveDevices:", conf.WIRELESSSLAVEDEVICES)
// for _,i := range conf.WIRELESSSLAVEDEVICES{
@ -101,14 +120,27 @@ func init() {
DEVICEDATAS.Lock()
DEVICEDATAS.DATA = make(map[string]Device)
//校验是否有设置重复串口
//var serialPort = make(map[string]int)
//初始化设备目前conf.DEVICES_LIST
for _, i := range conf.DEVICES_LIST {
//if _, c := serialPort[i[1]]; c {
// log.Println("repeatd serial port:", i[1])
// os.Exit(3)
//} else {
// serialPort[i[1]] = 0
//}
device.DATA = make(map[string]interface{})
device.ID = i[0]
device.VERSION = i[2]
//版本号+编号
DEVICEDATAS.DATA[i[2]+"_"+i[3]] = device
}
DEVICEDATAS.Unlock()
demoDevice.ID = "deb03e28-ddcb-4e5d-aa31-d870a1f0f09b"

View File

@ -11,6 +11,7 @@ func serial_run() {
SERIAL_PORT := make(map[string]*serial.Port)
ports_arr := make([]string, 0)
port_arr := make([]string, 0)
for _, i := range conf.DEVICES_LIST {
ports_arr = append(ports_arr, i[1])
}
@ -46,7 +47,7 @@ func serial_run() {
}
if conf.DEBUG {
log.Println(SERIAL_PORT)
log.Println("SERIAL_PORT:",SERIAL_PORT)
}
// 遍历设备对应的串口对应的端口并放到相应的run_port_device方法
for j, k := range SERIAL_PORT {