Backend.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Copyright (c) 2015, 2016 Hubert Denkmair <hubert@denkmair.de>
  3. This file is part of cangaroo.
  4. cangaroo is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. cangaroo is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with cangaroo. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #pragma once
  16. #include <stdint.h>
  17. #include <QObject>
  18. #include <QList>
  19. #include <QMutex>
  20. #include <QDateTime>
  21. #include <QElapsedTimer>
  22. #include <driver/CanDriver.h>
  23. #include <core/CanDb.h>
  24. #include <core/MeasurementSetup.h>
  25. #include <core/Log.h>
  26. class MeasurementNetwork;
  27. class CanTrace;
  28. class CanListener;
  29. class CanDbMessage;
  30. class SetupDialog;
  31. class LogModel;
  32. class Backend : public QObject
  33. {
  34. Q_OBJECT
  35. public:
  36. static Backend &instance();
  37. explicit Backend();
  38. virtual ~Backend();
  39. void addCanDriver(CanDriver &driver);
  40. bool startMeasurement();
  41. bool stopMeasurement();
  42. bool isMeasurementRunning() const;
  43. double getTimestampAtMeasurementStart() const;
  44. uint64_t getUsecsAtMeasurementStart() const;
  45. uint64_t getNsecsSinceMeasurementStart() const;
  46. uint64_t getUsecsSinceMeasurementStart() const;
  47. void logMessage(const QDateTime dt, const log_level_t level, const QString msg);
  48. MeasurementSetup &getSetup();
  49. void loadDefaultSetup(MeasurementSetup &setup);
  50. void setDefaultSetup();
  51. void setSetup(MeasurementSetup &new_setup);
  52. double currentTimeStamp() const;
  53. CanTrace *getTrace();
  54. void clearTrace();
  55. CanDbMessage *findDbMessage(const CanMessage &msg) const;
  56. CanInterfaceIdList getInterfaceList();
  57. CanDriver *getDriverById(CanInterfaceId id);
  58. CanInterface *getInterfaceById(CanInterfaceId id);
  59. QString getInterfaceName(CanInterfaceId id);
  60. QString getDriverName(CanInterfaceId id);
  61. CanDriver *getDriverByName(QString driverName);
  62. CanInterface *getInterfaceByDriverAndName(QString driverName, QString deviceName);
  63. pCanDb loadDbc(QString filename);
  64. void clearLog();
  65. LogModel &getLogModel() const;
  66. signals:
  67. void beginMeasurement();
  68. void endMeasurement();
  69. void onSetupChanged();
  70. void onLogMessage(const QDateTime dt, const log_level_t level, const QString msg);
  71. void onSetupDialogCreated(SetupDialog &dlg);
  72. public slots:
  73. private:
  74. static Backend *_instance;
  75. bool _measurementRunning;
  76. uint64_t _measurementStartTime;
  77. QElapsedTimer _timerSinceStart;
  78. QList<CanDriver*> _drivers;
  79. MeasurementSetup _setup;
  80. CanTrace *_trace;
  81. QList<CanListener*> _listeners;
  82. LogModel *_logModel;
  83. };