Browse Source

change cherrysigdecode for compile in ubuntu 20.04.

yuchuli 1 month ago
parent
commit
7999d74ef5

+ 13 - 0
src/test/testcandbc/cherrysigdecode.pro

@@ -4,6 +4,10 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
 CONFIG += c++17
 
+
+
+UBUNTU_VERSION=$$system(UBUNTU_VERSION=$(lsb_release -sr);echo "$UBUNTU_VERSION";)
+
 # You can make your code fail to compile if it uses deprecated APIs.
 # In order to do so, uncomment the following line.
 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
@@ -25,10 +29,19 @@ qnx: target.path = /tmp/$${TARGET}/bin
 else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target
 
+
 !include(../../../include/common.pri ) {
     error( "Couldn't find the common.pri file!" )
 }
 
+contains(UBUNTU_VERSION, "20.04") {
+    DEFINES += OLDCAN
+}
+
+contains(UBUNTU_VERSION, "18.04") {
+    DEFINES += OLDCAN
+}
+
 DEFINES += CHERRYSIGDECODE
 
 LIBS += -lcandbc

+ 39 - 6
src/test/testcandbc/lib.c

@@ -63,6 +63,7 @@ const char hex_asc_upper[] = "0123456789ABCDEF";
 #define hex_asc_upper_lo(x) hex_asc_upper[((x)&0x0F)]
 #define hex_asc_upper_hi(x) hex_asc_upper[((x)&0xF0) >> 4]
 
+
 static inline void put_hex_byte(char *buf, __u8 byte)
 {
 	buf[0] = hex_asc_upper_hi(byte);
@@ -219,13 +220,21 @@ int parse_canframe(char *cs, cu_t *cu)
 
 		/* check for optional DLC value for CAN 2.0B frames */
 		if (cs[++idx] && (tmp = asc2nibble(cs[idx++])) <= CAN_MAX_DLEN) {
+#ifdef OLDCAN
+            cu->cc.can_dlc = tmp;
+#else
 			cu->cc.len = tmp;
+#endif
 
 			/* check for optional raw DLC value for CAN 2.0B frames */
 			if ((tmp == CAN_MAX_DLEN) && (cs[idx++] == CC_DLC_DELIM)) {
 				tmp = asc2nibble(cs[idx]);
 				if ((tmp > CAN_MAX_DLEN) && (tmp <= CAN_MAX_RAW_DLC))
-					cu->cc.len8_dlc = tmp;
+#ifdef OLDCAN
+            cu->cc.can_dlc = tmp;
+#else
+            cu->cc.len = tmp;
+#endif
 			}
 		}
 		return mtu;
@@ -307,7 +316,13 @@ int parse_canframe(char *cs, cu_t *cu)
 		unsigned char dlc = asc2nibble(cs[idx]);
 
 		if ((dlc > CAN_MAX_DLEN) && (dlc <= CAN_MAX_RAW_DLC))
-			cu->cc.len8_dlc = dlc;
+        {
+#ifdef OLDCAN
+            cu->cc.can_dlc = dlc;
+#else
+            cu->cc.len = dlc;
+#endif
+        }
 	}
 
 	return mtu;
@@ -394,9 +409,19 @@ int snprintf_canframe(char *buf, size_t size, cu_t *cu, int sep)
 
 			/* check for optional raw DLC value for CAN 2.0B frames */
 			if (len == CAN_MAX_DLEN) {
-				if ((cu->cc.len8_dlc > CAN_MAX_DLEN) && (cu->cc.len8_dlc <= CAN_MAX_RAW_DLC)) {
+#ifdef OLDCAN
+                if ((cu->cc.can_dlc > CAN_MAX_DLEN) && (cu->cc.can_dlc <= CAN_MAX_RAW_DLC))
+#else
+                if ((cu->cc.len8_dlc > CAN_MAX_DLEN) && (cu->cc.len8_dlc <= CAN_MAX_RAW_DLC))
+#endif
+                {
 					buf[offset++] = CC_DLC_DELIM;
-					buf[offset++] = hex_asc_upper_lo(cu->cc.len8_dlc);
+#ifdef OLDCAN
+                    buf[offset++] = hex_asc_upper_lo(cu->cc.can_dlc);
+#else
+                    buf[offset++] = hex_asc_upper_lo(cu->cc.len8_dlc);
+#endif
+
 				}
 			}
 		}
@@ -424,7 +449,11 @@ int snprintf_canframe(char *buf, size_t size, cu_t *cu, int sep)
 
 	/* check for extra DLC when having a Classic CAN with 8 bytes payload */
 	if (!is_canfd && (len == CAN_MAX_DLEN)) {
-		unsigned char dlc = cu->cc.len8_dlc;
+#ifdef OLDCAN
+        unsigned char dlc = cu->cc.can_dlc;
+#else
+        unsigned char dlc = cu->cc.len8_dlc;
+#endif
 
 		if ((dlc > CAN_MAX_DLEN) && (dlc <= CAN_MAX_RAW_DLC)) {
 			buf[offset++] = CC_DLC_DELIM;
@@ -557,7 +586,11 @@ int snprintf_long_canframe(char *buf, size_t size, cu_t *cu, int view)
 	/* The len value is sanitized (see above) */
 	if (!is_canfd) {
 		if (view & CANLIB_VIEW_LEN8_DLC) {
-			unsigned char dlc = cu->cc.len8_dlc;
+#ifdef OLDCAN
+            unsigned char dlc = cu->cc.can_dlc;
+#else
+            unsigned char dlc = cu->cc.len8_dlc;
+#endif
 
 			/* fall back to len if we don't have a valid DLC > 8 */
 			if (!((len == CAN_MAX_DLEN) && (dlc > CAN_MAX_DLEN) &&

+ 8 - 0
src/test/testcandbc/lib.h

@@ -215,6 +215,14 @@ int snprintf_canframe(char *buf, size_t size, cu_t *cu, int sep);
 #define CANLIB_VIEW_INDENT_SFF	0x10
 #define CANLIB_VIEW_LEN8_DLC	0x20
 
+#ifndef CAN_MAX_RAW_DLC
+#define CAN_MAX_RAW_DLC 15
+#endif
+
+#ifndef CANFD_FDF
+#define CANFD_FDF 0x04
+#endif
+
 #define SWAP_DELIMITER '`'
 
 int snprintf_long_canframe(char *buf, size_t size, cu_t *cu, int view);

+ 1 - 0
src/test/testcandbc/main.cpp

@@ -2,6 +2,7 @@
 
 #include <QApplication>
 
+
 // #include <map>
 
 // void testmap()

+ 25 - 0
src/test/testcandbc/mainwindow.cpp

@@ -7,6 +7,10 @@
 
 #include <linux/can.h>
 
+#include <QTextStream>
+
+#include <sstream>
+
 extern "C"
 {
 #include "lib.h"
@@ -130,7 +134,13 @@ bool MainWindow::parsedumpline(char *strline,struct CanFrame & xFrame)
 {
     xFrame.dat.clear();
     QString str(strline);
+#if QT_VERSION_MAJOR==5 && QT_VERSION_MINOR<15
+    QStringList strlist = str.split(" ",QString::SkipEmptyParts);
+#endif
+
+#if (QT_VERSION_MAJOR==5 && QT_VERSION_MINOR==15)||(QT_VERSION_MAJOR>5)
     QStringList strlist = str.split(" ",Qt::SkipEmptyParts);
+#endif
 
     if(strlist.size() >= 2)
     {
@@ -217,7 +227,15 @@ bool MainWindow::parselogline(char * strline,struct CanFrame & xFrame)
 {
     xFrame.dat.clear();
     QString str(strline);
+#if QT_VERSION_MAJOR==5 && QT_VERSION_MINOR<15
+    QStringList strlist = str.split(" ",QString::SkipEmptyParts);
+#endif
+
+#if (QT_VERSION_MAJOR==5 && QT_VERSION_MINOR==15)||(QT_VERSION_MAJOR>5)
     QStringList strlist = str.split(" ",Qt::SkipEmptyParts);
+#endif
+
+
 
     // char device[22], afrbuf[AFRSZ];
     // unsigned long long sec, usec;
@@ -307,7 +325,14 @@ bool MainWindow::parseascline(char * strline,struct CanFrame & xFrame)
 {
     xFrame.dat.clear();
     QString str(strline);
+
+#if QT_VERSION_MAJOR==5 && QT_VERSION_MINOR<15
+    QStringList strlist = str.split(" ",QString::SkipEmptyParts);
+#endif
+
+#if (QT_VERSION_MAJOR==5 && QT_VERSION_MINOR==15)||(QT_VERSION_MAJOR>5)
     QStringList strlist = str.split(" ",Qt::SkipEmptyParts);
+#endif
 
     int npart = strlist.size();