CanMsg.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Neobotix GmbH
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Neobotix nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 
00036 
00037 #ifndef CANMSG_INCLUDEDEF_H
00038 #define CANMSG_INCLUDEDEF_H
00039 
00040 //-----------------------------------------------
00041 
00042 #include <iostream>
00043 
00044 //-----------------------------------------------
00045 
00050 class CanMsg
00051 {
00052 public:
00053         int m_iID;
00054         int m_iLen;
00055         int m_iType;
00056 
00057 private:
00061         char m_bDat[8];
00062 
00063 public:
00067         CanMsg()
00068         {
00069                 m_iID = 0;
00070                 m_iLen = 8;
00071                 m_iType = 0x00;
00072         }
00073 
00077         void set(char Data0, char Data1, char Data2, char Data3, char Data4, char Data5, char Data6, char Data7)
00078         {
00079                 m_bDat[0] = Data0;
00080                 m_bDat[1] = Data1;
00081                 m_bDat[2] = Data2;
00082                 m_bDat[3] = Data3;
00083                 m_bDat[4] = Data4;
00084                 m_bDat[5] = Data5;
00085                 m_bDat[6] = Data6;
00086                 m_bDat[7] = Data7;
00087         }
00088 
00092         void get(char* pData0, char* pData1, char* pData2, char* pData3, char* pData4, char* pData5, char* pData6, char* pData7)
00093         {
00094                 *pData0 = m_bDat[0];
00095                 *pData1 = m_bDat[1];
00096                 *pData2 = m_bDat[2];
00097                 *pData3 = m_bDat[3];
00098                 *pData4 = m_bDat[4];
00099                 *pData5 = m_bDat[5];
00100                 *pData6 = m_bDat[6];
00101                 *pData7 = m_bDat[7];
00102         }
00103 
00108         int getAt(int iNr)
00109         {
00110                 return m_bDat[iNr];
00111         }
00112 
00117         int printCanIdentMsgStatus()
00118         {
00119                 if(getStatus() == 0)
00120                 {
00121                         std::cout << "ID= " << m_iID << "  " << "Cmd= " << getCmd() << "   " << "Msg_OK" << std::endl;
00122                         return 0;
00123                 }
00124                 else
00125                 {
00126                         std::cout << "ID= " << m_iID << "  " << "Cmd= " << getCmd() << "   " << "Msg_Error" << std::endl;
00127                         return -1;
00128                 }
00129         }
00130 
00134         void print()
00135         {
00136                 std::cout << std::hex << std::showbase << "                id= " << m_iID << " type= " << m_iType << 
00137                         " len= " << m_iLen << " msg= " <<
00138                         (int)m_bDat[0] << " " << (int)m_bDat[1] << " " << (int)m_bDat[2] << " " << (int)m_bDat[3] << " " <<
00139                         (int)m_bDat[4] << " " << (int)m_bDat[5] << " " << (int)m_bDat[6] << " " << (int)m_bDat[7] << std::endl;
00140         }
00141 
00145         int getStatus()
00146         {
00147                 //bit 0 and bit 1 contain MsgStatus
00148                 return (int)(m_bDat[7] & 0x0003);
00149         }
00150 
00154         int getCmd()
00155         {
00156                 return (m_bDat[7] >> 2);
00157         }
00158 };
00159 
00164 class CANTimedMessage
00165 {
00166         public:
00170                 double dTimeStamp;
00171 
00175                 CanMsg *pCanMsg;
00176 };
00177 
00178 
00179 //-----------------------------------------------
00180 #endif


neo_relayboard
Author(s): Jan-Niklas Nieland
autogenerated on Thu Jun 6 2019 21:37:07