|
@@ -1 +1,48 @@
|
|
|
#include "mcu_ctrl_board.h"
|
|
#include "mcu_ctrl_board.h"
|
|
|
|
|
+#include "../../rtu_linux_modules/swapi/subjects/serial/serial.h"
|
|
|
|
|
+
|
|
|
|
|
+// 模块名称
|
|
|
|
|
+static const char MODULE_NAME[] = "MCUCtrlBoard";
|
|
|
|
|
+
|
|
|
|
|
+// 定义与单片机进行通讯的结构体, 同时定义结构体对象
|
|
|
|
|
+typedef struct
|
|
|
|
|
+{
|
|
|
|
|
+ void *h;
|
|
|
|
|
+} SMCBCom;
|
|
|
|
|
+
|
|
|
|
|
+static SMCBCom s_myCom = { 0 };
|
|
|
|
|
+
|
|
|
|
|
+// 接收处理来自MCU控制板的数据报文帧, 串口-线程回调
|
|
|
|
|
+static int comio_data_recv_proc(unsigned long wParam/*传递打开的串口句柄*/, unsigned long lParam/*保留暂未使用*/)
|
|
|
|
|
+{
|
|
|
|
|
+ return 1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 打开与MCU控制板的串口通讯, 返回: 0成功, <0时失败
|
|
|
|
|
+int MCBComInit()
|
|
|
|
|
+{
|
|
|
|
|
+#ifdef _DEBUG // 上位机单元测试时使用
|
|
|
|
|
+ const char *serialName = "/dev/ttyS0"; int baudrate = 115200;
|
|
|
|
|
+#else
|
|
|
|
|
+ const char *serialName = "/dev/ttymxc2"; int baudrate = 115200;
|
|
|
|
|
+#endif
|
|
|
|
|
+ const char *parityCheck = "none"; // 无校检
|
|
|
|
|
+ s_myCom.h = serial_open(serialName, baudrate, parityCheck, \
|
|
|
|
|
+ comio_data_recv_proc, comio_data_recv_proc, NULL);
|
|
|
|
|
+ if(!s_myCom.h)
|
|
|
|
|
+ {
|
|
|
|
|
+ sw_log_error("[%s] failed to open the \"%s:%d(%s parity)\" device!!", \
|
|
|
|
|
+ MODULE_NAME, serialName, baudrate, parityCheck);
|
|
|
|
|
+ MCBComExit(); return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 关闭与MCU控制板的串口通讯, 返回: 0成功, <0时失败
|
|
|
|
|
+int MCBComExit()
|
|
|
|
|
+{
|
|
|
|
|
+ if(s_myCom.h) serial_close(s_myCom.h, WAITTHRD_SAFEEXIT_TIMEOUT);
|
|
|
|
|
+ memset(&s_myCom, 0, sizeof(s_myCom));
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|