-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
250 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package dpt | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// DPT_242600 represents DPT 242.600 (DPT_Colour_xyY) | ||
// Colour xyY - x: 0-1 (= 0 - 65535) y: 0-1 (= 0 - 65535) | ||
// U16 U16 U8 r6B2 | ||
type DPT_242600 struct { | ||
X uint16 | ||
Y uint16 | ||
YBrightness uint8 | ||
ColorValid bool | ||
BrightnessValid bool | ||
} | ||
|
||
func (d DPT_242600) Pack() []byte { | ||
validBits := packB2(d.ColorValid, d.BrightnessValid) | ||
|
||
x := packU16(uint16(d.X)) | ||
y := packU16(uint16(d.Y)) | ||
|
||
return []byte{0, x[1], x[2], y[1], y[2], d.YBrightness, validBits[0]} | ||
} | ||
|
||
func (d *DPT_242600) Unpack(data []byte) error { | ||
if len(data) != 7 { | ||
return ErrInvalidLength | ||
} | ||
|
||
var colorValid, brightnessValid bool | ||
|
||
err := unpackB2([]byte{data[6]}, &colorValid, &brightnessValid) | ||
|
||
if err != nil { | ||
return ErrInvalidData | ||
} | ||
|
||
var x, y uint16 | ||
|
||
xData := []byte{0} | ||
xData = append(xData, data[1], data[2]) | ||
|
||
err = unpackU16(xData, &x) | ||
|
||
if err != nil { | ||
return ErrInvalidData | ||
} | ||
|
||
yData := []byte{0} | ||
yData = append(yData, data[3], data[4]) | ||
|
||
err = unpackU16(yData, &y) | ||
|
||
if err != nil { | ||
return ErrInvalidData | ||
} | ||
|
||
*d = DPT_242600{ | ||
X: x, | ||
Y: y, | ||
YBrightness: uint8(data[5]), | ||
ColorValid: colorValid, | ||
BrightnessValid: brightnessValid, | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (d DPT_242600) Unit() string { | ||
return "" | ||
} | ||
|
||
func (d DPT_242600) String() string { | ||
return fmt.Sprintf("x: %d y: %d Y: %d ColorValid: %t, BrightnessValid: %t", d.X, d.Y, d.YBrightness, d.ColorValid, d.BrightnessValid) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dpt | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestDPT_242600(t *testing.T) { | ||
var buf []byte | ||
var dst DPT_242600 | ||
sources := []DPT_242600{ | ||
{X: 0, Y: 0, YBrightness: 1, ColorValid: true, BrightnessValid: true}, | ||
{X: 65535, Y: 1, YBrightness: 255, ColorValid: true, BrightnessValid: true}, | ||
{X: 32767, Y: 32767, YBrightness: 127, ColorValid: true, BrightnessValid: true}, | ||
{X: 6553, Y: 58981, YBrightness: 127, ColorValid: true, BrightnessValid: true}, | ||
} | ||
|
||
for _, src := range sources { | ||
buf = src.Pack() | ||
err := dst.Unpack(buf) | ||
|
||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if !reflect.DeepEqual(src, dst) { | ||
fmt.Printf("%+v\n", src) | ||
fmt.Printf("%+v\n", dst) | ||
t.Errorf("Value [%s] after pack/unpack for DPT_242600 differs. Original value was [%v]!", dst, src) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.