添加debug重定向,添加命令行
This commit is contained in:
		| @@ -65,6 +65,14 @@ public: | |||||||
|   myarray mid(qsizetype index,qsizetype len=-1LL){ |   myarray mid(qsizetype index,qsizetype len=-1LL){ | ||||||
|     return myarray(QByteArray::mid(index,len)); |     return myarray(QByteArray::mid(index,len)); | ||||||
|   } |   } | ||||||
|  |   QList<myarray> split(char sep){ | ||||||
|  |     QByteArrayList list=QByteArray::split(sep); | ||||||
|  |     QList<myarray> myarrlist; | ||||||
|  |     foreach (QByteArray qb, list) { | ||||||
|  |       myarrlist.append(myarray(qb)); | ||||||
|  |     }; | ||||||
|  |     return myarrlist; | ||||||
|  |   } | ||||||
| }; | }; | ||||||
|  |  | ||||||
| class mystring : public QString | class mystring : public QString | ||||||
|   | |||||||
| @@ -4,7 +4,6 @@ | |||||||
| #include "QDir" | #include "QDir" | ||||||
|  |  | ||||||
| // 配置路径 | // 配置路径 | ||||||
| #define CFG_PATH mystring("/home/root/config/") |  | ||||||
| #define CHECK_CFG_FILE_NAME cfg_->def_check_cfg | #define CHECK_CFG_FILE_NAME cfg_->def_check_cfg | ||||||
|  |  | ||||||
| check_range my_json::json_to_range(QJsonValue v) | check_range my_json::json_to_range(QJsonValue v) | ||||||
| @@ -55,12 +54,6 @@ check_cfg::check_cfg() | |||||||
|   this->cfg_ = syscfg(); |   this->cfg_ = syscfg(); | ||||||
|   this->scheme_ = nullptr; |   this->scheme_ = nullptr; | ||||||
|  |  | ||||||
|   QDir path; |  | ||||||
|   if (!path.exists(CFG_PATH)) |  | ||||||
|   { |  | ||||||
|     path.mkdir(CFG_PATH); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   reload(); |   reload(); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -89,7 +82,7 @@ void check_cfg::scheme_json_to_struct() | |||||||
|     scheme_->task_num = get_check_task_num(); |     scheme_->task_num = get_check_task_num(); | ||||||
|     scheme_->timeout_m = get_check_time_out(); |     scheme_->timeout_m = get_check_time_out(); | ||||||
|     scheme_->marerr_num = errs.size(); |     scheme_->marerr_num = errs.size(); | ||||||
|     qDebug("scheme,id=%d,task_num=%d",scheme_->plan_id,scheme_->task_num); |     qDebug("scheme,id=%d,task_num=%d", scheme_->plan_id, scheme_->task_num); | ||||||
|     for (int i = 0; i < scheme_->task_num; i++) |     for (int i = 0; i < scheme_->task_num; i++) | ||||||
|     { |     { | ||||||
|       scheme_task_def *st = &scheme_->task[i]; |       scheme_task_def *st = &scheme_->task[i]; | ||||||
| @@ -102,10 +95,10 @@ void check_cfg::scheme_json_to_struct() | |||||||
|       QList<check_range> rangs = ct.get_ranges(); |       QList<check_range> rangs = ct.get_ranges(); | ||||||
|       int rangs_num = rangs.size(); |       int rangs_num = rangs.size(); | ||||||
|       int err_num = ret_errs.size(); |       int err_num = ret_errs.size(); | ||||||
|       qDebug("st,err,item_num=%d,taskid=%d,taskindex=%d",st->item_num,st->taskid,st->taskindex); |       qDebug("st,err,item_num=%d,taskid=%d,taskindex=%d", st->item_num, st->taskid, st->taskindex); | ||||||
|       for (int i = 0; i < st->item_num; i++) |       for (int i = 0; i < st->item_num; i++) | ||||||
|       { |       { | ||||||
|         qDebug("\ti=%d",i); |         qDebug("\ti=%d", i); | ||||||
|         if (rangs_num > i) |         if (rangs_num > i) | ||||||
|         { |         { | ||||||
|           st->range[i].err = 0; |           st->range[i].err = 0; | ||||||
| @@ -162,7 +155,7 @@ bool check_cfg::updata(QString jstring) | |||||||
|   json_doc = QJsonDocument::fromJson(jstring.toUtf8(), &err); |   json_doc = QJsonDocument::fromJson(jstring.toUtf8(), &err); | ||||||
|   if (err.error != QJsonParseError::NoError) |   if (err.error != QJsonParseError::NoError) | ||||||
|   { |   { | ||||||
|     qWarning("parse json failed:%s",err.errorString().toLocal8Bit().data()); |     qWarning("parse json failed:%s", err.errorString().toLocal8Bit().data()); | ||||||
|     qWarning() << jstring; |     qWarning() << jstring; | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
| @@ -495,7 +488,7 @@ QList<check_err> check_cfg::get_ch_merrcode() | |||||||
|   if (!ch_errcode.isEmpty()) |   if (!ch_errcode.isEmpty()) | ||||||
|   { |   { | ||||||
|     // 有子错误没找到主错误 |     // 有子错误没找到主错误 | ||||||
|     qWarning()<<"many suberr left.%d"<<ch_errcode; |     qWarning() << "many suberr left.%d" << ch_errcode; | ||||||
|   } |   } | ||||||
|   return l; |   return l; | ||||||
| } | } | ||||||
| @@ -511,7 +504,7 @@ bool check_cfg::in_err_range(QList<check_err> &l, uint8_t code) | |||||||
|       return true; |       return true; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   qDebug("can not find mcode,subcode=%d",code); |   qDebug("can not find mcode,subcode=%d", code); | ||||||
|   return false; |   return false; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										114
									
								
								base/debug.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								base/debug.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,114 @@ | |||||||
|  |  | ||||||
|  | #include <QFile> | ||||||
|  | #include <QMessageLogger> | ||||||
|  | #include <qlogging.h> | ||||||
|  | #include <QFile> | ||||||
|  | #include <QTextStream> | ||||||
|  | #include <QDateTime> | ||||||
|  | #include <QString> | ||||||
|  | #include "base/mycfg.h" | ||||||
|  | #include <QUdpSocket> | ||||||
|  | #include <QDir> | ||||||
|  | #include "QApplication" | ||||||
|  | #include "QMutex" | ||||||
|  |  | ||||||
|  | #define FILE_PATH "/home/root/log/" | ||||||
|  | #define FILE_NAME "_log.txt" | ||||||
|  |  | ||||||
|  | char *msgHead[] = | ||||||
|  |     { | ||||||
|  |         (char *)"Debug   ", | ||||||
|  |         (char *)"Warning ", | ||||||
|  |         (char *)"Critical", | ||||||
|  |         (char *)"Fatal   ", | ||||||
|  |         (char *)"Info    "}; | ||||||
|  |  | ||||||
|  | struct mydebug | ||||||
|  | { | ||||||
|  |   QFile *file; | ||||||
|  |   QUdpSocket *socket_; | ||||||
|  |   QByteArray send_data; | ||||||
|  |   QHostAddress host_addr; | ||||||
|  |   quint16 port; | ||||||
|  |   bool active; | ||||||
|  |   void (*send_data_fun)(QByteArray data); | ||||||
|  |   QMutex  mutex; | ||||||
|  |   // QList<QString> type_filter; | ||||||
|  |   // QList<QString> file_filter; | ||||||
|  |   // QList<filter_line> line_filter; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | static mydebug g_debug; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | void print_to_console(QtMsgType type, const QMessageLogContext &context, const QString &msg); | ||||||
|  | void print_to_file(QtMsgType type, const QMessageLogContext &context, const QString &msg); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // 创建日志文件,名称用于创建日志文件 | ||||||
|  | void mydebug_init(QString name) | ||||||
|  | { | ||||||
|  |   qSetMessagePattern("[%{type}] %{time yyyy-MM-dd hh:mm:ss.zzz}  %{function}:%{line} %{message}"); | ||||||
|  |   QDir tempDir; | ||||||
|  |   if (!tempDir.exists(FILE_PATH)) | ||||||
|  |   { | ||||||
|  |     tempDir.mkpath(FILE_PATH); | ||||||
|  |   } | ||||||
|  |   if (g_debug.file != nullptr) | ||||||
|  |   { | ||||||
|  |     delete g_debug.file; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   g_debug.file = new QFile(FILE_PATH + name + FILE_NAME); | ||||||
|  |   qInfo() << "set log file as " << g_debug.file->fileName(); | ||||||
|  |   if (g_debug.file->exists()) | ||||||
|  |   { | ||||||
|  |     if (g_debug.file->remove() != true) | ||||||
|  |       qWarning() << "remove file " << g_debug.file->fileName() << "err"; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   if (!g_debug.file->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) | ||||||
|  |   { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   qInstallMessageHandler(print_to_file); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void mydebug_init() | ||||||
|  | { | ||||||
|  |   qSetMessagePattern("[%{type}] %{time yyyy-MM-dd hh:mm:ss.zzz}  %{function}:%{line} %{message}"); | ||||||
|  |   qInfo() << "set log as console."; | ||||||
|  |   qInstallMessageHandler(print_to_console); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void print_to_console(QtMsgType type, const QMessageLogContext &context, const QString &msg) | ||||||
|  | { | ||||||
|  |   g_debug.mutex.lock(); | ||||||
|  |   QByteArray localMsg = msg.toLocal8Bit(); | ||||||
|  |   QString current_date_time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz"); | ||||||
|  |   Q_UNUSED(current_date_time); | ||||||
|  |   if(context.file!=0){ | ||||||
|  |     fprintf(stderr, "%s | %s | %s:%u | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), &context.file[20], context.line, localMsg.constData()); | ||||||
|  |   }else{ | ||||||
|  |     fprintf(stderr,"%s | %s | %s:%u | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), context.file, context.line, localMsg.constData()); | ||||||
|  |   } | ||||||
|  |   g_debug.mutex.unlock(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void print_to_file(QtMsgType type, const QMessageLogContext &context, const QString &msg) | ||||||
|  | { | ||||||
|  |   g_debug.mutex.lock(); | ||||||
|  |   QByteArray localMsg = msg.toLocal8Bit(); | ||||||
|  |   QString current_date_time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz"); | ||||||
|  |   if (g_debug.file) | ||||||
|  |   { | ||||||
|  |     QTextStream tWrite(g_debug.file); | ||||||
|  |     if(context.file!=0){ | ||||||
|  |       tWrite << QString::asprintf("%s | %s | %s:%u | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), &context.file[20], context.line, localMsg.constData()); | ||||||
|  |     }else{ | ||||||
|  |       tWrite << QString::asprintf("%s | %s | %s:%u | %s\n", msgHead[type], current_date_time.toLocal8Bit().constData(), context.file, context.line, localMsg.constData()); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   g_debug.mutex.unlock(); | ||||||
|  | } | ||||||
							
								
								
									
										18
									
								
								base/debug.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								base/debug.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | #ifndef debug_h__ | ||||||
|  | #define debug_h__ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #include "QDebug" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | void mydebug_init(QString name); | ||||||
|  |  | ||||||
|  | void mydebug_init(); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -168,13 +168,13 @@ void mycfg::to_class(mystring str) | |||||||
|   debug_port = j.value("debug_port").toInt(12345); |   debug_port = j.value("debug_port").toInt(12345); | ||||||
|   cmd_port = j.value("cmd_port").toInt(7777); |   cmd_port = j.value("cmd_port").toInt(7777); | ||||||
|   log_redirect = j.value("log_redirect").toString("console"); |   log_redirect = j.value("log_redirect").toString("console"); | ||||||
|   def_check_cfg = j.value("def_check_cfg").toString("checker_ye_cfg.json"); |   def_check_cfg = j.value("def_check_cfg").toString(CFG_PATH+"checker_ye_cfg.json"); | ||||||
|   def_mcu_app = j.value("def_mcu_app").toString("slave_app.pkt"); |   def_mcu_app = j.value("def_mcu_app").toString(CFG_PATH+"slave_app.pkt"); | ||||||
|   use_lua_judge = j.value("use_lua_judge").toBool(false); |   use_lua_judge = j.value("use_lua_judge").toBool(false); | ||||||
|   device_type = j.value("device_type").toString("checker"); |   device_type = j.value("device_type").toString("checker"); | ||||||
|   moter_count = j.value("moter_count").toInt(20000); |   moter_count = j.value("moter_count").toInt(20000); | ||||||
|   uart_bsp = j.value("uart_bsp").toInt(57600); |   uart_bsp = j.value("uart_bsp").toInt(57600); | ||||||
|   def_lua_judge = j.value("lua_judge").toString("judge.lua"); |   def_lua_judge = j.value("lua_judge").toString(CFG_PATH+"judge.lua"); | ||||||
|   coder_return_mode = j.value("coder_return_mode").toInt(1); |   coder_return_mode = j.value("coder_return_mode").toInt(1); | ||||||
|   slave_addr_start = j.value("slave_addr_start").toInt(0); |   slave_addr_start = j.value("slave_addr_start").toInt(0); | ||||||
|   slave_scheme_ext = j.value("slave_scheme_ext").toInt(0); |   slave_scheme_ext = j.value("slave_scheme_ext").toInt(0); | ||||||
| @@ -252,7 +252,7 @@ void mycfg::init_env() | |||||||
|     { |     { | ||||||
|       if (!info.privates.contains(name)) |       if (!info.privates.contains(name)) | ||||||
|       { |       { | ||||||
|         qInfo() << "release file " << file.fileName() << endl; |         qInfo() << "release file " << file.fileName(); | ||||||
|         file.open(QIODevice::ReadWrite); |         file.open(QIODevice::ReadWrite); | ||||||
|         file.write(d); |         file.write(d); | ||||||
|         file.close(); |         file.close(); | ||||||
| @@ -296,7 +296,7 @@ void mycfg::init_env() | |||||||
|       if (md5_1 != md5_2) |       if (md5_1 != md5_2) | ||||||
|       { |       { | ||||||
|         if (file_dst.remove() != true) |         if (file_dst.remove() != true) | ||||||
|           qWarning() << "remove file " << file_dst.fileName() << "err" << endl; |           qWarning() << "remove file " << file_dst.fileName() << "err"; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @@ -304,7 +304,7 @@ void mycfg::init_env() | |||||||
|   { |   { | ||||||
|     if (!QFile::copy(file_src.fileName(), file_dst.fileName())) |     if (!QFile::copy(file_src.fileName(), file_dst.fileName())) | ||||||
|     { |     { | ||||||
|       qWarning() << "copy app failed." << endl; |       qWarning() << "copy app failed."; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   if (file_dst.fileName() != file_src.fileName()) |   if (file_dst.fileName() != file_src.fileName()) | ||||||
| @@ -349,7 +349,7 @@ void mycfg::save() | |||||||
|   if (file.exists()) |   if (file.exists()) | ||||||
|   { |   { | ||||||
|     if (file.remove() != true) |     if (file.remove() != true) | ||||||
|       qWarning() << "remove file " << file.fileName() << "err" << endl; |       qWarning() << "remove file " << file.fileName() << "err"; | ||||||
|   } |   } | ||||||
|   file.open(QIODevice::ReadWrite); |   file.open(QIODevice::ReadWrite); | ||||||
|   QTextStream stream(&file); |   QTextStream stream(&file); | ||||||
| @@ -369,7 +369,7 @@ bool mycfg::save_file(mystring name, myarray data) | |||||||
|   { |   { | ||||||
|     if (file.remove() != true) |     if (file.remove() != true) | ||||||
|     { |     { | ||||||
|       qWarning() << "remove file " << file.fileName() << "err" << endl; |       qWarning() << "remove file " << file.fileName() << "err"; | ||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ SOURCES += \ | |||||||
|     base/base.cpp \ |     base/base.cpp \ | ||||||
|     base/check_cfg.cpp \ |     base/check_cfg.cpp \ | ||||||
|     base/crc.cpp \ |     base/crc.cpp \ | ||||||
|  |     base/debug.cpp \ | ||||||
|     base/mycfg.cpp \ |     base/mycfg.cpp \ | ||||||
|     elec/elec_judge.cpp \ |     elec/elec_judge.cpp \ | ||||||
|     elec/mystring.cpp \ |     elec/mystring.cpp \ | ||||||
| @@ -36,9 +37,11 @@ SOURCES += \ | |||||||
|     interface/interface.cpp \ |     interface/interface.cpp \ | ||||||
|     main.cpp \ |     main.cpp \ | ||||||
|     mainwindow.cpp \ |     mainwindow.cpp \ | ||||||
|  |     prot/prot_cmdline.cpp \ | ||||||
|     prot/prot_m4.cpp \ |     prot/prot_m4.cpp \ | ||||||
|     prot/prot_pc.cpp \ |     prot/prot_pc.cpp \ | ||||||
|     prot/prot_slave.cpp \ |     prot/prot_slave.cpp \ | ||||||
|  |     prot_cmd/cmd_cmdline.cpp \ | ||||||
|     prot_cmd/cmd_pc.cpp \ |     prot_cmd/cmd_pc.cpp \ | ||||||
|     prot_cmd/cmd_slave.cpp |     prot_cmd/cmd_slave.cpp | ||||||
|  |  | ||||||
| @@ -46,6 +49,7 @@ HEADERS += \ | |||||||
|     base/base.h \ |     base/base.h \ | ||||||
|     base/check_cfg.h \ |     base/check_cfg.h \ | ||||||
|     base/crc.h \ |     base/crc.h \ | ||||||
|  |     base/debug.h \ | ||||||
|     base/file.h \ |     base/file.h \ | ||||||
|     base/mycfg.h \ |     base/mycfg.h \ | ||||||
|     elec/elec_judge.h \ |     elec/elec_judge.h \ | ||||||
| @@ -59,6 +63,7 @@ HEADERS += \ | |||||||
|     interface/if_uart.h \ |     interface/if_uart.h \ | ||||||
|     interface/interface.h \ |     interface/interface.h \ | ||||||
|     mainwindow.h \ |     mainwindow.h \ | ||||||
|  |     prot/prot_cmdline.h \ | ||||||
|     prot/prot_m4.h \ |     prot/prot_m4.h \ | ||||||
|     prot/prot_pc.h \ |     prot/prot_pc.h \ | ||||||
|     prot/prot_slave.h \ |     prot/prot_slave.h \ | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ | |||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| #define BUILD_DATE  "2023-11-29 15:29:42" | #define BUILD_DATE  "2023-12-01 11:08:00" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										16
									
								
								info.json
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								info.json
									
									
									
									
									
								
							| @@ -1,10 +1,10 @@ | |||||||
| { | { | ||||||
|     "build_date": "2023-11-29 15:29:42", |   "build_date": "2023-12-01 11:08:00", | ||||||
|     "hard_version": "MHPZ2_V1.00", |   "hard_version": "MHPZ2_V1.00", | ||||||
|     "private": [ |   "private": [ | ||||||
|         "info.json", |     "info.json", | ||||||
|         "json.lua", |     "json.lua", | ||||||
|         "prints.lua" |     "prints.lua" | ||||||
|     ], |   ], | ||||||
|     "soft_version": "V1.09" |   "soft_version": "V2.00" | ||||||
| } | } | ||||||
| @@ -84,6 +84,12 @@ can_host::can_host(int bitrate) | |||||||
|  |  | ||||||
| can_host::~can_host() | can_host::~can_host() | ||||||
| { | { | ||||||
|  |   if(can_ !=nullptr){ | ||||||
|  |     delete can_; | ||||||
|  |   } | ||||||
|  |   if(timer_ !=nullptr){  | ||||||
|  |     delete timer_; | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| // 用于返回指定地址的从机对象 | // 用于返回指定地址的从机对象 | ||||||
|   | |||||||
| @@ -17,6 +17,15 @@ if_tcp::if_tcp() | |||||||
|  |  | ||||||
| if_tcp::~if_tcp() | if_tcp::~if_tcp() | ||||||
| { | { | ||||||
|  |   if(timer_reconnect_!=nullptr){ | ||||||
|  |     delete timer_reconnect_; | ||||||
|  |   } | ||||||
|  |   if(tcp_socket_!=nullptr){ | ||||||
|  |     delete tcp_socket_; | ||||||
|  |   } | ||||||
|  |   if(timer_recv_end_!=nullptr){ | ||||||
|  |     delete timer_recv_end_; | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| void if_tcp::init() | void if_tcp::init() | ||||||
| @@ -88,15 +97,14 @@ void if_tcp::reconnect_cb() | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     // 设置为配置的ip地址 |     // 设置为配置的ip地址 | ||||||
|     // if(QHostAddress(get_local_ip())!=QHostAddress(local_ip)) |     // if (get_local_ip().isEmpty()) | ||||||
|     if (get_local_ip().isEmpty()) |     // { | ||||||
|     { |     //   qDebug("modify local ip addr."); | ||||||
|       qDebug("modify local ip addr."); |     //   QString str = "ifconfig eth0 %1"; | ||||||
|       QString str = "ifconfig eth0 %1"; |     //   system(str.arg(cfg_->local_ip).toLocal8Bit().data()); | ||||||
|       system(str.arg(cfg_->local_ip).toLocal8Bit().data()); |     //   str = "route add default gw %1"; | ||||||
|       str = "route add default gw %1"; |     //   system(str.arg(cfg_->gateway_ip).toLocal8Bit().data()); | ||||||
|       system(str.arg(cfg_->gateway_ip).toLocal8Bit().data()); |     // } | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,43 +4,43 @@ | |||||||
| #include "base/mycfg.h" | #include "base/mycfg.h" | ||||||
| #include "QDebug" | #include "QDebug" | ||||||
|  |  | ||||||
|  |  | ||||||
| void if_uart::init() | void if_uart::init() | ||||||
| { | { | ||||||
|   if(serial_==nullptr) |   if (serial_ == nullptr) | ||||||
|   { |   { | ||||||
|       serial_=new QSerialPort(); |     serial_ = new QSerialPort(); | ||||||
|       serial_->setPortName(com); |     serial_->setPortName(com); | ||||||
|       serial_->setBaudRate(bsp); |     serial_->setBaudRate(bsp); | ||||||
|       serial_->setParity(QSerialPort::NoParity); |     serial_->setParity(QSerialPort::NoParity); | ||||||
|       serial_->setDataBits(QSerialPort::Data8); |     serial_->setDataBits(QSerialPort::Data8); | ||||||
|       serial_->setStopBits(QSerialPort::OneStop); |     serial_->setStopBits(QSerialPort::OneStop); | ||||||
|       serial_->setFlowControl(QSerialPort::NoFlowControl); |     serial_->setFlowControl(QSerialPort::NoFlowControl); | ||||||
|       if(serial_->open(QIODevice::ReadWrite)) |     if (serial_->open(QIODevice::ReadWrite)) | ||||||
|       { |     { | ||||||
|           connect(serial_,&QSerialPort::readyRead,this,&if_uart::ready_read_cb); |       connect(serial_, &QSerialPort::readyRead, this, &if_uart::ready_read_cb); | ||||||
|           qDebug("uart \"%s\" bsp=%d",serial_->portName().toLocal8Bit().data(), bsp); |       qDebug("uart \"%s\" bsp=%d", serial_->portName().toLocal8Bit().data(), bsp); | ||||||
|           serial_open=true; |       serial_open = true; | ||||||
|       } else |     } | ||||||
|       { |     else | ||||||
|           qWarning()<<"uart open failed."<<serial_->portName(); |     { | ||||||
|       } |       qWarning() << "uart open failed." << serial_->portName(); | ||||||
|  |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| int if_uart::write(myarray data) | int if_uart::write(myarray data) | ||||||
| { | { | ||||||
|   if((nullptr == serial_)||(serial_open!=true)) |   if ((nullptr == serial_) || (serial_open != true)) | ||||||
|   { |   { | ||||||
|     //qWarning() << "Can’t send data , TcpClient socket not connect."; |     // qWarning() << "Can’t send data , TcpClient socket not connect."; | ||||||
|     return 0; |     return 0; | ||||||
|   } |   } | ||||||
|   qDebug("uart send:%s",data.toHex(' ').data()); |   qDebug("uart send:%s", data.toHex(' ').data()); | ||||||
|  |  | ||||||
|   int wb = serial_->write(data); |   int wb = serial_->write(data); | ||||||
|   if((!serial_->flush())||(wb!=data.size())) |   if ((!serial_->flush()) || (wb != data.size())) | ||||||
|   { |   { | ||||||
|     //qWarning() << "uart data:"<<data.toHex(' ')<<"not sent."; |     // qWarning() << "uart data:"<<data.toHex(' ')<<"not sent."; | ||||||
|   } |   } | ||||||
|   return wb; |   return wb; | ||||||
| } | } | ||||||
| @@ -48,21 +48,19 @@ int if_uart::write(myarray data) | |||||||
| void if_uart::ready_read_cb() | void if_uart::ready_read_cb() | ||||||
| { | { | ||||||
|   QByteArray data = serial_->readAll(); |   QByteArray data = serial_->readAll(); | ||||||
|   qDebug("uart recv:%s",data.toHex(' ').data()); |   qDebug("uart recv:%s", data.toHex(' ').data()); | ||||||
|   if (irq_fun) |   if (irq_fun) | ||||||
|   { |   { | ||||||
|     irq_fun(myarray(data)); |     irq_fun(myarray(data)); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| InterFace *if_uart_hmi() | InterFace *if_uart_hmi() | ||||||
| { | { | ||||||
|   static InterFace *if_ = nullptr; |   static InterFace *if_ = nullptr; | ||||||
|   if (if_ == nullptr) |   if (if_ == nullptr) | ||||||
|   { |   { | ||||||
|     if_ = new if_uart("/dev/ttySTM1",115200); |     if_ = new if_uart("/dev/ttySTM1", 115200); | ||||||
|     // QTimer::singleShot(0, if_, &InterFace::init); |     // QTimer::singleShot(0, if_, &InterFace::init); | ||||||
|     if_->init(); |     if_->init(); | ||||||
|   } |   } | ||||||
| @@ -71,18 +69,17 @@ InterFace *if_uart_hmi() | |||||||
|  |  | ||||||
| if_export(uart_hmi, if_uart_hmi); | if_export(uart_hmi, if_uart_hmi); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| InterFace *if_uart_host() | InterFace *if_uart_host() | ||||||
| { | { | ||||||
|   static InterFace *if_ = nullptr; |   static InterFace *if_ = nullptr; | ||||||
|   if (if_ == nullptr) |   if (if_ == nullptr) | ||||||
|   { |   { | ||||||
|     int bsp=57600; |     int bsp = 57600; | ||||||
|     if(syscfg()->uart_bsp!=0){ |     if (syscfg()->uart_bsp != 0) | ||||||
|       bsp=syscfg()->uart_bsp; |     { | ||||||
|  |       bsp = syscfg()->uart_bsp; | ||||||
|     } |     } | ||||||
|     if_ = new if_uart("/dev/ttySTM2",bsp); |     if_ = new if_uart("/dev/ttySTM2", bsp); | ||||||
|     // QTimer::singleShot(0, if_, &InterFace::init); |     // QTimer::singleShot(0, if_, &InterFace::init); | ||||||
|     if_->init(); |     if_->init(); | ||||||
|   } |   } | ||||||
| @@ -91,14 +88,12 @@ InterFace *if_uart_host() | |||||||
|  |  | ||||||
| if_export(uart_host, if_uart_host); | if_export(uart_host, if_uart_host); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| InterFace *if_uart_m4() | InterFace *if_uart_m4() | ||||||
| { | { | ||||||
|   static InterFace *if_ = nullptr; |   static InterFace *if_ = nullptr; | ||||||
|   if (if_ == nullptr) |   if (if_ == nullptr) | ||||||
|   { |   { | ||||||
|     if_ = new if_uart("/dev/ttyRPMSG0",115200); |     if_ = new if_uart("/dev/ttyRPMSG0", 115200); | ||||||
|     // QTimer::singleShot(0, if_, &InterFace::init); |     // QTimer::singleShot(0, if_, &InterFace::init); | ||||||
|     if_->init(); |     if_->init(); | ||||||
|   } |   } | ||||||
| @@ -106,4 +101,3 @@ InterFace *if_uart_m4() | |||||||
| } | } | ||||||
|  |  | ||||||
| if_export(uart_m4, if_uart_m4); | if_export(uart_m4, if_uart_m4); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,7 +1,6 @@ | |||||||
| #ifndef if_uart_h__ | #ifndef if_uart_h__ | ||||||
| #define if_uart_h__ | #define if_uart_h__ | ||||||
|  |  | ||||||
|  |  | ||||||
| #include <QObject> | #include <QObject> | ||||||
| #include <interface/interface.h> | #include <interface/interface.h> | ||||||
| #include "QTimer" | #include "QTimer" | ||||||
| @@ -9,43 +8,38 @@ | |||||||
| #include <QTimer> | #include <QTimer> | ||||||
| #include "QByteArray" | #include "QByteArray" | ||||||
| #include "base/mycfg.h" | #include "base/mycfg.h" | ||||||
| #include <QSerialPort>         // 提供访问串口的功能 | #include <QSerialPort>     // 提供访问串口的功能 | ||||||
| #include <QSerialPortInfo>     // 提供系统中存在的串口信息 | #include <QSerialPortInfo> // 提供系统中存在的串口信息 | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class if_uart : public InterFace | class if_uart : public InterFace | ||||||
| { | { | ||||||
|   Q_OBJECT |   Q_OBJECT | ||||||
| public: | public: | ||||||
|   if_uart(mystring com,int bsp):InterFace(){ |   if_uart(mystring com, int bsp) : InterFace() | ||||||
|  |   { | ||||||
|     this->com = com; |     this->com = com; | ||||||
|     this->bsp = bsp; |     this->bsp = bsp; | ||||||
|     serial_=nullptr; |     serial_ = nullptr; | ||||||
|     serial_open=false; |     serial_open = false; | ||||||
|   } |   } | ||||||
|   virtual ~if_uart(){ |   virtual ~if_uart() | ||||||
|     if(serial_open==true){ |   { | ||||||
|  |     if (serial_open == true) | ||||||
|  |     { | ||||||
|       serial_->close(); |       serial_->close(); | ||||||
|       delete serial_; |       delete serial_; | ||||||
|     } |     } | ||||||
|   }; |   } | ||||||
|   void init(); |   void init(); | ||||||
|   int write(myarray data); |   int write(myarray data); | ||||||
| protected slots: | protected slots: | ||||||
|   void ready_read_cb(); |   void ready_read_cb(); | ||||||
| protected: |  | ||||||
|     mystring com; |  | ||||||
|     int bsp; |  | ||||||
|     QSerialPort *serial_; |  | ||||||
|     bool serial_open; |  | ||||||
|  |  | ||||||
|  | protected: | ||||||
|  |   mystring com; | ||||||
|  |   int bsp; | ||||||
|  |   QSerialPort *serial_; | ||||||
|  |   bool serial_open; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								main.cpp
									
									
									
									
									
								
							| @@ -1,5 +1,4 @@ | |||||||
| #include "mainwindow.h" | #include "mainwindow.h" | ||||||
|  |  | ||||||
| #include <QApplication> | #include <QApplication> | ||||||
| #include <QString> | #include <QString> | ||||||
| #include <QDebug> | #include <QDebug> | ||||||
| @@ -11,7 +10,8 @@ | |||||||
| #include "prot/prot_m4.h" | #include "prot/prot_m4.h" | ||||||
| #include "prot/prot_pc.h" | #include "prot/prot_pc.h" | ||||||
| #include "prot/prot_slave.h" | #include "prot/prot_slave.h" | ||||||
|  | #include "prot/prot_cmdline.h" | ||||||
|  | #include "base/debug.h" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -22,11 +22,19 @@ int main(int argc, char *argv[]) | |||||||
|   QApplication app(argc, argv); |   QApplication app(argc, argv); | ||||||
|   MainWindow w; |   MainWindow w; | ||||||
|   // w.show(); |   // w.show(); | ||||||
|   syscfg(); |   mycfg *cfg=syscfg(); | ||||||
|  |  | ||||||
|  |   if(cfg->log_redirect=="file"){ | ||||||
|  |     mydebug_init("debug"); | ||||||
|  |   }else{ | ||||||
|  |     mydebug_init(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   check_plan(); |   check_plan(); | ||||||
|   prot_m4 *m4=protM4(); |   prot_m4 *m4=protM4(); | ||||||
|   protPc(); |   protPc(); | ||||||
|   protSlave(); |   protSlave(); | ||||||
|  |   command_start(); | ||||||
|  |  | ||||||
|   // 获取m4的编译时间 |   // 获取m4的编译时间 | ||||||
|   m4->set_irq_fun([=](myarray data){ |   m4->set_irq_fun([=](myarray data){ | ||||||
|   | |||||||
| @@ -45,7 +45,7 @@ def main(): | |||||||
|             list_str=["info.json","json.lua","prints.lua"] |             list_str=["info.json","json.lua","prints.lua"] | ||||||
|             json_obj["private"]=list_str |             json_obj["private"]=list_str | ||||||
|             f.seek(0, os.SEEK_SET) |             f.seek(0, os.SEEK_SET) | ||||||
|             f.write(json.dumps(json_obj, sort_keys=True, indent=4, separators=(',', ': '))) |             f.write(json.dumps(json_obj, sort_keys=True, indent=2, separators=(',', ': '))) | ||||||
| if __name__=="__main__": | if __name__=="__main__": | ||||||
|     main() |     main() | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										151
									
								
								prot/prot_cmdline.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								prot/prot_cmdline.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,151 @@ | |||||||
|  |  | ||||||
|  | #include "prot_cmdline.h" | ||||||
|  | #include "base/mycfg.h" | ||||||
|  | #include "QNetworkConfigurationManager" | ||||||
|  | #include "QTimer" | ||||||
|  |  | ||||||
|  | prot_cmdline_cb cmdline_find(myarray name) | ||||||
|  | { | ||||||
|  |   extern const int __start_cmdldef; | ||||||
|  |   extern const int __stop_cmdldef; | ||||||
|  |   cmdline_def *start = (cmdline_def *)&__start_cmdldef; | ||||||
|  |   cmdline_def *end = (cmdline_def *)&__stop_cmdldef; | ||||||
|  |   cmdline_def *item = 0; | ||||||
|  |   for (item = start; item < end; item++) | ||||||
|  |   { | ||||||
|  |     if (item != nullptr) | ||||||
|  |     { | ||||||
|  |       if (name == item->cmd) | ||||||
|  |         return item->fun; | ||||||
|  |       // qDebug("if dev: %s",item->name); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   qWarning("can not find cmdline named '%s'", name.data()); | ||||||
|  |   return nullptr; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // 获取本机地址 | ||||||
|  | static QString get_local_ip() | ||||||
|  | { | ||||||
|  |   QList<QNetworkInterface> network = QNetworkInterface::allInterfaces(); | ||||||
|  |   foreach (QNetworkInterface net, network) | ||||||
|  |   { | ||||||
|  |     QString netName = net.humanReadableName(); | ||||||
|  |     if (netName == "eth0") | ||||||
|  |     { | ||||||
|  |       QList<QNetworkAddressEntry> list = net.addressEntries(); // 获取IP地址与子掩码等 | ||||||
|  |       foreach (QNetworkAddressEntry address, list) | ||||||
|  |       { | ||||||
|  |         if (address.ip().protocol() == QAbstractSocket::IPv4Protocol) // 获取IPv4的地址 | ||||||
|  |         { | ||||||
|  |           return address.ip().toString(); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   return QString(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void command::init_cb() | ||||||
|  | { | ||||||
|  |   mycfg *cfg_ = syscfg(); | ||||||
|  |   if (get_local_ip().isEmpty()) | ||||||
|  |   { | ||||||
|  |     qDebug("modify local ip addr."); | ||||||
|  |     QString str = "ifconfig eth0 %1"; | ||||||
|  |     system(str.arg(cfg_->local_ip).toLocal8Bit().data()); | ||||||
|  |     str = "route add default gw %1"; | ||||||
|  |     system(str.arg(cfg_->gateway_ip).toLocal8Bit().data()); | ||||||
|  |   } | ||||||
|  |   if (socket_ == nullptr) | ||||||
|  |   { | ||||||
|  |     socket_ = new QUdpSocket(this); | ||||||
|  |     socket_->bind(QHostAddress::Any, cfg_->cmd_port); | ||||||
|  |     connect(socket_, &QUdpSocket::readyRead, this, &command::ready_read_cb); | ||||||
|  |     qInfo() << "udp command start."; | ||||||
|  |     qInfo() << "cmd port=" << cfg_->cmd_port; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void command::send(QByteArray data) | ||||||
|  | { | ||||||
|  |   if (socket_ == nullptr) | ||||||
|  |     return; | ||||||
|  |   if (data.back() != '\n') | ||||||
|  |   { | ||||||
|  |     data.append('\n'); | ||||||
|  |   } | ||||||
|  |   socket_->writeDatagram(data, host_addr, port); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static void cmdline_help(QList<myarray> args); | ||||||
|  | void command::ready_read_cb() | ||||||
|  | { | ||||||
|  |   recv_data.resize(socket_->bytesAvailable()); | ||||||
|  |   socket_->readDatagram(recv_data.data(), recv_data.size(), &host_addr, &port); | ||||||
|  |   myarray cmd = recv_data.simplified(); | ||||||
|  |   QList<myarray> args=cmd.split(' '); | ||||||
|  |   if(args.size()>0){ | ||||||
|  |     prot_cmdline_cb fun=cmdline_find(args[0]); | ||||||
|  |     if(fun!=nullptr){ | ||||||
|  |       fun(args); | ||||||
|  |     }else{ | ||||||
|  |       mystring str; | ||||||
|  |       str=mystring::asprintf("can not find command: %s",cmd.data()); | ||||||
|  |       send(str.data()); | ||||||
|  |       cmdline_help(args); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   qInfo() << "udp command." << cmd; | ||||||
|  |   recv_data.clear(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | static void cmdline_help(QList<myarray> args) | ||||||
|  | { | ||||||
|  |   command *c=command_start(); | ||||||
|  |   extern const int __start_cmdldef; | ||||||
|  |   extern const int __stop_cmdldef; | ||||||
|  |   cmdline_def *start = (cmdline_def *)&__start_cmdldef; | ||||||
|  |   cmdline_def *end = (cmdline_def *)&__stop_cmdldef; | ||||||
|  |   cmdline_def *item = 0; | ||||||
|  |   for (item = start; item < end; item++) | ||||||
|  |   { | ||||||
|  |     if (item != nullptr) | ||||||
|  |     { | ||||||
|  |       QByteArray send_data; | ||||||
|  |       send_data.append(item->cmd); | ||||||
|  |       send_data.append(30-send_data.size(),'.'); | ||||||
|  |       send_data.append(item->help); | ||||||
|  |       c->send(send_data); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | cmdline_export(help,cmdline_help,print help information.); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |   | ||||||
|  |  | ||||||
|  |  | ||||||
|  | static command *g_command; | ||||||
|  | static QThread g_thread; | ||||||
|  | command *command_start() | ||||||
|  | { | ||||||
|  |   if (g_command == nullptr) | ||||||
|  |   { | ||||||
|  |     g_command = new command(); | ||||||
|  |     g_command->moveToThread(&g_thread); | ||||||
|  |     QTimer::singleShot(0, g_command, &command::init_cb); | ||||||
|  |     g_thread.start(); | ||||||
|  |   } | ||||||
|  |   return g_command; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										66
									
								
								prot/prot_cmdline.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								prot/prot_cmdline.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | |||||||
|  |  | ||||||
|  | #ifndef prot_cmdline_h__ | ||||||
|  | #define prot_cmdline_h__ | ||||||
|  |  | ||||||
|  | #include "QObject" | ||||||
|  | #include "base/base.h" | ||||||
|  | #include "QList" | ||||||
|  | #include "interface/codec.h" | ||||||
|  | #include "interface/interface.h" | ||||||
|  | #include "base/mycfg.h" | ||||||
|  | #include "QThread" | ||||||
|  | #include <QNetworkInterface> | ||||||
|  | #include <QUdpSocket> | ||||||
|  |  | ||||||
|  | // using namespace std; | ||||||
|  | // using namespace std::placeholders; | ||||||
|  |  | ||||||
|  | // typedef std::function<void(myarray data)> prot_cmdline_cb; | ||||||
|  | typedef void (*prot_cmdline_cb)(QList<myarray> data); | ||||||
|  |  | ||||||
|  | typedef struct | ||||||
|  | { | ||||||
|  |   const char *cmd; | ||||||
|  |   const char *help; | ||||||
|  |   prot_cmdline_cb fun; | ||||||
|  | } cmdline_def; | ||||||
|  |  | ||||||
|  | #define cmdline_export(name_, fun_, help_)                                                           \ | ||||||
|  |   const static char __cmdline_##name_##_name[] __attribute__((section(".rodata.cmdlstr"))) = #name_; \ | ||||||
|  |   const static char __cmdline_##name_##_help[] __attribute__((section(".rodata.cmdlstr"))) = #help_; \ | ||||||
|  |   __attribute__((used)) static cmdline_def _cmdline_##name_ __attribute__((section("cmdldef"))) = {  \ | ||||||
|  |       .cmd = __cmdline_##name_##_name,                                                               \ | ||||||
|  |       .help = __cmdline_##name_##_help,                                                              \ | ||||||
|  |       .fun = fun_,                                                                                   \ | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | class command : public QObject | ||||||
|  | { | ||||||
|  |   Q_OBJECT | ||||||
|  | public: | ||||||
|  |   command() | ||||||
|  |   { | ||||||
|  |     socket_ = nullptr; | ||||||
|  |   } | ||||||
|  |   virtual ~command() | ||||||
|  |   { | ||||||
|  |     if (socket_ != nullptr) | ||||||
|  |       delete socket_; | ||||||
|  |   } | ||||||
|  |   void send(QByteArray data); | ||||||
|  |   void init_cb(); | ||||||
|  |   void ready_read_cb(); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  |   QUdpSocket *socket_; | ||||||
|  |   QByteArray recv_data; | ||||||
|  |   QHostAddress host_addr; | ||||||
|  |   quint16 port; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | command *command_start(); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #endif | ||||||
							
								
								
									
										48
									
								
								prot_cmd/cmd_cmdline.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								prot_cmd/cmd_cmdline.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | #include "prot/prot_cmdline.h" | ||||||
|  | #include "base/mycfg.h" | ||||||
|  | #include "QNetworkConfigurationManager" | ||||||
|  | #include "QTimer" | ||||||
|  | #include "QtNetwork" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // 获取设备基本信息 | ||||||
|  | static void whos(QList<myarray> args) | ||||||
|  | { | ||||||
|  |   QString out; | ||||||
|  |   QString name = "local_id:%1,name:%2"; | ||||||
|  |   QString hostName = QHostInfo::localHostName(); | ||||||
|  |   command *c=command_start(); | ||||||
|  |   mycfg *cfg_=syscfg(); | ||||||
|  |   name = name.arg(cfg_->local_id).arg(hostName); | ||||||
|  |   out.append(name + "\n"); | ||||||
|  |   out.append("builed time:" + cfg_->build_date + "\n"); | ||||||
|  |   QList<QNetworkInterface> network = QNetworkInterface::allInterfaces(); | ||||||
|  |   foreach (QNetworkInterface net, network) | ||||||
|  |   { | ||||||
|  |     QString str = "net:%1"; | ||||||
|  |     QString netName = net.humanReadableName(); | ||||||
|  |     str = str.arg(netName); | ||||||
|  |     out.append(str + "\n"); | ||||||
|  |     QList<QNetworkAddressEntry> list = net.addressEntries(); // 获取IP地址与子掩码等 | ||||||
|  |     foreach (QNetworkAddressEntry address, list) | ||||||
|  |     { | ||||||
|  |       QString str = "ip:%1"; | ||||||
|  |       if (address.ip().protocol() == QAbstractSocket::IPv4Protocol) // 获取IPv4的地址 | ||||||
|  |       { | ||||||
|  |         out.append(str.arg(address.ip().toString()) + "\n"); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   out = "ack:1," + out; | ||||||
|  |   c->send(out.toLocal8Bit()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | cmdline_export(whos, whos, print device base info.); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -211,7 +211,7 @@ static HandlePc *get_selfdev_slaveupdate(){ | |||||||
|   return new selfdev_slaveupdate(); |   return new selfdev_slaveupdate(); | ||||||
| } | } | ||||||
|  |  | ||||||
| protpc_export(0x40, get_selfdev_slaveupdate); | protpc_export(0x41, get_selfdev_slaveupdate); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ | |||||||
| #define cmd_pc_h__ | #define cmd_pc_h__ | ||||||
|  |  | ||||||
| #include "prot/prot_pc.h" | #include "prot/prot_pc.h" | ||||||
|  | #include "prot/prot_m4.h" | ||||||
|  |  | ||||||
|  |  | ||||||
| // 检测 自研批检仪 | // 检测 自研批检仪 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 ranchuan
					ranchuan