diff --git a/conf/gateway.conf b/conf/gateway.conf index 196af62..a7b1ee0 100644 --- a/conf/gateway.conf +++ b/conf/gateway.conf @@ -210,5 +210,6 @@ "websocketurl": ["192.168.3.216:8080", "/echo"], "post_to_server": "https://smartoilets.cn/socketServer/statis/push", "debug": true, - "openserial":false + "openserial":false, + "open_tcp_server":false } diff --git a/loadconfig.go b/loadconfig.go index 44e1cb8..7db127a 100644 --- a/loadconfig.go +++ b/loadconfig.go @@ -19,16 +19,20 @@ type Satisfaction struct { } type Conf struct { - GATEWAY_INFO Gateway_info `json:"gateway_info"` - DEVICES_LIST [][]string `json:"devices_list` - SERIALPORTS_LIST map[string]Serialconf `json:"serialports_list"` - RS485DEVICES map[string]Rs485devices `json:"rs485devices"` - ICONURL string `json:"iconurl` - WEBSOCKETURL []string `json:"websocketurl"` - POST_TO_SERVER string `json:"post_to_server"` - DEBUG bool `json:"debug"` - OPENSERIAL bool `json:"openserial"` - WIRELESSSLAVEDEVICES []WirelessSlaveDevice `json:"wireless_slave_devices"` + GATEWAY_INFO Gateway_info `json:"gateway_info"` + DEVICES_LIST [][]string `json:"devices_list` + SERIALPORTS_LIST map[string]Serialconf `json:"serialports_list"` + RS485DEVICES map[string]Rs485devices `json:"rs485devices"` + ICONURL string `json:"iconurl` + WEBSOCKETURL []string `json:"websocketurl"` + POST_TO_SERVER string `json:"post_to_server"` + DEBUG bool `json:"debug"` + //是否初始化时打开串口 + 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 log.Println("init demoDevice success:", demoDevice) - airDevice.DATA = make(map[string]interface{}) - airDevice.DATA["data"]=0 + airDevice.DATA = make(map[string]interface{}) + airDevice.DATA["data"] = 0 dbdata_init() diff --git a/main.go b/main.go index e2b5e25..7aa8fe7 100644 --- a/main.go +++ b/main.go @@ -36,18 +36,21 @@ func main() { return } - for { - conn, err := listener.Accept() - if err != nil { - log.Printf("accept fail, err: %v\n", err) - continue + if conf.OPENTCPSETVER { + for { + conn, err := listener.Accept() + if err != nil { + log.Printf("accept fail, err: %v\n", err) + continue + } + // go process(conn) + go handleConn(conn) } - // go process(conn) - go handleConn(conn) + } else { + //如果不启动tcpserver,则需要执行这里 让程序不退出 + select {} } - // select {} - } func check(err error) {