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
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import (
"strings"
"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"
)
......@@ -31,23 +32,29 @@ func getCounter(msg *xaal.Message) *Counter {
return nil
}
func addCounter(msg *xaal.Message) {
func addCounter(msg *xaal.Message, prefix string) *Counter {
cnt := Counter{
Type: msg.DevType,
Type: prefix,
}
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
tmp := strings.Split(msg.DevType, ".")
prefix := tmp[0]
_, found := deviceIcons[prefix]
return found
if !found {
return ""
}
return prefix
}
func handleMessage(msg *xaal.Message) {
if filterCounter(msg) == false {
// t's filter the messages we are interested in
prefix := filterCounter(msg)
if prefix == "" {
return
}
......@@ -55,11 +62,10 @@ func handleMessage(msg *xaal.Message) {
if msg.IsAlive() {
if timeout, ok := msg.Body["timeout"].(uint64); ok {
cnt := getCounter(msg)
if cnt != nil {
cnt.Until = time.Now().Add(time.Duration(timeout) * time.Second)
} else {
addCounter(msg)
if cnt == nil {
cnt = addCounter(msg, prefix)
}
cnt.Until = time.Now().Add(time.Duration(timeout) * time.Second)
}
}
}
......@@ -77,4 +83,5 @@ func main() {
eng.Run()
// Let's count the 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