2023-11-26 23:05:35 +08:00
|
|
|
#include "cmd_pc.h"
|
2023-11-27 14:31:00 +08:00
|
|
|
#include "cmd_slave.h"
|
2023-11-26 23:05:35 +08:00
|
|
|
#include "prot/prot_m4.h"
|
|
|
|
#include "prot/prot_pc.h"
|
|
|
|
#include "prot/prot_slave.h"
|
|
|
|
#include "base/mycfg.h"
|
2023-11-27 14:31:00 +08:00
|
|
|
#include "base/check_cfg.h"
|
2023-11-26 23:05:35 +08:00
|
|
|
#include "QDebug"
|
2023-11-27 14:31:00 +08:00
|
|
|
#include "elec/elec_judge.h"
|
2023-11-26 23:05:35 +08:00
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int moter_count;
|
|
|
|
int moter_run;
|
|
|
|
} moter_def;
|
2023-11-26 23:05:35 +08:00
|
|
|
static moter_def g_moter;
|
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
|
|
|
|
// 电机控制
|
2023-11-26 23:05:35 +08:00
|
|
|
myarray moter_ctrl(myarray op)
|
|
|
|
{
|
2023-11-27 14:31:00 +08:00
|
|
|
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;
|
2023-11-29 15:36:45 +08:00
|
|
|
mystring s = mystring("moter %1").arg(count);
|
|
|
|
r = myarray(s.data());
|
2023-11-27 14:31:00 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning("moter count out of range.");
|
|
|
|
return r;
|
2023-11-26 23:05:35 +08:00
|
|
|
}
|
2023-11-27 14:31:00 +08:00
|
|
|
}
|
|
|
|
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;
|
2023-11-29 15:36:45 +08:00
|
|
|
mystring s = mystring("moter %1").arg(count);
|
|
|
|
r = myarray(s.data());
|
|
|
|
qDebug("moter down:%s",s.data());
|
2023-11-27 14:31:00 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning("moter count out of range.") ;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
2023-11-29 15:36:45 +08:00
|
|
|
qDebug("moter ctrl:%s",op.data());
|
|
|
|
return r;
|
2023-11-26 23:05:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-30 10:50:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
// 自研批检仪检测
|
2023-11-26 23:05:35 +08:00
|
|
|
int selfdev_check::dolater(int cmd, myarray data)
|
|
|
|
{
|
2023-11-27 14:31:00 +08:00
|
|
|
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);
|
2023-11-30 10:50:05 +08:00
|
|
|
moter_down_cb_fun=[=](myarray data)
|
2023-11-29 15:36:45 +08:00
|
|
|
{
|
2023-11-30 10:50:05 +08:00
|
|
|
m4->del_irq_fun(moter_down_cb_fun,"moter ");
|
2023-11-29 15:36:45 +08:00
|
|
|
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);
|
2023-11-27 14:31:00 +08:00
|
|
|
}
|
2023-11-26 23:05:35 +08:00
|
|
|
}
|
2023-11-29 15:36:45 +08:00
|
|
|
}
|
|
|
|
};
|
2023-11-30 10:50:05 +08:00
|
|
|
m4->set_irq_fun(moter_down_cb_fun,"moter ");
|
2023-11-27 14:31:00 +08:00
|
|
|
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;
|
2023-11-26 23:05:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-11-26 23:05:35 +08:00
|
|
|
|
2023-11-27 14:31:00 +08:00
|
|
|
static HandlePc *get_selfdev_check(){
|
|
|
|
return new selfdev_check();
|
|
|
|
}
|
2023-11-29 15:36:45 +08:00
|
|
|
protpc_export(0x30, get_selfdev_check);
|
|
|
|
|
2023-11-30 10:50:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-29 15:36:45 +08:00
|
|
|
int selfdev_moter::dolater(int cmd, myarray data)
|
|
|
|
{
|
|
|
|
prot_m4 *m4 = protM4();
|
|
|
|
connect(this, &selfdev_moter::send_to_m4_signal, m4, &prot_m4::send_data_slot);
|
|
|
|
if(data[0]==0x02){
|
|
|
|
emit send_to_m4_signal(moter_ctrl("up"));
|
|
|
|
}else if(data[0]==0x03){
|
|
|
|
emit send_to_m4_signal(moter_ctrl("down"));
|
|
|
|
}
|
|
|
|
emit send_data_signal(0x40,myarray(1,char(0)));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void selfdev_moter::timeout(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static HandlePc *get_selfdev_moter(){
|
|
|
|
return new selfdev_moter();
|
|
|
|
}
|
2023-11-26 23:05:35 +08:00
|
|
|
|
2023-11-29 15:36:45 +08:00
|
|
|
protpc_export(0x40, get_selfdev_moter);
|
2023-11-26 23:05:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-30 10:50:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int selfdev_slaveupdate::dolater(int cmd, myarray data)
|
|
|
|
{
|
|
|
|
prot_m4 *m4 = protM4();
|
|
|
|
connect(this, &selfdev_slaveupdate::send_to_m4_signal, m4, &prot_m4::send_data_slot);
|
|
|
|
if(data[0]==0x02){
|
|
|
|
emit send_to_m4_signal(moter_ctrl("up"));
|
|
|
|
}else if(data[0]==0x03){
|
|
|
|
emit send_to_m4_signal(moter_ctrl("down"));
|
|
|
|
}
|
|
|
|
emit send_data_signal(0x40,myarray(1,char(0)));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void selfdev_slaveupdate::timeout(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static HandlePc *get_selfdev_slaveupdate(){
|
|
|
|
return new selfdev_slaveupdate();
|
|
|
|
}
|
|
|
|
|
2023-12-02 11:27:25 +08:00
|
|
|
protpc_export(0x41, get_selfdev_slaveupdate);
|
2023-11-30 10:50:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|