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

Only prefix used right now

parent 0c92daf5
Branches
Tags
No related merge requests found
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/davecgh/go-spew/spew"
"gitlab.imt-atlantique.fr/xaal/code/go/core/uuid" "gitlab.imt-atlantique.fr/xaal/code/go/core/uuid"
"gitlab.imt-atlantique.fr/xaal/code/go/core/xaal" "gitlab.imt-atlantique.fr/xaal/code/go/core/xaal"
) )
...@@ -31,23 +32,29 @@ func getCounter(msg *xaal.Message) *Counter { ...@@ -31,23 +32,29 @@ func getCounter(msg *xaal.Message) *Counter {
return nil return nil
} }
func addCounter(msg *xaal.Message) { func addCounter(msg *xaal.Message, prefix string) *Counter {
cnt := Counter{ cnt := Counter{
Type: msg.DevType, Type: prefix,
} }
devices[msg.Source] = cnt devices[msg.Source] = cnt
return &cnt
} }
func filterCounter(msg *xaal.Message) bool { func filterCounter(msg *xaal.Message) string {
// let's split the msg.DevType on points and keep the first part // let's split the msg.DevType on points and keep the first part
tmp := strings.Split(msg.DevType, ".") tmp := strings.Split(msg.DevType, ".")
prefix := tmp[0] prefix := tmp[0]
_, found := deviceIcons[prefix] _, found := deviceIcons[prefix]
return found if !found {
return ""
}
return prefix
} }
func handleMessage(msg *xaal.Message) { func handleMessage(msg *xaal.Message) {
if filterCounter(msg) == false { // t's filter the messages we are interested in
prefix := filterCounter(msg)
if prefix == "" {
return return
} }
...@@ -55,11 +62,10 @@ func handleMessage(msg *xaal.Message) { ...@@ -55,11 +62,10 @@ func handleMessage(msg *xaal.Message) {
if msg.IsAlive() { if msg.IsAlive() {
if timeout, ok := msg.Body["timeout"].(uint64); ok { if timeout, ok := msg.Body["timeout"].(uint64); ok {
cnt := getCounter(msg) cnt := getCounter(msg)
if cnt != nil { if cnt == nil {
cnt.Until = time.Now().Add(time.Duration(timeout) * time.Second) cnt = addCounter(msg, prefix)
} else {
addCounter(msg)
} }
cnt.Until = time.Now().Add(time.Duration(timeout) * time.Second)
} }
} }
} }
...@@ -77,4 +83,5 @@ func main() { ...@@ -77,4 +83,5 @@ func main() {
eng.Run() eng.Run()
// Let's count the devices // Let's count the devices
slog.Info("Devices", "count", len(devices)) slog.Info("Devices", "count", len(devices))
spew.Dump(devices)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment