174 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			174 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "prot/prot_cmdline.h"
 | |
| #include "base/mycfg.h"
 | |
| #include "QNetworkConfigurationManager"
 | |
| #include "QTimer"
 | |
| #include "QtNetwork"
 | |
| #include "prot/prot_slave.h"
 | |
| #include "prot_cmd/cmd_slave.h"
 | |
| #include "base/check_cfg.h"
 | |
| #include "QFile"
 | |
| #include "base/base.h"
 | |
| #include "cmd_cmdline.h"
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| void rate_slot(int rate,mystring str)
 | |
| {
 | |
|   command *c=command_start();
 | |
|   mystring strs("rate:%1,%2");
 | |
|   strs=strs.arg(rate).arg(str);
 | |
|   c->send(strs.data());
 | |
| }
 | |
| void end_slot(int addr,int ack,slave_data data)
 | |
| {
 | |
|   command *c=command_start();
 | |
|   mystring strs("ack:%1,%2");
 | |
|   strs=strs.arg(ack).arg("end");
 | |
|   c->send(strs.data());
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| // 获取设备基本信息
 | |
| 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.);
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| // mcu 相关
 | |
| static void mcu_cmdlines(QList<myarray> args)
 | |
| {
 | |
|   command *c=command_start();
 | |
|   prot_slave *slave=protSlave();
 | |
|   mycfg *cfg_=syscfg();
 | |
|   check_cfg *ccfg_=check_plan();
 | |
|   if(args.size()<2){
 | |
|     c->send("cmd len too less.");
 | |
|     return ;
 | |
|   }
 | |
|   if(args.size()>=4){
 | |
|     QList<int> addrs=str_to_nums<int>(args[2],',');
 | |
|     
 | |
|     // 升级小板程序
 | |
|     if(args[1]=="updata"){
 | |
|       HandleBoardCast *b=new boardcast_updata();
 | |
|       bool ack=slave->set_boardcast_handle(addrs,b);
 | |
|       if(ack==false){
 | |
|         qWarning("handle is busy.");
 | |
|       }else{
 | |
|         b->set_cbfun([=](int addr,int ack,slave_data data){
 | |
|           end_slot(addr,!ack,data);
 | |
|         },[=](int rate,mystring str){
 | |
|           rate_slot(rate,str);
 | |
|         });
 | |
|         QFile file;
 | |
|         file.setFileName(args[3]);
 | |
|         if(file.open(QIODevice::ReadOnly)){
 | |
|           myarray data=file.readAll();
 | |
|           b->start(data);
 | |
|           file.close();
 | |
|         }else{
 | |
|           qWarning("open file failed.");
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|     // 升级jwt程序
 | |
|     else if(args[1]=="upjwt"){
 | |
|       HandleBoardCast *b=new boardcast_updata_jwt();
 | |
|       bool ack=slave->set_boardcast_handle(addrs,b);
 | |
|       if(ack==false){
 | |
|         qWarning("handle is busy.");
 | |
|       }else{
 | |
|         b->set_cbfun([=](int addr,int ack,slave_data data){
 | |
|           end_slot(addr,!ack,data);
 | |
|         },[=](int rate,mystring str){
 | |
|           rate_slot(rate,str);
 | |
|         });
 | |
|         QFile file;
 | |
|         file.setFileName(args[3]);
 | |
|         if(file.open(QIODevice::ReadOnly)){
 | |
|           myarray data=file.readAll();
 | |
|           b->start(data);
 | |
|           file.close();
 | |
|         }else{
 | |
|           qWarning("open file failed.");
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|   }else if(args.size()>=3){
 | |
|     QList<int> addrs=str_to_nums<int>(args[2],',');
 | |
|     // 升级方案
 | |
|     if(args[1]=="scheme"){
 | |
|       HandleBoardCast *b=new boardcast_updata_scheme();
 | |
|       bool ack=slave->set_boardcast_handle(addrs,b);
 | |
|       if(ack==false){
 | |
|         qWarning("handle is busy.");
 | |
|       }else{
 | |
|         b->set_cbfun([=](int addr,int ack,slave_data data){
 | |
|           end_slot(addr,!ack,data);
 | |
|         },[=](int rate,mystring str){
 | |
|           rate_slot(rate,str);
 | |
|         });
 | |
|         myarray data;
 | |
|         if(cfg_->slave_scheme_ext==0){
 | |
|             data=myarray((const char *)ccfg_->check_scheme()->slave_data,2048);
 | |
|         }else{
 | |
|             data=myarray((const char *)ccfg_->check_scheme(),ccfg_->check_scheme_size());
 | |
|         }
 | |
|         b->start(data);
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| }
 | |
| cmdline_export(mcu, mcu_cmdlines, mcu cmdlines` input [mcu help] to detail.);
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | 
