liuxiulin 2 years ago
parent
commit
b165c1c0f0

+ 3 - 3
protocol/dlt645_0x33323435.go

@@ -71,8 +71,8 @@ func (e *Dlt_0x33323435) stringToVoltageBlock(s string) error {
 	b1, _ := strconv.ParseFloat(s[6:8], 64)
 	c0, _ := strconv.ParseFloat(s[8:10], 64)
 	c1, _ := strconv.ParseFloat(s[10:12], 64)
-	e.VoltageA = a0*0.1 + a1*10
-	e.VoltageB = b0*0.1 + b1*10
-	e.VoltageC = c0*0.1 + c1*10
+	e.VoltageA = a0/10 + a1*10
+	e.VoltageB = b0/10 + b1*10
+	e.VoltageC = c0/10 + c1*10
 	return nil
 }

+ 3 - 3
protocol/dlt645_0x33323535.go

@@ -73,8 +73,8 @@ func (e *Dlt_0x33323535) stringToCurrentBlock(s string) error {
 	c0, _ := strconv.ParseFloat(s[12:14], 64)
 	c1, _ := strconv.ParseFloat(s[14:16], 64)
 	c2, _ := strconv.ParseFloat(s[16:18], 64)
-	e.CurrentA = a0*0.001 + a1*0.1 + a2*10
-	e.CurrentB = b0*0.001 + b1*0.1 + b2*10
-	e.CurrentC = c0*0.001 + c1*0.1 + c2*10
+	e.CurrentA = a0/1000 + a1/10 + a2*10
+	e.CurrentB = b0/1000 + b1/10 + b2*10
+	e.CurrentC = c0/1000 + c1/10 + c2*10
 	return nil
 }

+ 1 - 1
protocol/dlt645_0x33333433.go

@@ -65,6 +65,6 @@ func stringToWP(s string) (float64, error) {
 	a1, _ := strconv.ParseFloat(s[2:4], 64)
 	a2, _ := strconv.ParseFloat(s[4:6], 64)
 	a3, _ := strconv.ParseFloat(s[6:8], 64)
-	res := a0*0.01 + a1 + a2*100 + a3*10000
+	res := a0/100 + a1 + a2*100 + a3*10000
 	return res, nil
 }

+ 1 - 1
protocol/dlt645_0x33333533.go

@@ -64,6 +64,6 @@ func stringToReactiveEnergy(s string) (float64, error) {
 	a1, _ := strconv.ParseFloat(s[2:4], 64)
 	a2, _ := strconv.ParseFloat(s[4:6], 64)
 	a3, _ := strconv.ParseFloat(s[6:8], 64)
-	res := a0*0.01 + a1 + a2*100 + a3*10000
+	res := a0/100 + a1 + a2*100 + a3*10000
 	return res, nil
 }

+ 1 - 1
protocol/dlt645_0x33333635.go

@@ -68,6 +68,6 @@ func stringToActivePower(s string) (float64, error) {
 	a0, _ := strconv.ParseFloat(s[0:2], 64)
 	a1, _ := strconv.ParseFloat(s[2:4], 64)
 	a2, _ := strconv.ParseFloat(s[4:6], 64)
-	res := a0*0.0001 + a1*0.01 + a2
+	res := a0/10000 + a1/100 + a2
 	return res, nil
 }

+ 1 - 1
protocol/dlt645_0x33333735.go

@@ -63,6 +63,6 @@ func stringToReactivePower(s string) (float64, error) {
 	a0, _ := strconv.ParseFloat(s[0:2], 64)
 	a1, _ := strconv.ParseFloat(s[2:4], 64)
 	a2, _ := strconv.ParseFloat(s[4:6], 64)
-	res := a0*0.0001 + a1*0.01 + a2
+	res := a0/10000 + a1/100 + a2
 	return res, nil
 }

+ 1 - 1
protocol/dlt645_0x33333835.go

@@ -63,6 +63,6 @@ func stringToApparentPower(s string) (float64, error) {
 	a0, _ := strconv.ParseFloat(s[0:2], 64)
 	a1, _ := strconv.ParseFloat(s[2:4], 64)
 	a2, _ := strconv.ParseFloat(s[4:6], 64)
-	res := a0*0.0001 + a1*0.01 + a2
+	res := a0/10000 + a1/100 + a2
 	return res, nil
 }

+ 1 - 1
protocol/dlt645_0x33333935.go

@@ -62,6 +62,6 @@ func (e *Dlt_0x33333935) Decode(ctx *PacketContext, dataByte []byte) (data Data,
 func stringToPowerFactor(s string) (float64, error) {
 	a0, _ := strconv.ParseFloat(s[0:2], 64)
 	a1, _ := strconv.ParseFloat(s[2:4], 64)
-	res := a0*0.001 + a1*0.1
+	res := a0/10000 + a1/10
 	return res, nil
 }

+ 1 - 1
protocol/dlt645_0x33343435.go

@@ -63,6 +63,6 @@ func (e *Dlt_0x33343435) Decode(ctx *PacketContext, dataByte []byte) (data Data,
 func stringToVoltage(s string) (float64, error) {
 	a0, _ := strconv.ParseFloat(s[0:2], 64)
 	a1, _ := strconv.ParseFloat(s[2:4], 64)
-	res := a0*0.1 + a1*10
+	res := a0/10 + a1*10
 	return res, nil
 }

+ 1 - 1
protocol/dlt645_0x33343535.go

@@ -64,6 +64,6 @@ func stringToCurrent(s string) (float64, error) {
 	a0, _ := strconv.ParseFloat(s[0:2], 64)
 	a1, _ := strconv.ParseFloat(s[2:4], 64)
 	a2, _ := strconv.ParseFloat(s[4:6], 64)
-	res := a0*0.001 + a1*0.1 + a2*10
+	res := a0/1000 + a1/10 + a2*10
 	return res, nil
 }

+ 0 - 4
server/client.go

@@ -3,7 +3,6 @@ package server
 import (
 	"dlt645-server/protocol"
 	"errors"
-	"github.com/gogf/gf/encoding/gbinary"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/net/gtcp"
 	"github.com/gogf/gf/os/glog"
@@ -223,11 +222,8 @@ func (c *Client) SendGetAddress() error {
 				c.readError(err)
 				return err
 			}
-			glog.Debugf("收到数据:%2X", receiveBuf)
-
 			if len(receiveBuf) > 0 {
 				if !c.isReg {
-					c.SetId(gbinary.DecodeToString(receiveBuf))
 					c.isReg = true
 					continue
 				}

+ 2 - 2
server/server.go

@@ -67,13 +67,13 @@ func (s *Server) onClientConnect(conn *gtcp.Conn) {
 		_ = s.gateWay.SubDeviceLogin(g.Cfg().GetString("Sparrow.DeviceCode"), id)
 		s.clients.Set(id, c)
 	}
+
+	time.Sleep(10 * time.Second)
 	err := c.SendGetAddress()
 	if err != nil {
 		return
 	}
 
-	time.Sleep(10 * time.Second)
-
 	go c.SendLoop()
 
 	go c.GetActivePower()