Fixed CAN frame bug
This commit is contained in:
@ -29,34 +29,34 @@
|
||||
* CAN class to handle database of CAN signals from DBC (.dbc) file
|
||||
*/
|
||||
class CanDatabase : public DbcParser {
|
||||
// public data
|
||||
// public data
|
||||
public:
|
||||
|
||||
// private data
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
CanDatabase();
|
||||
// constructors
|
||||
CanDatabase();
|
||||
|
||||
// destructor
|
||||
virtual ~CanDatabase();
|
||||
// destructor
|
||||
virtual ~CanDatabase();
|
||||
|
||||
// virtual functions
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int FormatHeader( char *buf, int max );
|
||||
int FormatMessage( char *buf, int max );
|
||||
// public methods
|
||||
int FormatHeader( char *buf, int max );
|
||||
int FormatMessage( char *buf, int max );
|
||||
|
||||
int SubscribeCan( CanSocket *pCan );
|
||||
int ReadCan( CanSocket *pCan );
|
||||
int SubscribeCan( CanSocket *pCan );
|
||||
int ReadCan( CanSocket *pCan );
|
||||
|
||||
// static methods
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
@ -31,43 +31,43 @@
|
||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||
//
|
||||
class CanMessage {
|
||||
// public data
|
||||
// public data
|
||||
public:
|
||||
std::string Name; // Signal Name
|
||||
std::string Module; // Module Name
|
||||
u_int32_t Address; // 29 bits (standard or extended)
|
||||
u_int8_t Data[64]; // Data
|
||||
u_int Size; // DLC (CAN-FD > 8)
|
||||
std::string Name; // Signal Name
|
||||
std::string Module; // Module Name
|
||||
u_int32_t Address; // 29 bits (standard or extended)
|
||||
u_int8_t Data[64]; // Data
|
||||
u_int Size; // DLC (CAN-FD > 8)
|
||||
|
||||
|
||||
// list of signals in the message
|
||||
std::vector<CanSignal *> Signals;
|
||||
// list of signals in the message
|
||||
std::vector<CanSignal *> Signals;
|
||||
|
||||
// private data
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
CanMessage();
|
||||
// constructors
|
||||
CanMessage();
|
||||
|
||||
// destructor
|
||||
virtual ~CanMessage();
|
||||
// destructor
|
||||
virtual ~CanMessage();
|
||||
|
||||
// virtual functions
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int Read(CanFrame *frame);
|
||||
int Write(CanFrame *frame);
|
||||
int Convert(CanFrame *frame) {return Read(frame);};
|
||||
int Subscribe(void);
|
||||
int Unsubscribe(void);
|
||||
// public methods
|
||||
int Read(CanFrame *frame);
|
||||
int Write(CanFrame *frame);
|
||||
int Convert(CanFrame *frame) {return Read(frame);};
|
||||
int Subscribe(void);
|
||||
int Unsubscribe(void);
|
||||
|
||||
// static methods
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ class CanSignal : public BaseSignal, public VoltType {
|
||||
class CanSignal {
|
||||
#endif
|
||||
// public data
|
||||
public:
|
||||
public:
|
||||
std::string Name; // Signal Name
|
||||
std::string Units; // Signal Units
|
||||
u_int32_t Address; // 29 bits (standard or extended)
|
||||
@ -75,12 +75,12 @@ public:
|
||||
|
||||
|
||||
// private data
|
||||
private:
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
public:
|
||||
// constructors
|
||||
CanSignal();
|
||||
|
||||
@ -110,7 +110,7 @@ public:
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -32,8 +32,8 @@ typedef struct can_filter CanFilter;
|
||||
typedef struct can_frame CanFrame;
|
||||
|
||||
typedef struct _BcmFrame {
|
||||
struct bcm_msg_head head;
|
||||
struct can_frame frame;
|
||||
struct bcm_msg_head head;
|
||||
// struct can_frame frame;
|
||||
} BcmFrame;
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
@ -42,60 +42,60 @@ typedef struct _BcmFrame {
|
||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||
//
|
||||
class CanSocket {
|
||||
// public data
|
||||
// public data
|
||||
public:
|
||||
int m_sock;
|
||||
int m_proto;
|
||||
int m_sock;
|
||||
int m_proto;
|
||||
|
||||
// private data
|
||||
// private data
|
||||
private:
|
||||
// device
|
||||
int m_flags;
|
||||
// device
|
||||
int m_flags;
|
||||
|
||||
// errors
|
||||
bool m_logerrs;
|
||||
long m_errcount;
|
||||
// errors
|
||||
bool m_logerrs;
|
||||
long m_errcount;
|
||||
|
||||
// static data
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
CanSocket();
|
||||
// constructors
|
||||
CanSocket();
|
||||
|
||||
// destructor
|
||||
virtual ~CanSocket();
|
||||
// destructor
|
||||
virtual ~CanSocket();
|
||||
|
||||
// virtual functions
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
void AddrFlags( u_long f ) { m_flags = f; };
|
||||
int GetSock(void) {return m_sock;};
|
||||
int GetSocket(void) {return m_sock;};
|
||||
int GetProto(void) {return m_proto;};
|
||||
int CanOpen( const char *dev="can0", int proto=CAN_RAW, int flags=0 );
|
||||
void CanClose(void);
|
||||
// public methods
|
||||
void AddrFlags( u_long f ) { m_flags = f; };
|
||||
int GetSock(void) {return m_sock;};
|
||||
int GetSocket(void) {return m_sock;};
|
||||
int GetProto(void) {return m_proto;};
|
||||
int CanOpen( const char *dev="can0", int proto=CAN_RAW, int flags=0 );
|
||||
void CanClose(void);
|
||||
|
||||
// misc
|
||||
int ClearFilters( void );
|
||||
int Blocking(bool block=true);
|
||||
int NonBlocking(void) { return Blocking(false); };
|
||||
int Loopback(bool loop=true);
|
||||
int NoLoopback(void) { return Loopback(false); };
|
||||
void LogErrors(bool logerrs=true) {m_logerrs = logerrs;};
|
||||
// misc
|
||||
int ClearFilters( void );
|
||||
int Blocking(bool block=true);
|
||||
int NonBlocking(void) { return Blocking(false); };
|
||||
int Loopback(bool loop=true);
|
||||
int NoLoopback(void) { return Loopback(false); };
|
||||
void LogErrors(bool logerrs=true) {m_logerrs = logerrs;};
|
||||
|
||||
// rx filter
|
||||
int CanAddRx( u_int32_t addr );
|
||||
int CanAddRx( const CanFilter *filter, int max=1 );
|
||||
int CanDelRx( u_int32_t addr );
|
||||
// rx filter
|
||||
int CanAddRx( u_int32_t addr );
|
||||
int CanAddRx( const CanFilter *filter, int max=1 );
|
||||
int CanDelRx( u_int32_t addr );
|
||||
|
||||
// raw
|
||||
int CanRawRead( CanFrame *buf, int max=1 );
|
||||
int CanRawWrite( const CanFrame *buf, int max=1 );
|
||||
// raw
|
||||
int CanRawRead( CanFrame *buf, int max=1 );
|
||||
int CanRawWrite( const CanFrame *buf, int max=1 );
|
||||
|
||||
// bcm
|
||||
int CanBcmRead( BcmFrame *msg, int max=1 );
|
||||
int CanBcmWrite( BcmFrame *msg, int max=1 );
|
||||
// bcm
|
||||
int CanBcmRead( BcmFrame *msg, int max=1 );
|
||||
int CanBcmWrite( BcmFrame *msg, int max=1 );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -24,19 +24,19 @@
|
||||
|
||||
// based on .dbc data
|
||||
typedef struct _DbcFilter {
|
||||
// signal information
|
||||
char Name[32]; // Signal name
|
||||
regex_t preg;
|
||||
// signal information
|
||||
char Name[32]; // Signal name
|
||||
regex_t preg;
|
||||
|
||||
// address range
|
||||
u_int32_t CanAddrLo; // 29 bits
|
||||
u_int32_t CanAddrHi;
|
||||
// address range
|
||||
u_int32_t CanAddrLo; // 29 bits
|
||||
u_int32_t CanAddrHi;
|
||||
|
||||
// data conversion
|
||||
u_char StartBit; // 0..63
|
||||
u_char NumBits; // 1..32
|
||||
// data conversion
|
||||
u_char StartBit; // 0..63
|
||||
u_char NumBits; // 1..32
|
||||
|
||||
int found;
|
||||
int found;
|
||||
} DbcFilter;
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
@ -45,42 +45,42 @@ typedef struct _DbcFilter {
|
||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||
//
|
||||
class DbcParser {
|
||||
// public data
|
||||
// public data
|
||||
public:
|
||||
std::vector<DbcFilter *> MsgFilters; // message filter
|
||||
std::vector<DbcFilter *> SigFilters; // signal filter
|
||||
std::vector<CanMessage *> Messages;
|
||||
std::vector<CanSignal *> Signals;
|
||||
std::vector<DbcFilter *> MsgFilters; // message filter
|
||||
std::vector<DbcFilter *> SigFilters; // signal filter
|
||||
std::vector<CanMessage *> Messages;
|
||||
std::vector<CanSignal *> Signals;
|
||||
|
||||
// private data
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
// static data
|
||||
|
||||
// private methods
|
||||
DbcFilter *AddFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||
// private methods
|
||||
DbcFilter *AddFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||
|
||||
// public methods
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
DbcParser();
|
||||
// constructors
|
||||
DbcParser();
|
||||
|
||||
// destructor
|
||||
virtual ~DbcParser();
|
||||
// destructor
|
||||
virtual ~DbcParser();
|
||||
|
||||
// virtual functions
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int AddMsgFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||
int AddSigFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||
int AddMessage( char *name, u_int32_t addr, u_int32_t size, char *module );
|
||||
int AddSignal( char *name, char *units, u_int32_t addr, char start, char num, char endian, char sign, float scale, float offset );
|
||||
// public methods
|
||||
int AddMsgFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||
int AddSigFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||
int AddMessage( char *name, u_int32_t addr, u_int32_t size, char *module );
|
||||
int AddSignal( char *name, char *units, u_int32_t addr, char start, char num, char endian, char sign, float scale, float offset );
|
||||
|
||||
int LoadDatabase( const char *file );
|
||||
int LoadDatabase( const char *file );
|
||||
|
||||
// static methods
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
@ -28,6 +28,8 @@ set(LIBSRC
|
||||
# includes
|
||||
include_directories(../include)
|
||||
|
||||
add_compile_options(-Warray-bounds)
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../lib)
|
||||
|
||||
|
||||
@ -255,7 +255,7 @@ int CanSocket::CanAddRx( u_int32_t addr )
|
||||
|
||||
// mask
|
||||
msg.head.nframes = 1;
|
||||
U64_DATA(&msg.frame) = (__u64) 0xFFFFFFFFFFFFFFFFULL; // all 64 bits
|
||||
U64_DATA(&msg.head.frames[0]) = (__u64) 0xFFFFFFFFFFFFFFFFULL; // all 64 bits
|
||||
|
||||
// send it down
|
||||
if (write(m_sock, &msg, sizeof(msg)) < 0)
|
||||
|
||||
@ -33,7 +33,7 @@ typedef struct can_frame CanFrame;
|
||||
|
||||
typedef struct _BcmFrame {
|
||||
struct bcm_msg_head head;
|
||||
struct can_frame frame;
|
||||
// struct can_frame frame;
|
||||
} BcmFrame;
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
Reference in New Issue
Block a user