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

Refactoring in progress

Moving stuff to Gateway once again..
parent b13929ad
No related branches found
No related tags found
No related merge requests found
......@@ -7,15 +7,14 @@ import (
"sync"
MQTT "github.com/eclipse/paho.mqtt.golang"
"gitlab.imt-atlantique.fr/xaal/code/go/core/uuid"
"gitlab.imt-atlantique.fr/xaal/code/go/core/xaal"
)
type Gateway struct {
client MQTT.Client
engine *xaal.Engine
devices map[string]*Z2MDevice
baseAddr uuid.UUID
client MQTT.Client
engine *xaal.Engine
devices map[string]*Z2MDevice
config *Config
}
var (
......@@ -32,7 +31,7 @@ func GetGW() *Gateway {
func NewGW(cfg *Config, eng *xaal.Engine) *Gateway {
gw := GetGW()
gw.baseAddr = cfg.baseAddr
gw.config = cfg
gw.client = mqttSetup(cfg, gw.mqttPublishHander)
// NOTE: Wondering if we can setup engine before
gw.engine = eng
......@@ -52,7 +51,7 @@ func (gw *Gateway) GetZDevices() map[string]*Z2MDevice {
}
func (gw *Gateway) GetZDeviceByTopic(topic string) *Z2MDevice {
name := topic[len(mqttTopic+"/"):]
name := topic[len(gw.config.topic+"/"):]
return gw.GetZDevice(name)
}
......@@ -66,7 +65,7 @@ func (gw *Gateway) mqttPublishHander(client MQTT.Client, msg MQTT.Message) {
}
// slog.Debug("Received message on", "topic", msg.Topic())
// Is it devices definitions ?
if msg.Topic() == mqttTopic+"/bridge/devices" {
if msg.Topic() == gw.config.topic+"/bridge/devices" {
gw.jsonParseDevices(msg.Payload())
} else {
dev := gw.GetZDeviceByTopic(msg.Topic())
......
......@@ -100,7 +100,7 @@ func (zDev *Z2MDevice) HandleMessage(msg MQTT.Message) {
// creates new xAAL devices from a bridge device
func (zDev *Z2MDevice) setupXAALDevices(gw *Gateway) {
// TODO: Handle errors
baseAddr := gw.baseAddr
baseAddr := gw.config.baseAddr
ieeeAddr, _ := hexStringToInteger(zDev.IeeeAddress)
baseAddr, _ = baseAddr.Add(int64(ieeeAddr))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment