The map knew the names the card was showing as hex
Every field in the cloud MQTT map that has a documented meaning now reads as a named row, on the same labels the register map uses for the same quantities. The raw block stays, and shrinks to what genuinely nobody has identified — which is the only honest reason for a key like 0410.b9 to be on screen at all. Three fields the reference decodes for nobody are decoded here. ac is where the charge is coming from — off or paused, grid, solar — and it is called chargingSource rather than chargingMode, because that name already belongs to a Modbus register and the last time a cloud field borrowed one, d9 spent a release reporting the wrong thing under the right name. b6 is the session's order id. f1, f2 and f3 are the identity fields the reference marks multi-value: four bytes read as the parts of a version, in the order they arrive, which is what the account view's own firmware string looks like. If the panel shows those parts reversed, the order is the thing to flip — it is the one assumption here that the wire has not yet confirmed. The rest was already decoded and simply never drawn. The readings card now shows the session's start, its id, the charging source, whether a cable is in, the charging window, and — since a reading is worth what its age is — the live-stream flag and both stream clocks, because telemetry and settings arrive on different messages with different triggers. Per-phase session energy joins the phase matrix as a fourth column, appearing on the transport that counts a session and staying away from the one that does not, exactly as the reactive and apparent pair does. The settings block gains the fourteen the register map has no address for: plug lock, auto restart, random delay, the schedule and its mode, the weekend window and how the weekend is handled, the light-off schedule and window, the breaker limit, the solar mode and its minimum current, automatic phase switching, the three panel gestures, and what the two balancing features are watching — the meter and monitor serials by name, their two unpinned numbers as the numbers they are. A local network block says whether the charger's own Modbus server is on and where, which is the answer the Modbus mode's setup screen otherwise has to be given by hand. The device block gains the controller version. A test now holds the line the projection quietly drew: every name in the message maps must reach a snapshot field. A name added to a map without a field to land in would otherwise surface in the raw block looking like something we understood. Left raw: a1, the frame opener the charger echoes back; b7, which the map itself calls unidentified; b9, bc and bd, which appear in no map; the five-minute 0400; and 0857 — a message type the reference's closed inventory of fourteen does not contain and this charger publishes anyway. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
197ff73a39
commit
8e2073fc4c
@@ -91,6 +91,10 @@ type mqttField struct {
|
||||
factor float64
|
||||
unsigned bool
|
||||
clock bool
|
||||
// version marks the three identity fields, which the reference calls
|
||||
// multi-value: four bytes that are the parts of a version rather than one
|
||||
// number, in the order they arrive.
|
||||
version bool
|
||||
}
|
||||
|
||||
// evTelemetry decodes the 0410 message: the charger's live electrical state,
|
||||
@@ -108,6 +112,11 @@ var evTelemetry = map[byte]mqttField{
|
||||
0xa9: {name: "sessionSeconds"},
|
||||
0xaa: {name: "sessionWh"},
|
||||
0xab: {name: "sessionStartedAt", unsigned: true},
|
||||
// Where the charge is coming from: 0 off or paused, 1 grid, 7 solar. The
|
||||
// reference marks the reading uncertain, and it is not the Modbus map's
|
||||
// chargingMode — a third name for a fourth thing would be the same collision
|
||||
// the cloud's d9 already caused once.
|
||||
0xac: {name: "chargingSource"},
|
||||
0xad: {name: "plugCountdownSeconds"},
|
||||
0xae: {name: "startCountdownSeconds"},
|
||||
0xaf: {name: "chargingWindowSeconds"},
|
||||
@@ -117,6 +126,7 @@ var evTelemetry = map[byte]mqttField{
|
||||
0xb3: {name: "sessionWhL1"},
|
||||
0xb4: {name: "sessionWhL2"},
|
||||
0xb5: {name: "sessionWhL3"},
|
||||
0xb6: {name: "orderId", unsigned: true}, // the session's id upstream; uncertain in the reference
|
||||
0xb8: {name: "ocppStatus"},
|
||||
0xba: {name: "phaseMode"},
|
||||
0xbb: {name: "status"},
|
||||
@@ -169,6 +179,13 @@ var evParams = map[byte]mqttField{
|
||||
0xea: {name: "weekendEnd", unsigned: true, clock: true},
|
||||
0xeb: {name: "weekendMode"},
|
||||
0xec: {name: "scheduleMode"},
|
||||
// The three identity fields. The reference decodes none of them, marking them
|
||||
// multi-value; four bytes read as the parts of a version is what the account
|
||||
// view's own firmware string looks like, so they are read that way and shown
|
||||
// as they arrive rather than rearranged into an order we cannot check.
|
||||
0xf1: {name: "softwareVersion", version: true},
|
||||
0xf2: {name: "controllerVersion", version: true},
|
||||
0xf3: {name: "hardwareVersion", version: true},
|
||||
0xfe: {name: "minCurrentA"},
|
||||
}
|
||||
|
||||
@@ -401,6 +418,9 @@ func decodeValue(typ byte, b []byte, f mqttField) (any, bool) {
|
||||
if len(b) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
if f.version {
|
||||
return versionString(b), true
|
||||
}
|
||||
factor := f.factor
|
||||
if factor == 0 {
|
||||
factor = 1
|
||||
@@ -452,6 +472,20 @@ func decodeValue(typ byte, b []byte, f mqttField) (any, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// versionString reads an identity field. Four bytes are the parts of a version,
|
||||
// in wire order; anything else is text the charger padded, or — failing that —
|
||||
// the bytes themselves, because a version we cannot shape is still better shown
|
||||
// than dropped.
|
||||
func versionString(b []byte) string {
|
||||
if len(b) == 4 {
|
||||
return fmt.Sprintf("%d.%d.%d.%d", b[0], b[1], b[2], b[3])
|
||||
}
|
||||
if s := printable(b); s != "" {
|
||||
return s
|
||||
}
|
||||
return encodeHex(b)
|
||||
}
|
||||
|
||||
// round trims the floating-point noise a factor introduces, to the precision the
|
||||
// factor itself implies — 0.1 keeps one decimal, 0.001 keeps three.
|
||||
func round(v, factor float64) float64 {
|
||||
|
||||
@@ -278,3 +278,21 @@ func TestDecodeHexRejectsRubbish(t *testing.T) {
|
||||
t.Errorf("encodeHex is not lowercase hex")
|
||||
}
|
||||
}
|
||||
|
||||
// The three identity fields the reference leaves alone: four bytes that are the
|
||||
// parts of a version, kept in the order they arrived rather than rearranged into
|
||||
// one we cannot check.
|
||||
func TestDecodeVersionFields(t *testing.T) {
|
||||
v, ok := decodeValue(typeInt32LE, []byte{1, 0, 6, 1}, mqttField{name: "softwareVersion", version: true})
|
||||
if !ok || v != "1.0.6.1" {
|
||||
t.Errorf("softwareVersion = %v (ok=%v), want 1.0.6.1", v, ok)
|
||||
}
|
||||
// A field that is not four bytes is text where it can be read as text, and
|
||||
// the bytes themselves where it cannot — never nothing.
|
||||
if v, ok := decodeValue(typeString, []byte("V1.2\x00"), mqttField{version: true}); !ok || v != "V1.2" {
|
||||
t.Errorf("text version = %v (ok=%v), want V1.2", v, ok)
|
||||
}
|
||||
if v, ok := decodeValue(typeInt32LE, []byte{0x01, 0x02}, mqttField{version: true}); !ok || v != "0102" {
|
||||
t.Errorf("unreadable version = %v (ok=%v), want its bytes", v, ok)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,13 @@ type MqttSnapshot struct {
|
||||
Serial string `json:"serial"`
|
||||
Model string `json:"model,omitempty"`
|
||||
|
||||
// What the charger says it is, on the same names the register map uses for
|
||||
// the same three answers. The reference decodes none of them; see the
|
||||
// version fields in mqttframe.go for how they are read.
|
||||
Firmware string `json:"firmware,omitempty"`
|
||||
ControllerVersion string `json:"controllerVersion,omitempty"`
|
||||
Hardware string `json:"hardware,omitempty"`
|
||||
|
||||
Status *int `json:"status,omitempty"`
|
||||
StatusDesc string `json:"statusDesc,omitempty"`
|
||||
|
||||
@@ -51,6 +58,14 @@ type MqttSnapshot struct {
|
||||
SessionSeconds *float64 `json:"sessionSeconds,omitempty"`
|
||||
SessionWh *float64 `json:"sessionWh,omitempty"`
|
||||
|
||||
// The session's own three energies and when it began. The register map has
|
||||
// neither: a session is a cloud idea, and only this transport counts it.
|
||||
SessionWhL1 *float64 `json:"sessionWhL1,omitempty"`
|
||||
SessionWhL2 *float64 `json:"sessionWhL2,omitempty"`
|
||||
SessionWhL3 *float64 `json:"sessionWhL3,omitempty"`
|
||||
SessionStartedAt *float64 `json:"sessionStartedAt,omitempty"` // unix seconds
|
||||
OrderID *float64 `json:"orderId,omitempty"`
|
||||
|
||||
// The countdowns the charger runs before a session: how long it will wait for
|
||||
// a plug, and how long a start delay still has to go. They are why a charger
|
||||
// that has been told to start can sit in "preparing" without being broken.
|
||||
@@ -62,6 +77,11 @@ type MqttSnapshot struct {
|
||||
BoostMode *bool `json:"boostMode,omitempty"`
|
||||
Plugged *bool `json:"plugged,omitempty"`
|
||||
|
||||
// Where the charge is coming from — 0 off or paused, 1 grid, 7 solar. The
|
||||
// reference marks this reading uncertain, so it is reported as the number it
|
||||
// is and named for what it distinguishes rather than folded into a mode.
|
||||
ChargingSource *int `json:"chargingSource,omitempty"`
|
||||
|
||||
CPSignal *int `json:"cpSignal,omitempty"`
|
||||
CPSignalDesc string `json:"cpSignalDesc,omitempty"`
|
||||
|
||||
@@ -74,6 +94,21 @@ type MqttSnapshot struct {
|
||||
MinCurrentA *float64 `json:"minCurrentA,omitempty"`
|
||||
MaxCurrentA *float64 `json:"maxCurrentA,omitempty"`
|
||||
|
||||
// The panel's three gestures: what a swipe up, a swipe down and a touch do.
|
||||
SwipeUpMode *int `json:"swipeUpMode,omitempty"`
|
||||
SwipeDownMode *int `json:"swipeDownMode,omitempty"`
|
||||
SmartTouchMode *int `json:"smartTouchMode,omitempty"`
|
||||
|
||||
// What the two balancing features are watching. The reference has not pinned
|
||||
// down what the two modes and the flag select, so they are reported as the
|
||||
// numbers they are; the serials name the meter and the monitor themselves,
|
||||
// and nothing outside the charger knows them.
|
||||
LoadBalanceMonitorMode *int `json:"loadBalanceMonitorMode,omitempty"`
|
||||
LoadBalanceMeterFlag *int `json:"loadBalanceMeterFlag,omitempty"`
|
||||
LoadBalanceMonitorSN string `json:"loadBalanceMonitorSN,omitempty"`
|
||||
SolarMonitoringMode *int `json:"solarMonitoringMode,omitempty"`
|
||||
SolarMonitorSN string `json:"solarMonitorSN,omitempty"`
|
||||
|
||||
Settings *MqttSettings `json:"settings,omitempty"`
|
||||
|
||||
// Local reports what the charger says about its own LAN side: whether Modbus
|
||||
@@ -322,6 +357,19 @@ func projectMqttSnapshot(sn, model string, v map[string]any) MqttSnapshot {
|
||||
snap.PowerL1, snap.PowerL2, snap.PowerL3 = num("powerL1"), num("powerL2"), num("powerL3")
|
||||
snap.PowerTotal = num("powerTotal")
|
||||
snap.SessionSeconds, snap.SessionWh = num("sessionSeconds"), num("sessionWh")
|
||||
snap.SessionWhL1, snap.SessionWhL2 = num("sessionWhL1"), num("sessionWhL2")
|
||||
snap.SessionWhL3 = num("sessionWhL3")
|
||||
snap.SessionStartedAt, snap.OrderID = num("sessionStartedAt"), num("orderId")
|
||||
snap.ChargingSource = whole("chargingSource")
|
||||
snap.Firmware, snap.Hardware = text("softwareVersion"), text("hardwareVersion")
|
||||
snap.ControllerVersion = text("controllerVersion")
|
||||
snap.SwipeUpMode, snap.SwipeDownMode = whole("swipeUpMode"), whole("swipeDownMode")
|
||||
snap.SmartTouchMode = whole("smartTouchMode")
|
||||
snap.LoadBalanceMonitorMode = whole("loadBalanceMonitorMode")
|
||||
snap.LoadBalanceMeterFlag = whole("loadBalanceMeterFlag")
|
||||
snap.LoadBalanceMonitorSN = text("loadBalanceMonitorSN")
|
||||
snap.SolarMonitoringMode = whole("solarMonitoringMode")
|
||||
snap.SolarMonitorSN = text("solarMonitorSN")
|
||||
snap.PlugCountdownSeconds = num("plugCountdownSeconds")
|
||||
snap.StartCountdownSeconds = num("startCountdownSeconds")
|
||||
snap.ChargingWindowSeconds = num("chargingWindowSeconds")
|
||||
|
||||
@@ -145,32 +145,26 @@ func TestProjectSnapshotOfNothingIsEmpty(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A value the projection has a field for belongs in that field; everything else
|
||||
// the charger sent belongs in extra — the named values this package has not
|
||||
// modelled, and the fields no message map can name at all.
|
||||
// A value the projection has a field for belongs in that field; extra is what is
|
||||
// left, which — now that every name in the message maps is projected — is the
|
||||
// fields no map names at all.
|
||||
func TestProjectSnapshotKeepsWhatItHasNoFieldFor(t *testing.T) {
|
||||
snap := projectMqttSnapshot("SN1", "A5191", map[string]any{
|
||||
"powerTotal": 3680.0,
|
||||
"maxCurrentSetA": 16.0,
|
||||
"sessionStartedAt": 1756800000.0,
|
||||
"sessionWhL1": 4100.0,
|
||||
"swipeUpMode": 2.0,
|
||||
"loadBalanceMonitorSN": "METER1",
|
||||
rawFieldName(msgEVTelemetry, 0xc9): 300.0,
|
||||
rawFieldName("0400", 0xa2): 7.0,
|
||||
})
|
||||
|
||||
for _, key := range []string{"powerTotal", "maxCurrentSetA"} {
|
||||
for _, key := range []string{"powerTotal", "maxCurrentSetA", "sessionWhL1"} {
|
||||
if _, ok := snap.Extra[key]; ok {
|
||||
t.Errorf("extra[%q] is set; a value with a field of its own must not be repeated there", key)
|
||||
}
|
||||
}
|
||||
want := map[string]any{
|
||||
"sessionStartedAt": 1756800000.0, "sessionWhL1": 4100.0, "swipeUpMode": 2.0,
|
||||
"loadBalanceMonitorSN": "METER1", "0410.c9": 300.0,
|
||||
}
|
||||
for key, value := range want {
|
||||
if snap.Extra[key] != value {
|
||||
t.Errorf("extra[%q] = %v, want %v", key, snap.Extra[key], value)
|
||||
for key, want := range map[string]any{"0410.c9": 300.0, "0400.a2": 7.0} {
|
||||
if snap.Extra[key] != want {
|
||||
t.Errorf("extra[%q] = %v, want %v", key, snap.Extra[key], want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,3 +175,19 @@ func TestProjectSnapshotKeepsWhatItHasNoFieldFor(t *testing.T) {
|
||||
t.Errorf("extra = %v, want none when nothing is left over", bare.Extra)
|
||||
}
|
||||
}
|
||||
|
||||
// Every field the message maps name has somewhere to land. A name added to a map
|
||||
// without a field to project it into would otherwise show up in the raw block
|
||||
// under a name that reads as if it were understood.
|
||||
func TestEveryNamedFieldIsProjected(t *testing.T) {
|
||||
values := map[string]any{}
|
||||
for _, fields := range []map[byte]mqttField{evTelemetry, evParams, evCharging} {
|
||||
for _, f := range fields {
|
||||
values[f.name] = 1.0
|
||||
}
|
||||
}
|
||||
snap := projectMqttSnapshot("SN1", "A5191", values)
|
||||
if len(snap.Extra) != 0 {
|
||||
t.Errorf("these named fields reach no snapshot field: %v", snap.Extra)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user