Ver Fonte

Merge branch 'v2' of http://192.168.0.224:3000/yongxu/sparrow into v2

lijian há 1 ano atrás
pai
commit
27ce244721

+ 1 - 0
pkg/rpcs/access.go

@@ -34,4 +34,5 @@ type ArgsDeviceUpgrade struct {
 	Url         string
 	Md5         string
 	Version     string
+	FileSize    int64
 }

+ 2 - 1
services/apiprovider/actions.go

@@ -94,7 +94,7 @@ func GetDeviceInfoByIdentifier(urlparams martini.Params, r render.Render) {
 	server.Log.Printf("ACTION GetDeviceInfoByIdentifier, identifier:: %v", identifier)
 	device := &models.Device{}
 
-	err := server.RPCCallByName(context.Background(), rpcs.RegistryServerName, "Registry.FindDeviceByIdentifier", identifier, device)
+	err := server.RPCCallByName(context.Background(), rpcs.RegistryServerName, "Registry.FindDeviceByIdentifier2", identifier, device)
 	if err != nil {
 		r.JSON(http.StatusOK, renderError(ErrDeviceNotFound, err))
 		return
@@ -161,6 +161,7 @@ func DeviceUpgrade(device *models.Device, urlparams martini.Params, req *http.Re
 	args.Url = param.Url
 	args.Md5 = param.MD5
 	args.Version = param.Version
+	args.FileSize = param.FileSize
 	var reply rpcs.ReplyEmptyResult
 	err = server.RPCCallByName(context.Background(), rpcs.MQTTAccessName, "Access.Upgrade", args, &reply)
 	if err != nil {

+ 1 - 0
services/apiprovider/request.go

@@ -12,5 +12,6 @@ type DeviceUpgradeReq struct {
 	SubDeviceId string `json:"sub_device_id"`
 	Url         string `json:"url"`
 	MD5         string `json:"md5"`
+	FileSize    int64  `json:"file_size"`
 	Version     string `json:"version"`
 }

+ 17 - 8
services/mqttaccess/access.go

@@ -80,16 +80,25 @@ func (a *Access) SendCommand(args rpcs.ArgsSendCommand, reply *rpcs.ReplySendCom
 // Upgrade 设备OTA升级指令
 func (a *Access) Upgrade(args rpcs.ArgsDeviceUpgrade, reply *rpcs.ReplyEmptyResult) error {
 	server.Log.Infof("设备OTA升级:%s, %s", args.DeviceId, args.Version)
-	cmd := &klink.DevUpgrade{
-		Action:      "devUpgrade",
-		MsgId:       0,
-		DeviceCode:  args.DeviceId,
+
+	cmd := &klink.CloudSend{
+		Action:     "cloudSend",
+		MsgId:      0,
+		DeviceCode: args.DeviceId,
+		Timestamp:  time.Now().Unix(),
+		Data: &klink.CloudSendData{
+			Cmd: "devUpgrade",
+			Params: map[string]interface{}{
+				"md5":       args.Md5,
+				"url":       args.Url,
+				"version":   args.Version,
+				"file_size": args.FileSize,
+			},
+		},
+
 		SubDeviceId: args.SudDeviceId,
-		Timestamp:   time.Now().Unix(),
-		Version:     args.Version,
-		Url:         args.Url,
-		Md5:         args.Md5,
 	}
+
 	msg, err := cmd.Marshal()
 	if err != nil {
 		return err

+ 17 - 0
services/registry/registry.go

@@ -383,6 +383,23 @@ func (r *Registry) FindDeviceByIdentifier(identifier string, reply *models.Devic
 	return nil
 }
 
+// FindDeviceByIdentifier2 will find the device by indentifier
+func (r *Registry) FindDeviceByIdentifier2(identifier string, reply *models.Device) error {
+	db, err := getDB()
+	if err != nil {
+		return err
+	}
+
+	err = db.Where(&models.Device{
+		DeviceIdentifier: identifier,
+	}).First(reply).Error
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
 func (r *Registry) FindDeviceById(args uint64, reply *models.Device) error {
 	db, err := getDB()
 	if err != nil {