Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CANMSG_INCLUDEDEF_H
00019 #define CANMSG_INCLUDEDEF_H
00020
00021 #include <iostream>
00022
00023
00028 class CanMsg
00029 {
00030 public:
00032 typedef unsigned char BYTE;
00034 int m_iID;
00036 int m_iLen;
00038 int m_iType;
00039
00040 protected:
00044 BYTE m_bDat[8];
00045
00046 public:
00050 CanMsg()
00051 {
00052 m_iID = 0;
00053 m_iLen = 8;
00054 m_iType = 0x00;
00055 }
00056
00060 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)
00061 {
00062 m_bDat[0] = Data0;
00063 m_bDat[1] = Data1;
00064 m_bDat[2] = Data2;
00065 m_bDat[3] = Data3;
00066 m_bDat[4] = Data4;
00067 m_bDat[5] = Data5;
00068 m_bDat[6] = Data6;
00069 m_bDat[7] = Data7;
00070 }
00071
00075 void setAt(BYTE data, int iNr)
00076 {
00077 m_bDat[iNr] = data;
00078 }
00079
00083 void get(BYTE* pData0, BYTE* pData1, BYTE* pData2, BYTE* pData3, BYTE* pData4, BYTE* pData5, BYTE* pData6, BYTE* pData7)
00084 {
00085 *pData0 = m_bDat[0];
00086 *pData1 = m_bDat[1];
00087 *pData2 = m_bDat[2];
00088 *pData3 = m_bDat[3];
00089 *pData4 = m_bDat[4];
00090 *pData5 = m_bDat[5];
00091 *pData6 = m_bDat[6];
00092 *pData7 = m_bDat[7];
00093 }
00094
00099 int getAt(int iNr)
00100 {
00101 return m_bDat[iNr];
00102 }
00103
00108 int printCanIdentMsgStatus()
00109 {
00110 if(getStatus() == 0)
00111 {
00112 std::cout << "ID= " << m_iID << " " << "Cmd= " << getCmd() << " " << "Msg_OK" << std::endl;
00113 return 0;
00114 }
00115 else
00116 {
00117 std::cout << "ID= " << m_iID << " " << "Cmd= " << getCmd() << " " << "Msg_Error" << std::endl;
00118 return -1;
00119 }
00120 }
00121
00125 void print()
00126 {
00127 std::cout << "id= " << m_iID << " type= " << m_iType << " len= " << m_iLen << " data= " <<
00128 (int)m_bDat[0] << " " << (int)m_bDat[1] << " " << (int)m_bDat[2] << " " << (int)m_bDat[3] << " " <<
00129 (int)m_bDat[4] << " " << (int)m_bDat[5] << " " << (int)m_bDat[6] << " " << (int)m_bDat[7] << std::endl;
00130 }
00131
00135 int getStatus()
00136 {
00137
00138 return (int)(m_bDat[7] & 0x0003);
00139 }
00140
00144 int getCmd()
00145 {
00146 return (m_bDat[7] >> 2);
00147 }
00148
00153 int getID()
00154 {
00155 return m_iID;
00156 }
00157
00163 void setID(int id)
00164 {
00165 if( (0 <= id) && (id <= 2047) )
00166 m_iID = id;
00167 }
00168
00173 int getLength()
00174 {
00175 return m_iLen;
00176 }
00177
00182 void setLength(int len)
00183 {
00184 if( (0 <= len) && (len <= 8) )
00185 m_iLen = len;
00186 }
00187
00192 int getType()
00193 {
00194 return m_iType;
00195 }
00196
00201 void setType(int type)
00202 {
00203 m_iType = type;
00204 }
00205
00206
00207 };
00208
00209 #endif