-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
devices.go
96 lines (83 loc) · 2.55 KB
/
devices.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* sonic-ios-bridge Connect to your iOS Devices.
* Copyright (C) 2022 SonicCloudOrg
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package entity
import (
"encoding/json"
"fmt"
"strings"
"github.com/Masterminds/semver"
)
type DeviceList struct {
DeviceList []Device `json:"deviceList"`
}
type Device struct {
RemoteAddr string `json:"remoteAddr"`
DeviceID int `json:"deviceId"`
ConnectionSpeed int `json:"connectionSpeed"`
ConnectionType string `json:"connectionType"`
LocationID int `json:"locationId"`
ProductID int `json:"productId"`
SerialNumber string `json:"serialNumber"`
Status string `json:"status"`
DeviceDetail DeviceDetail `json:"deviceDetail"`
}
func (device *Device) GetStatus() string {
if device.ConnectionType != "" {
return "online"
} else {
return "offline"
}
}
func (device Device) ToString() string {
var s strings.Builder
s.WriteString(device.SerialNumber + " " + device.Status)
return s.String()
}
func (device Device) ToJson() string {
result, _ := json.Marshal(device)
return string(result)
}
func (device Device) ToFormat() string {
result, _ := json.MarshalIndent(device, "", "\t")
return string(result)
}
func (deviceList DeviceList) ToString() string {
for _, e := range deviceList.DeviceList {
fmt.Println(e.SerialNumber + " " + e.Status + " " + e.RemoteAddr)
}
return ""
}
func (deviceList DeviceList) ToJson() string {
result, _ := json.Marshal(deviceList)
return string(result)
}
func (deviceList DeviceList) ToFormat() string {
result, _ := json.MarshalIndent(deviceList, "", "\t")
return string(result)
}
type DevMode struct {
Device
DevModeStatus string `json:"status,omitempty"`
}
func (devmode DevMode) CanCheck() (bool, error) {
v, err := semver.NewVersion(devmode.DeviceDetail.ProductVersion)
if err != nil {
return false, err
}
return v.Major() >= 16, nil
}