CanMsg.h
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2010
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering   
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name: cob3_common
00012  * ROS package name: generic_can
00013  * Description:
00014  *                                                              
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *                      
00017  * Author: Christian Connette, email:christian.connette@ipa.fhg.de
00018  * Supervised by: Christian Connette, email:christian.connette@ipa.fhg.de
00019  *
00020  * Date of creation: Feb 2009
00021  * ToDo:
00022  *
00023  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00024  *
00025  * Redistribution and use in source and binary forms, with or without
00026  * modification, are permitted provided that the following conditions are met:
00027  *
00028  *     * Redistributions of source code must retain the above copyright
00029  *       notice, this list of conditions and the following disclaimer.
00030  *     * Redistributions in binary form must reproduce the above copyright
00031  *       notice, this list of conditions and the following disclaimer in the
00032  *       documentation and/or other materials provided with the distribution.
00033  *     * Neither the name of the Fraunhofer Institute for Manufacturing 
00034  *       Engineering and Automation (IPA) nor the names of its
00035  *       contributors may be used to endorse or promote products derived from
00036  *       this software without specific prior written permission.
00037  *
00038  * This program is free software: you can redistribute it and/or modify
00039  * it under the terms of the GNU Lesser General Public License LGPL as 
00040  * published by the Free Software Foundation, either version 3 of the 
00041  * License, or (at your option) any later version.
00042  * 
00043  * This program is distributed in the hope that it will be useful,
00044  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00045  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00046  * GNU Lesser General Public License LGPL for more details.
00047  * 
00048  * You should have received a copy of the GNU Lesser General Public 
00049  * License LGPL along with this program. 
00050  * If not, see <http://www.gnu.org/licenses/>.
00051  *
00052  ****************************************************************/
00053 
00054 
00055 #ifndef CANMSG_INCLUDEDEF_H
00056 #define CANMSG_INCLUDEDEF_H
00057 //-----------------------------------------------
00058 #include <iostream>
00059 //-----------------------------------------------
00060 
00065 class CanMsg
00066 {
00067 public:
00069         typedef unsigned char BYTE;
00071         int m_iID;
00073         int m_iLen;
00075         int m_iType;
00076 
00077 protected:
00081         BYTE m_bDat[8];
00082 
00083 public:
00087         CanMsg()
00088         {
00089                 m_iID = 0;
00090                 m_iLen = 8;
00091                 m_iType = 0x00;
00092         }
00093 
00097         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)
00098         {
00099                 m_bDat[0] = Data0;
00100                 m_bDat[1] = Data1;
00101                 m_bDat[2] = Data2;
00102                 m_bDat[3] = Data3;
00103                 m_bDat[4] = Data4;
00104                 m_bDat[5] = Data5;
00105                 m_bDat[6] = Data6;
00106                 m_bDat[7] = Data7;
00107         }
00108 
00112         void setAt(BYTE data, int iNr)
00113         {
00114                 m_bDat[iNr] = data;
00115         }
00116 
00120         void get(BYTE* pData0, BYTE* pData1, BYTE* pData2, BYTE* pData3, BYTE* pData4, BYTE* pData5, BYTE* pData6, BYTE* pData7)
00121         {
00122                 *pData0 = m_bDat[0];
00123                 *pData1 = m_bDat[1];
00124                 *pData2 = m_bDat[2];
00125                 *pData3 = m_bDat[3];
00126                 *pData4 = m_bDat[4];
00127                 *pData5 = m_bDat[5];
00128                 *pData6 = m_bDat[6];
00129                 *pData7 = m_bDat[7];
00130         }
00131 
00136         int getAt(int iNr)
00137         {
00138                 return m_bDat[iNr];
00139         }
00140 
00145         int printCanIdentMsgStatus()
00146         {
00147                 if(getStatus() == 0)
00148                 {
00149                         std::cout << "ID= " << m_iID << "  " << "Cmd= " << getCmd() << "   " << "Msg_OK" << std::endl;
00150                         return 0;
00151                 }
00152                 else
00153                 {
00154                         std::cout << "ID= " << m_iID << "  " << "Cmd= " << getCmd() << "   " << "Msg_Error" << std::endl;
00155                         return -1;
00156                 }
00157         }
00158 
00162         void print()
00163         {
00164                 std::cout << "id= " << m_iID << " type= " << m_iType << " len= " << m_iLen << " data= " <<
00165                         (int)m_bDat[0] << " " << (int)m_bDat[1] << " " << (int)m_bDat[2] << " " << (int)m_bDat[3] << " " <<
00166                         (int)m_bDat[4] << " " << (int)m_bDat[5] << " " << (int)m_bDat[6] << " " << (int)m_bDat[7] << std::endl;
00167         }
00168 
00172         int getStatus()
00173         {
00174                 //bit 0 and bit 1 contain MsgStatus
00175                 return (int)(m_bDat[7] & 0x0003);
00176         }
00177 
00181         int getCmd()
00182         {
00183                 return (m_bDat[7] >> 2);
00184         }
00185         
00190         int getID()
00191         {
00192                 return m_iID;
00193         }
00194 
00200         void setID(int id)
00201         {
00202                 if( (0 <= id) && (id <= 2047) )
00203                         m_iID = id;
00204         }
00205 
00210         int getLength()
00211         {
00212                 return m_iLen;
00213         }
00214 
00219         void setLength(int len)
00220         {
00221                 if( (0 <= len) && (len <= 8) )
00222                         m_iLen = len;
00223         }
00224 
00229         int getType()
00230         {
00231                 return m_iType;
00232         }
00233 
00238         void setType(int type)
00239         {
00240                 m_iType = type;
00241         }
00242 
00243 
00244 };
00245 //-----------------------------------------------
00246 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends


cob_generic_can
Author(s): Christian Connette
autogenerated on Fri Mar 1 2013 17:46:39