Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Processes/CMD/Debug.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file Processes/CMD/Debug.cpp
    00003 *
    00004 * Implementation of class Debug.
    00005 *
    00006 * @author Martin Lötzsch
    00007 */
    00008
    00009 #include "Debug.h"
    00010 #include "Tools/RobotConfiguration.h"
    00011 #include "Tools/Debugging/Debugging.h"
    00012 #include "Platform/GTAssert.h"
    00013 #include "Platform/SystemCall.h"
    00014
    00015 Debug::Debug() :
    00016 INIT_EXTERNAL_DEBUGGING,
    00017
    00018 INIT_RECEIVER_SENSORDATA(false),
    00019
    00020 INIT_DEBUG_RECEIVER(Cognition),
    00021 INIT_DEBUG_RECEIVER(Motion),
    00022
    00023 INIT_DEBUG_SENDER(Cognition),
    00024 INIT_DEBUG_SENDER(Motion),
    00025
    00026 mode(QueueFillRequest::immediateReadWrite),
    00027 saveOrSendTime(0)
    00028 {
    00029   //cout << "FREE Memory " << SystemCall::getFreeMem() << "\n" ;
    00030   //cout << flush;
    00031
    00032
    00033   debugIn.setSize(400000);
    00034   if (SystemCall::getRobotDesign() == RobotDesign::ERS7)
    00035     debugOut.setSize(9000000);
    00036   else
    00037     debugOut.setSize(1000000);
    00038
    00039   theCognitionReceiver.setSize(200000);
    00040   theCognitionSender.setSize(400000);
    00041
    00042 //****for GT2005WalkingEngine****
    00043   theMotionReceiver.setSize(40000); // original value 2000
    00044   theMotionSender.setSize(200000);
    00045 }
    00046
    00047 Debug::~Debug()
    00048 {
    00049 }
    00050
    00051 int Debug::main()
    00052 {
    00053   INFO( printRobotStatus, idText, text,
    00054     "Free mem: " << SystemCall::getFreeMem() << " bytes" << endl <<
    00055     "Remaining capacity: " << SystemCall::getRemainingPower() << "%" << endl <<
    00056     "MAC Address: " << getRobotConfiguration().getMacAddressString()
    00057     );
    00058   DEBUG_RESPONSE( "Processes: Debug - printRobotStatus",
    00059     OUTPUT(idText, text,
    00060     "Free mem: " << SystemCall::getFreeMem() << " bytes" << endl <<
    00061     "Remaining capacity: " << SystemCall::getRemainingPower() << "%" << endl <<
    00062     "MAC Address: " << getRobotConfiguration().getMacAddressString()
    00063     )
    00064     );
    00065
    00066   DEBUG_RESPONSE("no wlan:head button saves collected",
    00067     if(theSensorDataBufferReceiver.frame[0].data[SensorData::head] > 10)
    00068     {mode = QueueFillRequest::saveCollected;} );
    00069
    00070   DEBUG_RESPONSE("no wlan:back rear saves collected",
    00071     if(theSensorDataBufferReceiver.frame[0].data[SensorData::backR] > 10)
    00072     {mode = QueueFillRequest::saveCollected;} );
    00073
    00074   DEBUG_RESPONSE("no wlan:back front starts collecting messages",
    00075     if(theSensorDataBufferReceiver.frame[0].data[SensorData::backF] > 10)
    00076     {mode = QueueFillRequest::collect;} );
    00077
    00078   DEBUG_RESPONSE("no wlan:back middle stops collecting messages",
    00079     if(theSensorDataBufferReceiver.frame[0].data[SensorData::backM] > 10)
    00080     {mode = QueueFillRequest::blockNewMessages;} );
    00081
    00082
    00083   if(
    00084     mode != QueueFillRequest::saveCollected &&
    00085     mode != QueueFillRequest::sendCollected &&
    00086     mode != QueueFillRequest::blockNewMessages )
    00087   {
    00088     // add the messages from the queues from the processes to the outgoing queue
    00089     theCognitionReceiver.moveAllMessages(debugOut);
    00090     theMotionReceiver.moveAllMessages(debugOut);
    00091   }
    00092
    00093   switch (mode)
    00094   {
    00095   case QueueFillRequest::overwriteOlder:
    00096     debugOut.removeRepetitions();
    00097     break;
    00098   case QueueFillRequest::rejectAll:
    00099     debugOut.clear();
    00100     break;
    00101   case QueueFillRequest::toStickNSeconds:
    00102     if ((SystemCall::getCurrentSystemTime() > saveOrSendTime)&&(saveOrSendTime != 0))
    00103     {
    00104       // save the outgoing queue to the memory stick
    00105       if (!debugOut.isEmpty())
    00106       {
    00107         OutBinaryFile fout("/MS/Logfile.log");
    00108         fout << debugOut;
    00109         debugOut.clear();
    00110       }
    00111       saveOrSendTime = 0;
    00112     }
    00113     break;
    00114   case QueueFillRequest::toStickImmediately:
    00115     // append the outgoing queue to the memory stick
    00116     if (!debugOut.isEmpty())
    00117     {
    00118       OutBinaryFile fout("/MS/Logfile.log",true);
    00119       fout << debugOut;
    00120       debugOut.clear();
    00121     }
    00122     break;
    00123   case QueueFillRequest::saveCollected:
    00124     // append the outgoing queue to the memory stick
    00125     if (!debugOut.isEmpty())
    00126     {
    00127       OutBinaryFile fout("/MS/Logfile.log");
    00128       fout << debugOut;
    00129       debugOut.clear();
    00130     }
    00131     break;
    00132   }
    00133
    00134   // send the queues to the processes
    00135   theCognitionSender.send();
    00136   theMotionSender.send();
    00137
    00138 #if defined(_WIN32) || defined(WLAN)
    00139   // send the outgoing queue to RobotControl
    00140   // (direct in WIN32, via TcpGateway in WLAN)
    00141   if ((mode==QueueFillRequest::immediateReadWrite)||
    00142     ((mode==QueueFillRequest::collectNSeconds)&&(saveOrSendTime < SystemCall::getCurrentSystemTime()))||
    00143     (mode==QueueFillRequest::overwriteOlder) ||
    00144     (mode==QueueFillRequest::sendCollected)
    00145     )
    00146   {
    00147 #ifndef _WIN32
    00148     if (messageWasReceived) // Hallo Hack
    00149 #endif
    00150       theDebugSender.send();
    00151   }
    00152 #endif
    00153
    00154   return 1; // Wait at least 1 millisecond, then recall main()
    00155 }
    00156
    00157 void Debug::init()
    00158 {
    00159   INIT_EXTERNAL_DEBUGGING_HANDLER;
    00160
    00161   // read requests.dat
    00162   //
    00163   InBinaryFile fin("requests.dat");
    00164   if ((fin.exists())&&(! fin.eof()))
    00165     fin >> debugIn;
    00166
    00167   debugIn.handleAllMessages(*this);
    00168   debugIn.clear();
    00169   messageWasReceived = false;
    00170 }
    00171
    00172 bool Debug::handleMessage(InMessage& message)
    00173 {
    00174   messageWasReceived = true;
    00175
    00176   switch(message.getMessageID())
    00177   {
    00178   case idText: // loop back to GUI
    00179     message >> debugOut;
    00180     return true;
    00181   case idSensorData:
    00182   case idImage:
    00183   case idJPEGImage:
    00184   case idLowResImage:
    00185   case idPercepts:
    00186   case idHeadControlMode:
    00187   case idMotionRequest:
    00188   case idLEDRequest:
    00189   case idWorldState:
    00190   case idColorTable64:
    00191   case idColorTableTSL:
    00192   case idCameraParameters:
    00193   case idOracledWorldState:
    00194   case idRemoteCamWorldState:
    00195   case idGTCamWorldState:
    00196   case idGlobalGameControlData:
    00197   case idGameControlData:
    00198   case idSoundRequest:
    00199   case idSpecialPercept:
    00200   case idImageProcessorParameters:
    00201   case idLinesSelfLocatorParameters:
    00202   case idDDDSelfLocatorParameters:
    00203   case idJoystickData:
    00204   case idGT2004BallLocatorData:
    00205   case idKickSelectionTable:
    00206   case idMotionRatingBehaviorMessage:
    00207     message >> theCognitionSender;
    00208     return true;
    00209   case idHeadMotionRequest:
    00210   case idOdometryData:
    00211   case idJointDataSequence:
    00212   case idFourierCoefficients:
    00213   case idInvKinWalkingParameters:
    00214   case idPIDData:
    00215   case idGameSpeed:
    00216   case idMotionControlSlowMotion:
    00217   case idMotionNet:
    00218   case idOdometryScale:
    00219     message >> theMotionSender;
    00220     return true;
    00221   case idDebugKeyTable:
    00222     Process::handleMessage(message);
    00223   case idSolutionRequest:
    00224   case idGenericDebugData:
    00225   case idGT2004Parameters:
    00226   case idGT2004EvolutionRequest:
    00227   case idBehaviorEvolutionPopulation:
    00228   case idBehaviorEvolutionParameters:
    00229   case idYetAnotherInvKinParams:
    00230   case idYetAnotherInvKinPaws:
    00231   case idBodyOffsets:
    00232   case idXabsl2DebugRequest:
    00233   case idXabsl2IntermediateCode:
    00234   case idGTCamKalmanBallFilter:
    00235   case idGT2005BallLocator1:
    00236   case idGT2005BallLocator2:
    00237   case idGT2005TeamBallLocator:
    00238   case idMSHBallLocatorEvolution:
    00239   case idComboBallLocator:
    00240   case idDebugDataChangeRequest:
    00241     message >> theCognitionSender;
    00242     message >> theMotionSender;
    00243     return true;
    00244   case idDebugRequest:
    00245   {
    00246     message >> theCognitionSender;
    00247     message >> theMotionSender;
    00248     return Process::handleMessage(message);
    00249   }
    00250
    00251   //****for GT2005WalkingEngine****
    00252   case idGT2005Request:
    00253     message >> theMotionSender;
    00254     return true;
    00255
    00256   case idQueueFillRequest:
    00257     {
    00258       QueueFillRequest qfr;
    00259       message.bin >> qfr;
    00260       mode = qfr.mode;
    00261       saveOrSendTime = 1000*qfr.seconds + SystemCall::getCurrentSystemTime();
    00262       return true;
    00263     }
    00264   default:
    00265     return Process::handleMessage(message);
    00266   }
    00267 }
    00268
    00269 MAKE_PROCESS(Debug);