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
|
* CAN class to handle database of CAN signals from DBC (.dbc) file
|
||||||
*/
|
*/
|
||||||
class CanDatabase : public DbcParser {
|
class CanDatabase : public DbcParser {
|
||||||
// public data
|
// public data
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// private data
|
// private data
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// static data
|
// static data
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
CanDatabase();
|
CanDatabase();
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~CanDatabase();
|
virtual ~CanDatabase();
|
||||||
|
|
||||||
// virtual functions
|
// virtual functions
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
int FormatHeader( char *buf, int max );
|
int FormatHeader( char *buf, int max );
|
||||||
int FormatMessage( char *buf, int max );
|
int FormatMessage( char *buf, int max );
|
||||||
|
|
||||||
int SubscribeCan( CanSocket *pCan );
|
int SubscribeCan( CanSocket *pCan );
|
||||||
int ReadCan( CanSocket *pCan );
|
int ReadCan( CanSocket *pCan );
|
||||||
|
|
||||||
// static methods
|
// static methods
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -31,43 +31,43 @@
|
|||||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||||
//
|
//
|
||||||
class CanMessage {
|
class CanMessage {
|
||||||
// public data
|
// public data
|
||||||
public:
|
public:
|
||||||
std::string Name; // Signal Name
|
std::string Name; // Signal Name
|
||||||
std::string Module; // Module Name
|
std::string Module; // Module Name
|
||||||
u_int32_t Address; // 29 bits (standard or extended)
|
u_int32_t Address; // 29 bits (standard or extended)
|
||||||
u_int8_t Data[64]; // Data
|
u_int8_t Data[64]; // Data
|
||||||
u_int Size; // DLC (CAN-FD > 8)
|
u_int Size; // DLC (CAN-FD > 8)
|
||||||
|
|
||||||
|
|
||||||
// list of signals in the message
|
// list of signals in the message
|
||||||
std::vector<CanSignal *> Signals;
|
std::vector<CanSignal *> Signals;
|
||||||
|
|
||||||
// private data
|
// private data
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// static data
|
// static data
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
CanMessage();
|
CanMessage();
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~CanMessage();
|
virtual ~CanMessage();
|
||||||
|
|
||||||
// virtual functions
|
// virtual functions
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
int Read(CanFrame *frame);
|
int Read(CanFrame *frame);
|
||||||
int Write(CanFrame *frame);
|
int Write(CanFrame *frame);
|
||||||
int Convert(CanFrame *frame) {return Read(frame);};
|
int Convert(CanFrame *frame) {return Read(frame);};
|
||||||
int Subscribe(void);
|
int Subscribe(void);
|
||||||
int Unsubscribe(void);
|
int Unsubscribe(void);
|
||||||
|
|
||||||
// static methods
|
// static methods
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -38,11 +38,11 @@ class CanSignal : public BaseSignal, public VoltType {
|
|||||||
class CanSignal {
|
class CanSignal {
|
||||||
#endif
|
#endif
|
||||||
// public data
|
// public data
|
||||||
public:
|
public:
|
||||||
std::string Name; // Signal Name
|
std::string Name; // Signal Name
|
||||||
std::string Units; // Signal Units
|
std::string Units; // Signal Units
|
||||||
u_int32_t Address; // 29 bits (standard or extended)
|
u_int32_t Address; // 29 bits (standard or extended)
|
||||||
|
|
||||||
// data conversion (from .dbc file)
|
// data conversion (from .dbc file)
|
||||||
u_char StartBit; // 0..63
|
u_char StartBit; // 0..63
|
||||||
u_char NumBits; // 1..32
|
u_char NumBits; // 1..32
|
||||||
@ -50,7 +50,7 @@ public:
|
|||||||
u_char IsSigned; // 0 = unsigned, 1 = 2's Complement
|
u_char IsSigned; // 0 = unsigned, 1 = 2's Complement
|
||||||
double Scale; // scale
|
double Scale; // scale
|
||||||
double Offset; // offset
|
double Offset; // offset
|
||||||
|
|
||||||
// conversion help
|
// conversion help
|
||||||
u_char StartByte; // 0..7
|
u_char StartByte; // 0..7
|
||||||
u_char NumBytes; // 1..4
|
u_char NumBytes; // 1..4
|
||||||
@ -58,7 +58,7 @@ public:
|
|||||||
u_char LowBit; // #bits after
|
u_char LowBit; // #bits after
|
||||||
u_int64_t Mask; // 64 bit mask
|
u_int64_t Mask; // 64 bit mask
|
||||||
u_int64_t Sign; // 64 bit sign mask
|
u_int64_t Sign; // 64 bit sign mask
|
||||||
|
|
||||||
// status, data
|
// status, data
|
||||||
u_char doSubscribe; // CanSocket filter
|
u_char doSubscribe; // CanSocket filter
|
||||||
u_char isNew;
|
u_char isNew;
|
||||||
@ -67,28 +67,28 @@ public:
|
|||||||
int64_t currValue;
|
int64_t currValue;
|
||||||
int64_t lastValue;
|
int64_t lastValue;
|
||||||
double realValue;
|
double realValue;
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
u_int64_t activity; // activity counter
|
u_int64_t activity; // activity counter
|
||||||
void *userData; // user data
|
void *userData; // user data
|
||||||
int userIndex; // user index
|
int userIndex; // user index
|
||||||
|
|
||||||
|
|
||||||
// private data
|
// private data
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// static data
|
// static data
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
CanSignal();
|
CanSignal();
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~CanSignal();
|
virtual ~CanSignal();
|
||||||
|
|
||||||
// virtual functions
|
// virtual functions
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
int Init( void );
|
int Init( void );
|
||||||
int Convert(CanFrame *frame) {return Read(frame->data);};
|
int Convert(CanFrame *frame) {return Read(frame->data);};
|
||||||
@ -100,17 +100,17 @@ public:
|
|||||||
long Write(double value, u_char *pbyData);
|
long Write(double value, u_char *pbyData);
|
||||||
void Subscribe(void) {doSubscribe=1;};
|
void Subscribe(void) {doSubscribe=1;};
|
||||||
void Unsubscribe(void) {doSubscribe=0;};
|
void Unsubscribe(void) {doSubscribe=0;};
|
||||||
|
|
||||||
#ifndef __VoltType__
|
#ifndef __VoltType__
|
||||||
void SetScaling( double scale=1.0, double offset=0.0 ) { Scale=scale; Offset=offset; };
|
void SetScaling( double scale=1.0, double offset=0.0 ) { Scale=scale; Offset=offset; };
|
||||||
double GetScale( void ) { return Scale; };
|
double GetScale( void ) { return Scale; };
|
||||||
double GetOffset( void ) { return Offset; };
|
double GetOffset( void ) { return Offset; };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// static methods
|
// static methods
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -32,8 +32,8 @@ typedef struct can_filter CanFilter;
|
|||||||
typedef struct can_frame CanFrame;
|
typedef struct can_frame CanFrame;
|
||||||
|
|
||||||
typedef struct _BcmFrame {
|
typedef struct _BcmFrame {
|
||||||
struct bcm_msg_head head;
|
struct bcm_msg_head head;
|
||||||
struct can_frame frame;
|
// struct can_frame frame;
|
||||||
} BcmFrame;
|
} BcmFrame;
|
||||||
|
|
||||||
/* c class definitions ******************************************************/
|
/* c class definitions ******************************************************/
|
||||||
@ -42,60 +42,60 @@ typedef struct _BcmFrame {
|
|||||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||||
//
|
//
|
||||||
class CanSocket {
|
class CanSocket {
|
||||||
// public data
|
// public data
|
||||||
public:
|
public:
|
||||||
int m_sock;
|
int m_sock;
|
||||||
int m_proto;
|
int m_proto;
|
||||||
|
|
||||||
// private data
|
// private data
|
||||||
private:
|
private:
|
||||||
// device
|
// device
|
||||||
int m_flags;
|
int m_flags;
|
||||||
|
|
||||||
// errors
|
// errors
|
||||||
bool m_logerrs;
|
bool m_logerrs;
|
||||||
long m_errcount;
|
long m_errcount;
|
||||||
|
|
||||||
// static data
|
// static data
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
CanSocket();
|
CanSocket();
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~CanSocket();
|
virtual ~CanSocket();
|
||||||
|
|
||||||
// virtual functions
|
// virtual functions
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
void AddrFlags( u_long f ) { m_flags = f; };
|
void AddrFlags( u_long f ) { m_flags = f; };
|
||||||
int GetSock(void) {return m_sock;};
|
int GetSock(void) {return m_sock;};
|
||||||
int GetSocket(void) {return m_sock;};
|
int GetSocket(void) {return m_sock;};
|
||||||
int GetProto(void) {return m_proto;};
|
int GetProto(void) {return m_proto;};
|
||||||
int CanOpen( const char *dev="can0", int proto=CAN_RAW, int flags=0 );
|
int CanOpen( const char *dev="can0", int proto=CAN_RAW, int flags=0 );
|
||||||
void CanClose(void);
|
void CanClose(void);
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
int ClearFilters( void );
|
int ClearFilters( void );
|
||||||
int Blocking(bool block=true);
|
int Blocking(bool block=true);
|
||||||
int NonBlocking(void) { return Blocking(false); };
|
int NonBlocking(void) { return Blocking(false); };
|
||||||
int Loopback(bool loop=true);
|
int Loopback(bool loop=true);
|
||||||
int NoLoopback(void) { return Loopback(false); };
|
int NoLoopback(void) { return Loopback(false); };
|
||||||
void LogErrors(bool logerrs=true) {m_logerrs = logerrs;};
|
void LogErrors(bool logerrs=true) {m_logerrs = logerrs;};
|
||||||
|
|
||||||
// rx filter
|
// rx filter
|
||||||
int CanAddRx( u_int32_t addr );
|
int CanAddRx( u_int32_t addr );
|
||||||
int CanAddRx( const CanFilter *filter, int max=1 );
|
int CanAddRx( const CanFilter *filter, int max=1 );
|
||||||
int CanDelRx( u_int32_t addr );
|
int CanDelRx( u_int32_t addr );
|
||||||
|
|
||||||
// raw
|
// raw
|
||||||
int CanRawRead( CanFrame *buf, int max=1 );
|
int CanRawRead( CanFrame *buf, int max=1 );
|
||||||
int CanRawWrite( const CanFrame *buf, int max=1 );
|
int CanRawWrite( const CanFrame *buf, int max=1 );
|
||||||
|
|
||||||
// bcm
|
// bcm
|
||||||
int CanBcmRead( BcmFrame *msg, int max=1 );
|
int CanBcmRead( BcmFrame *msg, int max=1 );
|
||||||
int CanBcmWrite( BcmFrame *msg, int max=1 );
|
int CanBcmWrite( BcmFrame *msg, int max=1 );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -24,19 +24,19 @@
|
|||||||
|
|
||||||
// based on .dbc data
|
// based on .dbc data
|
||||||
typedef struct _DbcFilter {
|
typedef struct _DbcFilter {
|
||||||
// signal information
|
// signal information
|
||||||
char Name[32]; // Signal name
|
char Name[32]; // Signal name
|
||||||
regex_t preg;
|
regex_t preg;
|
||||||
|
|
||||||
// address range
|
// address range
|
||||||
u_int32_t CanAddrLo; // 29 bits
|
u_int32_t CanAddrLo; // 29 bits
|
||||||
u_int32_t CanAddrHi;
|
u_int32_t CanAddrHi;
|
||||||
|
|
||||||
// data conversion
|
// data conversion
|
||||||
u_char StartBit; // 0..63
|
u_char StartBit; // 0..63
|
||||||
u_char NumBits; // 1..32
|
u_char NumBits; // 1..32
|
||||||
|
|
||||||
int found;
|
int found;
|
||||||
} DbcFilter;
|
} DbcFilter;
|
||||||
|
|
||||||
/* c class definitions ******************************************************/
|
/* c class definitions ******************************************************/
|
||||||
@ -45,42 +45,42 @@ typedef struct _DbcFilter {
|
|||||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||||
//
|
//
|
||||||
class DbcParser {
|
class DbcParser {
|
||||||
// public data
|
// public data
|
||||||
public:
|
public:
|
||||||
std::vector<DbcFilter *> MsgFilters; // message filter
|
std::vector<DbcFilter *> MsgFilters; // message filter
|
||||||
std::vector<DbcFilter *> SigFilters; // signal filter
|
std::vector<DbcFilter *> SigFilters; // signal filter
|
||||||
std::vector<CanMessage *> Messages;
|
std::vector<CanMessage *> Messages;
|
||||||
std::vector<CanSignal *> Signals;
|
std::vector<CanSignal *> Signals;
|
||||||
|
|
||||||
// private data
|
// private data
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// static data
|
// static data
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
DbcFilter *AddFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
DbcFilter *AddFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
DbcParser();
|
DbcParser();
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~DbcParser();
|
virtual ~DbcParser();
|
||||||
|
|
||||||
// virtual functions
|
// virtual functions
|
||||||
|
|
||||||
// public methods
|
// public methods
|
||||||
int AddMsgFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
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 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 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 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:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,8 @@ set(LIBSRC
|
|||||||
# includes
|
# includes
|
||||||
include_directories(../include)
|
include_directories(../include)
|
||||||
|
|
||||||
|
add_compile_options(-Warray-bounds)
|
||||||
|
|
||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../lib)
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../lib)
|
||||||
set(CMAKE_LIBRARY_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
|
// mask
|
||||||
msg.head.nframes = 1;
|
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
|
// send it down
|
||||||
if (write(m_sock, &msg, sizeof(msg)) < 0)
|
if (write(m_sock, &msg, sizeof(msg)) < 0)
|
||||||
|
|||||||
@ -33,7 +33,7 @@ typedef struct can_frame CanFrame;
|
|||||||
|
|
||||||
typedef struct _BcmFrame {
|
typedef struct _BcmFrame {
|
||||||
struct bcm_msg_head head;
|
struct bcm_msg_head head;
|
||||||
struct can_frame frame;
|
// struct can_frame frame;
|
||||||
} BcmFrame;
|
} BcmFrame;
|
||||||
|
|
||||||
/* c class definitions ******************************************************/
|
/* c class definitions ******************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user