Skip to content

Commit

Permalink
Fixed invalid buffer level and tests. πŸ’‘
Browse files Browse the repository at this point in the history
`tagsl 105 801366ee2f4d00c4eb438ddde2a504e31aea1b01a7245a4c7a0d2ec026e98d560d2ebbccd42ef92ed4ae704f5708e1d1b9` returned buffer level `32787`
  • Loading branch information
michaelbeutler committed Sep 21, 2024
1 parent 4e799b8 commit 128dc63
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pkg/decoder/tagsl/v1/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (t TagSLv1Decoder) getConfig(port int16) (decoder.PayloadConfig, error) {
case 105:
return decoder.PayloadConfig{
Fields: []decoder.FieldConfig{
{Name: "BufferLevel", Start: 0, Length: 2},
{Name: "BufferLevel", Start: 1, Length: 1},
{Name: "Timestamp", Start: 2, Length: 4},
{Name: "Moving", Start: 7, Length: 1},
{Name: "Mac1", Start: 7, Length: 6, Optional: true},
Expand All @@ -222,7 +222,7 @@ func (t TagSLv1Decoder) getConfig(port int16) (decoder.PayloadConfig, error) {
case 110:
return decoder.PayloadConfig{
Fields: []decoder.FieldConfig{
{Name: "BufferLevel", Start: 0, Length: 2},
{Name: "BufferLevel", Start: 1, Length: 1},
{Name: "Moving", Start: 2, Length: 1},
{Name: "Latitude", Start: 3, Length: 4, Transform: func(v interface{}) interface{} {
return float64(v.(int)) / 1000000
Expand All @@ -243,7 +243,7 @@ func (t TagSLv1Decoder) getConfig(port int16) (decoder.PayloadConfig, error) {
case 150:
return decoder.PayloadConfig{
Fields: []decoder.FieldConfig{
{Name: "BufferLevel", Start: 0, Length: 2},
{Name: "BufferLevel", Start: 1, Length: 1},
{Name: "Moving", Start: 2, Length: 1},
{Name: "Latitude", Start: 3, Length: 4, Transform: func(v interface{}) interface{} {
return float64(v.(int)) / 1000000
Expand Down
27 changes: 24 additions & 3 deletions pkg/decoder/tagsl/v1/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func TestDecode(t *testing.T) {
payload: "010166c4a5ba00e0286d8aabfcb1e0286d8a9478c2ec6c9a74b58fad726c9a74b58dadf0b0140c96bbd0",
port: 105,
expected: Port105Payload{
BufferLevel: 257,
BufferLevel: 1,
Moving: false,
Timestamp: time.Date(2024, 8, 20, 14, 18, 34, 0, time.UTC),
Mac1: "e0286d8aabfc",
Expand All @@ -298,6 +298,27 @@ func TestDecode(t *testing.T) {
Rssi5: -48,
},
},
{
payload: "801366ee2f4d00c4eb438ddde2a504e31aea1b01a7245a4c7a0d2ec026e98d560d2ebbccd42ef92ed4ae704f5708e1d1b9",
port: 105,
expected: Port105Payload{
BufferLevel: 19,
Moving: false,
Timestamp: time.Date(2024, 9, 21, 2, 28, 29, 0, time.UTC),
Mac1: "c4eb438ddde2",
Rssi1: -91,
Mac2: "04e31aea1b01",
Rssi2: -89,
Mac3: "245a4c7a0d2e",
Rssi3: -64,
Mac4: "26e98d560d2e",
Rssi4: -69,
Mac5: "ccd42ef92ed4",
Rssi5: -82,
Mac6: "704f5708e1d1",
Rssi6: -71,
},
},
{
payload: "00020002d309ae008247c5113966c45d640f7e",
port: 110,
Expand All @@ -315,7 +336,7 @@ func TestDecode(t *testing.T) {
payload: "01020002d309ae008247c5113966c45d640f7e",
port: 110,
expected: Port110Payload{
BufferLevel: 258,
BufferLevel: 2,
Moving: false,
Latitude: 47.385006,
Longitude: 8.538053,
Expand Down Expand Up @@ -363,7 +384,7 @@ func TestDecode(t *testing.T) {
payload: "01020002d30c9300824c87117966c45dcd0f8118e0286d8aabfca9f0b0140c96bbc8726c9a74b58da8e0286d8a9478bf",
port: 150,
expected: Port150Payload{
BufferLevel: 258,
BufferLevel: 2,
Moving: false,
Latitude: 47.385747,
Longitude: 8.539271,
Expand Down
2 changes: 1 addition & 1 deletion pkg/decoder/tagsl/v1/port105.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "time"
// +-------+------+-------------------------------------------+-----------+
// | Byte | Size | Description | Format |
// +-------+------+-------------------------------------------+-----------+
// | 0 | 2 | Buffer level | uint16 |
// | 1 | 1 | Buffer level | uint16 |
// | 2 | 4 | Unix timestamp | uint32 |
// | 7 | 1 | Status[6:2] + Moving flag[0] (moving = 1) | uint8 |
// | 7 | 6 | MAC1 | 6 x uint8 |
Expand Down
2 changes: 1 addition & 1 deletion pkg/decoder/tagsl/v1/port110.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "time"
// +-------+------+-------------------------------------------+------------------------+
// | Byte | Size | Description | Format |
// +-------+------+-------------------------------------------+------------------------+
// | 0 | 2 | Buffer level | uint16 |
// | 1 | 1 | Buffer level | uint16 |
// | 2 | 1 | Status[6:2] + Moving flag[0] (moving = 1) | uint8 |
// | 3-6 | 4 | Latitude | int32, 1/1’000’000 deg |
// | 7-10 | 4 | Longitude | int32, 1/1’000’000 deg |
Expand Down
2 changes: 1 addition & 1 deletion pkg/decoder/tagsl/v1/port150.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "time"
// +------+------+-------------------------------------------+------------------------+
// | Byte | Size | Description | Format |
// +------+------+-------------------------------------------+------------------------+
// | 0 | 2 | Buffer level | uint16 |
// | 1 | 1 | Buffer level | uint16 |
// | 2 | 1 | Status[6:2] + Moving flag[0] (moving = 1) | uint8 |
// | 3-6 | 4 | Latitude | int32, 1/1’000’000 deg |
// | 7-10 | 4 | Longitude | int32, 1/1’000’000 deg |
Expand Down

0 comments on commit 128dc63

Please sign in to comment.