From 42eb0e04cc4bcab72f7412b7eefb78ccfd4ac999 Mon Sep 17 00:00:00 2001 From: simylein <67859356+simylein@users.noreply.github.com> Date: Tue, 8 Sep 2026 16:11:17 +0200 Subject: [PATCH] fix(smartlabel+tagsl): ts2 deci altitude and moving flag --- pkg/decoder/smartlabel/v1/decoder.go | 18 +++++++++--------- pkg/decoder/smartlabel/v1/decoder_test.go | 20 ++++++++++---------- pkg/decoder/smartlabel/v1/port10.go | 10 +++++----- pkg/decoder/tagxl/v1/decoder.go | 17 ++++++++++------- pkg/decoder/tagxl/v1/decoder_test.go | 18 +++++++----------- pkg/decoder/tagxl/v1/port10.go | 3 +-- pkg/decoder/tagxl/v1/port10_test.go | 2 +- 7 files changed, 43 insertions(+), 45 deletions(-) diff --git a/pkg/decoder/smartlabel/v1/decoder.go b/pkg/decoder/smartlabel/v1/decoder.go index 8cfff94..1fdcfc4 100644 --- a/pkg/decoder/smartlabel/v1/decoder.go +++ b/pkg/decoder/smartlabel/v1/decoder.go @@ -108,12 +108,12 @@ func (t SmartLabelv1Decoder) getConfig(port uint8, data string) (common.PayloadC case 10: return common.PayloadConfig{ Fields: []common.FieldConfig{ - {Name: "Status", Start: 0, Length: 1}, + {Name: "Moving", Start: 0, Length: 1, Transform: moving}, {Name: "Latitude", Start: 1, Length: 4, Transform: latitude}, {Name: "Longitude", Start: 5, Length: 4, Transform: longitude}, - {Name: "Altitude", Start: 9, Length: 2, Transform: port10Altitude}, + {Name: "Altitude", Start: 9, Length: 2, Transform: altitude}, {Name: "Timestamp", Start: 11, Length: 4, Transform: timestamp}, - {Name: "Battery", Start: 15, Length: 2, Transform: gnssBattery}, + {Name: "Battery", Start: 15, Length: 2, Transform: battery}, {Name: "TTF", Start: 17, Length: 1, Transform: ttf}, {Name: "PDOP", Start: 18, Length: 1, Transform: pdop}, {Name: "Satellites", Start: 19, Length: 1}, @@ -318,6 +318,10 @@ func humidity(v any) any { return float32(common.BytesToUint8(v.([]byte))) / 2 } +func moving(v any) any { + return (v.([]byte))[0]&0x01 == 1 +} + func latitude(v any) any { return float64(common.BytesToInt32(v.([]byte))) / 1000000 } @@ -326,18 +330,14 @@ func longitude(v any) any { return float64(common.BytesToInt32(v.([]byte))) / 1000000 } -func port10Altitude(v any) any { - return float64(common.BytesToUint16(v.([]byte))) / 100 +func altitude(v any) any { + return float64(common.BytesToUint16(v.([]byte))) / 10 } func timestamp(v any) any { return time.Unix(int64(common.BytesToUint32(v.([]byte))), 0).UTC() } -func gnssBattery(v any) any { - return float64(common.BytesToUint16(v.([]byte))) / 1000 -} - func ttf(v any) any { return time.Duration(int64(common.BytesToUint8(v.([]byte)))) * time.Second } diff --git a/pkg/decoder/smartlabel/v1/decoder_test.go b/pkg/decoder/smartlabel/v1/decoder_test.go index d3657ae..76a40f2 100644 --- a/pkg/decoder/smartlabel/v1/decoder_test.go +++ b/pkg/decoder/smartlabel/v1/decoder_test.go @@ -238,10 +238,10 @@ func TestDecode(t *testing.T) { }, { // Active GNSS fix near Zurich (tracker sample) - payload: "0002d2eeb40081d77ca3706a196afd0e74000009", + payload: "0002d2eeb40081d77c10586a196afd0e74000009", port: 10, expected: Port10Payload{ - Status: 0, + Moving: false, Latitude: 47.3781, Longitude: 8.509308, Altitude: 418.4, @@ -256,10 +256,10 @@ func TestDecode(t *testing.T) { payload: "0002d308b50082457f16eb66c4a5cd0ed3000505", port: 10, expected: Port10Payload{ - Status: 0, + Moving: false, Latitude: 47.384757, Longitude: 8.537471, - Altitude: 58.67, + Altitude: 586.7, Timestamp: time.Date(2024, 8, 20, 14, 18, 53, 0, time.UTC), Battery: 3.795, TTF: helpers.DurationPtr(0), @@ -271,10 +271,10 @@ func TestDecode(t *testing.T) { payload: "0002d30b070082491f11256718d9fe0ede190505", port: 10, expected: Port10Payload{ - Status: 0, + Moving: false, Latitude: 47.385351, Longitude: 8.538399, - Altitude: 43.89, + Altitude: 438.9, Timestamp: time.Date(2024, 10, 23, 11, 11, 58, 0, time.UTC), Battery: 3.806, PDOP: helpers.Float64Ptr(2.5), @@ -286,10 +286,10 @@ func TestDecode(t *testing.T) { payload: "0002d30b070082491f11256718d9fe0e74190505", port: 10, expected: Port10Payload{ - Status: 0, + Moving: false, Latitude: 47.385351, Longitude: 8.538399, - Altitude: 43.89, + Altitude: 438.9, Timestamp: time.Date(2024, 10, 23, 11, 11, 58, 0, time.UTC), Battery: 3.7, PDOP: helpers.Float64Ptr(2.5), @@ -582,7 +582,7 @@ func TestPort10Features(t *testing.T) { payload, ok := decoded.Data.(Port10Payload) assert.True(t, ok) - assert.Equal(t, uint8(0), payload.Status) + assert.Equal(t, false, payload.Moving) } func TestInvalidPort(t *testing.T) { @@ -880,7 +880,7 @@ func TestMarshal(t *testing.T) { { payload: "0002d30b070082491f11256718d9fe0ede190505", port: 10, - expected: []string{"\"status\": 0", "\"latitude\": 47.385351", "\"battery\": \"3.806v\"", "\"satellites\": 5"}, + expected: []string{"\"moving\": false", "\"latitude\": 47.385351", "\"battery\": \"3.806v\"", "\"satellites\": 5"}, }, { payload: "0f50107904da8d", diff --git a/pkg/decoder/smartlabel/v1/port10.go b/pkg/decoder/smartlabel/v1/port10.go index cb75ff2..b79103a 100644 --- a/pkg/decoder/smartlabel/v1/port10.go +++ b/pkg/decoder/smartlabel/v1/port10.go @@ -14,10 +14,10 @@ import ( // +------+------+-------------------------------------------+------------------------+ // | Byte | Size | Description | Format | // +------+------+-------------------------------------------+------------------------+ -// | 0 | 1 | Status | uint8 (FW always 0) | +// | 0 | 1 | Status | uint8 (bit 0 = moving) | // | 1 | 4 | Latitude | int32, 1/1'000'000 deg | // | 5 | 4 | Longitude | int32, 1/1'000'000 deg | -// | 9 | 2 | Altitude | uint16, centimeters | +// | 9 | 2 | Altitude | uint16, decimeters | // | 11 | 4 | Unix timestamp | uint32 | // | 15 | 2 | voltage_temp (battery) | uint16, mV | // | 17 | 1 | Time to fix | uint8, s | @@ -26,12 +26,12 @@ import ( // +------+------+-------------------------------------------+------------------------+ type Port10Payload struct { - Status uint8 `json:"status"` + Moving bool `json:"moving"` Latitude float64 `json:"latitude" validate:"gte=-90,lte=90"` Longitude float64 `json:"longitude" validate:"gte=-180,lte=180"` Altitude float64 `json:"altitude"` Timestamp time.Time `json:"timestamp"` - Battery float64 `json:"battery" validate:"gte=1,lte=5"` + Battery float32 `json:"battery" validate:"gte=1,lte=5"` TTF *time.Duration `json:"ttf"` PDOP *float64 `json:"pdop"` Satellites *uint8 `json:"satellites" validate:"gte=3,lte=27"` @@ -103,7 +103,7 @@ func (p Port10Payload) GetSatellites() *uint8 { } func (p Port10Payload) GetBatteryVoltage() float64 { - return p.Battery + return float64(p.Battery) } func (p Port10Payload) GetLowBattery() *bool { diff --git a/pkg/decoder/tagxl/v1/decoder.go b/pkg/decoder/tagxl/v1/decoder.go index 5108be3..d854ae1 100644 --- a/pkg/decoder/tagxl/v1/decoder.go +++ b/pkg/decoder/tagxl/v1/decoder.go @@ -78,13 +78,12 @@ func (t TagXLv1Decoder) getConfig(port uint8, payload []byte) (common.PayloadCon case 10: return common.PayloadConfig{ Fields: []common.FieldConfig{ - {Name: "Status", Start: 0, Length: 1}, - {Name: "Moving", Start: 0, Length: 1}, + {Name: "Moving", Start: 0, Length: 1, Transform: moving}, {Name: "Latitude", Start: 1, Length: 4, Transform: latitude}, {Name: "Longitude", Start: 5, Length: 4, Transform: longitude}, - {Name: "Altitude", Start: 9, Length: 2, Transform: port10Altitude}, + {Name: "Altitude", Start: 9, Length: 2, Transform: altitude}, {Name: "Timestamp", Start: 11, Length: 4, Transform: timestamp}, - {Name: "Battery", Start: 15, Length: 2, Transform: gnssBattery}, + {Name: "Battery", Start: 15, Length: 2, Transform: battery}, {Name: "TTF", Start: 17, Length: 1, Transform: ttf}, {Name: "PDOP", Start: 18, Length: 1, Transform: pdop}, {Name: "Satellites", Start: 19, Length: 1}, @@ -638,6 +637,10 @@ func (t TagXLv1Decoder) Decode(ctx context.Context, data string, port uint8) (*d return decoder.NewDecodedUplink(config.Features, decodedData), err } +func moving(v any) any { + return (v.([]byte))[0]&0x01 == 1 +} + func timestamp(v any) any { return time.Unix(int64(common.BytesToUint32(v.([]byte))), 0).UTC() } @@ -658,11 +661,11 @@ func longitude(v any) any { return float64(common.BytesToInt32(v.([]byte))) / 1000000 } -func port10Altitude(v any) any { - return float64(common.BytesToUint16(v.([]byte))) / 100 +func altitude(v any) any { + return float64(common.BytesToUint16(v.([]byte))) / 10 } -func gnssBattery(v any) any { +func battery(v any) any { return float64(common.BytesToUint16(v.([]byte))) / 1000 } diff --git a/pkg/decoder/tagxl/v1/decoder_test.go b/pkg/decoder/tagxl/v1/decoder_test.go index 722a82c..bf25559 100644 --- a/pkg/decoder/tagxl/v1/decoder_test.go +++ b/pkg/decoder/tagxl/v1/decoder_test.go @@ -91,9 +91,8 @@ func TestDecode(t *testing.T) { }, { port: 10, - payload: "0002d2eeb40081d77ca3706a196afd0e74000009", + payload: "0002d2eeb40081d77c10586a196afd0e74000009", expected: Port10Payload{ - Status: 0, Moving: false, Latitude: 47.3781, Longitude: 8.509308, @@ -109,11 +108,10 @@ func TestDecode(t *testing.T) { port: 10, payload: "0002d30b070082491f11256718d9fe0ede190505", expected: Port10Payload{ - Status: 0, Moving: false, Latitude: 47.385351, Longitude: 8.538399, - Altitude: 43.89, + Altitude: 438.9, Timestamp: time.Date(2024, 10, 23, 11, 11, 58, 0, time.UTC), Battery: 3.806, TTF: helpers.DurationPtr(25 * time.Second), @@ -125,11 +123,10 @@ func TestDecode(t *testing.T) { port: 10, payload: "0102d30b070082491f11256718d9fe0ede190505", expected: Port10Payload{ - Status: 1, Moving: true, Latitude: 47.385351, Longitude: 8.538399, - Altitude: 43.89, + Altitude: 438.9, Timestamp: time.Date(2024, 10, 23, 11, 11, 58, 0, time.UTC), Battery: 3.806, TTF: helpers.DurationPtr(25 * time.Second), @@ -141,11 +138,10 @@ func TestDecode(t *testing.T) { port: 10, payload: "0202d30b070082491f11256718d9fe0ede190505", expected: Port10Payload{ - Status: 2, Moving: false, Latitude: 47.385351, Longitude: 8.538399, - Altitude: 43.89, + Altitude: 438.9, Timestamp: time.Date(2024, 10, 23, 11, 11, 58, 0, time.UTC), Battery: 3.806, TTF: helpers.DurationPtr(25 * time.Second), @@ -1443,7 +1439,7 @@ func TestFeatures(t *testing.T) { allowNoFeatures: true, }, { - payload: "0002d2eeb40081d77ca3706a196afd0e74000009", + payload: "0002d2eeb40081d77c10586a196afd0e74000009", port: 10, }, { @@ -1762,12 +1758,12 @@ func TestMarshal(t *testing.T) { { payload: "0002d30b070082491f11256718d9fe0ede190505", port: 10, - expected: []string{"\"status\": 0", "\"moving\": false", "\"latitude\": 47.385351", "\"altitude\": \"43.9m\"", "\"battery\": \"3.806v\"", "\"ttf\": \"25s\"", "\"pdop\": \"2.5m\"", "\"satellites\": 5"}, + expected: []string{"\"moving\": false", "\"latitude\": 47.385351", "\"altitude\": \"438.9m\"", "\"battery\": \"3.806v\"", "\"ttf\": \"25s\"", "\"pdop\": \"2.5m\"", "\"satellites\": 5"}, }, { payload: "0102d30b070082491f11256718d9fe0ede190505", port: 10, - expected: []string{"\"status\": 1", "\"moving\": true", "\"latitude\": 47.385351", "\"altitude\": \"43.9m\"", "\"battery\": \"3.806v\"", "\"ttf\": \"25s\"", "\"pdop\": \"2.5m\"", "\"satellites\": 5"}, + expected: []string{"\"moving\": true", "\"latitude\": 47.385351", "\"altitude\": \"438.9m\"", "\"battery\": \"3.806v\"", "\"ttf\": \"25s\"", "\"pdop\": \"2.5m\"", "\"satellites\": 5"}, }, { payload: "010b0266acbcf0000000000756", diff --git a/pkg/decoder/tagxl/v1/port10.go b/pkg/decoder/tagxl/v1/port10.go index 3d709b0..22d5743 100644 --- a/pkg/decoder/tagxl/v1/port10.go +++ b/pkg/decoder/tagxl/v1/port10.go @@ -17,7 +17,7 @@ import ( // | 0 | 1 | Status | uint8 (bit 0 = moving) | // | 1 | 4 | Latitude | int32, 1/1'000'000 deg | // | 5 | 4 | Longitude | int32, 1/1'000'000 deg | -// | 9 | 2 | Altitude | uint16, centimeters | +// | 9 | 2 | Altitude | uint16, decimeters | // | 11 | 4 | Unix timestamp | uint32 | // | 15 | 2 | voltage_temp (battery) | uint16, mV | // | 17 | 1 | Time to fix | uint8, s | @@ -26,7 +26,6 @@ import ( // +------+------+-------------------------------------------+------------------------+ type Port10Payload struct { - Status uint8 `json:"status"` Moving bool `json:"moving"` Latitude float64 `json:"latitude" validate:"gte=-90,lte=90"` Longitude float64 `json:"longitude" validate:"gte=-180,lte=180"` diff --git a/pkg/decoder/tagxl/v1/port10_test.go b/pkg/decoder/tagxl/v1/port10_test.go index f8b11fc..c933cad 100644 --- a/pkg/decoder/tagxl/v1/port10_test.go +++ b/pkg/decoder/tagxl/v1/port10_test.go @@ -12,7 +12,7 @@ func TestPort10Payload_GNSSAndBatteryMethods(t *testing.T) { ttf := 25 * time.Second p := Port10Payload{ - Status: 0, + Moving: false, Latitude: 47.385351, Longitude: 8.538399, Altitude: 43.89,