Skip to content

Commit 616d7c9

Browse files
committed
Updated DPTs, clean-up
1 parent 054a8b3 commit 616d7c9

32 files changed

+250
-42
lines changed

knx/cemi/ldata_test.go

-14
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ func makeRandBuffer(n int) []byte {
1616
return buffer
1717
}
1818

19-
/* unused!
20-
21-
func makeRandTPDUSegment() []byte {
22-
n := util.Randint64() % 256
23-
24-
buffer := make([]byte, n+2)
25-
buffer[0] = byte(n)
26-
rand.Read(buffer[1:])
27-
28-
return buffer
29-
}
30-
31-
*/
32-
3319
func makeRandLData() []byte {
3420
return bytes.Join([][]byte{
3521
makeRandInfoSegment(),

knx/describe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package knx

knx/diagnostic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
// Described in 03_08_07 KNXnetIP Remote Configuration and Diagnosis v01.01.02 AS.pdf

knx/dpt/formats.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2+
// Copyright 2024 Martin Müller.
23
// Licensed under the MIT license which can be found in the LICENSE file.
34

45
package dpt

knx/dpt/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type DatapointValue interface {
1717
Unpack(data []byte) error
1818
}
1919

20-
// DatapointMeta gives meta information about a datapoint.
20+
// DatapointMeta gives meta information about a datapoint
2121
type DatapointMeta interface {
2222
// Unit returns the unit of this datapoint type or empty string if it doesn't have a unit.
2323
Unit() string

knx/dpt/types_10.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_10_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_11.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_11_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_12.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_12_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package dpt

knx/dpt/types_13_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_14_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_16.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_16_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_17.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
type DPT_17001 uint8
1212

1313
func (d DPT_17001) Pack() []byte {
14-
if d > 63 {
15-
return packU8(uint8(63))
14+
if d.IsValid() {
15+
return packU8(d)
1616
} else {
17-
return packU8(uint8(d))
17+
return packU8(uint8(63))
1818
}
1919
}
2020

@@ -38,6 +38,10 @@ func (d DPT_17001) Unit() string {
3838
return ""
3939
}
4040

41+
func (d DPT_17001) IsValid() bool {
42+
return d <= 0x3F
43+
}
44+
4145
func (d DPT_17001) String() string {
4246
return fmt.Sprintf("%d", uint8(d))
4347
}

knx/dpt/types_18.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_18_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2017 Ole Krüger.
2-
// Copyright 2022 Martin Müller.
2+
// Copyright 2024 Martin Müller.
33
// Licensed under the MIT license which can be found in the LICENSE file.
44

55
package dpt

knx/dpt/types_19.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package dpt

knx/dpt/types_19_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package dpt

knx/dpt/types_2.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package dpt

knx/dpt/types_21.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package dpt

knx/dpt/types_242.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package dpt
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
// DPT_242600 represents DPT 242.600 (DPT_Colour_xyY)
8+
// Colour xyY - x: 0-1 (= 0 - 65535) y: 0-1 (= 0 - 65535)
9+
// U16 U16 U8 r6B2
10+
type DPT_242600 struct {
11+
X uint16
12+
Y uint16
13+
YBrightness uint8
14+
ColorValid bool
15+
BrightnessValid bool
16+
}
17+
18+
func (d DPT_242600) Pack() []byte {
19+
validBits := packB2(d.ColorValid, d.BrightnessValid)
20+
21+
x := packU16(uint16(d.X))
22+
y := packU16(uint16(d.Y))
23+
24+
return []byte{0, x[1], x[2], y[1], y[2], d.YBrightness, validBits[0]}
25+
}
26+
27+
func (d *DPT_242600) Unpack(data []byte) error {
28+
if len(data) != 7 {
29+
return ErrInvalidLength
30+
}
31+
32+
var colorValid, brightnessValid bool
33+
34+
err := unpackB2([]byte{data[6]}, &colorValid, &brightnessValid)
35+
36+
if err != nil {
37+
return ErrInvalidData
38+
}
39+
40+
var x, y uint16
41+
42+
xData := []byte{0}
43+
xData = append(xData, data[1], data[2])
44+
45+
err = unpackU16(xData, &x)
46+
47+
if err != nil {
48+
return ErrInvalidData
49+
}
50+
51+
yData := []byte{0}
52+
yData = append(yData, data[3], data[4])
53+
54+
err = unpackU16(yData, &y)
55+
56+
if err != nil {
57+
return ErrInvalidData
58+
}
59+
60+
*d = DPT_242600{
61+
X: x,
62+
Y: y,
63+
YBrightness: uint8(data[5]),
64+
ColorValid: colorValid,
65+
BrightnessValid: brightnessValid,
66+
}
67+
68+
return nil
69+
}
70+
71+
func (d DPT_242600) Unit() string {
72+
return ""
73+
}
74+
75+
func (d DPT_242600) String() string {
76+
return fmt.Sprintf("x: %d y: %d Y: %d ColorValid: %t, BrightnessValid: %t", d.X, d.Y, d.YBrightness, d.ColorValid, d.BrightnessValid)
77+
}

knx/dpt/types_242_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package dpt
2+
3+
import (
4+
"fmt"
5+
"reflect"
6+
"testing"
7+
)
8+
9+
func TestDPT_242600(t *testing.T) {
10+
var buf []byte
11+
var dst DPT_242600
12+
sources := []DPT_242600{
13+
{X: 0, Y: 0, YBrightness: 1, ColorValid: true, BrightnessValid: true},
14+
{X: 65535, Y: 1, YBrightness: 255, ColorValid: true, BrightnessValid: true},
15+
{X: 32767, Y: 32767, YBrightness: 127, ColorValid: true, BrightnessValid: true},
16+
{X: 6553, Y: 58981, YBrightness: 127, ColorValid: true, BrightnessValid: true},
17+
}
18+
19+
for _, src := range sources {
20+
buf = src.Pack()
21+
err := dst.Unpack(buf)
22+
23+
if err != nil {
24+
t.Error(err)
25+
}
26+
27+
if !reflect.DeepEqual(src, dst) {
28+
fmt.Printf("%+v\n", src)
29+
fmt.Printf("%+v\n", dst)
30+
t.Errorf("Value [%s] after pack/unpack for DPT_242600 differs. Original value was [%v]!", dst, src)
31+
}
32+
}
33+
}

knx/dpt/types_251_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2024 Martin Müller.
2+
// Licensed under the MIT license which can be found in the LICENSE file.
3+
14
package dpt
25

36
import (

knx/dpt/types_2_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package dpt

knx/dpt/types_3.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package dpt

knx/dpt/types_3_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package dpt

knx/dpt/types_6.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Martin Müller.
1+
// Copyright 2024 Martin Müller.
22
// Licensed under the MIT license which can be found in the LICENSE file.
33

44
package dpt

0 commit comments

Comments
 (0)