瀏覽代碼

complete (signal laser log no locate)

zx 5 年之前
父節點
當前提交
a34a2a8868
共有 15 個文件被更改,包括 274 次插入98 次删除
  1. 2 1
      GarageMeasurement.pro
  2. 3 3
      GarageMeasurement.pro.user
  3. 11 9
      Process.cpp
  4. 8 6
      Process.h
  5. 1 0
      laser/Laser.h
  6. 1 1
      laser/LivoxLaser.cpp
  7. 32 1
      main.cpp
  8. 60 24
      mainwindow.cpp
  9. 5 3
      mainwindow.h
  10. 45 8
      mainwindow.ui
  11. 18 12
      modbus/PLCMonitor.cpp
  12. 6 5
      modbus/PLCMonitor.h
  13. 34 0
      qtmessagedef.h
  14. 45 21
      src/measuretask.cpp
  15. 3 4
      src/measuretask.h

+ 2 - 1
GarageMeasurement.pro

@@ -116,7 +116,8 @@ HEADERS += \
     src/measuretask.h \
     Process.h \
     src/pathcreator.h \
-    laser/LivoxHubLaser.h
+    laser/LivoxHubLaser.h \
+    qtmessagedef.h
 
 FORMS += \
         mainwindow.ui

+ 3 - 3
GarageMeasurement.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.4.1, 2019-10-22T22:46:28. -->
+<!-- Written by QtCreator 4.4.1, 2019-10-24T16:02:49. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -91,7 +91,7 @@
        <value type="QString">-r</value>
       </valuelist>
       <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
-      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">-j8</value>
       <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
      </valuemap>
      <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
@@ -151,7 +151,7 @@
        <value type="QString">-r</value>
       </valuelist>
       <value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
-      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
+      <value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">-j4</value>
       <value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
      </valuemap>
      <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>

+ 11 - 9
Process.cpp

@@ -10,8 +10,9 @@ CProcess::CProcess(Automatic::stCalibParam param, void* mainWnd)
 	m_laser = NULL;
 	m_main_wnd = mainWnd;
     m_thread_queue=0;
-    connect(this,SIGNAL(plc_signal(uint16_t*,int)),
-            (MainWindow*)m_main_wnd,SLOT(PLCSlot(uint16_t*,int)));
+
+    connect(this,SIGNAL(MainWndSignal(QVariant)),
+            (MainWindow*)m_main_wnd,SLOT(ProcessSlot(QVariant)));
 }
 
 
@@ -51,7 +52,7 @@ CProcess::~CProcess()
 	}
 	if (m_laser_calib_param.is_calib() == false)
 	{
-
+        //delete m_locate;
 	}
 
 	
@@ -133,8 +134,6 @@ bool CProcess::Init()
 		else
 		{
             m_monitor.set_callback(action_callback, monitor_callback,this);
-            /*m_monitor.SetLogWnd(((CMainFrame*)m_main_wnd)->m_wndSplitter.GetPane(0, 1),
-                &((CMainFrame*)m_main_wnd)->m_dlg_laser_data);*/
 		}
 
         /*if (m_locater == 0)
@@ -174,7 +173,7 @@ void CProcess::PushTask(uint16_t param, int action_type,bool test)
     /*else if(action_type==2)
         task = new CFenceTask(lasers, m_locater, int(plate), plc, m_laser_calib_param);*/
 
-    //task->SetResultCallback(this, result_callback);
+    ((MeasureTask*)task)->SetResultCallback(this, monitor_callback);
     m_thread_queue->AddTask(task);
 }
 
@@ -186,11 +185,14 @@ void CProcess::action_callback(bool bOn, uint16_t param, void* pointer, int acti
 		process->PushTask(param, action_type);
 }
 
-void CProcess::monitor_callback(uint16_t* data,int size, void* pointer)
+void CProcess::monitor_callback(QtMessageData data, void* pointer)
 {
-
+    static QtMessageData msg;
+    memcpy(&msg,&data,sizeof(data));
     CProcess* process = reinterpret_cast<CProcess*>(pointer);
-    emit process->plc_signal(data,size);
+    static QVariant var;
+    var.setValue(msg);
+    emit process->MainWndSignal(var);
 }
 
 void CProcess::create_mat_param(Automatic::stLaserCalibParam laser, double* buf)

+ 8 - 6
Process.h

@@ -5,7 +5,7 @@
 #include "./src/CalibParam.pb.h"
 #include "laser/LivoxLaser.h"
 #include "src/measuretask.h"
-
+#include "qtmessagedef.h"
 
 class CProcess :public QObject
 {
@@ -15,17 +15,19 @@ public:
 	bool			Init();
 	std::string		LastError() { return m_last_error; }
 	void			PushTask(uint16_t param , int action_type,bool test=false);
-    size_t			TaskQueueSize() { return 0;}//m_thread_queue.QueueSize(); }
-    size_t			TaskProcessSize() { return 0;}//m_thread_queue.ProcessSize(); }
+    size_t			TaskQueueSize() { return m_thread_queue->TaskCount(); }
     virtual ~CProcess();
 protected:
     static void action_callback(bool bOn, uint16_t param, void* pointer, int action_type);
-    static void monitor_callback(uint16_t* data, int size,void* pointer);
+    static void monitor_callback(QtMessageData data,void* pointer);
 	static void create_mat_param(Automatic::stLaserCalibParam laser, double*);
 
 protected:
 signals:
-    void plc_signal(uint16_t* data,int size);
+    void MainWndSignal(QVariant data);
+
+protected:
+    static void result_callback(void* data,void* pointer);
 
 public:
 
@@ -33,7 +35,7 @@ public:
 	modbus::CPLCMonitor							m_monitor;
 protected:
     tq::IQueue*                                 m_thread_queue;
-	// 激光标定参数和分割算法参数
+    // 激光标定参数
 	Automatic::stCalibParam		m_laser_calib_param;
 	std::string					m_last_error;
 

+ 1 - 0
laser/Laser.h

@@ -165,6 +165,7 @@ public:
 	void			SetSaveDir(std::string strDir,bool bSave=true);
 	///查询雷达是否空闲
 	bool			IsReady() { return m_statu == eLaser_ready; }
+    eLaserStatu     GetStatu(){return m_statu;}
 	int				ID() { return m_id; }
 protected:
 	////获取原始数据包

+ 1 - 1
laser/LivoxLaser.cpp

@@ -189,7 +189,7 @@ void CLivoxLaser::LidarDataCallback(uint8_t handle, LivoxEthPacket *data, uint32
 			g_count[handle]++;
 			
 		}
-		else
+        else if(livox->m_statu!=eLaser_ready)
 		{
 			//½ÓÊÕµ½Êý¾Ý£¬µ«Î´¿ªÊ¼
 			livox->m_statu = eLaser_ready;

+ 32 - 1
main.cpp

@@ -3,7 +3,37 @@
 #include <QApplication>
 
 #include "Process.h"
+#include "src/pathcreator.h"
+void InitGlog()
+{
+    time_t tt = time(0);//时间cuo
+    struct tm* t = localtime(&tt);
+
+    char strYear[255]={0};
+    char strMonth[255]={0};
+    char strDay[255]={0};
+
+    sprintf(strYear,"%04d", t->tm_year+1900);
+    sprintf(strMonth,"%02d", t->tm_mon);
+    sprintf(strDay,"%02d", t->tm_mday);
+
+    char buf[255]={0};
+    getcwd(buf,255);
+    char strdir[255]={0};
+    sprintf(strdir,"%s/log/%s/%s/%s", buf,strYear,strMonth,strDay);
+    PathCreator creator;
+    creator.Mkdir(strdir);
+
 
+    char logPath[255] = { 0 };
+    sprintf(logPath, "%s/", strdir);
+    FLAGS_max_log_size = 100;
+    FLAGS_logbufsecs = 0;
+    google::InitGoogleLogging("GarageMeasurement");
+    google::SetLogDestination(0, logPath);
+    //google::InstallFailureSignalHandler();
+    //google::InstallFailureWriter(0);
+}
 
 bool ReadProtoParam(std::string path, ::google::protobuf::Message& param)
 {
@@ -26,11 +56,12 @@ int main(int argc, char *argv[])
     QApplication a(argc, argv);
     MainWindow w;
     w.show();
-
     char buf[255]={0};
     getcwd(buf,255);
     sprintf(buf,"%s/setting/calib.prototxt",buf);
 
+    InitGlog();
+
     if(!ReadProtoParam(buf,m_laser_calib_param))
     {
         QMessageBox::about(NULL, "Error", "Read proto failed...");

+ 60 - 24
mainwindow.cpp

@@ -1,6 +1,7 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
-
+#include "qtmessagedef.h"
+#include <time.h>
 
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
@@ -9,13 +10,6 @@ MainWindow::MainWindow(QWidget *parent) :
     ui->setupUi(this);
     setWindowIcon(QIcon("./Resource/log.jpg"));
 
-    m_listbox=new QListWidget(this);//创建一个列表框对象
-    m_listbox->setGeometry(10,10,150,150);//设置列表框的位置和大小
-    m_listbox->insertItem(0,"Item 1");//向列表框中插入条目
-    m_listbox->insertItem(1,"Item 2");
-
-
-
 
 }
 
@@ -23,21 +17,68 @@ MainWindow::~MainWindow()
 {
     delete ui;
 }
+void MainWindow::AddLog(std::string log)
+{
+    if(ui->m_log_list->count()>50)
+        ui->m_log_list->clear();
+    char buf[255]={0};
+    time_t tt = time(0);//时间cuo
+    struct tm* t = localtime(&tt);
+    memset(buf,0,255);
+    sprintf(buf, "%d-%02d-%02d %02d:%02d:%02d     %s", t->tm_year + 1900,
+            t->tm_mon + 1,t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec,log.c_str());
+
+    ui->m_log_list->insertItem(ui->m_log_list->count(),buf);
+    ui->m_log_list->scrollToBottom();
 
-void MainWindow::PLCSlot(uint16_t* data,int size)
+}
+void MainWindow::ProcessSlot(QVariant var)
 {
-    printf("plc slots \n");
-    static unsigned short last_data[255]={0};
-    for(int i=0;i<size;++i)
+    QtMessageData data=var.value<QtMessageData>();
+    if(data.msg_type==ePlcSignal)
     {
-        if(data[i]!=last_data[i])
+        static unsigned short last_data[255]={0};
+        for(int i=0;i<data.signal_size;++i)
         {
-            char buf[255]={0};
-            sprintf(buf,"P[%d] %d ---> %d",i,last_data[i],data[i]);
-            m_listbox->insertItem(m_listbox->count(),buf);
-            m_listbox->scrollToBottom();
+            if(data.plc_data[i]!=last_data[i])
+            {
+                char buf[255]={0};
+                sprintf(buf,"P[%d] %d ---> %d",i,last_data[i],data.plc_data[i]);
+                AddLog(buf);
+            }
         }
     }
+    else if(data.msg_type==eMeasure)
+    {
+        std::string msgstr="Laser ID : ";
+        char buf[255];
+        memset(buf,0,255);
+        std::vector<int> IDS;
+        for(int i=0;i<16;++i)
+        {
+            if((0x01<<i) & data.lasers_id !=0)
+                IDS.push_back(i);
+        }
+        for(int i=0;i<IDS.size();++i)
+            sprintf(buf,"%d   ",IDS[i]+1);
+        msgstr+=buf;
+        msgstr+='\n';
+
+        memset(buf,0,255);
+        sprintf(buf,"Project dir : %s\n",data.project_dir);
+        msgstr+=buf;
+
+        memset(buf,0,255);
+        sprintf(buf,"x:%.2f  y:%.2f  c:%.2f\nl:%.2f  w:%.2f  h:%.2f   D:%.2f\nPosition id:%d\n",
+                data.x,data.y,data.c,data.l,data.w,data.h,data.d,data.position_id);
+        msgstr+=buf;
+
+        msgstr+=(data.OK!=0)?"Result  OK\n":"Result Failed\n";
+
+        msgstr+=data.time_str;
+
+        ui->m_measure_result->setText(msgstr.c_str());
+    }
 }
 #include "qmessagebox.h"
 #include "src/pathcreator.h"
@@ -53,11 +94,6 @@ extern CProcess* m_pProcess;
 void MainWindow::on_m_add_clicked()
 {
 
-    m_pProcess->PushTask(0x03,1,false);
-
-    /*int static k=3;
-    char buf[255]={0};
-    sprintf(buf,"Item %d",k++);
-    m_listbox->insertItem(m_listbox->count(),buf);
-    m_listbox->scrollToBottom();*/
+    m_pProcess->PushTask(0x01,1,false);
+    AddLog(" test tsak ");
 }

+ 5 - 3
mainwindow.h

@@ -5,6 +5,8 @@
 #include <QListWidget>
 #include <QPushButton>
 
+#include <QVariant>
+
 namespace Ui {
 class MainWindow;
 }
@@ -16,17 +18,17 @@ class MainWindow : public QMainWindow
 public:
     explicit MainWindow(QWidget *parent = 0);
     ~MainWindow();
-
+protected:
+    void AddLog(std::string log);
 private slots:
     void on_m_test_btn_clicked();
     void on_m_add_clicked();
 
 private slots:
-    void PLCSlot(uint16_t* data,int size);
+    void ProcessSlot(QVariant data);
 
 private:
     QPushButton* m_test_button;
-    QListWidget* m_listbox;
 
 private:
     Ui::MainWindow *ui;

+ 45 - 8
mainwindow.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>869</width>
-    <height>474</height>
+    <width>945</width>
+    <height>496</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -17,8 +17,8 @@
    <widget class="QPushButton" name="m_test_btn">
     <property name="geometry">
      <rect>
-      <x>350</x>
-      <y>40</y>
+      <x>210</x>
+      <y>270</y>
       <width>89</width>
       <height>51</height>
      </rect>
@@ -30,25 +30,62 @@
    <widget class="QPushButton" name="m_add">
     <property name="geometry">
      <rect>
-      <x>350</x>
-      <y>110</y>
+      <x>210</x>
+      <y>340</y>
       <width>91</width>
       <height>25</height>
      </rect>
     </property>
     <property name="text">
-     <string>add</string>
+     <string>push task</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="m_measure_result">
+    <property name="geometry">
+     <rect>
+      <x>600</x>
+      <y>240</y>
+      <width>331</width>
+      <height>191</height>
+     </rect>
+    </property>
+    <property name="layoutDirection">
+     <enum>Qt::LeftToRight</enum>
+    </property>
+    <property name="frameShape">
+     <enum>QFrame::WinPanel</enum>
+    </property>
+    <property name="text">
+     <string/>
+    </property>
+    <property name="alignment">
+     <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+    </property>
+    <property name="wordWrap">
+     <bool>false</bool>
+    </property>
+   </widget>
+   <widget class="QListWidget" name="m_log_list">
+    <property name="geometry">
+     <rect>
+      <x>600</x>
+      <y>10</y>
+      <width>331</width>
+      <height>221</height>
+     </rect>
     </property>
    </widget>
    <zorder>m_add</zorder>
    <zorder>m_test_btn</zorder>
+   <zorder>m_measure_result</zorder>
+   <zorder>m_log_list</zorder>
   </widget>
   <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>869</width>
+     <width>945</width>
      <height>22</height>
     </rect>
    </property>

+ 18 - 12
modbus/PLCMonitor.cpp

@@ -8,10 +8,10 @@ namespace modbus
 #ifndef WIN32
 #define Sleep(T)  usleep((T)*1000)
 #endif
-    const clock_t CPLCMonitor::PLC_LASER_TIMEOUT_READY = 1000*1000;		//完成信号到心跳延时
-    const clock_t CPLCMonitor::PLC_LASER_TIMEOUT_PINGPANG = 100*1000;
-    const clock_t CPLCMonitor::PLC_LASER_TIMEOUT_START = 300*1000;
-    const clock_t CPLCMonitor::PLC_LASER_TIMEOUT_MAXMEASURE = 60000*1000;
+    const double CPLCMonitor::PLC_LASER_TIMEOUT_READY = 1.0;		//完成信号到心跳延时
+    const double CPLCMonitor::PLC_LASER_TIMEOUT_PINGPANG = 0.1;
+    const double CPLCMonitor::PLC_LASER_TIMEOUT_START = 0.3;
+    const double CPLCMonitor::PLC_LASER_TIMEOUT_MAXMEASURE = 6.0;
 
 	CPLCMonitor::CPLCMonitor(void* pOwnerObject)
         :_monitoring(false)
@@ -240,7 +240,13 @@ namespace modbus
 					if (value[i] != last_value[i])
 					{
                         if(m_PlcDataCallback && m_pointer)
-                            m_PlcDataCallback(value,SIGNAL_NUM,m_pointer);
+                        {
+                            QtMessageData data;
+                            data.msg_type=ePlcSignal;
+                            data.signal_size=SIGNAL_NUM;
+                            memcpy(data.plc_data,value,sizeof(uint16_t)*SIGNAL_NUM);
+                            m_PlcDataCallback(data,m_pointer);
+                        }
                         break;
 					}
 				}
@@ -288,7 +294,7 @@ namespace modbus
 			if (PLC_LASER_START == finite_state_machines
 				|| PLC_LASER_WORKING == finite_state_machines)
 			{
-				if (current_clock - _heartbeat_write_clock >= PLC_LASER_TIMEOUT_READY)
+                if (double(current_clock - _heartbeat_write_clock)/CLOCKS_PER_SEC >= PLC_LASER_TIMEOUT_READY)
 				{
 					write_laserstatus_register(PLC_LASER_PING);
 					finite_state_machines = PLC_LASER_PING;
@@ -306,7 +312,7 @@ namespace modbus
                     || PLC_LASER_FINISH_FAILED == finite_state_machines)
                 {
                     //超过10秒,开始返回就绪状态
-                    if (current_clock - _heartbeat_write_clock >= PLC_LASER_TIMEOUT_READY)
+                    if (double(current_clock - _heartbeat_write_clock)/CLOCKS_PER_SEC >= PLC_LASER_TIMEOUT_READY)
                     {
 						//先清除数据
 						if (PLC_LASER_FINISH_FAILED == finite_state_machines)
@@ -325,7 +331,7 @@ namespace modbus
                     || PLC_LASER_PONG == finite_state_machines)
                 {
                     //超过3秒,开始返回心跳状态2
-                    if (current_clock - _heartbeat_write_clock >= PLC_LASER_TIMEOUT_PINGPANG)
+                    if (double(current_clock - _heartbeat_write_clock)/CLOCKS_PER_SEC >= PLC_LASER_TIMEOUT_PINGPANG)
                     {
                         write_laserstatus_register(PLC_LASER_PING);
 						finite_state_machines = PLC_LASER_PING;
@@ -335,7 +341,7 @@ namespace modbus
                 else if (PLC_LASER_PING == finite_state_machines)
                 {
                     //超过3秒,开始返回心跳状态1
-                    if (current_clock - _heartbeat_write_clock >= PLC_LASER_TIMEOUT_PINGPANG)
+                    if (double(current_clock - _heartbeat_write_clock)/CLOCKS_PER_SEC >= PLC_LASER_TIMEOUT_PINGPANG)
                     {
                         write_laserstatus_register(PLC_LASER_PONG);
 						finite_state_machines = PLC_LASER_PONG;
@@ -424,7 +430,7 @@ namespace modbus
 				if (PLC_LASER_FINISH_OK == finite_state_machines
 					|| PLC_LASER_FINISH_FAILED == finite_state_machines)
 				{
-					if (current_clock - _heartbeat_write_clock >= PLC_LASER_TIMEOUT_PINGPANG)
+                    if (double(current_clock - _heartbeat_write_clock)/CLOCKS_PER_SEC >= PLC_LASER_TIMEOUT_PINGPANG)
 					{
 						write_laserstatus_register(PLC_LASER_PING);
 						finite_state_machines = PLC_LASER_PING;
@@ -436,7 +442,7 @@ namespace modbus
                 {
 					current_clock = clock();  
                     //超过200毫秒,返回测量中
-                    if (current_clock - _heartbeat_write_clock >= PLC_LASER_TIMEOUT_START)
+                    if (double(current_clock - _heartbeat_write_clock)/CLOCKS_PER_SEC >= PLC_LASER_TIMEOUT_START)
                     {
                         write_laserstatus_register(PLC_LASER_WORKING);
 						finite_state_machines = PLC_LASER_WORKING;
@@ -467,7 +473,7 @@ namespace modbus
                     }
                     else {
                         current_clock = clock();
-                        if (current_clock - _heartbeat_write_clock > PLC_LASER_TIMEOUT_MAXMEASURE) //10分钟还没返回测量结果, 说明系统可能出错了
+                        if (double(current_clock - _heartbeat_write_clock)/CLOCKS_PER_SEC > PLC_LASER_TIMEOUT_MAXMEASURE) //10分钟还没返回测量结果, 说明系统可能出错了
                         {
                             write_laserstatus_register(PLC_LASER_ERROR);
 							finite_state_machines = PLC_LASER_ERROR;

+ 6 - 5
modbus/PLCMonitor.h

@@ -7,6 +7,7 @@
 #include <vector>
 #include <time.h>
 #include <QObject>
+#include "qtmessagedef.h"
 
 struct whiskboom_laser_value
 {
@@ -61,7 +62,7 @@ namespace modbus
 
 
 	typedef void(*CommandCallback)(bool On, uint16_t param,void* pointer,int action_type);
-    typedef void(*PLCMonitorCallback)(uint16_t* data,int size,void* pointer);
+    typedef void(*PLCMonitorCallback)(QtMessageData data,void* pointer);
 
     class CPLCMonitor :
         public CRunnable
@@ -113,10 +114,10 @@ namespace modbus
         int write_laserresult_register(int addr ,uint16_t *pvalue);
 
     private:
-        static const clock_t PLC_LASER_TIMEOUT_READY;
-		static const clock_t PLC_LASER_TIMEOUT_PINGPANG;
-		static const clock_t PLC_LASER_TIMEOUT_START;
-		static const clock_t PLC_LASER_TIMEOUT_MAXMEASURE;
+        static const double PLC_LASER_TIMEOUT_READY;
+        static const double PLC_LASER_TIMEOUT_PINGPANG;
+        static const double PLC_LASER_TIMEOUT_START;
+        static const double PLC_LASER_TIMEOUT_MAXMEASURE;
 
     public:
         virtual void Run();

+ 34 - 0
qtmessagedef.h

@@ -0,0 +1,34 @@
+#ifndef QTMESSAGE_H
+#define QTMESSAGE_H
+#include <QMetaType>
+#include <QVariant>
+
+const int MAXNUM=255;
+enum MessageType
+{
+    ePlcSignal=0
+    ,eMeasure
+};
+
+
+typedef struct QTMESSAGEDATA
+{
+    MessageType msg_type;
+    unsigned short plc_data[MAXNUM];
+    int signal_size;
+    // measure result
+    int OK;
+    double x,y,c;
+    double l,w,h;
+    double d;
+    int position_id;
+    int stat;
+    short lasers_id;
+    char project_dir[255];
+    char time_str[255];
+}QtMessageData;
+
+Q_DECLARE_METATYPE(QTMESSAGEDATA)
+
+
+#endif // QTMESSAGE_H

+ 45 - 21
src/measuretask.cpp

@@ -79,8 +79,8 @@ MeasureTask::MeasureTask(std::vector<CLaser*> lasers, void* locater,int positon_
     m_exit = false;
     m_calib_param = param;
     m_position_id = positon_id;
-    //m_searchPath.m_strProjectPath = (m_calib_param.project_dir()+"/").c_str();
     m_ptr = 0;
+    m_post_result_func=0;
 }
 
 ERROR_CODE MeasureTask::SelectResult(int plate_index, std::vector<CarPosition> results, CarPosition& result)
@@ -294,15 +294,22 @@ void MeasureTask::PushPoint(CPoint3D point, void* pointer)
     task->m_cloud.push_back(pcl_point);
 
 }
+void MeasureTask::SetResultCallback(void *ptr, ResultCallback func)
+{
+    m_post_result_func=func;
+    m_ptr=ptr;
+}
+
 void  MeasureTask::Main()
 {
     ////等待雷达空闲资源
+    PathCreator pathCreator;
     while (!m_exit)
     {
         g_mutex->lock();
         if (IsLaserReady())
         {
-            PathCreator pathCreator;
+
             pathCreator.CreateDatePath(m_calib_param.project_dir());
             LOG(INFO) << "\tTask dir:" << pathCreator.GetCurPath();
             //启动摆扫
@@ -319,17 +326,18 @@ void  MeasureTask::Main()
         usleep(100*1000);
     }
 
-    while (!m_exit && !IsLaserReady()) { usleep(1); }	//等待摆扫结束
+    while (!m_exit && !IsLaserReady()) { usleep(1000); }	//等待摆扫结束
 
     std::vector<CarPosition> results;
     ERROR_CODE code = eSucc;
     if (m_locater)
     {
+        //m_locater->Locate(m_cloud.makeShared(), results, strPath.GetBuffer(), code)
         if (m_cloud.size() == 0)
         {
             code = eCloud;
         }
-        else if (/*m_locater->Locate(m_cloud.makeShared(), results, strPath.GetBuffer(), code)*/0)
+        else if (0)
         {
             code = Dispatch_posID(results);
             if (code == eSucc)
@@ -368,28 +376,44 @@ void  MeasureTask::Main()
 
 
     /////回调函数,窗口显示结果
-    /*Locate_Message msg;
-    msg.error_code = code;
-    msg.positions = results;
-    msg.cloud = m_cloud.makeShared();
-    time_t tt = time(NULL);//时间cuo
+    QtMessageData msg;
+    msg.msg_type=eMeasure;
+
+    if(results.size()>0)
+    {
+        msg.OK=1;
+
+        msg.x=results[0].x;
+        msg.y=results[0].y;
+        msg.c=results[0].a;
+        msg.l=std::max(results[0].rrect.size.width,results[0].rrect.size.height);
+        msg.w=results[0].w;
+        msg.h=results[0].h;
+        msg.d=results[0].l;
+    }
+    else
+    {
+        msg.OK=0;
+    }
+    ///// id  time
+    short id=0;
+    for(int i=0;i<m_lasers.size();++i)
+    {
+        id =id | (0x01<<m_lasers[i]->ID());
+    }
+    msg.lasers_id=id;
+    time_t tt = time(0);//时间cuo
     tm* t = localtime(&tt);
-    char time[255] = { 0 };
-    sprintf(time, "%d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900, t->tm_mon + 1,
+    memset(msg.time_str,0,255);
+    sprintf(msg.time_str, "%d-%02d-%02d %02d:%02d:%02d", t->tm_year + 1900, t->tm_mon + 1,
         t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
-    msg.locate_time = time;
-    msg.save_dir = strPath.GetBuffer();
-
-    std::vector<int> IDs;
-    for (int i = 0; i < m_lasers.size(); ++i)
-        IDs.push_back(m_lasers[i]->ID() + 1);
-    msg.laser_id = IDs;
 
-    if (m_post_result_func && m_ptr)
-        m_post_result_func(msg, m_ptr);*/
+    memset(msg.project_dir,0,255);
+    sprintf(msg.project_dir,"%s",pathCreator.GetCurPath().c_str());
 
+    if(m_post_result_func)
+        m_post_result_func(msg,m_ptr);
 
-    delete this;
 }
 void  MeasureTask::Cancel()
 {

+ 3 - 4
src/measuretask.h

@@ -55,7 +55,7 @@ std::string Error_string(ERROR_CODE code);
 bool RegionInRegion(std::vector<cv::Point2f>& mini_poly, std::vector<cv::Point2f>& large_poly);
 double distance_polys(std::vector<cv::Point2f> poly1, std::vector<cv::Point2f> poly2);
 
-//typedef void(*ResultCallback)(Locate_Message message, void*);
+typedef void(*ResultCallback)(QtMessageData msg, void*);
 
 class MeasureTask : public tq::BaseTask
 {
@@ -64,7 +64,7 @@ public:
         modbus::CPLCMonitor* pcl, Automatic::stCalibParam	param);
     virtual void   Main();
     virtual void   Cancel();
-    //void			SetResultCallback(void* ptr,ResultCallback func = NULL);
+    void			SetResultCallback(void* ptr,ResultCallback func = NULL);
 
 protected:
     static void		PushPoint(CPoint3D point, void* pointer);
@@ -88,8 +88,7 @@ protected:
     static	std::mutex*			g_mutex;
     bool						m_exit;
 
-    //CSearchPath					m_searchPath;
-    //ResultCallback				m_post_result_func;
+    ResultCallback				m_post_result_func;
     void*						m_ptr;
 };