00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CANMSG_INCLUDEDEF_H
00023 #define CANMSG_INCLUDEDEF_H
00024
00025
00026
00027 #include <stdint.h>
00028 #define BYTE uint8_t
00029
00030 #include <iostream>
00031
00032
00037 class CanMsg
00038 {
00039 public:
00041 int m_iID;
00043 int m_iLen;
00045 int m_iType;
00046
00047 protected:
00051 BYTE m_bDat[8];
00052
00053 public:
00057 CanMsg()
00058 {
00059 m_iID = 0;
00060 m_iLen = 8;
00061 m_iType = 0x00;
00062 }
00063
00067 void set(BYTE Data0=0, BYTE Data1=0, BYTE Data2=0, BYTE Data3=0, BYTE Data4=0, BYTE Data5=0, BYTE Data6=0, BYTE Data7=0)
00068 {
00069 m_bDat[0] = Data0;
00070 m_bDat[1] = Data1;
00071 m_bDat[2] = Data2;
00072 m_bDat[3] = Data3;
00073 m_bDat[4] = Data4;
00074 m_bDat[5] = Data5;
00075 m_bDat[6] = Data6;
00076 m_bDat[7] = Data7;
00077 }
00078
00082 void setAt(BYTE data, int iNr)
00083 {
00084 m_bDat[iNr] = data;
00085 }
00086
00090 void get(BYTE* pData0, BYTE* pData1, BYTE* pData2, BYTE* pData3, BYTE* pData4, BYTE* pData5, BYTE* pData6, BYTE* pData7)
00091 {
00092 *pData0 = m_bDat[0];
00093 *pData1 = m_bDat[1];
00094 *pData2 = m_bDat[2];
00095 *pData3 = m_bDat[3];
00096 *pData4 = m_bDat[4];
00097 *pData5 = m_bDat[5];
00098 *pData6 = m_bDat[6];
00099 *pData7 = m_bDat[7];
00100 }
00101
00106 int getAt(int iNr)
00107 {
00108 return m_bDat[iNr];
00109 }
00110
00115 int printCanIdentMsgStatus()
00116 {
00117 if(getStatus() == 0)
00118 {
00119 std::cout <<"ID= " << m_iID << " " << "Cmd= " << getCmd() << " " << "Msg_OK" << std::endl;
00120 return 0;
00121 }
00122 else
00123 {
00124 std::cout << "ID= " << m_iID << " " << "Cmd= " << getCmd() << " " << "Msg_Error" << std::endl;
00125 return -1;
00126 }
00127 }
00128
00132 void print()
00133 {
00134 std::cout << "id= " << m_iID << " type= " << m_iType << " len= " << m_iLen << " data= " <<
00135 (int)m_bDat[0] << " " << (int)m_bDat[1] << " " << (int)m_bDat[2] << " " << (int)m_bDat[3] << " " <<
00136 (int)m_bDat[4] << " " << (int)m_bDat[5] << " " << (int)m_bDat[6] << " " << (int)m_bDat[7] << std::endl;
00137 }
00138
00142 int getStatus()
00143 {
00144
00145 return (int)(m_bDat[7] & 0x0003);
00146 }
00147
00151 int getCmd()
00152 {
00153 return (m_bDat[7] >> 2);
00154 }
00155
00160 int getID()
00161 {
00162 return m_iID;
00163 }
00164
00170 void setID(int id)
00171 {
00172 if( (0 <= id) && (id <= 2047) )
00173 m_iID = id;
00174 }
00175
00180 int getLength()
00181 {
00182 return m_iLen;
00183 }
00184
00189 void setLength(int len)
00190 {
00191 if( (0 <= len) && (len <= 8) )
00192 m_iLen = len;
00193 }
00194
00199 int getType()
00200 {
00201 return m_iType;
00202 }
00203
00208 void setType(int type)
00209 {
00210 m_iType = type;
00211 }
00212
00213
00214 };
00215
00216 #endif