Skip to content

Commit

Permalink
Added new features. 🆙
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbeutler committed Feb 21, 2025
1 parent 461b9a3 commit f73580a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
30 changes: 21 additions & 9 deletions pkg/decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ type Decoder interface {
type Feature string

const (
FeatureGNSS Feature = "gnss"
FeatureBuffered Feature = "buffered"
FeatureBattery Feature = "battery"
FeatureTemperature Feature = "temperature"
FeatureWiFi Feature = "wifi"
FeatureBle Feature = "ble"
FeatureButton Feature = "button"
FeatureConfig Feature = "config"
FeatureMoving Feature = "moving"
FeatureGNSS Feature = "gnss"
FeatureBuffered Feature = "buffered"
FeatureBattery Feature = "battery"
FeatureTemperature Feature = "temperature"
FeatureWiFi Feature = "wifi"
FeatureBle Feature = "ble"
FeatureButton Feature = "button"
FeatureConfig Feature = "config"
FeatureMoving Feature = "moving"
FeatureFirmwareVersion Feature = "firmware_version"
FeatureHardwareVersion Feature = "hardware_version"
)

type DecodedUplink struct {
Expand Down Expand Up @@ -105,3 +107,13 @@ type UplinkFeatureMoving interface {
// IsMoving returns true if the device is moving, otherwise it returns false.
IsMoving() bool
}

type UplinkFeatureFirmwareVersion interface {
// GetFirmwareVersion returns the firmware version of the device.
GetFirmwareVersion() string
}

type UplinkFeatureHardwareVersion interface {
// GetHardwareVersion returns the hardware version of the device.
GetHardwareVersion() string
}
1 change: 0 additions & 1 deletion pkg/decoder/decoder_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/decoder/tagsl/v1/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (t TagSLv1Decoder) getConfig(port int16) (common.PayloadConfig, error) {
{Name: "BufferSize", Start: 30, Length: 2, Optional: true},
},
TargetType: reflect.TypeOf(Port4Payload{}),
Features: []decoder.Feature{decoder.FeatureConfig},
Features: []decoder.Feature{decoder.FeatureConfig, decoder.FeatureHardwareVersion, decoder.FeatureFirmwareVersion},
}, nil
case 5:
return common.PayloadConfig{
Expand Down
18 changes: 18 additions & 0 deletions pkg/decoder/tagsl/v1/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,24 @@ func TestFeatures(t *testing.T) {
// call function to check if it panics
moving.IsMoving()
}
if decodedPayload.Is(decoder.FeatureFirmwareVersion) {
firmwareVersion, ok := decodedPayload.Data.(decoder.UplinkFeatureFirmwareVersion)
if !ok {
t.Fatalf("expected UplinkFeatureFirmwareVersion, got %T", decodedPayload)
}
if firmwareVersion.GetFirmwareVersion() == "" {
t.Fatalf("expected non empty firmware version")
}
}
if decodedPayload.Is(decoder.FeatureHardwareVersion) {
hardwareVersion, ok := decodedPayload.Data.(decoder.UplinkFeatureHardwareVersion)
if !ok {
t.Fatalf("expected UplinkFeatureHardwareVersion, got %T", decodedPayload)
}
if hardwareVersion.GetHardwareVersion() == "" {
t.Fatalf("expected non empty hardware version")
}
}
})
}
}
13 changes: 13 additions & 0 deletions pkg/decoder/tagsl/v1/port4.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tagsl

import (
"fmt"
"time"

"github.com/truvami/decoder/pkg/decoder"
Expand Down Expand Up @@ -40,7 +41,19 @@ type Port4Payload struct {
}

var _ decoder.UplinkFeatureBase = &Port4Payload{}
var _ decoder.UplinkFeatureFirmwareVersion = &Port4Payload{}
var _ decoder.UplinkFeatureHardwareVersion = &Port4Payload{}

func (p Port4Payload) GetTimestamp() *time.Time {
return nil
}

// GetHardwareVersion implements decoder.UplinkFeatureHardwareVersion.
func (p Port4Payload) GetHardwareVersion() string {
return fmt.Sprintf("%d.%d", p.HardwareVersionType, p.HardwareVersionRevision)
}

// GetFirmwareVersion implements decoder.UplinkFeatureFirmwareVersion.
func (p Port4Payload) GetFirmwareVersion() string {
return fmt.Sprintf("%d.%d.%d", p.FirmwareVersionMajor, p.FirmwareVersionMinor, p.FirmwareVersionPatch)
}

0 comments on commit f73580a

Please sign in to comment.