├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── cangaroo.desktop ├── cangaroo.pro ├── canifconfig ├── canifconfig.pro └── main.c ├── debian ├── cangaroo.install ├── changelog ├── compat ├── control ├── copyright ├── dirs ├── rules └── source │ └── format ├── gpl-header.txt └── src ├── assets ├── cangaroo.png ├── cangaroo.svg ├── mdibg.png └── mdibg.svg ├── cangaroo.qrc ├── core ├── Backend.cpp ├── Backend.h ├── CanDb.cpp ├── CanDb.h ├── CanDbMessage.cpp ├── CanDbMessage.h ├── CanDbNode.cpp ├── CanDbNode.h ├── CanDbSignal.cpp ├── CanDbSignal.h ├── CanMessage.cpp ├── CanMessage.h ├── CanTrace.cpp ├── CanTrace.h ├── ConfigurableWidget.cpp ├── ConfigurableWidget.h ├── Log.cpp ├── Log.h ├── LogModel.cpp ├── LogModel.h ├── MeasurementInterface.cpp ├── MeasurementInterface.h ├── MeasurementNetwork.cpp ├── MeasurementNetwork.h ├── MeasurementSetup.cpp ├── MeasurementSetup.h ├── core.pri └── portable_endian.h ├── docs └── can_signal_byteorder.ods ├── driver ├── CanDriver.cpp ├── CanDriver.h ├── CanInterface.cpp ├── CanInterface.h ├── CanListener.cpp ├── CanListener.h ├── CanTiming.cpp ├── CanTiming.h ├── CandleApiDriver │ ├── CandleApiDriver.cpp │ ├── CandleApiDriver.h │ ├── CandleApiDriver.pri │ ├── CandleApiInterface.cpp │ ├── CandleApiInterface.h │ ├── CandleApiTiming.cpp │ ├── CandleApiTiming.h │ └── api │ │ ├── LICENSE │ │ ├── candle.c │ │ ├── candle.h │ │ ├── candle_ctrl_req.c │ │ ├── candle_ctrl_req.h │ │ ├── candle_defs.h │ │ └── ch_9.h ├── GenericCanSetupPage.cpp ├── GenericCanSetupPage.h ├── GenericCanSetupPage.ui ├── PeakCanDriver │ ├── PeakCanDriver.cpp │ ├── PeakCanDriver.h │ ├── PeakCanDriver.pri │ ├── PeakCanInterface.cpp │ └── PeakCanInterface.h ├── SocketCanDriver │ ├── SocketCanDriver.cpp │ ├── SocketCanDriver.h │ ├── SocketCanDriver.pri │ ├── SocketCanInterface.cpp │ └── SocketCanInterface.h └── driver.pri ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── parser └── dbc │ ├── DbcParser.cpp │ ├── DbcParser.h │ ├── DbcTokens.cpp │ ├── DbcTokens.h │ └── dbc.pri ├── scripts └── setup_vcan.sh ├── src.pro └── window ├── CanStatusWindow ├── CanStatusWindow.cpp ├── CanStatusWindow.h ├── CanStatusWindow.pri └── CanStatusWindow.ui ├── GraphWindow ├── GraphWindow.cpp ├── GraphWindow.h ├── GraphWindow.pri └── GraphWindow.ui ├── LogWindow ├── LogWindow.cpp ├── LogWindow.h ├── LogWindow.pri └── LogWindow.ui ├── SetupDialog ├── SelectCanInterfacesDialog.cpp ├── SelectCanInterfacesDialog.h ├── SelectCanInterfacesDialog.ui ├── SetupDialog.cpp ├── SetupDialog.h ├── SetupDialog.pri ├── SetupDialog.ui ├── SetupDialogTreeItem.cpp ├── SetupDialogTreeItem.h ├── SetupDialogTreeModel.cpp └── SetupDialogTreeModel.h └── TraceWindow ├── AggregatedTraceViewItem.cpp ├── AggregatedTraceViewItem.h ├── AggregatedTraceViewModel.cpp ├── AggregatedTraceViewModel.h ├── BaseTraceViewModel.cpp ├── BaseTraceViewModel.h ├── LinearTraceViewModel.cpp ├── LinearTraceViewModel.h ├── TraceViewTypes.h ├── TraceWindow.cpp ├── TraceWindow.h ├── TraceWindow.pri └── TraceWindow.ui /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | 3 | *.slo 4 | *.lo 5 | *.o 6 | *.a 7 | *.la 8 | *.lai 9 | *.so 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | 15 | /.qmake.cache 16 | /.qmake.stash 17 | *.pro.user 18 | *.pro.user.* 19 | *.qbs.user 20 | *.qbs.user.* 21 | *.moc 22 | moc_*.cpp 23 | qrc_*.cpp 24 | ui_*.h 25 | Makefile* 26 | *-build-* 27 | 28 | # QtCreator 29 | 30 | *.autosave 31 | 32 | #QtCtreator Qml 33 | *.qmlproject.user 34 | *.qmlproject.user.* 35 | 36 | 37 | test.dbc 38 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | sudo: required 4 | 5 | services: 6 | - docker 7 | 8 | compiler: 9 | - clang 10 | - gcc 11 | 12 | before_install: 13 | - sudo apt-get update -qq 14 | - sudo apt-get install --yes qtbase5-dev qtdeclarative5-dev 15 | - sudo apt-get install --yes qt5-default qttools5-dev-tools libnl-route-3-dev 16 | - qmake -version 17 | 18 | script: 19 | - qmake cangaroo.pro 20 | - make 21 | 22 | git: 23 | depth: 3 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cangaroo 2 | open source can bus analyzer 3 | 4 | written by Hubert Denkmair 5 | 6 | ## building on linux 7 | * to install all required packages in a vanilla ubuntu 16.04: 8 | * sudo apt-get install build-essential git qt5-qmake qtbase5-dev libnl-3-dev libnl-route-3-dev 9 | * build with: 10 | * qmake -qt=qt5 11 | * make 12 | * make install 13 | 14 | ## building on windows 15 | * Qt Creator (Community Version is okay) brings everything you need 16 | * except for the PCAN libraries. 17 | * Get them from http://www.peak-system.com/fileadmin/media/files/pcan-basic.zip 18 | * Extract to .zip to src/driver/PeakCanDriver/pcan-basic-api 19 | * Make sure PCANBasic.dll (the one from pcan-basic-api/Win32 on a "normal" 32bit Windows build) 20 | is found when running cangaroo, e.g. by putting it in the same folder as the .exe file. 21 | * if you don't want Peak support, you can just disable the driver: 22 | remove the line "win32:include($$PWD/driver/PeakCanDriver/PeakCanDriver.pri)" 23 | from src/src.pro 24 | * if you want to deploy the cangaroo app, make sure to also include the needed Qt Libraries. 25 | for a normal release build, these are: Qt5Core.dll Qt5Gui.dll Qt5Widgets.dll Qt5Xml.dll 26 | 27 | ## changelog 28 | 29 | ### v0.2.1 unreleased 30 | * make logging easier 31 | * refactorings 32 | * scroll trace view per pixel, not per item (always show last message when autoscroll is on) 33 | 34 | ### v0.2.0 released 2016-01-24 35 | * docking windows system instead of MDI interface 36 | * windows build 37 | * windows PCAN-basic driver 38 | * handle muxed signals in backend and trace window 39 | * do not try to extract signals from messages when DLC too short 40 | * can status window 41 | * bugfixes in setup dialog 42 | * show timestamps, log level etc. in log window 43 | 44 | ### v0.1.3 released 2016-01-16 45 | * new can interface configuration GUI (missing a suid binary to actually set the config) 46 | * use libnl-route-3 for socketcan device config read 47 | * query socketcan interfaces for supported config options 48 | * new logging subsystem, do not use QDebug any more 49 | * some performance improvements when receiving lots of messages 50 | * bugfix with time-delta view: timestamps not shown when no previous message avail 51 | 52 | ### v0.1.2 released 2016-01-12 53 | * fix device re-scan ("could not bind" console message) 54 | * fix some dbc parsing issues (signed signals, ...) 55 | * implement big endian signals 56 | 57 | ### v0.1.1 released 2016-01-11 58 | * change source structure to better fit debian packaging 59 | * add debian packaging info 60 | 61 | ### v0.1 released 2016-01-10 62 | initial release \o/ 63 | 64 | 65 | 66 | ## todo 67 | 68 | ### backend 69 | * allow for canfd frames 70 | * support non-message frames in traces (e.g. markers) 71 | * implement plugin API 72 | * embed python for scripting 73 | 74 | ### can drivers 75 | * allow socketcan interface config through suid binary 76 | * socketcan: use hardware timestamps (SIOCSHWTSTAMP) if possible 77 | * cannelloni support 78 | * windows vector driver 79 | 80 | ### import / export 81 | * export to other file formats (e.g. Vector ASC, BLF, MDF) 82 | * import CAN-Traces 83 | 84 | ### general ui 85 | * give some style to dock windows 86 | * load/save docks from/to config 87 | 88 | ### log window 89 | * filter log messages by level 90 | 91 | ### can status window 92 | * display #warnings, #passive, #busoff, #restarts of socketcan devices 93 | 94 | ### trace window 95 | * message filtering 96 | * assign colors to can interfaces / messages 97 | * limit displayed number of messages 98 | * show error frames and other non-message frames 99 | * sort signals by startbit, name or position in candb 100 | 101 | ### raw message generator 102 | * provide a simple way to generate raw can messages 103 | 104 | ### CanDB based generator 105 | * generate can messages from candbs 106 | * set signals according to value tables etc. 107 | * provide generator functions for signal values 108 | * allow scripting of signal values 109 | 110 | ### replay window 111 | * replay can traces 112 | * map interfaces in traces to available networks 113 | 114 | ### graph window 115 | * test QCustomPlot 116 | * allow for graphing of interface stats, message stats and signals 117 | 118 | ### packaging / deployment 119 | * provide clean debian package 120 | * gentoo ebuild script 121 | * provide static linked binary 122 | * add windows installer 123 | 124 | -------------------------------------------------------------------------------- /cangaroo.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Version=1.0 3 | Type=Application 4 | Terminal=false 5 | Name=cangaroo 6 | Exec=/usr/bin/cangaroo %f 7 | Comment=CAN Bus Analyzer 8 | Icon=cangaroo 9 | StartupNotify=false 10 | Encoding=UTF-8 11 | Categories=Development 12 | 13 | -------------------------------------------------------------------------------- /cangaroo.pro: -------------------------------------------------------------------------------- 1 | SUBDIRS += src \ 2 | canifconfig 3 | TEMPLATE = subdirs 4 | CONFIG += ordered warn_on qt debug_and_release 5 | CONFIG += c++11 6 | -------------------------------------------------------------------------------- /canifconfig/canifconfig.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | CONFIG += console c++11 3 | CONFIG -= app_bundle 4 | CONFIG -= qt 5 | CONFIG += link_pkgconfig 6 | 7 | SOURCES += main.c 8 | 9 | PKGCONFIG += libnl-3.0 10 | PKGCONFIG += libnl-route-3.0 11 | -------------------------------------------------------------------------------- /debian/cangaroo.install: -------------------------------------------------------------------------------- 1 | bin/cangaroo usr/bin 2 | cangaroo.desktop usr/share/applications 3 | src/assets/cangaroo.png usr/share/pixmaps 4 | src/assets/cangaroo.svg usr/share/pixmaps 5 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | cangaroo (0.2.0-1) experimental; urgency=low 2 | * handle muxed signals in backend and trace window 3 | * can status window 4 | * bugfixes in setup dialog 5 | * do not try to extract signals from messages when DLC too short 6 | * fix windows build 7 | * windows PCAN-basic driver 8 | * show timestamps, log level etc. in log window 9 | 10 | -- Hubert Denkmair Tue, 12 Jan 2016 21:35:00 +0200 11 | 12 | cangaroo (0.1.3-1) experimental; urgency=low 13 | * new can interface configuration GUI (missing a suid binary to actually set the config) 14 | * use libnl-route-3 for socketcan device config read 15 | * query socketcan interfaces for supported config options 16 | * new logging subsystem, do not use QDebug any more 17 | * some performance improvements when receiving lots of messages 18 | * bugfixs with time-delta view 19 | 20 | -- Hubert Denkmair Tue, 12 Jan 2016 21:35:00 +0200 21 | 22 | cangaroo (0.1.2-1) experimental; urgency=low 23 | * fix device re-scan ("could not bind" console message) 24 | * fix some dbc parsing issues (signed signals, ...) 25 | * implement big endian signals 26 | 27 | -- Hubert Denkmair Tue, 12 Jan 2016 21:35:00 +0200 28 | 29 | cangaroo (0.1.1-1) experimental; urgency=low 30 | * change source structure to better fit debian packaging 31 | * add debian packaging info 32 | 33 | -- Hubert Denkmair Mon, 11 Jan 2016 00:30:00 +0200 34 | 35 | cangaroo (0.1.0-1) experimental; urgency=low 36 | * Initial Release 37 | 38 | -- Hubert Denkmair Sun, 10 Jan 2016 21:00:00 +0200 39 | 40 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: cangaroo 2 | Section: unknown 3 | Priority: optional 4 | Maintainer: Hubert Denkmair 5 | Build-Depends: debhelper (>= 9), qtbase5-dev, qtbase5-dev-tools, qt5-qmake 6 | Standards-Version: 3.9.6 7 | Homepage: https://cangaroo.org/ 8 | 9 | Package: cangaroo 10 | Architecture: any 11 | Depends: libqt5gui5, libqt5widgets5, libqt5core5a, libqt5xml5, ${misc:Depends}, ${shlibs:Depends} 12 | Description: Qt-based CAN Bus Analyzer 13 | cangaroo is a open source CAN Bus Analyzer based on Qt5 and C++. 14 | It allows for monitoring multiple SocketCAN interfaces, load DBC files, 15 | analyze the CAN Traffic in different views and much more. 16 | It is licensed under GPLv2. See README.md file for more information. 17 | 18 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: cangaroo 3 | Source: https://github.com/HubertD/cangaroo 4 | 5 | Files: * 6 | Copyright: 2015-2016 Hubert Denkmair 7 | License: GPL-2.0+ 8 | 9 | Files: debian/* 10 | Copyright: 2015-2016 Hubert Denkmair 11 | License: GPL-2.0+ 12 | 13 | License: GPL-2.0+ 14 | 15 | This program is free software: you can redistribute it and/or modify 16 | it under the terms of the GNU General Public License as published by 17 | the Free Software Foundation, either version 2 of the License, or 18 | (at your option) any later version. 19 | . 20 | This package is distributed in the hope that it will be useful, 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | GNU General Public License for more details. 24 | . 25 | You should have received a copy of the GNU General Public License 26 | along with this program. If not, see . 27 | . 28 | On Debian systems, the complete text of the GNU General 29 | Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". 30 | -------------------------------------------------------------------------------- /debian/dirs: -------------------------------------------------------------------------------- 1 | usr/bin 2 | usr/share/applications 3 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | export QT_SELECT := qt5 3 | 4 | %: 5 | dh $@ 6 | 7 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /gpl-header.txt: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | -------------------------------------------------------------------------------- /src/assets/cangaroo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HubertD/cangaroo/b4a9d6d8db7fe649444d835a76dbae5f7d82c12f/src/assets/cangaroo.png -------------------------------------------------------------------------------- /src/assets/mdibg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HubertD/cangaroo/b4a9d6d8db7fe649444d835a76dbae5f7d82c12f/src/assets/mdibg.png -------------------------------------------------------------------------------- /src/cangaroo.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | assets/mdibg.png 4 | assets/cangaroo.png 5 | assets/cangaroo.svg 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/core/Backend.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | class MeasurementNetwork; 36 | class CanTrace; 37 | class CanListener; 38 | class CanDbMessage; 39 | class SetupDialog; 40 | class LogModel; 41 | 42 | class Backend : public QObject 43 | { 44 | Q_OBJECT 45 | public: 46 | static Backend &instance(); 47 | 48 | explicit Backend(); 49 | virtual ~Backend(); 50 | 51 | void addCanDriver(CanDriver &driver); 52 | 53 | bool startMeasurement(); 54 | bool stopMeasurement(); 55 | bool isMeasurementRunning() const; 56 | double getTimestampAtMeasurementStart() const; 57 | uint64_t getUsecsAtMeasurementStart() const; 58 | uint64_t getNsecsSinceMeasurementStart() const; 59 | uint64_t getUsecsSinceMeasurementStart() const; 60 | 61 | 62 | void logMessage(const QDateTime dt, const log_level_t level, const QString msg); 63 | 64 | MeasurementSetup &getSetup(); 65 | void loadDefaultSetup(MeasurementSetup &setup); 66 | void setDefaultSetup(); 67 | void setSetup(MeasurementSetup &new_setup); 68 | 69 | double currentTimeStamp() const; 70 | 71 | CanTrace *getTrace(); 72 | void clearTrace(); 73 | 74 | CanDbMessage *findDbMessage(const CanMessage &msg) const; 75 | 76 | CanInterfaceIdList getInterfaceList(); 77 | CanDriver *getDriverById(CanInterfaceId id); 78 | CanInterface *getInterfaceById(CanInterfaceId id); 79 | QString getInterfaceName(CanInterfaceId id); 80 | QString getDriverName(CanInterfaceId id); 81 | 82 | CanDriver *getDriverByName(QString driverName); 83 | CanInterface *getInterfaceByDriverAndName(QString driverName, QString deviceName); 84 | 85 | pCanDb loadDbc(QString filename); 86 | 87 | void clearLog(); 88 | LogModel &getLogModel() const; 89 | 90 | signals: 91 | void beginMeasurement(); 92 | void endMeasurement(); 93 | 94 | void onSetupChanged(); 95 | 96 | void onLogMessage(const QDateTime dt, const log_level_t level, const QString msg); 97 | 98 | void onSetupDialogCreated(SetupDialog &dlg); 99 | 100 | public slots: 101 | 102 | private: 103 | static Backend *_instance; 104 | 105 | bool _measurementRunning; 106 | uint64_t _measurementStartTime; 107 | QElapsedTimer _timerSinceStart; 108 | QList _drivers; 109 | MeasurementSetup _setup; 110 | CanTrace *_trace; 111 | QList _listeners; 112 | 113 | LogModel *_logModel; 114 | }; 115 | -------------------------------------------------------------------------------- /src/core/CanDb.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "CanDb.h" 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | CanDb::CanDb() 29 | { 30 | 31 | } 32 | 33 | QString CanDb::getFileName() 34 | { 35 | QFileInfo fi(getPath()); 36 | return fi.fileName(); 37 | } 38 | 39 | QString CanDb::getDirectory() 40 | { 41 | QFileInfo fi(getPath()); 42 | return fi.absolutePath(); 43 | } 44 | 45 | CanDbNode *CanDb::getOrCreateNode(QString node_name) 46 | { 47 | if (!_nodes.contains(node_name)) { 48 | CanDbNode *node = new CanDbNode(this); 49 | node->setName(node_name); 50 | _nodes[node_name] = node; 51 | return node; 52 | } else { 53 | return _nodes[node_name]; 54 | } 55 | } 56 | 57 | CanDbMessage *CanDb::getMessageById(uint32_t raw_id) 58 | { 59 | if (_messages.contains(raw_id)) { 60 | return _messages[raw_id]; 61 | } else { 62 | return 0; 63 | } 64 | } 65 | 66 | void CanDb::addMessage(CanDbMessage *msg) 67 | { 68 | _messages[msg->getRaw_id()] = msg; 69 | } 70 | 71 | QString CanDb::getComment() const 72 | { 73 | return _comment; 74 | } 75 | 76 | void CanDb::setComment(const QString &comment) 77 | { 78 | _comment = comment; 79 | } 80 | 81 | bool CanDb::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root) 82 | { 83 | (void) backend; 84 | (void) xml; 85 | root.setAttribute("type", "dbc"); 86 | root.setAttribute("filename", _path); 87 | return true; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /src/core/CanDb.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "CanDbNode.h" 30 | #include "CanDbMessage.h" 31 | 32 | class QDomDocument; 33 | class QDomElement; 34 | 35 | class Backend; 36 | class CanDb; 37 | class CanDbMessage; 38 | 39 | typedef QMap CanDbNodeMap; 40 | typedef QMap CanDbMessageList; 41 | typedef QSharedPointer pCanDb; 42 | 43 | class CanDb 44 | { 45 | public: 46 | CanDb(); 47 | 48 | void setPath(QString path) { _path = path; } 49 | QString getPath() { return _path; } 50 | QString getFileName(); 51 | QString getDirectory(); 52 | 53 | void setVersion(QString version) { _version = version; } 54 | QString getVersion() { return _version; } 55 | 56 | CanDbNode *getOrCreateNode(QString node_name); 57 | 58 | CanDbMessage *getMessageById(uint32_t raw_id); 59 | void addMessage(CanDbMessage *msg); 60 | 61 | QString getComment() const; 62 | void setComment(const QString &comment); 63 | 64 | bool saveXML(Backend &backend, QDomDocument &xml, QDomElement &root); 65 | 66 | private: 67 | QString _path; 68 | QString _version; 69 | QString _comment; 70 | CanDbNodeMap _nodes; 71 | CanDbMessageList _messages; 72 | 73 | }; 74 | -------------------------------------------------------------------------------- /src/core/CanDbMessage.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "CanDbMessage.h" 23 | 24 | CanDbMessage::CanDbMessage(CanDb *parent) 25 | : _parent(parent), _raw_id(0), _dlc(0), _sender(0), _muxer(0) 26 | { 27 | } 28 | 29 | QString CanDbMessage::getName() const 30 | { 31 | return _name; 32 | } 33 | 34 | void CanDbMessage::setName(const QString &name) 35 | { 36 | _name = name; 37 | } 38 | 39 | uint32_t CanDbMessage::getRaw_id() const 40 | { 41 | return _raw_id; 42 | } 43 | 44 | void CanDbMessage::setRaw_id(const uint32_t &raw_id) 45 | { 46 | _raw_id = raw_id; 47 | } 48 | 49 | uint8_t CanDbMessage::getDlc() const 50 | { 51 | return _dlc; 52 | } 53 | 54 | void CanDbMessage::setDlc(const uint8_t &dlc) 55 | { 56 | _dlc = dlc; 57 | } 58 | 59 | CanDbNode *CanDbMessage::getSender() const 60 | { 61 | return _sender; 62 | } 63 | 64 | void CanDbMessage::setSender(CanDbNode *sender) 65 | { 66 | _sender = sender; 67 | } 68 | 69 | void CanDbMessage::addSignal(CanDbSignal *signal) 70 | { 71 | _signals.append(signal); 72 | } 73 | 74 | CanDbSignal *CanDbMessage::getSignal(int num) 75 | { 76 | if (_signals.size()>num) { 77 | return _signals[num]; 78 | } else { 79 | return 0; 80 | } 81 | } 82 | 83 | CanDbSignal *CanDbMessage::getSignalByName(QString signal_name) 84 | { 85 | CanDbSignal *signal; 86 | foreach (signal, _signals) { 87 | if (signal->name() == signal_name) { 88 | return signal; 89 | } 90 | } 91 | return 0; 92 | } 93 | 94 | QString CanDbMessage::getComment() const 95 | { 96 | return _comment; 97 | } 98 | 99 | void CanDbMessage::setComment(const QString &comment) 100 | { 101 | _comment = comment; 102 | } 103 | 104 | CanDbSignal *CanDbMessage::getMuxer() const 105 | { 106 | return _muxer; 107 | } 108 | 109 | void CanDbMessage::setMuxer(CanDbSignal *muxer) 110 | { 111 | _muxer = muxer; 112 | } 113 | -------------------------------------------------------------------------------- /src/core/CanDbMessage.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include "CanDb.h" 27 | #include "CanDbSignal.h" 28 | 29 | class CanDbNode; 30 | class CanDbSignal; 31 | 32 | typedef QList CanDbSignalList; 33 | 34 | class CanDbMessage 35 | { 36 | public: 37 | CanDbMessage(CanDb *parent); 38 | 39 | QString getName() const; 40 | void setName(const QString &name); 41 | 42 | uint32_t getRaw_id() const; 43 | void setRaw_id(const uint32_t &raw_id); 44 | 45 | uint8_t getDlc() const; 46 | void setDlc(const uint8_t &dlc); 47 | 48 | CanDbNode *getSender() const; 49 | void setSender(CanDbNode *sender); 50 | 51 | void addSignal(CanDbSignal *signal); 52 | CanDbSignal *getSignal(int num); 53 | CanDbSignal *getSignalByName(QString signal_name); 54 | 55 | CanDbSignalList getSignals() { return _signals; } 56 | 57 | QString getComment() const; 58 | void setComment(const QString &comment); 59 | 60 | CanDbSignal *getMuxer() const; 61 | void setMuxer(CanDbSignal *muxer); 62 | 63 | private: 64 | CanDb *_parent; 65 | QString _name; 66 | uint32_t _raw_id; 67 | uint8_t _dlc; 68 | CanDbNode *_sender; 69 | CanDbSignalList _signals; 70 | QString _comment; 71 | CanDbSignal *_muxer; 72 | 73 | }; 74 | -------------------------------------------------------------------------------- /src/core/CanDbNode.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "CanDbNode.h" 23 | 24 | CanDbNode::CanDbNode(CanDb *parent) 25 | : _parent(parent) 26 | { 27 | 28 | } 29 | 30 | QString CanDbNode::name() const 31 | { 32 | return _name; 33 | } 34 | 35 | void CanDbNode::setName(const QString &name) 36 | { 37 | _name = name; 38 | } 39 | 40 | QString CanDbNode::comment() const 41 | { 42 | return _comment; 43 | } 44 | 45 | void CanDbNode::setComment(const QString &comment) 46 | { 47 | _comment = comment; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/core/CanDbNode.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | class CanDb; 27 | 28 | class CanDbNode 29 | { 30 | public: 31 | CanDbNode(CanDb *parent); 32 | 33 | QString name() const; 34 | void setName(const QString &name); 35 | 36 | QString comment() const; 37 | void setComment(const QString &comment); 38 | 39 | private: 40 | CanDb *_parent; 41 | QString _name; 42 | QString _comment; 43 | }; 44 | -------------------------------------------------------------------------------- /src/core/CanDbSignal.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "CanDbSignal.h" 23 | 24 | CanDbSignal::CanDbSignal(CanDbMessage *parent) 25 | : _parent(parent), 26 | _isUnsigned(false), 27 | _isBigEndian(false), 28 | _factor(1), 29 | _offset(0), 30 | _min(0), 31 | _max(0), 32 | _isMuxer(false), 33 | _isMuxed(false), 34 | _muxValue(0) 35 | { 36 | } 37 | 38 | QString CanDbSignal::name() const 39 | { 40 | return _name; 41 | } 42 | 43 | void CanDbSignal::setName(const QString &name) 44 | { 45 | _name = name; 46 | } 47 | 48 | uint8_t CanDbSignal::startBit() const 49 | { 50 | return _startBit; 51 | } 52 | 53 | void CanDbSignal::setStartBit(uint8_t startBit) 54 | { 55 | _startBit = startBit; 56 | } 57 | 58 | uint8_t CanDbSignal::length() const 59 | { 60 | return _length; 61 | } 62 | 63 | void CanDbSignal::setLength(uint8_t length) 64 | { 65 | _length = length; 66 | } 67 | 68 | QString CanDbSignal::comment() const 69 | { 70 | return _comment; 71 | } 72 | 73 | void CanDbSignal::setComment(const QString &comment) 74 | { 75 | _comment = comment; 76 | } 77 | 78 | QString CanDbSignal::getValueName(const uint32_t value) const 79 | { 80 | if (_valueTable.contains(value)) { 81 | return _valueTable[value]; 82 | } else { 83 | return QString(); 84 | } 85 | } 86 | 87 | void CanDbSignal::setValueName(const uint32_t value, const QString &name) 88 | { 89 | _valueTable[value] = name; 90 | } 91 | 92 | double CanDbSignal::convertRawValueToPhysical(const uint32_t rawValue) 93 | { 94 | int v; 95 | if (isUnsigned()) { 96 | v = rawValue; 97 | } else { 98 | // TODO check with DBC that actually contains signed values?! 99 | v = (int32_t)(rawValue<<(32-_length)); 100 | v>>=(32-_length); 101 | } 102 | return v * _factor + _offset; 103 | } 104 | 105 | double CanDbSignal::extractPhysicalFromMessage(const CanMessage &msg) 106 | { 107 | return convertRawValueToPhysical(extractRawDataFromMessage(msg)); 108 | } 109 | 110 | double CanDbSignal::getFactor() const 111 | { 112 | return _factor; 113 | } 114 | 115 | void CanDbSignal::setFactor(double factor) 116 | { 117 | _factor = factor; 118 | } 119 | 120 | double CanDbSignal::getOffset() const 121 | { 122 | return _offset; 123 | } 124 | 125 | void CanDbSignal::setOffset(double offset) 126 | { 127 | _offset = offset; 128 | } 129 | 130 | double CanDbSignal::getMinimumValue() const 131 | { 132 | return _min; 133 | } 134 | 135 | void CanDbSignal::setMinimumValue(double min) 136 | { 137 | _min = min; 138 | } 139 | 140 | double CanDbSignal::getMaximumValue() const 141 | { 142 | return _max; 143 | } 144 | 145 | void CanDbSignal::setMaximumValue(double max) 146 | { 147 | _max = max; 148 | } 149 | 150 | QString CanDbSignal::getUnit() const 151 | { 152 | return _unit; 153 | } 154 | 155 | void CanDbSignal::setUnit(const QString &unit) 156 | { 157 | _unit = unit; 158 | } 159 | 160 | bool CanDbSignal::isUnsigned() const 161 | { 162 | return _isUnsigned; 163 | } 164 | 165 | void CanDbSignal::setUnsigned(bool isUnsigned) 166 | { 167 | _isUnsigned = isUnsigned; 168 | } 169 | bool CanDbSignal::isBigEndian() const 170 | { 171 | return _isBigEndian; 172 | } 173 | 174 | void CanDbSignal::setIsBigEndian(bool isBigEndian) 175 | { 176 | _isBigEndian = isBigEndian; 177 | } 178 | 179 | bool CanDbSignal::isMuxer() const 180 | { 181 | return _isMuxer; 182 | } 183 | 184 | void CanDbSignal::setIsMuxer(bool isMuxer) 185 | { 186 | _isMuxer = isMuxer; 187 | } 188 | 189 | bool CanDbSignal::isMuxed() const 190 | { 191 | return _isMuxed; 192 | } 193 | 194 | void CanDbSignal::setIsMuxed(bool isMuxed) 195 | { 196 | _isMuxed = isMuxed; 197 | } 198 | 199 | uint32_t CanDbSignal::getMuxValue() const 200 | { 201 | return _muxValue; 202 | } 203 | 204 | void CanDbSignal::setMuxValue(const uint32_t &muxValue) 205 | { 206 | _muxValue = muxValue; 207 | } 208 | 209 | bool CanDbSignal::isPresentInMessage(const CanMessage &msg) 210 | { 211 | if ((_startBit + _length)>(8*msg.getLength())) { 212 | return false; 213 | } 214 | 215 | if (!_isMuxed) { return true; } 216 | 217 | CanDbSignal *muxer = _parent->getMuxer(); 218 | if (!muxer) { return false; } 219 | 220 | return _muxValue == muxer->extractRawDataFromMessage(msg); 221 | } 222 | 223 | uint32_t CanDbSignal::extractRawDataFromMessage(const CanMessage &msg) 224 | { 225 | return msg.extractRawSignal(startBit(), length(), isBigEndian()); 226 | } 227 | 228 | 229 | -------------------------------------------------------------------------------- /src/core/CanDbSignal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "CanMessage.h" 25 | #include "CanDbMessage.h" 26 | #include 27 | #include 28 | 29 | class CanDbMessage; 30 | 31 | typedef QMap CanDbValueTable; 32 | 33 | class CanDbSignal 34 | { 35 | public: 36 | CanDbSignal(CanDbMessage *parent); 37 | QString name() const; 38 | void setName(const QString &name); 39 | 40 | uint8_t startBit() const; 41 | void setStartBit(uint8_t startBit); 42 | 43 | uint8_t length() const; 44 | void setLength(uint8_t length); 45 | 46 | QString comment() const; 47 | void setComment(const QString &comment); 48 | 49 | QString getValueName(const uint32_t value) const; 50 | void setValueName(const uint32_t value, const QString &name); 51 | 52 | double getFactor() const; 53 | void setFactor(double factor); 54 | 55 | double getOffset() const; 56 | void setOffset(double offset); 57 | 58 | double getMinimumValue() const; 59 | void setMinimumValue(double min); 60 | 61 | double getMaximumValue() const; 62 | void setMaximumValue(double max); 63 | 64 | QString getUnit() const; 65 | void setUnit(const QString &unit); 66 | 67 | bool isUnsigned() const; 68 | void setUnsigned(bool isUnsigned); 69 | 70 | bool isBigEndian() const; 71 | void setIsBigEndian(bool isBigEndian); 72 | 73 | bool isMuxer() const; 74 | void setIsMuxer(bool isMuxer); 75 | 76 | bool isMuxed() const; 77 | void setIsMuxed(bool isMuxed); 78 | 79 | uint32_t getMuxValue() const; 80 | void setMuxValue(const uint32_t &muxValue); 81 | 82 | bool isPresentInMessage(const CanMessage &msg); 83 | uint32_t extractRawDataFromMessage(const CanMessage &msg); 84 | 85 | double convertRawValueToPhysical(const uint32_t rawValue); 86 | double extractPhysicalFromMessage(const CanMessage &msg); 87 | 88 | 89 | private: 90 | CanDbMessage *_parent; 91 | QString _name; 92 | uint8_t _startBit; 93 | uint8_t _length; 94 | bool _isUnsigned; 95 | bool _isBigEndian; 96 | double _factor; 97 | double _offset; 98 | double _min; 99 | double _max; 100 | QString _unit; 101 | bool _isMuxer; 102 | bool _isMuxed; 103 | uint32_t _muxValue; 104 | QString _comment; 105 | CanDbValueTable _valueTable; 106 | }; 107 | -------------------------------------------------------------------------------- /src/core/CanMessage.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | class CanMessage { 32 | public: 33 | CanMessage(); 34 | CanMessage(uint32_t can_id); 35 | CanMessage(const CanMessage &msg); 36 | void cloneFrom(const CanMessage &msg); 37 | 38 | uint32_t getRawId() const; 39 | void setRawId(const uint32_t raw_id); 40 | 41 | uint32_t getId() const; 42 | void setId(const uint32_t id); 43 | 44 | bool isExtended() const; 45 | void setExtended(const bool isExtended); 46 | 47 | bool isRTR() const; 48 | void setRTR(const bool isRTR); 49 | 50 | bool isErrorFrame() const; 51 | void setErrorFrame(const bool isErrorFrame); 52 | 53 | CanInterfaceId getInterfaceId() const; 54 | void setInterfaceId(CanInterfaceId interface); 55 | 56 | uint8_t getLength() const; 57 | void setLength(const uint8_t dlc); 58 | 59 | uint8_t getByte(const uint8_t index) const; 60 | void setByte(const uint8_t index, const uint8_t value); 61 | 62 | uint64_t getU64() const; 63 | uint64_t extractRawSignal(uint8_t start_bit, const uint8_t length, const bool isBigEndian) const; 64 | 65 | void setData(const uint8_t d0); 66 | void setData(const uint8_t d0, const uint8_t d1); 67 | void setData(const uint8_t d0, const uint8_t d1, const uint8_t d2); 68 | void setData(const uint8_t d0, const uint8_t d1, const uint8_t d2, const uint8_t d3); 69 | void setData(const uint8_t d0, const uint8_t d1, const uint8_t d2, const uint8_t d3, const uint8_t d4); 70 | void setData(const uint8_t d0, const uint8_t d1, const uint8_t d2, const uint8_t d3, const uint8_t d4, const uint8_t d5); 71 | void setData(const uint8_t d0, const uint8_t d1, const uint8_t d2, const uint8_t d3, const uint8_t d4, const uint8_t d5, const uint8_t d6); 72 | void setData(const uint8_t d0, const uint8_t d1, const uint8_t d2, const uint8_t d3, const uint8_t d4, const uint8_t d5, const uint8_t d6, const uint8_t d7); 73 | 74 | struct timeval getTimestamp() const; 75 | void setTimestamp(const struct timeval timestamp); 76 | void setTimestamp(const uint64_t seconds, const uint32_t micro_seconds); 77 | 78 | double getFloatTimestamp() const; 79 | QDateTime getDateTime() const; 80 | 81 | QString getIdString() const; 82 | QString getDataHexString() const; 83 | 84 | private: 85 | uint32_t _raw_id; 86 | uint8_t _dlc; 87 | CanInterfaceId _interface; 88 | union { 89 | uint8_t _u8[8]; 90 | uint16_t _u16[4]; 91 | uint32_t _u32[2]; 92 | uint64_t _u64; 93 | }; 94 | struct timeval _timestamp; 95 | 96 | }; 97 | -------------------------------------------------------------------------------- /src/core/CanTrace.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "CanMessage.h" 32 | 33 | class CanInterface; 34 | class CanDbMessage; 35 | class CanDbSignal; 36 | class MeasurementSetup; 37 | class Backend; 38 | 39 | class CanTrace : public QObject 40 | { 41 | Q_OBJECT 42 | 43 | public: 44 | explicit CanTrace(Backend &backend, QObject *parent, int flushInterval); 45 | 46 | unsigned long size(); 47 | void clear(); 48 | const CanMessage *getMessage(int idx); 49 | void enqueueMessage(const CanMessage &msg, bool more_to_follow=false); 50 | 51 | void saveCanDump(QFile &file); 52 | void saveVectorAsc(QFile &file); 53 | 54 | bool getMuxedSignalFromCache(const CanDbSignal *signal, uint32_t *raw_value); 55 | 56 | signals: 57 | void messageEnqueued(int idx); 58 | void beforeAppend(int num_messages); 59 | void afterAppend(); 60 | void beforeClear(); 61 | void afterClear(); 62 | 63 | private slots: 64 | void flushQueue(); 65 | 66 | private: 67 | enum { 68 | pool_chunk_size = 1024 69 | }; 70 | 71 | Backend &_backend; 72 | 73 | QVector _data; 74 | int _dataRowsUsed; 75 | int _newRows; 76 | bool _isTimerRunning; 77 | 78 | QMap _muxCache; 79 | 80 | QMutex _mutex; 81 | QMutex _timerMutex; 82 | QTimer _flushTimer; 83 | 84 | void startTimer(); 85 | 86 | 87 | }; 88 | -------------------------------------------------------------------------------- /src/core/ConfigurableWidget.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "ConfigurableWidget.h" 23 | #include 24 | #include 25 | 26 | ConfigurableWidget::ConfigurableWidget(QWidget *parent) : QWidget(parent) 27 | { 28 | 29 | } 30 | 31 | bool ConfigurableWidget::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root) 32 | { 33 | (void) backend; 34 | (void) xml; 35 | (void) root; 36 | return true; 37 | } 38 | 39 | bool ConfigurableWidget::loadXML(Backend &backend, QDomElement &el) 40 | { 41 | (void) backend; 42 | (void) el; 43 | return true; 44 | } 45 | -------------------------------------------------------------------------------- /src/core/ConfigurableWidget.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | class Backend; 28 | class QDomDocument; 29 | class QDomElement; 30 | 31 | class ConfigurableWidget : public QWidget 32 | { 33 | Q_OBJECT 34 | public: 35 | explicit ConfigurableWidget(QWidget *parent = 0); 36 | virtual bool saveXML(Backend &backend, QDomDocument &xml, QDomElement &root); 37 | virtual bool loadXML(Backend &backend, QDomElement &el); 38 | 39 | signals: 40 | void settingsChanged(ConfigurableWidget *sender); 41 | 42 | public slots: 43 | }; 44 | -------------------------------------------------------------------------------- /src/core/Log.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "Log.h" 23 | #include 24 | 25 | void log_msg(const QDateTime dt, const log_level_t level, const QString msg) 26 | { 27 | Backend::instance().logMessage(dt, level, msg); 28 | } 29 | 30 | void log_msg(const log_level_t level, const QString msg) 31 | { 32 | Backend::instance().logMessage(QDateTime::currentDateTime(), level, msg); 33 | } 34 | 35 | void log_debug(const QString msg) 36 | { 37 | log_msg(log_level_debug, msg); 38 | } 39 | 40 | void log_info(const QString msg) 41 | { 42 | log_msg(log_level_info, msg); 43 | } 44 | 45 | void log_warning(const QString msg) 46 | { 47 | log_msg(log_level_warning, msg); 48 | } 49 | 50 | void log_error(const QString msg) 51 | { 52 | log_msg(log_level_error, msg); 53 | } 54 | 55 | void log_critical(const QString msg) 56 | { 57 | log_msg(log_level_critical, msg); 58 | } 59 | 60 | void log_fatal(const QString msg) 61 | { 62 | log_msg(log_level_fatal, msg); 63 | } 64 | -------------------------------------------------------------------------------- /src/core/Log.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | typedef enum log_level { 27 | log_level_debug, 28 | log_level_info, 29 | log_level_warning, 30 | log_level_error, 31 | log_level_critical, 32 | log_level_fatal 33 | } log_level_t; 34 | 35 | void log_msg(const QDateTime dt, const log_level_t level, const QString msg); 36 | void log_msg(const log_level_t level, const QString msg); 37 | 38 | void log_debug(const QString msg); 39 | void log_info(const QString msg); 40 | void log_warning(const QString msg); 41 | void log_error(const QString msg); 42 | void log_critical(const QString msg); 43 | void log_fatal(const QString msg); 44 | -------------------------------------------------------------------------------- /src/core/LogModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | 23 | #include "LogModel.h" 24 | 25 | LogModel::LogModel(Backend &backend) 26 | { 27 | connect(&backend, SIGNAL(onLogMessage(QDateTime,log_level_t,QString)), this, SLOT(onLogMessage(QDateTime,log_level_t,QString))); 28 | } 29 | 30 | LogModel::~LogModel() 31 | { 32 | qDeleteAll(_items); 33 | _items.clear(); 34 | } 35 | 36 | void LogModel::clear() 37 | { 38 | beginResetModel(); 39 | _items.clear(); 40 | endResetModel(); 41 | } 42 | 43 | QModelIndex LogModel::index(int row, int column, const QModelIndex &parent) const 44 | { 45 | if (parent.isValid()) { 46 | return QModelIndex(); 47 | } else { 48 | return createIndex(row, column, (quintptr)0); 49 | } 50 | } 51 | 52 | QModelIndex LogModel::parent(const QModelIndex &child) const 53 | { 54 | (void) child; 55 | return QModelIndex(); 56 | } 57 | 58 | int LogModel::rowCount(const QModelIndex &parent) const 59 | { 60 | (void) parent; 61 | return _items.size(); 62 | } 63 | 64 | int LogModel::columnCount(const QModelIndex &parent) const 65 | { 66 | (void) parent; 67 | return column_count; 68 | } 69 | 70 | bool LogModel::hasChildren(const QModelIndex &parent) const 71 | { 72 | return !parent.isValid(); 73 | } 74 | 75 | QVariant LogModel::headerData(int section, Qt::Orientation orientation, int role) const 76 | { 77 | if (role == Qt::DisplayRole) { 78 | 79 | if (orientation == Qt::Horizontal) { 80 | switch (section) { 81 | case column_time: 82 | return QString("Time"); 83 | case column_level: 84 | return QString("Level"); 85 | case column_text: 86 | return QString("Message"); 87 | } 88 | } 89 | 90 | } 91 | return QVariant(); 92 | } 93 | 94 | QVariant LogModel::data(const QModelIndex &index, int role) const 95 | { 96 | 97 | if (role == Qt::TextAlignmentRole) { 98 | switch (index.column()) { 99 | case column_time: 100 | return Qt::AlignRight + Qt::AlignVCenter; 101 | case column_level: 102 | return Qt::AlignCenter + Qt::AlignVCenter; 103 | case column_text: 104 | return Qt::AlignLeft + Qt::AlignVCenter; 105 | default: 106 | return QVariant(); 107 | } 108 | } 109 | 110 | if (role != Qt::DisplayRole) { 111 | return QVariant(); 112 | } 113 | 114 | if (!index.isValid()) { 115 | return QVariant(); 116 | } 117 | 118 | LogItem *item = _items.value(index.row(), 0); 119 | if (item) { 120 | 121 | switch (index.column()) { 122 | case column_time: 123 | return item->dt.toString("hh:mm:ss"); 124 | case column_level: 125 | return logLevelText(item->level); 126 | case column_text: 127 | return item->text; 128 | default: 129 | return QVariant(); 130 | } 131 | 132 | } 133 | return QVariant(); 134 | } 135 | 136 | void LogModel::onLogMessage(const QDateTime dt, const log_level_t level, const QString msg) 137 | { 138 | LogItem *item = new LogItem(); 139 | item->dt = dt; 140 | item->level = level; 141 | item->text = msg; 142 | 143 | beginInsertRows(QModelIndex(), _items.size(), _items.size()); 144 | _items.append(item); 145 | endInsertRows(); 146 | } 147 | 148 | QString LogModel::logLevelText(log_level_t level) 149 | { 150 | switch (level) { 151 | case log_level_debug: return "debug"; 152 | case log_level_info: return "info"; 153 | case log_level_warning: return "warning"; 154 | case log_level_error: return "error"; 155 | case log_level_critical: return "critical"; 156 | case log_level_fatal: return "fatal"; 157 | default: return ""; 158 | } 159 | } 160 | 161 | -------------------------------------------------------------------------------- /src/core/LogModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | class LogItem { 30 | public: 31 | QDateTime dt; 32 | log_level_t level; 33 | QString text; 34 | }; 35 | 36 | class LogModel : public QAbstractItemModel 37 | { 38 | Q_OBJECT 39 | 40 | public: 41 | enum { 42 | column_time, 43 | column_level, 44 | column_text, 45 | column_count 46 | }; 47 | 48 | public: 49 | LogModel(Backend &backend); 50 | virtual ~LogModel(); 51 | 52 | void clear(); 53 | 54 | virtual QModelIndex index(int row, int column, const QModelIndex &parent) const; 55 | virtual QModelIndex parent(const QModelIndex &child) const; 56 | 57 | virtual int rowCount(const QModelIndex &parent) const; 58 | virtual int columnCount(const QModelIndex &parent) const; 59 | virtual bool hasChildren(const QModelIndex &parent) const; 60 | 61 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; 62 | virtual QVariant data(const QModelIndex &index, int role) const; 63 | 64 | public slots: 65 | void onLogMessage(const QDateTime dt, const log_level_t level, const QString msg); 66 | 67 | private: 68 | QList _items; 69 | 70 | static QString logLevelText(log_level_t level); 71 | }; 72 | -------------------------------------------------------------------------------- /src/core/MeasurementInterface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "MeasurementInterface.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | MeasurementInterface::MeasurementInterface() 30 | : _doConfigure(true), 31 | _bitrate(500000), 32 | _samplePoint(875), 33 | _isCanFD(false), 34 | _fdBitrate(4000000), 35 | _fdSamplePoint(875), 36 | 37 | _isListenOnlyMode(false), 38 | _isOneShotMode(false), 39 | _isTripleSampling(false), 40 | _doAutoRestart(false), 41 | _autoRestartMs(100) 42 | { 43 | 44 | } 45 | 46 | bool MeasurementInterface::loadXML(Backend &backend, QDomElement &el) 47 | { 48 | (void) backend; 49 | 50 | _doConfigure = el.attribute("configure", "0").toInt() != 0; 51 | 52 | _bitrate = el.attribute("bitrate", "500000").toInt(); 53 | _samplePoint = el.attribute("sample-point", "875").toInt(); 54 | _isCanFD = el.attribute("can-fd", "0").toInt() != 0; 55 | _fdBitrate = el.attribute("bitrate-fd", "500000").toInt(); 56 | _fdSamplePoint = el.attribute("sample-point-fd", "875").toInt(); 57 | 58 | _isListenOnlyMode = el.attribute("listen-only", "0").toInt() != 0; 59 | _isOneShotMode = el.attribute("one-shot", "0").toInt() != 0; 60 | _isTripleSampling = el.attribute("triple-sampling", "0").toInt() != 0; 61 | _doAutoRestart = el.attribute("auto-restart", "0").toInt() != 0; 62 | _autoRestartMs = el.attribute("auto-restart-time", "100").toInt(); 63 | 64 | return true; 65 | } 66 | 67 | bool MeasurementInterface::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root) 68 | { 69 | (void) xml; 70 | 71 | root.setAttribute("type", "can"); 72 | root.setAttribute("driver", backend.getDriverName(_canif)); 73 | root.setAttribute("name", backend.getInterfaceName(_canif)); 74 | 75 | root.setAttribute("configure", _doConfigure ? 1 : 0); 76 | 77 | root.setAttribute("bitrate", _bitrate); 78 | root.setAttribute("sample-point", _samplePoint); 79 | root.setAttribute("can-fd", _isCanFD ? 1 : 0); 80 | root.setAttribute("bitrate-fd", _fdBitrate); 81 | root.setAttribute("sample-point-fd", _fdSamplePoint); 82 | 83 | root.setAttribute("listen-only", _isListenOnlyMode ? 1 : 0); 84 | root.setAttribute("one-shot", _isOneShotMode ? 1 : 0); 85 | root.setAttribute("triple-sampling", _isTripleSampling ? 1 : 0); 86 | root.setAttribute("auto-restart", _doAutoRestart ? 1 : 0); 87 | root.setAttribute("auto-restart-time", _autoRestartMs); 88 | 89 | return true; 90 | } 91 | 92 | unsigned MeasurementInterface::bitrate() const 93 | { 94 | return _bitrate; 95 | } 96 | 97 | void MeasurementInterface::setBitrate(unsigned bitrate) 98 | { 99 | _bitrate = bitrate; 100 | } 101 | 102 | CanInterfaceId MeasurementInterface::canInterface() const 103 | { 104 | return _canif; 105 | } 106 | 107 | void MeasurementInterface::setCanInterface(CanInterfaceId canif) 108 | { 109 | _canif = canif; 110 | } 111 | 112 | void MeasurementInterface::cloneFrom(MeasurementInterface &origin) 113 | { 114 | *this = origin; 115 | } 116 | 117 | bool MeasurementInterface::doConfigure() const 118 | { 119 | return _doConfigure; 120 | } 121 | 122 | void MeasurementInterface::setDoConfigure(bool doConfigure) 123 | { 124 | _doConfigure = doConfigure; 125 | } 126 | 127 | bool MeasurementInterface::isListenOnlyMode() const 128 | { 129 | return _isListenOnlyMode; 130 | } 131 | 132 | void MeasurementInterface::setListenOnlyMode(bool isListenOnlyMode) 133 | { 134 | _isListenOnlyMode = isListenOnlyMode; 135 | } 136 | 137 | bool MeasurementInterface::isOneShotMode() const 138 | { 139 | return _isOneShotMode; 140 | } 141 | 142 | void MeasurementInterface::setOneShotMode(bool isOneShotMode) 143 | { 144 | _isOneShotMode = isOneShotMode; 145 | } 146 | 147 | bool MeasurementInterface::isTripleSampling() const 148 | { 149 | return _isTripleSampling; 150 | } 151 | 152 | void MeasurementInterface::setTripleSampling(bool isTripleSampling) 153 | { 154 | _isTripleSampling = isTripleSampling; 155 | } 156 | 157 | bool MeasurementInterface::isCanFD() const 158 | { 159 | return _isCanFD; 160 | } 161 | 162 | void MeasurementInterface::setCanFD(bool isCanFD) 163 | { 164 | _isCanFD = isCanFD; 165 | } 166 | 167 | int MeasurementInterface::samplePoint() const 168 | { 169 | return _samplePoint; 170 | } 171 | 172 | void MeasurementInterface::setSamplePoint(int samplePoint) 173 | { 174 | _samplePoint = samplePoint; 175 | } 176 | 177 | unsigned MeasurementInterface::fdBitrate() const 178 | { 179 | return _fdBitrate; 180 | } 181 | 182 | void MeasurementInterface::setFdBitrate(unsigned fdBitrate) 183 | { 184 | _fdBitrate = fdBitrate; 185 | } 186 | 187 | unsigned MeasurementInterface::fdSamplePoint() const 188 | { 189 | return _fdSamplePoint; 190 | } 191 | 192 | void MeasurementInterface::setFdSamplePoint(unsigned fdSamplePoint) 193 | { 194 | _fdSamplePoint = fdSamplePoint; 195 | } 196 | 197 | bool MeasurementInterface::doAutoRestart() const 198 | { 199 | return _doAutoRestart; 200 | } 201 | 202 | void MeasurementInterface::setAutoRestart(bool doAutoRestart) 203 | { 204 | _doAutoRestart = doAutoRestart; 205 | } 206 | 207 | int MeasurementInterface::autoRestartMs() const 208 | { 209 | return _autoRestartMs; 210 | } 211 | 212 | void MeasurementInterface::setAutoRestartMs(int autoRestartMs) 213 | { 214 | _autoRestartMs = autoRestartMs; 215 | } 216 | -------------------------------------------------------------------------------- /src/core/MeasurementInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | class Backend; 29 | 30 | class MeasurementInterface 31 | { 32 | public: 33 | MeasurementInterface(); 34 | 35 | CanInterfaceId canInterface() const; 36 | void setCanInterface(CanInterfaceId canif); 37 | 38 | void cloneFrom(MeasurementInterface &origin); 39 | bool loadXML(Backend &backend, QDomElement &el); 40 | bool saveXML(Backend &backend, QDomDocument &xml, QDomElement &root); 41 | 42 | bool doConfigure() const; 43 | void setDoConfigure(bool doConfigure); 44 | 45 | bool isListenOnlyMode() const; 46 | void setListenOnlyMode(bool isListenOnlyMode); 47 | 48 | bool isOneShotMode() const; 49 | void setOneShotMode(bool isOneShotMode); 50 | 51 | bool isTripleSampling() const; 52 | void setTripleSampling(bool isTripleSampling); 53 | 54 | bool isCanFD() const; 55 | void setCanFD(bool isCanFD); 56 | 57 | unsigned bitrate() const; 58 | void setBitrate(unsigned bitrate); 59 | 60 | int samplePoint() const; 61 | void setSamplePoint(int samplePoint); 62 | 63 | unsigned fdBitrate() const; 64 | void setFdBitrate(unsigned fdBitrate); 65 | 66 | unsigned fdSamplePoint() const; 67 | void setFdSamplePoint(unsigned fdSamplePoint); 68 | 69 | bool doAutoRestart() const; 70 | void setAutoRestart(bool doAutoRestart); 71 | 72 | int autoRestartMs() const; 73 | void setAutoRestartMs(int autoRestartMs); 74 | 75 | private: 76 | CanInterfaceId _canif; 77 | 78 | bool _doConfigure; 79 | 80 | unsigned _bitrate; 81 | unsigned _samplePoint; 82 | 83 | bool _isCanFD; 84 | unsigned _fdBitrate; 85 | unsigned _fdSamplePoint; 86 | 87 | bool _isListenOnlyMode; 88 | bool _isOneShotMode; 89 | bool _isTripleSampling; 90 | bool _doAutoRestart; 91 | int _autoRestartMs; 92 | }; 93 | -------------------------------------------------------------------------------- /src/core/MeasurementNetwork.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "MeasurementNetwork.h" 23 | #include "MeasurementInterface.h" 24 | 25 | #include 26 | 27 | 28 | MeasurementNetwork::MeasurementNetwork() 29 | { 30 | } 31 | 32 | void MeasurementNetwork::cloneFrom(MeasurementNetwork &origin) 33 | { 34 | _name = origin._name; 35 | foreach (MeasurementInterface *omi, origin._interfaces) { 36 | MeasurementInterface *mi = new MeasurementInterface(); 37 | mi->cloneFrom(*omi); 38 | _interfaces.append(mi); 39 | } 40 | _canDbs = origin._canDbs; 41 | } 42 | 43 | void MeasurementNetwork::addInterface(MeasurementInterface *intf) 44 | { 45 | _interfaces.append(intf); 46 | } 47 | 48 | void MeasurementNetwork::removeInterface(MeasurementInterface *intf) 49 | { 50 | _interfaces.removeAll(intf); 51 | } 52 | 53 | QList MeasurementNetwork::interfaces() 54 | { 55 | return _interfaces; 56 | } 57 | 58 | MeasurementInterface *MeasurementNetwork::addCanInterface(CanInterfaceId canif) 59 | { 60 | MeasurementInterface *mi = new MeasurementInterface(); 61 | mi->setCanInterface(canif); 62 | addInterface(mi); 63 | return mi; 64 | } 65 | 66 | CanInterfaceIdList MeasurementNetwork::getReferencedCanInterfaces() 67 | { 68 | CanInterfaceIdList list; 69 | foreach (MeasurementInterface *mi, _interfaces) { 70 | list << mi->canInterface(); 71 | } 72 | return list; 73 | } 74 | 75 | void MeasurementNetwork::addCanDb(QSharedPointer candb) 76 | { 77 | _canDbs.append(candb); 78 | } 79 | 80 | QString MeasurementNetwork::name() const 81 | { 82 | return _name; 83 | } 84 | 85 | void MeasurementNetwork::setName(const QString &name) 86 | { 87 | _name = name; 88 | } 89 | 90 | bool MeasurementNetwork::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root) 91 | { 92 | root.setAttribute("name", _name); 93 | 94 | QDomElement interfacesNode = xml.createElement("interfaces"); 95 | foreach (MeasurementInterface *intf, _interfaces) { 96 | QDomElement intfNode = xml.createElement("interface"); 97 | if (!intf->saveXML(backend, xml, intfNode)) { 98 | return false; 99 | } 100 | interfacesNode.appendChild(intfNode); 101 | } 102 | root.appendChild(interfacesNode); 103 | 104 | QDomElement candbsNode = xml.createElement("databases"); 105 | foreach (pCanDb candb, _canDbs) { 106 | QDomElement dbNode = xml.createElement("database"); 107 | if (!candb->saveXML(backend, xml, dbNode)) { 108 | return false; 109 | } 110 | candbsNode.appendChild(dbNode); 111 | } 112 | root.appendChild(candbsNode); 113 | 114 | 115 | return true; 116 | } 117 | 118 | bool MeasurementNetwork::loadXML(Backend &backend, QDomElement el) 119 | { 120 | setName(el.attribute("name", "unnamed network")); 121 | 122 | QDomNodeList ifList = el.firstChildElement("interfaces").elementsByTagName("interface"); 123 | for (int i=0; igetId()); 130 | mi->loadXML(backend, elIntf); 131 | } else { 132 | log_error(QString("Could not find interface %1/%2, which is referenced in the workspace config file.").arg(driverName, deviceName)); 133 | } 134 | } 135 | 136 | 137 | QDomNodeList dbList = el.firstChildElement("databases").elementsByTagName("database"); 138 | for (int i=0; i 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | class Backend; 33 | class MeasurementInterface; 34 | 35 | class MeasurementNetwork 36 | { 37 | public: 38 | MeasurementNetwork(); 39 | void cloneFrom(MeasurementNetwork &origin); 40 | 41 | void addInterface(MeasurementInterface *intf); 42 | void removeInterface(MeasurementInterface *intf); 43 | QList interfaces(); 44 | 45 | MeasurementInterface *addCanInterface(CanInterfaceId canif); 46 | CanInterfaceIdList getReferencedCanInterfaces(); 47 | 48 | void addCanDb(pCanDb candb); 49 | QList _canDbs; 50 | 51 | QString name() const; 52 | void setName(const QString &name); 53 | 54 | bool saveXML(Backend &backend, QDomDocument &xml, QDomElement &root); 55 | bool loadXML(Backend &backend, QDomElement el); 56 | 57 | private: 58 | QString _name; 59 | QList _interfaces; 60 | }; 61 | -------------------------------------------------------------------------------- /src/core/MeasurementSetup.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "MeasurementSetup.h" 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | MeasurementSetup::MeasurementSetup(QObject *parent) 32 | : QObject(parent) 33 | { 34 | } 35 | 36 | MeasurementSetup::~MeasurementSetup() 37 | { 38 | qDeleteAll(_networks); 39 | } 40 | 41 | void MeasurementSetup::clear() 42 | { 43 | qDeleteAll(_networks); 44 | _networks.clear(); 45 | emit onSetupChanged(); 46 | } 47 | 48 | void MeasurementSetup::cloneFrom(MeasurementSetup &origin) 49 | { 50 | clear(); 51 | foreach (MeasurementNetwork *network, origin._networks) { 52 | MeasurementNetwork *network_copy = new MeasurementNetwork(); 53 | network_copy->cloneFrom(*network); 54 | _networks.append(network_copy); 55 | } 56 | emit onSetupChanged(); 57 | } 58 | 59 | bool MeasurementSetup::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root) 60 | { 61 | foreach (MeasurementNetwork *network, _networks) { 62 | QDomElement networkNode = xml.createElement("network"); 63 | if (!network->saveXML(backend, xml, networkNode)) { 64 | return false; 65 | } 66 | root.appendChild(networkNode); 67 | } 68 | return true; 69 | } 70 | 71 | bool MeasurementSetup::loadXML(Backend &backend, QDomElement &el) 72 | { 73 | clear(); 74 | 75 | QDomNodeList networks = el.elementsByTagName("network"); 76 | for (int i=0; iloadXML(backend, networks.item(i).toElement())) { 79 | return false; 80 | } 81 | } 82 | 83 | emit onSetupChanged(); 84 | return true; 85 | } 86 | 87 | 88 | MeasurementNetwork *MeasurementSetup::createNetwork() 89 | { 90 | MeasurementNetwork *network = new MeasurementNetwork(); 91 | _networks.append(network); 92 | return network; 93 | } 94 | 95 | void MeasurementSetup::removeNetwork(MeasurementNetwork *network) 96 | { 97 | _networks.removeAll(network); 98 | } 99 | 100 | 101 | CanDbMessage *MeasurementSetup::findDbMessage(const CanMessage &msg) const 102 | { 103 | CanDbMessage *result = 0; 104 | 105 | foreach (MeasurementNetwork *network, _networks) { 106 | foreach (pCanDb db, network->_canDbs) { 107 | result = db->getMessageById(msg.getRawId()); 108 | if (result != 0) { 109 | return result; 110 | } 111 | } 112 | } 113 | return result; 114 | } 115 | 116 | QString MeasurementSetup::getInterfaceName(const CanInterface &interface) const 117 | { 118 | return interface.getName(); 119 | } 120 | 121 | int MeasurementSetup::countNetworks() const 122 | { 123 | return _networks.length(); 124 | } 125 | 126 | MeasurementNetwork *MeasurementSetup::getNetwork(int index) const 127 | { 128 | return _networks.value(index); 129 | } 130 | 131 | MeasurementNetwork *MeasurementSetup::getNetworkByName(QString name) const 132 | { 133 | foreach (MeasurementNetwork *network, _networks) { 134 | if (network->name() == name) { 135 | return network; 136 | } 137 | } 138 | return 0; 139 | } 140 | 141 | QList MeasurementSetup::getNetworks() 142 | { 143 | return _networks; 144 | } 145 | 146 | -------------------------------------------------------------------------------- /src/core/MeasurementSetup.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | class Backend; 29 | class MeasurementNetwork; 30 | class CanTrace; 31 | class CanMessage; 32 | class CanInterface; 33 | class CanDbMessage; 34 | 35 | class MeasurementSetup : public QObject 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | explicit MeasurementSetup(QObject *parent); 41 | virtual ~MeasurementSetup(); 42 | void clear(); 43 | 44 | CanDbMessage *findDbMessage(const CanMessage &msg) const; 45 | QString getInterfaceName(const CanInterface &interface) const; 46 | 47 | int countNetworks() const; 48 | MeasurementNetwork *getNetwork(int index) const; 49 | MeasurementNetwork *getNetworkByName(QString name) const; 50 | QList getNetworks(); 51 | MeasurementNetwork *createNetwork(); 52 | void removeNetwork(MeasurementNetwork *network); 53 | 54 | void cloneFrom(MeasurementSetup &origin); 55 | bool saveXML(Backend &backend, QDomDocument &xml, QDomElement &root); 56 | bool loadXML(Backend &backend, QDomElement &el); 57 | 58 | signals: 59 | void onSetupChanged(); 60 | 61 | private: 62 | QList _networks; 63 | }; 64 | -------------------------------------------------------------------------------- /src/core/core.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/Backend.cpp \ 3 | $$PWD/CanMessage.cpp \ 4 | $$PWD/CanTrace.cpp \ 5 | $$PWD/CanDbMessage.cpp \ 6 | $$PWD/CanDb.cpp \ 7 | $$PWD/CanDbNode.cpp \ 8 | $$PWD/CanDbSignal.cpp \ 9 | $$PWD/MeasurementSetup.cpp \ 10 | $$PWD/MeasurementNetwork.cpp \ 11 | $$PWD/MeasurementInterface.cpp \ 12 | $$PWD/LogModel.cpp \ 13 | $$PWD/ConfigurableWidget.cpp \ 14 | $$PWD/Log.cpp 15 | 16 | HEADERS += \ 17 | $$PWD/portable_endian.h \ 18 | $$PWD/Backend.h \ 19 | $$PWD/CanMessage.h \ 20 | $$PWD/CanTrace.h \ 21 | $$PWD/CanDbMessage.h \ 22 | $$PWD/CanDb.h \ 23 | $$PWD/CanDbNode.h \ 24 | $$PWD/CanDbSignal.h \ 25 | $$PWD/MeasurementSetup.h \ 26 | $$PWD/MeasurementNetwork.h \ 27 | $$PWD/MeasurementInterface.h \ 28 | $$PWD/LogModel.h \ 29 | $$PWD/ConfigurableWidget.h \ 30 | $$PWD/Log.h 31 | -------------------------------------------------------------------------------- /src/core/portable_endian.h: -------------------------------------------------------------------------------- 1 | // "License": Public Domain 2 | // I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like. 3 | // In case there are jurisdictions that don't support putting things in the public domain you can also consider it to 4 | // be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it 5 | // an example on how to get the endian conversion functions on different platforms. 6 | 7 | #pragma once 8 | 9 | #if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__) 10 | 11 | # define __WINDOWS__ 12 | 13 | #endif 14 | 15 | #if defined(__linux__) || defined(__CYGWIN__) 16 | 17 | # include 18 | 19 | #elif defined(__WINDOWS__) 20 | 21 | # include 22 | 23 | # if BYTE_ORDER == LITTLE_ENDIAN 24 | 25 | # define htobe16(x) htons(x) 26 | # define htole16(x) (x) 27 | # define be16toh(x) ntohs(x) 28 | # define le16toh(x) (x) 29 | 30 | # define htobe32(x) htonl(x) 31 | # define htole32(x) (x) 32 | # define be32toh(x) ntohl(x) 33 | # define le32toh(x) (x) 34 | 35 | # define htobe64(x) htonll(x) 36 | # define htole64(x) (x) 37 | # define be64toh(x) ntohll(x) 38 | # define le64toh(x) (x) 39 | 40 | # elif BYTE_ORDER == BIG_ENDIAN 41 | 42 | /* that would be xbox 360 */ 43 | # define htobe16(x) (x) 44 | # define htole16(x) __builtin_bswap16(x) 45 | # define be16toh(x) (x) 46 | # define le16toh(x) __builtin_bswap16(x) 47 | 48 | # define htobe32(x) (x) 49 | # define htole32(x) __builtin_bswap32(x) 50 | # define be32toh(x) (x) 51 | # define le32toh(x) __builtin_bswap32(x) 52 | 53 | # define htobe64(x) (x) 54 | # define htole64(x) __builtin_bswap64(x) 55 | # define be64toh(x) (x) 56 | # define le64toh(x) __builtin_bswap64(x) 57 | 58 | # else 59 | 60 | # error byte order not supported 61 | 62 | # endif 63 | 64 | # define __BYTE_ORDER BYTE_ORDER 65 | # define __BIG_ENDIAN BIG_ENDIAN 66 | # define __LITTLE_ENDIAN LITTLE_ENDIAN 67 | # define __PDP_ENDIAN PDP_ENDIAN 68 | 69 | #else 70 | 71 | # error platform not supported 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/docs/can_signal_byteorder.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HubertD/cangaroo/b4a9d6d8db7fe649444d835a76dbae5f7d82c12f/src/docs/can_signal_byteorder.ods -------------------------------------------------------------------------------- /src/driver/CanDriver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "CanDriver.h" 23 | #include 24 | #include 25 | 26 | CanDriver::CanDriver(Backend &backend) 27 | : _backend(backend) 28 | { 29 | setId(0); 30 | } 31 | 32 | CanDriver::~CanDriver() { 33 | // TODO Auto-generated destructor stub 34 | } 35 | 36 | Backend &CanDriver::backend() const 37 | { 38 | return _backend; 39 | } 40 | 41 | void CanDriver::init(int id) 42 | { 43 | setId(id); 44 | } 45 | 46 | void CanDriver::setId(int id) 47 | { 48 | _id = id; 49 | } 50 | 51 | int CanDriver::id() 52 | { 53 | return _id; 54 | } 55 | 56 | QList CanDriver::getInterfaces() const 57 | { 58 | return _interfaces; 59 | } 60 | 61 | CanInterfaceIdList CanDriver::getInterfaceIds() const 62 | { 63 | CanInterfaceIdList retval; 64 | foreach (CanInterface *intf, _interfaces) { 65 | retval.push_back(intf->getId()); 66 | } 67 | return retval; 68 | } 69 | 70 | CanInterface *CanDriver::getInterfaceById(CanInterfaceId id) 71 | { 72 | return _interfaces.value(id & 0xFF); 73 | } 74 | 75 | CanInterfaceId CanDriver::addInterface(CanInterface *intf) 76 | { 77 | intf->setId((id()<<8) | _interfaces.size()); 78 | _interfaces.push_back(intf); 79 | return intf->getId(); 80 | } 81 | 82 | CanInterface *CanDriver::getInterfaceByName(QString ifName) 83 | { 84 | foreach (CanInterface *intf, _interfaces) { 85 | if (intf->getName() == ifName) { 86 | return intf; 87 | } 88 | } 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /src/driver/CanDriver.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | class Backend; 29 | class CanInterface; 30 | 31 | typedef uint16_t CanInterfaceId; 32 | typedef QList CanInterfaceIdList; 33 | 34 | class CanDriver { 35 | public: 36 | CanDriver(Backend &backend); 37 | virtual ~CanDriver(); 38 | 39 | Backend &backend() const; 40 | 41 | void init(int id); 42 | 43 | int id(); 44 | 45 | virtual QString getName() = 0; 46 | virtual bool update() = 0; 47 | 48 | CanInterfaceIdList getInterfaceIds() const; 49 | QList getInterfaces() const; 50 | CanInterface *getInterfaceById(CanInterfaceId id); 51 | CanInterfaceId addInterface(CanInterface *intf); 52 | 53 | CanInterface *getInterfaceByName(QString ifName); 54 | 55 | private: 56 | Backend &_backend; 57 | int _id; 58 | QList _interfaces; 59 | 60 | void setId(int id); 61 | }; 62 | -------------------------------------------------------------------------------- /src/driver/CanInterface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "CanInterface.h" 23 | 24 | #include 25 | 26 | CanInterface::CanInterface(CanDriver *driver) 27 | : _id(-1), _driver(driver) 28 | { 29 | } 30 | 31 | CanInterface::~CanInterface() { 32 | } 33 | 34 | CanDriver* CanInterface::getDriver() { 35 | return _driver; 36 | } 37 | 38 | QString CanInterface::getDetailsStr() const 39 | { 40 | return ""; 41 | } 42 | 43 | uint32_t CanInterface::getCapabilities() 44 | { 45 | return 0; 46 | } 47 | 48 | QList CanInterface::getAvailableBitrates() 49 | { 50 | QList retval; 51 | retval << CanTiming(0, 10000, 0, 875) \ 52 | << CanTiming(1, 20000, 0, 875) \ 53 | << CanTiming(2, 50000, 0, 875) \ 54 | << CanTiming(3, 83333, 0, 875) \ 55 | << CanTiming(4, 100000, 0, 875) \ 56 | << CanTiming(5, 125000, 0, 875) \ 57 | << CanTiming(6, 250000, 0, 875) \ 58 | << CanTiming(7, 500000, 0, 875) \ 59 | << CanTiming(8, 800000, 0, 875) \ 60 | << CanTiming(9, 1000000, 0, 875); 61 | return retval; 62 | } 63 | 64 | void CanInterface::open() { 65 | } 66 | 67 | void CanInterface::close() { 68 | } 69 | 70 | bool CanInterface::updateStatistics() 71 | { 72 | return false; 73 | } 74 | 75 | QString CanInterface::getStateText() 76 | { 77 | switch (getState()) { 78 | case state_ok: return "ok"; 79 | case state_warning: return "warning"; 80 | case state_passive: return "error passive"; 81 | case state_bus_off: return "bus off"; 82 | case state_stopped: return "stopped"; 83 | case state_unknown: return "unknown"; 84 | default: return ""; 85 | } 86 | } 87 | 88 | CanInterfaceId CanInterface::getId() const 89 | { 90 | return _id; 91 | } 92 | 93 | void CanInterface::setId(CanInterfaceId id) 94 | { 95 | _id = id; 96 | } 97 | -------------------------------------------------------------------------------- /src/driver/CanInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include "CanDriver.h" 27 | #include "CanTiming.h" 28 | 29 | class CanMessage; 30 | class MeasurementInterface; 31 | 32 | class CanInterface { 33 | public: 34 | enum { 35 | state_ok, 36 | state_warning, 37 | state_passive, 38 | state_bus_off, 39 | state_stopped, 40 | state_unknown 41 | }; 42 | 43 | enum { 44 | capability_canfd = 0x01, 45 | capability_listen_only = 0x02, 46 | capability_triple_sampling = 0x04, 47 | capability_one_shot = 0x08, 48 | capability_auto_restart = 0x10, 49 | capability_config_os = 0x20 50 | }; 51 | 52 | public: 53 | CanInterface(CanDriver *driver); 54 | virtual ~CanInterface(); 55 | virtual CanDriver *getDriver(); 56 | virtual QString getName() const = 0; 57 | virtual QString getDetailsStr() const; 58 | 59 | virtual void applyConfig(const MeasurementInterface &mi) = 0; 60 | 61 | virtual unsigned getBitrate() = 0; 62 | 63 | virtual uint32_t getCapabilities(); 64 | virtual QList getAvailableBitrates(); 65 | 66 | virtual void open(); 67 | virtual void close(); 68 | 69 | virtual void sendMessage(const CanMessage &msg) = 0; 70 | virtual bool readMessage(CanMessage &msg, unsigned int timeout_ms) = 0; 71 | 72 | virtual bool updateStatistics(); 73 | virtual uint32_t getState() = 0; 74 | virtual int getNumRxFrames() = 0; 75 | virtual int getNumRxErrors() = 0; 76 | virtual int getNumTxFrames() = 0; 77 | virtual int getNumTxErrors() = 0; 78 | virtual int getNumRxOverruns() = 0; 79 | virtual int getNumTxDropped() = 0; 80 | 81 | QString getStateText(); 82 | 83 | CanInterfaceId getId() const; 84 | void setId(CanInterfaceId id); 85 | 86 | private: 87 | CanInterfaceId _id; 88 | CanDriver *_driver; 89 | }; 90 | -------------------------------------------------------------------------------- /src/driver/CanListener.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "CanListener.h" 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include "CanInterface.h" 30 | 31 | CanListener::CanListener(QObject *parent, Backend &backend, CanInterface &intf) 32 | : QObject(parent), 33 | _backend(backend), 34 | _intf(intf), 35 | _shouldBeRunning(true) 36 | { 37 | _thread = new QThread(); 38 | } 39 | 40 | CanListener::~CanListener() 41 | { 42 | delete _thread; 43 | } 44 | 45 | CanInterfaceId CanListener::getInterfaceId() 46 | { 47 | return _intf.getId(); 48 | } 49 | 50 | CanInterface &CanListener::getInterface() 51 | { 52 | return _intf; 53 | } 54 | 55 | void CanListener::run() 56 | { 57 | CanMessage msg; 58 | CanTrace *trace = _backend.getTrace(); 59 | while (_shouldBeRunning) { 60 | if (_intf.readMessage(msg, 1000)) { 61 | trace->enqueueMessage(msg, false); 62 | } 63 | } 64 | _thread->quit(); 65 | } 66 | 67 | void CanListener::startThread() 68 | { 69 | moveToThread(_thread); 70 | connect(_thread, SIGNAL(started()), this, SLOT(run())); 71 | _thread->start(); 72 | } 73 | 74 | void CanListener::requestStop() 75 | { 76 | _shouldBeRunning = false; 77 | } 78 | 79 | void CanListener::waitFinish() 80 | { 81 | requestStop(); 82 | _thread->wait(); 83 | } 84 | -------------------------------------------------------------------------------- /src/driver/CanListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | class QThread; 29 | class CanMessage; 30 | class Backend; 31 | 32 | class CanListener : public QObject 33 | { 34 | Q_OBJECT 35 | 36 | public: 37 | explicit CanListener(QObject *parent, Backend &backend, CanInterface &intf); 38 | virtual ~CanListener(); 39 | 40 | CanInterfaceId getInterfaceId(); 41 | CanInterface &getInterface(); 42 | 43 | signals: 44 | void messageReceived(const CanMessage &msg); 45 | 46 | public slots: 47 | void run(); 48 | 49 | void startThread(); 50 | void requestStop(); 51 | void waitFinish(); 52 | 53 | private: 54 | Backend &_backend; 55 | CanInterface &_intf; 56 | bool _shouldBeRunning; 57 | QThread *_thread; 58 | 59 | }; 60 | -------------------------------------------------------------------------------- /src/driver/CanTiming.cpp: -------------------------------------------------------------------------------- 1 | #include "CanTiming.h" 2 | 3 | CanTiming::CanTiming(unsigned id, unsigned bitrate, unsigned bitrate_fd, unsigned samplePoint) 4 | : _id(id), 5 | _bitrate(bitrate), 6 | _bitrate_fd(bitrate_fd), 7 | _samplePoint(samplePoint) 8 | { 9 | } 10 | 11 | unsigned CanTiming::getId() 12 | { 13 | return _id; 14 | } 15 | 16 | unsigned CanTiming::getBitrate() 17 | { 18 | return _bitrate; 19 | } 20 | 21 | unsigned CanTiming::getBitrateFD() 22 | { 23 | return _bitrate_fd; 24 | } 25 | 26 | bool CanTiming::isCanFD() 27 | { 28 | return _bitrate_fd != 0; 29 | } 30 | 31 | unsigned CanTiming::getSamplePoint() 32 | { 33 | return _samplePoint; 34 | } 35 | 36 | QString CanTiming::getSamplePointStr(unsigned samplePoint) 37 | { 38 | return QString::number(samplePoint/10.0, 'f', 1).append("%"); 39 | } 40 | 41 | QString CanTiming::getTitle() 42 | { 43 | QString format = isCanFD() ? "%1/%3(FD) kBit/s, sample point %2" : "%1 kBit/s, sample point %2"; 44 | return format.arg( 45 | QString::number(getBitrate()/1000, 'f', 2), 46 | getSamplePointStr(getSamplePoint()), 47 | QString::number(getBitrateFD()/1000, 'f', 2) 48 | ); 49 | } 50 | -------------------------------------------------------------------------------- /src/driver/CanTiming.h: -------------------------------------------------------------------------------- 1 | #ifndef CANTIMING_H 2 | #define CANTIMING_H 3 | 4 | #include 5 | 6 | class CanTiming 7 | { 8 | public: 9 | /*! 10 | * \brief CanTiming generic CAN timing description 11 | * \param id internal id to identify this timing for the corresponding CAN driver 12 | * \param bitrate bitrate in bits per second, e.g. 500000 13 | * \param bitrate_fd bitrate for the FD part, or zero this is not a CanFD timing 14 | * \param samplePoint sample point, e.g. 0.875 15 | */ 16 | CanTiming(unsigned id, unsigned bitrate, unsigned bitrate_fd, unsigned samplePoint); 17 | unsigned getId(); 18 | unsigned getBitrate(); 19 | unsigned getBitrateFD(); 20 | bool isCanFD(); 21 | unsigned getSamplePoint(); 22 | static QString getSamplePointStr(unsigned samplePoint); 23 | 24 | /*! 25 | * \brief getTitle get a brief one-line description of this timing 26 | * \return description, e.g. "500kBit/s, sample point 87.5%" 27 | */ 28 | QString getTitle(); 29 | 30 | private: 31 | unsigned _id; 32 | unsigned _bitrate; 33 | unsigned _bitrate_fd; 34 | unsigned _samplePoint; 35 | }; 36 | 37 | #endif // CANTIMING_H 38 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/CandleApiDriver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "CandleApiDriver.h" 23 | #include "api/candle.h" 24 | 25 | #include "CandleApiInterface.h" 26 | #include 27 | 28 | CandleApiDriver::CandleApiDriver(Backend &backend) 29 | : CanDriver(backend), 30 | setupPage(new GenericCanSetupPage(0)) 31 | { 32 | QObject::connect(&backend, SIGNAL(onSetupDialogCreated(SetupDialog&)), setupPage, SLOT(onSetupDialogCreated(SetupDialog&))); 33 | } 34 | 35 | QString CandleApiDriver::getName() 36 | { 37 | return "CandleAPI"; 38 | } 39 | 40 | bool CandleApiDriver::update() 41 | { 42 | candle_list_handle clist; 43 | uint8_t num_interfaces; 44 | candle_handle dev; 45 | 46 | if (candle_list_scan(&clist)) { 47 | if (candle_list_length(clist, &num_interfaces)) { 48 | for (uint8_t i=0; iupdate(dev); 57 | } 58 | 59 | } 60 | 61 | } 62 | } 63 | candle_list_free(clist); 64 | } 65 | 66 | return true; 67 | } 68 | 69 | CandleApiInterface *CandleApiDriver::findInterface(candle_handle dev) 70 | { 71 | foreach (CanInterface *intf, getInterfaces()) { 72 | CandleApiInterface *cif = dynamic_cast(intf); 73 | if (cif->getPath() == std::wstring(candle_dev_get_path(dev))) { 74 | return cif; 75 | } 76 | } 77 | return NULL; 78 | } 79 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/CandleApiDriver.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include "api/candle.h" 27 | 28 | class CandleApiInterface; 29 | class GenericCanSetupPage; 30 | 31 | class CandleApiDriver : public CanDriver 32 | { 33 | public: 34 | CandleApiDriver(Backend &backend); 35 | 36 | virtual QString getName(); 37 | virtual bool update(); 38 | 39 | private: 40 | GenericCanSetupPage *setupPage; 41 | CandleApiInterface *findInterface(candle_handle dev); 42 | 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/CandleApiDriver.pri: -------------------------------------------------------------------------------- 1 | QMAKE_CFLAGS += -std=gnu11 2 | 3 | SOURCES += \ 4 | $$PWD/CandleApiDriver.cpp \ 5 | $$PWD/CandleApiInterface.cpp \ 6 | $$PWD/api/candle.c \ 7 | $$PWD/api/candle_ctrl_req.c \ 8 | $$PWD/CandleApiTiming.cpp 9 | 10 | #win32:LIBS += -L$$PWD/api/ -lcandle_api 11 | win32: LIBS += -lSetupApi 12 | win32: LIBS += -lOle32 13 | win32: LIBS += -lwinusb 14 | 15 | HEADERS += \ 16 | $$PWD/api/candle.h \ 17 | $$PWD/CandleApiDriver.h \ 18 | $$PWD/CandleApiInterface.h \ 19 | $$PWD/api/candle_ctrl_req.h \ 20 | $$PWD/api/candle_defs.h \ 21 | $$PWD/api/ch_9.h \ 22 | $$PWD/CandleApiTiming.h 23 | 24 | FORMS += 25 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/CandleApiInterface.h: -------------------------------------------------------------------------------- 1 | #ifndef CANDLEAPIINTERFACE_H 2 | #define CANDLEAPIINTERFACE_H 3 | 4 | #include 5 | #include 6 | #include "api/candle.h" 7 | #include "CandleApiTiming.h" 8 | #include 9 | #include 10 | 11 | class CandleApiDriver; 12 | 13 | using namespace std; 14 | 15 | class CandleApiInterface : public CanInterface 16 | { 17 | public: 18 | CandleApiInterface(CandleApiDriver *driver, candle_handle handle); 19 | virtual ~CandleApiInterface(); 20 | 21 | virtual QString getName() const; 22 | virtual QString getDetailsStr() const; 23 | 24 | virtual void applyConfig(const MeasurementInterface &mi); 25 | 26 | virtual unsigned getBitrate(); 27 | 28 | virtual uint32_t getCapabilities(); 29 | virtual QList getAvailableBitrates(); 30 | 31 | virtual void open(); 32 | virtual void close(); 33 | 34 | virtual void sendMessage(const CanMessage &msg); 35 | virtual bool readMessage(CanMessage &msg, unsigned int timeout_ms); 36 | 37 | virtual bool updateStatistics(); 38 | virtual uint32_t getState(); 39 | virtual int getNumRxFrames(); 40 | virtual int getNumRxErrors(); 41 | virtual int getNumTxFrames(); 42 | virtual int getNumTxErrors(); 43 | virtual int getNumRxOverruns(); 44 | virtual int getNumTxDropped(); 45 | 46 | wstring getPath() const; 47 | 48 | void update(candle_handle dev); 49 | 50 | private: 51 | 52 | uint64_t _hostOffsetStart; 53 | uint32_t _deviceTicksStart; 54 | 55 | candle_handle _handle; 56 | MeasurementInterface _settings; 57 | Backend &_backend; 58 | 59 | uint64_t _numRx; 60 | uint64_t _numTx; 61 | uint64_t _numTxErr; 62 | 63 | QList _timings; 64 | 65 | bool setBitTiming(uint32_t bitrate, uint32_t samplePoint); 66 | }; 67 | 68 | #endif // CANDLEAPIINTERFACE_H 69 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/CandleApiTiming.cpp: -------------------------------------------------------------------------------- 1 | #include "CandleApiTiming.h" 2 | 3 | CandleApiTiming::CandleApiTiming(uint32_t baseClk, uint32_t bitrate, uint32_t samplePoint, uint32_t brp, uint32_t phase_seg1, uint32_t phase_seg2) 4 | : _baseClk(baseClk), 5 | _bitrate(bitrate), 6 | _samplePoint(samplePoint) 7 | { 8 | _timing.brp = brp; 9 | _timing.phase_seg1 = phase_seg1; 10 | _timing.phase_seg2 = phase_seg2; 11 | _timing.sjw = 1; 12 | _timing.prop_seg = 1; 13 | } 14 | 15 | uint32_t CandleApiTiming::getBaseClk() const 16 | { 17 | return _baseClk; 18 | } 19 | 20 | uint32_t CandleApiTiming::getBitrate() const 21 | { 22 | return _bitrate; 23 | } 24 | 25 | uint32_t CandleApiTiming::getSamplePoint() const 26 | { 27 | return _samplePoint; 28 | } 29 | 30 | candle_bittiming_t CandleApiTiming::getTiming() const 31 | { 32 | return _timing; 33 | } 34 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/CandleApiTiming.h: -------------------------------------------------------------------------------- 1 | #ifndef CANDLEAPITIMING_H 2 | #define CANDLEAPITIMING_H 3 | 4 | #include "api/candle.h" 5 | 6 | class CandleApiTiming 7 | { 8 | public: 9 | CandleApiTiming( 10 | uint32_t baseClk, 11 | uint32_t bitrate, 12 | uint32_t samplePoint, 13 | uint32_t brp, 14 | uint32_t phase_seg1, 15 | uint32_t phase_seg2 16 | ); 17 | 18 | uint32_t getBaseClk() const; 19 | uint32_t getBitrate() const; 20 | uint32_t getSamplePoint() const; 21 | candle_bittiming_t getTiming() const; 22 | 23 | private: 24 | uint32_t _baseClk; 25 | uint32_t _bitrate; 26 | uint32_t _samplePoint; 27 | candle_bittiming_t _timing; 28 | 29 | }; 30 | 31 | #endif // CANDLEAPITIMING_H 32 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/api/candle.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of the candle windows API. 6 | 7 | This library is free software: you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation, either 10 | version 3 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | typedef void* candle_list_handle; 31 | typedef void* candle_handle; 32 | 33 | typedef enum { 34 | CANDLE_DEVSTATE_AVAIL, 35 | CANDLE_DEVSTATE_INUSE 36 | } candle_devstate_t; 37 | 38 | typedef enum { 39 | CANDLE_FRAMETYPE_UNKNOWN, 40 | CANDLE_FRAMETYPE_RECEIVE, 41 | CANDLE_FRAMETYPE_ECHO, 42 | CANDLE_FRAMETYPE_ERROR, 43 | CANDLE_FRAMETYPE_TIMESTAMP_OVFL 44 | } candle_frametype_t; 45 | 46 | enum { 47 | CANDLE_ID_EXTENDED = 0x80000000, 48 | CANDLE_ID_RTR = 0x40000000, 49 | CANDLE_ID_ERR = 0x20000000 50 | }; 51 | 52 | typedef enum { 53 | CANDLE_MODE_NORMAL = 0x00, 54 | CANDLE_MODE_LISTEN_ONLY = 0x01, 55 | CANDLE_MODE_LOOP_BACK = 0x02, 56 | CANDLE_MODE_TRIPLE_SAMPLE = 0x04, 57 | CANDLE_MODE_ONE_SHOT = 0x08, 58 | CANDLE_MODE_HW_TIMESTAMP = 0x10, 59 | } candle_mode_t; 60 | 61 | typedef enum { 62 | CANDLE_ERR_OK = 0, 63 | CANDLE_ERR_CREATE_FILE = 1, 64 | CANDLE_ERR_WINUSB_INITIALIZE = 2, 65 | CANDLE_ERR_QUERY_INTERFACE = 3, 66 | CANDLE_ERR_QUERY_PIPE = 4, 67 | CANDLE_ERR_PARSE_IF_DESCR = 5, 68 | CANDLE_ERR_SET_HOST_FORMAT = 6, 69 | CANDLE_ERR_GET_DEVICE_INFO = 7, 70 | CANDLE_ERR_GET_BITTIMING_CONST = 8, 71 | CANDLE_ERR_PREPARE_READ = 9, 72 | CANDLE_ERR_SET_DEVICE_MODE = 10, 73 | CANDLE_ERR_SET_BITTIMING = 11, 74 | CANDLE_ERR_BITRATE_FCLK = 12, 75 | CANDLE_ERR_BITRATE_UNSUPPORTED = 13, 76 | CANDLE_ERR_SEND_FRAME = 14, 77 | CANDLE_ERR_READ_TIMEOUT = 15, 78 | CANDLE_ERR_READ_WAIT = 16, 79 | CANDLE_ERR_READ_RESULT = 17, 80 | CANDLE_ERR_READ_SIZE = 18, 81 | CANDLE_ERR_SETUPDI_IF_DETAILS = 19, 82 | CANDLE_ERR_SETUPDI_IF_DETAILS2 = 20, 83 | CANDLE_ERR_MALLOC = 21, 84 | CANDLE_ERR_PATH_LEN = 22, 85 | CANDLE_ERR_CLSID = 23, 86 | CANDLE_ERR_GET_DEVICES = 24, 87 | CANDLE_ERR_SETUPDI_IF_ENUM = 25, 88 | CANDLE_ERR_SET_TIMESTAMP_MODE = 26, 89 | CANDLE_ERR_DEV_OUT_OF_RANGE = 27, 90 | CANDLE_ERR_GET_TIMESTAMP = 28, 91 | CANDLE_ERR_SET_PIPE_RAW_IO = 29 92 | } candle_err_t; 93 | 94 | #pragma pack(push,1) 95 | 96 | typedef struct { 97 | uint32_t echo_id; 98 | uint32_t can_id; 99 | uint8_t can_dlc; 100 | uint8_t channel; 101 | uint8_t flags; 102 | uint8_t reserved; 103 | uint8_t data[8]; 104 | uint32_t timestamp_us; 105 | } candle_frame_t; 106 | 107 | typedef struct { 108 | uint32_t feature; 109 | uint32_t fclk_can; 110 | uint32_t tseg1_min; 111 | uint32_t tseg1_max; 112 | uint32_t tseg2_min; 113 | uint32_t tseg2_max; 114 | uint32_t sjw_max; 115 | uint32_t brp_min; 116 | uint32_t brp_max; 117 | uint32_t brp_inc; 118 | } candle_capability_t; 119 | 120 | typedef struct { 121 | uint32_t prop_seg; 122 | uint32_t phase_seg1; 123 | uint32_t phase_seg2; 124 | uint32_t sjw; 125 | uint32_t brp; 126 | } candle_bittiming_t; 127 | 128 | #pragma pack(pop) 129 | 130 | #define DLL 131 | 132 | bool __stdcall DLL candle_list_scan(candle_list_handle *list); 133 | bool __stdcall DLL candle_list_free(candle_list_handle list); 134 | bool __stdcall DLL candle_list_length(candle_list_handle list, uint8_t *len); 135 | 136 | bool __stdcall DLL candle_dev_get(candle_list_handle list, uint8_t dev_num, candle_handle *hdev); 137 | bool __stdcall DLL candle_dev_get_state(candle_handle hdev, candle_devstate_t *state); 138 | wchar_t __stdcall DLL *candle_dev_get_path(candle_handle hdev); 139 | bool __stdcall DLL candle_dev_open(candle_handle hdev); 140 | bool __stdcall DLL candle_dev_get_timestamp_us(candle_handle hdev, uint32_t *timestamp_us); 141 | bool __stdcall DLL candle_dev_close(candle_handle hdev); 142 | bool __stdcall DLL candle_dev_free(candle_handle hdev); 143 | 144 | bool __stdcall DLL candle_channel_count(candle_handle hdev, uint8_t *num_channels); 145 | bool __stdcall DLL candle_channel_get_capabilities(candle_handle hdev, uint8_t ch, candle_capability_t *cap); 146 | bool __stdcall DLL candle_channel_set_timing(candle_handle hdev, uint8_t ch, candle_bittiming_t *data); 147 | bool __stdcall DLL candle_channel_set_bitrate(candle_handle hdev, uint8_t ch, uint32_t bitrate); 148 | bool __stdcall DLL candle_channel_start(candle_handle hdev, uint8_t ch, uint32_t flags); 149 | bool __stdcall DLL candle_channel_stop(candle_handle hdev, uint8_t ch); 150 | 151 | bool __stdcall DLL candle_frame_send(candle_handle hdev, uint8_t ch, candle_frame_t *frame); 152 | bool __stdcall DLL candle_frame_read(candle_handle hdev, candle_frame_t *frame, uint32_t timeout_ms); 153 | 154 | candle_frametype_t __stdcall DLL candle_frame_type(candle_frame_t *frame); 155 | uint32_t __stdcall DLL candle_frame_id(candle_frame_t *frame); 156 | bool __stdcall DLL candle_frame_is_extended_id(candle_frame_t *frame); 157 | bool __stdcall DLL candle_frame_is_rtr(candle_frame_t *frame); 158 | uint8_t __stdcall DLL candle_frame_dlc(candle_frame_t *frame); 159 | uint8_t __stdcall DLL *candle_frame_data(candle_frame_t *frame); 160 | uint32_t __stdcall DLL candle_frame_timestamp_us(candle_frame_t *frame); 161 | 162 | candle_err_t __stdcall DLL candle_dev_last_error(candle_handle hdev); 163 | 164 | #ifdef __cplusplus 165 | } 166 | #endif 167 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/api/candle_ctrl_req.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of the candle windows API. 6 | 7 | This library is free software: you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation, either 10 | version 3 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library. If not, see . 19 | 20 | */ 21 | 22 | #include "candle_ctrl_req.h" 23 | #include "ch_9.h" 24 | 25 | enum { 26 | CANDLE_BREQ_HOST_FORMAT = 0, 27 | CANDLE_BREQ_BITTIMING, 28 | CANDLE_BREQ_MODE, 29 | CANDLE_BREQ_BERR, 30 | CANDLE_BREQ_BT_CONST, 31 | CANDLE_BREQ_DEVICE_CONFIG, 32 | CANDLE_TIMESTAMP_GET, 33 | }; 34 | 35 | static bool usb_control_msg(WINUSB_INTERFACE_HANDLE hnd, uint8_t request, uint8_t requesttype, uint16_t value, uint16_t index, void *data, uint16_t size) 36 | { 37 | WINUSB_SETUP_PACKET packet; 38 | memset(&packet, 0, sizeof(packet)); 39 | 40 | packet.Request = request; 41 | packet.RequestType = requesttype; 42 | packet.Value = value; 43 | packet.Index = index; 44 | packet.Length = size; 45 | 46 | unsigned long bytes_sent = 0; 47 | return WinUsb_ControlTransfer(hnd, packet, (uint8_t*)data, size, &bytes_sent, 0); 48 | } 49 | 50 | bool candle_ctrl_set_host_format(candle_device_t *dev) 51 | { 52 | candle_host_config_t hconf; 53 | hconf.byte_order = 0x0000beef; 54 | 55 | bool rc = usb_control_msg( 56 | dev->winUSBHandle, 57 | CANDLE_BREQ_HOST_FORMAT, 58 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 59 | 1, 60 | dev->interfaceNumber, 61 | &hconf, 62 | sizeof(hconf) 63 | ); 64 | 65 | dev->last_error = rc ? CANDLE_ERR_OK : CANDLE_ERR_SET_HOST_FORMAT; 66 | return rc; 67 | } 68 | 69 | bool candle_ctrl_set_device_mode(candle_device_t *dev, uint8_t channel, uint32_t mode, uint32_t flags) 70 | { 71 | candle_device_mode_t dm; 72 | dm.mode = mode; 73 | dm.flags = flags; 74 | 75 | bool rc = usb_control_msg( 76 | dev->winUSBHandle, 77 | CANDLE_BREQ_MODE, 78 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 79 | channel, 80 | dev->interfaceNumber, 81 | &dm, 82 | sizeof(dm) 83 | ); 84 | 85 | dev->last_error = rc ? CANDLE_ERR_OK : CANDLE_ERR_SET_DEVICE_MODE; 86 | return rc; 87 | } 88 | 89 | 90 | bool candle_ctrl_get_config(candle_device_t *dev, candle_device_config_t *dconf) 91 | { 92 | bool rc = usb_control_msg( 93 | dev->winUSBHandle, 94 | CANDLE_BREQ_DEVICE_CONFIG, 95 | USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 96 | 1, 97 | dev->interfaceNumber, 98 | dconf, 99 | sizeof(*dconf) 100 | ); 101 | 102 | dev->last_error = rc ? CANDLE_ERR_OK : CANDLE_ERR_GET_DEVICE_INFO; 103 | return rc; 104 | } 105 | 106 | bool candle_ctrl_get_timestamp(candle_device_t *dev, uint32_t *current_timestamp) 107 | { 108 | bool rc = usb_control_msg( 109 | dev->winUSBHandle, 110 | CANDLE_TIMESTAMP_GET, 111 | USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 112 | 1, 113 | dev->interfaceNumber, 114 | current_timestamp, 115 | sizeof(*current_timestamp) 116 | ); 117 | 118 | dev->last_error = rc ? CANDLE_ERR_OK : CANDLE_ERR_GET_TIMESTAMP; 119 | return rc; 120 | } 121 | 122 | bool candle_ctrl_get_capability(candle_device_t *dev, uint8_t channel, candle_capability_t *data) 123 | { 124 | bool rc = usb_control_msg( 125 | dev->winUSBHandle, 126 | CANDLE_BREQ_BT_CONST, 127 | USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 128 | channel, 129 | 0, 130 | data, 131 | sizeof(*data) 132 | ); 133 | 134 | dev->last_error = rc ? CANDLE_ERR_OK : CANDLE_ERR_GET_BITTIMING_CONST; 135 | return rc; 136 | } 137 | 138 | bool candle_ctrl_set_bittiming(candle_device_t *dev, uint8_t channel, candle_bittiming_t *data) 139 | { 140 | bool rc = usb_control_msg( 141 | dev->winUSBHandle, 142 | CANDLE_BREQ_BITTIMING, 143 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, 144 | channel, 145 | 0, 146 | data, 147 | sizeof(*data) 148 | ); 149 | 150 | dev->last_error = rc ? CANDLE_ERR_OK : CANDLE_ERR_SET_BITTIMING; 151 | return rc; 152 | } 153 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/api/candle_ctrl_req.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of the candle windows API. 6 | 7 | This library is free software: you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation, either 10 | version 3 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "candle_defs.h" 25 | 26 | enum { 27 | CANDLE_DEVMODE_RESET = 0, 28 | CANDLE_DEVMODE_START = 1 29 | }; 30 | 31 | bool candle_ctrl_set_host_format(candle_device_t *dev); 32 | bool candle_ctrl_set_device_mode(candle_device_t *dev, uint8_t channel, uint32_t mode, uint32_t flags); 33 | bool candle_ctrl_get_config(candle_device_t *dev, candle_device_config_t *dconf); 34 | bool candle_ctrl_get_capability(candle_device_t *dev, uint8_t channel, candle_capability_t *data); 35 | bool candle_ctrl_set_bittiming(candle_device_t *dev, uint8_t channel, candle_bittiming_t *data); 36 | bool candle_ctrl_get_timestamp(candle_device_t *dev, uint32_t *current_timestamp); 37 | 38 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/api/candle_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of the candle windows API. 6 | 7 | This library is free software: you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation, either 10 | version 3 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #undef __CRT__NO_INLINE 33 | #include 34 | #define __CRT__NO_INLINE 35 | 36 | #include "candle.h" 37 | 38 | #define CANDLE_MAX_DEVICES 32 39 | #define CANDLE_URB_COUNT 30 40 | 41 | #pragma pack(push,1) 42 | 43 | typedef struct { 44 | uint32_t byte_order; 45 | } candle_host_config_t; 46 | 47 | typedef struct { 48 | uint8_t reserved1; 49 | uint8_t reserved2; 50 | uint8_t reserved3; 51 | uint8_t icount; 52 | uint32_t sw_version; 53 | uint32_t hw_version; 54 | } candle_device_config_t; 55 | 56 | typedef struct { 57 | uint32_t mode; 58 | uint32_t flags; 59 | } candle_device_mode_t; 60 | 61 | #pragma pack(pop) 62 | 63 | 64 | typedef struct { 65 | OVERLAPPED ovl; 66 | uint8_t buf[128]; 67 | } canlde_rx_urb; 68 | 69 | typedef struct { 70 | wchar_t path[256]; 71 | candle_devstate_t state; 72 | candle_err_t last_error; 73 | 74 | HANDLE deviceHandle; 75 | WINUSB_INTERFACE_HANDLE winUSBHandle; 76 | UCHAR interfaceNumber; 77 | UCHAR bulkInPipe; 78 | UCHAR bulkOutPipe; 79 | 80 | candle_device_config_t dconf; 81 | candle_capability_t bt_const; 82 | canlde_rx_urb rxurbs[CANDLE_URB_COUNT]; 83 | HANDLE rxevents[CANDLE_URB_COUNT]; 84 | } candle_device_t; 85 | 86 | typedef struct { 87 | uint8_t num_devices; 88 | candle_err_t last_error; 89 | candle_device_t dev[CANDLE_MAX_DEVICES]; 90 | } candle_list_t; 91 | -------------------------------------------------------------------------------- /src/driver/CandleApiDriver/api/ch_9.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of the candle windows API. 6 | 7 | This library is free software: you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation, either 10 | version 3 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #define USB_DIR_OUT 0 /* to device */ 25 | #define USB_DIR_IN 0x80 /* to host */ 26 | 27 | #define USB_TYPE_MASK (0x03 << 5) 28 | #define USB_TYPE_STANDARD (0x00 << 5) 29 | #define USB_TYPE_CLASS (0x01 << 5) 30 | #define USB_TYPE_VENDOR (0x02 << 5) 31 | #define USB_TYPE_RESERVED (0x03 << 5) 32 | 33 | #define USB_RECIP_MASK 0x1f 34 | #define USB_RECIP_DEVICE 0x00 35 | #define USB_RECIP_INTERFACE 0x01 36 | #define USB_RECIP_ENDPOINT 0x02 37 | #define USB_RECIP_OTHER 0x03 38 | -------------------------------------------------------------------------------- /src/driver/GenericCanSetupPage.cpp: -------------------------------------------------------------------------------- 1 | #include "GenericCanSetupPage.h" 2 | #include "ui_GenericCanSetupPage.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | GenericCanSetupPage::GenericCanSetupPage(QWidget *parent) : 11 | QWidget(parent), 12 | ui(new Ui::GenericCanSetupPage), 13 | _mi(0), 14 | _enable_ui_updates(false) 15 | { 16 | ui->setupUi(this); 17 | connect(ui->cbBitrate, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); 18 | connect(ui->cbSamplePoint, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); 19 | connect(ui->cbBitrateFD, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); 20 | connect(ui->cbSamplePointFD, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); 21 | 22 | connect(ui->cbConfigOS, SIGNAL(stateChanged(int)), this, SLOT(updateUI())); 23 | connect(ui->cbListenOnly, SIGNAL(stateChanged(int)), this, SLOT(updateUI())); 24 | connect(ui->cbOneShot, SIGNAL(stateChanged(int)), this, SLOT(updateUI())); 25 | connect(ui->cbTripleSampling, SIGNAL(stateChanged(int)), this, SLOT(updateUI())); 26 | connect(ui->cbAutoRestart, SIGNAL(stateChanged(int)), this, SLOT(updateUI())); 27 | } 28 | 29 | GenericCanSetupPage::~GenericCanSetupPage() 30 | { 31 | delete ui; 32 | } 33 | 34 | void GenericCanSetupPage::onSetupDialogCreated(SetupDialog &dlg) 35 | { 36 | dlg.addPage(this); 37 | connect(&dlg, SIGNAL(onShowInterfacePage(SetupDialog&,MeasurementInterface*)), this, SLOT(onShowInterfacePage(SetupDialog&,MeasurementInterface*))); 38 | } 39 | 40 | void GenericCanSetupPage::onShowInterfacePage(SetupDialog &dlg, MeasurementInterface *mi) 41 | { 42 | _mi = mi; 43 | CanInterface *intf = backend().getInterfaceById(_mi->canInterface()); 44 | 45 | _enable_ui_updates = false; 46 | 47 | ui->laDriver->setText(intf->getDriver()->getName()); 48 | ui->laInterface->setText(intf->getName()); 49 | ui->laInterfaceDetails->setText(intf->getDetailsStr()); 50 | 51 | fillBitratesList(intf, _mi->bitrate()); 52 | fillSamplePointsForBitrate(intf, _mi->bitrate(), _mi->samplePoint()); 53 | 54 | ui->cbConfigOS->setChecked(!_mi->doConfigure()); 55 | ui->cbListenOnly->setChecked(_mi->isListenOnlyMode()); 56 | ui->cbOneShot->setChecked(_mi->isOneShotMode()); 57 | ui->cbTripleSampling->setChecked(_mi->isTripleSampling()); 58 | ui->cbAutoRestart->setChecked(_mi->doAutoRestart()); 59 | 60 | disenableUI(_mi->doConfigure()); 61 | dlg.displayPage(this); 62 | 63 | _enable_ui_updates = true; 64 | } 65 | 66 | void GenericCanSetupPage::updateUI() 67 | { 68 | if (_enable_ui_updates && (_mi!=0)) { 69 | CanInterface *intf = backend().getInterfaceById(_mi->canInterface()); 70 | 71 | _mi->setDoConfigure(!ui->cbConfigOS->isChecked()); 72 | _mi->setListenOnlyMode(ui->cbListenOnly->isChecked()); 73 | _mi->setOneShotMode(ui->cbOneShot->isChecked()); 74 | _mi->setTripleSampling(ui->cbTripleSampling->isChecked()); 75 | _mi->setAutoRestart(ui->cbAutoRestart->isChecked()); 76 | _mi->setBitrate(ui->cbBitrate->currentData().toUInt()); 77 | _mi->setSamplePoint(ui->cbSamplePoint->currentData().toUInt()); 78 | 79 | _enable_ui_updates = false; 80 | 81 | disenableUI(_mi->doConfigure()); 82 | fillSamplePointsForBitrate( 83 | intf, 84 | ui->cbBitrate->currentData().toUInt(), 85 | ui->cbSamplePoint->currentData().toUInt() 86 | ); 87 | _enable_ui_updates = true; 88 | 89 | } 90 | 91 | 92 | } 93 | 94 | void GenericCanSetupPage::fillBitratesList(CanInterface *intf, unsigned selectedBitrate) 95 | { 96 | QList bitrates; 97 | foreach (CanTiming t, intf->getAvailableBitrates()) { 98 | if (!bitrates.contains(t.getBitrate())) { 99 | bitrates.append(t.getBitrate()); 100 | } 101 | } 102 | qSort(bitrates); 103 | 104 | ui->cbBitrate->clear(); 105 | foreach (uint32_t br, bitrates) { 106 | ui->cbBitrate->addItem(QString::number(br), br); 107 | } 108 | ui->cbBitrate->setCurrentText(QString::number(selectedBitrate)); 109 | } 110 | 111 | void GenericCanSetupPage::fillSamplePointsForBitrate(CanInterface *intf, unsigned selectedBitrate, unsigned selectedSamplePoint) 112 | { 113 | QList samplePoints; 114 | foreach(CanTiming t, intf->getAvailableBitrates()) { 115 | if (t.getBitrate() == selectedBitrate) { 116 | if (!samplePoints.contains(t.getSamplePoint())) { 117 | samplePoints.append(t.getSamplePoint()); 118 | } 119 | } 120 | } 121 | qSort(samplePoints); 122 | 123 | ui->cbSamplePoint->clear(); 124 | foreach (uint32_t sp, samplePoints) { 125 | ui->cbSamplePoint->addItem(CanTiming::getSamplePointStr(sp), sp); 126 | } 127 | ui->cbSamplePoint->setCurrentText(CanTiming::getSamplePointStr(selectedSamplePoint)); 128 | } 129 | 130 | void GenericCanSetupPage::disenableUI(bool enabled) 131 | { 132 | 133 | CanInterface *intf = backend().getInterfaceById(_mi->canInterface()); 134 | uint32_t caps = intf->getCapabilities(); 135 | 136 | ui->cbBitrate->setEnabled(enabled); 137 | ui->cbSamplePoint->setEnabled(enabled); 138 | ui->cbConfigOS->setEnabled(caps & CanInterface::capability_config_os); 139 | 140 | ui->cbBitrateFD->setEnabled(enabled && (caps & CanInterface::capability_canfd)); 141 | ui->cbSamplePointFD->setEnabled(enabled && (caps & CanInterface::capability_canfd)); 142 | ui->cbListenOnly->setEnabled(enabled && (caps & CanInterface::capability_listen_only)); 143 | ui->cbOneShot->setEnabled(enabled && (caps & CanInterface::capability_one_shot)); 144 | ui->cbTripleSampling->setEnabled(enabled && (caps & CanInterface::capability_triple_sampling)); 145 | ui->cbAutoRestart->setEnabled(enabled && (caps & CanInterface::capability_auto_restart)); 146 | } 147 | 148 | Backend &GenericCanSetupPage::backend() 149 | { 150 | return Backend::instance(); 151 | } 152 | -------------------------------------------------------------------------------- /src/driver/GenericCanSetupPage.h: -------------------------------------------------------------------------------- 1 | #ifndef GENERICCANSETUPPAGE_H 2 | #define GENERICCANSETUPPAGE_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class GenericCanSetupPage; 8 | } 9 | 10 | class CanInterface; 11 | class SetupDialog; 12 | class MeasurementInterface; 13 | class Backend; 14 | 15 | class GenericCanSetupPage : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit GenericCanSetupPage(QWidget *parent = 0); 21 | ~GenericCanSetupPage(); 22 | 23 | public slots: 24 | void onSetupDialogCreated(SetupDialog &dlg); 25 | void onShowInterfacePage(SetupDialog &dlg, MeasurementInterface *mi); 26 | 27 | private slots: 28 | void updateUI(); 29 | 30 | private: 31 | Ui::GenericCanSetupPage *ui; 32 | MeasurementInterface *_mi; 33 | bool _enable_ui_updates; 34 | 35 | void fillBitratesList(CanInterface *intf, unsigned selectedBitrate); 36 | void fillSamplePointsForBitrate(CanInterface *intf, unsigned selectedBitrate, unsigned selectedSamplePoint); 37 | void disenableUI(bool enabled); 38 | 39 | Backend &backend(); 40 | }; 41 | 42 | #endif // GENERICCANSETUPPAGE_H 43 | -------------------------------------------------------------------------------- /src/driver/PeakCanDriver/PeakCanDriver.cpp: -------------------------------------------------------------------------------- 1 | #include "PeakCanDriver.h" 2 | #include "PeakCanInterface.h" 3 | #include 4 | 5 | #include 6 | #include "pcan-basic-api/Include/PCANBasic.h" 7 | 8 | PeakCanDriver::PeakCanDriver(Backend &backend) 9 | : CanDriver(backend), 10 | setupPage(new GenericCanSetupPage(0)) 11 | { 12 | QObject::connect(&backend, SIGNAL(onSetupDialogCreated(SetupDialog&)), setupPage, SLOT(onSetupDialogCreated(SetupDialog&))); 13 | } 14 | 15 | QString PeakCanDriver::getName() 16 | { 17 | return "PCAN"; 18 | } 19 | 20 | bool PeakCanDriver::update() 21 | { 22 | uint32_t channel_status; 23 | for (uint32_t i=PCAN_USBBUS1; i<=PCAN_USBBUS8; i++) { 24 | TPCANStatus result = CAN_GetValue(i, PCAN_CHANNEL_CONDITION, &channel_status, sizeof(channel_status)); 25 | // returns PCAN_CHANNEL_UNAVAILABLE, PCAN_CHANNEL_AVAILABLE, PCAN_CHANNEL_OCCUPIED, PCAN_CHANNEL_PCANVIEW 26 | if(result == PCAN_ERROR_OK) { 27 | if (channel_status!=PCAN_CHANNEL_UNAVAILABLE) { 28 | PeakCanInterface *intf = createOrUpdateInterface(i); 29 | intf->update(); 30 | } 31 | } else { 32 | return false; 33 | } 34 | } 35 | return true; 36 | } 37 | 38 | PeakCanInterface *PeakCanDriver::createOrUpdateInterface(uint32_t hnd) 39 | { 40 | foreach (CanInterface *intf, getInterfaces()) { 41 | PeakCanInterface *pcif = dynamic_cast(intf); 42 | if (pcif->getHandle() == hnd) { 43 | return pcif; 44 | } 45 | } 46 | 47 | PeakCanInterface *pcif = new PeakCanInterface(this, hnd); 48 | addInterface(pcif); 49 | return pcif; 50 | } 51 | -------------------------------------------------------------------------------- /src/driver/PeakCanDriver/PeakCanDriver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class PeakCanInterface; 7 | class GenericCanSetupPage; 8 | 9 | class PeakCanDriver : public CanDriver 10 | { 11 | public: 12 | PeakCanDriver(Backend &backend); 13 | 14 | virtual QString getName(); 15 | virtual bool update(); 16 | 17 | private: 18 | PeakCanInterface *createOrUpdateInterface(uint32_t hnd); 19 | GenericCanSetupPage *setupPage; 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /src/driver/PeakCanDriver/PeakCanDriver.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/PeakCanDriver.cpp \ 3 | $$PWD/PeakCanInterface.cpp 4 | 5 | win32:LIBS += -L$$PWD/pcan-basic-api/Win32/VC_LIB/ -lPCANBasic 6 | win32:INCLUDEPATH += $$PWD/pcan-basic-api/Win32/VC_LIB 7 | win32:DEPENDPATH += $$PWD/pcan-basic-api/Win32/VC_LIB 8 | 9 | HEADERS += \ 10 | $$PWD/PeakCanDriver.h \ 11 | $$PWD/PeakCanInterface.h 12 | 13 | FORMS += 14 | -------------------------------------------------------------------------------- /src/driver/PeakCanDriver/PeakCanInterface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class PeakCanDriver; 7 | 8 | class PeakCanInterface : public CanInterface 9 | { 10 | public: 11 | PeakCanInterface(PeakCanDriver *driver, uint32_t handle); 12 | virtual ~PeakCanInterface(); 13 | void update(); 14 | uint32_t getHandle() const; 15 | 16 | virtual QString getName() const; 17 | 18 | virtual void applyConfig(const MeasurementInterface &mi); 19 | 20 | virtual uint32_t getCapabilities(); 21 | virtual unsigned getBitrate(); 22 | 23 | virtual QList getAvailableBitrates(); 24 | 25 | virtual void open(); 26 | virtual void close(); 27 | 28 | virtual void sendMessage(const CanMessage &msg); 29 | virtual bool readMessage(CanMessage &msg, unsigned int timeout_ms); 30 | 31 | virtual bool updateStatistics(); 32 | virtual uint32_t getState(); 33 | virtual int getNumRxFrames(); 34 | virtual int getNumRxErrors(); 35 | virtual int getNumTxFrames(); 36 | virtual int getNumTxErrors(); 37 | virtual int getNumRxOverruns(); 38 | virtual int getNumTxDropped(); 39 | 40 | private: 41 | uint32_t _handle; 42 | uint64_t _hostOffsetFirstFrame; 43 | uint64_t _peakOffsetFirstFrame; 44 | void *_autoResetEvent; 45 | 46 | struct { 47 | bool autoRestart; 48 | bool listenOnly; 49 | unsigned bitrate; 50 | unsigned samplePoint; 51 | } _config; 52 | 53 | QList _timings; 54 | 55 | uint16_t calcBitrateMode(unsigned bitrate, unsigned samplePoint); 56 | QString getErrorText(uint32_t status_code); 57 | bool tryReadMessage(CanMessage &msg); 58 | 59 | }; 60 | -------------------------------------------------------------------------------- /src/driver/SocketCanDriver/SocketCanDriver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | 23 | #include "SocketCanDriver.h" 24 | #include "SocketCanInterface.h" 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | SocketCanDriver::SocketCanDriver(Backend &backend) 41 | : CanDriver(backend), 42 | setupPage(new GenericCanSetupPage()) 43 | { 44 | QObject::connect(&backend, SIGNAL(onSetupDialogCreated(SetupDialog&)), setupPage, SLOT(onSetupDialogCreated(SetupDialog&))); 45 | } 46 | 47 | SocketCanDriver::~SocketCanDriver() { 48 | } 49 | 50 | bool SocketCanDriver::update() { 51 | 52 | struct nl_sock *sock = nl_socket_alloc(); 53 | struct nl_cache *cache; 54 | 55 | nl_connect(sock, NETLINK_ROUTE); 56 | int result = rtnl_link_alloc_cache(sock, AF_UNSPEC, &cache); 57 | 58 | if (result < 0) { 59 | log_error(QString("Could not access netlink device list: %1").arg(result)); 60 | } else { 61 | 62 | for (struct nl_object *obj = nl_cache_get_first(cache); obj!=0; obj=nl_cache_get_next(obj)) { 63 | struct rtnl_link *link = (struct rtnl_link *)obj; 64 | 65 | if (rtnl_link_get_arptype(link)==ARPHRD_CAN) { 66 | SocketCanInterface *intf = createOrUpdateInterface(rtnl_link_get_ifindex(link), QString(rtnl_link_get_name(link))); 67 | intf->readConfigFromLink(link); 68 | } 69 | } 70 | } 71 | 72 | nl_cache_free(cache); 73 | nl_close(sock); 74 | nl_socket_free(sock); 75 | 76 | return true; 77 | } 78 | 79 | QString SocketCanDriver::getName() { 80 | return "SocketCAN"; 81 | } 82 | 83 | SocketCanInterface *SocketCanDriver::createOrUpdateInterface(int index, QString name) { 84 | 85 | foreach (CanInterface *intf, getInterfaces()) { 86 | SocketCanInterface *scif = dynamic_cast(intf); 87 | if (scif->getIfIndex() == index) { 88 | scif->setName(name); 89 | return scif; 90 | } 91 | } 92 | 93 | 94 | SocketCanInterface *scif = new SocketCanInterface(this, index, name); 95 | addInterface(scif); 96 | return scif; 97 | } 98 | -------------------------------------------------------------------------------- /src/driver/SocketCanDriver/SocketCanDriver.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | class SocketCanInterface; 29 | class SetupDialogInterfacePage; 30 | class GenericCanSetupPage; 31 | 32 | class SocketCanDriver: public CanDriver { 33 | public: 34 | SocketCanDriver(Backend &backend); 35 | virtual ~SocketCanDriver(); 36 | 37 | virtual QString getName(); 38 | virtual bool update(); 39 | 40 | private: 41 | SocketCanInterface *createOrUpdateInterface(int index, QString name); 42 | GenericCanSetupPage *setupPage; 43 | }; 44 | -------------------------------------------------------------------------------- /src/driver/SocketCanDriver/SocketCanDriver.pri: -------------------------------------------------------------------------------- 1 | CONFIG += c++11 2 | 3 | SOURCES += \ 4 | $$PWD/SocketCanInterface.cpp \ 5 | $$PWD/SocketCanDriver.cpp 6 | 7 | HEADERS += \ 8 | $$PWD/SocketCanInterface.h \ 9 | $$PWD/SocketCanDriver.h 10 | 11 | FORMS += 12 | 13 | -------------------------------------------------------------------------------- /src/driver/SocketCanDriver/SocketCanInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "../CanInterface.h" 25 | #include 26 | 27 | class SocketCanDriver; 28 | 29 | typedef struct { 30 | bool supports_canfd; 31 | bool supports_timing; 32 | uint32_t state; 33 | uint32_t base_freq; 34 | uint32_t sample_point; 35 | uint32_t ctrl_mode; 36 | uint32_t restart_ms; 37 | struct can_bittiming bit_timing; 38 | } can_config_t; 39 | 40 | typedef struct { 41 | uint32_t can_state; 42 | 43 | uint64_t rx_count; 44 | int rx_errors; 45 | uint64_t rx_overruns; 46 | 47 | uint64_t tx_count; 48 | int tx_errors; 49 | uint64_t tx_dropped; 50 | } can_status_t; 51 | 52 | class SocketCanInterface: public CanInterface { 53 | public: 54 | SocketCanInterface(SocketCanDriver *driver, int index, QString name); 55 | virtual ~SocketCanInterface(); 56 | 57 | virtual QString getName() const; 58 | void setName(QString name); 59 | 60 | virtual QList getAvailableBitrates(); 61 | 62 | virtual void applyConfig(const MeasurementInterface &mi); 63 | virtual bool readConfig(); 64 | virtual bool readConfigFromLink(struct rtnl_link *link); 65 | 66 | bool supportsTimingConfiguration(); 67 | bool supportsCanFD(); 68 | bool supportsTripleSampling(); 69 | 70 | virtual unsigned getBitrate(); 71 | virtual uint32_t getCapabilities(); 72 | 73 | 74 | virtual void open(); 75 | virtual void close(); 76 | 77 | virtual void sendMessage(const CanMessage &msg); 78 | virtual bool readMessage(CanMessage &msg, unsigned int timeout_ms); 79 | 80 | virtual bool updateStatistics(); 81 | virtual uint32_t getState(); 82 | virtual int getNumRxFrames(); 83 | virtual int getNumRxErrors(); 84 | virtual int getNumRxOverruns(); 85 | 86 | virtual int getNumTxFrames(); 87 | virtual int getNumTxErrors(); 88 | virtual int getNumTxDropped(); 89 | 90 | 91 | int getIfIndex(); 92 | 93 | private: 94 | typedef enum { 95 | ts_mode_SIOCSHWTSTAMP, 96 | ts_mode_SIOCGSTAMPNS, 97 | ts_mode_SIOCGSTAMP 98 | } ts_mode_t; 99 | 100 | int _idx; 101 | int _fd; 102 | QString _name; 103 | 104 | can_config_t _config; 105 | can_status_t _status; 106 | ts_mode_t _ts_mode; 107 | 108 | const char *cname(); 109 | bool updateStatus(); 110 | 111 | QString buildIpRouteCmd(const MeasurementInterface &mi); 112 | QStringList buildCanIfConfigArgs(const MeasurementInterface &mi); 113 | }; 114 | -------------------------------------------------------------------------------- /src/driver/driver.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/CanInterface.cpp \ 3 | $$PWD/CanListener.cpp \ 4 | $$PWD/CanDriver.cpp \ 5 | $$PWD/CanTiming.cpp \ 6 | $$PWD/GenericCanSetupPage.cpp 7 | 8 | HEADERS += \ 9 | $$PWD/CanInterface.h \ 10 | $$PWD/CanListener.h \ 11 | $$PWD/CanDriver.h \ 12 | $$PWD/CanTiming.h \ 13 | $$PWD/GenericCanSetupPage.h 14 | 15 | FORMS += \ 16 | $$PWD/GenericCanSetupPage.ui 17 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "mainwindow.h" 23 | #include 24 | 25 | int main(int argc, char *argv[]) 26 | { 27 | QApplication a(argc, argv); 28 | MainWindow w; 29 | 30 | w.show(); 31 | 32 | return a.exec(); 33 | } 34 | -------------------------------------------------------------------------------- /src/mainwindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | QT_BEGIN_NAMESPACE 29 | class QAction; 30 | class QMenu; 31 | class QMdiArea; 32 | class QMdiSubWindow; 33 | class QWidget; 34 | class QSignalMapper; 35 | class QDomElement; 36 | QT_END_NAMESPACE 37 | 38 | namespace Ui { 39 | class MainWindow; 40 | } 41 | 42 | class ConfigurableWidget; 43 | class SetupDialog; 44 | 45 | class MainWindow : public QMainWindow 46 | { 47 | Q_OBJECT 48 | 49 | public: 50 | explicit MainWindow(QWidget *parent = 0); 51 | ~MainWindow(); 52 | 53 | protected: 54 | void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; 55 | 56 | public slots: 57 | QMainWindow *createTraceWindow(QString title=QString()); 58 | QMainWindow *createGraphWindow(QString title=QString()); 59 | 60 | void addLogWidget(QMainWindow *parent=0); 61 | void addStatusWidget(QMainWindow *parent=0); 62 | 63 | bool showSetupDialog(); 64 | void showAboutDialog(); 65 | 66 | void startMeasurement(); 67 | void stopMeasurement(); 68 | void saveTraceToFile(); 69 | 70 | void updateMeasurementActions(); 71 | 72 | private slots: 73 | void on_action_WorkspaceNew_triggered(); 74 | void on_action_WorkspaceOpen_triggered(); 75 | void on_action_WorkspaceSave_triggered(); 76 | void on_action_WorkspaceSaveAs_triggered(); 77 | void on_action_TraceClear_triggered(); 78 | 79 | void on_actionCan_Status_View_triggered(); 80 | 81 | private: 82 | Ui::MainWindow *ui; 83 | SetupDialog *_setupDlg; 84 | 85 | bool _workspaceModified; 86 | QString _workspaceFileName; 87 | QString _baseWindowTitle; 88 | 89 | Backend &backend(); 90 | 91 | QMainWindow *createTab(QString title); 92 | QMainWindow *currentTab(); 93 | 94 | void stopAndClearMeasurement(); 95 | 96 | void clearWorkspace(); 97 | bool loadWorkspaceTab(QDomElement el); 98 | bool loadWorkspaceSetup(QDomElement el); 99 | void loadWorkspaceFromFile(QString filename); 100 | bool saveWorkspaceToFile(QString filename); 101 | 102 | void newWorkspace(); 103 | void loadWorkspace(); 104 | bool saveWorkspace(); 105 | bool saveWorkspaceAs(); 106 | 107 | void setWorkspaceModified(bool modified); 108 | int askSaveBecauseWorkspaceModified(); 109 | 110 | }; 111 | -------------------------------------------------------------------------------- /src/parser/dbc/DbcParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include "DbcTokens.h" 32 | 33 | class CanDbMessage; 34 | 35 | class DbcParser 36 | { 37 | 38 | public: 39 | typedef QList DbcTokenList; 40 | 41 | typedef enum { 42 | err_ok, 43 | err_cannot_open_file, 44 | err_tokenize_error, 45 | } error_t; 46 | 47 | public: 48 | DbcParser(); 49 | bool parseFile(QFile *file, CanDb &candb); 50 | 51 | private: 52 | int _errorLine; 53 | int _errorColumn; 54 | 55 | QString _dbcVersion; 56 | QStringList _nsEntries; 57 | QStringList _buEntries; 58 | 59 | DbcToken *createNewToken(QChar ch, int line, int column); 60 | error_t tokenize(QFile *file, DbcTokenList &tokens); 61 | 62 | bool isSectionEnding(DbcToken *token, bool newLineIsSectionEnding=false); 63 | bool expectSectionEnding(DbcTokenList &tokens, bool newLineIsSectionEnding=false); 64 | bool expectLineBreak(DbcTokenList &tokens); 65 | bool expectAndSkipToken(DbcTokenList &tokens, dbc_token_type_t type, bool skipWhitespace=true, bool skipSectionEnding=false); 66 | 67 | bool expectData(DbcTokenList &tokens, dbc_token_type_t type, QString *data, bool skipWhitespace=true, bool skipSectionEnding=false, bool newLineIsSectionEnding=false); 68 | bool expectIdentifier(DbcTokenList &tokens, QString *id, bool skipWhitespace=true, bool skipSectionEnding=false, bool newLineIsSectionEnding=false); 69 | bool expectString(DbcTokenList &tokens, QString *str, bool skipWhitespace=true); 70 | 71 | bool expectNumber(DbcTokenList &tokens, QString *str, bool skipWhitespace=true); 72 | 73 | bool expectInt(DbcTokenList &tokens, int *i, int base=10, bool skipWhitespace=true); 74 | bool expectLongLong(DbcTokenList &tokens, long long *i, int base=10, bool skipWhitespace=true); 75 | bool expectDouble(DbcTokenList &tokens, double *df, bool skipWhitespace=true); 76 | void skipUntilSectionEnding(DbcTokenList &tokens); 77 | 78 | DbcToken *readToken(DbcTokenList &tokens, int typeMask, bool skipWhitespace=true, bool skipSectionEnding=false, bool newLineIsSectionEnding=false); 79 | 80 | bool parse(CanDb &candb, DbcTokenList &tokens); 81 | bool parseIdentifierList(DbcTokenList &tokens, QStringList *list, bool newLineIsSectionEnding=false); 82 | 83 | bool parseSection(CanDb &candb, DbcTokenList &tokens); 84 | bool parseSectionVersion(CanDb &candb, DbcTokenList &tokens); 85 | bool parseSectionBs(DbcTokenList &tokens); 86 | bool parseSectionBu(CanDb &candb, DbcTokenList &tokens); 87 | bool parseSectionBo(CanDb &candb, DbcTokenList &tokens); 88 | bool parseSectionBoSg(CanDb &candb, CanDbMessage *msg, DbcTokenList &tokens); 89 | bool parseSectionCm(CanDb &candb, DbcTokenList &tokens); 90 | bool parseSectionVal(CanDb &candb, DbcTokenList &tokens); 91 | 92 | }; 93 | -------------------------------------------------------------------------------- /src/parser/dbc/DbcTokens.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "DbcTokens.h" 23 | 24 | DbcToken::DbcToken(int line, int column, dbc_token_type_t type) 25 | : _line(line), _col(column), _type(type), _numLineBreaks(0) 26 | { 27 | 28 | } 29 | 30 | bool DbcToken::appendChar(QChar ch) 31 | { 32 | if (acceptsChar(ch)) { 33 | if (ch=='\n') { 34 | _numLineBreaks++; 35 | } 36 | _data.append(ch); 37 | return true; 38 | } else { 39 | return false; 40 | } 41 | } 42 | 43 | dbc_token_type_t DbcToken::getType() 44 | { 45 | return _type; 46 | } 47 | 48 | QString DbcToken::getData() 49 | { 50 | return _data; 51 | } 52 | 53 | int DbcToken::countLineBreaks() 54 | { 55 | return _numLineBreaks; 56 | } 57 | 58 | int DbcToken::getLine() 59 | { 60 | return _line; 61 | } 62 | 63 | int DbcToken::getColumn() 64 | { 65 | return _col; 66 | } 67 | 68 | 69 | DbcIdentifierToken::DbcIdentifierToken(int line, int column) 70 | : DbcToken(line, column, dbc_tok_identifier) 71 | { 72 | } 73 | 74 | bool DbcIdentifierToken::acceptsChar(QChar ch) 75 | { 76 | static const QString acceptableStartChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"); 77 | static const QString acceptableChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"); 78 | if (_data.isEmpty()) { 79 | return acceptableStartChars.contains(ch); 80 | } else { 81 | return acceptableChars.contains(ch); 82 | } 83 | } 84 | 85 | 86 | DbcStringToken::DbcStringToken(int line, int column) 87 | : DbcToken(line, column, dbc_tok_string) 88 | { 89 | } 90 | 91 | bool DbcStringToken::acceptsChar(QChar ch) 92 | { 93 | if (_data.isEmpty()) { 94 | return (ch=='"'); 95 | } else if (_data.length()<2) { 96 | return true; 97 | } else { 98 | return !_data.endsWith('"'); 99 | } 100 | } 101 | 102 | 103 | 104 | 105 | DbcWhitespaceToken::DbcWhitespaceToken(int line, int column) 106 | : DbcToken(line, column, dbc_tok_whitespace) 107 | { 108 | } 109 | 110 | bool DbcWhitespaceToken::acceptsChar(QChar ch) 111 | { 112 | return ch.isSpace(); 113 | } 114 | 115 | DbcRegExpToken::DbcRegExpToken(int line, int column, dbc_token_type_t type, QRegExp re) 116 | : DbcToken(line, column, type), 117 | _re(re) 118 | { 119 | } 120 | 121 | bool DbcRegExpToken::acceptsChar(QChar ch) 122 | { 123 | QString s = _data + ch; 124 | return (_re.indexIn(s)==0); 125 | } 126 | 127 | DbcSingleCharToken::DbcSingleCharToken(int line, int column, dbc_token_type_t type, QChar ch) 128 | : DbcToken(line, column, type), 129 | _ch(ch) 130 | { 131 | } 132 | 133 | bool DbcSingleCharToken::acceptsChar(QChar ch) 134 | { 135 | return (ch==_ch) && _data.isEmpty(); 136 | } 137 | 138 | -------------------------------------------------------------------------------- /src/parser/dbc/DbcTokens.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | typedef enum { 29 | dbc_tok_whitespace = 1, 30 | dbc_tok_identifier = 2, 31 | dbc_tok_string = 4, 32 | dbc_tok_number = 8, 33 | dbc_tok_colon = 16, 34 | dbc_tok_pipe = 32, 35 | dbc_tok_at = 64, 36 | dbc_tok_plus = 128, 37 | dbc_tok_parenth_open = 256, 38 | dbc_tok_parenth_close = 512, 39 | dbc_tok_bracket_open = 1024, 40 | dbc_tok_bracket_close = 2048, 41 | dbc_tok_comma = 4096, 42 | dbc_tok_semicolon = 8192, 43 | dbc_tok_minus = 16384, 44 | 45 | dbc_tok_ALL = 0xFFFFFFFF 46 | } dbc_token_type_t; 47 | 48 | class DbcToken { 49 | public: 50 | DbcToken(int line, int column, dbc_token_type_t type); 51 | virtual bool acceptsChar(QChar ch) = 0; 52 | 53 | bool appendChar(QChar ch); 54 | dbc_token_type_t getType(); 55 | QString getData(); 56 | int countLineBreaks(); 57 | int getLine(); 58 | int getColumn(); 59 | 60 | protected: 61 | QString _data; 62 | private: 63 | int _line; 64 | int _col; 65 | dbc_token_type_t _type; 66 | int _numLineBreaks; 67 | }; 68 | 69 | class DbcWhitespaceToken : public DbcToken { 70 | public: 71 | DbcWhitespaceToken(int line, int column); 72 | virtual bool acceptsChar(QChar ch); 73 | 74 | }; 75 | 76 | class DbcIdentifierToken : public DbcToken { 77 | public: 78 | DbcIdentifierToken(int line, int column); 79 | virtual bool acceptsChar(QChar ch); 80 | }; 81 | 82 | class DbcStringToken : public DbcToken { 83 | public: 84 | DbcStringToken(int line, int column); 85 | virtual bool acceptsChar(QChar ch); 86 | }; 87 | 88 | class DbcRegExpToken : public DbcToken { 89 | public: 90 | DbcRegExpToken(int line, int column, dbc_token_type_t type, QRegExp re); 91 | virtual bool acceptsChar(QChar ch); 92 | private: 93 | QRegExp _re; 94 | }; 95 | 96 | class DbcSingleCharToken : public DbcToken { 97 | public: 98 | DbcSingleCharToken(int line, int column, dbc_token_type_t type, QChar ch); 99 | virtual bool acceptsChar(QChar ch); 100 | private: 101 | QChar _ch; 102 | }; 103 | -------------------------------------------------------------------------------- /src/parser/dbc/dbc.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/DbcParser.h \ 3 | $$PWD/DbcTokens.h 4 | 5 | SOURCES += \ 6 | $$PWD/DbcParser.cpp \ 7 | $$PWD/DbcTokens.cpp 8 | -------------------------------------------------------------------------------- /src/scripts/setup_vcan.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo modprobe can 3 | sudo modprobe can_raw 4 | sudo modprobe vcan 5 | 6 | sudo ip link add dev vcan0 type vcan 7 | sudo ip link set up vcan0 8 | 9 | sudo ip link add dev vcan1 type vcan 10 | sudo ip link set up vcan1 11 | 12 | sudo ip link add dev vcan2 type vcan 13 | sudo ip link set up vcan2 14 | 15 | -------------------------------------------------------------------------------- /src/src.pro: -------------------------------------------------------------------------------- 1 | lessThan(QT_MAJOR_VERSION, 5): error("requires Qt 5") 2 | 3 | QT += core gui 4 | QT += widgets 5 | QT += xml 6 | 7 | TARGET = cangaroo 8 | TEMPLATE = app 9 | CONFIG += warn_on 10 | CONFIG += link_pkgconfig 11 | 12 | DESTDIR = ../bin 13 | MOC_DIR = ../build/moc 14 | RCC_DIR = ../build/rcc 15 | UI_DIR = ../build/ui 16 | unix:OBJECTS_DIR = ../build/o/unix 17 | win32:OBJECTS_DIR = ../build/o/win32 18 | macx:OBJECTS_DIR = ../build/o/mac 19 | 20 | 21 | SOURCES += main.cpp\ 22 | mainwindow.cpp \ 23 | 24 | HEADERS += mainwindow.h \ 25 | 26 | FORMS += mainwindow.ui 27 | 28 | RESOURCES = cangaroo.qrc 29 | 30 | include($$PWD/core/core.pri) 31 | include($$PWD/driver/driver.pri) 32 | include($$PWD/parser/dbc/dbc.pri) 33 | include($$PWD/window/TraceWindow/TraceWindow.pri) 34 | include($$PWD/window/SetupDialog/SetupDialog.pri) 35 | include($$PWD/window/LogWindow/LogWindow.pri) 36 | include($$PWD/window/GraphWindow/GraphWindow.pri) 37 | include($$PWD/window/CanStatusWindow/CanStatusWindow.pri) 38 | 39 | unix:PKGCONFIG += libnl-3.0 40 | unix:PKGCONFIG += libnl-route-3.0 41 | unix:include($$PWD/driver/SocketCanDriver/SocketCanDriver.pri) 42 | 43 | win32:include($$PWD/driver/PeakCanDriver/PeakCanDriver.pri) 44 | win32:include($$PWD/driver/CandleApiDriver/CandleApiDriver.pri) 45 | -------------------------------------------------------------------------------- /src/window/CanStatusWindow/CanStatusWindow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | 23 | #include "CanStatusWindow.h" 24 | #include "ui_CanStatusWindow.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | CanStatusWindow::CanStatusWindow(QWidget *parent, Backend &backend) : 34 | ConfigurableWidget(parent), 35 | ui(new Ui::CanStatusWindow), 36 | _backend(backend), 37 | _timer(new QTimer(this)) 38 | { 39 | ui->setupUi(this); 40 | ui->treeWidget->setHeaderLabels(QStringList() 41 | << "Driver" << "Interface" << "State" 42 | << "Rx Frames" << "Rx Errors" << "Rx Overrun" 43 | << "Tx Frames" << "Tx Errors" << "Tx Dropped" 44 | << "# Warning" << "# Passive" << "# Bus Off" << " #Restarts" 45 | ); 46 | ui->treeWidget->setColumnWidth(0, 80); 47 | ui->treeWidget->setColumnWidth(1, 70); 48 | 49 | connect(&backend, SIGNAL(beginMeasurement()), this, SLOT(beginMeasurement())); 50 | connect(&backend, SIGNAL(endMeasurement()), this, SLOT(endMeasurement())); 51 | connect(_timer, SIGNAL(timeout()), this, SLOT(update())); 52 | } 53 | 54 | CanStatusWindow::~CanStatusWindow() 55 | { 56 | delete ui; 57 | } 58 | 59 | void CanStatusWindow::beginMeasurement() 60 | { 61 | ui->treeWidget->clear(); 62 | foreach (CanInterfaceId ifid, backend().getInterfaceList()) { 63 | CanInterface *intf = backend().getInterfaceById(ifid); 64 | QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget); 65 | item->setData(0, Qt::UserRole, QVariant::fromValue((void*)intf)); 66 | item->setText(column_driver, intf->getDriver()->getName()); 67 | item->setText(column_interface, intf->getName()); 68 | 69 | item->setTextAlignment(column_driver, Qt::AlignLeft); 70 | item->setTextAlignment(column_interface, Qt::AlignLeft); 71 | item->setTextAlignment(column_state, Qt::AlignCenter); 72 | for (int i=column_rx_frames; isetTextAlignment(i, Qt::AlignRight); 74 | } 75 | 76 | ui->treeWidget->addTopLevelItem(item); 77 | } 78 | update(); 79 | _timer->start(100); 80 | } 81 | 82 | void CanStatusWindow::endMeasurement() 83 | { 84 | _timer->stop(); 85 | } 86 | 87 | void CanStatusWindow::update() 88 | { 89 | for (QTreeWidgetItemIterator it(ui->treeWidget); *it; ++it) { 90 | QTreeWidgetItem *item = *it; 91 | CanInterface *intf = (CanInterface *)item->data(0, Qt::UserRole).value(); 92 | if (intf) { 93 | intf->updateStatistics(); 94 | item->setText(column_state, intf->getStateText()); 95 | item->setText(column_rx_frames, QString().number(intf->getNumRxFrames())); 96 | item->setText(column_rx_errors, QString().number(intf->getNumRxErrors())); 97 | item->setText(column_rx_overrun, QString().number(intf->getNumRxOverruns())); 98 | item->setText(column_tx_frames, QString().number(intf->getNumTxFrames())); 99 | item->setText(column_tx_errors, QString().number(intf->getNumTxErrors())); 100 | item->setText(column_tx_dropped, QString().number(intf->getNumTxDropped())); 101 | } 102 | } 103 | 104 | } 105 | 106 | Backend &CanStatusWindow::backend() 107 | { 108 | return _backend; 109 | } 110 | -------------------------------------------------------------------------------- /src/window/CanStatusWindow/CanStatusWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace Ui { 27 | class CanStatusWindow; 28 | } 29 | 30 | class Backend; 31 | class QTimer; 32 | 33 | class CanStatusWindow : public ConfigurableWidget 34 | { 35 | Q_OBJECT 36 | 37 | public: 38 | enum { 39 | column_driver, 40 | column_interface, 41 | column_state, 42 | column_rx_frames, 43 | column_rx_errors, 44 | column_rx_overrun, 45 | column_tx_frames, 46 | column_tx_errors, 47 | column_tx_dropped, 48 | column_num_warning, 49 | column_num_passive, 50 | column_num_busoff, 51 | column_num_restarts, 52 | column_count 53 | }; 54 | 55 | public: 56 | explicit CanStatusWindow(QWidget *parent, Backend &backend); 57 | ~CanStatusWindow(); 58 | 59 | private slots: 60 | void beginMeasurement(); 61 | void endMeasurement(); 62 | void update(); 63 | 64 | private: 65 | Ui::CanStatusWindow *ui; 66 | Backend &_backend; 67 | 68 | Backend &backend(); 69 | QTimer *_timer; 70 | }; 71 | -------------------------------------------------------------------------------- /src/window/CanStatusWindow/CanStatusWindow.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/CanStatusWindow.cpp \ 3 | 4 | HEADERS += \ 5 | $$PWD/CanStatusWindow.h \ 6 | 7 | FORMS += \ 8 | $$PWD/CanStatusWindow.ui \ 9 | -------------------------------------------------------------------------------- /src/window/CanStatusWindow/CanStatusWindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | CanStatusWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 756 10 | 459 11 | 12 | 13 | 14 | Can Status 15 | 16 | 17 | 18 | 2 19 | 20 | 21 | 2 22 | 23 | 24 | 2 25 | 26 | 27 | 2 28 | 29 | 30 | 31 | 32 | 0 33 | 34 | 35 | false 36 | 37 | 38 | 13 39 | 40 | 41 | 80 42 | 43 | 44 | 45 | 1 46 | 47 | 48 | 49 | 50 | 2 51 | 52 | 53 | 54 | 55 | 3 56 | 57 | 58 | 59 | 60 | 4 61 | 62 | 63 | 64 | 65 | 5 66 | 67 | 68 | 69 | 70 | 6 71 | 72 | 73 | 74 | 75 | 7 76 | 77 | 78 | 79 | 80 | 8 81 | 82 | 83 | 84 | 85 | 9 86 | 87 | 88 | 89 | 90 | 10 91 | 92 | 93 | 94 | 95 | 11 96 | 97 | 98 | 99 | 100 | 12 101 | 102 | 103 | 104 | 105 | 13 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /src/window/GraphWindow/GraphWindow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "GraphWindow.h" 23 | #include "ui_GraphWindow.h" 24 | 25 | #include 26 | 27 | #include 28 | 29 | GraphWindow::GraphWindow(QWidget *parent, Backend &backend) : 30 | ConfigurableWidget(parent), 31 | ui(new Ui::GraphWindow), 32 | _backend(backend) 33 | { 34 | ui->setupUi(this); 35 | } 36 | 37 | GraphWindow::~GraphWindow() 38 | { 39 | delete ui; 40 | } 41 | 42 | bool GraphWindow::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root) 43 | { 44 | if (!ConfigurableWidget::saveXML(backend, xml, root)) { return false; } 45 | root.setAttribute("type", "GraphWindow"); 46 | return true; 47 | } 48 | 49 | bool GraphWindow::loadXML(Backend &backend, QDomElement &el) 50 | { 51 | if (!ConfigurableWidget::loadXML(backend, el)) { return false; } 52 | return true; 53 | } 54 | -------------------------------------------------------------------------------- /src/window/GraphWindow/GraphWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace Ui { 29 | class GraphWindow; 30 | } 31 | 32 | class QDomDocument; 33 | class QDomElement; 34 | 35 | class GraphWindow : public ConfigurableWidget 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | explicit GraphWindow(QWidget *parent, Backend &backend); 41 | ~GraphWindow(); 42 | virtual bool saveXML(Backend &backend, QDomDocument &xml, QDomElement &root); 43 | virtual bool loadXML(Backend &backend, QDomElement &el); 44 | 45 | private: 46 | Ui::GraphWindow *ui; 47 | Backend &_backend; 48 | }; 49 | -------------------------------------------------------------------------------- /src/window/GraphWindow/GraphWindow.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/GraphWindow.cpp 3 | 4 | HEADERS += \ 5 | $$PWD/GraphWindow.h 6 | 7 | FORMS += \ 8 | $$PWD/GraphWindow.ui 9 | -------------------------------------------------------------------------------- /src/window/GraphWindow/GraphWindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | GraphWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 752 10 | 541 11 | 12 | 13 | 14 | Graph 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/window/LogWindow/LogWindow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "LogWindow.h" 23 | #include "ui_LogWindow.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | LogWindow::LogWindow(QWidget *parent, Backend &backend) : 30 | ConfigurableWidget(parent), 31 | ui(new Ui::LogWindow) 32 | { 33 | connect(&backend.getLogModel(), SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted(QModelIndex,int,int))); 34 | 35 | ui->setupUi(this); 36 | ui->treeView->setModel(&backend.getLogModel()); 37 | } 38 | 39 | LogWindow::~LogWindow() 40 | { 41 | delete ui; 42 | } 43 | 44 | bool LogWindow::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root) 45 | { 46 | if (!ConfigurableWidget::saveXML(backend, xml, root)) { return false; } 47 | root.setAttribute("type", "LogWindow"); 48 | return true; 49 | } 50 | 51 | bool LogWindow::loadXML(Backend &backend, QDomElement &el) 52 | { 53 | return ConfigurableWidget::loadXML(backend, el); 54 | } 55 | 56 | void LogWindow::rowsInserted(const QModelIndex &parent, int first, int last) 57 | { 58 | (void) parent; 59 | (void) first; 60 | (void) last; 61 | ui->treeView->scrollToBottom(); 62 | } 63 | -------------------------------------------------------------------------------- /src/window/LogWindow/LogWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | namespace Ui { 28 | class LogWindow; 29 | } 30 | 31 | class QDomDocument; 32 | class QDomElement; 33 | class LogModel; 34 | 35 | class LogWindow : public ConfigurableWidget 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | explicit LogWindow(QWidget *parent, Backend &backend); 41 | ~LogWindow(); 42 | 43 | virtual bool saveXML(Backend &backend, QDomDocument &xml, QDomElement &root); 44 | virtual bool loadXML(Backend &backend, QDomElement &el); 45 | 46 | private slots: 47 | void rowsInserted(const QModelIndex & parent, int first, int last); 48 | 49 | private: 50 | Ui::LogWindow *ui; 51 | }; 52 | -------------------------------------------------------------------------------- /src/window/LogWindow/LogWindow.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/LogWindow.cpp \ 3 | 4 | 5 | HEADERS += \ 6 | $$PWD/LogWindow.h \ 7 | 8 | 9 | FORMS += \ 10 | $$PWD/LogWindow.ui \ 11 | -------------------------------------------------------------------------------- /src/window/LogWindow/LogWindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LogWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Log 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/window/SetupDialog/SelectCanInterfacesDialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "SelectCanInterfacesDialog.h" 23 | #include "ui_SelectCanInterfacesDialog.h" 24 | #include 25 | 26 | SelectCanInterfacesDialog::SelectCanInterfacesDialog(QWidget *parent) : 27 | QDialog(parent), 28 | ui(new Ui::SelectCanInterfacesDialog) 29 | { 30 | ui->setupUi(this); 31 | ui->treeWidget->setHeaderLabels(QStringList() << "Device" << "Driver" << "Description"); 32 | } 33 | 34 | SelectCanInterfacesDialog::~SelectCanInterfacesDialog() 35 | { 36 | delete ui; 37 | } 38 | 39 | bool SelectCanInterfacesDialog::selectInterfaces(Backend &backend, CanInterfaceIdList &selectedInterfaces, const CanInterfaceIdList &excludeInterfaces) 40 | { 41 | ui->treeWidget->clear(); 42 | 43 | CanInterfaceIdList allInterfaces; 44 | foreach (CanInterfaceId intf, backend.getInterfaceList()) { 45 | if (!excludeInterfaces.contains(intf)) { 46 | allInterfaces.append(intf); 47 | } 48 | } 49 | 50 | 51 | foreach (CanInterfaceId intf, allInterfaces) { 52 | QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget); 53 | treeItem->setText(0, backend.getInterfaceName(intf)); 54 | treeItem->setText(1, backend.getDriverName(intf)); 55 | treeItem->setText(2, ""); 56 | } 57 | 58 | if (exec()==QDialog::Accepted) { 59 | selectedInterfaces.clear(); 60 | foreach (QModelIndex idx, ui->treeWidget->selectionModel()->selectedRows()) { 61 | if (idx.isValid()) { 62 | selectedInterfaces.append(allInterfaces[idx.row()]); 63 | } 64 | } 65 | return true; 66 | } else { 67 | return false; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/window/SetupDialog/SelectCanInterfacesDialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | class Backend; 30 | 31 | namespace Ui { 32 | class SelectCanInterfacesDialog; 33 | } 34 | 35 | class SelectCanInterfacesDialog : public QDialog 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | explicit SelectCanInterfacesDialog(QWidget *parent = 0); 41 | ~SelectCanInterfacesDialog(); 42 | 43 | bool selectInterfaces(Backend &backend, CanInterfaceIdList &selectedInterfaces, const CanInterfaceIdList &excludeInterfaces); 44 | 45 | private: 46 | Ui::SelectCanInterfacesDialog *ui; 47 | }; 48 | -------------------------------------------------------------------------------- /src/window/SetupDialog/SelectCanInterfacesDialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SelectCanInterfacesDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 570 10 | 438 11 | 12 | 13 | 14 | Select CAN Interface(s) 15 | 16 | 17 | 18 | :/assets/cangaroo.png:/assets/cangaroo.png 19 | 20 | 21 | 22 | 23 | 24 | 25 | 0 26 | 27 | 28 | 0 29 | 30 | 31 | 0 32 | 33 | 34 | 0 35 | 36 | 37 | 38 | 39 | 0 40 | 41 | 42 | 3 43 | 44 | 45 | 100 46 | 47 | 48 | 49 | 1 50 | 51 | 52 | 53 | 54 | 2 55 | 56 | 57 | 58 | 59 | 3 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 0 69 | 70 | 71 | 0 72 | 73 | 74 | 0 75 | 76 | 77 | 0 78 | 79 | 80 | 81 | 82 | &Create Interface... 83 | 84 | 85 | 86 | 87 | 88 | 89 | Qt::Horizontal 90 | 91 | 92 | 93 | 40 94 | 20 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | Qt::Horizontal 109 | 110 | 111 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | buttonBox 123 | accepted() 124 | SelectCanInterfacesDialog 125 | accept() 126 | 127 | 128 | 248 129 | 254 130 | 131 | 132 | 157 133 | 274 134 | 135 | 136 | 137 | 138 | buttonBox 139 | rejected() 140 | SelectCanInterfacesDialog 141 | reject() 142 | 143 | 144 | 316 145 | 260 146 | 147 | 148 | 286 149 | 274 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /src/window/SetupDialog/SetupDialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | class Backend; 28 | class MeasurementSetup; 29 | class MeasurementNetwork; 30 | class MeasurementInterface; 31 | class QItemSelection; 32 | class SetupDialogTreeItem; 33 | class SetupDialogTreeModel; 34 | 35 | namespace Ui { 36 | class SetupDialog; 37 | } 38 | 39 | class SetupDialog : public QDialog 40 | { 41 | Q_OBJECT 42 | 43 | public: 44 | explicit SetupDialog(Backend &backend, QWidget *parent = 0); 45 | ~SetupDialog(); 46 | 47 | bool showSetupDialog(MeasurementSetup &setup); 48 | void addPage(QWidget *widget); 49 | void displayPage(QWidget *widget); 50 | 51 | signals: 52 | void onShowInterfacePage(SetupDialog &dlg, MeasurementInterface *mi); 53 | 54 | public slots: 55 | void treeViewSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected); 56 | void treeViewContextMenu(const QPoint& pos); 57 | 58 | private slots: 59 | void edNetworkNameChanged(); 60 | 61 | void on_btAddInterface_clicked(); 62 | void on_btRemoveInterface_clicked(); 63 | 64 | void on_btAddDatabase_clicked(); 65 | void on_btRemoveDatabase_clicked(); 66 | void updateButtons(); 67 | 68 | void executeAddCanDb(); 69 | void executeDeleteCanDb(); 70 | 71 | void executeAddInterface(); 72 | void executeDeleteInterface(); 73 | 74 | void on_btAddNetwork_clicked(); 75 | void on_btRemoveNetwork_clicked(); 76 | 77 | 78 | private: 79 | Ui::SetupDialog *ui; 80 | Backend *_backend; 81 | 82 | QAction *_actionDeleteInterface; 83 | QAction *_actionDeleteCanDb; 84 | QAction *_actionAddInterface; 85 | QAction *_actionAddCanDb; 86 | 87 | SetupDialogTreeModel *model; 88 | MeasurementNetwork *_currentNetwork; 89 | 90 | QModelIndex getSelectedIndex(); 91 | SetupDialogTreeItem *getSelectedItem(); 92 | 93 | void addCanDb(const QModelIndex &parent); 94 | void addInterface(const QModelIndex &parent); 95 | 96 | }; 97 | -------------------------------------------------------------------------------- /src/window/SetupDialog/SetupDialog.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/SetupDialog.cpp \ 3 | $$PWD/SetupDialogTreeModel.cpp \ 4 | $$PWD/SetupDialogTreeItem.cpp \ 5 | $$PWD/SelectCanInterfacesDialog.cpp 6 | 7 | HEADERS += \ 8 | $$PWD/SetupDialog.h \ 9 | $$PWD/SetupDialogTreeModel.h \ 10 | $$PWD/SetupDialogTreeItem.h \ 11 | $$PWD/SelectCanInterfacesDialog.h 12 | 13 | FORMS += \ 14 | $$PWD/SetupDialog.ui \ 15 | $$PWD/SelectCanInterfacesDialog.ui 16 | -------------------------------------------------------------------------------- /src/window/SetupDialog/SetupDialogTreeItem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "SetupDialogTreeItem.h" 23 | #include 24 | #include 25 | #include "SetupDialogTreeModel.h" 26 | 27 | SetupDialogTreeItem::SetupDialogTreeItem(item_type type, Backend *backend, SetupDialogTreeItem *parent) 28 | : setup(0), network(0), intf(0), candb(0), _backend(backend), _type(type), _parent(parent) 29 | { 30 | 31 | } 32 | 33 | SetupDialogTreeItem::~SetupDialogTreeItem() 34 | { 35 | qDeleteAll(_children); 36 | } 37 | 38 | SetupDialogTreeItem *SetupDialogTreeItem::getParentItem() const 39 | { 40 | return _parent; 41 | } 42 | 43 | int SetupDialogTreeItem::getChildCount() const 44 | { 45 | return _children.length(); 46 | } 47 | 48 | void SetupDialogTreeItem::appendChild(SetupDialogTreeItem *child) 49 | { 50 | _children.append(child); 51 | } 52 | 53 | void SetupDialogTreeItem::removeChild(SetupDialogTreeItem *child) 54 | { 55 | _children.removeAll(child); 56 | } 57 | 58 | SetupDialogTreeItem *SetupDialogTreeItem::child(int row) const 59 | { 60 | return _children.value(row); 61 | } 62 | 63 | int SetupDialogTreeItem::row() const 64 | { 65 | if (_parent) { 66 | return _parent->_children.indexOf(const_cast(this)); 67 | } else { 68 | return 0; 69 | } 70 | } 71 | 72 | QVariant SetupDialogTreeItem::dataInterface(const QModelIndex &index) const 73 | { 74 | switch (index.column()) { 75 | case SetupDialogTreeModel::column_device: 76 | return _backend->getInterfaceName(intf->canInterface()); 77 | case SetupDialogTreeModel::column_driver: 78 | return _backend->getDriverName(intf->canInterface()); 79 | case SetupDialogTreeModel::column_bitrate: 80 | return intf->bitrate(); 81 | default: 82 | return QVariant(); 83 | } 84 | } 85 | 86 | QVariant SetupDialogTreeItem::dataCanDb(const QModelIndex &index) const 87 | { 88 | switch (index.column()) { 89 | case SetupDialogTreeModel::column_device: 90 | return candb->getFileName(); 91 | case SetupDialogTreeModel::column_filename: 92 | return candb->getFileName(); 93 | case SetupDialogTreeModel::column_path: 94 | return candb->getDirectory(); 95 | default: 96 | return QVariant(); 97 | } 98 | } 99 | 100 | QVariant SetupDialogTreeItem::dataDisplayRole(const QModelIndex &index) const 101 | { 102 | switch (_type) { 103 | case type_root: return "Setup"; 104 | case type_network: return (network!=0) ? network->name() : QVariant(); 105 | case type_interface_root: return "Interfaces"; 106 | case type_interface: return dataInterface(index); 107 | case type_candb_root: return "Can Databases"; 108 | case type_candb: return dataCanDb(index); 109 | } 110 | return QVariant(); 111 | } 112 | 113 | SetupDialogTreeItem::item_type SetupDialogTreeItem::getType() 114 | { 115 | return _type; 116 | } 117 | 118 | -------------------------------------------------------------------------------- /src/window/SetupDialog/SetupDialogTreeItem.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class SetupDialogTreeItem 34 | { 35 | public: 36 | 37 | typedef enum { 38 | type_root, 39 | type_network, 40 | type_interface_root, 41 | type_interface, 42 | type_candb_root, 43 | type_candb 44 | } item_type; 45 | 46 | public: 47 | SetupDialogTreeItem(item_type type, Backend *backend, SetupDialogTreeItem *parent=0); 48 | virtual ~SetupDialogTreeItem(); 49 | 50 | MeasurementSetup *setup; 51 | MeasurementNetwork *network; 52 | MeasurementInterface *intf; 53 | pCanDb candb; 54 | 55 | SetupDialogTreeItem *getParentItem() const; 56 | int getChildCount() const; 57 | void appendChild(SetupDialogTreeItem *child); 58 | void removeChild(SetupDialogTreeItem *child); 59 | 60 | SetupDialogTreeItem *child(int row) const; 61 | int row() const; 62 | 63 | QVariant dataDisplayRole(const QModelIndex &index) const; 64 | item_type getType(); 65 | 66 | private: 67 | Backend *_backend; 68 | item_type _type; 69 | SetupDialogTreeItem *_parent; 70 | QList _children; 71 | 72 | QVariant dataInterface(const QModelIndex &index) const; 73 | QVariant dataCanDb(const QModelIndex &index) const; 74 | }; 75 | -------------------------------------------------------------------------------- /src/window/SetupDialog/SetupDialogTreeModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "SetupDialogTreeItem.h" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | class SetupDialogTreeModel : public QAbstractItemModel 31 | { 32 | Q_OBJECT 33 | 34 | public: 35 | enum { 36 | column_device, 37 | column_driver, 38 | column_bitrate, 39 | column_filename, 40 | column_path, 41 | column_count 42 | }; 43 | 44 | public: 45 | explicit SetupDialogTreeModel(Backend *backend, QObject *parent=0); 46 | virtual ~SetupDialogTreeModel(); 47 | 48 | QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; 49 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; 50 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 51 | QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; 52 | int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 53 | int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 54 | 55 | QModelIndex indexOfItem(const SetupDialogTreeItem *item) const; 56 | 57 | void load(MeasurementSetup &setup); 58 | 59 | SetupDialogTreeItem *addNetwork(); 60 | void deleteNetwork(const QModelIndex &index); 61 | 62 | SetupDialogTreeItem *addCanDb(const QModelIndex &parent, pCanDb db); 63 | void deleteCanDb(const QModelIndex &index); 64 | 65 | SetupDialogTreeItem *addInterface(const QModelIndex &parent, CanInterfaceId &interface); 66 | void deleteInterface(const QModelIndex &index); 67 | 68 | private: 69 | Backend *_backend; 70 | SetupDialogTreeItem *_rootItem; 71 | SetupDialogTreeItem *itemOrRoot(const QModelIndex &index) const; 72 | 73 | SetupDialogTreeItem *loadNetwork(SetupDialogTreeItem *root, MeasurementNetwork &network); 74 | SetupDialogTreeItem *loadMeasurementInterface(SetupDialogTreeItem &parent, MeasurementInterface *intf); 75 | SetupDialogTreeItem *loadCanDb(SetupDialogTreeItem &parent, pCanDb &db); 76 | }; 77 | -------------------------------------------------------------------------------- /src/window/TraceWindow/AggregatedTraceViewItem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "AggregatedTraceViewItem.h" 23 | 24 | AggregatedTraceViewItem::AggregatedTraceViewItem(AggregatedTraceViewItem *parent) 25 | : _parent(parent) 26 | { 27 | } 28 | 29 | AggregatedTraceViewItem::~AggregatedTraceViewItem() 30 | { 31 | qDeleteAll(_children); 32 | } 33 | 34 | void AggregatedTraceViewItem::appendChild(AggregatedTraceViewItem *child) 35 | { 36 | _children.append(child); 37 | } 38 | 39 | AggregatedTraceViewItem *AggregatedTraceViewItem::child(int row) const 40 | { 41 | return _children.value(row); 42 | } 43 | 44 | int AggregatedTraceViewItem::childCount() const 45 | { 46 | return _children.count(); 47 | } 48 | 49 | int AggregatedTraceViewItem::row() const 50 | { 51 | if (_parent) { 52 | return _parent->_children.indexOf(const_cast(this)); 53 | } else { 54 | return 0; 55 | } 56 | } 57 | 58 | AggregatedTraceViewItem *AggregatedTraceViewItem::parent() const 59 | { 60 | return _parent; 61 | } 62 | 63 | AggregatedTraceViewItem *AggregatedTraceViewItem::firstChild() const 64 | { 65 | return _children.first(); 66 | } 67 | 68 | AggregatedTraceViewItem *AggregatedTraceViewItem::lastChild() const 69 | { 70 | return _children.last(); 71 | } 72 | -------------------------------------------------------------------------------- /src/window/TraceWindow/AggregatedTraceViewItem.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | class AggregatedTraceViewItem 29 | { 30 | public: 31 | AggregatedTraceViewItem(AggregatedTraceViewItem *parent); 32 | virtual ~AggregatedTraceViewItem(); 33 | 34 | void appendChild(AggregatedTraceViewItem *child); 35 | AggregatedTraceViewItem *child(int row) const; 36 | int childCount() const; 37 | int row() const; 38 | AggregatedTraceViewItem *parent() const; 39 | AggregatedTraceViewItem *firstChild() const; 40 | AggregatedTraceViewItem *lastChild() const; 41 | 42 | CanMessage _lastmsg, _prevmsg; 43 | 44 | private: 45 | AggregatedTraceViewItem *_parent; 46 | QList _children; 47 | 48 | }; 49 | -------------------------------------------------------------------------------- /src/window/TraceWindow/AggregatedTraceViewModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "BaseTraceViewModel.h" 30 | #include 31 | #include 32 | 33 | #include "AggregatedTraceViewItem.h" 34 | 35 | 36 | class CanTrace; 37 | 38 | class AggregatedTraceViewModel : public BaseTraceViewModel 39 | { 40 | Q_OBJECT 41 | 42 | public: 43 | typedef uint64_t unique_key_t; 44 | typedef QMap CanIdMap; 45 | 46 | public: 47 | AggregatedTraceViewModel(Backend &backend); 48 | 49 | virtual QModelIndex index(int row, int column, const QModelIndex &parent) const; 50 | virtual QModelIndex parent(const QModelIndex &child) const; 51 | virtual int rowCount(const QModelIndex &parent) const; 52 | 53 | private: 54 | CanIdMap _map; 55 | AggregatedTraceViewItem *_rootItem; 56 | QList _pendingMessageUpdates; 57 | QMap _pendingMessageInserts; 58 | 59 | unique_key_t makeUniqueKey(const CanMessage &msg) const; 60 | void createItem(const CanMessage &msg, AggregatedTraceViewItem *item, unique_key_t key); 61 | double getTimeDiff(const timeval t1, const timeval t2) const; 62 | 63 | protected: 64 | virtual QVariant data_DisplayRole(const QModelIndex &index, int role) const; 65 | virtual QVariant data_TextColorRole(const QModelIndex &index, int role) const; 66 | 67 | private slots: 68 | void createItem(const CanMessage &msg); 69 | void updateItem(const CanMessage &msg); 70 | void onUpdateModel(); 71 | void onSetupChanged(); 72 | 73 | void beforeAppend(int num_messages); 74 | void beforeClear(); 75 | void afterClear(); 76 | }; 77 | -------------------------------------------------------------------------------- /src/window/TraceWindow/BaseTraceViewModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include "TraceViewTypes.h" 26 | 27 | class Backend; 28 | class CanTrace; 29 | class CanMessage; 30 | class CanDbSignal; 31 | 32 | class BaseTraceViewModel : public QAbstractItemModel 33 | { 34 | Q_OBJECT 35 | 36 | public: 37 | enum { 38 | column_timestamp, 39 | column_channel, 40 | column_direction, 41 | column_canid, 42 | column_name, 43 | column_dlc, 44 | column_data, 45 | column_comment, 46 | column_count 47 | }; 48 | 49 | public: 50 | BaseTraceViewModel(Backend &backend); 51 | virtual int columnCount(const QModelIndex &parent) const; 52 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; 53 | virtual QVariant data(const QModelIndex &index, int role) const; 54 | 55 | Backend *backend() const; 56 | CanTrace *trace() const; 57 | 58 | timestamp_mode_t timestampMode() const; 59 | void setTimestampMode(timestamp_mode_t timestampMode); 60 | 61 | protected: 62 | virtual QVariant data_DisplayRole(const QModelIndex &index, int role) const; 63 | virtual QVariant data_DisplayRole_Message(const QModelIndex &index, int role, const CanMessage ¤tMsg, const CanMessage &lastMsg) const; 64 | virtual QVariant data_DisplayRole_Signal(const QModelIndex &index, int role, const CanMessage &msg) const; 65 | virtual QVariant data_TextAlignmentRole(const QModelIndex &index, int role) const; 66 | virtual QVariant data_TextColorRole(const QModelIndex &index, int role) const; 67 | virtual QVariant data_TextColorRole_Signal(const QModelIndex &index, int role, const CanMessage &msg) const; 68 | 69 | QVariant formatTimestamp(timestamp_mode_t mode, const CanMessage ¤tMsg, const CanMessage &lastMsg) const; 70 | 71 | private: 72 | Backend *_backend; 73 | timestamp_mode_t _timestampMode; 74 | 75 | }; 76 | -------------------------------------------------------------------------------- /src/window/TraceWindow/LinearTraceViewModel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #include "LinearTraceViewModel.h" 23 | #include 24 | #include 25 | #include 26 | 27 | LinearTraceViewModel::LinearTraceViewModel(Backend &backend) 28 | : BaseTraceViewModel(backend) 29 | { 30 | connect(backend.getTrace(), SIGNAL(beforeAppend(int)), this, SLOT(beforeAppend(int))); 31 | connect(backend.getTrace(), SIGNAL(afterAppend()), this, SLOT(afterAppend())); 32 | connect(backend.getTrace(), SIGNAL(beforeClear()), this, SLOT(beforeClear())); 33 | connect(backend.getTrace(), SIGNAL(afterClear()), this, SLOT(afterClear())); 34 | } 35 | 36 | QModelIndex LinearTraceViewModel::index(int row, int column, const QModelIndex &parent) const 37 | { 38 | if (parent.isValid() && parent.internalId()) { 39 | return createIndex(row, column, (unsigned int)(0x80000000 | parent.internalId())); 40 | } else { 41 | return createIndex(row, column, row+1); 42 | } 43 | } 44 | 45 | QModelIndex LinearTraceViewModel::parent(const QModelIndex &child) const 46 | { 47 | (void) child; 48 | quintptr id = child.internalId(); 49 | if (id & 0x80000000) { 50 | return createIndex(id & 0x7FFFFFFF, 0, (unsigned int)(id & 0x7FFFFFFF)); 51 | } 52 | return QModelIndex(); 53 | } 54 | 55 | int LinearTraceViewModel::rowCount(const QModelIndex &parent) const 56 | { 57 | if (parent.isValid()) { 58 | quintptr id = parent.internalId(); 59 | if (id & 0x80000000) { // node of a message 60 | return 0; 61 | } else { // a message 62 | const CanMessage *msg = trace()->getMessage(id-1); 63 | if (msg) { 64 | CanDbMessage *dbmsg = backend()->findDbMessage(*msg); 65 | return (dbmsg!=0) ? dbmsg->getSignals().length() : 0; 66 | } else { 67 | return 0; 68 | } 69 | } 70 | } else { 71 | return trace()->size(); 72 | } 73 | } 74 | 75 | int LinearTraceViewModel::columnCount(const QModelIndex &parent) const 76 | { 77 | (void) parent; 78 | return column_count; 79 | } 80 | 81 | bool LinearTraceViewModel::hasChildren(const QModelIndex &parent) const 82 | { 83 | return rowCount(parent)>0; 84 | } 85 | 86 | void LinearTraceViewModel::beforeAppend(int num_messages) 87 | { 88 | beginInsertRows(QModelIndex(), trace()->size(), trace()->size()+num_messages-1); 89 | } 90 | 91 | void LinearTraceViewModel::afterAppend() 92 | { 93 | endInsertRows(); 94 | } 95 | 96 | void LinearTraceViewModel::beforeClear() 97 | { 98 | beginResetModel(); 99 | } 100 | 101 | void LinearTraceViewModel::afterClear() 102 | { 103 | endResetModel(); 104 | } 105 | 106 | QVariant LinearTraceViewModel::data_DisplayRole(const QModelIndex &index, int role) const 107 | { 108 | quintptr id = index.internalId(); 109 | int msg_id = (id & ~0x80000000)-1; 110 | 111 | const CanMessage *msg = trace()->getMessage(msg_id); 112 | if (!msg) { return QVariant(); } 113 | 114 | if (id & 0x80000000) { 115 | return data_DisplayRole_Signal(index, role, *msg); 116 | } else if (id) { 117 | if (msg_id>1) { 118 | const CanMessage *prev_msg = trace()->getMessage(msg_id-1); 119 | return data_DisplayRole_Message(index, role, *msg, *prev_msg); 120 | } else { 121 | return data_DisplayRole_Message(index, role, *msg, CanMessage()); 122 | } 123 | } 124 | 125 | return QVariant(); 126 | } 127 | 128 | QVariant LinearTraceViewModel::data_TextColorRole(const QModelIndex &index, int role) const 129 | { 130 | (void) role; 131 | 132 | quintptr id = index.internalId(); 133 | 134 | if (id & 0x80000000) { // CanSignal row 135 | int msg_id = (id & ~0x80000000)-1; 136 | const CanMessage *msg = trace()->getMessage(msg_id); 137 | if (msg) { 138 | return data_TextColorRole_Signal(index, role, *msg); 139 | } 140 | } 141 | 142 | return QVariant(); 143 | } 144 | -------------------------------------------------------------------------------- /src/window/TraceWindow/LinearTraceViewModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include "BaseTraceViewModel.h" 28 | 29 | class Backend; 30 | 31 | class LinearTraceViewModel : public BaseTraceViewModel 32 | { 33 | Q_OBJECT 34 | 35 | public: 36 | LinearTraceViewModel(Backend &backend); 37 | 38 | virtual QModelIndex index(int row, int column, const QModelIndex &parent) const; 39 | virtual QModelIndex parent(const QModelIndex &child) const; 40 | virtual int rowCount(const QModelIndex &parent) const; 41 | virtual int columnCount(const QModelIndex &parent) const; 42 | virtual bool hasChildren(const QModelIndex &parent) const; 43 | 44 | private slots: 45 | void beforeAppend(int num_messages); 46 | void afterAppend(); 47 | void beforeClear(); 48 | void afterClear(); 49 | 50 | private: 51 | virtual QVariant data_DisplayRole(const QModelIndex &index, int role) const; 52 | virtual QVariant data_TextColorRole(const QModelIndex &index, int role) const; 53 | }; 54 | -------------------------------------------------------------------------------- /src/window/TraceWindow/TraceViewTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | typedef enum timestamp_mode { 25 | timestamp_mode_absolute, 26 | timestamp_mode_relative, 27 | timestamp_mode_delta, 28 | timestamp_modes_count 29 | } timestamp_mode_t; 30 | 31 | -------------------------------------------------------------------------------- /src/window/TraceWindow/TraceWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2015, 2016 Hubert Denkmair 4 | 5 | This file is part of cangaroo. 6 | 7 | cangaroo is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | cangaroo is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with cangaroo. If not, see . 19 | 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include "TraceViewTypes.h" 26 | 27 | namespace Ui { 28 | class TraceWindow; 29 | } 30 | 31 | class QDomDocument; 32 | class QDomElement; 33 | class QSortFilterProxyModel; 34 | class LinearTraceViewModel; 35 | class AggregatedTraceViewModel; 36 | class Backend; 37 | 38 | class TraceWindow : public ConfigurableWidget 39 | { 40 | Q_OBJECT 41 | 42 | public: 43 | typedef enum mode { 44 | mode_linear, 45 | mode_aggregated 46 | } mode_t; 47 | 48 | explicit TraceWindow(QWidget *parent, Backend &backend); 49 | ~TraceWindow(); 50 | 51 | void setMode(mode_t mode); 52 | void setAutoScroll(bool doAutoScroll); 53 | void setTimestampMode(int mode); 54 | 55 | virtual bool saveXML(Backend &backend, QDomDocument &xml, QDomElement &root); 56 | virtual bool loadXML(Backend &backend, QDomElement &el); 57 | 58 | public slots: 59 | void rowsInserted(const QModelIndex & parent, int first, int last); 60 | 61 | private slots: 62 | void on_cbAggregated_stateChanged(int i); 63 | void on_cbAutoScroll_stateChanged(int i); 64 | 65 | void on_cbTimestampMode_currentIndexChanged(int index); 66 | 67 | private: 68 | Ui::TraceWindow *ui; 69 | Backend *_backend; 70 | mode_t _mode; 71 | bool _doAutoScroll; 72 | timestamp_mode_t _timestampMode; 73 | 74 | LinearTraceViewModel *_linearTraceViewModel; 75 | AggregatedTraceViewModel *_aggregatedTraceViewModel; 76 | QSortFilterProxyModel *_aggregatedProxyModel; 77 | QSortFilterProxyModel *_linearProxyModel; 78 | }; 79 | -------------------------------------------------------------------------------- /src/window/TraceWindow/TraceWindow.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/LinearTraceViewModel.cpp \ 3 | $$PWD/AggregatedTraceViewModel.cpp \ 4 | $$PWD/BaseTraceViewModel.cpp \ 5 | $$PWD/AggregatedTraceViewItem.cpp \ 6 | $$PWD/TraceWindow.cpp 7 | 8 | HEADERS += \ 9 | $$PWD/LinearTraceViewModel.h \ 10 | $$PWD/AggregatedTraceViewModel.h \ 11 | $$PWD/BaseTraceViewModel.h \ 12 | $$PWD/AggregatedTraceViewItem.h \ 13 | $$PWD/TraceWindow.h \ 14 | $$PWD/TraceViewTypes.h 15 | 16 | FORMS += \ 17 | $$PWD/TraceWindow.ui 18 | -------------------------------------------------------------------------------- /src/window/TraceWindow/TraceWindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TraceWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 918 10 | 616 11 | 12 | 13 | 14 | Trace View 15 | 16 | 17 | 18 | 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 0 31 | 32 | 33 | 34 | 35 | Timestamps: 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | aggregate by ID 46 | 47 | 48 | 49 | 50 | 51 | 52 | auto scroll 53 | 54 | 55 | 56 | 57 | 58 | 59 | Qt::Horizontal 60 | 61 | 62 | 63 | 40 64 | 20 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | QAbstractItemView::ScrollPerPixel 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | --------------------------------------------------------------------------------