CanESD.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: cob_drivers
00012  * ROS package name: cob_generic_can
00013  * Description: This class implements the interface to an ESD can node
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: April 2010
00021  * ToDo: - Remove Mutex.h search for a Boost lib
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 CANESD_INCLUDEDEF_H
00056 #define CANESD_INCLUDEDEF_H
00057 //-----------------------------------------------
00058 
00059 #include <libntcan/ntcan.h>
00060 // general includes
00061 #include <cob_utilities/windows.h>
00062 #include <iostream>
00063 #include <errno.h>
00064 
00065 // Headers provided by other cob-packages
00066 #include <cob_generic_can/CanItf.h>
00067 
00068 // Headers provided by other cob-packages which should be avoided/removed
00069 #include <cob_utilities/IniFile.h>
00070 #include <cob_utilities/Mutex.h>
00071 
00072 
00073 //-----------------------------------------------
00077 class CanESD : public CanItf
00078 {
00079 private:
00080         BYTE m_DeviceNr;
00081         BYTE m_BaudRate;
00082         NTCAN_HANDLE m_Handle;
00083         int m_LastID;
00084         bool m_bObjectMode;
00085         bool m_bIsTXError;
00086         Mutex m_Mutex;
00087 
00088         IniFile m_IniFile;
00089 
00090         void initIntern();
00091 
00092 public:
00093         CanESD(const char* cIniFile, bool bObjectMode = false);
00094         ~CanESD();
00095         void init(){};
00096         bool transmitMsg(CanMsg CMsg, bool bBlocking = true);
00097         bool receiveMsgRetry(CanMsg* pCMsg, int iNrOfRetry);
00098         bool receiveMsg(CanMsg* pCMsg);
00099         bool isObjectMode() { return m_bObjectMode; }
00100         bool isTransmitError() { return m_bIsTXError; }
00101 protected:
00102 
00112         int invert(int id)
00113         {
00114                 return (~id) & 0x7F8;
00115         }
00116         
00117         int canIdAddGroup(NTCAN_HANDLE handle, int id);
00118 
00119         std::string GetErrorStr(int ntstatus) const;
00120         int readEvent();
00121 };
00122 //-----------------------------------------------
00123 #endif


cob_generic_can
Author(s): Christian Connette
autogenerated on Thu Aug 27 2015 12:45:37