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

Processes/CMD/Logger.cpp

Go to the documentation of this file.
00001 /** 
00002 * @file Logger.cpp
00003 * 
00004 * Implementation of class Logger.
00005 *
00006 * @author Max Risler
00007 */
00008  
00009 #include "Logger.h"
00010 #include "Tools/RobotConfiguration.h"
00011 #include "Tools/Debugging/Debugging.h"
00012 #include "Platform/GTAssert.h"
00013 #include "Platform/SystemCall.h"
00014 
00015 Logger::Logger() : 
00016   INIT_DEBUGGING,
00017   INIT_RECEIVER_SENSORDATA(true),
00018 
00019   mode(QueueFillRequest::immediateReadWrite),
00020   saveOrSendTime(0),
00021   fin(0)
00022 {
00023   debugIn.setSize(400000);
00024   debugOut.setSize(2000000);
00025 }
00026 
00027 Logger::~Logger() 
00028 {
00029   if (fin)
00030     delete(fin);
00031 }
00032 
00033 int Logger::main() 
00034 {
00035   WATCH(sendSensorData,idSensorData,bin,theSensorDataBufferReceiver);
00036 
00037   //if somebody attached messages to that file, process them now
00038   if ((fin->exists())&&(! fin->eof()))
00039   {
00040     *fin >> debugIn;
00041     debugIn.handleAllMessages(*this);
00042     debugIn.clear();
00043   }
00044 
00045 
00046   INFO(printRobotStatus,idText,text,"Free mem: "<<SystemCall::getFreeMem()<<" bytes"<<endl<<"Remaining capacity: "<<SystemCall::getRemainingPower()<<"%"<<endl << "MAC Address: " << getRobotConfiguration().getMacAddressString());
00047   
00048   switch (mode)
00049   {
00050   case QueueFillRequest::overwriteOlder:
00051     debugOut.removeRepetitions();
00052     break;
00053   case QueueFillRequest::rejectAll:
00054     debugOut.clear();
00055     break;
00056   case QueueFillRequest::toStickNSeconds:
00057     if ((SystemCall::getCurrentSystemTime() > saveOrSendTime)&&(saveOrSendTime != 0))
00058     {
00059       // save the outgoing queue to the memory stick
00060       if (!debugOut.isEmpty())
00061       {
00062         OutBinaryFile fout("Logfile.log");
00063         fout << debugOut;
00064         debugOut.clear();
00065       }
00066       saveOrSendTime = 0;
00067     }
00068     break;
00069   case QueueFillRequest::toStickImmediately:
00070       // save the outgoing queue to the memory stick
00071       if (!debugOut.isEmpty())
00072       {
00073         OutBinaryFile fout("Logfile.log");
00074         fout << debugOut;
00075       }
00076      break;
00077   }
00078   
00079 #if defined(_WIN32) || defined(WLAN)
00080   // send the outgoing queue to RobotControl 
00081   // (direct in WIN32, via TcpGateway in WLAN)
00082   if ((mode==QueueFillRequest::immediateReadWrite)||
00083       ((mode==QueueFillRequest::collectNSeconds)&&(saveOrSendTime < SystemCall::getCurrentSystemTime()))||
00084       (mode==QueueFillRequest::overwriteOlder))
00085   {
00086 #ifndef _WIN32
00087     if (messageWasReceived) // Hallo Hack
00088 #endif
00089       theDebugSender.send();
00090   }
00091 #endif
00092 
00093   return 1; // Wait at least 1 millisecond, then recall main()
00094 }
00095 
00096 void Logger::init()
00097 {
00098   fin = new InBinaryFile("requests.dat");
00099   if ((fin->exists())&&(! fin->eof()))
00100   {
00101     *fin >> debugIn;
00102   }
00103   debugIn.handleAllMessages(*this);
00104   debugIn.clear();
00105   messageWasReceived = false;
00106 }
00107 
00108 bool Logger::handleMessage(InMessage& message)
00109 {
00110   messageWasReceived = true;
00111 
00112   switch(message.getMessageID())
00113   {
00114   case idQueueFillRequest:
00115     {
00116     QueueFillRequest qfr;
00117     message.bin >> qfr;
00118     mode = qfr.mode;
00119     saveOrSendTime = 1000*qfr.seconds + SystemCall::getCurrentSystemTime();
00120     return true;
00121     }
00122   default:
00123     return Process::handleMessage(message);
00124   }
00125 }
00126 
00127 MAKE_PROCESS(Logger);
00128 
00129 /*
00130  * Change log :
00131  * 
00132  * $Log: Logger.cpp,v $
00133  * Revision 1.2  2004/06/16 21:48:22  goehring
00134  * saveToStickImmediately added, saveToStickAfterNSeconds deletes queue
00135  *
00136  * Revision 1.1.1.1  2004/05/22 17:24:57  cvsadm
00137  * created new repository GT2004_WM
00138  *
00139  * Revision 1.1  2003/10/07 10:07:01  cvsadm
00140  * Created GT2004 (M.J.)
00141  *
00142  * Revision 1.1  2003/07/24 13:33:15  risler
00143  * new process logger
00144  *
00145  */

Generated on Thu Sep 23 19:57:35 2004 for GT2004 by doxygen 1.3.6