|
|
@@ -95,13 +95,13 @@ func RTU_ProcessCommand(request *C.char) *C.char {
|
|
|
call := func(f func(*jsonrpc2.Request) (*jsonrpc2.Response, error)) *jsonrpc2.Response {
|
|
|
resp, e := f(r)
|
|
|
if e != nil { // 调用本地RPC处理函数时发生错误
|
|
|
- return jsonrpc2.BuildInternalError(r.ID)
|
|
|
+ return jsonrpc2.BuildError(r, jsonrpc2.ErrInternal, "")
|
|
|
}
|
|
|
return resp
|
|
|
}
|
|
|
|
|
|
if err != nil {
|
|
|
- w = jsonrpc2.BuildParseError(r.ID)
|
|
|
+ w = jsonrpc2.BuildError(r, jsonrpc2.ErrParse, "")
|
|
|
} else {
|
|
|
switch r.Method {
|
|
|
// 控制板查询数据板状态
|
|
|
@@ -117,7 +117,7 @@ func RTU_ProcessCommand(request *C.char) *C.char {
|
|
|
case "power_down":
|
|
|
w = call(handlePowerDown)
|
|
|
default:
|
|
|
- w = jsonrpc2.BuildMethodNotFound(r.ID)
|
|
|
+ w = jsonrpc2.BuildError(r, jsonrpc2.ErrMethodNotFound, "")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -147,20 +147,20 @@ func handleGetRTUStatus(r *jsonrpc2.Request) (*jsonrpc2.Response, error) {
|
|
|
}
|
|
|
|
|
|
wjson := fmt.Sprintf(`{"netst":"%s","systm":"%s","wrkst":"%s"}`, netst, systm, wrkst)
|
|
|
- return jsonrpc2.BuildResult(r.ID, wjson)
|
|
|
+ return jsonrpc2.BuildResult(r, wjson)
|
|
|
}
|
|
|
|
|
|
// 控制板发送传感器数据
|
|
|
func handleSendSensorData(r *jsonrpc2.Request) (*jsonrpc2.Response, error) {
|
|
|
if Board == nil || Board.OneEnvDataCh == nil {
|
|
|
- return jsonrpc2.BuildInternalError(r.ID), nil
|
|
|
+ return jsonrpc2.BuildError(r, jsonrpc2.ErrInternal, ""), nil
|
|
|
}
|
|
|
GlobalWorkState.Add(SensorDataReceiving)
|
|
|
defer GlobalWorkState.Remove(SensorDataReceiving)
|
|
|
|
|
|
var dataOne EnvSensorData
|
|
|
if err := json.Unmarshal([]byte(r.Params), &dataOne); err != nil {
|
|
|
- return jsonrpc2.BuildInvalidParams(r.ID), nil
|
|
|
+ return jsonrpc2.BuildError(r, jsonrpc2.ErrInvalidParams, ""), nil
|
|
|
}
|
|
|
|
|
|
select {
|
|
|
@@ -171,13 +171,13 @@ func handleSendSensorData(r *jsonrpc2.Request) (*jsonrpc2.Response, error) {
|
|
|
Board.OneEnvDataCh <- &dataOne
|
|
|
}
|
|
|
|
|
|
- return jsonrpc2.BuildResult(r.ID, "success")
|
|
|
+ return jsonrpc2.BuildResult(r, "success")
|
|
|
}
|
|
|
|
|
|
// 控制板请求数据板拍照
|
|
|
func handleTakePhoto(r *jsonrpc2.Request) (*jsonrpc2.Response, error) {
|
|
|
if Board == nil || Board.ReqTakePhoCh == nil {
|
|
|
- return jsonrpc2.BuildInternalError(r.ID), nil
|
|
|
+ return jsonrpc2.BuildError(r, jsonrpc2.ErrInternal, ""), nil
|
|
|
}
|
|
|
|
|
|
select {
|
|
|
@@ -187,7 +187,7 @@ func handleTakePhoto(r *jsonrpc2.Request) (*jsonrpc2.Response, error) {
|
|
|
Board.ReqTakePhoCh <- true
|
|
|
}
|
|
|
|
|
|
- return jsonrpc2.BuildResult(r.ID, "success")
|
|
|
+ return jsonrpc2.BuildResult(r, "success")
|
|
|
}
|
|
|
|
|
|
// 控制板发送预掉电通知
|
|
|
@@ -212,5 +212,5 @@ func handlePowerDown(r *jsonrpc2.Request) (*jsonrpc2.Response, error) {
|
|
|
|
|
|
wjson := fmt.Sprintf(`{"netst":"%s","systm":"%s","wrkst":"%s"}`, netst, systm, wrkst)
|
|
|
|
|
|
- return jsonrpc2.BuildResult(r.ID, wjson)
|
|
|
+ return jsonrpc2.BuildResult(r, wjson)
|
|
|
}
|