Skip to content

Commit

Permalink
Added (untested) temperature register for newer devices
Browse files Browse the repository at this point in the history
  • Loading branch information
pvainio committed Apr 26, 2024
1 parent d54c172 commit 1c05bda
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/pvainio/vallox-rs485

go 1.20
go 1.22

require github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07

require golang.org/x/sys v0.6.0 // indirect
require golang.org/x/sys v0.19.0 // indirect
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
45 changes: 29 additions & 16 deletions vallox.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const (
TempOutgoingInside byte = 0x5a
TempIncomingInside byte = 0x5b
TempOutgoingOutside byte = 0x5c

// Registers for newer protocol
TempIncomingOutsideNew byte = 0x32
TempOutgoingInsideNew byte = 0x34
TempIncomingInsideNew byte = 0x35
TempOutgoingOutsideNew byte = 0x33
)

type Event struct {
Expand Down Expand Up @@ -103,8 +109,8 @@ func Open(cfg Config) (*Vallox, error) {
running: true,
buffer: bufio.NewReadWriter(bufio.NewReader(buffer), bufio.NewWriter(buffer)),
remoteClientId: cfg.RemoteClientId,
in: make(chan Event, 15),
out: make(chan valloxPackage, 15),
in: make(chan Event, 50),
out: make(chan valloxPackage, 50),
writeAllowed: cfg.EnableWrite,
logDebug: cfg.LogDebug,
}
Expand Down Expand Up @@ -182,6 +188,7 @@ func handleOutgoing(vallox *Vallox) {

now := time.Now()
if vallox.lastActivity.IsZero() || now.UnixMilli()-vallox.lastActivity.UnixMilli() < 50 {
updateLastActivity(vallox)
vallox.logDebug.Printf("delay outgoing to %x %x = %x, lastActivity %v now %v, diff %d ms",
pkg.Destination, pkg.Register, pkg.Value, vallox.lastActivity, now, now.UnixMilli()-vallox.lastActivity.UnixMilli())
time.Sleep(time.Millisecond * 50)
Expand Down Expand Up @@ -255,28 +262,34 @@ func handleBuffer(vallox *Vallox) {
}

func handlePackage(pkg *valloxPackage, vallox *Vallox) {
vallox.in <- *event(pkg, vallox)
vallox.in <- *event(pkg)
}

type mapFn func(byte) int8

var registerMap = map[byte]mapFn{
FanSpeed: valueToSpeed,
TempIncomingInside: valueToTemp,
TempIncomingOutside: valueToTemp,
TempOutgoingInside: valueToTemp,
TempOutgoingOutside: valueToTemp,
TempIncomingInsideNew: valueToTemp,
TempIncomingOutsideNew: valueToTemp,
TempOutgoingInsideNew: valueToTemp,
TempOutgoingOutsideNew: valueToTemp,
}

func event(pkg *valloxPackage, vallox *Vallox) *Event {
func event(pkg *valloxPackage) *Event {
event := new(Event)
event.Time = time.Now()
event.Source = pkg.Source
event.Destination = pkg.Destination
event.Register = pkg.Register
event.RawValue = pkg.Value
switch pkg.Register {
case FanSpeed:
event.Value = int16(valueToSpeed(pkg.Value))
case TempIncomingInside:
event.Value = int16(valueToTemp(pkg.Value))
case TempIncomingOutside:
event.Value = int16(valueToTemp(pkg.Value))
case TempOutgoingInside:
event.Value = int16(valueToTemp(pkg.Value))
case TempOutgoingOutside:
event.Value = int16(valueToTemp(pkg.Value))
default:
mapFn, ok := registerMap[pkg.Register]
if ok {
event.Value = int16(mapFn(pkg.Value))
} else {
event.Value = int16(pkg.Value)
}
return event
Expand Down

0 comments on commit 1c05bda

Please sign in to comment.