添加广播方式升级

This commit is contained in:
ranchuan
2023-11-29 15:36:45 +08:00
parent a0b0f41c39
commit e34b8111dc
30 changed files with 1388 additions and 146 deletions

View File

@@ -5,16 +5,25 @@ void prot_m4::init()
{
if_ = interFaceFind("uart_m4");
codec_ = codecFind("codec_m4");
if(if_==nullptr||codec_==nullptr){
return;
}
if_->set_irq([=](myarray recv)
{
if(codec_->packCheck(recv_data)==true){
int cmd,src,dst;
myarray data=codec_->decode(src,dst,cmd,recv_data);
if(exe_cb_fun(data)==false){
qWarning("can not find cb fun with:\"%s\"",data.data());
}
recv_data.clear();
recv_data+=recv;
int pack_len=0;
while(pack_len=codec_->packCheck(recv_data),pack_len>0){
int cmd,src,dst;
myarray data=codec_->decode(src,dst,cmd,recv_data);
recv_data.remove(0,pack_len);
if(wait>0) wait--;
if(exe_cb_fun(data)==false){
qWarning("can not find cb fun with:\"%s\"",data.data());
}
if(send_list.size()>0){
if_->write(send_list.takeFirst());
wait+=2;
}
}
});
}
@@ -24,7 +33,12 @@ void prot_m4::send_data_slot(myarray data)
if ((if_ != nullptr) && (codec_ != nullptr))
{
myarray send = codec_->encode(0, 0, 0, data);
if_->write(send);
send_list.append(send);
if(wait==0){
wait+=2;
qDebug("send m4:%s",data.data());
if_->write(send_list.takeFirst());
}
}
}
@@ -33,13 +47,16 @@ bool prot_m4::exe_cb_fun(myarray data)
int left;
for (int i = 0; i < funs.size(); i++)
{
left = funs[i].cmd.size();
// 这里size包含结尾符要去掉
left = funs[i].cmd.size()-1;
if (data.left(left) == funs[i].cmd)
{
if (funs[i].fun != nullptr)
{
funs[i].fun(data.mid(left));
return true;
for(int j=0;j<funs[i].funs.size();j++){
prot_m4_cb fun=funs[i].funs[j];
if(fun!=nullptr){
fun(data.mid(left));
return true;
}
}
}
}
@@ -65,12 +82,21 @@ bool prot_m4::set_irq_fun(prot_m4_cb fun, myarray data)
left = funs[i].cmd.size();
if (data.left(left) == funs[i].cmd)
{
return false;
for(int j=0;j<funs[i].funs.size();j++){
prot_m4_cb temp=funs[i].funs[j];
if(fun.target<void(*)(myarray data)>()==temp.target<void(*)(myarray data)>()){
qDebug("this function pointer was exited.");
return false;
}
}
qDebug("add function pointer success.");
funs[i].funs.append(fun);
return true;
}
}
HandleM4_def m4_cmd;
m4_cmd.cmd = data;
m4_cmd.fun = fun;
m4_cmd.funs.append(fun);
funs.append(m4_cmd);
return true;
}
@@ -83,8 +109,24 @@ bool prot_m4::del_irq_fun(prot_m4_cb fun, myarray data)
left = funs[i].cmd.size();
if (data.left(left) == funs[i].cmd)
{
funs.removeAt(i);
return true;
if(fun==nullptr){
qDebug("del the same string cb.");
funs.removeAt(i);
return true;
}else{
for(int j=0;j<funs[i].funs.size();j++){
prot_m4_cb temp=funs[i].funs[j];
if(fun.target<void(*)(myarray data)>()==temp.target<void(*)(myarray data)>()){
qDebug("del the same function pointer.");
funs[i].funs.removeAt(j);
if(funs[i].funs.size()==0){
funs.removeAt(i);
}
return true;
}
}
return false;
}
}
}
return false;