├── AnalyzerFrameTable.cpp ├── AnalyzerFrameTable.h ├── Libraries ├── canal.lib ├── canal32.lib ├── canal32d.lib ├── canal64.lib ├── canal64d.lib └── canald.lib ├── README.md ├── RxFrameTable.cpp ├── StreamFrameTable.cpp ├── StreamFrameTable.h ├── Windows.h ├── analyzerframetable.qmodel ├── can_usb.pro ├── can_usb.pro.user ├── can_usb.pro.user.4.8-pre1 ├── can_usb.pro.user.a8408b7 ├── canal.h ├── canal_macro.h ├── dialogabout.cpp ├── dialogabout.h ├── dialogabout.ui ├── dialoghelp.ui ├── dialoginitstring.cpp ├── dialoginitstring.h ├── dialoginitstring.ui ├── icon.ico ├── img ├── Rusoku_Icon.png └── icon.ico ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── mainwindowfiles.cpp ├── mainwindowsendcanmsg.cpp ├── mainwindowsettings.cpp ├── mainwindowwidgitsinit.cpp ├── messagetypes.h ├── portablesleep.h ├── resource.qrc ├── rxworkerthread.cpp ├── rxworkerthread.h ├── txworkerthread.cpp └── txworkerthread.h /AnalyzerFrameTable.cpp: -------------------------------------------------------------------------------- 1 | #include "AnalyzerFrameTable.h" 2 | #include "mainwindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | AnalyzerFrameTable::AnalyzerFrameTable(QObject *parent, QVector* streamDatabase) 12 | : QAbstractTableModel(parent) 13 | { 14 | m_StreamCanFrames = streamDatabase; 15 | m_AnalyzerCanFrames = new QVector; 16 | 17 | //RxFrameTable *table = reinterpreter_cast (parent); 18 | //m_StreamCanFrames = table->getStreamDatabasePointer(); 19 | //m_StreamCanFrames = table->m_StreamCanFrames; 20 | } 21 | 22 | AnalyzerFrameTable::~AnalyzerFrameTable() 23 | { 24 | m_AnalyzerCanFrames->clear(); 25 | m_AnalyzerCanFrames->squeeze(); 26 | delete m_AnalyzerCanFrames; 27 | } 28 | 29 | /* 30 | QVector* AnalyzerFrameTable::getStreamDatabasePointer(void) 31 | { 32 | return m_AnalyzerCanFrames; 33 | } 34 | */ 35 | 36 | QVariant AnalyzerFrameTable::headerData(int section, Qt::Orientation orientation, int role) const 37 | { 38 | 39 | if (role == Qt::DisplayRole && orientation == Qt::Horizontal) 40 | { 41 | switch (section) 42 | { 43 | //case 0: 44 | // return QString("Timestamp (us)"); 45 | case 0: 46 | return QString("Rt h:m:sec.ms"); 47 | case 1: 48 | return QString("Count"); 49 | case 2: 50 | return QString("Id type"); 51 | case 3: 52 | return QString("Id (hex)"); 53 | case 4: 54 | return QString("Length"); 55 | case 5: 56 | return QString("Data (hex)"); 57 | case 6: 58 | return QString("Ascii"); 59 | } 60 | } 61 | 62 | if (role == Qt::FontRole && orientation == Qt::Horizontal) 63 | { 64 | QFont font; 65 | font.setBold(true); 66 | return font; 67 | } 68 | 69 | return QVariant(); 70 | } 71 | 72 | int AnalyzerFrameTable::rowCount(const QModelIndex &parent) const 73 | { 74 | if (parent.isValid()) 75 | return 0; 76 | 77 | return m_AnalyzerCanFrames->size(); 78 | } 79 | 80 | int AnalyzerFrameTable::columnCount(const QModelIndex &parent) const 81 | { 82 | if (parent.isValid()) 83 | return 0; 84 | 85 | return 7; 86 | } 87 | 88 | QVariant AnalyzerFrameTable::data(const QModelIndex &index, int role) const 89 | { 90 | if (!index.isValid()) 91 | return QVariant(); 92 | 93 | analyzerMsg canframe; 94 | QByteArray data_array; 95 | QString data; 96 | QChar ch; 97 | 98 | int row = index.row(); 99 | int col = index.column(); 100 | 101 | /********************* Qt::DisplayRole ********************/ 102 | 103 | if (role == Qt::DisplayRole) 104 | { 105 | if(row < m_AnalyzerCanFrames->size()) 106 | { 107 | canframe = m_AnalyzerCanFrames->at(row); 108 | 109 | switch(col) 110 | { 111 | //case 0: 112 | // return QString("%1").arg( canframe.msg.timestamp,0,10); 113 | case 0: 114 | { 115 | return QDateTime::fromMSecsSinceEpoch(canframe.stat.diff_time, Qt::UTC).toString("hh:mm:ss.zzz"); 116 | } 117 | case 1: 118 | return QString("%1").arg(canframe.stat.count,0,10); 119 | case 2: 120 | { 121 | QString flag_string; 122 | 123 | if(canframe.msg.flags & CANAL_IDFLAG_EXTENDED) 124 | flag_string = "Ext"; 125 | else 126 | flag_string = "Std"; 127 | 128 | if(canframe.msg.flags & CANAL_IDFLAG_RTR) 129 | flag_string.append(":Rtr"); 130 | 131 | if(canframe.msg.flags & CANAL_IDFLAG_STATUS) 132 | flag_string = "Status"; 133 | 134 | return flag_string; 135 | } 136 | case 3: 137 | return QString().asprintf("%08X",canframe.msg.id); 138 | case 4: 139 | return QString("%1").arg(canframe.msg.sizeData,0,10); 140 | case 5: 141 | { 142 | data_array = QByteArray::fromRawData((const char*) canframe.msg.data, canframe.msg.sizeData).toHex(' ').toUpper(); 143 | //data = data_array.toHex(' '); 144 | //return data.toUpper(); 145 | return data_array; 146 | } 147 | case 6: 148 | { 149 | data_array = QByteArray::fromRawData((const char*) canframe.msg.data, canframe.msg.sizeData); 150 | 151 | for(int x=0; x< canframe.msg.sizeData ; x++) 152 | { 153 | ch = data_array.at(x); 154 | if(ch.isLetterOrNumber()) 155 | { 156 | data.append(ch.toLatin1()); 157 | } 158 | else 159 | data.append('.'); 160 | } 161 | return data; 162 | } 163 | } 164 | } 165 | } 166 | 167 | if( role == Qt::TextAlignmentRole) 168 | { 169 | if (col != 5) //change text alignment only for cell(1,1) 170 | return Qt::AlignHCenter + Qt::AlignVCenter; 171 | } 172 | 173 | /****************** Qt::SizeHintRole *****************/ 174 | 175 | if( role == Qt::SizeHintRole ) 176 | { 177 | if (col == 6) //change text alignment only for cell(1,1) 178 | { 179 | } 180 | } 181 | 182 | return QVariant(); 183 | } 184 | 185 | /***************************** SLOTS ****************************************/ 186 | 187 | void AnalyzerFrameTable::on_doAnalyze(const QModelIndex ¤t,const QModelIndex &previous) 188 | { 189 | //Q_UNUSED(current); 190 | Q_UNUSED(previous) 191 | //qDebug() << QString::number(current.row()); 192 | 193 | analyzerMsg tmp_analyzerMsg = {}; 194 | streamMsg tmp_streamMsg = {}; 195 | qint32 streamSelectionIndex = current.row(); 196 | /* 197 | qDebug() << ""; 198 | qDebug() << "******************************************************************"; 199 | qDebug() << QString("streamSelectionIndex %1").arg(streamSelectionIndex,0,10); 200 | qDebug() << QString("streamDataSize %1").arg(m_StreamCanFrames->size(),0,10); 201 | qDebug() << QString("analyzerDataSize %1").arg(m_AnalyzerCanFrames->size(),0,10); 202 | qDebug() << "******************************************************************"; 203 | qDebug() << ""; 204 | */ 205 | 206 | m_AnalyzerCanFrames->clear(); 207 | m_AnalyzerCanFrames->squeeze(); 208 | 209 | for(qint32 i = 0; i< streamSelectionIndex+1; ++i) // curent selected row in streamAnalyzer 210 | { 211 | //qDebug() << QString("stream counter = %1").arg(i,0,10); 212 | 213 | tmp_streamMsg = m_StreamCanFrames->at(i); 214 | 215 | if(lookForFrame(&tmp_streamMsg)) 216 | { 217 | //qDebug() << "Radom.Pakeiciam"; 218 | } 219 | else 220 | { 221 | //qDebug() << "Neradom.Irasom nauja"; 222 | tmp_analyzerMsg.msg = tmp_streamMsg.msg; 223 | tmp_analyzerMsg.stat.time = tmp_streamMsg.stat.time; 224 | tmp_analyzerMsg.stat.diff_time = 0; 225 | tmp_analyzerMsg.stat.count = 1; 226 | m_AnalyzerCanFrames->append(tmp_analyzerMsg); 227 | } 228 | } 229 | 230 | layoutAboutToBeChanged(); 231 | layoutChanged(); 232 | 233 | /* 234 | for (qint32 i = 0; i < m_AnalyzerCanFrames->size(); ++i) 235 | { 236 | temp_rxmsg = m_AnalyzerCanFrames->at(i); 237 | 238 | if((temp_rxmsg.msg.id == rxmsg.id) && (temp_rxmsg.msg.flags == rxmsg.flags)) 239 | { 240 | temp_rxmsg.msg = rxmsg; 241 | temp_rxmsg.stat.count++; 242 | 243 | temp_rxmsg.stat.diff_time = QDateTime::currentMSecsSinceEpoch() - temp_rxmsg.stat.time; 244 | temp_rxmsg.stat.time = QDateTime::currentMSecsSinceEpoch(); 245 | 246 | m_AnalyzerCanFrames->replace(i,temp_rxmsg); 247 | goto end; 248 | } 249 | } 250 | */ 251 | 252 | //temp_rxmsg.msg = rxmsg; 253 | //temp_rxmsg.stat.time = QDateTime::currentMSecsSinceEpoch(); 254 | //temp_rxmsg.stat.diff_time = 0; 255 | //m_AnalyzerCanFrames->append(temp_rxmsg); 256 | //end: 257 | 258 | } 259 | 260 | bool AnalyzerFrameTable::lookForFrame(streamMsg *streamMesage) 261 | { 262 | analyzerMsg tmp_analyzerMsg = {}; 263 | 264 | for(qint32 j = 0; j< m_AnalyzerCanFrames->size(); j++) 265 | { 266 | tmp_analyzerMsg = m_AnalyzerCanFrames->at(j); 267 | 268 | //qDebug() << ""; 269 | //qDebug() << QString("Stream Id %1").arg(streamFrame->id,0,16); 270 | //qDebug() << QString("Analyzer Id %1").arg(tmp_analyzerMsg.msg.id,0,16); 271 | 272 | if((tmp_analyzerMsg.msg.id == streamMesage->msg.id ) && (tmp_analyzerMsg.msg.flags == streamMesage->msg.flags)) 273 | { 274 | tmp_analyzerMsg.msg = streamMesage->msg; 275 | tmp_analyzerMsg.stat.count++; 276 | tmp_analyzerMsg.stat.diff_time = streamMesage->stat.time - tmp_analyzerMsg.stat.time; 277 | tmp_analyzerMsg.stat.time = streamMesage->stat.time; 278 | m_AnalyzerCanFrames->replace(j,tmp_analyzerMsg); 279 | //qDebug() << "Pass"; 280 | //qDebug() << ""; 281 | return true; 282 | } 283 | } 284 | 285 | //qDebug() << QString("Stream Id %1").arg(streamFrame->id,0,16); 286 | //qDebug() << QString("Analyzer Id %1").arg(tmp_analyzerMsg.msg.id,0,16); 287 | //qDebug() << "Unpass"; 288 | //qDebug() << ""; 289 | return false; 290 | } 291 | 292 | -------------------------------------------------------------------------------- /AnalyzerFrameTable.h: -------------------------------------------------------------------------------- 1 | #ifndef ANALYZERFRAMETABLE_H 2 | #define ANALYZERFRAMETABLE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "canal.h" 8 | #include "messagetypes.h" 9 | 10 | 11 | class AnalyzerFrameTable : public QAbstractTableModel 12 | { 13 | Q_OBJECT 14 | 15 | private: 16 | bool lookForFrame(streamMsg *streamFrame); 17 | 18 | public: 19 | explicit AnalyzerFrameTable(QObject *parent = nullptr, QVector* streamDatabase = nullptr); 20 | ~AnalyzerFrameTable(); 21 | 22 | // QVector* getStreamDatabasePointer(void); 23 | 24 | // Header: 25 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 26 | 27 | // Basic functionality: 28 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; 29 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; 30 | 31 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 32 | 33 | QVector *m_AnalyzerCanFrames; 34 | QVector *m_StreamCanFrames; 35 | 36 | //public slots: 37 | 38 | public slots: 39 | void on_doAnalyze(const QModelIndex ¤t, const QModelIndex &previous); 40 | }; 41 | 42 | #endif // ANALYZERFRAMETABLE_H 43 | -------------------------------------------------------------------------------- /Libraries/canal.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rusoku/CANAL-View/f1c9d3c5826059f54d98f3535f2f295f545af478/Libraries/canal.lib -------------------------------------------------------------------------------- /Libraries/canal32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rusoku/CANAL-View/f1c9d3c5826059f54d98f3535f2f295f545af478/Libraries/canal32.lib -------------------------------------------------------------------------------- /Libraries/canal32d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rusoku/CANAL-View/f1c9d3c5826059f54d98f3535f2f295f545af478/Libraries/canal32d.lib -------------------------------------------------------------------------------- /Libraries/canal64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rusoku/CANAL-View/f1c9d3c5826059f54d98f3535f2f295f545af478/Libraries/canal64.lib -------------------------------------------------------------------------------- /Libraries/canal64d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rusoku/CANAL-View/f1c9d3c5826059f54d98f3535f2f295f545af478/Libraries/canal64d.lib -------------------------------------------------------------------------------- /Libraries/canald.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rusoku/CANAL-View/f1c9d3c5826059f54d98f3535f2f295f545af478/Libraries/canald.lib -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CANAL-View 2 | CANAL View Qt GUI for TouCAN series USB to CAN bus converter 3 | 4 | Init string parameters: 5 | 6 | 1 2 3 4 5 6 7 7 | device_type ; device_serial_number ; speed ; tseg1 ; tseg2 ; sjw ; brp 8 | 9 | where: 10 | 1 - device type: for TouCAN,TouCAN Marine,TouCAN Duo this paramer is always == 0 11 | 2 - device serial number: always 8 symbols like 12345678 12 | serial number you can find on bottom device case side like sn:12345678 13 | 3 - CAN bus speed: standard speed list: 10;20;50;100;125;250;500;1000 14 | 4 - CAN bus parameter tseg1 15 | 5 - CAN bus parameter tseg2 16 | 6 - CAN bus parameter sjw 17 | 7 - CAN bus parameter brp 18 | 19 | If standard speed list is used next arguments can be skipped. 20 | For example init string will looks like 0;12345678;1000 21 | 22 | For non standard CAN bus speeds: speed parameter must be == 0 23 | For example 1000 kbit speed init string will looks like: 0;12345678;0;7;2;2;5 24 | where: tseg1 = 7, tseg2 = 2, sjw = 2, brp = 5 25 | CAN interface clock is : 50MHz 26 | 27 | CAN bus parameters calculator: http://www.bittiming.can-wiki.info 28 | -------------------------------------------------------------------------------- /RxFrameTable.cpp: -------------------------------------------------------------------------------- 1 | #include "RxFrameTable.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | //m_RxMsgList = new QVector; 10 | 11 | RxFrameTable::RxFrameTable(QObject *parent/*, QVector& rxmsglist*/) : QAbstractTableModel(parent), /*m_RxCanFrames(rxmsglist),*/ m_timer(new QTimer(this)) 12 | { 13 | //m_timer->setInterval(100); 14 | //connect(m_timer, &QTimer::timeout , this, &RxFrameTable::timerHit); 15 | //m_timer->start(); 16 | m_RxCanFrames = new QVector; 17 | 18 | } 19 | 20 | RxFrameTable::~RxFrameTable() 21 | { 22 | m_RxCanFrames->clear(); 23 | m_RxCanFrames->squeeze(); 24 | delete m_RxCanFrames; 25 | } 26 | 27 | 28 | /* QTableItemModel */ 29 | QVariant RxFrameTable::headerData(int section, Qt::Orientation orientation, int role) const 30 | { 31 | if (role == Qt::DisplayRole && orientation == Qt::Horizontal) 32 | { 33 | switch (section) 34 | { 35 | case 0: 36 | return QString("Timestamp (us)"); 37 | case 1: 38 | return QString("Type"); 39 | case 2: 40 | return QString("Id"); 41 | case 3: 42 | return QString("Length"); 43 | case 4: 44 | return QString("Data"); 45 | } 46 | } 47 | 48 | 49 | if (role == Qt::SizeHintRole && orientation == Qt::Horizontal){ 50 | 51 | //QSize size(100,10); 52 | //size.shrunkBy() 53 | //return size; 54 | } 55 | 56 | // if (role == Qt::BackgroundRole && orientation == Qt::Horizontal){ 57 | //return QBrush(Qt::red); 58 | // return ??? 59 | // } 60 | 61 | /* 62 | if (role == Qt::DisplayRole && orientation == Qt::Vertical) 63 | { 64 | //return QString("%1").arg(section + 1); 65 | return QVariant(section).toString(); 66 | } 67 | */ 68 | 69 | return QVariant(); 70 | } 71 | 72 | 73 | int RxFrameTable::rowCount(const QModelIndex &parent) const 74 | { 75 | if (parent.isValid()) 76 | return 0; 77 | 78 | return m_RxCanFrames->size(); 79 | //return 1; 80 | } 81 | 82 | int RxFrameTable::columnCount(const QModelIndex &parent) const 83 | { 84 | if (parent.isValid()) 85 | return 0; 86 | 87 | return 5; 88 | } 89 | 90 | QVariant RxFrameTable::data(const QModelIndex &index, int role) const 91 | { 92 | 93 | int row = index.row(); 94 | int col = index.column(); 95 | // uint cnt = 0; 96 | 97 | /* 98 | typedef struct _CANframe 99 | { 100 | quint32 timestamp; 101 | quint8 flags; 102 | quint32 id; 103 | quint8 sizeData; 104 | quint8 data[64]; 105 | } CANframe; 106 | */ 107 | //CANframe canframeFD; 108 | canalMsg canframe; 109 | 110 | //canframeFD.sizeData = 64; 111 | //for(int x=0; x<64; x++) canframeFD.data [x] = x; 112 | 113 | /* 114 | typedef struct structCanalMsg { 115 | unsigned long flags; // CAN message flags 116 | unsigned long obid; // Used by driver for channel info etc. 117 | unsigned long id; // CAN id (11-bit or 29-bit) 118 | unsigned char sizeData; // Data size 0-8 119 | unsigned char data[8]; // CAN Data 120 | unsigned long timestamp; // Relative time stamp for package in microseconds 121 | } canalMsg; 122 | */ 123 | 124 | 125 | /********************* Qt::DisplayRole ********************/ 126 | 127 | if (role == Qt::DisplayRole) 128 | { 129 | QByteArray data_array; 130 | QString data; 131 | 132 | if(row < m_RxCanFrames->size()) 133 | { 134 | canframe = m_RxCanFrames->at(row); 135 | 136 | switch(col) 137 | { 138 | case 0: 139 | return QString("%1").arg(canframe.timestamp,0,10); 140 | case 1: 141 | { 142 | QString flag_string; 143 | 144 | if(canframe.flags & CANAL_IDFLAG_EXTENDED) 145 | flag_string = "Ext"; 146 | else 147 | flag_string = "Std"; 148 | 149 | if(canframe.flags & CANAL_IDFLAG_RTR) 150 | flag_string.append(":Rtr"); 151 | 152 | if(canframe.flags & CANAL_IDFLAG_STATUS) 153 | flag_string = "Status"; 154 | 155 | return flag_string; 156 | } 157 | case 2: 158 | return QString("0x%1").arg(canframe.id,0,16); 159 | case 3: 160 | return QString("%1").arg(canframe.sizeData,0,10); 161 | case 4: 162 | { 163 | //data_array = QByteArray::fromRawData((const char*) canframeFD.data, canframeFD.sizeData); 164 | data_array = QByteArray::fromRawData((const char*) canframe.data, canframe.sizeData & 0xF); 165 | data = data_array.toHex(' '); 166 | return data; 167 | } 168 | } 169 | } 170 | } 171 | 172 | /****************** Qt::TextAlignmentRole *****************/ 173 | 174 | if( role == Qt::ForegroundRole) 175 | { 176 | if(col == 2) 177 | { 178 | //return QColor(Qt::red); 179 | } 180 | } 181 | 182 | /****************** Qt::TextAlignmentRole *****************/ 183 | 184 | if( role == Qt::TextAlignmentRole) 185 | { 186 | if (col != 4) //change text alignment only for cell(1,1) 187 | return Qt::AlignHCenter + Qt::AlignVCenter; 188 | } 189 | 190 | /****************** Qt::SizeHintRole *****************/ 191 | 192 | if( role == Qt::SizeHintRole ) 193 | { 194 | if (col == 4) //change text alignment only for cell(1,1) 195 | { 196 | //QSize size; 197 | //size.setWidth(50); 198 | //return size; 199 | } 200 | } 201 | 202 | 203 | return QVariant(); 204 | } 205 | 206 | Qt::ItemFlags RxFrameTable::flags(const QModelIndex &index) const 207 | { 208 | Qt::ItemFlags flags; 209 | 210 | flags = QAbstractItemModel::flags(index); 211 | 212 | flags |= Qt::ItemIsEditable; 213 | return flags; 214 | } 215 | 216 | /**************************** Timer *****************************/ 217 | void RxFrameTable::timerHit() 218 | { 219 | //selectR 220 | //ui->RxMsgTableView->scrollToBottom(); 221 | //ui->RxMsgTableView->selectRow(RxTableModel->m_RxCanFrames.size()-1); 222 | //ui->RxMsgTableView->setFocus(); 223 | } 224 | 225 | 226 | -------------------------------------------------------------------------------- /StreamFrameTable.cpp: -------------------------------------------------------------------------------- 1 | #include "StreamFrameTable.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | RxFrameTable::RxFrameTable(QObject *parent/*, QVector& rxmsglist*/) : QAbstractTableModel(parent), /*m_RxCanFrames(rxmsglist),*/ m_timer(new QTimer(this)) 13 | { 14 | //m_timer->setInterval(100); 15 | //connect(m_timer, &QTimer::timeout , this, &RxFrameTable::timerHit); 16 | //m_timer->start(); 17 | m_StreamCanFrames = new QVector; 18 | 19 | } 20 | 21 | RxFrameTable::~RxFrameTable() 22 | { 23 | m_StreamCanFrames->clear(); 24 | m_StreamCanFrames->squeeze(); 25 | delete m_StreamCanFrames; 26 | } 27 | 28 | QVector* RxFrameTable::getStreamDatabasePointer(void) 29 | { 30 | return m_StreamCanFrames; 31 | } 32 | 33 | /* QTableItemModel */ 34 | QVariant RxFrameTable::headerData(int section, Qt::Orientation orientation, int role) const 35 | { 36 | if (role == Qt::DisplayRole && orientation == Qt::Horizontal) 37 | { 38 | switch (section) 39 | { 40 | case 0: 41 | return QString("Timestamp (us)"); 42 | case 1: 43 | return QString("T h:m:sec.ms"); 44 | case 2: 45 | return QString("Id type"); 46 | case 3: 47 | return QString("Id (hex)"); 48 | case 4: 49 | return QString("Length"); 50 | case 5: 51 | return QString("Data (hex)"); 52 | case 6: 53 | return QString("Ascii"); 54 | } 55 | } 56 | 57 | if (role == Qt::SizeHintRole && orientation == Qt::Horizontal){ 58 | 59 | //QSize size(100,10); 60 | //size.shrunkBy() 61 | //return size; 62 | } 63 | 64 | if (role == Qt::FontRole && orientation == Qt::Horizontal) 65 | { 66 | QFont font; 67 | font.setBold(true); 68 | return font; 69 | } 70 | 71 | 72 | // if (role == Qt::BackgroundRole && orientation == Qt::Horizontal){ 73 | //return QBrush(Qt::red); 74 | // return ??? 75 | // } 76 | 77 | /* 78 | if (role == Qt::DisplayRole && orientation == Qt::Vertical) 79 | { 80 | //return QString("%1").arg(section + 1); 81 | return QVariant(section).toString(); 82 | } 83 | */ 84 | 85 | return QVariant(); 86 | } 87 | 88 | 89 | int RxFrameTable::rowCount(const QModelIndex &parent) const 90 | { 91 | if (parent.isValid()) 92 | return 0; 93 | /* 94 | if(m_RxCanFrames->size() == 0) 95 | return 1; 96 | else 97 | return m_RxCanFrames->size(); 98 | */ 99 | return m_StreamCanFrames->size(); 100 | } 101 | 102 | int RxFrameTable::columnCount(const QModelIndex &parent) const 103 | { 104 | if (parent.isValid()) 105 | return 0; 106 | 107 | return 7; 108 | } 109 | 110 | QVariant RxFrameTable::data(const QModelIndex &index, int role) const 111 | { 112 | 113 | int row = index.row(); 114 | int col = index.column(); 115 | 116 | streamMsg canframe; 117 | 118 | QByteArray data_array; 119 | QString data; 120 | QChar ch; 121 | 122 | /********************* Qt::DisplayRole ********************/ 123 | 124 | if (role == Qt::DisplayRole) 125 | { 126 | if(row < m_StreamCanFrames->size()) 127 | { 128 | canframe = m_StreamCanFrames->at(row); 129 | 130 | switch(col) 131 | { 132 | case 0: 133 | return QString("%1").arg(canframe.msg.timestamp,0,10); 134 | case 1: 135 | return QDateTime::fromMSecsSinceEpoch(canframe.stat.time, Qt::UTC).toString("hh:mm:ss.zzz"); 136 | case 2: 137 | { 138 | QString flag_string; 139 | 140 | if(canframe.msg.flags & CANAL_IDFLAG_EXTENDED) 141 | flag_string = "Ext"; 142 | else 143 | flag_string = "Std"; 144 | 145 | if(canframe.msg.flags & CANAL_IDFLAG_RTR) 146 | flag_string.append(":Rtr"); 147 | 148 | if(canframe.msg.flags & CANAL_IDFLAG_STATUS) 149 | flag_string = "Status"; 150 | 151 | return flag_string; 152 | } 153 | case 3: 154 | return QString().asprintf("%08X",canframe.msg.id); 155 | case 4: 156 | return QString("%1").arg(canframe.msg.sizeData,0,10); 157 | case 5: 158 | { 159 | data_array = QByteArray::fromRawData((const char*) canframe.msg.data, canframe.msg.sizeData & 0x0F).toHex(' ').toUpper(); 160 | //data = data_array.toHex(' '); 161 | //return data.toUpper(); 162 | return data_array; 163 | } 164 | case 6: 165 | { 166 | data_array = QByteArray::fromRawData((const char*) canframe.msg.data, canframe.msg.sizeData & 0x0F); 167 | 168 | for(int x=0; x< canframe.msg.sizeData ; x++) 169 | { 170 | ch = data_array.at(x); 171 | if(ch.isLetterOrNumber()) 172 | { 173 | data.append(ch.toLatin1()); 174 | } 175 | else 176 | data.append('.'); 177 | } 178 | return data; 179 | } 180 | } 181 | } 182 | } 183 | 184 | /****************** Qt::TextAlignmentRole *****************/ 185 | 186 | if( role == Qt::ForegroundRole) 187 | { 188 | if(col == 2) 189 | { 190 | //return QColor(Qt::red); 191 | } 192 | } 193 | 194 | /****************** Qt::TextAlignmentRole *****************/ 195 | 196 | if( role == Qt::TextAlignmentRole) 197 | { 198 | if (col != 5) //change text alignment only for cell(1,1) 199 | return Qt::AlignHCenter + Qt::AlignVCenter; 200 | } 201 | 202 | /****************** Qt::SizeHintRole *****************/ 203 | 204 | if( role == Qt::SizeHintRole ) 205 | { 206 | if (col == 4) //change text alignment only for cell(1,1) 207 | { 208 | //QSize size; 209 | //size.setWidth(50); 210 | //return size; 211 | } 212 | } 213 | 214 | return QVariant(); 215 | } 216 | 217 | Qt::ItemFlags RxFrameTable::flags(const QModelIndex &index) const 218 | { 219 | Qt::ItemFlags flags; 220 | 221 | flags = QAbstractItemModel::flags(index); 222 | 223 | flags |= Qt::ItemIsEditable; 224 | return flags; 225 | } 226 | 227 | void RxFrameTable::updateFrame(quint32 cnt, canalMsg rxmsg) 228 | { 229 | Q_UNUSED(cnt); 230 | streamMsg stream_msg; 231 | 232 | // ui->label_RxFramesCnt->setText(QString::number(cnt)); 233 | //ui->progressBar->setValue(cnt); 234 | //RxTableModel->m_RxCanFrames.indexOf(rxmsg.id,0); 235 | 236 | m_FramesCnt = cnt; 237 | 238 | stream_msg.msg = rxmsg; 239 | stream_msg.stat.time = QDateTime::currentMSecsSinceEpoch(); 240 | 241 | m_StreamCanFrames->append(stream_msg); 242 | if(updateFrameTimerEnable == false) 243 | { 244 | QTimer::singleShot(100, this ,SLOT(updateFrameTimerCallback())); 245 | updateFrameTimerEnable = true; 246 | } 247 | 248 | //ui->RxMsgTableView->scrollToBottom(); 249 | //ui->RxMsgTableView->selectRow(RxTableModel->m_RxCanFrames.size()-1); 250 | //ui->RxMsgTableView->setFocus(); 251 | } 252 | 253 | void RxFrameTable::updateFrameTimerCallback(void) 254 | { 255 | //QModelIndex Left = createIndex(m_StreamCanFrames->size(),0); 256 | //QModelIndex Right = createIndex(m_StreamCanFrames->size(),6); 257 | 258 | //const QModelIndex idx = index(0); 259 | //emit dataChanged(idx ,idx ); 260 | 261 | /* signal */ 262 | // dataChanged(Left, Right); 263 | layoutAboutToBeChanged(); 264 | layoutChanged(); 265 | 266 | /* signal */ 267 | emit newFrameArrived(m_FramesCnt); 268 | 269 | updateFrameTimerEnable = false; 270 | } 271 | 272 | /**************************** Timer *****************************/ 273 | void RxFrameTable::timerHit() 274 | { 275 | //selectR 276 | //ui->RxMsgTableView->scrollToBottom(); 277 | //ui->RxMsgTableView->selectRow(RxTableModel->m_RxCanFrames.size()-1); 278 | //ui->RxMsgTableView->setFocus(); 279 | } 280 | 281 | -------------------------------------------------------------------------------- /StreamFrameTable.h: -------------------------------------------------------------------------------- 1 | #ifndef RXFRAMETABLE_H 2 | #define RXFRAMETABLE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "canal.h" 8 | #include "messagetypes.h" 9 | 10 | 11 | class RxFrameTable : public QAbstractTableModel 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit RxFrameTable(QObject *parent); 17 | ~RxFrameTable(); 18 | 19 | QVector* getStreamDatabasePointer(void); 20 | 21 | // Header: 22 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 23 | 24 | // Basic functionality: 25 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; 26 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; 27 | 28 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 29 | Qt::ItemFlags flags(const QModelIndex &parent) const override; 30 | 31 | QVector* m_StreamCanFrames; 32 | 33 | signals: 34 | void newFrameArrived(int cnt); 35 | 36 | private: 37 | 38 | bool updateFrameTimerEnable = false; 39 | QTimer *m_timer; 40 | quint32 m_FramesCnt; 41 | 42 | public slots: 43 | void updateFrame(quint32 cnt, canalMsg rxmsg); 44 | 45 | private slots: 46 | void updateFrameTimerCallback(void); 47 | void timerHit(); 48 | 49 | }; 50 | 51 | #endif // RXFRAMETABLE_H 52 | -------------------------------------------------------------------------------- /Windows.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /*++ BUILD Version: 0001 Increment this if a change has global effects 4 | 5 | Copyright (c) Microsoft Corporation. All rights reserved. 6 | 7 | Module Name: 8 | 9 | 10 | windows.h 11 | 12 | Abstract: 13 | 14 | Master include file for Windows applications. 15 | 16 | --*/ 17 | 18 | #ifndef _WINDOWS_ 19 | #define _WINDOWS_ 20 | 21 | 22 | #include 23 | 24 | #ifndef _INC_WINDOWS 25 | #define _INC_WINDOWS 26 | 27 | #if defined (_MSC_VER) && (_MSC_VER >= 1020) 28 | #pragma once 29 | #endif 30 | 31 | #pragma region Application Family or OneCore Family 32 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) 33 | 34 | 35 | /* If defined, the following flags inhibit definition 36 | * of the indicated items. 37 | * 38 | * NOGDICAPMASKS - CC_*, LC_*, PC_*, CP_*, TC_*, RC_ 39 | * NOVIRTUALKEYCODES - VK_* 40 | * NOWINMESSAGES - WM_*, EM_*, LB_*, CB_* 41 | * NOWINSTYLES - WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_* 42 | * NOSYSMETRICS - SM_* 43 | * NOMENUS - MF_* 44 | * NOICONS - IDI_* 45 | * NOKEYSTATES - MK_* 46 | * NOSYSCOMMANDS - SC_* 47 | * NORASTEROPS - Binary and Tertiary raster ops 48 | * NOSHOWWINDOW - SW_* 49 | * OEMRESOURCE - OEM Resource values 50 | * NOATOM - Atom Manager routines 51 | * NOCLIPBOARD - Clipboard routines 52 | * NOCOLOR - Screen colors 53 | * NOCTLMGR - Control and Dialog routines 54 | * NODRAWTEXT - DrawText() and DT_* 55 | * NOGDI - All GDI defines and routines 56 | * NOKERNEL - All KERNEL defines and routines 57 | * NOUSER - All USER defines and routines 58 | * NONLS - All NLS defines and routines 59 | * NOMB - MB_* and MessageBox() 60 | * NOMEMMGR - GMEM_*, LMEM_*, GHND, LHND, associated routines 61 | * NOMETAFILE - typedef METAFILEPICT 62 | * NOMINMAX - Macros min(a,b) and max(a,b) 63 | * NOMSG - typedef MSG and associated routines 64 | * NOOPENFILE - OpenFile(), OemToAnsi, AnsiToOem, and OF_* 65 | * NOSCROLL - SB_* and scrolling routines 66 | * NOSERVICE - All Service Controller routines, SERVICE_ equates, etc. 67 | * NOSOUND - Sound driver routines 68 | * NOTEXTMETRIC - typedef TEXTMETRIC and associated routines 69 | * NOWH - SetWindowsHook and WH_* 70 | * NOWINOFFSETS - GWL_*, GCL_*, associated routines 71 | * NOCOMM - COMM driver routines 72 | * NOKANJI - Kanji support stuff. 73 | * NOHELP - Help engine interface. 74 | * NOPROFILER - Profiler interface. 75 | * NODEFERWINDOWPOS - DeferWindowPos routines 76 | * NOMCX - Modem Configuration Extensions 77 | */ 78 | 79 | #if defined(RC_INVOKED) && !defined(NOWINRES) 80 | 81 | #include 82 | 83 | #else 84 | 85 | #if defined(RC_INVOKED) 86 | /* Turn off a bunch of stuff to ensure that RC files compile OK. */ 87 | #define NOATOM 88 | #define NOGDI 89 | #define NOGDICAPMASKS 90 | #define NOMETAFILE 91 | #define NOMINMAX 92 | #define NOMSG 93 | #define NOOPENFILE 94 | #define NORASTEROPS 95 | #define NOSCROLL 96 | #define NOSOUND 97 | #define NOSYSMETRICS 98 | #define NOTEXTMETRIC 99 | #define NOWH 100 | #define NOCOMM 101 | #define NOKANJI 102 | #define NOCRYPT 103 | #define NOMCX 104 | #endif 105 | 106 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_IX86) 107 | #define _X86_ 108 | #if !defined(_CHPE_X86_ARM64_) && defined(_M_HYBRID) 109 | #define _CHPE_X86_ARM64_ 110 | #endif 111 | #endif 112 | 113 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_AMD64) 114 | #define _AMD64_ 115 | #endif 116 | 117 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_ARM) 118 | #define _ARM_ 119 | #endif 120 | 121 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_ARM64) 122 | #define _ARM64_ 123 | #endif 124 | 125 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_M68K) 126 | #define _68K_ 127 | #endif 128 | 129 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_MPPC) 130 | #define _MPPC_ 131 | #endif 132 | 133 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && !defined(_ARM_) && !defined(_ARM64_) && defined(_M_IA64) 134 | #if !defined(_IA64_) 135 | #define _IA64_ 136 | #endif /* !_IA64_ */ 137 | #endif 138 | 139 | #ifndef _MAC 140 | #if defined(_68K_) || defined(_MPPC_) 141 | #define _MAC 142 | #endif 143 | #endif 144 | 145 | #if defined (_MSC_VER) 146 | #if ( _MSC_VER >= 800 ) 147 | #ifndef __cplusplus 148 | #pragma warning(disable:4116) /* TYPE_ALIGNMENT generates this - move it */ 149 | /* outside the warning push/pop scope. */ 150 | #endif 151 | #endif 152 | #endif 153 | 154 | #ifndef RC_INVOKED 155 | #if ( _MSC_VER >= 800 ) 156 | #pragma warning(disable:4514) 157 | #ifndef __WINDOWS_DONT_DISABLE_PRAGMA_PACK_WARNING__ 158 | #pragma warning(disable:4103) 159 | #endif 160 | #if _MSC_VER >= 1200 161 | #pragma warning(push) 162 | #endif 163 | #pragma warning(disable:4001) 164 | #pragma warning(disable:4201) 165 | #pragma warning(disable:4214) 166 | #endif 167 | #include 168 | #include 169 | #endif /* RC_INVOKED */ 170 | 171 | #include 172 | #include 173 | #include 174 | #include 175 | #if !defined(_MAC) || defined(_WIN32NLS) 176 | #include 177 | #endif 178 | #ifndef _MAC 179 | #include 180 | #include 181 | #endif 182 | #if !defined(_MAC) || defined(_WIN32REG) 183 | #include 184 | #endif 185 | #ifndef _MAC 186 | #include 187 | #endif 188 | 189 | #ifndef WIN32_LEAN_AND_MEAN 190 | #include 191 | #include 192 | #include 193 | #include 194 | #ifndef _MAC 195 | #include 196 | #include 197 | #include 198 | #include 199 | #endif 200 | #include 201 | #ifndef _MAC 202 | #include 203 | #include 204 | #endif 205 | #ifndef NOCRYPT 206 | #include 207 | #include 208 | #include 209 | #endif 210 | 211 | #ifndef NOGDI 212 | #ifndef _MAC 213 | #include 214 | #ifdef INC_OLE1 215 | #include 216 | #else 217 | #include 218 | #endif /* !INC_OLE1 */ 219 | #endif /* !MAC */ 220 | #include 221 | #endif /* !NOGDI */ 222 | #endif /* WIN32_LEAN_AND_MEAN */ 223 | 224 | #include 225 | 226 | #ifdef _MAC 227 | #include 228 | #endif 229 | 230 | 231 | #ifdef INC_OLE2 232 | #include 233 | #endif /* INC_OLE2 */ 234 | 235 | #ifndef _MAC 236 | #ifndef NOSERVICE 237 | #include 238 | #endif 239 | 240 | #if(WINVER >= 0x0400) 241 | #ifndef NOMCX 242 | #include 243 | #endif /* NOMCX */ 244 | 245 | #ifndef NOIME 246 | #include 247 | #endif 248 | #endif /* WINVER >= 0x0400 */ 249 | #endif 250 | 251 | #ifndef RC_INVOKED 252 | #if ( _MSC_VER >= 800 ) 253 | #if _MSC_VER >= 1200 254 | #pragma warning(pop) 255 | #else 256 | #pragma warning(default:4001) 257 | #pragma warning(default:4201) 258 | #pragma warning(default:4214) 259 | /* Leave 4514 disabled. It's an unneeded warning anyway. */ 260 | #endif 261 | #endif 262 | #endif /* RC_INVOKED */ 263 | 264 | #endif /* RC_INVOKED */ 265 | 266 | #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */ 267 | #pragma endregion 268 | 269 | #endif /* _INC_WINDOWS */ 270 | 271 | #endif /* _WINDOWS_ */ 272 | 273 | -------------------------------------------------------------------------------- /analyzerframetable.qmodel: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {70b681c7-f47d-4514-8b79-7c32e4d49f84} 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | {cd0a228f-7ab2-4afc-8fbf-aaf641b302a4} 13 | 14 | 15 | AnalyzerFrameTable 16 | 17 | 18 | 19 | 20 | 21 | 22 | {9c3ad4b8-2457-46cf-9235-85f10bf1bc2e} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | {9c3ad4b8-2457-46cf-9235-85f10bf1bc2e} 33 | 34 | 35 | AnalyzerFrameTable 36 | 37 | 38 | General 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /can_usb.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2018-12-02T19:24:24 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = CanalView 12 | TEMPLATE = app 13 | 14 | RC_ICONS = icon.ico 15 | 16 | VERSION = 1.0.8 17 | QMAKE_TARGET_COMPANY = RUSOKU Technologies 18 | QMAKE_TARGET_PRODUCT = CANAL View 19 | QMAKE_TARGET_DESCRIPTION = Demo software for CANAL library 20 | QMAKE_TARGET_COPYRIGHT = LGPL 21 | 22 | # The following define makes your compiler emit warnings if you use 23 | # any feature of Qt which has been marked as deprecated (the exact warnings 24 | # depend on your compiler). Please consult the documentation of the 25 | # deprecated API in order to know how to port your code away from it. 26 | DEFINES += QT_DEPRECATED_WARNINGS 27 | 28 | # You can also make your code fail to compile if you use deprecated APIs. 29 | # In order to do so, uncomment the following line. 30 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 31 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 32 | 33 | #CONFIG += c++11 34 | #CONFIG += dll 35 | #CONFIG -= embed_manifest_exe 36 | 37 | SOURCES += \ 38 | AnalyzerFrameTable.cpp \ 39 | StreamFrameTable.cpp \ 40 | rxworkerthread.cpp \ 41 | main.cpp \ 42 | mainwindow.cpp \ 43 | mainwindowfiles.cpp \ 44 | mainwindowsettings.cpp \ 45 | mainwindowwidgitsinit.cpp \ 46 | mainwindowsendcanmsg.cpp \ 47 | txworkerthread.cpp \ 48 | dialogabout.cpp \ 49 | dialoginitstring.cpp 50 | 51 | 52 | HEADERS += \ 53 | AnalyzerFrameTable.h \ 54 | StreamFrameTable.h \ 55 | mainwindow.h \ 56 | canal.h \ 57 | messagetypes.h \ 58 | rxworkerthread.h \ 59 | portablesleep.h \ 60 | txworkerthread.h \ 61 | dialogabout.h \ 62 | dialoginitstring.h 63 | 64 | FORMS += \ 65 | mainwindow.ui \ 66 | dialogabout.ui \ 67 | dialoginitstring.ui 68 | 69 | #DEFINES += QT_NO_CAST_FROM_ASCII \ 70 | # QT_NO_CAST_TO_ASCII 71 | 72 | #INCLUDEPATH += "$$PWD/ucrt" 73 | LIBS += -L"$$PWD/Libraries" 74 | 75 | # Default rules for deployment. 76 | #qnx: target.path = /tmp/$${TARGET}/bin 77 | #else: unix:!android: target.path = /opt/$${TARGET}/bin 78 | #!isEmpty(target.path): INSTALLS += target 79 | 80 | #contains(QT_ARCH, i386) { 81 | CONFIG(release, debug|release): LIBS += -L$$PWD/Libraries -lcanal 82 | CONFIG(debug, debug|release): LIBS += -L$$PWD/Libraries -lcanald 83 | 84 | #} else { 85 | # CONFIG(release, debug|release): LIBS += -L$$PWD/Libraries -lcanal 86 | # CONFIG(debug, debug|release): LIBS += -L$$PWD/Libraries -lcanal 87 | #} 88 | 89 | RESOURCES += \ 90 | resource.qrc 91 | 92 | DISTFILES += 93 | 94 | -------------------------------------------------------------------------------- /can_usb.pro.user.a8408b7: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {a8408b7b-0c08-4dd7-961d-8fcdc51ab540} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 2 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | -fno-delayed-template-parsing 60 | 61 | true 62 | 63 | true 64 | Builtin.TidyAndClazy 65 | 4 66 | 67 | C:/QTprojects/can_usb/can_usb.pro 68 | 69 | 70 | 71 | true 72 | 73 | 74 | 75 | 76 | ProjectExplorer.Project.Target.0 77 | 78 | Desktop Qt 5.14.2 MSVC2017 32bit 79 | Desktop Qt 5.14.2 MSVC2017 32bit 80 | qt.qt5.5142.win32_msvc2017_kit 81 | 1 82 | 0 83 | 0 84 | 85 | C:/QTprojects/build-can_usb-Desktop_Qt_5_14_2_MSVC2017_32bit-Debug 86 | 87 | 88 | true 89 | QtProjectManager.QMakeBuildStep 90 | true 91 | 92 | false 93 | false 94 | false 95 | 96 | 97 | true 98 | Qt4ProjectManager.MakeStep 99 | 100 | false 101 | 102 | 103 | false 104 | 105 | 2 106 | Build 107 | Build 108 | ProjectExplorer.BuildSteps.Build 109 | 110 | 111 | 112 | true 113 | Qt4ProjectManager.MakeStep 114 | 115 | true 116 | clean 117 | 118 | false 119 | 120 | 1 121 | Clean 122 | Clean 123 | ProjectExplorer.BuildSteps.Clean 124 | 125 | 2 126 | false 127 | 128 | Debug 129 | Qt4ProjectManager.Qt4BuildConfiguration 130 | 2 131 | 132 | 133 | C:/QTprojects/build-can_usb-Desktop_Qt_5_14_2_MSVC2017_32bit-Release 134 | 135 | 136 | true 137 | QtProjectManager.QMakeBuildStep 138 | false 139 | 140 | false 141 | false 142 | true 143 | 144 | 145 | true 146 | Qt4ProjectManager.MakeStep 147 | 148 | false 149 | 150 | 151 | false 152 | 153 | 2 154 | Build 155 | Build 156 | ProjectExplorer.BuildSteps.Build 157 | 158 | 159 | 160 | true 161 | Qt4ProjectManager.MakeStep 162 | 163 | true 164 | clean 165 | 166 | false 167 | 168 | 1 169 | Clean 170 | Clean 171 | ProjectExplorer.BuildSteps.Clean 172 | 173 | 2 174 | false 175 | 176 | Release 177 | Qt4ProjectManager.Qt4BuildConfiguration 178 | 0 179 | 180 | 181 | C:/QTprojects/build-can_usb-Desktop_Qt_5_14_2_MSVC2017_32bit-Profile 182 | 183 | 184 | true 185 | QtProjectManager.QMakeBuildStep 186 | true 187 | 188 | false 189 | true 190 | true 191 | 192 | 193 | true 194 | Qt4ProjectManager.MakeStep 195 | 196 | false 197 | 198 | 199 | false 200 | 201 | 2 202 | Build 203 | Build 204 | ProjectExplorer.BuildSteps.Build 205 | 206 | 207 | 208 | true 209 | Qt4ProjectManager.MakeStep 210 | 211 | true 212 | clean 213 | 214 | false 215 | 216 | 1 217 | Clean 218 | Clean 219 | ProjectExplorer.BuildSteps.Clean 220 | 221 | 2 222 | false 223 | 224 | Profile 225 | Qt4ProjectManager.Qt4BuildConfiguration 226 | 0 227 | 228 | 3 229 | 230 | 231 | 0 232 | Deploy 233 | Deploy 234 | ProjectExplorer.BuildSteps.Deploy 235 | 236 | 1 237 | ProjectExplorer.DefaultDeployConfiguration 238 | 239 | 1 240 | 241 | 242 | dwarf 243 | 244 | cpu-cycles 245 | 246 | 247 | 250 248 | 249 | -e 250 | cpu-cycles 251 | --call-graph 252 | dwarf,4096 253 | -F 254 | 250 255 | 256 | -F 257 | true 258 | 4096 259 | false 260 | false 261 | 1000 262 | 263 | true 264 | 265 | false 266 | false 267 | false 268 | false 269 | true 270 | 0.01 271 | 10 272 | true 273 | kcachegrind 274 | 1 275 | 25 276 | 277 | 1 278 | true 279 | false 280 | true 281 | valgrind 282 | 283 | 0 284 | 1 285 | 2 286 | 3 287 | 4 288 | 5 289 | 6 290 | 7 291 | 8 292 | 9 293 | 10 294 | 11 295 | 12 296 | 13 297 | 14 298 | 299 | 2 300 | 301 | Qt4ProjectManager.Qt4RunConfiguration:C:/QTprojects/can_usb/can_usb.pro 302 | C:/QTprojects/can_usb/can_usb.pro 303 | 304 | false 305 | 306 | false 307 | true 308 | true 309 | false 310 | false 311 | true 312 | 313 | C:/QTprojects/build-can_usb-Desktop_Qt_5_14_2_MSVC2017_32bit-Release 314 | 315 | 1 316 | 317 | 318 | 319 | ProjectExplorer.Project.Target.1 320 | 321 | Desktop Qt 5.14.2 MSVC2017 64bit 322 | Desktop Qt 5.14.2 MSVC2017 64bit 323 | qt.qt5.5142.win64_msvc2017_64_kit 324 | 1 325 | 0 326 | 0 327 | 328 | C:/QTprojects/build-can_usb-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug 329 | 330 | 331 | true 332 | QtProjectManager.QMakeBuildStep 333 | true 334 | 335 | false 336 | false 337 | false 338 | 339 | 340 | true 341 | Qt4ProjectManager.MakeStep 342 | 343 | false 344 | 345 | 346 | false 347 | 348 | 2 349 | Build 350 | Build 351 | ProjectExplorer.BuildSteps.Build 352 | 353 | 354 | 355 | true 356 | Qt4ProjectManager.MakeStep 357 | 358 | true 359 | clean 360 | 361 | false 362 | 363 | 1 364 | Clean 365 | Clean 366 | ProjectExplorer.BuildSteps.Clean 367 | 368 | 2 369 | false 370 | 371 | Debug 372 | Qt4ProjectManager.Qt4BuildConfiguration 373 | 2 374 | 375 | 376 | C:/QTprojects/build-can_usb-Desktop_Qt_5_14_2_MSVC2017_64bit-Release 377 | 378 | 379 | true 380 | QtProjectManager.QMakeBuildStep 381 | false 382 | 383 | false 384 | false 385 | true 386 | 387 | 388 | true 389 | Qt4ProjectManager.MakeStep 390 | 391 | false 392 | 393 | 394 | false 395 | 396 | 2 397 | Build 398 | Build 399 | ProjectExplorer.BuildSteps.Build 400 | 401 | 402 | 403 | true 404 | Qt4ProjectManager.MakeStep 405 | 406 | true 407 | clean 408 | 409 | false 410 | 411 | 1 412 | Clean 413 | Clean 414 | ProjectExplorer.BuildSteps.Clean 415 | 416 | 2 417 | false 418 | 419 | Release 420 | Qt4ProjectManager.Qt4BuildConfiguration 421 | 0 422 | 423 | 424 | C:/QTprojects/build-can_usb-Desktop_Qt_5_14_2_MSVC2017_64bit-Profile 425 | 426 | 427 | true 428 | QtProjectManager.QMakeBuildStep 429 | true 430 | 431 | false 432 | true 433 | true 434 | 435 | 436 | true 437 | Qt4ProjectManager.MakeStep 438 | 439 | false 440 | 441 | 442 | false 443 | 444 | 2 445 | Build 446 | Build 447 | ProjectExplorer.BuildSteps.Build 448 | 449 | 450 | 451 | true 452 | Qt4ProjectManager.MakeStep 453 | 454 | true 455 | clean 456 | 457 | false 458 | 459 | 1 460 | Clean 461 | Clean 462 | ProjectExplorer.BuildSteps.Clean 463 | 464 | 2 465 | false 466 | 467 | Profile 468 | Qt4ProjectManager.Qt4BuildConfiguration 469 | 0 470 | 471 | 3 472 | 473 | 474 | 0 475 | Deploy 476 | Deploy 477 | ProjectExplorer.BuildSteps.Deploy 478 | 479 | 1 480 | ProjectExplorer.DefaultDeployConfiguration 481 | 482 | 1 483 | 484 | 485 | dwarf 486 | 487 | cpu-cycles 488 | 489 | 490 | 250 491 | 492 | -e 493 | cpu-cycles 494 | --call-graph 495 | dwarf,4096 496 | -F 497 | 250 498 | 499 | -F 500 | true 501 | 4096 502 | false 503 | false 504 | 1000 505 | 506 | true 507 | 508 | false 509 | false 510 | false 511 | false 512 | true 513 | 0.01 514 | 10 515 | true 516 | kcachegrind 517 | 1 518 | 25 519 | 520 | 1 521 | true 522 | false 523 | true 524 | valgrind 525 | 526 | 0 527 | 1 528 | 2 529 | 3 530 | 4 531 | 5 532 | 6 533 | 7 534 | 8 535 | 9 536 | 10 537 | 11 538 | 12 539 | 13 540 | 14 541 | 542 | 2 543 | 544 | Qt4ProjectManager.Qt4RunConfiguration:C:/QTprojects/can_usb/can_usb.pro 545 | C:/QTprojects/can_usb/can_usb.pro 546 | 547 | false 548 | 549 | false 550 | true 551 | true 552 | false 553 | false 554 | true 555 | 556 | 557 | 558 | 1 559 | 560 | 561 | 562 | ProjectExplorer.Project.TargetCount 563 | 2 564 | 565 | 566 | ProjectExplorer.Project.Updater.FileVersion 567 | 22 568 | 569 | 570 | Version 571 | 22 572 | 573 | 574 | -------------------------------------------------------------------------------- /canal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL interface DLL for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB to CAN bus converter 3 | * 4 | * Copyright (C) 2005-2023 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | //https://learn.microsoft.com/en-us/cpp/build/exporting-from-a-dll-using-declspec-dllexport?view=msvc-170 21 | //https://learn.microsoft.com/en-us/cpp/build/exporting-functions-from-a-dll-by-ordinal-rather-than-by-name?view=msvc-170 22 | //https://learn.microsoft.com/en-us/cpp/build/linking-an-executable-to-a-dll?view=msvc-170#determining-which-linking-method-to-use 23 | //https://learn.microsoft.com/en-us/cpp/build/run-time-library-behavior?view=msvc-170#initializing-a-dll 24 | //https://stackoverflow.com/questions/39330898/c-winapi-call-exported-function-via-getprocaddress 25 | 26 | #pragma once 27 | 28 | #ifdef WIN32 29 | #define DllExport __declspec(dllexport) 30 | #define WINAPI __stdcall 31 | #endif 32 | 33 | // Canal Levels 34 | #define CANAL_LEVEL_STANDARD 1 35 | #define CANAL_LEVEL_USES_TCPIP 2 36 | 37 | // VSCP Daemon client Open types 38 | #define CANAL_COMMAND_OPEN_VSCP_LEVEL1 1 // VSCP Level I channel (CAN) 39 | #define CANAL_COMMAND_OPEN_VSCP_LEVEL2 2 // VSCP Level II channel 40 | #define CANAL_COMMAND_OPEN_VSCP_CONTROL 3 // Daemon Control channel 41 | 42 | #define CANAL_MAIN_VERSION 1 43 | #define CANAL_MINOR_VERSION 0 44 | #define CANAL_SUB_VERSION 15 45 | 46 | #define CAN_MAX_STANDARD_ID 0x7ff 47 | #define CAN_MAX_EXTENDED_ID 0x1fffffff 48 | 49 | #define COMMAND_FAILURE (0) 50 | #define COMMAND_SUCCESS (1) 51 | #define PACKAGE_ACK (0) 52 | #define PACKAGE_NACK (1) 53 | #define PACKAGE_TIMEOUT (-1) 54 | #define PACKAGE_UNKNOWN (-1) 55 | #define PACKAGE_FAILURE (0) 56 | #define PACKAGE_SUCCESS (1) 57 | 58 | #define CANAL_NONBLOCK 1 59 | 60 | /// ID flags 61 | #define CANAL_IDFLAG_STANDARD 0x00000000 // Standard message id (11-bit) 62 | #define CANAL_IDFLAG_EXTENDED 0x00000001 // Extended message id (29-bit) 63 | #define CANAL_IDFLAG_RTR 0x00000002 // RTR-Frame 64 | #define CANAL_IDFLAG_STATUS 0x00000004 // This package is a status indication (id holds error code) 65 | #define CANAL_IDFLAG_SEND 0x80000000 // Reserved for use by application software to indicate send 66 | 67 | /// Communicaton speeds 68 | #define CANAL_BAUD_USER 0 // User specified (In CANAL i/f DLL). 69 | #define CANAL_BAUD_1000 1 // 1 Mbit 70 | #define CANAL_BAUD_800 2 // 800 Kbit 71 | #define CANAL_BAUD_500 3 // 500 Kbit 72 | #define CANAL_BAUD_250 4 // 250 Kbit 73 | #define CANAL_BAUD_125 5 // 125 Kbit 74 | #define CANAL_BAUD_100 6 // 100 Kbit 75 | #define CANAL_BAUD_50 7 // 50 Kbit 76 | #define CANAL_BAUD_20 8 // 20 Kbit 77 | #define CANAL_BAUD_10 9 // 10 Kbit 78 | 79 | /// Status message codes ( in received message ) 80 | #define CANAL_STATUSMSG_OK 0x00 // Normal condition. 81 | #define CANAL_STATUSMSG_OVERRUN 0x01 // Overrun occured when sending data to CAN bus. 82 | #define CANAL_STATUSMSG_BUSLIGHT 0x02 // Error counter has reached 96. 83 | #define CANAL_STATUSMSG_BUSHEAVY 0x03 // Error counter has reached 128. 84 | #define CANAL_STATUSMSG_BUSOFF 0x04 // Device is in BUSOFF. CANAL_STATUS_OK is 85 | // sent when returning to operational mode. 86 | #define CANAL_STATUSMSG_STUFF 0x20 // Stuff Error. 87 | #define CANAL_STATUSMSG_FORM 0x21 // Form Error. 88 | #define CANAL_STATUSMSG_ACK 0x23 // Ack Error. 89 | #define CANAL_STATUSMSG_BIT1 0x24 // Bit1 Error. 90 | #define CANAL_STATUSMSG_BIT0 0x25 // Bit0 Error. 91 | #define CANAL_STATUSMSG_CRC 0x27 // CRC Error. 92 | 93 | /// Status codes /returned by status request) 94 | #define CANAL_STATUS_NONE 0x00000000 95 | #define CANAL_STATUS_ACTIVE 0x10000000 96 | #define CANAL_STATUS_PASSIVE 0x40000000 97 | #define CANAL_STATUS_BUS_OFF 0x80000000 98 | #define CANAL_STATUS_BUS_WARN 0x20000000 99 | #define CANAL_STATUS_PHY_FAULT 0x08000000 100 | #define CANAL_STATUS_PHY_H 0x04000000 101 | #define CANAL_STATUS_PHY_L 0x02000000 102 | #define CANAL_STATUS_SLEEPING 0x01000000 103 | #define CANAL_STATUS_STOPPED 0x00800000 104 | #define CANAL_STATUS_RECIVE_BUFFER_FULL 0x00400000 // Drivers buffer 105 | #define CANAL_STATUS_TRANSMIT_BUFFER_FULL 0x00200000 // Drivers buffer 106 | 107 | /// Error Codes 108 | #define CANAL_ERROR_SUCCESS 0 // All is OK 109 | #define CANAL_ERROR_BAUDRATE 1 // Baudrate error 110 | #define CANAL_ERROR_BUS_OFF 2 // Bus off error 111 | #define CANAL_ERROR_BUS_PASSIVE 3 // Bus Passive error 112 | #define CANAL_ERROR_BUS_WARNING 4 // Bus warning error 113 | #define CANAL_ERROR_CAN_ID 5 // Invalid CAN ID 114 | #define CANAL_ERROR_CAN_MESSAGE 6 // Invalid CAN message 115 | #define CANAL_ERROR_CHANNEL 7 // Invalid channel 116 | #define CANAL_ERROR_FIFO_EMPTY 8 // FIFO is empty 117 | #define CANAL_ERROR_FIFO_FULL 9 // FIFI is full 118 | #define CANAL_ERROR_FIFO_SIZE 10 // FIFO size error 119 | #define CANAL_ERROR_FIFO_WAIT 11 120 | #define CANAL_ERROR_GENERIC 12 // Generic error 121 | #define CANAL_ERROR_HARDWARE 13 // Hardware error 122 | #define CANAL_ERROR_INIT_FAIL 14 // Initialization failed 123 | #define CANAL_ERROR_INIT_MISSING 15 124 | #define CANAL_ERROR_INIT_READY 16 125 | #define CANAL_ERROR_NOT_SUPPORTED 17 // Not supported 126 | #define CANAL_ERROR_OVERRUN 18 // Overrun 127 | #define CANAL_ERROR_RCV_EMPTY 19 // Receive buffer empty 128 | #define CANAL_ERROR_REGISTER 20 // Register value error 129 | #define CANAL_ERROR_TRM_FULL 21 130 | #define CANAL_ERROR_ERRFRM_STUFF 22 // Errorframe: stuff error detected 131 | #define CANAL_ERROR_ERRFRM_FORM 23 // Errorframe: form error detected 132 | #define CANAL_ERROR_ERRFRM_ACK 24 // Errorframe: acknowledge error 133 | #define CANAL_ERROR_ERRFRM_BIT1 25 // Errorframe: bit 1 error 134 | #define CANAL_ERROR_ERRFRM_BIT0 26 // Errorframe: bit 0 error 135 | #define CANAL_ERROR_ERRFRM_CRC 27 // Errorframe: CRC error 136 | #define CANAL_ERROR_LIBRARY 28 // Unable to load library 137 | #define CANAL_ERROR_PROCADDRESS 29 // Unable get library proc address 138 | #define CANAL_ERROR_ONLY_ONE_INSTANCE 30 // Only one instance allowed 139 | #define CANAL_ERROR_SUB_DRIVER 31 // Problem with sub driver call 140 | #define CANAL_ERROR_TIMEOUT 32 // Blocking call timeout 141 | #define CANAL_ERROR_NOT_OPEN 33 // The device is not open. 142 | #define CANAL_ERROR_PARAMETER 34 // A parameter is invalid. 143 | #define CANAL_ERROR_MEMORY 35 // Memory exhausted. 144 | #define CANAL_ERROR_INTERNAL 36 // Some kind of internal program error 145 | #define CANAL_ERROR_COMMUNICATION 37 // Some kind of communication error 146 | #define CANAL_ERROR_USER 38 // Login error 147 | 148 | // CANAL commands sent over the pipe interface (depricated) 149 | #define CANAL_COMMAND_NOOP 0 // No command 150 | #define CANAL_COMMAND_OPEN 1 // Open channel 151 | #define CANAL_COMMAND_CLOSE 2 // Close channel 152 | #define CANAL_COMMAND_SEND 3 // Send message 153 | #define CANAL_COMMAND_RECEIVE 4 // Receive message 154 | #define CANAL_COMMAND_CHECKDATA 5 // Check if data is available 155 | #define CANAL_COMMAND_BAUDRATE 6 // Set Baudrate 156 | #define CANAL_COMMAND_STATUS 7 // Get status 157 | #define CANAL_COMMAND_STATISTICS 8 // Get statistics 158 | #define CANAL_COMMAND_FILTER 9 // Set filter 159 | #define CANAL_COMMAND_MASK 10 // Set mask 160 | #define CANAL_COMMAND_VERSION 11 // CANAL version 161 | #define CANAL_COMMAND_DLL_VERSION 12 // CANAL DLL version 162 | #define CANAL_COMMAND_VENDOR_STRING 13 // CANAL vendor string 163 | #define CANAL_COMMAND_LEVEL 14 // CANAL Level bitarray 164 | 165 | // CANAL responses sent over the pipe interface (depricated) 166 | #define CANAL_RESPONSE_NONE 0 // 167 | #define CANAL_RESPONSE_SUCCESS 1 // OK message 168 | #define CANAL_RESPONSE_ERROR 2 // ERROR message 169 | #define CANAL_RESPONSE_MESSAGE 3 // Response to read 170 | 171 | // CANAL error codes sent over the client interface 172 | // on error responses 173 | #define CANAL_IFERROR_GENERAL 128 // General error 174 | #define CANAL_IFERROR_UNKNOWN_COMMAND 129 175 | #define CANAL_IFERROR_CHANNEL_OPEN 130 176 | #define CANAL_IFERROR_CHANNEL_CLOSED 131 177 | #define CANAL_IFERROR_SEND_SUCCESS 132 178 | #define CANAL_IFERROR_SEND_MSG_ALLOCATON 133 179 | #define CANAL_IFERROR_BUFFER_EMPTY 134 180 | #define CANAL_IFERROR_BUFFER_FULL 135 181 | #define CANAL_IFERROR_READ_FAILURE 136 182 | #define CANAL_IFERROR_SEND_STORAGE 137 183 | 184 | // * * * TCP/IP FAST mode interface constants 185 | 186 | // FAST mode primary states 187 | #define CANAL_BINARY_FRAME_TYPE_VSCP 0 // VSCP event 188 | #define CANAL_BINARY_FRAME_TYPE_ERROR 1 // ACK/NACK/errors 189 | #define CANAL_BINARY_FRAME_TYPE_COMMAND 2 // Command frame 190 | #define CANAL_BINARY_FRAME_TYPE_CAN 3 // CAN Frame 191 | 192 | #define CANAL_BINARY_COMMAND_NOOP 0 // No operation 193 | #define CANAL_BINARY_COMMAND_READ 1 // Read one frame 194 | #define CANAL_BINARY_COMMAND_CLOSE 2 // Close communication channel 195 | 196 | // FAST error codes 197 | #define CANAL_BINARY_ERROR_NONE 0 // OK 198 | #define CANAL_BINARY_ERROR_GENERAL 1 // General error 199 | #define CANAL_BINARY_ERROR_TO_SMALL 2 // Packet smaller then min packet 200 | #define CANAL_BINARY_ERROR_FORMAT 3 // Packet have bad format 201 | #define CANAL_BINARY_ERROR_UNKNOW_FRAME 4 // Unknown frame type 202 | #define CANAL_BINARY_ERROR_MEMORY 5 // No room for event 203 | #define CANAL_BINARY_ERROR_NO_DATA 6 // No data available 204 | #define CANAL_BINARY_ERROR_INVALID_CMD 7 // Command not recognized. 205 | 206 | // Filter mask settings 207 | #define CANUSB_ACCEPTANCE_FILTER_ALL 0x00000000 208 | #define CANUSB_ACCEPTANCE_MASK_ALL 0xFFFFFFFF 209 | 210 | #define CANAL_DEVLIST_SIZE_MAX 64 211 | 212 | typedef struct struct_CANAL_DEV_INFO { 213 | unsigned int DeviceId; 214 | unsigned int vid; 215 | unsigned int pid; 216 | char SerialNumber[10]; 217 | } canal_dev_info, *pcanal_dev_info; 218 | 219 | typedef struct struct_CANAL_DEV_LIST{ 220 | canal_dev_info canDevInfo[CANAL_DEVLIST_SIZE_MAX]; 221 | unsigned int canDevCount; 222 | } canal_dev_list, *pcanal_dev_list; 223 | 224 | /** @name CanalMsg 225 | * @brief CANAL CAN message structure 226 | */ 227 | 228 | typedef struct structCanalMsg { 229 | unsigned long flags; // CAN message flags 230 | unsigned long obid; // Used by driver for channel info etc. 231 | unsigned long id; // CAN id (11-bit or 29-bit) 232 | unsigned char sizeData; // Data size 0-8 233 | unsigned char data[8]; // CAN Data 234 | unsigned long timestamp; // Relative time stamp for package in microseconds 235 | } canalMsg; 236 | typedef canalMsg* PCANALMSG; 237 | 238 | /** @name CanalStatistics 239 | * @brief CANAL statistics structure 240 | */ 241 | typedef struct structCanalStatistics { 242 | unsigned long cntReceiveFrames; // # of receive frames 243 | unsigned long cntTransmitFrames; // # of transmitted frames 244 | unsigned long cntReceiveData; // # of received data bytes 245 | unsigned long cntTransmitData; // # of transmitted data bytes 246 | unsigned long cntOverruns; // # of overruns 247 | unsigned long cntBusWarnings; // # of bys warnings 248 | unsigned long cntBusOff; // # of bus off's 249 | } canalStatistics; 250 | typedef canalStatistics* PCANALSTATISTICS; 251 | 252 | /** @name CanalStatus 253 | * @brief CANAL status structure 254 | */ 255 | typedef struct structCanalStatus { 256 | unsigned long channel_status; // Current state for channel 257 | unsigned long lasterrorcode; // Last error code 258 | unsigned long lasterrorsubcode; // Last error subcode 259 | char lasterrorstr[80]; // Last error string 260 | } canalStatus; 261 | typedef canalStatus* PCANALSTATUS; 262 | 263 | /** @name CANHANDLE 264 | * @brief CAN driver open handle 265 | */ 266 | typedef long CANHANDLE; 267 | 268 | #ifdef __cplusplus 269 | extern "C" { 270 | #endif 271 | 272 | /** @name CanalOpen 273 | @brief CAN driver open handle. 274 | @param pDevice Physical device to connect to. 275 | @param flags Give extra info to the CANAL i/F. 276 | @return Handle of device or -1 if error. 277 | */ 278 | DllExport long WINAPI CanalOpen(const char *pDevice, unsigned long flags); 279 | 280 | /** @name CanalClose 281 | @brief Close a CANAL chanel. 282 | @param handle Handle to close physical CANAL channel. 283 | @return zero on success or error-code on failure. 284 | */ 285 | DllExport long WINAPI CanalClose(long handle); 286 | 287 | /** @name CanalGetLevel 288 | @brief 289 | @param handle Handle to close physical CANAL channel. 290 | @return 291 | */ 292 | DllExport long WINAPI CanalGetLevel(long handle); 293 | 294 | /** 295 | @name CanalSend 296 | @brief Send a message on a CANAL channel 297 | @param handle - Handle to open physical CANAL channel. 298 | @param pCanMsg - Message to send. 299 | @return zero on success or error-code on failure. 300 | */ 301 | DllExport int WINAPI CanalSend(long handle, PCANALMSG pCanalMsg); 302 | 303 | /** 304 | @name CanalBlockingSend 305 | @brief Send a message on a CANAL channel 306 | @param handle - Handle to open physical CANAL channel. 307 | @param pCanMsg - Message to send. 308 | @param @param timeout - Timeout in ms. 0 is forever. 309 | @return zero on success or error-code on failure. 310 | */ 311 | DllExport int WINAPI CanalBlockingSend(long handle, PCANALMSG pCanalMsg, unsigned long timeout); 312 | 313 | /** 314 | @name CanalSend 315 | @brief Receive a message from a CANAL channel 316 | @param handle - Handle to open physical CANAL channel. 317 | @param pCanMsg - Message to receive. 318 | @return zero on success or error-code on failure. 319 | */ 320 | DllExport int WINAPI CanalReceive(long handle, PCANALMSG pCanalMsg); 321 | 322 | /** 323 | @name CanalBlockingSend 324 | @brief Receive a message from a CANAL channel 325 | @param handle - Handle to open physical CANAL channel. 326 | @param pCanMsg - Message to receive. 327 | @param @param timeout - Timeout in ms. 0 is forever. 328 | @return zero on success or error-code on failure. 329 | */ 330 | DllExport int WINAPI CanalBlockingReceive(long handle, PCANALMSG pCanalMsg, unsigned long timeout); 331 | 332 | /** 333 | @name CanalDataAvailable 334 | @brief Check a CANAL channel for message availability 335 | @param handle - Handle to open physical CANAL channel. 336 | @return Zero if no message is available or the number of messages is 337 | there are messages waiting to be received. 338 | */ 339 | DllExport int WINAPI CanalDataAvailable(long handle); 340 | 341 | /** 342 | @name CanalGetStatus 343 | @brief Get status for a CANAL channel. 344 | @param handle - Handle to open physical CANAL channel. 345 | @param pCanStatus Pointer to a CANAL status structure. 346 | @param zero on success or error-code on failure. 347 | */ 348 | DllExport int WINAPI CanalGetStatus(long handle, PCANALSTATUS pCanalStatus); 349 | 350 | /** 351 | @name CanalGetStatistics 352 | @brief Get statistics for a CANAL channel. 353 | @param handle - Handle to open physical CANAL channel. 354 | @param pCanStatus Pointer to a CANAL status structure. 355 | @param zero on success or error-code on failure. 356 | */ 357 | DllExport int WINAPI CanalGetStatistics(long handle, PCANALSTATISTICS pCanalStatistics); 358 | 359 | /** 360 | @name CanalSetFilter 361 | @brief Set the filter for a CANAL channel. 362 | @param handle - Handle to open physical CANAL channel. 363 | @param filter 364 | @param zero on success or error-code on failure. 365 | */ 366 | DllExport int WINAPI CanalSetFilter(long handle, unsigned long filter); 367 | 368 | /** 369 | @name CanalSetMask 370 | @brief Set the mask for a CANAL channel. 371 | @param handle - Handle to open physical CANAL channel. 372 | @param filter 373 | @param zero on success or error-code on failure. 374 | */ 375 | DllExport int WINAPI CanalSetMask(long handle, unsigned long mask); 376 | 377 | /** 378 | @name CanalSetBaudrate 379 | @brief Set the baudrate for a CANAL channel. 380 | @param handle - Handle to open physical CANAL channel. 381 | @param baudrate Baudrate for the channel 382 | @param zero on success or error-code on failure. 383 | */ 384 | DllExport int WINAPI CanalSetBaudrate(long handle, unsigned long baudrate); 385 | 386 | /** 387 | @name CanalGetVersion 388 | @brief Get CANAL version. 389 | @return version for CANAL i/f. 390 | */ 391 | DllExport unsigned long WINAPI CanalGetVersion(void); 392 | 393 | /** 394 | @name CanalGetDllVersion 395 | @brief Get CANAL DLL version. 396 | @return version for CANAL dll implemention. 397 | */ 398 | DllExport unsigned long WINAPI CanalGetDllVersion(void); 399 | 400 | /** 401 | @name CanalGetDriverInfo 402 | @brief Get CANAL driver properties. 403 | @return driver info string. 404 | */ 405 | DllExport const char* WINAPI CanalGetVendorString(void); 406 | 407 | /** 408 | @name CanalGetDriverInfo 409 | @brief Get CANAL vendor string. 410 | @return vendor string. 411 | */ 412 | DllExport const char* WINAPI CanalGetDriverInfo(void); 413 | 414 | /************************************************************* 415 | * EXTENDED NON STANDARD API LIST 416 | */ 417 | 418 | /* FILTER req type */ 419 | typedef enum { 420 | FILTER_ACCEPT_ALL = 0, 421 | FILTER_REJECT_ALL, 422 | FILTER_VALUE, 423 | }Filter_Type_TypeDef; 424 | 425 | /*! 426 | Set the 11bit filter ID, Mask for a CANAL channel 427 | 428 | @param handle Handle to open physical CANAL channel. 429 | @return zero on success or error-code on failure. 430 | */ 431 | 432 | DllExport int WINAPI CanalSetFilter11bit( long handle, Filter_Type_TypeDef type, unsigned long list, unsigned long mask ); 433 | 434 | /*! 435 | Set the 29bit filter ID, Mask for a CANAL channel 436 | 437 | @param handle Handle to open physical CANAL channel. 438 | @return zero on success or error-code on failure. 439 | */ 440 | DllExport int WINAPI CanalSetFilter29bit( long handle, Filter_Type_TypeDef type, unsigned long list, unsigned long mask ); 441 | 442 | /*! 443 | Get bootloader ver 444 | 445 | @param handle Handle to open physical CANAL channel. 446 | @return zero on success or error-code on failure. 447 | */ 448 | DllExport int WINAPI CanalGetBootloaderVersion(long handle, unsigned long* bootloader_version); 449 | 450 | DllExport int WINAPI CanalGetHardwareVersion(long handle, unsigned long* hardware_version); 451 | DllExport int WINAPI CanalGetFirmwareVersion(long handle, unsigned long* firmware_version); 452 | DllExport int WINAPI CanalGetSerialNumber(long handle, unsigned long* serial); 453 | DllExport int WINAPI CanalGetVidPid(long handle, unsigned long* vidpid); 454 | DllExport int WINAPI CanalGetDeviceId(long handle, unsigned long* deviceid); 455 | DllExport int WINAPI CanalGetVendor(long handle, unsigned int size, char* vendor); 456 | DllExport int WINAPI CanalInterfaceStart(long handle); 457 | DllExport int WINAPI CanalInterfaceStop(long handle); 458 | DllExport int WINAPI CanalGetDeviceList(pcanal_dev_list canalDeviceList, int canalDeviceListSize); 459 | 460 | #ifdef __cplusplus 461 | } 462 | #endif 463 | 464 | //DWORD WINAPI ReadThread(LPVOID lParam); 465 | -------------------------------------------------------------------------------- /canal_macro.h: -------------------------------------------------------------------------------- 1 | // udpReceiveThread.cpp 2 | // 3 | // This program is free software; you can redistribute it and/or 4 | // modify it under the terms of the GNU General Public License 5 | // as published by the Free Software Foundation; either version 6 | // 2 of the License, or (at your option) any later version. 7 | // 8 | // This file is part of the VSCP (http://can.sourceforge.net) 9 | // 10 | // Copyright (C) 2000-2008 Ake Hedman, D of Scandinavia, 11 | // 12 | // This file 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 this file see the file COPYING. If not, write to 19 | // the Free Software Foundation, 59 Temple Place - Suite 330, 20 | // Boston, MA 02111-1307, USA. 21 | // 22 | // $RCSfile: canal_macro.h,v $ 23 | // $Date: 2005/01/05 12:16:09 $ 24 | // $Author: akhe $ 25 | // $Revision: 1.4 $ 26 | 27 | #ifdef WIN32 28 | 29 | #define LOCK_MUTEX( x ) ( WaitForSingleObject( x, INFINITE ) ) 30 | #define UNLOCK_MUTEX( x ) ( ReleaseMutex( x ) ) 31 | #define SLEEP( x ) ( Sleep( x ) ) 32 | #define SYSLOG( a, b ) ( wxLogError( b ) ) 33 | #define BZERO( a ) ( memset( ( _u8* )&a, 0, sizeof( a ) ) ) 34 | 35 | #else 36 | 37 | #define LOCK_MUTEX( x ) ( pthread_mutex_lock( &x ) ) 38 | #define UNLOCK_MUTEX( x ) ( pthread_mutex_unlock( &x ) ) 39 | #define SLEEP( x ) ( usleep( ( 1000 * x ) ) ) 40 | #define SYSLOG( a, b ) ( syslog( a, b ) ) 41 | #define BZERO( a ) ( bzero( ( _u8* )&a, sizeof( a ) ) ) 42 | 43 | #endif 44 | 45 | 46 | #define MAX( a, b ) ( ( (a) > (b) ) ? (a) : (b) ) 47 | #define MIN( a, b ) ( ( (a) < (b) ) ? (a) : (b) ) 48 | #define ABS( a ) (( (int) (a) < 0 ) ? ((a) ^ 0xffffffff) + 1 : (a) ) 49 | 50 | -------------------------------------------------------------------------------- /dialogabout.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #include "dialogabout.h" 21 | #include "ui_dialogabout.h" 22 | 23 | DialogAbout::DialogAbout(QWidget *parent) : 24 | QDialog(parent), 25 | ui(new Ui::DialogAbout) 26 | { 27 | ui->setupUi(this); 28 | } 29 | 30 | DialogAbout::~DialogAbout() 31 | { 32 | delete ui; 33 | } 34 | 35 | void DialogAbout::on_pushButton_clicked() 36 | { 37 | close(); 38 | } 39 | -------------------------------------------------------------------------------- /dialogabout.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #ifndef DIALOGABOUT_H 21 | #define DIALOGABOUT_H 22 | 23 | #include 24 | 25 | namespace Ui { 26 | class DialogAbout; 27 | } 28 | 29 | class DialogAbout : public QDialog 30 | { 31 | Q_OBJECT 32 | 33 | public: 34 | explicit DialogAbout(QWidget *parent = nullptr); 35 | ~DialogAbout(); 36 | 37 | private slots: 38 | void on_pushButton_clicked(); 39 | 40 | private: 41 | Ui::DialogAbout *ui; 42 | }; 43 | 44 | #endif // DIALOGABOUT_H 45 | -------------------------------------------------------------------------------- /dialogabout.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | DialogAbout 4 | 5 | 6 | 7 | 0 8 | 0 9 | 259 10 | 200 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | Qt::ImhNone 18 | 19 | 20 | 21 | 22 | 160 23 | 170 24 | 80 25 | 22 26 | 27 | 28 | 29 | Ok 30 | 31 | 32 | 33 | 34 | 35 | 0 36 | 0 37 | 261 38 | 161 39 | 40 | 41 | 42 | 43 | 44 | CANAL view 1.0.8 64bit version 45 | 46 | licensed under GPL 3.0 license 47 | ©RUSOKU Technologies Ltd 48 | e-mail: info@rusoku.com 49 | web: www.rusoku.com 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /dialoghelp.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Dialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 568 10 | 378 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 0 20 | 0 21 | 561 22 | 331 23 | 24 | 25 | 26 | 27 | Init string parameters: 28 | 29 | 1 2 4 5 6 7 8 30 | 0 ; device_serial_number ; speed ; tseg1 ; tseg2 ; sjw ; brp 31 | 32 | where: 33 | 1 - device type: for "TouCAN", "TouCAN Marine", "TouCAN Duo" this parameter always == "0" 34 | 2 - device serial number: always 8 symbols like "12345678" 35 | 3 - CAN interface speed: standard speeds: 10;20;50;100;125;250;500;1000 36 | 4 - CAN bus parameter "tseg1" 37 | 5 - CAN bus parameter "tseg2" 38 | 6 - CAN bus parameter "sjw" 39 | 7 - CAN bus parameter "brp" 40 | 41 | If standard speed list is used next arguments can be skipped. 42 | For example init string will looks like "0; 12345678; 1000" 43 | 44 | For non standard CAN bus speeds: "speed" parameter must be = "0" 45 | For example 1000 mbit speed init string will looks like: "0;12345678;0;7;2;2;5" 46 | CAN interface clock is : 100MHz 47 | 48 | 49 | 50 | 51 | 52 | 53 | 440 54 | 340 55 | 80 56 | 22 57 | 58 | 59 | 60 | Ok 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /dialoginitstring.cpp: -------------------------------------------------------------------------------- 1 | #include "dialoginitstring.h" 2 | #include "ui_dialoginitstring.h" 3 | 4 | DialogInitString::DialogInitString(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::DialogInitString) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | DialogInitString::~DialogInitString() 12 | { 13 | delete ui; 14 | } 15 | 16 | void DialogInitString::on_pushButton_clicked() 17 | { 18 | close(); 19 | } 20 | -------------------------------------------------------------------------------- /dialoginitstring.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOGINITSTRING_H 2 | #define DIALOGINITSTRING_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class DialogInitString; 8 | } 9 | 10 | class DialogInitString : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit DialogInitString(QWidget *parent = nullptr); 16 | ~DialogInitString(); 17 | 18 | private slots: 19 | void on_pushButton_clicked(); 20 | 21 | private: 22 | Ui::DialogInitString *ui; 23 | }; 24 | 25 | #endif // DIALOGINITSTRING_H 26 | -------------------------------------------------------------------------------- /dialoginitstring.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | DialogInitString 4 | 5 | 6 | 7 | 0 8 | 0 9 | 556 10 | 442 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 440 20 | 410 21 | 80 22 | 22 23 | 24 | 25 | 26 | Ok 27 | 28 | 29 | 30 | 31 | 32 | 0 33 | 0 34 | 561 35 | 401 36 | 37 | 38 | 39 | 40 | Init string parameters: 41 | 42 | 1 2 3 4 5 6 7 43 | device_type ; device_serial_number ; speed ; tseg1 ; tseg2 ; sjw ; brp 44 | 45 | where: 46 | 1 - device type: for "TouCAN", "TouCAN Marine", "TouCAN Duo" this parameter always == "0" 47 | 2 - device serial number: always 8 symbols like "12345678" 48 | serial number you can find on bottom device case side like "sn:12345678" 49 | 3 - CAN bus speed: standard speed list: 10;20;50;100;125;250;500;1000 50 | 4 - CAN bus parameter "tseg1" 51 | 5 - CAN bus parameter "tseg2" 52 | 6 - CAN bus parameter "sjw" 53 | 7 - CAN bus parameter "brp" 54 | 55 | If standard speed list is used next arguments can be skipped. 56 | For example init string will looks like "0; 12345678; 1000" 57 | 58 | For non standard CAN bus speeds: "speed" parameter must be == "0" 59 | For example 1000 kbit speed init string will looks like: "0;12345678;0;7;2;2;5" 60 | where: tseg1 = 7, tseg2 = 2, sjw = 2, brp = 5 61 | CAN interface clock is : 50MHz 62 | 63 | CAN bus parameters calculator: http://www.bittiming.can-wiki.info 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rusoku/CANAL-View/f1c9d3c5826059f54d98f3535f2f295f545af478/icon.ico -------------------------------------------------------------------------------- /img/Rusoku_Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rusoku/CANAL-View/f1c9d3c5826059f54d98f3535f2f295f545af478/img/Rusoku_Icon.png -------------------------------------------------------------------------------- /img/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rusoku/CANAL-View/f1c9d3c5826059f54d98f3535f2f295f545af478/img/icon.ico -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | 21 | #include "mainwindow.h" 22 | #include "canal.h" 23 | #include 24 | #include 25 | #include 26 | 27 | int main(int argc, char *argv[]) 28 | { 29 | QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 30 | //QApplication::setStyle(QStyleFactory::create("Fusion")); 31 | qRegisterMetaType("canalMsg"); 32 | 33 | QApplication app(argc, argv); 34 | app.setWindowIcon(QIcon(":/resources/img/Rusoku_Icon.png")); 35 | app.setStyle("fusion"); 36 | 37 | QApplication::setOrganizationDomain("RUSOKU Technologies"); 38 | QApplication::setApplicationName("CANAL View"); 39 | 40 | MainWindow w(0); 41 | w.show(); 42 | 43 | return app.exec(); 44 | } 45 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #include "mainwindow.h" 21 | #include "ui_mainwindow.h" 22 | #include "dialogabout.h" 23 | #include "canal.h" 24 | //#include "rxworkerthread.h" 25 | #include "QValidator" 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | MainWindow::MainWindow(QWidget *parent) : 37 | QMainWindow(parent), 38 | ui(new Ui::MainWindow) 39 | { 40 | ui->setupUi(this); 41 | 42 | QString str; 43 | 44 | m_bOpen = false; 45 | m_bRun = false; 46 | 47 | // Rx CANAL Thread 48 | countRunning = false; 49 | infiniteCountRunning = false; 50 | RxMsgCnt = 0; 51 | TxMsgCnt = 0; 52 | 53 | m_TxMsgList = new QVector; 54 | 55 | // TxMsg data[] init 56 | for(int x=0; x<8; x++) 57 | m_TxMsg.msg.data[x] = 0; 58 | 59 | loadSettings(); 60 | WidgetValuesInit(); 61 | 62 | // TIMERS 63 | timerStatus = new QTimer(this); 64 | connect(timerStatus, &QTimer::timeout,this, &MainWindow::statusTimerTimeout); 65 | //timerStatistics = new QTimer; 66 | //connect(timerStatistics, &QTimer::timeout,this, &MainWindow::statisticsTimerTimeout); 67 | //connect(RxTableModel, &QAbstractTableModel::dataChanged, AnalyzerTableModel, &AnalyzerFrameTable::on_doAnalyze); 68 | //connect(ui->RxMsgTableView-> 69 | 70 | } 71 | 72 | MainWindow::~MainWindow() 73 | { 74 | saveSettings(); 75 | 76 | // stop Threads 77 | stopRxThread(); 78 | 79 | // Status timer stop 80 | timerStatus->stop(); 81 | // Statistics timer stop 82 | //timerStatistics->stop(); 83 | 84 | CanalClose( m_drvHandle ); 85 | 86 | m_TxMsgList->clear(); 87 | m_TxMsgList->squeeze(); 88 | 89 | delete ui; 90 | } 91 | 92 | void MainWindow::on_openButton_clicked() 93 | { 94 | unsigned long openflags = 0; 95 | QString str; 96 | 97 | openflags = ((ui->cb_SilentMode->isChecked()) ? 1 : 0 ) | 98 | ((ui->cb_LoopbackMode->isChecked()) ? 2 : 0 ) | 99 | ((ui->cb_DisRetransmition->isChecked()) ? 4 : 0 ) | 100 | ((ui->cb_WakeUpMode->isChecked()) ? 8 : 0 ) | 101 | ((ui->cb_AutoBusOff->isChecked()) ? 16: 0 ) | 102 | ((ui->cb_TimMode->isChecked()) ? 32: 0 ) | 103 | ((ui->cb_RxFifoLocked->isChecked()) ? 64: 0 ) | 104 | ((ui->cb_TxFifoPriority->isChecked()) ? 128: 0) | 105 | ((ui->cb_EnStatusMessage->isChecked()) ? 256: 0) | 106 | ((ui->cb_TimestampDelay->isChecked()) ? 512: 0); 107 | 108 | str = ui->le_OpenParameters->text(); 109 | //cstr = str.toStdString().c_str(); 110 | 111 | if(( m_drvHandle = CanalOpen(str.toStdString().c_str(),openflags)) <= 0) 112 | { 113 | QMessageBox::critical(this,"Error","failed to open USB-CAN interface"); 114 | m_bOpen = false; 115 | return; 116 | } 117 | 118 | WidgetValuesOpen(); 119 | 120 | // start Threads 121 | startRxThread(); 122 | 123 | // Status task let's go 124 | timerStatus->start(500); 125 | // Statistics task let's go 126 | //timerStatistics->start(500); 127 | 128 | m_bOpen = true; 129 | } 130 | 131 | //signals 132 | void MainWindow::on_closeButton_clicked() 133 | { 134 | // Status timer stop 135 | timerStatus->stop(); 136 | //Statistics timer stop 137 | //timerStatistics->stop(); 138 | 139 | // stop Threads 140 | stopRxThread(); 141 | // stopTxThread(); 142 | 143 | CanalClose( m_drvHandle ); 144 | m_bOpen = false; 145 | WidgetValuesClose(); 146 | } 147 | 148 | // led_data0 ====================== 149 | void MainWindow::on_le_data0_textChanged(const QString &arg1) 150 | { 151 | Q_UNUSED(arg1); 152 | //ui->le_data0->setCursorPosition(2); 153 | ui->le_data0->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 154 | } 155 | 156 | void MainWindow::on_le_data0_editingFinished() 157 | { 158 | QString str; 159 | bool convertOk; 160 | 161 | ui->le_data0->setStyleSheet(""); 162 | ui->le_data0->clearFocus(); 163 | str = ui->le_data0->text(); 164 | str.remove(0,2); 165 | m_TxMsg.msg.data[0] = (str.toUInt(&convertOk,16) & 0xFF); 166 | } 167 | 168 | void MainWindow::on_le_data1_textChanged(const QString &arg1) 169 | { 170 | Q_UNUSED(arg1); 171 | ui->le_data1->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 172 | } 173 | 174 | void MainWindow::on_le_data1_editingFinished() 175 | { 176 | QString str; 177 | bool convertOk; 178 | 179 | ui->le_data1->setStyleSheet(""); 180 | ui->le_data1->clearFocus(); 181 | str = ui->le_data1->text(); 182 | str.remove(0,2); 183 | m_TxMsg.msg.data[1] = (str.toUInt(&convertOk,16) & 0xFF); 184 | } 185 | 186 | void MainWindow::on_le_data2_textChanged(const QString &arg1) 187 | { 188 | Q_UNUSED(arg1); 189 | ui->le_data2->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 190 | } 191 | 192 | void MainWindow::on_le_data2_editingFinished() 193 | { 194 | QString str; 195 | bool convertOk; 196 | 197 | ui->le_data2->setStyleSheet(""); 198 | ui->le_data2->clearFocus(); 199 | str = ui->le_data2->text(); 200 | str.remove(0,2); 201 | m_TxMsg.msg.data[2] = (str.toUInt(&convertOk,16) & 0xFF); 202 | } 203 | 204 | void MainWindow::on_le_data3_textChanged(const QString &arg1) 205 | { 206 | Q_UNUSED(arg1); 207 | ui->le_data3->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 208 | } 209 | 210 | void MainWindow::on_le_data3_editingFinished() 211 | { 212 | QString str; 213 | bool convertOk; 214 | 215 | ui->le_data3->setStyleSheet(""); 216 | ui->le_data3->clearFocus(); 217 | str = ui->le_data3->text(); 218 | str.remove(0,2); 219 | m_TxMsg.msg.data[3] = (str.toUInt(&convertOk,16) & 0xFF); 220 | } 221 | 222 | void MainWindow::on_le_data4_textChanged(const QString &arg1) 223 | { 224 | Q_UNUSED(arg1); 225 | ui->le_data4->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 226 | } 227 | 228 | void MainWindow::on_le_data4_editingFinished() 229 | { 230 | QString str; 231 | bool convertOk; 232 | 233 | ui->le_data4->setStyleSheet(""); 234 | ui->le_data4->clearFocus(); 235 | str = ui->le_data4->text(); 236 | str.remove(0,2); 237 | m_TxMsg.msg.data[4] = (str.toUInt(&convertOk,16) & 0xFF); 238 | } 239 | 240 | 241 | void MainWindow::on_le_data5_textChanged(const QString &arg1) 242 | { 243 | Q_UNUSED(arg1); 244 | ui->le_data5->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 245 | } 246 | 247 | void MainWindow::on_le_data5_editingFinished() 248 | { 249 | QString str; 250 | bool convertOk; 251 | 252 | ui->le_data5->setStyleSheet(""); 253 | ui->le_data5->clearFocus(); 254 | str = ui->le_data5->text(); 255 | str.remove(0,2); 256 | m_TxMsg.msg.data[5] = (str.toUInt(&convertOk,16) & 0xFF); 257 | } 258 | 259 | 260 | void MainWindow::on_le_data6_textChanged(const QString &arg1) 261 | { 262 | Q_UNUSED(arg1); 263 | ui->le_data6->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 264 | } 265 | 266 | void MainWindow::on_le_data6_editingFinished() 267 | { 268 | QString str; 269 | bool convertOk; 270 | 271 | ui->le_data6->setStyleSheet(""); 272 | ui->le_data6->clearFocus(); 273 | str = ui->le_data6->text(); 274 | str.remove(0,2); 275 | m_TxMsg.msg.data[6] = (str.toUInt(&convertOk,16) & 0xFF); 276 | } 277 | 278 | 279 | 280 | void MainWindow::on_le_data7_textChanged(const QString &arg1) 281 | { 282 | Q_UNUSED(arg1); 283 | ui->le_data7->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 284 | } 285 | 286 | void MainWindow::on_le_data7_editingFinished() 287 | { 288 | QString str; 289 | bool convertOk; 290 | 291 | ui->le_data7->setStyleSheet(""); 292 | ui->le_data7->clearFocus(); 293 | str = ui->le_data7->text(); 294 | str.remove(0,2); 295 | m_TxMsg.msg.data[7] = (str.toUInt(&convertOk,16) & 0xFF); 296 | } 297 | 298 | void MainWindow::on_le_dlc_textChanged(const QString &arg1) 299 | { 300 | Q_UNUSED(arg1); 301 | ui->le_dlc->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 302 | } 303 | 304 | 305 | void MainWindow::on_le_dlc_editingFinished() 306 | { 307 | QString str; 308 | bool convertOk; 309 | 310 | ui->le_dlc->setStyleSheet(""); 311 | ui->le_dlc->clearFocus(); 312 | str = ui->le_dlc->text(); 313 | m_TxMsg.msg.sizeData = (str.toUInt(&convertOk,10) & 0xFF); 314 | } 315 | 316 | void MainWindow::on_le_txcount_textChanged(const QString &arg1) 317 | { 318 | Q_UNUSED(arg1); 319 | ui->le_txcount->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 320 | } 321 | 322 | 323 | void MainWindow::on_le_txcount_editingFinished() 324 | { 325 | QString str; 326 | //bool convertOk; 327 | 328 | ui->le_txcount->setStyleSheet(""); 329 | ui->le_txcount->clearFocus(); 330 | str = ui->le_txcount->text(); 331 | //m_TxMsg.sizeData = (str.toUInt(&convertOk,10) & 0xFF); 332 | } 333 | 334 | 335 | void MainWindow::on_le_msg_ID_textChanged(const QString &arg1) 336 | { 337 | Q_UNUSED(arg1); 338 | // ui->le_msg_ID->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 339 | } 340 | 341 | void MainWindow::on_le_msg_ID_editingFinished() 342 | { 343 | QString str; 344 | bool convertOk; 345 | //unsigned long tmp_long; 346 | 347 | ui->le_msg_ID->setStyleSheet(""); 348 | ui->le_msg_ID->clearFocus(); 349 | str = ui->le_msg_ID->text(); 350 | 351 | str.remove(0,2); 352 | m_TxMsg.msg.id = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 353 | 354 | if(ui->cb_msg_ext->isChecked()) 355 | { 356 | m_TxMsg.msg.flags = CANAL_IDFLAG_EXTENDED; 357 | } 358 | else 359 | { 360 | m_TxMsg.msg.flags = CANAL_IDFLAG_STANDARD; 361 | } 362 | 363 | if(ui->cb_msg_ext->isChecked()) 364 | { 365 | m_TxMsg.msg.flags |= CANAL_IDFLAG_RTR; 366 | } 367 | } 368 | 369 | void MainWindow::on_cb_msg_ext_stateChanged(int arg1) 370 | { 371 | Q_UNUSED(arg1); 372 | 373 | if(ui->cb_msg_ext->isChecked()) 374 | { 375 | ui->le_msg_ID->setMaxLength(10); 376 | ui->le_msg_ID->setInputMask("\\0\\x>BHHHHHHH"); 377 | ui->le_msg_ID->setText("0x00000000"); 378 | //ui->le_msg_ID->setCursorPosition(0); 379 | } 380 | else 381 | { 382 | ui->le_msg_ID->setMaxLength(5); 383 | ui->le_msg_ID->setInputMask("\\0\\x>9HH"); 384 | ui->le_msg_ID->setText("0x000"); 385 | //ui->le_msg_ID->setCursorPosition(0); 386 | } 387 | // ui->le_msg_ID->setFocus(); 388 | } 389 | 390 | void MainWindow::on_le_filter_id_11bit_textChanged(const QString &arg1) 391 | { 392 | Q_UNUSED(arg1); 393 | ui->le_filter_id_11bit->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 394 | } 395 | 396 | void MainWindow::on_le_filter_id_11bit_editingFinished() 397 | { 398 | QString str; 399 | bool convertOk; 400 | 401 | ui->le_filter_id_11bit->setStyleSheet(""); 402 | ui->le_filter_id_11bit->clearFocus(); 403 | str = ui->le_filter_id_11bit->text(); 404 | str.remove(0,2); 405 | filter_list_11bit = (str.toUInt(&convertOk,16) & 0x7FF); 406 | } 407 | 408 | void MainWindow::on_le_filter_mask_11bit_textChanged(const QString &arg1) 409 | { 410 | Q_UNUSED(arg1); 411 | ui->le_filter_mask_11bit->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 412 | } 413 | 414 | void MainWindow::on_le_filter_mask_11bit_editingFinished() 415 | { 416 | QString str; 417 | bool convertOk; 418 | 419 | ui->le_filter_mask_11bit->setStyleSheet(""); 420 | ui->le_filter_mask_11bit->clearFocus(); 421 | str = ui->le_filter_mask_11bit->text(); 422 | str.remove(0,2); 423 | filter_mask_11bit = (str.toUInt(&convertOk,16) & 0x7FF); 424 | } 425 | 426 | void MainWindow::on_le_filter_id_29bit_textChanged(const QString &arg1) 427 | { 428 | Q_UNUSED(arg1); 429 | ui->le_filter_id_29bit->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 430 | } 431 | 432 | void MainWindow::on_le_filter_id_29bit_editingFinished() 433 | { 434 | QString str; 435 | bool convertOk; 436 | 437 | ui->le_filter_id_29bit->setStyleSheet(""); 438 | ui->le_filter_id_29bit->clearFocus(); 439 | str = ui->le_filter_id_29bit->text(); 440 | str.remove(0,2); 441 | filter_list_29bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFFF); 442 | } 443 | 444 | void MainWindow::on_le_filter_mask_29bit_textChanged(const QString &arg1) 445 | { 446 | Q_UNUSED(arg1); 447 | ui->le_filter_mask_29bit->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 448 | } 449 | 450 | void MainWindow::on_le_filter_mask_29bit_editingFinished() 451 | { 452 | QString str; 453 | bool convertOk; 454 | 455 | ui->le_filter_mask_29bit->setStyleSheet(""); 456 | ui->le_filter_mask_29bit->clearFocus(); 457 | str = ui->le_filter_mask_29bit->text(); 458 | str.remove(0,2); 459 | filter_mask_29bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 460 | } 461 | 462 | void MainWindow::on_pb_filter_set_11bit_clicked() 463 | { 464 | QString str; 465 | bool convertOk; 466 | 467 | if(!m_bOpen) 468 | { 469 | QMessageBox::critical(this,"Error","CANAL is closed"); 470 | return; 471 | } 472 | 473 | if(ui->rb_filter_11bit_reject_all->isChecked()) 474 | { 475 | if(CanalSetFilter11bit(m_drvHandle, FILTER_REJECT_ALL, 0, 0) != CANAL_ERROR_SUCCESS) 476 | { 477 | QMessageBox::critical(this,"Error","CANAL communication error"); 478 | } 479 | else 480 | { 481 | //QMessageBox::information(this,"Information","Filter 11bit set up successfully"); 482 | } 483 | } 484 | else if (ui->rb_filter_11bit_accept_all->isChecked()) 485 | { 486 | if(CanalSetFilter11bit(m_drvHandle, FILTER_ACCEPT_ALL, 0, 0) != CANAL_ERROR_SUCCESS) 487 | { 488 | QMessageBox::critical(this,"Error","CANAL communication error"); 489 | } 490 | else 491 | { 492 | //QMessageBox::information(this,"Information","Filter 11bit set up successfully"); 493 | } 494 | } 495 | else if(ui->rb_filter_11bit_list_mask->isChecked()) 496 | { 497 | str = ui->le_filter_id_11bit->text(); 498 | str.remove(0,2); 499 | filter_list_11bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 500 | 501 | str = ui->le_filter_mask_11bit->text(); 502 | str.remove(0,2); 503 | filter_mask_11bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 504 | 505 | if(CanalSetFilter11bit(m_drvHandle, FILTER_VALUE, filter_list_11bit, filter_mask_11bit) != CANAL_ERROR_SUCCESS) 506 | { 507 | QMessageBox::critical(this,"Error","CANAL communication error"); 508 | } 509 | else 510 | { 511 | //QMessageBox::information(this,"Information","Filter 11bit set up successfully"); 512 | } 513 | } 514 | } 515 | 516 | 517 | void MainWindow::on_pb_filter_set_29bit_10_clicked() 518 | { 519 | QString str; 520 | bool convertOk; 521 | 522 | if(!m_bOpen) 523 | { 524 | QMessageBox::critical(this,"Error","CANAL is closed"); 525 | return; 526 | } 527 | 528 | if(ui->rb_filter_29bit_reject_all->isChecked()) 529 | { 530 | if(CanalSetFilter29bit(m_drvHandle, FILTER_REJECT_ALL, 0, 0) != CANAL_ERROR_SUCCESS) 531 | { 532 | QMessageBox::critical(this,"Error","CANAL communication error"); 533 | } 534 | else 535 | { 536 | //QMessageBox::information(this,"Information","Filter 29bit set up successfully"); 537 | } 538 | } 539 | else if (ui->rb_filter_29bit_accept_all->isChecked()) 540 | { 541 | if(CanalSetFilter29bit(m_drvHandle, FILTER_ACCEPT_ALL, 0, 0) != CANAL_ERROR_SUCCESS) 542 | { 543 | QMessageBox::critical(this,"Error","CANAL communication error"); 544 | } 545 | else 546 | { 547 | //QMessageBox::information(this,"Information","Filter 29bit set up successfully"); 548 | } 549 | } 550 | else if(ui->rb_filter_29bit_list_mask->isChecked()) 551 | { 552 | str = ui->le_filter_id_29bit->text(); 553 | str.remove(0,2); 554 | filter_list_29bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 555 | 556 | str = ui->le_filter_mask_29bit->text(); 557 | str.remove(0,2); 558 | filter_mask_29bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 559 | 560 | if(CanalSetFilter29bit(m_drvHandle, FILTER_VALUE, filter_list_29bit, filter_mask_29bit) != CANAL_ERROR_SUCCESS) 561 | { 562 | QMessageBox::critical(this,"Error","CANAL communication error"); 563 | } 564 | else 565 | { 566 | qDebug() << QString().asprintf("List = %08X, Mask = %08X",filter_list_29bit, filter_mask_29bit); 567 | //QMessageBox::information(this,"Information","Filter 29bit set up successfully"); 568 | } 569 | } 570 | } 571 | 572 | 573 | void MainWindow::statusTimerTimeout() 574 | { 575 | canalStatistics stat; 576 | canalStatus status; 577 | 578 | if ( CanalGetStatus( m_drvHandle,&status ) == CANAL_ERROR_SUCCESS ) 579 | { 580 | if( status.channel_status & CANAL_STATUS_BUS_OFF ) 581 | ui->rb_busOff->setChecked(true); 582 | else if( status.channel_status & CANAL_STATUS_PASSIVE ) 583 | ui->rb_passive->setChecked(true); 584 | else if( status.channel_status & CANAL_STATUS_BUS_WARN ) 585 | ui->rb_warning->setChecked(true); 586 | else 587 | ui->rb_errorFree->setChecked(true); 588 | 589 | ui->label_RxErr->setText(QString::number((status.channel_status>>8)&0xFF)); 590 | ui->label_TxErr->setText(QString::number(status.channel_status & 0xFF)); 591 | } 592 | 593 | if ( CanalGetStatistics( m_drvHandle,&stat ) == CANAL_ERROR_SUCCESS ) 594 | { 595 | ui->lb_ReceivedFrames->setText(QString::number(stat.cntReceiveFrames)); 596 | ui->lb_ReceivedData->setText(QString::number(stat.cntReceiveData)); 597 | ui->lb_TransmitedFrames->setText(QString::number(stat.cntTransmitFrames)); 598 | ui->lb_transmitedData->setText(QString::number(stat.cntTransmitData)); 599 | ui->lb_Overruns->setText(QString::number(stat.cntOverruns)); 600 | ui->lb_Warnings->setText(QString::number(stat.cntBusWarnings)); 601 | ui->lb_BussOff->setText(QString::number(stat.cntBusOff)); 602 | } 603 | } 604 | 605 | void MainWindow::statisticsTimerTimeout() 606 | { 607 | 608 | } 609 | 610 | void MainWindow::on_actionClose_triggered() 611 | { 612 | close(); 613 | } 614 | 615 | void MainWindow::on_startButton_clicked() 616 | { 617 | if(!m_bOpen) 618 | { 619 | QMessageBox::critical(this,"Error","CANAL is closed"); 620 | return; 621 | } 622 | 623 | if(CanalInterfaceStart(m_drvHandle) == CANAL_ERROR_SUCCESS) 624 | { 625 | ui->startButton->setEnabled(false); 626 | ui->stopButton->setEnabled(true); 627 | } 628 | ui->RxMsgTableView->setFocus(); 629 | } 630 | 631 | void MainWindow::on_stopButton_clicked() 632 | { 633 | if(!m_bOpen) 634 | { 635 | QMessageBox::critical(this,"Error","CANAL is closed"); 636 | return; 637 | } 638 | 639 | if(CanalInterfaceStop(m_drvHandle) == CANAL_ERROR_SUCCESS) 640 | { 641 | ui->startButton->setEnabled(true); 642 | ui->stopButton->setEnabled(false); 643 | } 644 | } 645 | 646 | 647 | void MainWindow::on_le_transmit_delay_editingFinished() 648 | { 649 | QString str; 650 | bool convertOk; 651 | 652 | ui->le_transmit_delay->setStyleSheet(""); 653 | ui->le_transmit_delay->clearFocus(); 654 | str = ui->le_transmit_delay->text(); 655 | m_TxMsg.msg.timestamp = (str.toUInt(&convertOk,10)); 656 | } 657 | 658 | void MainWindow::on_le_transmit_delay_textChanged(const QString &arg1) 659 | { 660 | Q_UNUSED(arg1); 661 | ui->le_transmit_delay->setStyleSheet("QLineEdit {background-color: rgb(255, 240, 179)}"); 662 | } 663 | 664 | 665 | void MainWindow::on_actionAbout_triggered() 666 | { 667 | dlgAbout = new DialogAbout; 668 | dlgAbout->setWindowTitle("About"); 669 | dlgAbout->setWindowFlags(Qt::WindowTitleHint); 670 | dlgAbout->exec(); 671 | delete dlgAbout; 672 | } 673 | 674 | void MainWindow::on_actionInit_string_triggered() 675 | { 676 | dlgInitString = new DialogInitString; 677 | dlgInitString->setWindowTitle("Init string"); 678 | dlgInitString->setWindowFlags(Qt::WindowTitleHint); 679 | dlgInitString->exec(); 680 | delete dlgInitString; 681 | } 682 | 683 | /* Stream database clear */ 684 | void MainWindow::on_pb_clear_list_clicked() 685 | { 686 | //QGuiApplication::setOverrideCursor(Qt::WaitCursor); 687 | //this->setCursor(Qt::WaitCursor); 688 | 689 | ui->label_RxFramesCnt->setText(QString::number(0)); 690 | 691 | m_RxTableModel->m_StreamCanFrames->clear(); 692 | m_RxTableModel->m_StreamCanFrames->squeeze(); 693 | m_RxTableModel->layoutAboutToBeChanged(); 694 | m_RxTableModel->layoutChanged(); 695 | 696 | // analyzer table clear 697 | on_pushButton_2_clicked(); 698 | 699 | //streamTableSelectionModel->clearSelection(); 700 | streamTableSelectionModel->reset(); 701 | 702 | //ui->RxMsgTableView->clearSelection(); 703 | 704 | //m_RxCanFrames->clear(); 705 | //m_RxCanFrames->squeeze(); 706 | //m_RxTableModel->layoutChanged(); 707 | 708 | // clear all buffers 709 | //RxMsgCnt = 0; 710 | 711 | ui->progressBar->setValue(0); 712 | emit resetRxThreadCounter(); 713 | //this->setCursor(Qt::ArrowCursor); 714 | //QGuiApplication::setOverrideCursor(Qt::ArrowCursor); 715 | } 716 | 717 | /* Analyzer database clear */ 718 | void MainWindow::on_pushButton_2_clicked() 719 | { 720 | // QVector* m_AnalyzerCanFrames = AnalyzerTableModel->getStreamDatabasePointer(); 721 | 722 | //QGuiApplication::setOverrideCursor(Qt::WaitCursor); 723 | //this->setCursor(Qt::WaitCursor); 724 | /***** Analyzer table ********/ 725 | AnalyzerTableModel->m_AnalyzerCanFrames->clear(); 726 | AnalyzerTableModel->m_AnalyzerCanFrames->squeeze(); 727 | AnalyzerTableModel->layoutAboutToBeChanged(); 728 | AnalyzerTableModel->layoutChanged(); 729 | 730 | 731 | // m_AnalyzerCanFrames->clear(); 732 | // m_AnalyzerCanFrames->squeeze(); 733 | // AnalyzerTableModel->layoutChanged(); 734 | 735 | //this->setCursor(Qt::ArrowCursor); 736 | //QGuiApplication::setOverrideCursor(Qt::ArrowCursor); 737 | } 738 | 739 | void MainWindow::StreamTable_scroll_down() 740 | { 741 | QModelIndex index; 742 | index.siblingAtRow(m_RxTableModel->getStreamDatabasePointer()->size()-1); 743 | 744 | //QVector *temp_RxCanFrames = m_RxTableModel->getStreamDatabasePointer(); 745 | 746 | ui->RxMsgTableView->scrollToBottom(); 747 | 748 | /* selection */ 749 | //ui->RxMsgTableView->selectRow(m_RxTableModel->getStreamDatabasePointer()->size()-1); 750 | //streamTableSelectionModel->select(index,QItemSelectionModel::Select); 751 | 752 | //ui->RxMsgTableView->setFocus(); 753 | //ui->RxMsgTableView->selectRow(0); 754 | } 755 | 756 | void MainWindow::on_ListButton_clicked() 757 | { 758 | canal_dev_list CanDevList; 759 | QString deviceListStr; 760 | qint8 cnt; 761 | 762 | ui->listDevices->clear(); 763 | 764 | if(CANAL_ERROR_SUCCESS == CanalGetDeviceList(&CanDevList,8)) 765 | cnt = CanDevList.canDevCount; 766 | else 767 | return; 768 | 769 | for(int x = 0; x < cnt; x++ ){ 770 | deviceListStr.clear(); 771 | deviceListStr.append(CanDevList.canDevInfo[x].SerialNumber); 772 | ui->listDevices->addItem(deviceListStr); 773 | } 774 | } 775 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #ifndef MAINWINDOW_H 21 | #define MAINWINDOW_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "canal.h" 31 | #include "rxworkerthread.h" 32 | #include "txworkerthread.h" 33 | #include "dialogabout.h" 34 | #include "dialoginitstring.h" 35 | #include "StreamFrameTable.h" 36 | #include "AnalyzerFrameTable.h" 37 | 38 | Q_DECLARE_METATYPE(structCanalMsg) 39 | 40 | 41 | namespace Ui { 42 | class MainWindow; 43 | } 44 | 45 | class MainWindow : public QMainWindow 46 | { 47 | Q_OBJECT 48 | 49 | public: 50 | explicit MainWindow(QWidget *parent = nullptr); 51 | ~MainWindow(); 52 | 53 | // application open.close state 54 | bool m_bOpen; 55 | // run threads 56 | bool m_bRun; 57 | 58 | //CANAL messages 59 | //QVector *m_RxMsgList; 60 | QVector *m_TxMsgList; 61 | 62 | //canalMsg m_TxMsg; 63 | transmitMsg m_TxMsg; 64 | streamMsg m_RxMsg; 65 | unsigned int m_burst_cnt; 66 | 67 | /* Rx Msg Table */ 68 | //RxFrameTable *RxTableModel; 69 | 70 | //settings 71 | void saveSettings(); 72 | void loadSettings(); 73 | 74 | signals: 75 | void stopRxThreadSignal(); 76 | void resetRxThreadCounter(); 77 | 78 | void stopTxThreadSignal(); 79 | void resetTxThreadCounter(); 80 | 81 | private: 82 | QVector* m_RxCanFrames; 83 | 84 | private slots: 85 | 86 | void on_closeButton_clicked(); 87 | void on_openButton_clicked(); 88 | void on_le_data0_textChanged(const QString &arg1); 89 | void on_le_data0_editingFinished(); 90 | void on_le_data1_textChanged(const QString &arg1); 91 | void on_le_data1_editingFinished(); 92 | void on_le_data2_textChanged(const QString &arg1); 93 | void on_le_data2_editingFinished(); 94 | void on_le_data3_textChanged(const QString &arg1); 95 | void on_le_data3_editingFinished(); 96 | void on_le_data4_textChanged(const QString &arg1); 97 | void on_le_data4_editingFinished(); 98 | void on_le_data5_textChanged(const QString &arg1); 99 | void on_le_data5_editingFinished(); 100 | void on_le_data6_textChanged(const QString &arg1); 101 | void on_le_data6_editingFinished(); 102 | void on_le_data7_textChanged(const QString &arg1); 103 | void on_le_data7_editingFinished(); 104 | void on_le_dlc_editingFinished(); 105 | void on_le_dlc_textChanged(const QString &arg1); 106 | //void on_le_burst_cnt_editingFinished(); 107 | //void on_le_burst_cnt_textChanged(const QString &arg1); 108 | void on_le_msg_ID_textChanged(const QString &arg1); 109 | void on_le_msg_ID_editingFinished(); 110 | void on_cb_msg_ext_stateChanged(int arg1); 111 | void on_le_filter_id_11bit_textChanged(const QString &arg1); 112 | void on_le_filter_id_11bit_editingFinished(); 113 | void on_le_filter_mask_11bit_textChanged(const QString &arg1); 114 | void on_le_filter_mask_11bit_editingFinished(); 115 | void on_le_filter_id_29bit_textChanged(const QString &arg1); 116 | void on_le_filter_id_29bit_editingFinished(); 117 | void on_le_filter_mask_29bit_textChanged(const QString &arg1); 118 | void on_le_filter_mask_29bit_editingFinished(); 119 | void on_pb_filter_set_11bit_clicked(); 120 | void on_pb_filter_set_29bit_10_clicked(); 121 | 122 | // staus & statistics Timer 123 | void statusTimerTimeout(); 124 | void statisticsTimerTimeout(); 125 | 126 | // Rx CANAL Thread 127 | //void updateInfiniteCountStream(qulonglong cnt, canalMsg msg); 128 | //void updateInfiniteCountAnalyzer(qulonglong cnt, canalMsg msg); 129 | // Tx message sent 130 | void updateInfiniteTxCount(unsigned long cnt); 131 | //void infiniteCountFinished(); 132 | void startRxThread(); 133 | void stopRxThread(); //GS 134 | 135 | void startTxThread(); 136 | 137 | // Tx CANAL Thread 138 | 139 | 140 | void on_pb_clear_list_clicked(); 141 | 142 | // TEST button 143 | //void on_pushButton_clicked(/*canalMsg msg*/); 144 | void on_actionSave_buffer_triggered(); 145 | void on_actionClose_triggered(); 146 | void on_pb_msg_send_clicked(); 147 | 148 | void on_startButton_clicked(); 149 | void on_stopButton_clicked(); 150 | 151 | void on_pb_DeleteLast_clicked(); 152 | void on_pb_AddItem_clicked(); 153 | 154 | void on_le_transmit_delay_editingFinished(); 155 | 156 | void on_le_transmit_delay_textChanged(const QString &arg1); 157 | 158 | void on_actionAbout_triggered(); 159 | 160 | void on_actionInit_string_triggered(); 161 | 162 | void StreamTable_scroll_down(); 163 | //void on_AnalyzerTable_scroll_down(); 164 | 165 | // void on_pushButton_2_clicked(); 166 | 167 | // void on_pushButton_3_clicked(); 168 | 169 | void on_pushButton_2_clicked(); 170 | 171 | 172 | void on_pushButton_3_clicked(); 173 | 174 | void on_pushButton_4_clicked(); 175 | 176 | void on_le_txcount_editingFinished(); 177 | 178 | void on_le_txcount_textChanged(const QString &arg1); 179 | 180 | 181 | void on_ListButton_clicked(); 182 | 183 | private: 184 | Ui::MainWindow *ui; 185 | 186 | void exportTableWidgetToCSV(); 187 | 188 | //Widgets values settings 189 | void WidgetValuesInit(); 190 | void WidgetValuesOpen(); 191 | void WidgetValuesClose(); 192 | 193 | // Canal DLL device handle 194 | int m_drvHandle; 195 | 196 | // Widgets value settings 197 | QSettings *settings; 198 | 199 | //Filter 200 | unsigned long filter_list_11bit; 201 | unsigned long filter_mask_11bit; 202 | unsigned long filter_list_29bit; 203 | unsigned long filter_mask_29bit; 204 | 205 | QTimer *timerStatistics; 206 | QTimer *timerStatus; 207 | 208 | // Rx CANAL Thread 209 | bool countRunning; 210 | bool infiniteCountRunning; 211 | unsigned long RxMsgCnt; 212 | unsigned long TxMsgCnt; 213 | 214 | // Rx thread 215 | QThread *m_RxWorkerThread; 216 | RxWorkerThreadInfinite *m_RxWorker ; 217 | 218 | // Tx worker 219 | QThread *m_TxWorkerThread; 220 | TxWorkerThreadInfinite *m_TxWorker ; 221 | 222 | // MsgTableWidget 223 | QTableWidgetItem *tbl; 224 | int m_rowCountCurrent = 0; 225 | 226 | //MsgSend 227 | void SendWidgetToTxMsg(bool insert_type); 228 | 229 | DialogAbout *dlgAbout; 230 | DialogInitString *dlgInitString; 231 | 232 | /* QtableViewModels */ 233 | RxFrameTable *m_RxTableModel; 234 | AnalyzerFrameTable *AnalyzerTableModel; 235 | 236 | QItemSelectionModel *streamTableSelectionModel; 237 | QItemSelectionModel *TxTableSelectionModel; 238 | }; 239 | 240 | #endif // MAINWINDOW_H 241 | -------------------------------------------------------------------------------- /mainwindowfiles.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #include "mainwindow.h" 21 | #include "ui_mainwindow.h" 22 | #include "canal.h" 23 | #include "rxworkerthread.h" 24 | #include "QValidator" 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | //void MainWindow::startRxThread() 34 | 35 | void MainWindow::exportTableWidgetToCSV() 36 | { 37 | streamMsg canframe; 38 | QString string; 39 | QByteArray data_array; 40 | //QChar ch; 41 | 42 | //QVector* RxCanFrames = RxTableModel->m_RxCanFrames; 43 | QVector* RxCanFrames = m_RxTableModel->getStreamDatabasePointer(); 44 | 45 | QString fileName = QFileDialog::getSaveFileName(this,tr("Save file"),QStandardPaths::writableLocation((QStandardPaths::DocumentsLocation)), tr("CSV files (*.csv)")); 46 | QFile file(fileName); 47 | 48 | // QGuiApplication::setOverrideCursor(Qt::WaitCursor); 49 | this->setCursor(Qt::WaitCursor); 50 | 51 | //if (f.open(QFile::WriteOnly | QFile::Truncate)) 52 | if(file.open(QIODevice::WriteOnly | QIODevice::Text)) 53 | { 54 | QTextStream stream(&file); 55 | stream <<"TouCAN USB to CAN bus converter raw data log: " << QDateTime::currentDateTime().toString() << "\n\r"; 56 | stream << "Nr" <<';'<< "Timestamp"<<";"<< "T h:m:sec.ms" <<';'<<"Type (hex)"<<';'<< "Id (hex)"<<';'<<"Length" << ';' << "Data (hex)" << "\n"; 57 | 58 | for(qint32 x = 0 ; x < RxCanFrames->size(); x++) 59 | { 60 | canframe = RxCanFrames->at(x); 61 | stream << QString("%1").arg(x+1,0,10) << ';' ; 62 | stream << QString("%1").arg(canframe.msg.timestamp,0,10) << ';' ; 63 | 64 | stream << QDateTime::fromMSecsSinceEpoch(canframe.stat.time, Qt::UTC).toString("hh:mm:ss.zzz") << ';' ; 65 | 66 | if(canframe.msg.flags & CANAL_IDFLAG_EXTENDED) 67 | string = "Ext"; 68 | else 69 | string = "Std"; 70 | 71 | if(canframe.msg.flags & CANAL_IDFLAG_RTR) 72 | string.append(":Rtr"); 73 | 74 | if(canframe.msg.flags & CANAL_IDFLAG_STATUS) 75 | string = "Status"; 76 | string.append(';'); 77 | 78 | stream << string; 79 | stream << QString("%1").arg(canframe.msg.id,0,16).toUpper() << ';' << QString("%1").arg(canframe.msg.sizeData,0,10).toUpper() << ';' ; 80 | 81 | data_array = QByteArray::fromRawData((const char*) canframe.msg.data, canframe.msg.sizeData); 82 | string = data_array.toHex(' ').toUpper(); 83 | stream << string << "\n"; 84 | } 85 | 86 | } 87 | file.flush(); 88 | file.close(); 89 | //QGuiApplication::setOverrideCursor(Qt::ArrowCursor); 90 | this->setCursor(Qt::ArrowCursor); 91 | } 92 | 93 | void MainWindow::on_actionSave_buffer_triggered() 94 | { 95 | exportTableWidgetToCSV(); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /mainwindowsendcanmsg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #include "mainwindow.h" 21 | #include "ui_mainwindow.h" 22 | #include "canal.h" 23 | #include "rxworkerthread.h" 24 | #include "QValidator" 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | void MainWindow::SendWidgetToTxMsg(bool insert_type) 31 | { 32 | //Q_UNUSED(TransmitMessageFrame); 33 | 34 | QString str; 35 | bool convertOk; 36 | transmitMsg canMsg; 37 | QTableWidgetItem *tbl; 38 | 39 | qint32 row; 40 | 41 | if(insert_type == append){ 42 | row = ui->TxMsgTableWidget->rowCount(); 43 | } 44 | else{ 45 | row = ui->TxMsgTableWidget->currentRow(); 46 | if(row < 0) return; 47 | } 48 | 49 | ui->TxMsgTableWidget->insertRow(row); 50 | 51 | // message ID 52 | str = ui->le_msg_ID->text(); 53 | str.remove(0,2); 54 | canMsg.msg.id = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 55 | 56 | // TxTable "ID" 57 | str = (ui->le_msg_ID->text()); 58 | tbl = new QTableWidgetItem(str); 59 | tbl->setTextAlignment(Qt::AlignCenter); 60 | ui->TxMsgTableWidget->setItem(row, 0, tbl); 61 | 62 | // message STD:EXT:RTR 63 | if(ui->cb_msg_ext->isChecked()) 64 | { 65 | canMsg.msg.flags = CANAL_IDFLAG_EXTENDED; 66 | } 67 | else 68 | { 69 | canMsg.msg.flags = CANAL_IDFLAG_STANDARD; 70 | } 71 | 72 | if(ui->cb_msg_rtr->isChecked()) 73 | { 74 | canMsg.msg.flags |= CANAL_IDFLAG_RTR; 75 | } 76 | 77 | // TxTable "STD:EXT:RTR" 78 | if(canMsg.msg.flags & CANAL_IDFLAG_EXTENDED) 79 | str = "Ext"; 80 | else 81 | str = "Sds"; 82 | 83 | if(canMsg.msg.flags & CANAL_IDFLAG_RTR) 84 | str.append(":Rtr"); 85 | 86 | tbl = new QTableWidgetItem(str); 87 | tbl->setTextAlignment(Qt::AlignCenter); 88 | ui->TxMsgTableWidget->setItem(row, 1, tbl); 89 | 90 | // count 91 | str = ui->le_txcount->text(); 92 | canMsg.stat.count = (str.toUInt(&convertOk,10)); 93 | 94 | // TxTable "Count" 95 | str = (ui->le_txcount->text()); 96 | tbl = new QTableWidgetItem(str); 97 | tbl->setTextAlignment(Qt::AlignCenter); 98 | ui->TxMsgTableWidget->setItem(row, 2, tbl); 99 | 100 | // message DLC 101 | str = ui->le_dlc->text(); 102 | canMsg.msg.sizeData = (str.toUInt(&convertOk,10) & 0xFF); 103 | 104 | // TxTable "dlc" 105 | str = (ui->le_dlc->text()); 106 | tbl = new QTableWidgetItem(str); 107 | tbl->setTextAlignment(Qt::AlignCenter); 108 | ui->TxMsgTableWidget->setItem(row, 3, tbl); 109 | 110 | /*************** DATA **********************/ 111 | 112 | // message DATA 113 | str = ui->le_data0->text(); 114 | str.remove(0,2); 115 | canMsg.msg.data[0] = (str.toUInt(&convertOk,16) & 0xFF); 116 | 117 | // TxTable "data0" 118 | str = (ui->le_data0->text()); 119 | tbl = new QTableWidgetItem(str); 120 | tbl->setTextAlignment(Qt::AlignCenter); 121 | ui->TxMsgTableWidget->setItem(row, 4, tbl); 122 | 123 | str = ui->le_data1->text(); 124 | str.remove(0,2); 125 | canMsg.msg.data[1] = (str.toUInt(&convertOk,16) & 0xFF); 126 | 127 | // TxTable "data1" 128 | str = (ui->le_data1->text()); 129 | tbl = new QTableWidgetItem(str); 130 | tbl->setTextAlignment(Qt::AlignCenter); 131 | ui->TxMsgTableWidget->setItem(row, 5, tbl); 132 | 133 | str = ui->le_data2->text(); 134 | str.remove(0,2); 135 | canMsg.msg.data[2] = (str.toUInt(&convertOk,16) & 0xFF); 136 | 137 | // TxTable "data2" 138 | str = (ui->le_data2->text()); 139 | tbl = new QTableWidgetItem(str); 140 | tbl->setTextAlignment(Qt::AlignCenter); 141 | ui->TxMsgTableWidget->setItem(row, 6, tbl); 142 | 143 | str = ui->le_data3->text(); 144 | str.remove(0,2); 145 | canMsg.msg.data[3] = (str.toUInt(&convertOk,16) & 0xFF); 146 | 147 | // TxTable "data3" 148 | str = (ui->le_data3->text()); 149 | tbl = new QTableWidgetItem(str); 150 | tbl->setTextAlignment(Qt::AlignCenter); 151 | ui->TxMsgTableWidget->setItem(row, 7, tbl); 152 | 153 | str = ui->le_data4->text(); 154 | str.remove(0,2); 155 | canMsg.msg.data[4] = (str.toUInt(&convertOk,16) & 0xFF); 156 | 157 | // TxTable "data4" 158 | str = (ui->le_data4->text()); 159 | tbl = new QTableWidgetItem(str); 160 | tbl->setTextAlignment(Qt::AlignCenter); 161 | ui->TxMsgTableWidget->setItem(row, 8, tbl); 162 | 163 | str = ui->le_data5->text(); 164 | str.remove(0,2); 165 | canMsg.msg.data[5] = (str.toUInt(&convertOk,16) & 0xFF); 166 | 167 | // TxTable "data5" 168 | str = (ui->le_data5->text()); 169 | tbl = new QTableWidgetItem(str); 170 | tbl->setTextAlignment(Qt::AlignCenter); 171 | ui->TxMsgTableWidget->setItem(row, 9, tbl); 172 | 173 | str = ui->le_data6->text(); 174 | str.remove(0,2); 175 | canMsg.msg.data[6] = (str.toUInt(&convertOk,16) & 0xFF); 176 | 177 | // TxTable "data6" 178 | str = (ui->le_data6->text()); 179 | tbl = new QTableWidgetItem(str); 180 | tbl->setTextAlignment(Qt::AlignCenter); 181 | ui->TxMsgTableWidget->setItem(row, 10, tbl); 182 | 183 | str = ui->le_data7->text(); 184 | str.remove(0,2); 185 | canMsg.msg.data[7] = (str.toUInt(&convertOk,16) & 0xFF); 186 | 187 | // TxTable "data7" 188 | str = (ui->le_data7->text()); 189 | tbl = new QTableWidgetItem(str); 190 | tbl->setTextAlignment(Qt::AlignCenter); 191 | ui->TxMsgTableWidget->setItem(row, 11, tbl); 192 | 193 | /**************************************************************/ 194 | 195 | // transmit delay 196 | str = ui->le_transmit_delay->text(); 197 | canMsg.msg.timestamp = (str.toUInt(&convertOk,10)); 198 | 199 | // TxTable "Transmit delay" 200 | str = (ui->le_transmit_delay->text()); 201 | tbl = new QTableWidgetItem(str); 202 | tbl->setTextAlignment(Qt::AlignCenter); 203 | ui->TxMsgTableWidget->setItem(row, 12, tbl); 204 | 205 | 206 | if (insert_type == append) 207 | { 208 | m_TxMsgList->append(canMsg); 209 | ui->TxMsgTableWidget->selectRow(row); 210 | } 211 | else 212 | { 213 | m_TxMsgList->insert(row,canMsg); 214 | } 215 | 216 | } 217 | 218 | // delete last item 219 | void MainWindow::on_pb_DeleteLast_clicked() 220 | { 221 | ui->TxMsgTableWidget->setRowCount(0); 222 | 223 | m_TxMsgList->clear(); 224 | m_TxMsgList->squeeze(); 225 | 226 | emit resetTxThreadCounter(); 227 | } 228 | 229 | /* add Tx row */ 230 | void MainWindow::on_pb_AddItem_clicked() 231 | { 232 | SendWidgetToTxMsg(append); 233 | } 234 | 235 | /* insert TX row */ 236 | void MainWindow::on_pushButton_4_clicked() 237 | { 238 | SendWidgetToTxMsg(insert); 239 | } 240 | 241 | 242 | /* delete Tx row */ 243 | void MainWindow::on_pushButton_3_clicked() 244 | { 245 | qint32 row; 246 | 247 | row = ui->TxMsgTableWidget->currentRow(); 248 | 249 | if( row >= 0) 250 | { 251 | ui->TxMsgTableWidget->removeRow(row); 252 | m_TxMsgList->remove(row); 253 | } 254 | } 255 | 256 | void MainWindow::updateInfiniteTxCount(unsigned long cnt) 257 | { 258 | Q_UNUSED(cnt); 259 | ui->label_TxFramesCnt->setText(QString::number(++TxMsgCnt)); 260 | } 261 | 262 | void MainWindow::on_pb_msg_send_clicked() 263 | { 264 | QString str; 265 | 266 | if(!m_bOpen) 267 | { 268 | QMessageBox::critical(this,"Error","CANAL is closed"); 269 | return; 270 | } 271 | 272 | // qDebug() << m_TxMsg.id << m_TxMsg.sizeData << m_TxMsg.data[0] << m_TxMsg.data[1] << m_TxMsg.data[2] << m_TxMsg.data[3] \ 273 | // << m_TxMsg.data[4] << m_TxMsg.data[5] << m_TxMsg.data[6] << m_TxMsg.data[7] \ 274 | // << m_TxMsg.timestamp; 275 | 276 | startTxThread(); 277 | } 278 | 279 | 280 | 281 | -------------------------------------------------------------------------------- /mainwindowsettings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #include "mainwindow.h" 21 | #include "ui_mainwindow.h" 22 | #include 23 | #include 24 | 25 | void MainWindow::saveSettings() 26 | { 27 | //settings->beginGroup("forms"); 28 | //settings->setValue("title", windowTitle()); 29 | //settings->beginGroup(objectName()); 30 | //settings->setValue("geometry", geometry()); 31 | //settings->endGroup(); 32 | //settings->endGroup(); 33 | 34 | settings->beginGroup("OpenFlags"); 35 | settings->setValue("Silent", ui->cb_SilentMode->isChecked()); 36 | settings->setValue("Loopback", ui->cb_LoopbackMode->isChecked()); 37 | settings->setValue("Retransmition", ui->cb_DisRetransmition->isChecked()); 38 | settings->setValue("BusOff", ui->cb_AutoBusOff->isChecked()); 39 | settings->setValue("StatusMessage", ui->cb_EnStatusMessage->isChecked()); 40 | settings->setValue("TimMode", ui->cb_TimMode->isChecked()); 41 | settings->setValue("RxFifoLocked", ui->cb_RxFifoLocked->isChecked()); 42 | settings->setValue("TxFifoMode", ui->cb_TxFifoPriority->isChecked()); 43 | settings->setValue("WakeUp", ui->cb_WakeUpMode->isChecked()); 44 | settings->setValue("TimeDelay", ui->cb_TimestampDelay->isChecked()); 45 | settings->setValue("OpenString",ui->le_OpenParameters->text()); 46 | settings->endGroup(); 47 | } 48 | 49 | void MainWindow::loadSettings() 50 | { 51 | //setWindowTitle(settings->value("title","CANAL View").toString()); 52 | //settings->beginGroup("forms"); 53 | //settings->beginGroup(objectName()); 54 | //setGeometry(settings->value("geometry", QRect(200, 200, 300, 300)).toRect()); 55 | //settings->endGroup(); 56 | //settings->endGroup(); 57 | 58 | 59 | //settings = new QSettings("RUSOKU Technologies", "CANAL View", this); 60 | settings = new QSettings("settings.ini", QSettings::IniFormat, this); 61 | //settings = new QSettings(); 62 | //settings->setPath(QSettings::IniFormat,QSettings::SystemScope,"settings.ini"); 63 | 64 | //setObjectName(name); 65 | setWindowTitle("CANAL view v.1.0.8"); 66 | 67 | settings->beginGroup("OpenFlags"); 68 | ui->cb_SilentMode->setChecked(settings->value("Silent",false).toBool()); 69 | ui->cb_LoopbackMode->setChecked(settings->value("Loopback",false).toBool()); 70 | ui->cb_DisRetransmition->setChecked(settings->value("Retransmition",false).toBool()); 71 | ui->cb_AutoBusOff->setChecked(settings->value("BusOff",false).toBool()); 72 | ui->cb_EnStatusMessage->setChecked(settings->value("StatusMessage",false).toBool()); 73 | ui->cb_TimMode->setChecked(settings->value("TimMode",false).toBool()); 74 | ui->cb_RxFifoLocked->setChecked(settings->value("RxFifoLocked",false).toBool()); 75 | ui->cb_TxFifoPriority->setChecked(settings->value("TxFifoMode",false).toBool()); 76 | ui->cb_WakeUpMode->setChecked(settings->value("WakeUp",false).toBool()); 77 | ui->cb_TimestampDelay->setChecked(settings->value("TimeDelay",false).toBool()); 78 | ui->le_OpenParameters->setText(settings->value("OpenString","0;00000000;250").toString()); 79 | settings->endGroup(); 80 | } 81 | -------------------------------------------------------------------------------- /mainwindowwidgitsinit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #include "mainwindow.h" 21 | #include "ui_mainwindow.h" 22 | #include "canal.h" 23 | //#include "rxworkerthread.h" 24 | #include "QValidator" 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | void MainWindow::WidgetValuesInit() 32 | { 33 | QString str; 34 | bool convertOk; 35 | unsigned long temp_u32; 36 | 37 | ui->startButton->setEnabled(false); 38 | ui->stopButton->setEnabled(false); 39 | ui->closeButton->setEnabled(false); 40 | ui->label_Hardware->setText("-"); 41 | ui->label_Firmware->setText("-"); 42 | ui->label_Canal->setText("-"); 43 | ui->label_CanalDll->setText("-"); 44 | ui->label_Vendor->setText("-"); 45 | ui->label_Bootloader->setText("-"); 46 | ui->rb_errorFree->setChecked(true); 47 | ui->statusBar->showMessage("CANAL status: Closed"); 48 | 49 | // set RxMsg Table index focus 50 | ui->tabWidget->setCurrentIndex(0); 51 | 52 | ui->le_data0->setInputMask("\\0\\x>HH"); 53 | ui->le_data1->setInputMask("\\0\\x>HH"); 54 | ui->le_data2->setInputMask("\\0\\x>HH"); 55 | ui->le_data3->setInputMask("\\0\\x>HH"); 56 | ui->le_data4->setInputMask("\\0\\x>HH"); 57 | ui->le_data5->setInputMask("\\0\\x>HH"); 58 | ui->le_data6->setInputMask("\\0\\x>HH"); 59 | ui->le_data7->setInputMask("\\0\\x>HH"); 60 | ui->le_transmit_delay->setValidator(new QIntValidator(1,999)); 61 | ui->le_txcount->setValidator(new QIntValidator(1,999)); 62 | ui->le_dlc->setValidator(new QIntValidator(0,8)); 63 | //ui->le_burst_cnt->setValidator(new QIntValidator(1,10000)); 64 | 65 | //msg ID 66 | ui->le_msg_ID->setInputMask("\\0\\x>BHHHHHHHH"); 67 | //ui->le_msg_ID->setInputMask("BHHHHHHHH"); 68 | ui->cb_msg_ext->setChecked(true); 69 | 70 | // buffer progressBar 71 | //ui->progressBar->setFocusPolicy(Qt::NoFocus); 72 | 73 | //================================= StreamFrameTable ========================= 74 | 75 | m_RxTableModel = new RxFrameTable(this); 76 | ui->RxMsgTableView->setModel(m_RxTableModel); 77 | //QItemSelectionModel *streamTableSelectionModel = ui->RxMsgTableView->selectionModel(); 78 | streamTableSelectionModel = ui->RxMsgTableView->selectionModel(); 79 | 80 | //RxTableModel->blockSignals(true); 81 | //ui->RxMsgTableView->blockSignals(true); 82 | 83 | ui->RxMsgTableView->setWordWrap(false); 84 | ui->RxMsgTableView->horizontalHeader()->setSectionResizeMode(5,QHeaderView::Stretch); 85 | //ui->RxMsgTableView->horizontalHeader()->setSectionResizeMode(5,QHeaderView::Stretch); 86 | 87 | /* Selecting only rows */ 88 | ui->RxMsgTableView->setSelectionBehavior(QAbstractItemView::SelectRows); 89 | /* horizontal rows resizing */ 90 | //ui->RxMsgTableView->horizontalHeader()->resizeSections(QHeaderView::Stretch); 91 | 92 | /* Vertical rows resize mode*/ 93 | ui->RxMsgTableView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); 94 | ui->RxMsgTableView->verticalHeader()->setDefaultSectionSize(18); 95 | 96 | /* ??? */ 97 | ui->RxMsgTableView->setEditTriggers(QAbstractItemView::NoEditTriggers); 98 | ui->RxMsgTableView->setSelectionMode(QAbstractItemView::SingleSelection); 99 | //ui->RxMsgTableView->setSelectionMode(QAbstractItemView::NoSelection); 100 | 101 | 102 | //ui->RxMsgTableView->setStyleSheet("QHeaderView::section {background-color: rgb(51, 51, 255)}, QTableCornerButton::section {background-color: rgb(224, 224, 224}"); 103 | 104 | /* 105 | QTableWidget::item{ selection-background-color: red} 106 | arba: 107 | QTableWidget::item{ background-color: blue } 108 | QTableWidget::item:selected{ background-color: red } 109 | */ 110 | 111 | //ui->RxMsgTableView->setStyleSheet("QTableView::item{selection-background-color: red} "); 112 | ui->RxMsgTableView->setStyleSheet("QTableView::item:selected:active{selection-background-color: grey; selection-color: #FFFFFFFF; } "); 113 | ui->RxMsgTableView->setStyleSheet("QTableView::item:selected:inactive{selection-background-color: grey; selection-color: #FFFFFFFF; } "); 114 | 115 | 116 | //ui->RxMsgTableView->setStyleSheet("QTableView::item:selected{background: rgb(0 0, 244)}"); 117 | //ui->RxMsgTableView->setStyleSheet("QTableView::item:selected:active{background: rgb(0 0, 244)}"); 118 | //ui->RxMsgTableView->setStyleSheet("QTableView::item:selected:!active{background: rgb(0 0, 244)}"); 119 | 120 | //ui->RxMsgTableView->selectRow(0); 121 | 122 | /* get RxCanFramesVector pointer from QTableViewModel */ 123 | m_RxCanFrames = m_RxTableModel->getStreamDatabasePointer(); 124 | 125 | //================================= AnalyzerFrameTable ========================= 126 | 127 | QSortFilterProxyModel *analyzerFrameProxyModel = new QSortFilterProxyModel; 128 | AnalyzerTableModel = new AnalyzerFrameTable(this, m_RxCanFrames); 129 | 130 | analyzerFrameProxyModel->setSourceModel(AnalyzerTableModel); 131 | 132 | //ui->AnalyzerTableView->setModel(AnalyzerTableModel); 133 | ui->AnalyzerTableView->setModel(analyzerFrameProxyModel); 134 | 135 | /* Sorting */ 136 | ui->AnalyzerTableView->setSortingEnabled(true); 137 | ui->AnalyzerTableView->sortByColumn(3,Qt::AscendingOrder); 138 | 139 | ui->AnalyzerTableView->setWordWrap(false); 140 | ui->AnalyzerTableView->horizontalHeader()->setSectionResizeMode(5,QHeaderView::Stretch); 141 | 142 | /* Vertical rows resize mode*/ 143 | ui->AnalyzerTableView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); 144 | ui->AnalyzerTableView->verticalHeader()->setDefaultSectionSize(18); 145 | 146 | ui->AnalyzerTableView->setEditTriggers(QAbstractItemView::NoEditTriggers); 147 | //ui->AnalyzerTableView->setSelectionMode(QAbstractItemView::SingleSelection); 148 | ui->AnalyzerTableView->setSelectionMode(QAbstractItemView::NoSelection); 149 | 150 | /****** QTableView models signals ******/ 151 | /* Analyze frame after stream table row selection */ 152 | connect(streamTableSelectionModel, &QItemSelectionModel::currentRowChanged, AnalyzerTableModel, &AnalyzerFrameTable::on_doAnalyze); 153 | /* Scroll down sream table after frame received */ 154 | connect(m_RxTableModel, &RxFrameTable::layoutChanged, this, &MainWindow::StreamTable_scroll_down); 155 | 156 | /* neveikia TODO kodel */ 157 | //connect(m_RxTableModel, &RxFrameTable::newFrameArrived, ui->label_24, &QLabel::setNum); 158 | 159 | /* Rx counter for Label and progressBar */ 160 | connect(m_RxTableModel, SIGNAL(newFrameArrived(int)), ui->label_RxFramesCnt, SLOT(setNum(int))); 161 | connect(m_RxTableModel, SIGNAL(newFrameArrived(int)), ui->progressBar, SLOT(setValue(int))); 162 | 163 | //================================= TxTableWidget ========================= 164 | 165 | //TxTableSelectionModel = ui->TxMsgTableWidget->selectionModel(); 166 | //TxTableSelectionModel-> 167 | 168 | //if(TxTableSelectionModel == nullptr) 169 | // qDebug() << "TXx table nullptr"; 170 | 171 | ui->TxMsgTableWidget->setColumnCount(13); 172 | ui->TxMsgTableWidget->verticalHeader()->hide(); 173 | ui->TxMsgTableWidget->setHorizontalHeaderLabels(QStringList() << "Id" << "Flag" << "Count" << "Length" << "D0" << "D1" \ 174 | << "D2" << "D3" << "D4" << "D5" << "D6" << "D7" << "Transmit delay (ms)"); 175 | 176 | QFont font; 177 | font.setBold(true); 178 | ui->TxMsgTableWidget->horizontalHeader()->setFont(font); 179 | 180 | ui->TxMsgTableWidget->resizeRowsToContents(); 181 | ui->TxMsgTableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); 182 | //ui->TxMsgTableWidget->resizeColumnToContents(0); 183 | ui->TxMsgTableWidget->resizeColumnToContents(1); 184 | //ui->TxMsgTableWidget->resizeColumnToContents(12); 185 | 186 | ui->TxMsgTableWidget->setStyleSheet("QTableView::item:selected:active{selection-background-color: grey; selection-color: #FFFFFFFF; } "); 187 | ui->TxMsgTableWidget->setStyleSheet("QTableView::item:selected:inactive{selection-background-color: grey; selection-color: #FFFFFFFF; } "); 188 | 189 | /* 190 | ui->RxMsgTableView->setEditTriggers(QAbstractItemView::NoEditTriggers); 191 | ui->RxMsgTableView->setSelectionMode(QAbstractItemView::SingleSelection); 192 | //ui->RxMsgTableView->setSelectionMode(QAbstractItemView::NoSelection); 193 | */ 194 | 195 | 196 | ui->TxMsgTableWidget->horizontalHeader()->setStretchLastSection(true); 197 | 198 | // ui->TxMsgTableWidget->setStyleSheet("QHeaderView::section {background-color: rgb(224, 224, 224)},\ 199 | // QTableCornerButton::section {background-color: rgb(224, 224, 224}"); 200 | 201 | ui->TxMsgTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); 202 | //ui->TxMsgTableWidget->setFocusPolicy(Qt::NoFocus); 203 | ui->TxMsgTableWidget->setSelectionMode(QAbstractItemView::QAbstractItemView::SingleSelection); 204 | ui->TxMsgTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); 205 | 206 | 207 | //msg ID 208 | ui->le_msg_ID->setText("0x00000000"); 209 | ui->le_msg_ID->setInputMask("\\0\\x>BHHHHHHH"); 210 | ui->cb_msg_ext->setChecked(true); 211 | 212 | // Filters 213 | ui->le_filter_id_11bit->setInputMask("\\0\\x>9HH"); 214 | ui->le_filter_mask_11bit->setInputMask("\\0\\x>9HH"); 215 | ui->le_filter_id_29bit->setInputMask("\\0\\x>BHHHHHHH"); 216 | ui->le_filter_mask_29bit->setInputMask("\\0\\x>BHHHHHHH"); 217 | 218 | // 11bit list 219 | str = ui->le_filter_id_11bit->text(); 220 | str.remove(0,2); 221 | filter_list_11bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 222 | 223 | // 11bit mask 224 | str = ui->le_filter_mask_11bit->text(); 225 | str.remove(0,2); 226 | filter_mask_11bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 227 | 228 | // 29bit list 229 | str = ui->le_filter_id_29bit->text(); 230 | str.remove(0,2); 231 | filter_list_29bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 232 | 233 | // 29bit mask 234 | str = ui->le_filter_mask_29bit->text(); 235 | str.remove(0,2); 236 | filter_mask_29bit = (str.toUInt(&convertOk,16) & 0x1FFFFFFF); 237 | 238 | temp_u32 = CanalGetVersion(); 239 | str = QString("%1.%2.%3").arg(temp_u32 & 0xFF).arg((temp_u32>>8) & 0xFF).arg(temp_u32>>16 & 0xFF); 240 | ui->label_Canal->setText(str); 241 | temp_u32 = CanalGetDllVersion(); 242 | 243 | unsigned char maj = temp_u32 & 0xff; 244 | unsigned char min = (temp_u32>>8) & 0xff; 245 | unsigned char patch = (temp_u32 >>16) & 0xff; 246 | 247 | if(( maj < 1) || (min < 0) || (patch < 5)){ 248 | QMessageBox::critical(this,"Error","Wrong CANAL DLL version, 1.0.5 or later"); 249 | } 250 | 251 | str = QString("%1.%2.%3").arg(temp_u32 & 0xFF).arg((temp_u32>>8) & 0xFF).arg(temp_u32>>16 & 0xFF); 252 | ui->label_CanalDll->setText(str); 253 | 254 | // checked 255 | //ui->cb_AutoBusOff->setChecked(true); 256 | } 257 | 258 | void MainWindow::WidgetValuesOpen() 259 | { 260 | QString str; 261 | unsigned long temp_u32; 262 | 263 | // enabled 264 | ui->cb_SilentMode->setEnabled(false); 265 | ui->cb_LoopbackMode->setEnabled(false); 266 | ui->cb_DisRetransmition->setEnabled(false); 267 | ui->cb_WakeUpMode->setEnabled(false); 268 | ui->cb_AutoBusOff->setEnabled(false); 269 | ui->cb_TimMode->setEnabled(false); 270 | ui->cb_RxFifoLocked->setEnabled(false); 271 | ui->cb_TxFifoPriority->setEnabled(false); 272 | ui->cb_EnStatusMessage->setEnabled(false); 273 | ui->cb_TimestampDelay->setEnabled(false); 274 | 275 | // checked 276 | //ui->cb_AutoBusOff->setCheckState(Qt::Checked); 277 | //ui->cb_AutoBusOff->setChecked(true); 278 | 279 | ui->openButton->setEnabled(false); 280 | ui->closeButton->setEnabled(true); 281 | ui->startButton->setEnabled(false); 282 | ui->stopButton->setEnabled(true); 283 | ui->statusBar->showMessage("CANAL status: Open"); 284 | ui->label_RxFramesCnt->setText(QString::number(0)); 285 | ui->label_TxFramesCnt->setText(QString::number(0)); 286 | 287 | str = QString::fromStdString(CanalGetVendorString()); 288 | QStringList parts = str.split(';'); 289 | ui->label_Hardware->setText(parts.at(0)); 290 | ui->label_Firmware->setText(parts.at(1)); 291 | ui->label_Vendor->setText(parts.at(2)); 292 | 293 | if(CanalGetBootloaderVersion(m_drvHandle, &temp_u32) == CANAL_ERROR_SUCCESS) 294 | { 295 | str = QString("%1.%2.%3").arg(temp_u32>>24 & 0xFF).arg((temp_u32>>16) & 0xFF).arg(temp_u32>>8 & 0xFF); 296 | ui->label_Bootloader->setText(str); 297 | } 298 | else 299 | ui->label_Bootloader->setText("-"); 300 | 301 | ui->le_OpenParameters->setEnabled(false); 302 | ui->RxMsgTableView->setFocus(); 303 | 304 | TxMsgCnt = 0; 305 | } 306 | 307 | void MainWindow::WidgetValuesClose() 308 | { 309 | ui->startButton->setEnabled(false); 310 | ui->stopButton->setEnabled(false); 311 | ui->openButton->setEnabled(true); 312 | ui->closeButton->setEnabled(false); 313 | ui->statusBar->showMessage("CANAL status: Closed"); 314 | 315 | ui->label_Hardware->setText("-"); 316 | ui->label_Firmware->setText("-"); 317 | // ui->label_Canal->setText("-"); 318 | // ui->label_CanalDll->setText("-"); 319 | ui->label_Vendor->setText("-"); 320 | ui->label_Bootloader->setText("-"); 321 | 322 | ui->cb_SilentMode->setEnabled(true); 323 | ui->cb_LoopbackMode->setEnabled(true); 324 | ui->cb_DisRetransmition->setEnabled(true); 325 | ui->cb_WakeUpMode->setEnabled(true); 326 | ui->cb_AutoBusOff->setEnabled(true); 327 | ui->cb_TimMode->setEnabled(true); 328 | ui->cb_RxFifoLocked->setEnabled(true); 329 | ui->cb_TxFifoPriority->setEnabled(true); 330 | ui->cb_EnStatusMessage->setEnabled(true); 331 | ui->cb_TimestampDelay->setEnabled(true); 332 | 333 | ui->lb_ReceivedFrames->setText("0"); 334 | ui->lb_ReceivedData->setText("0"); 335 | ui->lb_TransmitedFrames->setText("0"); 336 | ui->lb_transmitedData->setText("0"); 337 | ui->lb_Overruns->setText("0"); 338 | ui->lb_Warnings->setText("0"); 339 | ui->lb_BussOff->setText("0"); 340 | 341 | ui->rb_filter_11bit_accept_all->setChecked(true); 342 | ui->rb_filter_29bit_accept_all->setChecked(true); 343 | 344 | ui->label_RxFramesCnt->setText(QString::number(0)); 345 | ui->label_TxFramesCnt->setText(QString::number(0)); 346 | 347 | ui->le_OpenParameters->setEnabled(true); 348 | 349 | TxMsgCnt = 0; 350 | } 351 | 352 | -------------------------------------------------------------------------------- /messagetypes.h: -------------------------------------------------------------------------------- 1 | #ifndef MESSAGETYPES_H 2 | #define MESSAGETYPES_H 3 | 4 | #include 5 | #include "canal.h" 6 | 7 | enum 8 | { 9 | insert = false, 10 | append = true 11 | }; 12 | 13 | 14 | /* analyzer message */ 15 | typedef struct _analyzerStat { 16 | qint32 count; 17 | qint64 time; 18 | qint64 diff_time; 19 | } analyzerStat; 20 | 21 | typedef struct _analyzerMsg{ 22 | canalMsg msg; 23 | analyzerStat stat; 24 | } analyzerMsg; 25 | 26 | /* stream message */ 27 | typedef struct _streamStat{ 28 | qint64 time; 29 | }streamStat; 30 | 31 | typedef struct _streamMsg{ 32 | canalMsg msg; 33 | streamStat stat; 34 | }streamMsg; 35 | 36 | /* transmit message */ 37 | 38 | typedef struct _transmitStat{ 39 | qint16 count; 40 | }transmitStat; 41 | 42 | typedef struct _transmitMsg{ 43 | canalMsg msg; 44 | transmitStat stat; 45 | }transmitMsg; 46 | 47 | #endif // MESSAGETYPES_H 48 | -------------------------------------------------------------------------------- /portablesleep.h: -------------------------------------------------------------------------------- 1 | #ifndef PORTABLESLEEP_H 2 | #define PORTABLESLEEP_H 3 | 4 | #ifdef _WIN32 5 | # include 6 | #else 7 | # include 8 | #endif 9 | 10 | class PortableSleep 11 | { 12 | public: 13 | static void msleep(unsigned int milliSec) 14 | { 15 | #ifdef _WIN32 16 | Sleep(milliSec); 17 | #else 18 | usleep(milliSec * 1000); 19 | #endif 20 | }; 21 | }; 22 | 23 | #endif // PORTABLESLEEP_H 24 | -------------------------------------------------------------------------------- /resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | img/Rusoku_Icon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /rxworkerthread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #include "rxworkerthread.h" 21 | #include "portablesleep.h" 22 | #include "mainwindow.h" 23 | #include 24 | #include 25 | 26 | 27 | //=========================== Infinite Thread =========================== 28 | RxWorkerThreadInfinite::RxWorkerThreadInfinite(int handler) : m_running(true) 29 | { 30 | m_drvHandle = handler; 31 | m_msg = new canalMsg; 32 | cnt = 0; 33 | } 34 | 35 | void RxWorkerThreadInfinite::stopWork() 36 | { 37 | m_running = false; 38 | } 39 | 40 | void RxWorkerThreadInfinite::resetRxCounter() 41 | { 42 | cnt = 0; 43 | } 44 | 45 | void RxWorkerThreadInfinite::doWork() 46 | { 47 | while(m_running) 48 | { 49 | //PortableSleep::msleep(1); 50 | //QThread::msleep(1); 51 | 52 | QCoreApplication::processEvents(); 53 | 54 | if(CanalBlockingReceive(m_drvHandle, m_msg , 100) == CANAL_ERROR_SUCCESS) 55 | { 56 | if(m_running) 57 | { 58 | if(++cnt < 10000000) emit updateInfiniteCount(cnt, *m_msg); 59 | } 60 | } 61 | } 62 | emit finished(); 63 | } 64 | 65 | //========================= Thread driving ========================= 66 | void MainWindow::startRxThread() 67 | { 68 | m_RxWorkerThread = new QThread; 69 | m_RxWorker = new RxWorkerThreadInfinite(m_drvHandle); 70 | m_RxWorker->moveToThread(m_RxWorkerThread); 71 | 72 | connect(m_RxWorkerThread, &QThread::started, m_RxWorker, &RxWorkerThreadInfinite::doWork); 73 | connect(m_RxWorker, &RxWorkerThreadInfinite::finished, m_RxWorkerThread, &QThread::quit); 74 | connect(m_RxWorker, &RxWorkerThreadInfinite::finished, m_RxWorker, &RxWorkerThreadInfinite::deleteLater); 75 | connect(m_RxWorkerThread, &QThread::finished, m_RxWorkerThread, &QThread::deleteLater); 76 | 77 | //connect(m_RxWorker, &RxWorkerThreadInfinite::updateInfiniteCount, this, &MainWindow::updateInfiniteCountStream); //Qt::BlockingQueuedConnection); 78 | connect(m_RxWorker, &RxWorkerThreadInfinite::updateInfiniteCount, m_RxTableModel, &RxFrameTable::updateFrame); 79 | 80 | connect(this, &MainWindow::stopRxThreadSignal, m_RxWorker, &RxWorkerThreadInfinite::stopWork);//GS 81 | connect(this, &MainWindow::resetRxThreadCounter, m_RxWorker, &RxWorkerThreadInfinite::resetRxCounter);//GS 82 | 83 | m_RxWorkerThread->start(); 84 | infiniteCountRunning = true; 85 | } 86 | 87 | void MainWindow::stopRxThread() 88 | { 89 | emit stopRxThreadSignal(); 90 | infiniteCountRunning = false; 91 | //m_workerThread->wait(150); 92 | } 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /rxworkerthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies TouCAN USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | 21 | #ifndef RXWORKERTHREAD_H 22 | #define RXWORKERTHREAD_H 23 | 24 | #include "canal.h" 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | //======================= RxWorkerThreadInfinite =================== 31 | class RxWorkerThreadInfinite : public QObject 32 | { 33 | Q_OBJECT 34 | 35 | public: 36 | explicit RxWorkerThreadInfinite(int handler); 37 | 38 | public slots: 39 | void doWork(); 40 | void stopWork(); 41 | void resetRxCounter(); 42 | 43 | signals: 44 | void updateInfiniteCount(quint32, canalMsg); 45 | void finished(); 46 | 47 | private: 48 | canalMsg *m_msg; 49 | int m_drvHandle; 50 | bool m_running; 51 | quint32 cnt; 52 | }; 53 | 54 | #endif // RXWORKERTHREAD_H 55 | -------------------------------------------------------------------------------- /txworkerthread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #include "txworkerthread.h" 21 | #include "portablesleep.h" 22 | #include "mainwindow.h" 23 | #include 24 | #include 25 | 26 | //=========================== Infinite Thread =========================== 27 | TxWorkerThreadInfinite::TxWorkerThreadInfinite(int handler, QVector *canalMSGlist) : m_running(true) 28 | { 29 | m_drvHandle = handler; 30 | m_msg = new transmitMsg; 31 | m_TxcanalMSGlist = canalMSGlist; 32 | m_MsgCnt = 0; 33 | } 34 | 35 | 36 | void TxWorkerThreadInfinite::doWork() 37 | { 38 | canalMsg TxMsg; 39 | qint32 count = 0; 40 | //qint16 delay; 41 | 42 | cnt = m_TxcanalMSGlist->count(); 43 | 44 | for(qint32 x=0; x < cnt; x++) 45 | { 46 | TxMsg = m_TxcanalMSGlist->at(x).msg; 47 | count = m_TxcanalMSGlist->at(x).stat.count; 48 | 49 | if(count > 999) 50 | count = 999; 51 | 52 | for(qint64 z=0; zprocessEvents(); 61 | } 62 | emit finished(); 63 | } 64 | 65 | 66 | //========================= Thread driving ========================= 67 | void MainWindow::startTxThread() 68 | { 69 | m_TxWorkerThread = new QThread; 70 | m_TxWorker = new TxWorkerThreadInfinite(m_drvHandle, m_TxMsgList); 71 | m_TxWorker->moveToThread(m_TxWorkerThread); 72 | 73 | /*pradeda darba*/ 74 | connect(m_TxWorkerThread, &QThread::started, m_TxWorker, &TxWorkerThreadInfinite::doWork); 75 | /* susinaikina abu */ 76 | connect(m_TxWorker, &TxWorkerThreadInfinite::finished, m_TxWorkerThread, &QThread::quit); 77 | connect(m_TxWorker, &TxWorkerThreadInfinite::finished, m_TxWorker, &TxWorkerThreadInfinite::deleteLater); 78 | connect(m_TxWorkerThread, &QThread::finished, m_TxWorkerThread, &QThread::deleteLater); 79 | 80 | /* po kiekvieno issiusto Msg signalina atvaizdavimui */ 81 | connect(m_TxWorker, &TxWorkerThreadInfinite::updateInfiniteTxCount, this, &MainWindow::updateInfiniteTxCount); // canal msg is sent 82 | m_TxWorkerThread->start(); 83 | } 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /txworkerthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CANAL view demo software for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB<=>CAN bus converter 3 | * 4 | * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published 8 | * by the Free Software Foundation; version 3.0 of the License. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along 16 | * with this program. 17 | * 18 | */ 19 | 20 | #ifndef TXWORKERTHREAD_H 21 | #define TXWORKERTHREAD_H 22 | 23 | #include "canal.h" 24 | #include "portablesleep.h" 25 | #include 26 | #include 27 | #include 28 | #include "messagetypes.h" 29 | 30 | 31 | //======================= RxWorkerThreadInfinite =================== 32 | class TxWorkerThreadInfinite : public QObject 33 | { 34 | Q_OBJECT 35 | 36 | public: 37 | explicit TxWorkerThreadInfinite(int handler, QVector *canalMSGlist); 38 | 39 | public slots: 40 | void doWork(); 41 | 42 | signals: 43 | void updateInfiniteTxCount(int); 44 | void finished(); 45 | void frameSent(); 46 | 47 | private: 48 | transmitMsg *m_msg; 49 | int m_drvHandle; 50 | bool m_running; 51 | int cnt, m_MsgCnt; 52 | QVector *m_TxcanalMSGlist; 53 | }; 54 | 55 | #endif // TXWORKERTHREAD_H 56 | --------------------------------------------------------------------------------