广播方式升级从机成功
This commit is contained in:
@@ -5,8 +5,38 @@
|
||||
#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,myarray data)
|
||||
{
|
||||
command *c=command_start();
|
||||
mystring strs("ack:%1,%2");
|
||||
strs=strs.arg(ack).arg("end");
|
||||
c->send(strs.data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -54,33 +84,83 @@ cmdline_export(whos, whos, print device base info.);
|
||||
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)&&(args[1]=="updata")){
|
||||
if(args.size()>=4){
|
||||
QList<int> addrs=str_to_nums<int>(args[2],',');
|
||||
HandleBoardCast *b=new boardcast_updata();
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg_=syscfg();
|
||||
bool ack=slave->set_boardcast_handle(addrs,b);
|
||||
if(ack==false){
|
||||
qWarning("handle is busy.");
|
||||
}else{
|
||||
// connect(b,&HandleBoardCast::end_signal,nullptr,[=](int addr,int ack, myarray data){
|
||||
// if(ack==0)
|
||||
// c->send("slave updata success.");
|
||||
// else
|
||||
// c->send("slave updata failed.");
|
||||
// });
|
||||
QFile file;
|
||||
file.setFileName(args[3]);
|
||||
if(file.open(QIODevice::ReadOnly)){
|
||||
myarray data=file.readAll();
|
||||
b->start(data);
|
||||
file.close();
|
||||
|
||||
// 升级小板程序
|
||||
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{
|
||||
qWarning("open file failed.");
|
||||
b->set_cbfun([=](int addr,int ack,myarray 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,myarray 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,myarray 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user