CANOpen_buffer.h
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2012
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering   
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: CIN-Reha
00011  * ROS stack name: cob_drivers
00012  * ROS package name: cob_generic_can
00013  * Description:
00014  *                                                              
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *                      
00017  * Author: 
00018  * Supervised by:
00019  *
00020  * Date of creation: Jan 2012
00021  *
00022  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00023  *
00024  * Redistribution and use in source and binary forms, with or without
00025  * modification, are permitted provided that the following conditions are met:
00026  *
00027  *     * Redistributions of source code must retain the above copyright
00028  *       notice, this list of conditions and the following disclaimer.
00029  *     * Redistributions in binary form must reproduce the above copyright
00030  *       notice, this list of conditions and the following disclaimer in the
00031  *       documentation and/or other materials provided with the distribution.
00032  *     * Neither the name of the Fraunhofer Institute for Manufacturing 
00033  *       Engineering and Automation (IPA) nor the names of its
00034  *       contributors may be used to endorse or promote products derived from
00035  *       this software without specific prior written permission.
00036  *
00037  * This program is free software: you can redistribute it and/or modify
00038  * it under the terms of the GNU Lesser General Public License LGPL as 
00039  * published by the Free Software Foundation, either version 3 of the 
00040  * License, or (at your option) any later version.
00041  * 
00042  * This program is distributed in the hope that it will be useful,
00043  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00044  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00045  * GNU Lesser General Public License LGPL for more details.
00046  * 
00047  * You should have received a copy of the GNU Lesser General Public 
00048  * License LGPL along with this program. 
00049  * If not, see <http://www.gnu.org/licenses/>.
00050  *
00051  ****************************************************************/
00052 
00053 #ifndef CANOpen_buffer_INCLUDEDEF_H
00054 #define CANOpen_buffer_INCLUDEDEF_H
00055 //-----------------------------------------------
00056 
00057 #include <cob_generic_can/CanItf.h>
00058 
00059 /*=============================================*/
00060  
00061 class CANOpen_buffer
00062 {       
00063         private:
00064         
00065         // TODO make struct size variable
00066         // global PDO buffer 
00067         
00068         struct Data
00069         {       
00070                 int NodeID;
00071                 CanMsg CMsg;
00072                 bool active;
00073                 int desired_SYNC_freq_HZ; //experimental
00074         }data[32];      //8 nodes with 4 PDOs
00075         
00076 
00077         public:
00078 
00079         // constructor
00080         // param CAN-ID offset for specifing PDO1, PDO2, SDO... 
00081         CANOpen_buffer()
00082         {       
00083                 for (int i=0;i<32;i++)
00084                 {       
00085                         data[i].active = false;         
00086                 }       
00087         }
00088         
00089         // destructor
00090         ~CANOpen_buffer()
00091         {}
00092 
00093         int RegMsg(int, int, int);
00094         bool IsActive(int);
00095         int SetMsg(int, char*);
00096         CanMsg* GetMsg(int number);
00097 };      
00098 
00099         // set Msg in buffer
00100         // TODO check params befor setting
00101         int CANOpen_buffer::RegMsg(int ID, int number, int des_freq)
00102         {       
00103                 if (!data[number].active)
00104                 {       
00105                         data[number].CMsg.m_iLen = 8;
00106                         data[number].CMsg.m_iID = ID;                   
00107                         data[number].active = true;
00108                         data[number].desired_SYNC_freq_HZ = des_freq;
00109                 }
00110                 else 
00111                 {return -1;}    
00112                 return 0;
00113         }       
00114         
00115         // Is active
00116         // TODO: test is ID is in range
00117         bool CANOpen_buffer::IsActive(int ID)
00118         {       
00119                 return data[ID].active;
00120         }       
00121         
00122         // set Msg in buffer
00123         // TODO check params befor setting
00124         int CANOpen_buffer::SetMsg(int number, char* Msg)
00125         {       
00126                         data[number].CMsg.set(Msg[0], Msg[1], Msg[2], Msg[3], Msg[4], Msg[5], Msg[6], Msg[7]);
00127                 return 0;
00128         }       
00129         
00130         // Get Msg in buffer
00131         CanMsg* CANOpen_buffer::GetMsg(int number)
00132         {       
00133                 if(!data[number].active)
00134                 { return &data[number].CMsg;}
00135                 return 0;
00136         }       
00137 
00138 //-----------------------------------------------
00139 #endif
00140 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


CANOpen_driver
Author(s): Tim Fröhlich
autogenerated on Mon Jan 14 2013 16:55:42