Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
z2m
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xAAL
Code
Go
z2m
Commits
47284950
Commit
47284950
authored
9 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Initial functionnal release.
Still a lot of stuff to fix
parent
b68c2730
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
devices.go
+3
-3
3 additions, 3 deletions
devices.go
gateway.go
+1
-1
1 addition, 1 deletion
gateway.go
z2m.go
+37
-6
37 additions, 6 deletions
z2m.go
with
41 additions
and
10 deletions
devices.go
+
3
−
3
View file @
47284950
...
...
@@ -6,7 +6,7 @@ import (
"gitlab.imt-atlantique.fr/xaal/code/go/core/xaal"
)
func
setupDevice
(
dev
*
xaal
.
Device
,
bDevice
BridgeDevice
)
{
func
setupDevice
(
dev
*
xaal
.
Device
,
bDevice
*
BridgeDevice
)
{
dev
.
VendorID
=
bDevice
.
Definition
.
Vendor
dev
.
ProductID
=
bDevice
.
Definition
.
Model
dev
.
HWID
=
bDevice
.
IeeeAddress
...
...
@@ -15,7 +15,7 @@ func setupDevice(dev *xaal.Device, bDevice BridgeDevice) {
}
func
NewDevices
(
bDevice
BridgeDevice
)
{
func
NewDevices
(
bDevice
*
BridgeDevice
)
{
// TODO: Handle errors
baseAddr
,
_
:=
uuid
.
RandomBase
(
8
)
ieeeAddr
,
_
:=
hexStringToInteger
(
bDevice
.
IeeeAddress
)
...
...
@@ -32,6 +32,7 @@ func NewDevices(bDevice BridgeDevice) {
"temperature"
:
schemas
.
NewThermometer
,
"humidity"
:
schemas
.
NewHygrometer
,
"power"
:
schemas
.
NewPowermeter
,
"linkquality"
:
schemas
.
NewLinkquality
,
}
if
createDevice
,
ok
:=
deviceMap
[
expose
.
Name
];
ok
{
...
...
@@ -48,6 +49,5 @@ func NewDevices(bDevice BridgeDevice) {
bDevice
.
XAALDevice
=
append
(
bDevice
.
XAALDevice
,
dev
)
eng
.
AddDevice
(
dev
)
}
}
}
This diff is collapsed.
Click to expand it.
gateway.go
+
1
−
1
View file @
47284950
...
...
@@ -3,7 +3,7 @@ package main
import
"sync"
type
gateway
struct
{
devices
[]
BridgeDevice
devices
[]
*
BridgeDevice
}
var
instance
*
gateway
...
...
This diff is collapsed.
Click to expand it.
z2m.go
+
37
−
6
View file @
47284950
...
...
@@ -4,10 +4,12 @@ import (
"encoding/json"
"fmt"
"log"
"math"
"slices"
"sort"
"strings"
"github.com/davecgh/go-spew/spew"
MQTT
"github.com/eclipse/paho.mqtt.golang"
"gitlab.imt-atlantique.fr/xaal/code/go/core/xaal"
)
...
...
@@ -37,7 +39,6 @@ type BridgeDevice struct {
FriendlyName
string
`json:"friendly_name"`
XAALDevice
[]
*
xaal
.
Device
// Manufacturer string `json:"manufacturer"` // TODO: This is quite the same as Vendor / Model
// ModelID string `json:"model_id"`
}
type
Expose
struct
{
...
...
@@ -65,8 +66,17 @@ func parseDeviceJSON(jsonData []byte) {
gw
:=
GetGW
()
for
_
,
device
:=
range
devices
{
// TODO: filter if device already exists
gw
.
devices
=
append
(
gw
.
devices
,
device
)
newFlag
:=
false
for
known
:=
range
gw
.
devices
{
spew
.
Dump
(
known
)
// if device.FriendlyName == known.FriendlyName {
// newFlag = true
// break
// }
}
if
newFlag
{
continue
}
// Extraction des informations
fmt
.
Println
(
"Vendor:"
,
device
.
Definition
.
Vendor
)
...
...
@@ -88,7 +98,27 @@ func parseDeviceJSON(jsonData []byte) {
}
fmt
.
Printf
(
"------------------
\n\n
"
)
// spew.Dump(device)
NewDevices
(
device
)
NewDevices
(
&
device
)
// TODO: filter if device already exists
gw
.
devices
=
append
(
gw
.
devices
,
&
device
)
}
}
func
updateXAALDevice
(
bDevice
*
BridgeDevice
,
payload
map
[
string
]
interface
{})
{
log
.
Printf
(
"Updating device %s
\n
"
,
bDevice
.
FriendlyName
)
for
_
,
dev
:=
range
bDevice
.
XAALDevice
{
for
key
,
value
:=
range
payload
{
if
key
==
"contact"
&&
dev
.
DevType
==
"contact.basic"
{
dev
.
GetAttribute
(
"detected"
)
.
SetValue
(
value
)
}
if
key
==
"battery"
&&
dev
.
DevType
==
"battery.basic"
{
dev
.
GetAttribute
(
"level"
)
.
SetValue
(
value
)
}
if
key
==
"linkquality"
&&
dev
.
DevType
==
"linkquality.basic"
{
value
=
math
.
Round
(
value
.
(
float64
)
/
255
*
100
)
dev
.
GetAttribute
(
"level"
)
.
SetValue
(
value
)
}
}
}
}
...
...
@@ -97,8 +127,9 @@ func deviceHandler(device *BridgeDevice, msg MQTT.Message) {
err
:=
json
.
Unmarshal
(
msg
.
Payload
(),
&
data
)
if
err
!=
nil
{
log
.
Fatalf
(
"Erreur lors du décodage du JSON : %v"
,
err
)
}
else
{
updateXAALDevice
(
device
,
data
)
}
}
func
getDevices
(
topic
string
)
*
BridgeDevice
{
...
...
@@ -106,7 +137,7 @@ func getDevices(topic string) *BridgeDevice {
target
:=
strings
.
TrimPrefix
(
topic
,
mqttTopic
+
"/"
)
for
_
,
device
:=
range
gw
.
devices
{
if
device
.
FriendlyName
==
target
{
return
&
device
return
device
}
}
return
nil
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment