CanMsg.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef CANMSG_INCLUDEDEF_H
19 #define CANMSG_INCLUDEDEF_H
20 //-----------------------------------------------
21 #include <iostream>
22 //-----------------------------------------------
23 
28 class CanMsg
29 {
30 public:
32  typedef unsigned char BYTE;
34  int m_iID;
36  int m_iLen;
38  int m_iType;
39 
40 protected:
44  BYTE m_bDat[8];
45 
46 public:
51  {
52  m_iID = 0;
53  m_iLen = 8;
54  m_iType = 0x00;
55  }
56 
60  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)
61  {
62  m_bDat[0] = Data0;
63  m_bDat[1] = Data1;
64  m_bDat[2] = Data2;
65  m_bDat[3] = Data3;
66  m_bDat[4] = Data4;
67  m_bDat[5] = Data5;
68  m_bDat[6] = Data6;
69  m_bDat[7] = Data7;
70  }
71 
75  void setAt(BYTE data, int iNr)
76  {
77  m_bDat[iNr] = data;
78  }
79 
83  void get(BYTE* pData0, BYTE* pData1, BYTE* pData2, BYTE* pData3, BYTE* pData4, BYTE* pData5, BYTE* pData6, BYTE* pData7)
84  {
85  *pData0 = m_bDat[0];
86  *pData1 = m_bDat[1];
87  *pData2 = m_bDat[2];
88  *pData3 = m_bDat[3];
89  *pData4 = m_bDat[4];
90  *pData5 = m_bDat[5];
91  *pData6 = m_bDat[6];
92  *pData7 = m_bDat[7];
93  }
94 
99  int getAt(int iNr)
100  {
101  return m_bDat[iNr];
102  }
103 
109  {
110  if(getStatus() == 0)
111  {
112  std::cout << "ID= " << m_iID << " " << "Cmd= " << getCmd() << " " << "Msg_OK" << std::endl;
113  return 0;
114  }
115  else
116  {
117  std::cout << "ID= " << m_iID << " " << "Cmd= " << getCmd() << " " << "Msg_Error" << std::endl;
118  return -1;
119  }
120  }
121 
125  void print()
126  {
127  std::cout << "id= " << m_iID << " type= " << m_iType << " len= " << m_iLen << " data= " <<
128  (int)m_bDat[0] << " " << (int)m_bDat[1] << " " << (int)m_bDat[2] << " " << (int)m_bDat[3] << " " <<
129  (int)m_bDat[4] << " " << (int)m_bDat[5] << " " << (int)m_bDat[6] << " " << (int)m_bDat[7] << std::endl;
130  }
131 
135  int getStatus()
136  {
137  //bit 0 and bit 1 contain MsgStatus
138  return (int)(m_bDat[7] & 0x0003);
139  }
140 
144  int getCmd()
145  {
146  return (m_bDat[7] >> 2);
147  }
148 
153  int getID()
154  {
155  return m_iID;
156  }
157 
163  void setID(int id)
164  {
165  if( (0 <= id) && (id <= 2047) )
166  m_iID = id;
167  }
168 
173  int getLength()
174  {
175  return m_iLen;
176  }
177 
182  void setLength(int len)
183  {
184  if( (0 <= len) && (len <= 8) )
185  m_iLen = len;
186  }
187 
192  int getType()
193  {
194  return m_iType;
195  }
196 
201  void setType(int type)
202  {
203  m_iType = type;
204  }
205 
206 
207 };
208 //-----------------------------------------------
209 #endif
void setLength(int len)
Definition: CanMsg.h:182
int getID()
Definition: CanMsg.h:153
Definition: CanMsg.h:28
int getStatus()
Definition: CanMsg.h:135
int m_iLen
Definition: CanMsg.h:36
void setAt(BYTE data, int iNr)
Definition: CanMsg.h:75
BYTE m_bDat[8]
Definition: CanMsg.h:44
int getCmd()
Definition: CanMsg.h:144
int printCanIdentMsgStatus()
Definition: CanMsg.h:108
void setType(int type)
Definition: CanMsg.h:201
void print()
Definition: CanMsg.h:125
int getType()
Definition: CanMsg.h:192
void setID(int id)
Definition: CanMsg.h:163
int m_iType
Definition: CanMsg.h:38
int m_iID
Definition: CanMsg.h:34
int getLength()
Definition: CanMsg.h:173
CanMsg()
Definition: CanMsg.h:50
unsigned char BYTE
Include typedefs from windows.h.
Definition: CanMsg.h:32
int getAt(int iNr)
Definition: CanMsg.h:99


cob_generic_can
Author(s): Christian Connette
autogenerated on Wed Apr 7 2021 02:11:52