-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Decoder support for TEKTELIC Kona All-in-One Home Sensor
- Update `pkg/decode`, unit tests, and decoder unit and integration tests. - Sync `vendor/` for updated dependencies. - All test variations pass.
- Loading branch information
Showing
48 changed files
with
1,386 additions
and
450 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package decode | ||
|
||
import ( | ||
"math" | ||
) | ||
|
||
// CToF converts a temperature from Celsius to Fahrenheit, rounded to one | ||
// decimal digit. | ||
func CToF(tempC float64) float64 { | ||
tempF := tempC*9/5 + 32 | ||
|
||
return math.Round(tempF*10) / 10 | ||
} |
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 |
---|---|---|
@@ -1,14 +1,2 @@ | ||
// Package globalsat provides parse functions for GlobalSat sensors. | ||
package globalsat | ||
|
||
import ( | ||
"math" | ||
) | ||
|
||
// cToF converts a temperature from Celsius to Fahrenheit, rounded to one | ||
// decimal digit. | ||
func cToF(tempC float64) float64 { | ||
tempF := tempC*9/5 + 32 | ||
|
||
return math.Round(tempF*10) / 10 | ||
} |
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,101 @@ | ||
package tektelic | ||
|
||
import ( | ||
"github.com/thingspect/atlas/pkg/decode" | ||
) | ||
|
||
const ( | ||
identChanMotion = 0x0a | ||
identChanTempC = 0x03 | ||
identChanHumidity = 0x04 | ||
identChanBatteryV = 0x00 | ||
) | ||
|
||
// chanMotion parses a Motion data channel from a []byte according to the spec | ||
// and returns the points, the remaining bytes, and an error value. | ||
func chanMotion(body []byte) ([]*decode.Point, []byte, error) { | ||
// Motion data channel must be at least 3 bytes. | ||
if len(body) < 3 { | ||
return nil, nil, decode.ErrFormat("chanMotion", "bad length", body) | ||
} | ||
|
||
if body[0] != identChanMotion { | ||
return nil, nil, decode.ErrFormat("chanMotion", "bad identifier", body) | ||
} | ||
|
||
// Parse motion. | ||
motion, rem, err := typeDigital(body) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return []*decode.Point{{Attr: "motion", Value: motion}}, rem, nil | ||
} | ||
|
||
// chanTempC parses a Temperature data channel from a []byte according to the | ||
// spec and returns the points, the remaining bytes, and an error value. | ||
func chanTempC(body []byte) ([]*decode.Point, []byte, error) { | ||
// Temperature data channel must be at least 4 bytes. | ||
if len(body) < 4 { | ||
return nil, nil, decode.ErrFormat("chanTempC", "bad length", body) | ||
} | ||
|
||
if body[0] != identChanTempC { | ||
return nil, nil, decode.ErrFormat("chanTempC", "bad identifier", body) | ||
} | ||
|
||
// Parse temperature. | ||
tempC, rem, err := typeTempC(body) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return []*decode.Point{ | ||
{Attr: "temp_c", Value: tempC}, | ||
{Attr: "temp_f", Value: decode.CToF(tempC)}, | ||
}, rem, nil | ||
} | ||
|
||
// chanHumidity parses a Humidity data channel from a []byte according to the | ||
// spec and returns the points, the remaining bytes, and an error value. | ||
func chanHumidity(body []byte) ([]*decode.Point, []byte, error) { | ||
// Humidity data channel must be at least 3 bytes. | ||
if len(body) < 3 { | ||
return nil, nil, decode.ErrFormat("chanHumidity", "bad length", body) | ||
} | ||
|
||
if body[0] != identChanHumidity { | ||
return nil, nil, decode.ErrFormat("chanHumidity", "bad identifier", | ||
body) | ||
} | ||
|
||
// Parse humidity. | ||
humidity, rem, err := typeHumidity(body) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return []*decode.Point{{Attr: "humidity_pct", Value: humidity}}, rem, nil | ||
} | ||
|
||
// chanBatteryV parses a Battery (V) data channel from a []byte according to the | ||
// spec and returns the points, the remaining bytes, and an error value. | ||
func chanBatteryV(body []byte) ([]*decode.Point, []byte, error) { | ||
// Battery (V) data channel must be at least 4 bytes. | ||
if len(body) < 4 { | ||
return nil, nil, decode.ErrFormat("chanBatteryV", "bad length", body) | ||
} | ||
|
||
if body[0] != identChanBatteryV { | ||
return nil, nil, decode.ErrFormat("chanBatteryV", "bad identifier", | ||
body) | ||
} | ||
|
||
// Parse voltage. | ||
voltage, rem, err := typeAnalogV(body) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return []*decode.Point{{Attr: "battery_v", Value: voltage}}, rem, nil | ||
} |
Oops, something went wrong.