writecore.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "writecore.h"
  2. #include "../DataWriteDog/writeshm.h"
  3. WriteCore::WriteCore(QObject *parent) : QObject(parent)
  4. {
  5. timer = new QTimer(this);
  6. connect(timer,&QTimer::timeout,this,&WriteCore::time_out);
  7. timer->start(1000);
  8. dbthread = new DatabaseThread(this);
  9. dbthread->start();
  10. connect(dbthread,&DatabaseThread::mqtt_conf,this,&WriteCore::mqtt_data);
  11. connect(dbthread,&DatabaseThread::dbdata_log,this,&WriteCore::dbdata_log);
  12. dbeventthread = new DatabaseEventThread(this);
  13. dbeventthread->start();
  14. connect(dbeventthread,&DatabaseEventThread::dbdata_log,this,&WriteCore::dbdata_log);
  15. logthread = new LogThread(this);
  16. logthread->start();
  17. mqthread = new MqttDataThread(this);
  18. connect(mqthread,&MqttDataThread::mq_log,this,&WriteCore::mq_log);
  19. connect(mqthread,&MqttDataThread::sendMqttData,this,&WriteCore::sendMqttData);
  20. dealmqthread = new DealMqttThread(this);
  21. connect(dealmqthread,&DealMqttThread::dmq_log,this,&WriteCore::dmq_log);
  22. connect(dealmqthread,&DealMqttThread::dmqSql,this,&WriteCore::appendSql);
  23. mqeventthread = new MqttEventDataThread(this);
  24. connect(mqeventthread,&MqttEventDataThread::mq_log,this,&WriteCore::mq_log);
  25. connect(mqeventthread,&MqttEventDataThread::sendMqttData,this,&WriteCore::sendMqttEventData);
  26. dealmqeventthread = new DealMqttEventThread(this);
  27. connect(dealmqeventthread,&DealMqttEventThread::dmq_log,this,&WriteCore::dmq_log);
  28. connect(dealmqeventthread,&DealMqttEventThread::dmqSql,this,&WriteCore::appendEventSql);
  29. mqalarmthread = new MqttAlarmDataThread(this);
  30. connect(mqalarmthread,&MqttAlarmDataThread::mq_log,this,&WriteCore::mq_log);
  31. connect(mqalarmthread,&MqttAlarmDataThread::sendMqttData,this,&WriteCore::sendMqttAlarmData);
  32. dealmqalarmthread = new DealMqttAlarmThread(this);
  33. connect(dealmqalarmthread,&DealMqttAlarmThread::dmq_log,this,&WriteCore::dmq_log);
  34. connect(dealmqalarmthread,&DealMqttAlarmThread::dmqSql,this,&WriteCore::appendEventSql);
  35. }
  36. WriteCore::~WriteCore()
  37. {
  38. dbthread->stop();
  39. dbeventthread->stop();
  40. logthread->stop();
  41. dealmqthread->stop();
  42. dealmqeventthread->stop();
  43. dealmqalarmthread->stop();
  44. }
  45. void WriteCore::start()
  46. {
  47. mqthread->start();
  48. dealmqthread->start();
  49. mqeventthread->start();
  50. dealmqeventthread->start();
  51. mqalarmthread->start();
  52. dealmqalarmthread->start();
  53. }
  54. void WriteCore::time_out()
  55. {
  56. // dataWriteShm->processStatus[1].t_time = QDateTime::currentDateTime().toTime_t();
  57. }
  58. void WriteCore::mqtt_data(QString ip,QString port,QString username,QString password)
  59. {
  60. mqthread->mqtt_conf(ip,port,username,password);
  61. mqeventthread->mqtt_conf(ip,port,username,password);
  62. mqalarmthread->mqtt_conf(ip,port,username,password);
  63. }
  64. void WriteCore::dbdata_log(QString log)
  65. {
  66. logthread->appendData(log);
  67. }
  68. void WriteCore::mq_log(QString log)
  69. {
  70. logthread->appendData(log);
  71. }
  72. void WriteCore::sendMqttData(QString topic,QByteArray data)
  73. {
  74. dealmqthread->appendMqttData(MqttData(topic,data));
  75. }
  76. void WriteCore::sendMqttEventData(QString topic,QByteArray data)
  77. {
  78. dealmqeventthread->appendMqttData(MqttEventData(topic,data));
  79. }
  80. void WriteCore::sendMqttAlarmData(QString topic,QByteArray data)
  81. {
  82. dealmqalarmthread->appendMqttData(MqttAlarmData(topic,data));
  83. }
  84. void WriteCore::dmq_log(QString log)
  85. {
  86. logthread->appendData(log);
  87. }
  88. void WriteCore::appendSql(QString sql)
  89. {
  90. dbthread->appendSql(sql);
  91. }
  92. void WriteCore::appendEventSql(QString sql)
  93. {
  94. dbeventthread->appendSql(sql);
  95. }