00001 /**************************************************************** 00002 * 00003 * Copyright (c) 2011 00004 * All rights reserved. 00005 * 00006 * Hochschule Bonn-Rhein-Sieg 00007 * University of Applied Sciences 00008 * Computer Science Department 00009 * 00010 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00011 * 00012 * Author: 00013 * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov 00014 * Supervised by: 00015 * Gerhard K. Kraetzschmar 00016 * 00017 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00018 * 00019 * This sofware is published under a dual-license: GNU Lesser General Public 00020 * License LGPL 2.1 and BSD license. The dual-license implies that users of this 00021 * code may choose which terms they prefer. 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 Hochschule Bonn-Rhein-Sieg 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 2.1 of the 00040 * License, or (at your option) any later version or the BSD license. 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 and the BSD license for more details. 00046 * 00047 * You should have received a copy of the GNU Lesser General Public 00048 * License LGPL and BSD license along with this program. 00049 * 00050 ****************************************************************/ 00051 00052 #ifndef _YOUBOT_SLAVE_MAILBOX_MESSAGE_H 00053 #define _YOUBOT_SLAVE_MAILBOX_MESSAGE_H 00054 00055 #include <ethercattype.h> 00056 #include <string> 00057 #include <time.h> 00058 #include "generic/dataobjectlockfree/DataObjectLockFree.hpp" 00059 00060 namespace youbot { 00061 00062 /// Output part from the EtherCAT mailbox message of the youBot slaves 00063 00064 struct mailboxOutputBuffer { 00065 uint8 moduleAddress; //0 = Drive 1 = Gripper 00066 uint8 commandNumber; 00067 uint8 typeNumber; 00068 uint8 motorNumber; //always zero 00069 uint32 value; //MSB first! 00070 00071 mailboxOutputBuffer() : moduleAddress(0), commandNumber(0), typeNumber(0), motorNumber(0), value(0) {}; 00072 } __attribute__((__packed__)); 00073 00074 /// Input part from the EtherCAT mailbox message of the youBot slaves 00075 00076 struct mailboxInputBuffer { 00077 uint8 replyAddress; 00078 uint8 moduleAddress; 00079 uint8 status; //(e.g. 100 means “no error”) 00080 uint8 commandNumber; 00081 uint32 value; //MSB first! 00082 00083 mailboxInputBuffer() : replyAddress(0), moduleAddress(0), status(0), commandNumber(0), value(0) {}; 00084 } __attribute__((__packed__)); 00085 00086 /////////////////////////////////////////////////////////////////////////////// 00087 /// EtherCAT mailbox message of the youBot slaves 00088 /////////////////////////////////////////////////////////////////////////////// 00089 00090 class YouBotSlaveMailboxMsg { 00091 public: 00092 00093 mailboxOutputBuffer stctOutput; 00094 mailboxInputBuffer stctInput; 00095 00096 // Constructor 00097 YouBotSlaveMailboxMsg() { 00098 slaveNumber = 1000; 00099 } 00100 00101 // Constructor 00102 00103 YouBotSlaveMailboxMsg(unsigned int slaveNo) { 00104 slaveNumber = slaveNo; 00105 } 00106 // Copy-Constructor 00107 00108 YouBotSlaveMailboxMsg(const YouBotSlaveMailboxMsg& copy) { 00109 stctOutput = copy.stctOutput; 00110 stctInput = copy.stctInput; 00111 slaveNumber = copy.slaveNumber; 00112 parameterName = copy.parameterName; 00113 } 00114 00115 00116 // Destructor 00117 00118 ~YouBotSlaveMailboxMsg() { 00119 } 00120 00121 // assignment operator 00122 00123 YouBotSlaveMailboxMsg & operator=(const YouBotSlaveMailboxMsg& copy) { 00124 stctOutput = copy.stctOutput; 00125 stctInput = copy.stctInput; 00126 slaveNumber = copy.slaveNumber; 00127 parameterName = copy.parameterName; 00128 return *this; 00129 } 00130 00131 std::string parameterName; 00132 unsigned int slaveNumber; 00133 }; 00134 00135 00136 /////////////////////////////////////////////////////////////////////////////// 00137 /// EtherCAT mailbox message of the youBot slaves (thread safe) 00138 /////////////////////////////////////////////////////////////////////////////// 00139 class YouBotSlaveMailboxMsgThreadSafe { 00140 public: 00141 00142 DataObjectLockFree<mailboxOutputBuffer> stctOutput; 00143 DataObjectLockFree<mailboxInputBuffer> stctInput; 00144 00145 // Constructor 00146 YouBotSlaveMailboxMsgThreadSafe() { 00147 slaveNumber.Set(1000); 00148 } 00149 00150 // Constructor 00151 00152 YouBotSlaveMailboxMsgThreadSafe(unsigned int slaveNo) { 00153 slaveNumber.Set(slaveNo); 00154 } 00155 // Copy-Constructor 00156 00157 YouBotSlaveMailboxMsgThreadSafe(const YouBotSlaveMailboxMsgThreadSafe& copy) { 00158 mailboxOutputBuffer tempStctOutput; 00159 mailboxInputBuffer tempStctInput; 00160 std::string tempParameterName; 00161 unsigned int SlaveNumber; 00162 00163 00164 copy.stctOutput.Get(tempStctOutput); 00165 stctOutput.Set(tempStctOutput); 00166 00167 copy.stctInput.Get(tempStctInput); 00168 stctInput.Set(tempStctInput); 00169 00170 copy.slaveNumber.Get(SlaveNumber); 00171 slaveNumber.Set(SlaveNumber); 00172 00173 copy.parameterName.Get(tempParameterName); 00174 parameterName.Set(tempParameterName); 00175 } 00176 00177 // Destructor 00178 00179 ~YouBotSlaveMailboxMsgThreadSafe() { 00180 } 00181 00182 // assignment operator 00183 00184 YouBotSlaveMailboxMsgThreadSafe & operator=(const YouBotSlaveMailboxMsgThreadSafe& copy) { 00185 mailboxOutputBuffer tempStctOutput; 00186 mailboxInputBuffer tempStctInput; 00187 std::string tempParameterName; 00188 unsigned int SlaveNumber; 00189 00190 00191 copy.stctOutput.Get(tempStctOutput); 00192 stctOutput.Set(tempStctOutput); 00193 00194 copy.stctInput.Get(tempStctInput); 00195 stctInput.Set(tempStctInput); 00196 00197 copy.slaveNumber.Get(SlaveNumber); 00198 slaveNumber.Set(SlaveNumber); 00199 00200 copy.parameterName.Get(tempParameterName); 00201 parameterName.Set(tempParameterName); 00202 return *this; 00203 } 00204 00205 DataObjectLockFree<std::string> parameterName; 00206 00207 DataObjectLockFree<unsigned int> slaveNumber; 00208 }; 00209 00210 00211 00212 } // namespace youbot 00213 00214 #endif /* _YOUBOT_SLAVE_MESSAGE_H */