-
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
3 changed files
with
85 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dpt | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// DPT_232600 represents DPT 232.600 (G) / DPT_Colour_RGB. | ||
// Colour RGB - RGB value 4x(0..100%) / U8 U8 U8 | ||
type DPT_232600 struct { | ||
Red uint8 | ||
Green uint8 | ||
Blue uint8 | ||
} | ||
|
||
func (d DPT_232600) Pack() []byte { | ||
|
||
return pack3U8(d.Red, d.Green, d.Blue) | ||
} | ||
|
||
func (d *DPT_232600) Unpack(data []byte) error { | ||
|
||
if len(data) != 4 { | ||
return ErrInvalidLength | ||
} | ||
|
||
err := unpack3U8(data, &d.Red, &d.Green, &d.Blue) | ||
|
||
if err != nil { | ||
return ErrInvalidLength | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (d DPT_232600) Unit() string { | ||
return "" | ||
} | ||
|
||
func (d DPT_232600) String() string { | ||
return fmt.Sprintf("%d %d %d", d.Red, d.Green, d.Blue) | ||
} |
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,27 @@ | ||
package dpt | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestDPT_232600(t *testing.T) { | ||
var buf []byte | ||
var dst DPT_232600 | ||
sources := []DPT_232600{ | ||
{Red: 255, Green: 96, Blue: 0}, | ||
{Red: 0, Green: 128, Blue: 128}, | ||
} | ||
|
||
for _, src := range sources { | ||
buf = src.Pack() | ||
_ = dst.Unpack(buf) | ||
|
||
if !reflect.DeepEqual(src, dst) { | ||
fmt.Printf("%+v\n", src) | ||
fmt.Printf("%+v\n", dst) | ||
t.Errorf("Value [%s] after pack/unpack for DPT_232600 differs. Original value was [%v].", dst, src) | ||
} | ||
} | ||
} |