SocketCanInterface.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. Copyright (c) 2015, 2016 Hubert Denkmair
  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 "../CanInterface.h"
  17. #include <linux/can/netlink.h>
  18. class SocketCanDriver;
  19. typedef struct {
  20. bool supports_canfd;
  21. bool supports_timing;
  22. uint32_t state;
  23. uint32_t base_freq;
  24. uint32_t sample_point;
  25. uint32_t ctrl_mode;
  26. uint32_t restart_ms;
  27. struct can_bittiming bit_timing;
  28. } can_config_t;
  29. typedef struct {
  30. uint32_t can_state;
  31. uint64_t rx_count;
  32. int rx_errors;
  33. uint64_t rx_overruns;
  34. uint64_t tx_count;
  35. int tx_errors;
  36. uint64_t tx_dropped;
  37. } can_status_t;
  38. class SocketCanInterface: public CanInterface {
  39. public:
  40. SocketCanInterface(SocketCanDriver *driver, int index, QString name);
  41. virtual ~SocketCanInterface();
  42. virtual QString getName() const;
  43. void setName(QString name);
  44. virtual QList<CanTiming> getAvailableBitrates();
  45. virtual void applyConfig(const MeasurementInterface &mi);
  46. virtual bool readConfig();
  47. virtual bool readConfigFromLink(struct rtnl_link *link);
  48. bool supportsTimingConfiguration();
  49. bool supportsCanFD();
  50. bool supportsTripleSampling();
  51. virtual unsigned getBitrate();
  52. virtual uint32_t getCapabilities();
  53. virtual void open();
  54. virtual bool isOpen();
  55. virtual void close();
  56. virtual void sendMessage(const CanMessage &msg);
  57. virtual bool readMessage(CanMessage &msg, unsigned int timeout_ms);
  58. virtual bool updateStatistics();
  59. virtual uint32_t getState();
  60. virtual int getNumRxFrames();
  61. virtual int getNumRxErrors();
  62. virtual int getNumRxOverruns();
  63. virtual int getNumTxFrames();
  64. virtual int getNumTxErrors();
  65. virtual int getNumTxDropped();
  66. int getIfIndex();
  67. private:
  68. typedef enum {
  69. ts_mode_SIOCSHWTSTAMP,
  70. ts_mode_SIOCGSTAMPNS,
  71. ts_mode_SIOCGSTAMP
  72. } ts_mode_t;
  73. int _idx;
  74. bool _isOpen;
  75. int _fd;
  76. QString _name;
  77. can_config_t _config;
  78. can_status_t _status;
  79. ts_mode_t _ts_mode;
  80. const char *cname();
  81. bool updateStatus();
  82. QString buildIpRouteCmd(const MeasurementInterface &mi);
  83. QStringList buildCanIfConfigArgs(const MeasurementInterface &mi);
  84. };