广播命令已接收的回复不再触发回调
检测命令0x0c只能使用单播方式,广播方式因为不能即时回复停止信号,回复会出错 添加电阻测试命令,添加自检命令
This commit is contained in:
@@ -126,6 +126,8 @@ static myarray tran_slave_to_selfdev_check(myarray &data)
|
||||
int paramerr_num=(return_num+7)/8;
|
||||
// 每个通道占用的长度
|
||||
int len_for_each=1+8+paramerr_num+return_num*2;
|
||||
// 去掉应答位
|
||||
data.remove(0,1);
|
||||
myarray r;
|
||||
if(data.size()<17){
|
||||
r.append(char(208));
|
||||
@@ -169,6 +171,77 @@ protpc_export(0x30, get_selfdev_check);
|
||||
|
||||
|
||||
|
||||
// 自研批检仪检测
|
||||
int selfdev_check2::dolater(int cmd, myarray data)
|
||||
{
|
||||
prot_m4 *m4 = protM4();
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg=syscfg();
|
||||
busy=1;
|
||||
connect(this, &selfdev_check2::send_to_m4_signal, m4, &prot_m4::send_data_slot);
|
||||
moter_down_cb_fun=[=](myarray data)
|
||||
{
|
||||
m4->del_irq_fun(moter_down_cb_fun,"moter down");
|
||||
{
|
||||
// 这里开始检测
|
||||
qDebug("start check.");
|
||||
emit send_data_signal(cmd,myarray(1,0));
|
||||
QList<int> addrs=cfg->calc_slave_addrs();
|
||||
HandleBoardCast *s=new slave_check2();
|
||||
bool ack=slave->set_boardcast_handle(addrs,s);
|
||||
if(ack==false){
|
||||
qWarning("handle is busy.");
|
||||
}else{
|
||||
connect(s,&HandleBoardCast::end_signal,this,&selfdev_check2::slave_end_slot);
|
||||
s->start(myarray());
|
||||
}
|
||||
}
|
||||
};
|
||||
myarray moter_cmd=moter_ctrl("down");
|
||||
if(moter_cmd.size()==0){
|
||||
busy=0;
|
||||
qWarning("moter failed.");
|
||||
}else{
|
||||
m4->set_irq_fun(moter_down_cb_fun,"moter down");
|
||||
emit send_to_m4_signal(moter_cmd);
|
||||
}
|
||||
slave_acked.clear();
|
||||
for(int i=0;i<cfg->slave_num;i++){
|
||||
slave_acked.append(myarray());
|
||||
}
|
||||
slave_acked_num=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void selfdev_check2::timeout()
|
||||
{
|
||||
busy=0;
|
||||
}
|
||||
void selfdev_check2::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
for(int i=0;i<data.size();i++){
|
||||
slave_ret slave=data.at(i);
|
||||
slave_acked.replace(slave.addr-1,slave.data);
|
||||
slave_acked_num++;
|
||||
}
|
||||
myarray r;
|
||||
r.append(char(0));
|
||||
for(int i=0;i<slave_acked.size();i++){
|
||||
r.append(tran_slave_to_selfdev_check(slave_acked[i]));
|
||||
}
|
||||
emit send_data_signal(0x31,r);
|
||||
busy=0;
|
||||
}
|
||||
|
||||
//static HandlePc *get_selfdev_check2(){
|
||||
// return new selfdev_check2();
|
||||
//}
|
||||
//protpc_export(0x30, get_selfdev_check2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 检测结束 电机上升
|
||||
@@ -274,7 +347,7 @@ void selfdev_slaveupdate::timeout(){
|
||||
|
||||
void selfdev_slaveupdate::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
qDebug("slave update end,ack=%d",ack);
|
||||
qDebug("slave update end,ack=%s",ack?"failed":"success");
|
||||
busy=0;
|
||||
}
|
||||
|
||||
@@ -331,7 +404,8 @@ int selfdev_update_scheme::dolater(int cmd, myarray data)
|
||||
busy=0;
|
||||
}else{
|
||||
connect(b,&HandleBoardCast::end_signal,this,&selfdev_update_scheme::slave_end_slot);
|
||||
b->start(data);
|
||||
myarray scheme=myarray((const char *)ccfg_->check_scheme(),ccfg_->check_scheme_size());
|
||||
b->start(scheme);
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -350,7 +424,7 @@ void selfdev_update_scheme::timeout(){
|
||||
|
||||
void selfdev_update_scheme::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
qDebug("slave update end,ack=%d",ack);
|
||||
qDebug("slave update end,ack=%s",ack?"failed":"success");
|
||||
busy=0;
|
||||
}
|
||||
|
||||
@@ -449,24 +523,23 @@ protpc_export(0x27, get_selfdev_jwtupdate);
|
||||
int selfdev_bootinfo::dolater(int cmd, myarray data)
|
||||
{
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg=syscfg();
|
||||
mycfg *cfg_=syscfg();
|
||||
busy=1;
|
||||
// 这里开始检测
|
||||
qDebug("get bootinfo.");
|
||||
emit send_data_signal(cmd,myarray(1,0));
|
||||
QList<int> addrs=cfg->calc_slave_addrs();
|
||||
foreach(int addr, addrs){
|
||||
HandleSlave *s=new slave_check();
|
||||
bool ack=slave->set_slave_handle(addr,s);
|
||||
if(ack==false){
|
||||
qWarning("addr %d handle is busy.",addr);
|
||||
}else{
|
||||
connect(s,&HandleSlave::end_signal,this,&selfdev_bootinfo::slave_end_slot);
|
||||
s->start(myarray());
|
||||
}
|
||||
HandleBoardCast *b=new slave_cmd();
|
||||
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_bootinfo::slave_end_slot);
|
||||
b->cmd=0x13;
|
||||
b->start(data);
|
||||
}
|
||||
slave_acked.clear();
|
||||
for(int i=0;i<cfg->slave_num;i++){
|
||||
for(int i=0;i<cfg_->slave_num;i++){
|
||||
slave_acked.append(myarray());
|
||||
}
|
||||
slave_acked_num=0;
|
||||
@@ -523,12 +596,13 @@ myarray bootinfo_fill_local(void)
|
||||
QStringList iplist;
|
||||
mycfg *cfg_=syscfg();
|
||||
check_cfg *ccfg_=check_plan();
|
||||
uint8_t *d=(uint8_t *)calloc(1,sizeof(local_bootinfo));
|
||||
memcpy(d,cfg_->build_date.toLocal8Bit(),cfg_->build_date.size()+1);d+=20;
|
||||
memcpy(d,cfg_->soft_version.toLocal8Bit(),cfg_->soft_version.size()+1);d+=8;
|
||||
uint8_t *d=(uint8_t *)calloc(1,sizeof(local_bootinfo)+1);
|
||||
uint8_t *d_free=d;
|
||||
memcpy(d,cfg_->build_date.data(),cfg_->build_date.size()+1);d+=20;
|
||||
memcpy(d,cfg_->soft_version.data(),cfg_->soft_version.size()+1);d+=8;
|
||||
memcpy(d,&tick,4);d+=4;
|
||||
memcpy(d,&wdog,1);d+=1;
|
||||
memcpy(d,cfg_->device_type.toLocal8Bit(),cfg_->device_type.size()+1);d+=12;
|
||||
memcpy(d,cfg_->device_type.data(),cfg_->device_type.size()+1);d+=12;
|
||||
iplist=cfg_->local_ip.split('.');
|
||||
ip[0]=iplist[0].toInt();
|
||||
ip[1]=iplist[1].toInt();
|
||||
@@ -552,60 +626,44 @@ myarray bootinfo_fill_local(void)
|
||||
temp32|=1<<i;
|
||||
}
|
||||
memcpy(d,&temp32,4);d+=4;
|
||||
myarray arry((char *)d,sizeof(local_bootinfo));
|
||||
free(d);
|
||||
myarray arry((char *)d_free,sizeof(local_bootinfo));
|
||||
free(d_free);
|
||||
qDebug()<<"local data="<<arry.toHex(' ');
|
||||
return arry;
|
||||
}
|
||||
|
||||
|
||||
static myarray slave_to_bootinfo_byte(myarray data){
|
||||
data.append(sizeof(bootinfo_data)-data.size(),0);
|
||||
data.remove(0,1);
|
||||
int size_slave=sizeof(bootinfo_data);
|
||||
int data_size=data.size();
|
||||
if(size_slave>data_size){
|
||||
data.append(size_slave-data_size,0);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
//void selfdev_bootinfo::slave_end_slot(int addr,int ack, slave_data data)
|
||||
//{
|
||||
// if(addr<=0||addr>slave_acked.size()){
|
||||
// qWarning("slave addr err:%d",addr);
|
||||
// return;
|
||||
// }
|
||||
// for(int i=0;i<data.size();i++){
|
||||
// slave_ret slave=data.at(i);
|
||||
// slave_acked.replace(slave.addr-1,slave.data);
|
||||
// slave_acked_num++;
|
||||
// myarray r;
|
||||
// r.append(char(0));
|
||||
// r+=bootinfo_fill_local();
|
||||
// for(int i=0;i<slave_acked.size();i++){
|
||||
// r.append(slave_to_bootinfo_byte(slave_acked[i]));
|
||||
// }
|
||||
// emit send_data_signal(0x34,r);
|
||||
// busy=0;
|
||||
// }
|
||||
//}
|
||||
|
||||
void selfdev_bootinfo::slave_end_slot(int addr,int ack, myarray data)
|
||||
void selfdev_bootinfo::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
if(addr<=0||addr>slave_acked.size()){
|
||||
qWarning("slave addr err:%d",addr);
|
||||
return;
|
||||
qDebug("selfdev get bootinfo end.");
|
||||
myarray r;
|
||||
r.append(char(0));
|
||||
r+=bootinfo_fill_local();
|
||||
for(int i=0;i<data.size();i++){
|
||||
slave_ret slave=data.at(i);
|
||||
slave_acked.replace(slave.addr-1,slave.data);
|
||||
slave_acked_num++;
|
||||
}
|
||||
slave_acked.replace(addr-1,data);
|
||||
slave_acked_num++;
|
||||
if(slave_acked_num>=slave_acked.size()){
|
||||
myarray r;
|
||||
r.append(char(0));
|
||||
r+=bootinfo_fill_local();
|
||||
for(int i=0;i<slave_acked.size();i++){
|
||||
r.append(slave_to_bootinfo_byte(slave_acked[i]));
|
||||
}
|
||||
emit send_data_signal(0x34,r);
|
||||
busy=0;
|
||||
for(int i=0;i<slave_acked.size();i++){
|
||||
r.append(slave_to_bootinfo_byte(slave_acked[i]));
|
||||
}
|
||||
emit send_data_signal(0x35,r);
|
||||
busy=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static HandlePc *get_selfdev_bootinfo(){
|
||||
return new selfdev_bootinfo();
|
||||
}
|
||||
@@ -617,3 +675,137 @@ protpc_export(0x34, get_selfdev_bootinfo);
|
||||
|
||||
|
||||
|
||||
// 测量电阻
|
||||
int selfdev_measure_rescv::dolater(int cmd, myarray data)
|
||||
{
|
||||
prot_m4 *m4 = protM4();
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg=syscfg();
|
||||
busy=1;
|
||||
connect(this, &selfdev_measure_rescv::send_to_m4_signal, m4, &prot_m4::send_data_slot);
|
||||
moter_down_cb_fun=[=](myarray data)
|
||||
{
|
||||
m4->del_irq_fun(moter_down_cb_fun,"moter down");
|
||||
{
|
||||
// 这里开始检测
|
||||
qDebug("start check.");
|
||||
QList<int> addrs=cfg->calc_slave_addrs();
|
||||
HandleBoardCast *s=new slave_cmd();
|
||||
bool ack=slave->set_boardcast_handle(addrs,s);
|
||||
if(ack==false){
|
||||
qWarning("handle is busy.");
|
||||
}else{
|
||||
connect(s,&HandleBoardCast::end_signal,this,&selfdev_measure_rescv::slave_end_slot);
|
||||
s->cmd=0x05;
|
||||
s->start(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
myarray moter_cmd=moter_ctrl("down");
|
||||
if(moter_cmd.size()==0){
|
||||
busy=0;
|
||||
qWarning("moter failed.");
|
||||
}else{
|
||||
m4->set_irq_fun(moter_down_cb_fun,"moter down");
|
||||
emit send_to_m4_signal(moter_cmd);
|
||||
}
|
||||
slave_acked.clear();
|
||||
for(int i=0;i<cfg->slave_num;i++){
|
||||
slave_acked.append(myarray());
|
||||
}
|
||||
slave_acked_num=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void selfdev_measure_rescv::timeout()
|
||||
{
|
||||
busy=0;
|
||||
}
|
||||
|
||||
void selfdev_measure_rescv::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
qDebug("selfdev measure_rescv end.");
|
||||
emit send_to_m4_signal(moter_ctrl("up"));
|
||||
myarray r;
|
||||
r.append(char(0));
|
||||
for(int i=0;i<data.size();i++){
|
||||
slave_ret slave=data.at(i);
|
||||
slave_acked.replace(slave.addr-1,slave.data);
|
||||
slave_acked_num++;
|
||||
}
|
||||
for(int i=0;i<slave_acked.size();i++){
|
||||
r.append(char(i+1));
|
||||
r.append(slave_acked[i].right(2));
|
||||
}
|
||||
QTimer::singleShot(0, this, [=](){
|
||||
emit send_data_signal(0x42,r);
|
||||
});
|
||||
busy=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static HandlePc *get_selfdev_measure_rescv(){
|
||||
return new selfdev_measure_rescv();
|
||||
}
|
||||
protpc_export(0x42, get_selfdev_measure_rescv);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 设置电阻校准
|
||||
int selfdev_set_rescv::dolater(int cmd, myarray data)
|
||||
{
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg_=syscfg();
|
||||
busy=1;
|
||||
// 这里开始检测
|
||||
qDebug("set_rescv.");
|
||||
emit send_data_signal(cmd,myarray(1,0));
|
||||
HandleBoardCast *b=new slave_cmd();
|
||||
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_set_rescv::slave_end_slot);
|
||||
// 广播设置校准值,需使用新增命令
|
||||
b->cmd=0x13;
|
||||
b->start(data);
|
||||
}
|
||||
slave_acked.clear();
|
||||
for(int i=0;i<cfg_->slave_num;i++){
|
||||
slave_acked.append(myarray());
|
||||
}
|
||||
slave_acked_num=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void selfdev_set_rescv::timeout()
|
||||
{
|
||||
busy=0;
|
||||
}
|
||||
|
||||
void selfdev_set_rescv::slave_end_slot(int addr,int ack, slave_data data)
|
||||
{
|
||||
qDebug("selfdev set_rescv end.");
|
||||
myarray r;
|
||||
r.append(char(0));
|
||||
emit send_data_signal(0x41,r);
|
||||
busy=0;
|
||||
}
|
||||
|
||||
static HandlePc *get_selfdev_set_rescv(){
|
||||
return new selfdev_set_rescv();
|
||||
}
|
||||
protpc_export(0x41, get_selfdev_set_rescv);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user