完善配置,添加是否启动tcpserver配置项

This commit is contained in:
fish 2019-03-28 11:50:56 +08:00
parent 41d2d2d3ee
commit d82e284bb7
3 changed files with 30 additions and 22 deletions

View File

@ -210,5 +210,6 @@
"websocketurl": ["192.168.3.216:8080", "/echo"], "websocketurl": ["192.168.3.216:8080", "/echo"],
"post_to_server": "https://smartoilets.cn/socketServer/statis/push", "post_to_server": "https://smartoilets.cn/socketServer/statis/push",
"debug": true, "debug": true,
"openserial":false "openserial":false,
"open_tcp_server":false
} }

View File

@ -19,16 +19,20 @@ 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"` //是否初始化时打开串口
WIRELESSSLAVEDEVICES []WirelessSlaveDevice `json:"wireless_slave_devices"` OPENSERIAL bool `json:"openserial"`
//无线 设备
WIRELESSSLAVEDEVICES []WirelessSlaveDevice `json:"wireless_slave_devices"`
//是否启动tcpserver
OPENTCPSETVER bool `json:"open_tcp_server"`
} }
//无线 下位机 //无线 下位机
@ -116,8 +120,8 @@ func init() {
demoDevice.ONLINE = true demoDevice.ONLINE = true
log.Println("init demoDevice success:", demoDevice) log.Println("init demoDevice success:", demoDevice)
airDevice.DATA = make(map[string]interface{}) airDevice.DATA = make(map[string]interface{})
airDevice.DATA["data"]=0 airDevice.DATA["data"] = 0
dbdata_init() dbdata_init()

21
main.go
View File

@ -36,18 +36,21 @@ func main() {
return return
} }
for { if conf.OPENTCPSETVER {
conn, err := listener.Accept() for {
if err != nil { conn, err := listener.Accept()
log.Printf("accept fail, err: %v\n", err) if err != nil {
continue log.Printf("accept fail, err: %v\n", err)
continue
}
// go process(conn)
go handleConn(conn)
} }
// go process(conn) } else {
go handleConn(conn) //如果不启动tcpserver则需要执行这里 让程序不退出
select {}
} }
// select {}
} }
func check(err error) { func check(err error) {