|
@@ -2,6 +2,7 @@ package protocol
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/hex"
|
|
"encoding/hex"
|
|
|
|
+ "fmt"
|
|
"github.com/gogf/gf/os/glog"
|
|
"github.com/gogf/gf/os/glog"
|
|
"strconv"
|
|
"strconv"
|
|
)
|
|
)
|
|
@@ -50,7 +51,7 @@ func (e *Dlt_0x33323435) Decode(ctx *PacketContext, dataByte []byte) (data Data,
|
|
e.DeviceID = hex.EncodeToString(bytea)
|
|
e.DeviceID = hex.EncodeToString(bytea)
|
|
//正向总电能每个字节-33,1-4,分别为,小数位,个位,百位,万位
|
|
//正向总电能每个字节-33,1-4,分别为,小数位,个位,百位,万位
|
|
byteb := make([]byte, 6)
|
|
byteb := make([]byte, 6)
|
|
- for i := 0; i < 2; i++ {
|
|
|
|
|
|
+ for i := 0; i < 6; i++ {
|
|
byteb[i] = dataByte[14+i] - 0x33
|
|
byteb[i] = dataByte[14+i] - 0x33
|
|
}
|
|
}
|
|
|
|
|
|
@@ -65,14 +66,14 @@ func (e *Dlt_0x33323435) Decode(ctx *PacketContext, dataByte []byte) (data Data,
|
|
}
|
|
}
|
|
|
|
|
|
func (e *Dlt_0x33323435) stringToVoltageBlock(s string) error {
|
|
func (e *Dlt_0x33323435) stringToVoltageBlock(s string) error {
|
|
- a0, _ := strconv.ParseFloat(s[0:2], 64)
|
|
|
|
- a1, _ := strconv.ParseFloat(s[2:4], 64)
|
|
|
|
- b0, _ := strconv.ParseFloat(s[4:6], 64)
|
|
|
|
- b1, _ := strconv.ParseFloat(s[6:8], 64)
|
|
|
|
- c0, _ := strconv.ParseFloat(s[8:10], 64)
|
|
|
|
- c1, _ := strconv.ParseFloat(s[10:12], 64)
|
|
|
|
- e.VoltageA = a0/10 + a1*10
|
|
|
|
- e.VoltageB = b0/10 + b1*10
|
|
|
|
- e.VoltageC = c0/10 + c1*10
|
|
|
|
|
|
+ a0, _ := strconv.ParseFloat(s[0:2], 32)
|
|
|
|
+ a1, _ := strconv.ParseFloat(s[2:4], 32)
|
|
|
|
+ b0, _ := strconv.ParseFloat(s[4:6], 32)
|
|
|
|
+ b1, _ := strconv.ParseFloat(s[6:8], 32)
|
|
|
|
+ c0, _ := strconv.ParseFloat(s[8:10], 32)
|
|
|
|
+ c1, _ := strconv.ParseFloat(s[10:12], 32)
|
|
|
|
+ e.VoltageA, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", a0/10+a1*10), 64)
|
|
|
|
+ e.VoltageB, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", b0/10+b1*10), 64)
|
|
|
|
+ e.VoltageC, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", c0/10+c1*10), 64)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|