mainwindow.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #include "qmessagebox.h"
  30. void MainWindow::ProcessSlot(QVariant var)
  31. {
  32. QtMessageData data=var.value<QtMessageData>();
  33. if(data.msg_type==ePlcSignal)
  34. {
  35. static unsigned short last_data[255]={0};
  36. for(int i=0;i<data.signal_size;++i)
  37. {
  38. if(data.plc_data[i]!=last_data[i])
  39. {
  40. char buf[255]={0};
  41. sprintf(buf,"P[%d] %d ---> %d",i,last_data[i],data.plc_data[i]);
  42. AddLog(buf);
  43. }
  44. }
  45. }
  46. else if(data.msg_type==eMeasure)
  47. {
  48. std::string msgstr="Laser ID : ";
  49. char buf[255];
  50. memset(buf,0,255);
  51. std::vector<int> IDS;
  52. for(int i=0;i<16;++i)
  53. {
  54. if(((0x01<<i) & data.lasers_id) !=0)
  55. IDS.push_back(i);
  56. }
  57. for(int i=0;i<IDS.size();++i)
  58. sprintf(buf+strlen(buf),"%d ",IDS[i]+1);
  59. msgstr+=buf;
  60. msgstr+='\n';
  61. memset(buf,0,255);
  62. sprintf(buf,"Project dir : %s\n",data.project_dir);
  63. msgstr+=buf;
  64. memset(buf,0,255);
  65. sprintf(buf,"x:%.2f y:%.2f c:%.2f\nl:%.2f w:%.2f h:%.2f D:%.2f\nPosition id:%d\n",
  66. data.x,data.y,data.c,data.l,data.w,data.h,data.d,data.position_id);
  67. msgstr+=buf;
  68. msgstr+=(data.OK!=0)?"Result OK\n":"Result Failed\n";
  69. msgstr+=data.time_str;
  70. ui->m_measure_result->setText(msgstr.c_str());
  71. }
  72. }
  73. #include "qmessagebox.h"
  74. #include "src/pathcreator.h"
  75. void MainWindow::on_m_test_btn_clicked()
  76. {
  77. PathCreator pathCreator;
  78. pathCreator.CreateDatePath("/home/zx/data");
  79. }
  80. #include "Process.h"
  81. extern CProcess* m_pProcess;
  82. void MainWindow::on_m_add_clicked()
  83. {
  84. m_pProcess->PushTask(0xFF,1,false);
  85. AddLog(" test tsak ");
  86. }
  87. void MainWindow::on_m_signal_test_clicked()
  88. {
  89. switch(label_color){
  90. case 0:
  91. ui->m_test_label->setStyleSheet(red_style);
  92. label_color++;
  93. break;
  94. case 1:
  95. ui->m_test_label->setStyleSheet(green_style);
  96. label_color++;
  97. break;
  98. case 2:
  99. ui->m_test_label->setStyleSheet(blue_style);
  100. label_color = 0;
  101. break;
  102. }
  103. }