update
parent
9dcaee11d5
commit
9b9862fee9
@ -0,0 +1,54 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SibDevice struct {
|
||||||
|
UDID string `json:"udid"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Src string `json:"src"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetIOSDevices() map[string]SibDevice {
|
||||||
|
m_devices := make(map[string]SibDevice)
|
||||||
|
cmd := exec.Command("sib", "devices")
|
||||||
|
stdout, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return m_devices
|
||||||
|
}
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return m_devices
|
||||||
|
}
|
||||||
|
scanner := bufio.NewScanner(stdout)
|
||||||
|
for scanner.Scan() {
|
||||||
|
output := scanner.Text()
|
||||||
|
if strings.Contains(output, "no device") {
|
||||||
|
// 没设备
|
||||||
|
return m_devices
|
||||||
|
}
|
||||||
|
if len(output) < 20 {
|
||||||
|
//空行
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strs := strings.Fields(output); len(strs) >= 3 {
|
||||||
|
var d SibDevice
|
||||||
|
d.UDID = strs[0]
|
||||||
|
d.Status = strs[1]
|
||||||
|
d.Src = strs[2]
|
||||||
|
m_devices[d.UDID] = d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return m_devices
|
||||||
|
}
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
return m_devices
|
||||||
|
}
|
||||||
|
return m_devices
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package crontask
|
||||||
|
|
||||||
|
import (
|
||||||
|
"autogo/cli"
|
||||||
|
"autogo/dbsql"
|
||||||
|
"autogo/models"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckIOSDevices() {
|
||||||
|
m := cli.GetIOSDevices()
|
||||||
|
|
||||||
|
db, err := dbsql.GetConn(dbsql.DSN)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[Crontab] 数据库连接失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer dbsql.Close(db)
|
||||||
|
|
||||||
|
var list []models.Device
|
||||||
|
db.Model(models.Device{}).Where("platform = ? AND is_del = 0", "ios").Find(&list)
|
||||||
|
for _, v := range list {
|
||||||
|
if vv, ok := m[v.Udid]; ok {
|
||||||
|
if vv.Status != "online" && v.Status != vv.Status {
|
||||||
|
db.Model(models.Device{}).Where("udid = ?", v.Udid).Update("status", vv.Status)
|
||||||
|
fmt.Println("[Crontab]", v.Udid, "连接状态异常:", v.Status)
|
||||||
|
} else if v.Status == "offline" && vv.Status == "online" {
|
||||||
|
db.Model(models.Device{}).Where("udid = ?", v.Udid).Update("status", "online")
|
||||||
|
fmt.Println("[Crontab]", v.Udid, "已连接")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if v.Status == "online" || v.Status == "busy" {
|
||||||
|
db.Model(models.Device{}).Where("udid = ?", v.Udid).Update("status", "offline")
|
||||||
|
fmt.Println("[Crontab]", v.Udid, "已离线")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
package device
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetIOSDevices() []sibDevice {
|
||||||
|
out := struct {
|
||||||
|
DeviceList []sibDevice
|
||||||
|
}{}
|
||||||
|
cmd := exec.Command("sib", "devices", "-f", "-d")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return out.DeviceList
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(output, &out)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return out.DeviceList
|
||||||
|
}
|
||||||
|
return out.DeviceList
|
||||||
|
}
|
||||||
|
|
||||||
|
type sibDevice 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 struct {
|
||||||
|
GenerationName string `json:"generationName"`
|
||||||
|
DeviceName string `json:"deviceName"`
|
||||||
|
DeviceColor string `json:"deviceColor"`
|
||||||
|
DeviceClass string `json:"deviceClass"`
|
||||||
|
ProductVersion string `json:"productVersion"`
|
||||||
|
ProductType string `json:"productType"`
|
||||||
|
ProductName string `json:"productName"`
|
||||||
|
ModelNumber string `json:"modelNumber"`
|
||||||
|
SerialNumber string `json:"serialNumber"`
|
||||||
|
SimStatus string `json:"simStatus"`
|
||||||
|
CPUArchitecture string `json:"cpuArchitecture"`
|
||||||
|
ProtocolVersion string `json:"protocolVersion"`
|
||||||
|
RegionInfo string `json:"regionInfo"`
|
||||||
|
TelephonyCapability bool `json:"telephonyCapability"`
|
||||||
|
TimeZone string `json:"timeZone"`
|
||||||
|
UniqueDeviceID string `json:"uniqueDeviceID"`
|
||||||
|
WifiAddress string `json:"wifiAddress"`
|
||||||
|
WirelessBoardSerialNumber string `json:"wirelessBoardSerialNumber"`
|
||||||
|
BluetoothAddress string `json:"bluetoothAddress"`
|
||||||
|
BuildVersion string `json:"buildVersion"`
|
||||||
|
} `json:"deviceDetail"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查sib是否已安装
|
||||||
|
func CheckSib() bool {
|
||||||
|
cmd := exec.Command("sib")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if strings.Contains(string(output), "SonicCloudOrg") {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue