|
|
|
@@ -1,18 +1,10 @@
|
|
|
|
package rpc
|
|
|
|
package rpc
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 设备详情
|
|
|
|
|
|
|
|
type DeviceDetail struct {
|
|
|
|
|
|
|
|
Type uint8 `json:"type"`
|
|
|
|
|
|
|
|
ConnectType uint8 `json:"connect_type"`
|
|
|
|
|
|
|
|
Secret string `json:"secret"`
|
|
|
|
|
|
|
|
PId uint32 `json:"p_id"`
|
|
|
|
|
|
|
|
DataId uint32 `json:"data_id"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var device *Device
|
|
|
|
var device *Device
|
|
|
|
|
|
|
|
|
|
|
|
// 获取设备相关RPC类
|
|
|
|
// 获取设备相关RPC类
|
|
|
|
@@ -27,7 +19,7 @@ func GetDevice() *Device {
|
|
|
|
type Device struct{}
|
|
|
|
type Device struct{}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取设备详情
|
|
|
|
// 获取设备详情
|
|
|
|
func (d *Device) GetDetail(deviceId uint32) (*Result[DeviceDetail], error) {
|
|
|
|
func (d *Device) GetDetail(deviceId uint32) (*DeviceDetail, error) {
|
|
|
|
body := map[string]any{
|
|
|
|
body := map[string]any{
|
|
|
|
"device_id": deviceId,
|
|
|
|
"device_id": deviceId,
|
|
|
|
"field_list": []string{"type", "secret", "connect_type", "p_id", "data_id"},
|
|
|
|
"field_list": []string{"type", "secret", "connect_type", "p_id", "data_id"},
|
|
|
|
@@ -36,20 +28,38 @@ func (d *Device) GetDetail(deviceId uint32) (*Result[DeviceDetail], error) {
|
|
|
|
if err := GetRequest().Send("device.get_detail", body, result); err != nil {
|
|
|
|
if err := GetRequest().Send("device.get_detail", body, result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return &result.Data, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取设备属性列表
|
|
|
|
|
|
|
|
func (d *Device) GetAttributeOptionList() (*[]DeviceAttributeOption, error) {
|
|
|
|
|
|
|
|
result := &Result[[]DeviceAttributeOption]{}
|
|
|
|
|
|
|
|
if err := GetRequest().Send("device.get_attribute_option_list", map[string]any{}, result); err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return &result.Data, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 重置设备在线状态
|
|
|
|
// 重置设备在线状态
|
|
|
|
func (d *Device) ResetOnlineStatus() (*Result[any], error) {
|
|
|
|
func (d *Device) ResetOnlineStatus() error {
|
|
|
|
result := &Result[any]{}
|
|
|
|
result := &Result[any]{}
|
|
|
|
if err := GetRequest().Send("device.reset_online_status", map[string]any{}, result); err != nil {
|
|
|
|
if err := GetRequest().Send("device.reset_online_status", map[string]any{}, result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新设备在线状态
|
|
|
|
// 更新设备在线状态
|
|
|
|
func (d *Device) UpdateOnlineStatus(deviceId uint32, online bool, updateTime time.Time) (*Result[any], error) {
|
|
|
|
func (d *Device) UpdateOnlineStatus(deviceId uint32, online bool, updateTime time.Time) error {
|
|
|
|
body := map[string]any{
|
|
|
|
body := map[string]any{
|
|
|
|
"device_id": deviceId,
|
|
|
|
"device_id": deviceId,
|
|
|
|
"online": online,
|
|
|
|
"online": online,
|
|
|
|
@@ -57,13 +67,16 @@ func (d *Device) UpdateOnlineStatus(deviceId uint32, online bool, updateTime tim
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result := &Result[any]{}
|
|
|
|
result := &Result[any]{}
|
|
|
|
if err := GetRequest().Send("device.update_online_status", body, result); err != nil {
|
|
|
|
if err := GetRequest().Send("device.update_online_status", body, result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新从设备在线状态
|
|
|
|
// 更新从设备在线状态
|
|
|
|
func (d *Device) UpdateSlaveOnlineStatus(deviceId uint32, online bool, updateTime time.Time, parentId *uint32) (*Result[any], error) {
|
|
|
|
func (d *Device) UpdateSlaveOnlineStatus(deviceId uint32, online bool, updateTime time.Time, parentId *uint32) error {
|
|
|
|
body := map[string]any{
|
|
|
|
body := map[string]any{
|
|
|
|
"device_id": deviceId,
|
|
|
|
"device_id": deviceId,
|
|
|
|
"online": online,
|
|
|
|
"online": online,
|
|
|
|
@@ -74,13 +87,16 @@ func (d *Device) UpdateSlaveOnlineStatus(deviceId uint32, online bool, updateTim
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result := &Result[any]{}
|
|
|
|
result := &Result[any]{}
|
|
|
|
if err := GetRequest().Send("device.update_salve_online_status", body, result); err != nil {
|
|
|
|
if err := GetRequest().Send("device.update_salve_online_status", body, result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新设备属性上报时间
|
|
|
|
// 更新设备属性上报时间
|
|
|
|
func (d *Device) UpdateReportTime(deviceId uint32, reportTime *time.Time) (*Result[any], error) {
|
|
|
|
func (d *Device) UpdateReportTime(deviceId uint32, reportTime *time.Time) error {
|
|
|
|
body := map[string]any{
|
|
|
|
body := map[string]any{
|
|
|
|
"device_id": deviceId,
|
|
|
|
"device_id": deviceId,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -89,26 +105,32 @@ func (d *Device) UpdateReportTime(deviceId uint32, reportTime *time.Time) (*Resu
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result := &Result[any]{}
|
|
|
|
result := &Result[any]{}
|
|
|
|
if err := GetRequest().Send("device.update_report_time", body, result); err != nil {
|
|
|
|
if err := GetRequest().Send("device.update_report_time", body, result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置设备属性
|
|
|
|
// 设置设备属性
|
|
|
|
func (d *Device) SetAttribute(deviceId uint32, attributeSet map[string]any) (*Result[any], error) {
|
|
|
|
func (d *Device) SetAttribute(deviceId uint32, attributeSet map[string]any) error {
|
|
|
|
body := map[string]any{
|
|
|
|
body := map[string]any{
|
|
|
|
"device_id": deviceId,
|
|
|
|
"device_id": deviceId,
|
|
|
|
"attribute": attributeSet,
|
|
|
|
"attribute": attributeSet,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result := &Result[any]{}
|
|
|
|
result := &Result[any]{}
|
|
|
|
if err := GetRequest().Send("device.set_attribute", body, result); err != nil {
|
|
|
|
if err := GetRequest().Send("device.set_attribute", body, result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取设备属性
|
|
|
|
// 获取设备属性
|
|
|
|
func (d *Device) GetAttribute(deviceId uint32) (*Result[map[string]any], error) {
|
|
|
|
func (d *Device) GetAttribute(deviceId uint32) (*map[string]any, error) {
|
|
|
|
body := map[string]any{
|
|
|
|
body := map[string]any{
|
|
|
|
"device_id": deviceId,
|
|
|
|
"device_id": deviceId,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -116,24 +138,30 @@ func (d *Device) GetAttribute(deviceId uint32) (*Result[map[string]any], error)
|
|
|
|
if err := GetRequest().Send("device.get_attribute", body, result); err != nil {
|
|
|
|
if err := GetRequest().Send("device.get_attribute", body, result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return &result.Data, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新设备版本信息
|
|
|
|
// 更新设备版本信息
|
|
|
|
func (d *Device) UpdateVersion(deviceId uint32, versionNumber uint) (*Result[any], error) {
|
|
|
|
func (d *Device) UpdateVersion(deviceId uint32, versionNumber uint) error {
|
|
|
|
body := map[string]any{
|
|
|
|
body := map[string]any{
|
|
|
|
"device_id": deviceId,
|
|
|
|
"device_id": deviceId,
|
|
|
|
"version_number": versionNumber,
|
|
|
|
"version_number": versionNumber,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result := &Result[any]{}
|
|
|
|
result := &Result[any]{}
|
|
|
|
if err := GetRequest().Send("device.update_version", body, result); err != nil {
|
|
|
|
if err := GetRequest().Send("device.update_version", body, result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 保存升级结果
|
|
|
|
// 保存升级结果
|
|
|
|
func (d *Device) SaveUpgradeResult(upgradeTaskId uint32, status uint8, finishTime time.Time) (*Result[any], error) {
|
|
|
|
func (d *Device) SaveUpgradeResult(upgradeTaskId uint32, status uint8, finishTime time.Time) error {
|
|
|
|
body := map[string]any{
|
|
|
|
body := map[string]any{
|
|
|
|
"upgrade_task_id": upgradeTaskId,
|
|
|
|
"upgrade_task_id": upgradeTaskId,
|
|
|
|
"status": status,
|
|
|
|
"status": status,
|
|
|
|
@@ -141,7 +169,10 @@ func (d *Device) SaveUpgradeResult(upgradeTaskId uint32, status uint8, finishTim
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result := &Result[any]{}
|
|
|
|
result := &Result[any]{}
|
|
|
|
if err := GetRequest().Send("device.save_upgrade_result", body, result); err != nil {
|
|
|
|
if err := GetRequest().Send("device.save_upgrade_result", body, result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
if result.Code != 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("%s", result.Message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|