package m9zApi import ( "encoding/json" "github.com/towgo/towgo/errors/terror" "github.com/towgo/towgo/towgo" "tgk-touch/internal/global" ) var deviceInfo map[string]interface{} func Init() { marshal, _ := json.Marshal(g.Config().DeviceInfo) json.Unmarshal(marshal, &deviceInfo) towgo.SetFunc("/m9z/fault/list", faultList) towgo.SetFunc("/m9z/fault/batchExec", execFailByIds) // 获取设备输出状态参数 towgo.SetFunc("/m9z/getOutStatus", getOutStatus) // 获取设备模式 towgo.SetFunc("/m9z/getDeviceMode", getDeviceMode) // 设置设备模式 towgo.SetFunc("/m9z/setDeviceMode", setDeviceMode) // 获取手动控制信息 towgo.SetFunc("/m9z/getDeviceManualInfo", getDeviceManualInfo) // 设置手动控制 towgo.SetFunc("/m9z/setDeviceManualInfo", setDeviceManualInfo) // 获取设备时间 towgo.SetFunc("/m9z/getDeviceTime", getDeviceTime) // 设置设备时间 towgo.SetFunc("/m9z/setDeviceTime", setDeviceTime) // 获取设备经纬度信息 towgo.SetFunc("/m9z/getLgnLatData", getLgnLatData) // 设置设备经纬度信息 towgo.SetFunc("/m9z/setLgnLatData", setLgnLatData) // 获取日出日落时间偏差 towgo.SetFunc("/m9z/getSunRiseSet", getSunRiseSet) // 设置日出日落时间偏差 towgo.SetFunc("/m9z/setSunRiseSet", setSunRiseSet) // 获取设备的状态 towgo.SetFunc("/m9z/getDeviceStatus", getDeviceStatus) // 实时监控 towgo.SetFunc("/m9z/getDeviceStatus2", getDeviceStatus2) // 获取设备的配置 towgo.SetFunc("/m9z/getDeviceConfig", getDeviceConfig) // 设置设备的配置 towgo.SetFunc("/m9z/setDeviceConfig", setDeviceConfig) // 获取日出日落时间 towgo.SetFunc("/m9z/getDeviceSunRiseTime", getDeviceSunRiseTime) // 保存配置参数 towgo.SetFunc("/m9z/setSave", setSave) // 重启设备 towgo.SetFunc("/m9z/setRestart", setRestart) // 设置经纬度和日出日落时间差 towgo.SetFunc("/m9z/setDeviceLgnLatAndSunRsTime", setDeviceLgnLatAndSunRsTime) // 读取开始任务 (优化指令 CMD=0x13) towgo.SetFunc("/m9z/getStartTask", getStartTask) // 读取中间任务 (优化指令 CMD=0x14) towgo.SetFunc("/m9z/getMiddleTaskRead", getMiddleTaskRead) // 读取结束任务 (优化指令 CMD=0x15) towgo.SetFunc("/m9z/getStopTaskRead", getStopTaskRead) // 写入开始任务 (优化指令 CMD=0x13) towgo.SetFunc("/m9z/setStartTaskWrite", setStartTaskWrite) // 写入中间任务 (优化指令 CMD=0x14) towgo.SetFunc("/m9z/setMiddleTaskWrite", setMiddleTaskWrite) // 写入结束任务 (优化指令 CMD=0x15) towgo.SetFunc("/m9z/setStopTaskWrite", setStopTaskWrite) towgo.SetFunc("/m9z/getStartTask2", getStartTask2) towgo.SetFunc("/m9z/getStopTask2", getStopTask2) towgo.SetFunc("/m9z/setStartTask2", setStartTask2) towgo.SetFunc("/m9z/setStopTask2", setStopTask2) towgo.SetFunc("/m9z/getMiddleTask2", getMiddleTask2) towgo.SetFunc("/m9z/setMiddleTask2", setMiddleTask2) towgo.SetFunc("/m9z/getSubLoopParameters", getSubLoopParameters) towgo.SetFunc("/m9z/getAllSubLoopParameter", getAllSubLoopParameter) towgo.SetFunc("/m9z/touchdisplay/getDeviceID", getTouchDeviceId) } func getTouchDeviceId(rpc towgo.JsonRpcConnection) { rpc.WriteResult(deviceInfo) } func faultDelete(rpc towgo.JsonRpcConnection) { var p struct { Id int `json:"id"` } rpc.ReadResult(&p) if p.Id == 0 { panic(terror.New("id 为空")) } err := deleteById(p.Id) if err != nil { panic(err) } rpc.WriteResult("ok") } func faultList(rpc towgo.JsonRpcConnection) { data, err := readData() if err != nil { panic(err) } rpc.WriteResult(g.NewPageResult(int64(len(data)), data)) } func execFailByIds(rpc towgo.JsonRpcConnection) { var p struct { Ids []int `json:"ids"` Operate uint `json:"operate"` // 0 处理 1删除 } rpc.ReadParams(&p) if p.Operate == 0 { } else { for _, id := range p.Ids { err := deleteById(id) if err != nil { panic(err) } } } rpc.WriteResult("ok") }