Browse Source

处理子设备

lijian 2 years ago
parent
commit
e3445b25ab
2 changed files with 21 additions and 5 deletions
  1. 2 0
      pkg/klink/klink.go
  2. 19 5
      services/mqttaccess/mqtt_provider.go

+ 2 - 0
pkg/klink/klink.go

@@ -18,6 +18,7 @@ type DevLogin struct {
 	Action      string `json:"action"`
 	MsgId       int64  `json:"msgId"`
 	DeviceCode  string `json:"deviceCode"`
+	Pk          string `json:"pk"`
 	SubDeviceId string `json:"subDeviceId"`
 	Timestamp   int64  `json:"timestamp"`
 }
@@ -25,6 +26,7 @@ type DevLogin struct {
 // DevLogout 子设备下线
 type DevLogout struct {
 	Action      string `json:"action"`
+	Pk          string `json:"pk"`
 	MsgId       int64  `json:"msgId"`
 	DeviceCode  string `json:"deviceCode"`
 	SubDeviceId string `json:"subDeviceId"`

+ 19 - 5
services/mqttaccess/mqtt_provider.go

@@ -124,12 +124,26 @@ func processReportStatus(deviceid, vendorId string, message *gjson.Json) {
 	}
 }
 
-// TODO 子设备上线
-func processDevLogin(deviceId string) {
-
+func processDevLogin(subDeviceId string) error {
+	reply := rpcs.ReplyGetOnline{}
+	var args rpcs.ArgsGetOnline
+	args.Id = subDeviceId
+	err := server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.GetOnline", args, &reply)
+	if err != nil {
+		server.Log.Errorf("device online error. args: %v, error: %v", args, err)
+	}
+	return err
 }
 
-// TODO 子设备下线
-func processDevLogout(deviceId string) {
+func processDevLogout(subDeviceId string) error {
+	args := rpcs.ArgsGetOffline{
+		Id: subDeviceId,
+	}
+	reply := rpcs.ReplyGetOffline{}
+	err := server.RPCCallByName(nil, rpcs.DeviceManagerName, "DeviceManager.GetOffline", args, &reply)
+	if err != nil {
+		server.Log.Errorf("device offline error. deviceid: %v, error: %v", subDeviceId, err)
+	}
 
+	return err
 }