广播方式升级从机成功
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
2023.12.4
|
||||
自研批检仪检测命令测试成功
|
||||
广播方式升级从机发现卡死现象
|
||||
|
||||
2023.12.5
|
||||
广播方式升级从机成功
|
||||
|
||||
|
||||
|
||||
|
@@ -67,6 +67,7 @@ HEADERS += \
|
||||
prot/prot_m4.h \
|
||||
prot/prot_pc.h \
|
||||
prot/prot_slave.h \
|
||||
prot_cmd/cmd_cmdline.h \
|
||||
prot_cmd/cmd_pc.h \
|
||||
prot_cmd/cmd_slave.h
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
|
||||
#define BUILD_DATE "2023-12-04 18:04:43"
|
||||
#define BUILD_DATE "2023-12-05 18:18:14"
|
||||
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"build_date": "2023-12-04 18:04:43",
|
||||
"build_date": "2023-12-05 18:18:14",
|
||||
"hard_version": "MHPZ2_V1.00",
|
||||
"private": [
|
||||
"info.json",
|
||||
|
@@ -188,6 +188,7 @@ void can_host::recv_data_cb()
|
||||
{
|
||||
irq_fun(myarray(slave.get_data()));
|
||||
}
|
||||
emit recv_data_signal(slave_addr,slave.get_data());
|
||||
}
|
||||
qDebug()<<"can recv from:"<<slave_addr<<slave.get_data().toHex(' ');
|
||||
}
|
||||
@@ -213,6 +214,7 @@ void can_host::recv_data_cb()
|
||||
{
|
||||
irq_fun(myarray(slave.get_data()));
|
||||
}
|
||||
emit recv_data_signal(slave_addr,slave.get_data());
|
||||
}
|
||||
qDebug()<<"can recv from:"<<slave_addr<<slave.get_data().toHex(' ');
|
||||
}
|
||||
@@ -229,23 +231,20 @@ void can_host::recv_data_cb()
|
||||
|
||||
int can_host::write(int dst,myarray data)
|
||||
{
|
||||
qDebug()<<"can send to:"<<dst<<data.toHex(' ');
|
||||
// qDebug()<<"can send to:"<<dst<<data.toHex(' ');
|
||||
append(dst, 1, data);
|
||||
// qDebug("can send end.");
|
||||
return data.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void can_host::send_data_cb(uint8_t dst, int fun_class, QByteArray data)
|
||||
{
|
||||
append(dst, fun_class, data);
|
||||
}
|
||||
|
||||
// 群发消息
|
||||
void can_host::send_data_mul_cb(QList<uint8_t> dst, int fun_class, QByteArray data)
|
||||
void can_host::send_data_mul_slot(QList<int> addrs, QByteArray data)
|
||||
{
|
||||
for (int i = 0; i < dst.size(); i++)
|
||||
append(dst[i], fun_class, data);
|
||||
for (int i = 0; i < addrs.size(); i++)
|
||||
append(addrs[i], 1, data);
|
||||
}
|
||||
|
||||
void can_host::append(uint8_t addr, uint8_t fun_class, QByteArray data)
|
||||
@@ -290,6 +289,7 @@ void can_host::append(uint8_t addr, uint8_t fun_class, QByteArray data)
|
||||
QCanBusFrame frame = QCanBusFrame(frameId.Exide, data.left(8));
|
||||
while (can_->writeFrame(frame) != true)
|
||||
{
|
||||
// qDebug("wait for written.");
|
||||
can_->waitForFramesWritten(1000);
|
||||
}
|
||||
data.remove(0, 8);
|
||||
|
@@ -54,9 +54,9 @@ private:
|
||||
void append(uint8_t addr, uint8_t fun_class, QByteArray data);
|
||||
public slots:
|
||||
// 用户把发送数据信号连接到这个槽
|
||||
void send_data_cb(uint8_t dst, int fun_class, QByteArray data);
|
||||
void send_data_mul_cb(QList<uint8_t> dst, int fun_class, QByteArray data);
|
||||
|
||||
void send_data_mul_slot(QList<int> addrs, QByteArray data);
|
||||
signals:
|
||||
void recv_data_signal(int src,QByteArray data);
|
||||
private slots:
|
||||
void freams_sent_cb(qint64 count);
|
||||
void recv_data_cb();
|
||||
|
@@ -25,12 +25,15 @@ void prot_slave::init()
|
||||
}else{
|
||||
if((broadcast_!=nullptr)&&(broadcast_->busy)){
|
||||
broadcast_->addr_response|=1<<(src-1);
|
||||
if(broadcast_->check_response()==true)
|
||||
broadcast_->dolater(broadcast_->cmd,data);
|
||||
if(broadcast_->check_response()==true){
|
||||
// broadcast_->dolater(broadcast_->cmd,data);
|
||||
emit boardcast_dolater_signal(broadcast_->cmd,data);
|
||||
}
|
||||
}else{
|
||||
handle=slaves[src-1];
|
||||
if(handle!=nullptr){
|
||||
handle->dolater(cmd,data);
|
||||
// handle->dolater(cmd,data);
|
||||
emit slave_dolater_signal(cmd,data);
|
||||
}else{
|
||||
qWarning("slave addr=%d not have handle.",src);
|
||||
}
|
||||
@@ -63,6 +66,7 @@ bool prot_slave::set_slave_handle(int addr, HandleSlave *handle)
|
||||
}
|
||||
handle->addr=addr;
|
||||
connect(handle, &HandleSlave::send_data_signal, this, &prot_slave::send_data_slot);
|
||||
connect(this,&prot_slave::slave_dolater_signal,handle,&HandleSlave::dolater);
|
||||
slaves.replace(addr - 1, handle);
|
||||
return true;
|
||||
}
|
||||
@@ -84,6 +88,7 @@ bool prot_slave::set_boardcast_handle(QList<int> addrs,HandleBoardCast *handle)
|
||||
broadcast_=handle;
|
||||
broadcast_->trun_list_to_bit(addrs);
|
||||
connect(handle, &HandleBoardCast::send_data_signal, this, &prot_slave::send_data_slot);
|
||||
connect(this,&prot_slave::boardcast_dolater_signal,handle,&HandleBoardCast::dolater);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -100,6 +100,11 @@ signals:
|
||||
};
|
||||
|
||||
|
||||
using namespace std;
|
||||
// using namespace std::placeholders;
|
||||
|
||||
typedef std::function<void(int addr,int ack,myarray data)> prots_end_cbfun;
|
||||
typedef std::function<void(int rate,mystring data)> prots_rate_cbfun;
|
||||
|
||||
|
||||
|
||||
@@ -116,6 +121,8 @@ public:
|
||||
timer_retry_=nullptr;
|
||||
times_retry=0;
|
||||
addr_response=0;
|
||||
end_cb=nullptr;
|
||||
rate_cb=nullptr;
|
||||
}
|
||||
virtual ~HandleBoardCast() {
|
||||
if(timer_!=nullptr){
|
||||
@@ -145,6 +152,10 @@ public:
|
||||
addr|=1<<(adr-1);
|
||||
}
|
||||
}
|
||||
void set_cbfun(prots_end_cbfun end_fun,prots_rate_cbfun rate_fun){
|
||||
this->end_cb=end_fun;
|
||||
this->rate_cb=rate_fun;
|
||||
}
|
||||
signals:
|
||||
void timeout_stop_retry_signal();
|
||||
void timeout_stop_signal();
|
||||
@@ -156,39 +167,52 @@ protected:
|
||||
this->cmd=cmd;
|
||||
this->data_send=data;
|
||||
this->times_retry=times;
|
||||
this->addr_response=0;
|
||||
if(timer_retry_==nullptr){
|
||||
timer_retry_=new QTimer();
|
||||
connect(timer_,&QTimer::timeout,this,&HandleBoardCast::timeout_retry);
|
||||
connect(timer_retry_,&QTimer::timeout,this,&HandleBoardCast::timeout_retry);
|
||||
connect(this,&HandleBoardCast::timeout_stop_retry_signal,timer_retry_,&QTimer::stop);
|
||||
connect(this,&HandleBoardCast::timeout_start_retry_signal,this,&HandleBoardCast::timeout_start_retry_cb);
|
||||
}
|
||||
qDebug("handle_board:start retry");
|
||||
timeout_retry();
|
||||
// timeout_retry();
|
||||
// emit timeout_start_retry_signal(5);
|
||||
timeout_start_retry_cb(5);
|
||||
return 0;
|
||||
}
|
||||
// 发送操作结束信号
|
||||
int end(int ack,myarray data){
|
||||
emit end_signal(0x1f,ack,data);
|
||||
if(end_cb!=nullptr){
|
||||
end_cb(0x1f,ack,data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void rate(int rate,mystring str){
|
||||
emit rate_signal(rate,str);
|
||||
if(rate_cb!=nullptr){
|
||||
rate_cb(rate,str);
|
||||
}
|
||||
}
|
||||
// 开始超时计时器,此计时器用于整个操作的超时
|
||||
void timeout_start(int ms){
|
||||
qDebug("handle_board:start timeout");
|
||||
if(timer_==nullptr){
|
||||
timer_=new QTimer();
|
||||
connect(timer_,&QTimer::timeout,this,&HandleBoardCast::timeout);
|
||||
connect(this,&HandleBoardCast::timeout_stop_signal,timer_,&QTimer::stop);
|
||||
connect(this,&HandleBoardCast::timeout_start_signal,this,&HandleBoardCast::timeout_start_cb);
|
||||
}else{
|
||||
emit timeout_start_signal(ms);
|
||||
// timer_->start(ms);
|
||||
}
|
||||
// emit timeout_start_signal(ms);
|
||||
timeout_start_cb(ms);
|
||||
}
|
||||
void timeout_start_cb(int ms){
|
||||
timer_->start(ms);
|
||||
qDebug("handle_board:start timeout");
|
||||
timer_->setInterval(ms);
|
||||
timer_->start();
|
||||
}
|
||||
void timeout_start_retry_cb(int ms){
|
||||
timer_retry_->start(ms);
|
||||
qDebug("handle_board:start retry");
|
||||
timer_retry_->setInterval(ms);
|
||||
timer_retry_->start();
|
||||
}
|
||||
// 停止超时计时器,此方法同时停止重发计时器
|
||||
void timeout_stop(){
|
||||
@@ -217,10 +241,11 @@ private:
|
||||
s.append(data_send);
|
||||
emit send_data_signal(0x1f,cmd,s);
|
||||
// timer_retry_->start(300);
|
||||
emit timeout_start_retry_signal(300);
|
||||
//emit timeout_start_retry_signal(300);
|
||||
timeout_start_retry_cb(1000);
|
||||
}else{
|
||||
// timer_retry_->stop();
|
||||
emit timeout_stop_retry_signal();
|
||||
timeout_stop_retry();
|
||||
}
|
||||
}
|
||||
private:
|
||||
@@ -228,9 +253,12 @@ private:
|
||||
QTimer *timer_retry_;
|
||||
int times_retry;
|
||||
myarray data_send;
|
||||
prots_end_cbfun end_cb;
|
||||
prots_rate_cbfun rate_cb;
|
||||
signals:
|
||||
void send_data_signal(int addr, int cmd, myarray data);
|
||||
void end_signal(int addr,int ack,myarray data);
|
||||
void rate_signal(int rate,mystring str);
|
||||
};
|
||||
|
||||
|
||||
@@ -260,6 +288,10 @@ protected:
|
||||
Codec *codec_;
|
||||
QList<HandleSlave *> slaves;
|
||||
HandleBoardCast *broadcast_;
|
||||
signals:
|
||||
void boardcast_dolater_signal(int cmd,myarray data);
|
||||
void slave_dolater_signal(int cmd,myarray data);
|
||||
|
||||
};
|
||||
|
||||
prot_slave *protSlave();
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
30
prot_cmd/cmd_cmdline.h
Normal file
30
prot_cmd/cmd_cmdline.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef CMD_CMDLINE_H
|
||||
#define CMD_CMDLINE_H
|
||||
|
||||
|
||||
#include "QObject"
|
||||
#include "base/base.h"
|
||||
|
||||
|
||||
//class cmd_line_slots:public QObject
|
||||
//{
|
||||
// Q_OBJECT
|
||||
//public:
|
||||
// cmd_line_slots(){}
|
||||
// ~cmd_line_slots(){}
|
||||
//public slots:
|
||||
// void rate_slot(int rate,mystring str);
|
||||
// void end_slot(int addr,int ack,myarray data);
|
||||
//};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CMD_CMDLINE_H
|
@@ -234,6 +234,7 @@ int selfdev_slaveupdate::dolater(int cmd, myarray data)
|
||||
mystring name=data.mid(1,len_filename);
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg_=syscfg();
|
||||
busy=1;
|
||||
qInfo()<<"slave_app name:"<<name<<endl;
|
||||
data.remove(0,len_filename+1);
|
||||
|
||||
@@ -249,6 +250,7 @@ int selfdev_slaveupdate::dolater(int cmd, myarray data)
|
||||
bool ack=slave->set_boardcast_handle(cfg_->calc_slave_addrs(),b);
|
||||
if(ack==false){
|
||||
qWarning("handle is busy.");
|
||||
busy=0;
|
||||
}else{
|
||||
connect(b,&HandleBoardCast::end_signal,this,&selfdev_slaveupdate::slave_end_slot);
|
||||
b->start(data);
|
||||
@@ -258,12 +260,14 @@ int selfdev_slaveupdate::dolater(int cmd, myarray data)
|
||||
}
|
||||
|
||||
void selfdev_slaveupdate::timeout(){
|
||||
|
||||
busy=0;
|
||||
qDebug("slave update timeout");
|
||||
}
|
||||
|
||||
void selfdev_slaveupdate::slave_end_slot(int addr,int ack, myarray data)
|
||||
{
|
||||
qDebug("slave update end,ack=%d",ack);
|
||||
busy=0;
|
||||
}
|
||||
|
||||
static HandlePc *get_selfdev_slaveupdate(){
|
||||
@@ -276,3 +280,86 @@ protpc_export(0xfe, get_selfdev_slaveupdate);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int selfdev_update_scheme::dolater(int cmd, myarray data)
|
||||
{
|
||||
myarray r;
|
||||
int len_filename=data[0];
|
||||
mystring name=data.mid(1,len_filename);
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg_=syscfg();
|
||||
check_cfg *ccfg_=check_plan();
|
||||
uint8_t rw=data[0];
|
||||
data.remove(0,1);
|
||||
|
||||
busy=1;
|
||||
if(rw==0)
|
||||
{
|
||||
// 读方案
|
||||
r.append(char(0));
|
||||
r.append(rw);
|
||||
r.append(ccfg_->scheme_to_jstring());
|
||||
emit send_data_signal(0x22,r);
|
||||
busy=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 写方案
|
||||
bool ack=ccfg_->updata(QString(data));
|
||||
r.append(ack?char(0):char(1));
|
||||
r.append(rw);
|
||||
if(ack){
|
||||
// 检测数据保存
|
||||
// if(comm_f_!=nullptr){
|
||||
// delete comm_f_;
|
||||
// comm_f_=nullptr;
|
||||
// }
|
||||
// 自动给小板升级
|
||||
HandleBoardCast *b=new boardcast_updata_scheme();
|
||||
bool ack=slave->set_boardcast_handle(cfg_->calc_slave_addrs(),b);
|
||||
if(ack==false){
|
||||
qWarning("handle is busy.");
|
||||
busy=0;
|
||||
}else{
|
||||
connect(b,&HandleBoardCast::end_signal,this,&selfdev_update_scheme::slave_end_slot);
|
||||
b->start(data);
|
||||
}
|
||||
}
|
||||
else{
|
||||
r.append("方案解析失败");
|
||||
qWarning("scheme check failed.");
|
||||
}
|
||||
emit send_data_signal(0x22,r);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void selfdev_update_scheme::timeout(){
|
||||
busy=0;
|
||||
qDebug("slave update timeout");
|
||||
}
|
||||
|
||||
void selfdev_update_scheme::slave_end_slot(int addr,int ack, myarray data)
|
||||
{
|
||||
qDebug("slave update end,ack=%d",ack);
|
||||
busy=0;
|
||||
}
|
||||
|
||||
static HandlePc *get_selfdev_update_scheme(){
|
||||
return new selfdev_update_scheme();
|
||||
}
|
||||
|
||||
protpc_export(0x22, get_selfdev_update_scheme);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -90,5 +90,25 @@ signals:
|
||||
|
||||
|
||||
|
||||
// 升级方案
|
||||
class selfdev_update_scheme : public HandlePc
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
selfdev_update_scheme() : HandlePc() {}
|
||||
~selfdev_update_scheme() {}
|
||||
int dolater(int cmd, myarray data);
|
||||
void timeout();
|
||||
public slots:
|
||||
void slave_end_slot(int addr,int ack, myarray data);
|
||||
signals:
|
||||
void send_to_m4_signal(myarray data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -218,7 +218,7 @@ void boardcast_updata::timeout()
|
||||
|
||||
int boardcast_updata::start(myarray data)
|
||||
{
|
||||
int timeout=50000;
|
||||
int timeout=5000;
|
||||
busy=1;
|
||||
qWarning()<<"addr "<<addr<<" updata start.";
|
||||
timeout_start(timeout);
|
||||
@@ -231,8 +231,7 @@ int boardcast_updata::start(myarray data)
|
||||
|
||||
int boardcast_updata::dolater(int cmd, myarray data)
|
||||
{
|
||||
timeout_stop_retry();
|
||||
timeout_start(50000);
|
||||
timeout_start(5000);
|
||||
if(step==0){
|
||||
if(send_packet()==true){
|
||||
step=1;
|
||||
@@ -257,6 +256,8 @@ int boardcast_updata::dolater(int cmd, myarray data)
|
||||
send_data(0xfb,s,10);
|
||||
step=2;
|
||||
}else if(step==2){
|
||||
timeout_stop();
|
||||
timeout_stop_retry();
|
||||
qDebug("slave updata end.");
|
||||
end(0,data);
|
||||
busy=0;
|
||||
@@ -268,7 +269,7 @@ bool boardcast_updata::send_packet()
|
||||
{
|
||||
if(count_sent<data.size()){
|
||||
uint32_t addr=MCU_APP_ADDR_BASE+count_sent;
|
||||
int pack_size=240;
|
||||
int pack_size=236;
|
||||
myarray s;
|
||||
if(pack_size>data.size()-count_sent){
|
||||
pack_size=data.size()-count_sent;
|
||||
@@ -280,6 +281,7 @@ bool boardcast_updata::send_packet()
|
||||
s+=data.mid(count_sent,pack_size);
|
||||
count_sent+=pack_size;
|
||||
send_data(0xfc,s,10);
|
||||
rate(count_sent*100/data.size(),"slave_updata");
|
||||
}
|
||||
if(count_sent<data.size()){
|
||||
return false;
|
||||
@@ -289,3 +291,95 @@ bool boardcast_updata::send_packet()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void boardcast_updata_scheme::timeout()
|
||||
{
|
||||
timeout_stop();
|
||||
qWarning("slave updata timeout.");
|
||||
end(1,myarray());
|
||||
busy=0;
|
||||
}
|
||||
|
||||
int boardcast_updata_scheme::start(myarray data)
|
||||
{
|
||||
int timeout=5000;
|
||||
busy=1;
|
||||
base_addr=MCU_TASKID_ADDR_BASE;
|
||||
qWarning()<<"addr "<<addr<<" updata start.";
|
||||
timeout_start(timeout);
|
||||
// 擦除
|
||||
step=0;
|
||||
this->data=data;
|
||||
send_packet();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int boardcast_updata_scheme::dolater(int cmd, myarray data)
|
||||
{
|
||||
timeout_start(5000);
|
||||
if(step==0){
|
||||
if(send_packet()==true){
|
||||
step=1;
|
||||
}
|
||||
}else if(step==1){
|
||||
send_data(0x15,myarray(),10);
|
||||
step=2;
|
||||
}else if(step==2){
|
||||
timeout_stop();
|
||||
timeout_stop_retry();
|
||||
qDebug("slave updata scheme end.");
|
||||
end(0,data);
|
||||
busy=0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool boardcast_updata_scheme::send_packet()
|
||||
{
|
||||
if(count_sent<data.size()){
|
||||
uint32_t addr=base_addr+count_sent;
|
||||
int pack_size=236;
|
||||
myarray s;
|
||||
if(pack_size>data.size()-count_sent){
|
||||
pack_size=data.size()-count_sent;
|
||||
}
|
||||
s.append((addr)&0xff);
|
||||
s.append((addr>>8)&0xff);
|
||||
s.append((addr>>16)&0xff);
|
||||
s.append((addr>>24)&0xff);
|
||||
s+=data.mid(count_sent,pack_size);
|
||||
count_sent+=pack_size;
|
||||
send_data(0x11,s,10);
|
||||
rate(count_sent*100/data.size(),"slave_updata_scheme");
|
||||
}
|
||||
if(count_sent<data.size()){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int boardcast_updata_jwt::start(myarray data)
|
||||
{
|
||||
int timeout=5000;
|
||||
busy=1;
|
||||
base_addr=MCU_JWT_ADDR_BASE;
|
||||
qWarning()<<"addr "<<addr<<" updata start.";
|
||||
timeout_start(timeout);
|
||||
// 擦除
|
||||
step=0;
|
||||
this->data=data;
|
||||
send_packet();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -90,6 +90,33 @@ private:
|
||||
|
||||
|
||||
|
||||
// 方案升级
|
||||
class boardcast_updata_scheme:public HandleBoardCast
|
||||
{
|
||||
public:
|
||||
boardcast_updata_scheme():HandleBoardCast(){step=0;count_sent=0;base_addr=0;}
|
||||
virtual int start(myarray data);
|
||||
int dolater(int cmd, myarray data);
|
||||
void timeout();
|
||||
bool send_packet();
|
||||
protected:
|
||||
int step;
|
||||
myarray data;
|
||||
int count_sent;
|
||||
uint32_t base_addr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// jwt升级
|
||||
class boardcast_updata_jwt:public boardcast_updata_scheme
|
||||
{
|
||||
public:
|
||||
boardcast_updata_jwt():boardcast_updata_scheme(){step=0;count_sent=0;base_addr=0;}
|
||||
int start(myarray data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user