71 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "cmd_pc.h"
 | |
| #include "prot/prot_m4.h"
 | |
| #include "prot/prot_pc.h"
 | |
| #include "prot/prot_slave.h"
 | |
| #include "base/mycfg.h"
 | |
| #include "QDebug"
 | |
| 
 | |
| 
 | |
| 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;
 | |
|         }
 | |
|     }
 | |
|     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"));
 | |
|   return 0;
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | 
