|
|
@@ -7,6 +7,8 @@ import "C"
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+
|
|
|
+ "hnyfkj.com.cn/rtu/xy_v/utils/jsonrpc2"
|
|
|
)
|
|
|
|
|
|
// 打开与MCU控制板的串口通讯
|
|
|
@@ -29,7 +31,27 @@ func mcuCtrlBoard_ComExit() error {
|
|
|
|
|
|
//export RTU_ProcessCommand
|
|
|
func RTU_ProcessCommand(request *C.char) *C.char {
|
|
|
- //goReq := C.GoString(request)
|
|
|
- goResp := "{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32601,\"message\":\"Method not found\"},\"id\":1}"
|
|
|
- return C.CString(goResp)
|
|
|
+ r, err := jsonrpc2.ParseRequest(C.GoString(request))
|
|
|
+ var w *jsonrpc2.RpcResponse
|
|
|
+ if err != nil {
|
|
|
+ w = jsonrpc2.BuildParseError(r.ID)
|
|
|
+ } else {
|
|
|
+ switch r.Method {
|
|
|
+ // 控制板查询数据板状态
|
|
|
+ case "get_mcu_status":
|
|
|
+ // 控制板发送传感器数据
|
|
|
+ case "send_sensor_data":
|
|
|
+ // 控制板请求数据板拍照
|
|
|
+ case "take_photo":
|
|
|
+ // 控制板发送掉电预通知
|
|
|
+ case "power_down":
|
|
|
+ default:
|
|
|
+ w = jsonrpc2.BuildMethodNotFound(r.ID)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ b, err := w.String()
|
|
|
+ if err != nil {
|
|
|
+ return C.CString(fmt.Sprintf("an error occurred while calling the String() method of RpcResponse: %v", err))
|
|
|
+ }
|
|
|
+ return C.CString(b)
|
|
|
}
|