From 05df09d5ea32440d5cbfce01e43580fa2ab291e6 Mon Sep 17 00:00:00 2001 From: "lxbpxylps@126.com" Date: Wed, 17 Feb 2021 13:22:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A0=91=E8=8E=93=E6=B4=BE?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E8=B0=83=E8=AF=95=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RPi Debugger/debugTaiChi.cpp | 112 +++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 RPi Debugger/debugTaiChi.cpp diff --git a/RPi Debugger/debugTaiChi.cpp b/RPi Debugger/debugTaiChi.cpp new file mode 100644 index 0000000..dcb6341 --- /dev/null +++ b/RPi Debugger/debugTaiChi.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +using namespace std; + + +#define DEBUG_GPIO 0 +#define DEBUG_BAUT_RATE 115200 + +//终端颜色 +#define COLOR_RED "\x1B[31m" +#define COLOR_GRN "\x1B[32m" +#define COLOR_YEL "\x1B[33m" +#define COLOR_BLU "\x1B[34m" +#define COLOR_MAG "\x1B[35m" +#define COLOR_CYN "\x1B[36m" +#define COLOR_WHT "\x1B[37m" +#define COLOR_RESET "\x1B[0m" + + +//向 Arduino 发送暂停命令 +static void SendDebugPause(int siginal) +{ + digitalWrite(DEBUG_GPIO, LOW); +} + + +//向 Arduino 发送执行命令 +static void SendDebugContinue(int siginal) +{ + digitalWrite(DEBUG_GPIO, HIGH); + cout << '\n'; +} + + +//获取当前时间字符串 +string GetStrTime() +{ + time_t timep; + time(&timep); + char tmp[9]; + strftime(tmp, sizeof(tmp), "%H:%M:%S", localtime(&timep)); + return tmp; +} + + +int main(void) +{ + //注册 linux 终端信号 + signal(SIGINT, SendDebugPause); //Ctrl + C + signal(SIGTSTP, SendDebugContinue); //Ctrl + Z + + //初始化树莓派 GPIO + wiringPiSetup(); + pinMode(DEBUG_GPIO, OUTPUT); + + //暂停执行,等待发送执行命令 + digitalWrite(DEBUG_GPIO, LOW); + + //打开串口 + int fd = serialOpen("/dev/ttyACM0", DEBUG_BAUT_RATE); + while (1) + { + string line_head = GetStrTime() + " -> "; + string line_info; + + while (1) + { + if (serialDataAvail(fd) > 0) //串口接收到内容 + { + char serial_get_c = serialGetchar(fd); + line_info += serial_get_c; + + if (serial_get_c == '\n') + { + string line_info_head = line_info.substr(0, 8); + string line_type; + + //根据调试信息类型选择对应的颜色 + if (line_info_head == "#TAICHI:") + { + line_type = COLOR_YEL; + } + else if (line_info_head == "#MOVE: ") + { + line_type = COLOR_RED; + } + else if (line_info_head == "#SENSOR:") + { + line_type = COLOR_GRN; + } + else if (line_info_head == "#SERVO: ") + { + line_type = COLOR_BLU; + } + + cout << line_head + line_type + line_info + COLOR_RESET; + break; + } + } + } + } + + return 0; +} \ No newline at end of file