CanInterface.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <QString>
  17. #include <stdint.h>
  18. #include "CanDriver.h"
  19. #include "CanTiming.h"
  20. #include <QObject>
  21. class CanMessage;
  22. class MeasurementInterface;
  23. class CanInterface: public QObject {
  24. public:
  25. enum {
  26. state_ok,
  27. state_warning,
  28. state_passive,
  29. state_bus_off,
  30. state_stopped,
  31. state_unknown
  32. };
  33. enum {
  34. capability_canfd = 0x01,
  35. capability_listen_only = 0x02,
  36. capability_triple_sampling = 0x04,
  37. capability_one_shot = 0x08,
  38. capability_auto_restart = 0x10,
  39. capability_config_os = 0x20
  40. };
  41. public:
  42. CanInterface(CanDriver *driver);
  43. virtual ~CanInterface();
  44. virtual CanDriver *getDriver();
  45. virtual QString getName() const = 0;
  46. virtual QString getDetailsStr() const;
  47. virtual void applyConfig(const MeasurementInterface &mi) = 0;
  48. virtual unsigned getBitrate() = 0;
  49. virtual uint32_t getCapabilities();
  50. virtual QList<CanTiming> getAvailableBitrates();
  51. virtual void open();
  52. virtual void close();
  53. virtual bool isOpen();
  54. virtual void sendMessage(const CanMessage &msg) = 0;
  55. virtual bool readMessage(CanMessage &msg, unsigned int timeout_ms) = 0;
  56. virtual bool updateStatistics();
  57. virtual uint32_t getState() = 0;
  58. virtual int getNumRxFrames() = 0;
  59. virtual int getNumRxErrors() = 0;
  60. virtual int getNumTxFrames() = 0;
  61. virtual int getNumTxErrors() = 0;
  62. virtual int getNumRxOverruns() = 0;
  63. virtual int getNumTxDropped() = 0;
  64. QString getStateText();
  65. CanInterfaceId getId() const;
  66. void setId(CanInterfaceId id);
  67. private:
  68. CanInterfaceId _id;
  69. CanDriver *_driver;
  70. };