mainwindow.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "qtmessagedef.h"
  4. #include <time.h>
  5. MainWindow::MainWindow(QWidget *parent) :
  6. QMainWindow(parent),
  7. ui(new Ui::MainWindow)
  8. {
  9. ui->setupUi(this);
  10. setWindowIcon(QIcon("./Resource/log.jpg"));
  11. }
  12. MainWindow::~MainWindow()
  13. {
  14. delete ui;
  15. }
  16. void MainWindow::AddLog(std::string log)
  17. {
  18. if(ui->m_log_list->count()>50)
  19. ui->m_log_list->clear();
  20. char buf[255]={0};
  21. time_t tt = time(0);//时间cuo
  22. struct tm* t = localtime(&tt);
  23. memset(buf,0,255);
  24. sprintf(buf, "%d-%02d-%02d %02d:%02d:%02d %s", t->tm_year + 1900,
  25. t->tm_mon + 1,t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec,log.c_str());
  26. ui->m_log_list->insertItem(ui->m_log_list->count(),buf);
  27. ui->m_log_list->scrollToBottom();
  28. }
  29. void MainWindow::ProcessSlot(QVariant var)
  30. {
  31. QtMessageData data=var.value<QtMessageData>();
  32. if(data.msg_type==ePlcSignal)
  33. {
  34. static unsigned short last_data[255]={0};
  35. for(int i=0;i<data.signal_size;++i)
  36. {
  37. if(data.plc_data[i]!=last_data[i])
  38. {
  39. char buf[255]={0};
  40. sprintf(buf,"P[%d] %d ---> %d",i,last_data[i],data.plc_data[i]);
  41. AddLog(buf);
  42. }
  43. }
  44. }
  45. else if(data.msg_type==eMeasure)
  46. {
  47. std::string msgstr="Laser ID : ";
  48. char buf[255];
  49. memset(buf,0,255);
  50. std::vector<int> IDS;
  51. for(int i=0;i<16;++i)
  52. {
  53. if((0x01<<i) & data.lasers_id !=0)
  54. IDS.push_back(i);
  55. }
  56. for(int i=0;i<IDS.size();++i)
  57. sprintf(buf,"%d ",IDS[i]+1);
  58. msgstr+=buf;
  59. msgstr+='\n';
  60. memset(buf,0,255);
  61. sprintf(buf,"Project dir : %s\n",data.project_dir);
  62. msgstr+=buf;
  63. memset(buf,0,255);
  64. sprintf(buf,"x:%.2f y:%.2f c:%.2f\nl:%.2f w:%.2f h:%.2f D:%.2f\nPosition id:%d\n",
  65. data.x,data.y,data.c,data.l,data.w,data.h,data.d,data.position_id);
  66. msgstr+=buf;
  67. msgstr+=(data.OK!=0)?"Result OK\n":"Result Failed\n";
  68. msgstr+=data.time_str;
  69. ui->m_measure_result->setText(msgstr.c_str());
  70. }
  71. }
  72. #include "qmessagebox.h"
  73. #include "src/pathcreator.h"
  74. void MainWindow::on_m_test_btn_clicked()
  75. {
  76. PathCreator pathCreator;
  77. pathCreator.CreateDatePath("/home/zx/data");
  78. }
  79. #include "Process.h"
  80. extern CProcess* m_pProcess;
  81. void MainWindow::on_m_add_clicked()
  82. {
  83. m_pProcess->PushTask(0x01,1,false);
  84. AddLog(" test tsak ");
  85. }