| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package mcu_ctrl_board
- /*
- #include "mcu_ctrl_board.h"
- */
- import "C"
- import (
- "fmt"
- "unsafe"
- "hnyfkj.com.cn/rtu/linux/rtu/cbd/utils"
- )
- // 打开与MCU控制板的串口通讯
- func mcuCtrlBoard_ComInit() (int, error) {
- ret := int(C.MCU_ComInit())
- if ret != 0 {
- return ret, fmt.Errorf("an error occurred while calling the C.MCU_ComInit() function(%d)", ret)
- }
- return 0, nil
- }
- // 关闭与MCU控制板的串口通讯
- func mcuCtrlBoard_ComExit() (int, error) {
- ret := int(C.MCU_ComExit())
- if ret != 0 {
- return ret, fmt.Errorf("an error occurred while calling the C.MCU_ComExit() function(%d)", ret)
- }
- return 0, nil
- }
- // 向MCU控制板主动的写入数据
- func mcuCtrlBoard_Write(data []byte) (int, error) {
- var p *C.uchar
- if len(data) > 0 { // 避免访问空切片导致异常
- p = (*C.uchar)(unsafe.Pointer(&data[0]))
- }
- ret := int(C.MCU_SendRaw(p, C.int(len(data))))
- if ret != len(data) {
- return ret, fmt.Errorf("an error occurred while calling the C.MCU_SendRaw() function(%d)", ret)
- }
- return ret, nil
- }
- //export go_handle_serial_json_info
- func go_handle_serial_json_info(jsonStr *C.char) *C.char {
- if Board == nil {
- return nil
- }
- s := C.GoString(jsonStr)
- t := utils.DetectJsonType(s)
- switch t {
- case "jsondata":
- return processJson(s)
- case "jsonrpc2":
- return processRPC2(s)
- default:
- return nil
- }
- }
- //export go_handle_serial_text_info
- func go_handle_serial_text_info(textStr *C.char) *C.char {
- if Board == nil {
- return nil
- }
- s := C.GoString(textStr)
- return processText(s)
- }
|