Make fortoprt handling more robust

This commit is contained in:
Nise Void 2018-09-28 14:05:06 +02:00
parent c83feeb845
commit bd9e9136e6
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3

View File

@ -8,6 +8,7 @@ import (
"git.fuyu.moe/5GPowerQuality/parser/data" "git.fuyu.moe/5GPowerQuality/parser/data"
"git.fuyu.moe/5GPowerQuality/parser/shared" "git.fuyu.moe/5GPowerQuality/parser/shared"
"git.fuyu.moe/Fuyu/flog"
"golang.org/x/net/websocket" "golang.org/x/net/websocket"
) )
@ -43,6 +44,18 @@ func FetchData() {
requestData(conn, 2) requestData(conn, 2)
for { for {
readData(conn)
}
}
func readData(conn *websocket.Conn) {
defer func() {
v := recover()
if v != nil {
flog.Critical(v)
}
}()
b, n := make([]byte, 16384), 0 b, n := make([]byte, 16384), 0
msg := message{} msg := message{}
@ -62,7 +75,6 @@ func FetchData() {
break break
} }
// sets := data.Sets{}
mID := data.GetMeterID(data.SourceFortop, host+`-`+strconv.Itoa(msg.Data["U1"].DeviceID)) mID := data.GetMeterID(data.SourceFortop, host+`-`+strconv.Itoa(msg.Data["U1"].DeviceID))
sets := data.Sets{} sets := data.Sets{}
@ -86,7 +98,6 @@ func FetchData() {
data.InsertSets(sets) data.InsertSets(sets)
} }
}
func requestData(conn *websocket.Conn, meter int) { func requestData(conn *websocket.Conn, meter int) {
write(conn, `{"MESSAGEINFO":{"VERSION":1,"APPLICATION":"DCEM_ENTERPRISE","MODULE":"LIVEDATA","FUNCTION":"REQUEST_DATASTREAM","REVISION":1},"VARS":{"DEVICEID":`+strconv.Itoa(meter)+`,"VALUES":`+values+`}}`) write(conn, `{"MESSAGEINFO":{"VERSION":1,"APPLICATION":"DCEM_ENTERPRISE","MODULE":"LIVEDATA","FUNCTION":"REQUEST_DATASTREAM","REVISION":1},"VARS":{"DEVICEID":`+strconv.Itoa(meter)+`,"VALUES":`+values+`}}`)