etri-smartfarm-poc-controll.../examples/main.go

52 lines
995 B
Go
Raw Permalink Normal View History

2021-12-10 01:14:34 +00:00
package main
import (
2021-12-10 06:45:28 +00:00
"bufio"
2021-12-10 01:14:34 +00:00
"fmt"
2021-12-10 06:45:28 +00:00
"os"
"strconv"
"strings"
2021-12-10 01:14:34 +00:00
manager "git.godopu.net/lab/etri-smartfarm-poc-controller-serial"
)
func main() {
2021-12-10 08:07:20 +00:00
manager.AddRecvListener(manager.NewEventHandler(func(e manager.Event) {
fmt.Println("RECV: ", e.Params())
}))
2021-12-10 10:26:13 +00:00
manager.AddRegisterHandleFunc(func(e manager.Event) {
param := e.Params()
fmt.Println(param["uuid"].(string), " is registered!! ] ", param["sname"])
2021-12-10 08:07:20 +00:00
})
2021-12-10 01:14:34 +00:00
2021-12-10 10:26:13 +00:00
manager.AddRemoveHandleFunc(func(e manager.Event) {
param := e.Params()
fmt.Println(param["uuid"].(string), " is removed!!")
2021-12-10 08:07:20 +00:00
})
2021-12-12 01:08:11 +00:00
2021-12-10 08:07:20 +00:00
go manager.Run()
defer manager.Close()
2021-12-12 01:08:11 +00:00
param := map[string]interface{}{}
2021-12-10 06:45:28 +00:00
for {
fmt.Print("> ")
reader := bufio.NewReader(os.Stdin)
b, _, _ := reader.ReadLine()
cmd := string(b)
fmt.Println("cmd: ", cmd)
if cmd == "exit" {
return
}
2021-12-10 01:14:34 +00:00
2021-12-10 06:45:28 +00:00
tkns := strings.Split(cmd, " ")
key := tkns[0]
value, err := strconv.Atoi(tkns[2])
if err != nil {
continue
}
2021-12-12 01:08:11 +00:00
param[tkns[1]] = value
2021-12-10 06:45:28 +00:00
manager.Sync(key, param)
2021-12-10 01:14:34 +00:00
}
}