添加自研批检仪检测命令
This commit is contained in:
@@ -1,70 +1,155 @@
|
||||
#include "cmd_pc.h"
|
||||
#include "cmd_slave.h"
|
||||
#include "prot/prot_m4.h"
|
||||
#include "prot/prot_pc.h"
|
||||
#include "prot/prot_slave.h"
|
||||
#include "base/mycfg.h"
|
||||
#include "base/check_cfg.h"
|
||||
#include "QDebug"
|
||||
#include "elec/elec_judge.h"
|
||||
|
||||
|
||||
typedef struct{
|
||||
int moter_count;
|
||||
int moter_run;
|
||||
}moter_def;
|
||||
typedef struct
|
||||
{
|
||||
int moter_count;
|
||||
int moter_run;
|
||||
} moter_def;
|
||||
static moter_def g_moter;
|
||||
|
||||
|
||||
// 电机控制
|
||||
myarray moter_ctrl(myarray op)
|
||||
{
|
||||
mycfg *cfg_=syscfg();
|
||||
moter_def *moter=&g_moter;
|
||||
myarray r;
|
||||
if(op=="up"){
|
||||
int count=0;
|
||||
if(moter->moter_count>0){
|
||||
moter->moter_run=1;
|
||||
count=-moter->moter_count-100;
|
||||
moter->moter_count=0;
|
||||
QString s=QString("moter %1").arg(count);
|
||||
r=s.toLocal8Bit();
|
||||
}else{
|
||||
qWarning()<<"moter count out of range."<<endl;
|
||||
return r;
|
||||
}
|
||||
}else if(op=="down"){
|
||||
int count=0;
|
||||
if(moter->moter_count<cfg_->moter_count){
|
||||
moter->moter_run=1;
|
||||
count=cfg_->moter_count-moter->moter_count;
|
||||
moter->moter_count+=count;
|
||||
QString s=QString("moter %1").arg(count);
|
||||
r=s.toLocal8Bit();
|
||||
}else{
|
||||
qWarning()<<"moter count out of range."<<endl;
|
||||
return r;
|
||||
}
|
||||
mycfg *cfg_ = syscfg();
|
||||
moter_def *moter = &g_moter;
|
||||
myarray r;
|
||||
if (op == "up")
|
||||
{
|
||||
int count = 0;
|
||||
if (moter->moter_count > 0)
|
||||
{
|
||||
moter->moter_run = 1;
|
||||
count = -moter->moter_count - 100;
|
||||
moter->moter_count = 0;
|
||||
QString s = QString("moter %1").arg(count);
|
||||
r = s.toLocal8Bit();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int selfdev_check::dolater(int cmd, myarray data)
|
||||
{
|
||||
prot_m4 *m4=protM4();
|
||||
connect(this,send_to_m4_signal,m4,&prot_m4::send_data_slot);
|
||||
m4->set_irq_fun([=](myarray data){
|
||||
m4->del_irq_fun(nullptr,"moter ");
|
||||
if(data=="down"){
|
||||
// 这里开始检测
|
||||
}
|
||||
},"moter ");
|
||||
emit send_to_m4_signal(moter_ctrl("up"));
|
||||
else
|
||||
{
|
||||
qWarning("moter count out of range.");
|
||||
return r;
|
||||
}
|
||||
}
|
||||
else if (op == "down")
|
||||
{
|
||||
int count = 0;
|
||||
if (moter->moter_count < cfg_->moter_count)
|
||||
{
|
||||
moter->moter_run = 1;
|
||||
count = cfg_->moter_count - moter->moter_count;
|
||||
moter->moter_count += count;
|
||||
QString s = QString("moter %1").arg(count);
|
||||
r = s.toLocal8Bit();
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("moter count out of range.") ;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// 自研批检仪检测
|
||||
int selfdev_check::dolater(int cmd, myarray data)
|
||||
{
|
||||
prot_m4 *m4 = protM4();
|
||||
prot_slave *slave=protSlave();
|
||||
mycfg *cfg=syscfg();
|
||||
busy=1;
|
||||
connect(this, &selfdev_check::send_to_m4_signal, m4, &prot_m4::send_data_slot);
|
||||
m4->set_irq_fun([=](myarray data)
|
||||
{
|
||||
m4->del_irq_fun(nullptr,"moter ");
|
||||
if(data=="down"){
|
||||
// 这里开始检测
|
||||
QList<int> addrs=cfg->calc_slave_addrs();
|
||||
HandleSlave *s=new slave_check();
|
||||
foreach(int addr, addrs){
|
||||
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_check::slave_end_slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
},"moter ");
|
||||
emit send_to_m4_signal(moter_ctrl("down"));
|
||||
slave_acked.clear();
|
||||
for(int i=0;i<cfg->slave_num;i++){
|
||||
slave_acked.append(myarray());
|
||||
}
|
||||
slave_acked_num=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void selfdev_check::timeout()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 把小板的返回数据转化为自研批检仪上位机的格式
|
||||
static myarray tran_slave_to_selfdev_check(myarray &data)
|
||||
{
|
||||
check_cfg *ccfg_=check_plan();
|
||||
// 返回值个数
|
||||
int return_num=ccfg_->get_return_num();
|
||||
// 参数错误字节数
|
||||
int paramerr_num=(return_num+7)/8;
|
||||
// 每个通道占用的长度
|
||||
int len_for_each=1+8+paramerr_num+return_num*2;
|
||||
myarray r;
|
||||
if(data.size()<17){
|
||||
r.append(char(208));
|
||||
r.append((len_for_each-1),char(0xff));
|
||||
}else{
|
||||
myarray paramerr=ccfg_->returns_to_paramerr(data.right(return_num*2));
|
||||
r=data.left(8)+paramerr+data.right(return_num*2);
|
||||
uint8_t marerr=0,suberr=0;
|
||||
uint8_t *d=(uint8_t *)data.data();
|
||||
elec_judge(ccfg_->check_scheme(),ccfg_->get_check_task_num(),
|
||||
d,d+8,d+16,&marerr,&suberr);
|
||||
r.insert(0,uint8_t(marerr));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
void selfdev_check::slave_end_slot(int addr,int ack, myarray data)
|
||||
{
|
||||
if(addr<=0||addr>slave_acked.size()){
|
||||
slave_acked.replace(addr-1,data);
|
||||
}
|
||||
slave_acked_num++;
|
||||
if(slave_acked_num>=slave_acked.size()){
|
||||
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_check(){
|
||||
return new selfdev_check();
|
||||
}
|
||||
|
||||
protpc_export(0xff, get_selfdev_check);
|
||||
|
||||
|
||||
|
||||
|
@@ -5,24 +5,21 @@
|
||||
|
||||
|
||||
// 检测 自研批检仪
|
||||
class selfdev_check:public HandlePc {
|
||||
Q_OBJECT
|
||||
class selfdev_check : public HandlePc
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
selfdev_check():HandlePc(){}
|
||||
~selfdev_check(){}
|
||||
int dolater(int cmd, myarray data);
|
||||
selfdev_check() : HandlePc() {slave_acked_num=0;}
|
||||
~selfdev_check() {}
|
||||
int dolater(int cmd, myarray data);
|
||||
void timeout();
|
||||
public slots:
|
||||
void slave_end_slot(int addr,int ack, myarray data);
|
||||
protected:
|
||||
QList<myarray> slave_acked;
|
||||
int slave_acked_num;
|
||||
signals:
|
||||
void send_to_m4_signal(myarray data);
|
||||
void send_to_m4_signal(myarray data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -1,12 +1,40 @@
|
||||
#include "cmd_slave.h"
|
||||
|
||||
|
||||
#include "base/mycfg.h"
|
||||
#include "base/check_cfg.h"
|
||||
#include "QDebug"
|
||||
|
||||
|
||||
|
||||
int slave_check::start(myarray data)
|
||||
{
|
||||
return 0;
|
||||
mycfg *cfg_=syscfg();
|
||||
int timeout=100000;
|
||||
busy=1;
|
||||
cmd=0x0c;
|
||||
qDebug("addr %d start check,timeout=%d",addr,timeout);
|
||||
send_data(cmd,myarray());
|
||||
timeout_start(timeout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void slave_check::timeout()
|
||||
{
|
||||
qWarning("addr %d check timeout.",addr);
|
||||
end(1,myarray());
|
||||
busy=0;
|
||||
}
|
||||
|
||||
int slave_check::dolater(int cmd, myarray data)
|
||||
{
|
||||
if(cmd!=this->cmd){
|
||||
qWarning("addr %d recv err cmd:%02x",addr,cmd);
|
||||
return 1;
|
||||
}
|
||||
end(0,data);
|
||||
busy=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -9,6 +9,8 @@ class slave_check:public HandleSlave
|
||||
public:
|
||||
slave_check():HandleSlave(){}
|
||||
int start(myarray data);
|
||||
int dolater(int cmd, myarray data);
|
||||
void timeout();
|
||||
};
|
||||
|
||||
#endif // CMD_SLAVE_H
|
||||
|
Reference in New Issue
Block a user