fix(adapter): usp handler online status | closes #248
This commit is contained in:
parent
7e5b9a682a
commit
28a0e3e491
|
|
@ -5,6 +5,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/db"
|
"github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/db"
|
||||||
|
"github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/usp"
|
||||||
|
"github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/usp/usp_msg"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handler) HandleDeviceStatus(device, subject string, data []byte, mtp string, ack func()) {
|
func (h *Handler) HandleDeviceStatus(device, subject string, data []byte, mtp string, ack func()) {
|
||||||
|
|
@ -15,6 +18,8 @@ func (h *Handler) HandleDeviceStatus(device, subject string, data []byte, mtp st
|
||||||
}
|
}
|
||||||
|
|
||||||
switch payload {
|
switch payload {
|
||||||
|
case ONLINE:
|
||||||
|
h.deviceOnline(device, mtp)
|
||||||
case OFFLINE:
|
case OFFLINE:
|
||||||
h.deviceOffline(device, mtp)
|
h.deviceOffline(device, mtp)
|
||||||
default:
|
default:
|
||||||
|
|
@ -22,6 +27,35 @@ func (h *Handler) HandleDeviceStatus(device, subject string, data []byte, mtp st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) deviceOnline(device, mtp string) {
|
||||||
|
|
||||||
|
log.Printf("Device %s is online", device)
|
||||||
|
|
||||||
|
msg := usp.NewGetMsg(usp_msg.Get{
|
||||||
|
ParamPaths: []string{
|
||||||
|
"Device.DeviceInfo.Manufacturer",
|
||||||
|
"Device.DeviceInfo.ModelName",
|
||||||
|
"Device.DeviceInfo.SoftwareVersion",
|
||||||
|
"Device.DeviceInfo.SerialNumber",
|
||||||
|
"Device.DeviceInfo.ProductClass",
|
||||||
|
},
|
||||||
|
MaxDepth: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
payload, _ := proto.Marshal(&msg)
|
||||||
|
record := usp.NewUspRecord(payload, device, h.cid)
|
||||||
|
|
||||||
|
tr369Message, err := proto.Marshal(&record)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Failed to encode tr369 record:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.nc.Publish(mtp+"-adapter.usp.v1."+device+".info", tr369Message)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to publish online device message: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) deviceOffline(device, mtp string) {
|
func (h *Handler) deviceOffline(device, mtp string) {
|
||||||
log.Printf("Device %s is offline", device)
|
log.Printf("Device %s is offline", device)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user