Skip to content

Commit 663dc34

Browse files
committed
wip
1 parent 64e0266 commit 663dc34

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

meters/rs485/dtsu666h.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package rs485
2+
3+
import (
4+
. "github.com/volkszaehler/mbmd/meters"
5+
)
6+
7+
func init() {
8+
Register("DTSU666H", NewDTSU666HProducer)
9+
}
10+
11+
type DTSU666HProducer struct {
12+
Opcodes
13+
}
14+
15+
func NewDTSU666HProducer() Producer {
16+
/***
17+
* Opcodes as defined by Chint DTSU666-H (Huawei firmware).
18+
* Based on https://github.com/salakrzy/DTSU666_CHINT_to_HUAWEI_translator
19+
* Huawei firmware uses different register addresses starting at 0x0836 (2102).
20+
*/
21+
ops := Opcodes{
22+
CurrentL1: 2102, // Phase current A (IEEE754 float32, A, scale: 1000) - Pos 0
23+
CurrentL2: 2104, // Phase current B (IEEE754 float32, A, scale: 1000) - Pos 1
24+
CurrentL3: 2106, // Phase current C (IEEE754 float32, A, scale: 1000) - Pos 2
25+
VoltageL1: 2110, // Phase voltage A (IEEE754 float32, V, scale: 10) - Pos 4
26+
VoltageL2: 2112, // Phase voltage B (IEEE754 float32, V, scale: 10) - Pos 5
27+
VoltageL3: 2114, // Phase voltage C (IEEE754 float32, V, scale: 10) - Pos 6
28+
Frequency: 2124, // Grid frequency (IEEE754 float32, Hz, scale: 100) - Pos 11
29+
Power: 2126, // Active power total (IEEE754 float32, kW, scale: 10) - Pos 12
30+
PowerL1: 2128, // Active power A (IEEE754 float32, kW, scale: 10) - Pos 13
31+
PowerL2: 2130, // Active power B (IEEE754 float32, kW, scale: 10) - Pos 14
32+
PowerL3: 2132, // Active power C (IEEE754 float32, kW, scale: 10) - Pos 15
33+
ReactivePower: 2134, // Reactive power total (IEEE754 float32, kVar, scale: 10) - Pos 16
34+
ReactivePowerL1: 2136, // Reactive power A (IEEE754 float32, kVar, scale: 10) - Pos 17
35+
ReactivePowerL2: 2138, // Reactive power B (IEEE754 float32, kVar, scale: 10) - Pos 18
36+
ReactivePowerL3: 2140, // Reactive power C (IEEE754 float32, kVar, scale: 10) - Pos 19
37+
Cosphi: 2144, // Power factor total (IEEE754 float32, scale: 10) - Pos 24
38+
CosphiL1: 2146, // Power factor A (IEEE754 float32, scale: 10) - Pos 25
39+
CosphiL2: 2148, // Power factor B (IEEE754 float32, scale: 10) - Pos 26
40+
CosphiL3: 2150, // Power factor C (IEEE754 float32, scale: 10) - Pos 27
41+
Import: 2166, // Total positive active energy (IEEE754 float32, kWh, scale: 1) - Pos 32
42+
Export: 2180, // Total negative active energy (IEEE754 float32, kWh, scale: 1) - Pos 36
43+
}
44+
45+
return &DTSU666HProducer{Opcodes: ops}
46+
}
47+
48+
func (p *DTSU666HProducer) Description() string {
49+
return "Chint DTSU666-H (Huawei)"
50+
}
51+
52+
func (p *DTSU666HProducer) snip(iec Measurement, scaler ...float64) Operation {
53+
operation := Operation{
54+
FuncCode: ReadHoldingReg,
55+
OpCode: p.Opcode(iec),
56+
ReadLen: 2,
57+
IEC61850: iec,
58+
Transform: RTUIeee754ToFloat64,
59+
}
60+
61+
if len(scaler) > 0 {
62+
operation.Transform = MakeScaledTransform(operation.Transform, scaler[0])
63+
}
64+
65+
return operation
66+
}
67+
68+
func (p *DTSU666HProducer) Probe() Operation {
69+
return p.snip(VoltageL1, 10)
70+
}
71+
72+
func (p *DTSU666HProducer) Produce() (res []Operation) {
73+
for _, op := range []Measurement{
74+
VoltageL1, VoltageL2, VoltageL3,
75+
Power, PowerL1, PowerL2, PowerL3,
76+
ReactivePower, ReactivePowerL1, ReactivePowerL2, ReactivePowerL3,
77+
Cosphi, CosphiL1, CosphiL2, CosphiL3,
78+
} {
79+
res = append(res, p.snip(op, 10))
80+
}
81+
82+
for _, op := range []Measurement{
83+
CurrentL1, CurrentL2, CurrentL3,
84+
} {
85+
res = append(res, p.snip(op, 1000))
86+
}
87+
88+
for _, op := range []Measurement{
89+
Frequency,
90+
} {
91+
res = append(res, p.snip(op, 100))
92+
}
93+
94+
for _, op := range []Measurement{
95+
Import, Export,
96+
} {
97+
res = append(res, p.snip(op, 1))
98+
}
99+
100+
return res
101+
}

0 commit comments

Comments
 (0)