Skip to content
Snippets Groups Projects
Commit 8244b42d authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Added devices counter

parent ef078cdd
No related branches found
No related tags found
No related merge requests found
package main
import (
"log/slog"
"time"
"github.com/davecgh/go-spew/spew"
"gitlab.imt-atlantique.fr/xaal/code/go/core/uuid"
"gitlab.imt-atlantique.fr/xaal/code/go/core/xaal"
)
type Counter struct {
Type string
Until time.Time
}
var (
devices map[uuid.UUID]Counter
)
func handleMessage(msg *xaal.Message) {
if msg.IsAlive() {
timeout := msg.Body["timeout"]
if timeout == nil {
return
}
slog.Debug("Received alive message from", "timeout", timeout)
devices[msg.Source] = Counter{Type: msg.DevType, Until: time.Now()}
// msg.Dump()
// fmt.Println()
}
}
func init() {
xaal.SetupLogger(slog.LevelDebug)
}
func main() {
eng := xaal.NewEngine()
eng.DisableMessageFilter()
devices = make(map[uuid.UUID]Counter)
eng.Subscribe(handleMessage)
eng.Run()
spew.Dump(devices)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment