00001
00002
00003
00004
00005
00006
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
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
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
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
00081
00082 if ((mode==QueueFillRequest::immediateReadWrite)||
00083 ((mode==QueueFillRequest::collectNSeconds)&&(saveOrSendTime < SystemCall::getCurrentSystemTime()))||
00084 (mode==QueueFillRequest::overwriteOlder))
00085 {
00086 #ifndef _WIN32
00087 if (messageWasReceived)
00088 #endif
00089 theDebugSender.send();
00090 }
00091 #endif
00092
00093 return 1;
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
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145