diff --git a/study/CScreenCom/CScreenCom.cpp b/study/CScreenCom/CScreenCom.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b30743f4d397b05eee495a5598ae390a6d984c49 --- /dev/null +++ b/study/CScreenCom/CScreenCom.cpp @@ -0,0 +1,122 @@ +#include "CScreenCom.h" +#include "../common.h" +extern bool b_bshowtext; + +CScreenCom *CScreenCom::m_pInstance = NULL; +CScreenCom::CScreenCom() +{ + LOGI("start"); + initScreenCom(); + LOGI("end"); +} + +CScreenCom::~CScreenCom() +{ + LOGI("start"); + // 关闭端口 + m_SerialPort.closecom(); + + delete m_pInstance; + m_pInstance = NULL; + LOGI("end"); +} + +// 单例 +CScreenCom *CScreenCom::GetInstance() +{ + if (m_pInstance == NULL) + { + m_pInstance = new CScreenCom(); + } + return m_pInstance; +} + +/* + 透传到端口管理 +*/ +int CScreenCom::sendtoscreen(char *data, int datalen) +{ + int len = 0; + len = m_SerialPort.senddatatocom(data, datalen); + return len; +} + +/* + 透传到端口管理 +*/ +int CScreenCom::recvscreen(char *data, int datalen) +{ + int len = 0; + len = m_SerialPort.recvdatafromcom(data, datalen); + return len; +} + +void CScreenCom::ShowMessage1(char* text) +{ + // b_bshowtext =true; + char szchn[64] = {0}; + sprintf(szchn, "DA%s", text); + string strchn = szchn; + sendtoscreen((char *)strchn.c_str(), strchn.length()); +} + +void CScreenCom::ShowMessage2(char* text) +{ + // b_bshowtext =true; + char szchn[64] = {0}; + sprintf(szchn, "DB%s", text); + string strchn = szchn; + sendtoscreen((char *)strchn.c_str(), strchn.length()); +} + +void CScreenCom::ShowMessage3(char* text) +{ + // b_bshowtext =true; + char szchn[64] = {0}; + sprintf(szchn, "DC%s", text); + string strchn = szchn; + sendtoscreen((char *)strchn.c_str(), strchn.length()); +} + +void CScreenCom::ShowMessage4(char* text) +{ + // b_bshowtext =true; + char szchn[64] = {0}; + sprintf(szchn, "DD%s", text); + string strchn = szchn; + sendtoscreen((char *)strchn.c_str(), strchn.length()); +} + +void CScreenCom::ShowMessage5(char* text) +{ + // b_bshowtext =true; + char szchn[64] = {0}; + sprintf(szchn, "DE%s", text); + string strchn = szchn; + sendtoscreen((char *)strchn.c_str(), strchn.length()); +} + +void CScreenCom::initScreenCom() +{ + m_SerialPort.setPortName("/dev/ttyS4"); + m_SerialPort.setPrompt('0'); + m_SerialPort.setBaudRate(9600); + m_SerialPort.setDataBits('8'); + m_SerialPort.setDebug('0'); + m_SerialPort.setEcho('0'); + m_SerialPort.setParity('0'); + m_SerialPort.setStopBits('1'); + m_SerialPort.setFlowControl('0'); + m_SerialPort.setReserved(0); + + bool rc = m_SerialPort.openport(O_RDWR | O_NOCTTY | O_NONBLOCK); + if (!rc) { + printf("open screencom(/dev/ttyS4) failed!\n"); + // common::WriteLog("open screencom(/dev/ttyS4) failed!\n"); + m_SerialPort.closecom(); + } else { + printf("You have opened screencom(/dev/ttyS4)!\n"); + // common::WriteLog("You have opened screencom port(/dev/ttyS3)!\n"); + } +} + diff --git a/study/CScreenCom/CScreenCom.h b/study/CScreenCom/CScreenCom.h new file mode 100644 index 0000000000000000000000000000000000000000..d09b9438fb0e86b7159f64882b74799bb1a5eae6 --- /dev/null +++ b/study/CScreenCom/CScreenCom.h @@ -0,0 +1,31 @@ +#ifndef CSCREENCOM_H +#define CSCREENCOM_H + +#include "../common.h" +#include "../CSerialPort/CSerialPort.h" +#include "../Log/Log.h" + +class CScreenCom +{ +public: + explicit CScreenCom(); + ~CScreenCom(); + + static CScreenCom* GetInstance(); + int sendtoscreen(char *data, int datalen); + int recvscreen(char *data, int datalen); + void ShowMessage1(char* text); + void ShowMessage2(char* text); + void ShowMessage3(char* text); + void ShowMessage4(char* text); + void ShowMessage5(char* text); + +private: + void initScreenCom(); + +private: + static CScreenCom * m_pInstance; + CSerialPort m_SerialPort; +}; + +#endif // CDATABASE_H diff --git a/study/CScreenCom/CScreenCom.o b/study/CScreenCom/CScreenCom.o new file mode 100644 index 0000000000000000000000000000000000000000..8ab2324ee75d2f5506643c60f1ff2963fcee3895 Binary files /dev/null and b/study/CScreenCom/CScreenCom.o differ diff --git a/study/CSerialPort/CSerialPort.cpp b/study/CSerialPort/CSerialPort.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42000246850b03258950463ba17bb377f592856b --- /dev/null +++ b/study/CSerialPort/CSerialPort.cpp @@ -0,0 +1,280 @@ +#include "CSerialPort.h" + +CSerialPort::CSerialPort(/* args */) +{ +} + +CSerialPort::~CSerialPort() +{ +} + +/* + 设置端口号 +*/ +bool CSerialPort::setPortName(string strPort) +{ + m_strPortname = strPort; + return true; +} + +bool CSerialPort::setPrompt(char prompt) +{ + m_stuportinfo.prompt = prompt; + return true; +} +/* + 设置 波特率 +*/ +bool CSerialPort::setBaudRate(int baudrate) +{ + m_stuportinfo.baudrate = baudrate; + return true; +} +/* + 设置 数据位 +*/ +bool CSerialPort::setDataBits(char dataBits) +{ + m_stuportinfo.databit = dataBits; + return true; +} +/* + 设置 调试模式 +*/ +bool CSerialPort::setDebug(char debug) +{ + m_stuportinfo.debug = debug; + return true; +} + +bool CSerialPort::setEcho(char echo) +{ + m_stuportinfo.echo = echo; + return true; +} + +bool CSerialPort::setParity(char parity) +{ + m_stuportinfo.parity = parity; + return true; +} +/* + 设置 停止位 +*/ +bool CSerialPort::setStopBits(char stopBits) +{ + m_stuportinfo.stopbit = stopBits; + return true; +} + +bool CSerialPort::setFlowControl(char flowControl) +{ + m_stuportinfo.fctl = flowControl; + return true; +} + +bool CSerialPort::setReserved(int reserved) +{ + m_stuportinfo.reserved = reserved; + return true; +} + +bool CSerialPort::openport(int OpenMode) // O_RDWR | O_NOCTTY | O_NONBLOCK +{ + m_com_fd = open(m_strPortname.c_str(), OpenMode); + if (m_com_fd < 0) + { + printf("Open Com failed,exit!\n"); + // common::WriteLog("Open %s Com failed,,exit!", m_strPortname.c_str()); + return false; + } + PortSet(m_com_fd, &m_stuportinfo); + return true; +} + +int CSerialPort::convbaud(unsigned long int baudrate) +{ + switch (baudrate) + { + case 2400: + return B2400; + case 4800: + return B4800; + case 9600: + return B9600; + case 19200: + return B19200; + case 38400: + return B38400; + case 57600: + return B57600; + case 115200: + return B115200; + default: + return B9600; + } +} + +int CSerialPort::PortSet(int fdcom, const pportinfo_t pportinfo) +{ + struct termios termios_old, termios_new; + int baudrate, tmp; + char databit, stopbit, parity, fctl; + + bzero(&termios_old, sizeof(termios_old)); + bzero(&termios_new, sizeof(termios_new)); + cfmakeraw(&termios_new); + tcgetattr(fdcom, &termios_old); // get the serial port attributions + /*------------设置端口属性----------------*/ + // baudrates + baudrate = convbaud(pportinfo->baudrate); + cfsetispeed(&termios_new, baudrate); // 填入串口输入端的波特率 + cfsetospeed(&termios_new, baudrate); // 填入串口输出端的波特率 + termios_new.c_cflag |= CLOCAL; // 控制模式,保证程序不会成为端口的占有者 + termios_new.c_cflag |= CREAD; // 控制模式,使能端口读取输入的数据 + + // 控制模式,flow control + fctl = pportinfo->fctl; + switch (fctl) + { + case '0': + { + termios_new.c_cflag &= ~CRTSCTS; // no flow control + } + break; + case '1': + { + termios_new.c_cflag |= CRTSCTS; // hardware flow control + } + break; + case '2': + { + termios_new.c_iflag |= IXON | IXOFF | IXANY; // software flow control + } + break; + } + + // 控制模式,data bits + termios_new.c_cflag &= ~CSIZE; // 控制模式,屏蔽字符大小位 + databit = pportinfo->databit; + switch (databit) + { + case '5': + termios_new.c_cflag |= CS5; + break; + case '6': + termios_new.c_cflag |= CS6; + break; + case '7': + termios_new.c_cflag |= CS7; + break; + default: + termios_new.c_cflag |= CS8; + break; + } + + // 控制模式 parity check + parity = pportinfo->parity; + switch (parity) + { + case '0': + termios_new.c_cflag &= ~PARENB; // no parity check + termios_new.c_iflag &= ~INPCK; + break; + case '1': + termios_new.c_cflag |= (PARODD | PARENB); // odd check + termios_new.c_iflag |= INPCK; + break; + case '2': + termios_new.c_cflag |= PARENB; // even check + termios_new.c_cflag &= ~PARODD; + termios_new.c_iflag |= INPCK; + break; + case '3': + termios_new.c_cflag |= (PARODD | PARENB); // mark check + termios_new.c_cflag |= CMSPAR; + break; + case '4': + termios_new.c_cflag |= PARENB; // space check + termios_new.c_cflag &= ~PARODD; + termios_new.c_cflag |= CMSPAR; + break; + } + + // 控制模式,stop bits + stopbit = pportinfo->stopbit; + if (stopbit == '2') + { + termios_new.c_cflag |= CSTOPB; // 2 stop bits + } + else + { + termios_new.c_cflag &= ~CSTOPB; // 1 stop bits + } + + // other attributions default + termios_new.c_oflag &= ~OPOST; // 输出模式,原始数据输出 + termios_new.c_cc[VMIN] = 1; // 控制字符, 所要读取字符的最小数量 + termios_new.c_cc[VTIME] = 1; // 控制字符, 读取第一个字符的等待时间 unit: (1/10)second + + tcflush(fdcom, TCIFLUSH); // 溢出的数据可以接收,但不读 + tmp = tcsetattr(fdcom, TCSANOW, &termios_new); // 设置新属性,TCSANOW:所有改变立即生效 tcgetattr(fdcom, &termios_old); + return (tmp); +} + +int CSerialPort::senddatatocom(char *data, int datalen) +{ + int len = 0; + len = PortSend(m_com_fd, data, datalen); + return len; +} + +int CSerialPort::recvdatafromcom(char *data, int datalen) +{ + int len = 0; + len = PortRecv(m_com_fd, data, datalen); + return len; +} + +int CSerialPort::PortSend(int fdcom, char *data, int datalen) +{ + int len = 0; + len = write(fdcom, data, datalen); // 实际写入的长度 + if (len == datalen) { + return (len); + } else { + tcflush(fdcom, TCOFLUSH); // 刷新缓存区 + return -1; + } +} + +int CSerialPort::PortRecv(int fdcom, char *data, int datalen) +{ + int readlen, fs_sel; + fd_set fs_read; + struct timeval tv_timeout; + + FD_ZERO(&fs_read); + FD_SET(fdcom, &fs_read); + tv_timeout.tv_sec = 0; + tv_timeout.tv_usec = 20000; + + fs_sel = select(fdcom + 1, &fs_read, NULL, NULL, &tv_timeout); + if (fs_sel) + { + usleep(50000); + readlen = read(fdcom, data, datalen); + return (readlen); + } + else + { + return (-1); + } + + return (readlen); +} + +void CSerialPort::closecom() +{ + close(m_com_fd); +} \ No newline at end of file diff --git a/study/CSerialPort/CSerialPort.h b/study/CSerialPort/CSerialPort.h new file mode 100644 index 0000000000000000000000000000000000000000..f9d543e31d00af6b9fc62baa79f2d620a4811f94 --- /dev/null +++ b/study/CSerialPort/CSerialPort.h @@ -0,0 +1,97 @@ +#ifndef CSERIALPORT_H +#define CSERIALPORT_H + +/*串口数据处理类*/ +#include "../common.h" +#include "../Log/Log.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//串口结构 +typedef struct{ + char prompt; //prompt after reciving data + int baudrate; //baudrate + char databit; //data bits, 5, 6, 7, 8 + char debug; //debug mode, 0: none, 1: debug + char echo; //echo mode, 0: none, 1: echo + char fctl; //flow control, 0: none, 1: hardware, 2: software + char parity; //parity 0: none, 1: odd, 2: even + char stopbit; //stop bits, 1, 2 + int reserved; //reserved, must be zero +}portinfo_t; +typedef portinfo_t *pportinfo_t; + +class CSerialPort +{ +private: + /* data */ + string m_strPortname; + portinfo_t m_stuportinfo; + int m_com_fd; + +public: + CSerialPort(/* args */); + ~CSerialPort(); + +public: + /* + 设置端口号 + */ + bool setPortName(string strPort); + /* + 设置端口号 + */ + bool setPrompt(char prompt); + bool setBaudRate(int baudrate); + bool setDataBits(char dataBits); // 设置数据位 + bool setDebug(char debug); + bool setEcho(char echo); + bool setParity(char parity); + bool setStopBits(char stopBits); // 停止位设置为1 + bool setFlowControl(char flowControl); // 设置为无流控制 + bool setReserved(int reserved); + bool openport(int OpenMode); + int senddatatocom(char *data, int datalen); + int recvdatafromcom(char *data, int datalen); + void closecom(); + +private: + +/******************************************* + * Setup comm attr + * fdcom: 串口文件描述符,pportinfo: 待设置的端口信息(请确认) + * +********************************************/ +int PortSet(int fdcom, pportinfo_t pportinfo); + +/******************************************* + * 波特率转换函数 +********************************************/ +int convbaud(unsigned long int baudrate); + +/******************************************** + * send data + * fdcom: 串口描述符,data: 待发送数据,datalen: 数据长度 + * 返回实际发送长度 +*********************************************/ +int PortSend(int fdcom, char *data, int datalen); + +/******************************************* + * receive data + * 返回实际读入的字节数 + * +********************************************/ +int PortRecv(int fdcom, char *data, int datalen); +}; + +#endif diff --git a/study/CSerialPort/CSerialPort.o b/study/CSerialPort/CSerialPort.o new file mode 100644 index 0000000000000000000000000000000000000000..957cdb10f631a74b5e2aa2108b2333d01b71349b Binary files /dev/null and b/study/CSerialPort/CSerialPort.o differ diff --git a/study/Log/Log.cpp b/study/Log/Log.cpp new file mode 100644 index 0000000000000000000000000000000000000000..daf664e71c4e475c587d63f2d90f33e5015c6086 --- /dev/null +++ b/study/Log/Log.cpp @@ -0,0 +1,71 @@ +#include "Log.h" + +const char* LevelToString(ELogLevel level) { + switch (level) { + case LOG_LEVEL_DEBUG: + return "D"; + case LOG_LEVEL_INFO: + return "I"; + case LOG_LEVEL_ERROR: + return "E"; + case LOG_LEVEL_WARRING: + return "W"; + default: + return "UNKNOWN"; + } +} + +std::ofstream Log::file_("log.txt"); + +void Log::Debug(const std::string& file_name, int line_number, const std::string& func_name, const std::string& message) { + Write(LOG_LEVEL_DEBUG, file_name, line_number, func_name, message); +} + +void Log::Info(const std::string& file_name, int line_number, const std::string& func_name, const std::string& message) { + Write(LOG_LEVEL_INFO, file_name, line_number, func_name, message); +} + +void Log::Error(const std::string& file_name, int line_number, const std::string& func_name, const std::string& message) { + Write(LOG_LEVEL_ERROR, file_name, line_number, func_name, message); +} + +void Log::Warring(const std::string& file_name, int line_number, const std::string& func_name, const std::string& message) { + Write(LOG_LEVEL_WARRING, file_name, line_number, func_name, message); +} + +void Log::Write(ELogLevel level, const std::string& file_name, int line_number, const std::string& func_name, + const std::string& message) { + std::string leftBracket = "["; + std::string rightBracket = "] "; + std::string colon = ":"; + std::string drop = "."; + // 获取当前时间 + auto now = std::chrono::system_clock::now(); + // 将当前时间转化为毫秒级别 + auto now_ms = std::chrono::time_point_cast(now); + + auto now_str = std::chrono::system_clock::to_time_t(now); + char time_buf[20]; + strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", localtime(&now_str)); + // 计算毫秒 + std::string millisecond = std::to_string(now_ms.time_since_epoch().count() % 1000); + std::string log_message = leftBracket // [ + + time_buf + drop + millisecond + " " // 2023-05-26 10:35:05.109 + + LevelToString(level) // I/E/W/D + + rightBracket // ] + + file_name + colon + std::to_string(line_number) + " " + func_name + colon // CScreenCom/CScreenCom.cpp:15 ~CScreenCom: + + message // "123" + + drop; // . + // 输出日志 + std::cout << log_message << std::endl; + + // 将时间字符串作为日志文件名 + std::string filename = std::string("log_") + time_buf + ".txt"; + // 写入日志文件 + std::ofstream logfile(filename, std::ios_base::app); + if (logfile.is_open()) + { + logfile << log_message << std::endl; + logfile.close(); + } +} diff --git a/study/Log/Log.h b/study/Log/Log.h new file mode 100644 index 0000000000000000000000000000000000000000..725ebc16875b838d097d9de0a9833ae436aa81c2 --- /dev/null +++ b/study/Log/Log.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include + +using namespace std; + +enum ELogLevel { + LOG_LEVEL_DEBUG, + LOG_LEVEL_INFO, + LOG_LEVEL_WARRING, + LOG_LEVEL_ERROR +}; + +const char* LevelToString(ELogLevel level); + +class Log { +public: + static void Debug(const std::string& file_name, int line_number, const std::string& func_name, const std::string& message); + static void Info(const std::string& file_name, int line_number, const std::string& func_name, const std::string& message); + static void Error(const std::string& file_name, int line_number, const std::string& func_name, const std::string& message); + static void Warring(const std::string& file_name, int line_number, const std::string& func_name, const std::string& message); + +private: + static std::ofstream file_; + + static void Write(ELogLevel level, const std::string& file_name, int line_number, const std::string& func_name, + const std::string& message); + // static void my_function(); +}; + +#define LOGD(message) Log::Debug(__FILE__, __LINE__, __FUNCTION__, message) +#define LOGI(message) Log::Info(__FILE__, __LINE__, __FUNCTION__, message) +#define LOGE(message) Log::Error(__FILE__, __LINE__, __FUNCTION__, message) +#define LOGW(message) Log::Error(__FILE__, __LINE__, __FUNCTION__, message) diff --git a/study/Log/Log.o b/study/Log/Log.o new file mode 100644 index 0000000000000000000000000000000000000000..0be78bfed7959b1bb40063815e8b10de520510c1 Binary files /dev/null and b/study/Log/Log.o differ diff --git a/study/Makefile b/study/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..124cf7691e8560f54c5a45518f26887a815f8f2d --- /dev/null +++ b/study/Makefile @@ -0,0 +1,26 @@ +#以下是指定编译器路径 +CXX=aarch64-linux-g++ + +#以下是指定编译需要的头文件 +CXXHEADER=-I./Serial + + +SRCS=main.cpp +SRCS+=./CSerialPort/CSerialPort.cpp \ + ./Log/Log.cpp \ + ./CScreenCom/CScreenCom.cpp + +#以下是指定.o文件 +OBJS=$(SRCS:.cpp=.o) + +#以下是生成可执行文件 +TARGET=test + +$(TARGET):$(OBJS) + $(CXX) -s $(CXXHEADER) $(OBJS) -o $(TARGET) $(LIBS) $(CXXFLAGS) + +%.o:%.cpp + @$(CXX) -s $(CXXHEADER) $(CXXFLAGS) -c $< -w -o $@ + +clean: + @rm -f $(OBJS) $(TARGET)  diff --git a/study/common.h b/study/common.h new file mode 100644 index 0000000000000000000000000000000000000000..fbdd32fcb6f11e740c7dea26db8d27578e97bb00 --- /dev/null +++ b/study/common.h @@ -0,0 +1,472 @@ +#ifndef COMMON_H +#define COMMON_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// #include "rapidjson/document.h" +// #include "rapidjson/stringbuffer.h" +// #include "rapidjson/writer.h" + +#ifndef PARAMETER_FLOW +#define PARAMETER_FLOW +#define IN +#define OUT +#define INOUT +#endif //PARAMETER_FLOW + +#ifndef BASE_TYPE_DEF +#define BASE_TYPE_DEF +typedef int16_t SHORT; +typedef uint16_t USHORT; +typedef int32_t INT; +typedef uint32_t UINT; +typedef int64_t DLONG; +typedef uint64_t DULONG; +typedef void VOID; +typedef bool BOOL; +typedef char CHAR; +typedef unsigned char UCHAR; +typedef float FLOAT; +typedef double DOUBLE; +#endif //BASE_TYPE_DEF + +// using rapidjson::Document; +// using rapidjson::StringBuffer; +// using rapidjson::Value; +// using rapidjson::Writer; +// using rapidjson::StringRef; + +using std::make_pair; +using std::pair; +using std::string; +using std::vector; +using namespace std; + +#define OUTLEN 255 +#define PI 3.1415926 +#define EARTH_RADIUS 6370.856 //地球近似半径 + +#define TRANSMIT_SERVER_IP "http://192.168.0.200:9870" + +#define MAX_NAME_LEN 256+1 +#define SETTINGS_FILE "Settings.ini" +#define OPTION_FILE "Option.ini" +#define PROCESSNAME ".log" //日志文件后缀 +#define LOG_PATH "log" + +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef unsigned short uint16_t; +typedef signed short int16_t; +typedef unsigned int uint32_t; +typedef signed int int32_t; + +#define put8(p, dat) ( (p)[0] = (uint8_t)((dat)>>0)&0xff ) +#define putle16(p, dat) ( (p)[0] = ((uint16_t)(dat)>>0)&0xff, (p)[1] = ((uint16_t)(dat)>>8)&0xff ) +#define putle24(p, dat) ( (p)[0] = (uint8_t)((uint32_t)(dat)>>0)&0xff, (p)[1] = (uint8_t)((uint32_t)(dat)>>8)&0xff, (p)[2] = (uint8_t)((uint32_t)(dat)>>16)&0xff ) +#define putle32(p, dat) ( (p)[0] = (uint8_t)((uint32_t)(dat)>>0)&0xff, (p)[1] = (uint8_t)((uint32_t)(dat)>>8)&0xff, (p)[2] = (uint8_t)((uint32_t)(dat)>>16)&0xff, (p)[3] = (uint8_t)((uint32_t)(dat)>>24)&0xff ) +#define putle64(p, dat) ( (p)[0] = (uint8_t)((uint64_t)(dat)>>0)&0xff, (p)[1] = (uint8_t)((uint64_t)(dat)>>8)&0xff, (p)[2] = (uint8_t)((uint64_t)(dat)>>16)&0xff, (p)[3] = (uint8_t)((uint64_t)(dat)>>24)&0xff, (p)[4] = (uint8_t)((uint64_t)(dat)>>32)&0xff, (p)[5] = (uint8_t)((uint64_t)(dat)>>40)&0xff, (p)[6] = (uint8_t)((uint64_t)(dat)>>48)&0xff, (p)[7] = (uint8_t)((uint64_t)(dat)>>56)&0xff ) +#define putbe16(p, dat) ( (p)[0] = ((uint16_t)(dat)>>8)&0xff, (p)[1] = ((uint16_t)(dat)>>0)&0xff ) +#define putbe24(p, dat) ( (p)[0] = (uint8_t)((uint32_t)(dat)>>16)&0xff, (p)[1] = (uint8_t)((uint32_t)(dat)>>8)&0xff, (p)[2] = (uint8_t)((uint32_t)(dat)>>0)&0xff ) +#define putbe32(p, dat) ( (p)[0] = (uint8_t)((uint32_t)(dat)>>24)&0xff, (p)[1] = (uint8_t)((uint32_t)(dat)>>16)&0xff, (p)[2] = (uint8_t)((uint32_t)(dat)>>8)&0xff, (p)[3] = (uint8_t)((uint32_t)(dat)>>0)&0xff ) +#define putbe64(p, dat) ( (p)[0] = (uint8_t)((uint64_t)(dat)>>56)&0xff, (p)[1] = (uint8_t)((uint64_t)(dat)>>48)&0xff, (p)[2] = (uint8_t)((uint64_t)(dat)>>40)&0xff, (p)[3] = (uint8_t)((uint64_t)(dat)>>32)&0xff, (p)[4] = (uint8_t)((uint64_t)(dat)>>24)&0xff, (p)[5] = (uint8_t)((uint64_t)(dat)>>16)&0xff, (p)[6] = (uint8_t)((uint64_t)(dat)>>8)&0xff, (p)[7] = (uint8_t)((uint64_t)(dat)>>0)&0xff ) + +enum ebindstatus{ + unbind = 0, //未绑定 + binding = 1, //绑定中 + binded = 2, //绑定完成 + unbinding = 3 //正在解绑 +}; + +struct stuserver{ + string webserver; + string webserverport; + string gpsserver; + int gpsport; +}; + +struct stumodels{ + int OBD; + int lift; + int NFC; + int GPS; +}; + +struct stuKeyData +{ + bool bsendunbind; + bool bkeycanceldown; + bool bkeyfaultdown; + bool bkeyParkingdown; + bool bkeyburstdown; + bool bkeyrepairdown; +}; + +struct stuNFCData +{ + uint8_t NFCid[4]; + bool bGetNFCID; + long clocktime; + string strNFCid; +}; + +struct stuDisply +{ + string strText; +}; + +struct GPSData +{ + int height; + int speed; + int direction; + double latitude; + double longitude; +}; + +struct stuIO +{ + int iNvrIO; +}; + +struct stuOBD +{ + uint8_t key_status; //钥匙状态 + uint8_t gear; //挡位 + uint8_t Accpedal_amplitude; //加速踏板幅度 + uint8_t water_temperature; //水温 + uint16_t rpm; //转速 + float speed; //车速 + uint8_t Remaining_oil; //剩余油量 + uint8_t Battery_remaining; //剩余电量 + + float oil_consumption; //瞬时油耗 + float oil_Average; //平均油耗 + float oil_total; //累计耗油量 + + uint16_t Mileage; //续航里程 + float total_Mileage; //总里程 + + uint32_t total_rpm; //发动机总转速 + float engine_run_time; //发动机总运行时间 + + stuOBD() + { + key_status = 0; //钥匙状态 + gear = 0; //挡位 + Accpedal_amplitude = 0; //加速踏板幅度 + water_temperature = 0; //水温 + rpm = 0; //转速 + speed = 0; //车速 + Remaining_oil = 0; //剩余油量 + Battery_remaining = 0; //剩余电量 + + oil_consumption = 0; //瞬时油耗 + oil_Average = 0; //平均油耗 + oil_total = 0; //累计耗油量 + + Mileage = 0; //续航里程 + total_Mileage = 0; //总里程 + + total_rpm = 0; //发动机总转速 + engine_run_time = 0; //发动机总运行时间 + } +}; + +struct stuScanData +{ + uint8_t Scanid[3]; //扫描到的挖机id + int Distance; +}; + + +struct stuDiggerData +{ + bool bGetLoadQuality; + bool bHasBindTruck; + bool bHasUnBindTruck; + bool bBindStatus; + bool bGetTruckNum; + bool bGetTruckNummsg; + bool brecvTruckNum; + bool brecvTruckIMEI; + bool bGetDriverID; + bool bGetDiggerNFC; + bool bGetDiggerclock; + bool bbindstatus; + bool bbindstatusmsg; + bool brecvunbind; + bool brecvbindstatus; + bool brecvbindstatusmsg; + uint8_t TruckNum; + uint8_t loadqualified; + uint8_t strTruckNum[8]; + uint8_t DiggerNFC[4]; + uint8_t Diggerclock[4]; + uint8_t Diggerid[3]; + bool bGetTruckID; + bool bPreBind; + bool bGetDiggerID; + vector< stuScanData* > vecScanData; + vector< stuScanData* > vecErasedid; //缓存扫描到的不是当前绑定挖机的id + bool blift; + bool bliftmsg; + int DiggerNum; + bool bPreunbind; + bool bGetTruckIMEI; + bool bGetTruckIMEImsg; + uint8_t strTruckIMEI[32]; +}; + +struct stuTruckData +{ + //bool bGetTruckID; + uint8_t Truckid[3]; + uint8_t DiggerId[3]; + bool bGetDiggerID; + bool bbindstatus; + bool brecvbindstatus; + bool bGetDiggerNum; + bool bGetDiggerNummsg; + bool bGetDiggerDrvID; + int DiggerNum; + uint8_t DiggerDrvID[4]; + bool bGetDistance; + uint8_t distance[4]; + bool btransportend; + bool blocking; + bool blift; + bool brecvdata; + bool brecvunbind; + //bool bbinded; + bool bbinding; + uint8_t strDiggerNum[8]; + bool bBeginLoad; + bool bEndload; + bool bPreunbind; + bool bPreunbindmsg; + uint8_t strDiggerIMEI[32]; + bool bGetDiggerIMEI; + bool bGetDiggerIMEImsg; +}; + +struct stunetstate +{ + bool bconnect; + bool bStopPing; + bool brunwithoutnet; +}; + + +struct stuPolePunchData +{ + uint8_t RFIDNum[2]; + bool bRFIDClock; + deque dRFIDNum; +}; + +struct CommonData +{ + stuKeyData KeyData; + stuDisply Disply; + GPSData Gps; + stuIO IO; + stuOBD OBD; + stuDiggerData DiggerData; + stuTruckData TruckData; + stuNFCData NFCData; + stunetstate NetState; + stuPolePunchData PolePunchData; +}; + +struct URL_Param{ + string key; + string value; +}; + +struct stuCarInfo{ + string bucketVolume; //斗容量 + string createBy; //整车质量 + string createTime; + string currentDriverId; //当前司机id + string currentDriverIpassId; //当前司机一卡通编号 + string currentDriverName; //当前司机名称 + string currentDriverPhone; //当前司机手机号 + string customFeildTemplate; //自定义字段模板 + string deviceId; //当前绑定的通讯设备ID + string enginePower; //发动机功率 + string formerDriverId; //前任司机id + string formerDriverIpassId; //前任司机一卡通编号 + string formerDriverName; //前任司机姓名 + string formerDriverPhone; //前任司机手机号 + string grpId; //集团ID + string id; + string leasePrice; //租赁价格 + string leaseType; //租赁类型;1:对内租赁,2:对外租赁,3:外协车辆 + string model; //型号 + string outsource; //是否外协:0->否;1->是 + string packingCaseHighly; //货箱高度 + string packingCaseLength; //货箱长度 + string packingCaseVolume; //箱体 + string packingCaseWidth; //货箱宽度 + string plateNumber; //车牌号 + string proId; //项目ID + string remark; //备注 + string revision; //乐观锁 + string vehicleCode; //喷码 + string updateBy; //集团ID + string updateTime; + string vehicleBrandId; //车辆品牌id + string vehicleBrandName; //车辆品牌名(冗余字段) + string vehicleHighly; //车辆高度 + string vehicleLength; //车辆长度 + string vehicleOrgId; //车辆组织id + string vehicleOrgName; //车辆组织名 + string vehicleType; //车辆类型:1->自卸车;2->挖机 + string vehicleWidth; //车辆宽度 + string vin; //车架号 + string weight; //整车质量 + string workState; //工作状态;0.正常、1.装车、2.运输、3.维修、4.加油、5.休息、6.临停 +}; + +struct stuRecordData +{ + int uniqueId; + string endAltitude; //运输结束高程 + string endLatitude; //运输结束纬度 + string endLongitude; //运输结束经度 + string endTime; //运输结束时间 + string loadEndTime; //装车结束时间 + string loadStartTime; //装车开始时间 + string lockModelId; //挖机自卸车之间锁定模块id + string qualifiedStatus; //装车质量是否合格;2:不合格;1:合格;0:初始化 + string shiftDay; //班次日期 + string shiftId; //班次id + string shiftName; //班次名称 + string startAltitude; //运输开始高程 + string startLatitude; //运输开始纬度 + string startLongitude; //运输开始经度 + string startTime; //运输开始时间 + string transportDistance; //运输距离 + string vehicleDumperDriverId; //自卸车司机id + string vehicleDumperDriverIpassId; //自卸车司机一卡通编号 + string vehicleDumperDriverName; //自卸车司机名称 + string vehicleDumperDriverPhone; //自卸车司机手机号 + float beginmileage; + float endmileage; + double dstartLatitude; //运输开始纬度 double + double dstartLongitude; //运输开始经度 double + string jsonstr; + + stuRecordData() + { + beginmileage = 0; + endmileage = 0; + } +}; + + +//点坐标 +struct Point +{ + double X;//X坐标 + double Y;//Y坐标 + + Point(double dx, double dy) + { + X = dx; + Y = dy; + } +}; + +typedef struct file_list +{ + time_t file_ctime; + string file_name; +}file_list_t; + +//common name space,all common code is here +/* +namespace common +{ + void trimall(string &s); + vector split(string str, const char token); + pair exeShellCmd(IN const string &cmd, OUT string &results); + string GetCPUSerial(); + int code_convert(char *from_charset,char *to_charset,char *inbuf,int inlen,char *outbuf,int outlen); + int u2g(char *inbuf,int inlen,char *outbuf,int outlen); + int g2u(char *inbuf,size_t inlen,char *outbuf,size_t outlen); + string gbkToUtf8(char *inbuf); + string Utf8Togbk(char *inbuf); + int getascii(char *rstr, unsigned char *dstr); + unsigned int GetCRC16(unsigned char *ptr, unsigned char len); + int ze_string_to_bcd(const char *str, uint8_t *bcd, int bcd_len); + uint8_t bb_calc_crc(uint8_t *bufptr, int buflen); + int bb_packet_decode(uint8_t *sptr, int slen, uint8_t *dptr, int dlen); + int bb_packet_encode(uint8_t *sptr, int slen, uint8_t *dptr, int dlen); + uint16_t bswap_16(uint16_t x); + uint32_t bswap_32(uint32_t x); + bool HexToString(char* pInput, char* pOutput, int len); + void SendToTTL(char* Text); + time_t getcurrenttime(); + string GetTimeString(); + int searchdir(std::string path, vector& filelist); + int searchdir(std::string strpath, vector &filelist); + void WriteLog(const char *fm, ...); + int strtohex(string strdata, uint8_t *dptr); + void hexToBytes(const std::string& hex, uint8_t * bytes); + string ParamsToJson(vector parms); + string ParamsToUrlcode(vector parms); + double radian(double d); // 求弧度 + double get_distance(double lat1, double lng1, double lat2, double lng2); //根据经纬度计算两点之间的距离 + // void HandleChild(Value &object); + std::string HandleJsonString(const char* jsonString); + string GetNumberFromString(string text); + bool IsPointInPolygon(const Point& vtPoint, const vector& vecPoints); //判断点是否落在多边形内 + int SocketConnected(int sockfd); + bool isSingleProcess(); + string GetOptionPath(int type); + string GetSettingsPath(int type); + unsigned char ToHex(unsigned char x); + unsigned char FromHex(unsigned char x); + string UrlEncode(const std::string& str); + string UrlDecode(const std::string& str); + void longToHex(long ldata, uint8_t * Hexbytes); + vector MySplit(const string& str, const string& pattern);//输入要分割的字符串和分割的方式 + bool contains(std::string str, std::string substr); //检查一个字符串是否包含另一个字符串 +}; +*/ +#endif // COMMON_H diff --git a/study/htcomhex/Makefile b/study/htcomhex/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..64040b423f9782f262e6b143dd720ff45ebfc1ed --- /dev/null +++ b/study/htcomhex/Makefile @@ -0,0 +1,9 @@ +CROSS=aarch64-linux- + +all: htcomhex + +htcomhex: + $(CROSS)gcc -o htcomhex htcomhex.c + +clean: + @rm -vf htcomhex *.o *~ diff --git a/study/htcomhex/htcomhex b/study/htcomhex/htcomhex new file mode 100644 index 0000000000000000000000000000000000000000..28a683e2e6bedceade66ce9dd4c5280aea71786a Binary files /dev/null and b/study/htcomhex/htcomhex differ diff --git a/study/htcomhex/htcomhex.c b/study/htcomhex/htcomhex.c new file mode 100644 index 0000000000000000000000000000000000000000..8db780b59c6caceb97e2985bd0ba25c7b3fa0252 --- /dev/null +++ b/study/htcomhex/htcomhex.c @@ -0,0 +1,314 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include + +int com_fd; + +//´®¿Ú½á¹¹ +typedef struct{ + char prompt; //prompt after reciving data + int baudrate; //baudrate + char databit; //data bits, 5, 6, 7, 8 + char debug; //debug mode, 0: none, 1: debug + char echo; //echo mode, 0: none, 1: echo + char fctl; //flow control, 0: none, 1: hardware, 2: software + char parity; //parity 0: none, 1: odd, 2: even + char stopbit; //stop bits, 1, 2 + const int reserved; //reserved, must be zero +}portinfo_t; +typedef portinfo_t *pportinfo_t; + + +/******************************************* + * ²¨ÌØÂÊת»»º¯Êý£¨ÇëÈ·ÈÏÊÇ·ñÕýÈ·£© +********************************************/ +int convbaud(unsigned long int baudrate) +{ + switch(baudrate){ + case 2400: + return B2400; + case 4800: + return B4800; + case 9600: + return B9600; + case 19200: + return B19200; + case 38400: + return B38400; + case 57600: + return B57600; + case 115200: + return B115200; + default: + return B9600; + } +} + +/******************************************* + * Setup comm attr + * fdcom: ´®¿ÚÎļþÃèÊö·û£¬pportinfo: ´ýÉèÖõĶ˿ÚÐÅÏ¢£¨ÇëÈ·ÈÏ£© + * +********************************************/ +int PortSet(int fdcom, const pportinfo_t pportinfo) +{ + struct termios termios_old, termios_new; + int baudrate, tmp; + char databit, stopbit, parity, fctl; + + bzero(&termios_old, sizeof(termios_old)); + bzero(&termios_new, sizeof(termios_new)); + cfmakeraw(&termios_new); + tcgetattr(fdcom, &termios_old); //get the serial port attributions + /*------------ÉèÖö˿ÚÊôÐÔ----------------*/ + //baudrates + baudrate = convbaud(pportinfo -> baudrate); + cfsetispeed(&termios_new, baudrate); //ÌîÈë´®¿ÚÊäÈë¶ËµÄ²¨ÌØÂÊ + cfsetospeed(&termios_new, baudrate); //ÌîÈë´®¿ÚÊä³ö¶ËµÄ²¨ÌØÂÊ + termios_new.c_cflag |= CLOCAL; //¿ØÖÆģʽ£¬±£Ö¤³ÌÐò²»»á³ÉΪ¶Ë¿ÚµÄÕ¼ÓÐÕß + termios_new.c_cflag |= CREAD; //¿ØÖÆģʽ£¬Ê¹Äܶ˿ڶÁÈ¡ÊäÈëµÄÊý¾Ý + + // ¿ØÖÆģʽ£¬flow control + fctl = pportinfo-> fctl; + switch(fctl){ + case '0':{ + termios_new.c_cflag &= ~CRTSCTS; //no flow control + }break; + case '1':{ + termios_new.c_cflag |= CRTSCTS; //hardware flow control + }break; + case '2':{ + termios_new.c_iflag |= IXON | IXOFF |IXANY; //software flow control + }break; + } + + //¿ØÖÆģʽ£¬data bits + termios_new.c_cflag &= ~CSIZE; //¿ØÖÆģʽ£¬ÆÁ±Î×Ö·û´óСλ + databit = pportinfo -> databit; + switch(databit){ + case '5': + termios_new.c_cflag |= CS5; + break; + case '6': + termios_new.c_cflag |= CS6; + break; + case '7': + termios_new.c_cflag |= CS7; + break; + default: + termios_new.c_cflag |= CS8; + break; + } + + //¿ØÖÆģʽ parity check + parity = pportinfo -> parity; + switch(parity){ + case '0': + termios_new.c_cflag &= ~PARENB; //no parity check + termios_new.c_iflag &= ~INPCK; + break; + case '1': + termios_new.c_cflag |= (PARODD | PARENB); //odd check + termios_new.c_iflag |= INPCK; + break; + case '2': + termios_new.c_cflag |= PARENB; //even check + termios_new.c_cflag &= ~PARODD; + termios_new.c_iflag |= INPCK; + break; + case '3': + termios_new.c_cflag |= (PARODD | PARENB); //mark check + termios_new.c_cflag |= CMSPAR; + break; + case '4': + termios_new.c_cflag |= PARENB; //space check + termios_new.c_cflag &= ~PARODD; + termios_new.c_cflag |= CMSPAR; + break; + } + + //¿ØÖÆģʽ£¬stop bits + stopbit = pportinfo -> stopbit; + if(stopbit == '2'){ + termios_new.c_cflag |= CSTOPB; //2 stop bits + } + else{ + termios_new.c_cflag &= ~CSTOPB; //1 stop bits + } + + //other attributions default + termios_new.c_oflag &= ~OPOST; //Êä³öģʽ£¬Ô­Ê¼Êý¾ÝÊä³ö + termios_new.c_cc[VMIN] = 1; //¿ØÖÆ×Ö·û, ËùÒª¶ÁÈ¡×Ö·ûµÄ×îСÊýÁ¿ + termios_new.c_cc[VTIME] = 1; //¿ØÖÆ×Ö·û, ¶ÁÈ¡µÚÒ»¸ö×Ö·ûµÄµÈ´ýʱ¼ä unit: (1/10)second + + tcflush(fdcom, TCIFLUSH); //Òç³öµÄÊý¾Ý¿ÉÒÔ½ÓÊÕ£¬µ«²»¶Á + tmp = tcsetattr(fdcom, TCSANOW, &termios_new); //ÉèÖÃÐÂÊôÐÔ£¬TCSANOW£ºËùÓиıäÁ¢¼´ÉúЧ tcgetattr(fdcom, &termios_old); + return(tmp); +} + +/******************************************** + * send data + * fdcom: ´®¿ÚÃèÊö·û£¬data: ´ý·¢ËÍÊý¾Ý£¬datalen: Êý¾Ý³¤¶È + * ·µ»Øʵ¼Ê·¢Ëͳ¤¶È +*********************************************/ +int PortSend(int fdcom, char *data, int datalen) +{ + int len = 0; + + len = write(fdcom, data, datalen); //ʵ¼ÊдÈëµÄ³¤¶È + usleep(500); + sleep(3); + tcflush(fdcom, TCOFLUSH); + if(len == datalen){ + return (len); + } + else{ + tcflush(fdcom, TCOFLUSH); + return -1; + } +} + +/******************************************* + * receive data + * ·µ»Øʵ¼Ê¶ÁÈëµÄ×Ö½ÚÊý + * +********************************************/ +int PortRecv(int fdcom, char *data, int datalen) +{ + int readlen, fs_sel; + fd_set fs_read; + struct timeval tv_timeout; + + FD_ZERO(&fs_read); + FD_SET(fdcom, &fs_read); + tv_timeout.tv_sec = 0; + tv_timeout.tv_usec = 20000; + + fs_sel = select(fdcom+1, &fs_read, NULL, NULL, &tv_timeout); + if(fs_sel){ + usleep(50000); + readlen = read(fdcom, data, datalen); + return(readlen); + } + else{ + return(-1); + } + + return (readlen); +} + +int main(int argc, char *argv[]) +{ + + int Txlen,i; + int tmpData[100],k; + char sendData[100]; + int RxLen; + char rxData[100]; + + portinfo_t portinfo ={ + '0', // print prompt after receiving + 9600, // baudrate: 9600 + '8', // databit: 8 + '0', // debug: off + '0', // echo: off + '0', // flow control: none + '0', // parity: none + '1', // stopbit: 1 + 0 // reserved + }; + + if(argc != 3) + { + printf("Wrong argc number,exit!\n"); + exit(1); + } + + com_fd = open(argv[1], O_RDWR | O_NOCTTY | O_NONBLOCK); + if(com_fd<0) + { + printf("Open Com failed,exit!\n"); + exit(1); + } + + portinfo.baudrate = atoi(argv[2]); + PortSet(com_fd, &portinfo); + + //printf("Please input send data in Hex:\n"); + + /*for(i=0;i<100;i++) + { + + scanf("%x",&tmpData[i]); + k=getchar(); + if(k=='\n') + { + Txlen=i+1; + break; + } + }*/ + + char sz[64] = "DA001"; + char tz[64] = "DA002"; + //scanf("%s",sz); + + + /*printf("Prepare to send data:\n"); + for(i=0;i 0) + { + //printf("%s",rxData); + //fflush(stdout); + printf("recv %d data:",RxLen); + for(i=0;i + +#include "./CSerialPort/CSerialPort.h" +#include "./CScreenCom/CScreenCom.h" +#include "./Log/Log.h" +using namespace std; +int main() { + CScreenCom csSreenCom; + csSreenCom.sendtoscreen("123",3); + return 0; +} diff --git a/study/main.o b/study/main.o new file mode 100644 index 0000000000000000000000000000000000000000..eb4a85f7fbffa06f8ee812741796e957dd70ef84 Binary files /dev/null and b/study/main.o differ diff --git a/study/student/Makefile b/study/student/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..496a1277993fb99946a2786be5cabff0902819f5 --- /dev/null +++ b/study/student/Makefile @@ -0,0 +1,24 @@ +#以下是指定编译器路径 +CXX=aarch64-linux-g++ + +#以下是指定编译需要的头文件 +#CXXHEADER=-I./Serial + + +SRCS=a.cpp +#SRCS+=./Serial/Serial.cpp \ + +#以下是指定.o文件 +OBJS=$(SRCS:.cpp=.o) + +#以下是生成可执行文件 +TARGET=test + +$(TARGET):$(OBJS) + $(CXX) -s $(CXXHEADER) $(OBJS) -o $(TARGET) $(LIBS) $(CXXFLAGS) + +%.o:%.cpp + @$(CXX) -s $(CXXHEADER) $(CXXFLAGS) -c $< -w -o $@ + +clean: + @rm -f $(OBJS) $(TARGET) diff --git a/study/student/a.cpp b/study/student/a.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f335be845a97bae612aab863121c6469e40f1a3 --- /dev/null +++ b/study/student/a.cpp @@ -0,0 +1,115 @@ +#include +#include +#include + +// 定义学生结构体 +struct Student { + char name[20]; + int age; + float score; +}; + +// 声明函数 +void addStudent(struct Student *students, int size); +void deleteStudent(struct Student *students, int size); +void displayStudents(struct Student *students, int size); + +int main() { + // 初始化学生数组 + struct Student students[50]; + int size = 0; + + while (1) { + // 输出菜单 + printf("\n\n"); + printf("--- 学生管理系统 ---\n"); + printf("1. 添加学生\n"); + printf("2. 删除学生\n"); + printf("3. 查看所有学生\n"); + printf("4. 退出程序\n"); + + // 获取用户输入 + int choice; + printf("请输入菜单编号:"); + scanf("%d", &choice); + + // 根据用户选择调用相应的函数 + switch (choice) { + case 1: + addStudent(students, size); + size++; + break; + case 2: + deleteStudent(students, size); + if (size > 0) { + size--; + } + break; + case 3: + displayStudents(students, size); + break; + case 4: + exit(0); + break; + default: + printf("无效的菜单编号!\n"); + break; + } + } + + return 0; +} + +// 添加学生函数 +void addStudent(struct Student *students, int size) { + // 获取用户输入 + printf("请输入学生姓名:"); + scanf("%s", students[size].name); + printf("请输入学生年龄:"); + scanf("%d", &students[size].age); + printf("请输入学生成绩:"); + scanf("%f", &students[size].score); + + printf("成功添加学生:%s\n", students[size].name); +} + +// 删除学生函数 +void deleteStudent(struct Student *students, int size) { + // 获取用户输入 + char name[20]; + printf("请输入要删除的学生姓名:"); + scanf("%s", name); + + // 查找是否存在该学生 + int i; + for (i = 0; i < size; i++) { + if (strcmp(students[i].name, name) == 0) { + printf("成功删除学生:%s\n", students[i].name); + + // 将后面的学生向前移动 + int j; + for (j = i; j < size - 1; j++) { + students[j] = students[j + 1]; + } + + // 清空最后一个学生结构体 + strcpy(students[size - 1].name, ""); + students[size - 1].age = 0; + students[size - 1].score = 0; + + return; + } + } + + printf("未找到该学生!\n"); +} + +// 显示所有学生函数 +void displayStudents(struct Student *students, int size) { + printf("当前共有 %d 名学生:\n", size); + + int i; + for (i = 0; i < size; i++) { + printf("姓名:%s,年龄:%d,成绩:%g\n", students[i].name, students[i].age, students[i].score); + } +} diff --git a/study/student/a.o b/study/student/a.o new file mode 100644 index 0000000000000000000000000000000000000000..33865a02f506b4ed13b27938a67b3e9be8d5abe1 Binary files /dev/null and b/study/student/a.o differ diff --git a/study/student/test b/study/student/test new file mode 100644 index 0000000000000000000000000000000000000000..ead57c45123dfee7e7279b4355f0ab8c4f384016 Binary files /dev/null and b/study/student/test differ diff --git a/study/test b/study/test new file mode 100644 index 0000000000000000000000000000000000000000..2c44cd7bbe0ca73110e5dc8d8a78bf9df4576fbc Binary files /dev/null and b/study/test differ diff --git a/truckdispatch/Serial/CTruckRecv485Thread.cpp b/truckdispatch/Serial/CTruckRecv485Thread.cpp index edd608e2b129574b55d76497f4f5ebfa63b38406..65e6ab2943ab61f3693d28a522d9cf2085512670 100644 --- a/truckdispatch/Serial/CTruckRecv485Thread.cpp +++ b/truckdispatch/Serial/CTruckRecv485Thread.cpp @@ -215,4 +215,6 @@ bool CTruckRecv485Thread::IsFindID(vector &vecID, uint8_t *id) } } return ret; -} \ No newline at end of file +} + +common::WriteLog("[%s,%d,%s]:%s", __FILE__, __LINE__, __func__, "eww"); \ No newline at end of file diff --git a/truckdispatch/SerialCom/CSerialPort.h b/truckdispatch/SerialCom/CSerialPort.h index a0e9888fb6f499bf26907ec7667f611cae1a7b5d..54b8dba7a26abe1dd137d46f37014542cedda01b 100644 --- a/truckdispatch/SerialCom/CSerialPort.h +++ b/truckdispatch/SerialCom/CSerialPort.h @@ -2,7 +2,7 @@ #define CSERIALPORT_H /*串口数据处理类*/ -#include "common.h" +#include "com2mon.h" #include #include