-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for dpt 8.xxx (attempt 2) #93
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,179 @@ | ||
// Copyright 2017 Ole Krüger. | ||
// Licensed under the MIT license which can be found in the LICENSE file. | ||
|
||
package dpt | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// DPT_8001 represents DPT 8.001 / Counter. | ||
type DPT_8001 int16 | ||
|
||
func (d DPT_8001) Pack() []byte { | ||
return packV16(int16(d)) | ||
} | ||
|
||
func (d *DPT_8001) Unpack(data []byte) error { | ||
return unpackV16(data, (*int16)(d)) | ||
} | ||
|
||
func (d DPT_8001) Unit() string { | ||
return "pulses" | ||
} | ||
|
||
func (d DPT_8001) String() string { | ||
return fmt.Sprintf("%d pulses", int16(d)) | ||
} | ||
|
||
// DPT_8002 represents DPT 8.002 / delta time ms. | ||
type DPT_8002 int16 | ||
|
||
func (d DPT_8002) Pack() []byte { | ||
return packV16(int16(d)) | ||
} | ||
|
||
func (d *DPT_8002) Unpack(data []byte) error { | ||
return unpackV16(data, (*int16)(d)) | ||
} | ||
|
||
func (d DPT_8002) Unit() string { | ||
return "ms" | ||
} | ||
|
||
func (d DPT_8002) String() string { | ||
return fmt.Sprintf("%d ms", int16(d)) | ||
} | ||
|
||
// DPT_8003 represents DPT 8.003 / delta time ms (range -327.68 s ... 327.67 s) | ||
type DPT_8003 int32 | ||
|
||
func (d DPT_8003) Pack() []byte { | ||
return packV32AsV16(int32(d), 10) | ||
} | ||
|
||
func (d *DPT_8003) Unpack(data []byte) error { | ||
return unpackV16AsV32(data, (*int32)(d), 10) | ||
} | ||
|
||
func (d DPT_8003) Unit() string { | ||
return "ms" | ||
} | ||
|
||
func (d DPT_8003) String() string { | ||
return fmt.Sprintf("%d ms", int32(d)) | ||
} | ||
|
||
// DPT_8004 represents DPT 8.004 / delta time ms (range -3276.8 s ... 3276.7 s) | ||
type DPT_8004 int32 | ||
|
||
func (d DPT_8004) Pack() []byte { | ||
return packV32AsV16(int32(d), 100) | ||
} | ||
|
||
func (d *DPT_8004) Unpack(data []byte) error { | ||
return unpackV16AsV32(data, (*int32)(d), 100) | ||
} | ||
|
||
func (d DPT_8004) Unit() string { | ||
return "ms" | ||
} | ||
|
||
func (d DPT_8004) String() string { | ||
return fmt.Sprintf("%d ms", int32(d)) | ||
} | ||
|
||
// DPT_8005 represents DPT 8.005 / delta time seconds | ||
type DPT_8005 int16 | ||
|
||
func (d DPT_8005) Pack() []byte { | ||
return packV16(int16(d)) | ||
} | ||
|
||
func (d *DPT_8005) Unpack(data []byte) error { | ||
return unpackV16(data, (*int16)(d)) | ||
} | ||
|
||
func (d DPT_8005) Unit() string { | ||
return "s" | ||
} | ||
|
||
func (d DPT_8005) String() string { | ||
return fmt.Sprintf("%d s", int16(d)) | ||
} | ||
|
||
// DPT_8006 represents DPT 8.005 / delta time minutes | ||
type DPT_8006 int16 | ||
|
||
func (d DPT_8006) Pack() []byte { | ||
return packV16(int16(d)) | ||
} | ||
|
||
func (d *DPT_8006) Unpack(data []byte) error { | ||
return unpackV16(data, (*int16)(d)) | ||
} | ||
|
||
func (d DPT_8006) Unit() string { | ||
return "min" | ||
} | ||
|
||
func (d DPT_8006) String() string { | ||
return fmt.Sprintf("%d min", int16(d)) | ||
} | ||
|
||
// DPT_8007 represents DPT 8.007 / delta time hours | ||
type DPT_8007 int16 | ||
|
||
func (d DPT_8007) Pack() []byte { | ||
return packV16(int16(d)) | ||
} | ||
|
||
func (d *DPT_8007) Unpack(data []byte) error { | ||
return unpackV16(data, (*int16)(d)) | ||
} | ||
|
||
func (d DPT_8007) Unit() string { | ||
return "h" | ||
} | ||
|
||
func (d DPT_8007) String() string { | ||
return fmt.Sprintf("%d h", int16(d)) | ||
} | ||
|
||
// DPT_8010 represents DPT 8.010 / percentage difference | ||
type DPT_8010 float32 | ||
|
||
func (d DPT_8010) Pack() []byte { | ||
return packFloat32AsV16(float32(d), 0.01) | ||
} | ||
|
||
func (d *DPT_8010) Unpack(data []byte) error { | ||
return unpackV16AsFloat32(data, (*float32)(d), 0.01) | ||
} | ||
|
||
func (d DPT_8010) Unit() string { | ||
return "%" | ||
} | ||
|
||
func (d DPT_8010) String() string { | ||
return fmt.Sprintf("%f %%", float32(d)) | ||
} | ||
|
||
// DPT_8011 represents DPT 8.011 / Rotation angle °. | ||
type DPT_8011 int16 | ||
|
||
func (d DPT_8011) Pack() []byte { | ||
return packV16(int16(d)) | ||
} | ||
|
||
func (d *DPT_8011) Unpack(data []byte) error { | ||
return unpackV16(data, (*int16)(d)) | ||
} | ||
|
||
func (d DPT_8011) Unit() string { | ||
return "°" | ||
} | ||
|
||
func (d DPT_8011) String() string { | ||
return fmt.Sprintf("%d °", int16(d)) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no checks in place here to ensure the value provided (
i
) is within valid bounds. I.e. withinmath.MinInt16 * resolution ... math.MaxInt16 * resolution
.However, the pack functions does not offer an
error
as return value, and changing this would break the interface and cause ripple effects.