| 1 |
/** @file |
/** @file |
| 2 |
* $Author: nagni $ |
* $Author: kusanagi $ |
| 3 |
* $Date: 2004/06/09 23:18:20 $ |
* $Date: 2004/08/20 15:01:42 $ |
| 4 |
* $Revision: 1.12 $ |
* $Revision: 1.7 $ |
| 5 |
* |
* |
| 6 |
* Implementation of the functions of a sample Algorithm class. |
* Implementation of the functions of a sample Algorithm class. |
| 7 |
* This file can be used as a templace to develop your own algorithm. |
* This file can be used as a templace to develop your own algorithm. |
| 24 |
using namespace pamela::techmodel; |
using namespace pamela::techmodel; |
| 25 |
|
|
| 26 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.EventReader"); |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.EventReader"); |
| 27 |
static unsigned int prevPckCounter = 0; |
unsigned int EventReader::prevPckCounter = 0; |
| 28 |
static unsigned int prevPckOBT = 0; |
unsigned int EventReader::prevPckOBT = 0; |
| 29 |
/** |
/** |
| 30 |
* Constructor. |
* Constructor. |
| 31 |
*/ |
*/ |
| 35 |
<< "Constructor " |
<< "Constructor " |
| 36 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 37 |
Header = new EventHeader(); |
Header = new EventHeader(); |
| 38 |
/* |
|
| 39 |
|
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::PhysEndRun, new PhysEndRunReader())); |
| 40 |
|
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse1, new CalibCalPulse1Reader())); |
| 41 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Alarm, |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse2, new CalibCalPulse2Reader())); |
| 42 |
new AlarmReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Physics, new PhysicsReader())); |
| 43 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Khb, |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrkBoth, new CalibTrkBothReader())); |
| 44 |
new KhbReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk1, new CalibTrk1Reader())); |
| 45 |
*/ |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk2, new CalibTrk2Reader())); |
| 46 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Physics, new PhysicsReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrd, new CalibTrdReader())); |
| 47 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ForcedPkt, new ForcedPktReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof, new CalibTofReader())); |
| 48 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunHeader, new RunHeaderReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4, new CalibS4Reader())); |
| 49 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunTrailer, new RunTrailerReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPed, new CalibCalPedReader())); |
| 50 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Log, new LogReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibAc, new CalibAcReader())); |
| 51 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::VarDump, new VarDumpReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunHeader, new RunHeaderReader())); |
| 52 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ArrDump, new ArrDumpReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunTrailer, new RunTrailerReader())); |
| 53 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TabDump, new TabDumpReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibHeader, new CalibHeaderReader())); |
| 54 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Tmtc, new TmtcReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrailer, new CalibTrailerReader())); |
| 55 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Mcmd, new McmdReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitHeader, new InitHeaderReader())); |
| 56 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCal, new CalibCalReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitTrailer, new InitTrailerReader())); |
| 57 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk, new CalibTrkReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::EventTrk, new EventTrkReader())); |
| 58 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrg, new CalibTrgReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TestTrk, new TestTrkReader())); |
| 59 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrd, new CalibTrdReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Log, new LogReader())); |
| 60 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof, new CalibTofReader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::VarDump, new VarDumpReader())); |
| 61 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4, new CalibS4Reader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ArrDump, new ArrDumpReader())); |
| 62 |
/* |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TabDump, new TabDumpReader())); |
| 63 |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::HA_Header_E5, |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Tmtc, new TmtcReader())); |
| 64 |
new E5Reader())); |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Mcmd, new McmdReader())); |
| 65 |
*/ |
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ForcedFECmd, new ForcedFECmdReader())); |
| 66 |
|
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::AcInit, new AcInitReader())); |
| 67 |
|
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalInit, new CalInitReader())); |
| 68 |
|
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrkInit, new TrkInitReader())); |
| 69 |
|
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofInit, new TofInitReader())); |
| 70 |
|
TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgInit, new TrgInitReader())); |
| 71 |
} |
} |
| 72 |
|
|
| 73 |
/** |
/** |
| 75 |
*/ |
*/ |
| 76 |
std::string EventReader::GetVersionInfo(void) const { |
std::string EventReader::GetVersionInfo(void) const { |
| 77 |
return |
return |
| 78 |
"$Header: /home/cvspamela/yoda/techmodel/EventReader.cpp,v 1.12 2004/06/09 23:18:20 nagni Exp $\n"; |
"$Header: /home/cvsmanager/yoda/techmodel/EventReader.cpp,v 1.7 2004/08/20 15:01:42 kusanagi Exp $\n"; |
| 79 |
} |
} |
| 80 |
|
|
| 81 |
/** |
/** |
| 113 |
// 15 June 2004 ---note------------------ |
// 15 June 2004 ---note------------------ |
| 114 |
void EventReader::RunEvent(int EventNumber) { |
void EventReader::RunEvent(int EventNumber) { |
| 115 |
|
|
| 116 |
cat << log4cpp::Priority::ERROR << "Start Unpacking........" |
cat << log4cpp::Priority::INFO << "Start Unpacking........" |
| 117 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
| 118 |
//for now i'll suppose that the raw file starts immediately with the right bytes |
//for now i'll suppose that the raw file starts immediately with the right bytes |
| 119 |
//to insert a GetPacketStart() |
//to insert a GetPacketStart() |
| 138 |
//**TO BE DONE** <<WRONG CRC l --- LOST PACKET>>// |
//**TO BE DONE** <<WRONG CRC l --- LOST PACKET>>// |
| 139 |
//Have to be defined a "WrongCRC" packet::Type? |
//Have to be defined a "WrongCRC" packet::Type? |
| 140 |
//} |
//} |
| 141 |
} |
} |
| 142 |
} catch (...) { |
} catch (...) { |
| 143 |
//This have to be more detailed. More exceptions type are needed. |
//This have to be more detailed. More exceptions type are needed. |
| 144 |
cat << log4cpp::Priority::ERROR << "Couldn't read the event. Skipping to the next header." |
cat << log4cpp::Priority::ERROR << "Couldn't read the event. Skipping to the next header." |
| 162 |
char buff[16]; |
char buff[16]; |
| 163 |
InputFile->read(buff, sizeof(buff)); |
InputFile->read(buff, sizeof(buff)); |
| 164 |
|
|
|
prevPckCounter = 0; |
|
|
prevPckOBT = 0; |
|
| 165 |
|
|
| 166 |
unsigned char PacketId1 = buff[3]; |
unsigned char PacketId1 = buff[3]; |
| 167 |
unsigned char PacketId2 = buff[4]; |
unsigned char PacketId2 = buff[4]; |
| 171 |
unsigned char CRC = buff[15]; |
unsigned char CRC = buff[15]; |
| 172 |
|
|
| 173 |
if (Counter < prevPckCounter){ |
if (Counter < prevPckCounter){ |
| 174 |
cat << log4cpp::Priority::ERROR |
cat << log4cpp::Priority::WARN |
| 175 |
<< " Packet counter is less than before of " << (prevPckCounter - Counter) |
<< " Packet counter is less than before of " << (prevPckCounter - Counter) |
| 176 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< " " << log4cpp::CategoryStream::ENDLINE; |
| 177 |
} |
} |
| 178 |
|
|
| 179 |
if (OrbitalTime < prevPckOBT){ |
if (OrbitalTime < prevPckOBT){ |
| 180 |
cat << log4cpp::Priority::WARN |
cat << log4cpp::Priority::WARN |
| 181 |
<< " Orbital Time is less than before of " << (prevPckOBT - OrbitalTime) |
<< " Orbital Time is less than before of " << (prevPckOBT - OrbitalTime) |
| 182 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< " " << log4cpp::CategoryStream::ENDLINE; |
| 183 |
} |
} |
| 184 |
|
|
| 185 |
|
|
| 186 |
if ((BYTE)CM_Compute_CRC16(0, (BYTE*)&buff, 15) == (BYTE)buff[15]){ |
if (((BYTE)CM_Compute_CRC16(0, (BYTE*)&buff, 15) == (BYTE)buff[15]) && (PacketId1 == PacketId2)){ |
| 187 |
|
prevPckCounter = Counter; |
| 188 |
|
prevPckOBT = OrbitalTime; |
| 189 |
long int initPos = InputFile->tellg(); |
long int initPos = InputFile->tellg(); |
| 190 |
long int finalPos; |
long int finalPos; |
| 191 |
Header->GetPscuHeader()->SetPacketId(PacketId1, PacketId2); |
Header->GetPscuHeader()->SetPacketId(PacketId1, PacketId2); |
| 201 |
FindStart(); |
FindStart(); |
| 202 |
finalPos = (long int)InputFile->tellg() - (1 + initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght())); |
finalPos = (long int)InputFile->tellg() - (1 + initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght())); |
| 203 |
if(finalPos == 0){ |
if(finalPos == 0){ |
| 204 |
cat << log4cpp::Priority::INFO << " Correct packet length \n" |
cat << log4cpp::Priority::DEBUG << " Correct packet length" |
| 205 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< " " << log4cpp::CategoryStream::ENDLINE; |
| 206 |
} |
} |
| 207 |
if (finalPos > 0 && finalPos < 64) { |
if (finalPos > 0 && finalPos < 64) { |
| 208 |
cat << log4cpp::Priority::WARN |
cat << log4cpp::Priority::WARN |
| 209 |
<< " Correct packet length: Padded of " << finalPos << " bytes \n" |
<< " Correct packet length: Padded of " << finalPos << " bytes" |
| 210 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< " " << log4cpp::CategoryStream::ENDLINE; |
| 211 |
} |
} |
| 212 |
if (finalPos > 64){ |
if (finalPos > 64){ |
| 213 |
cat << log4cpp::Priority::ERROR << " Wrong packet length? (because of wrong padding?) \n" |
cat << log4cpp::Priority::ERROR << " Wrong packet length? (because of wrong padding?) " |
| 214 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< " " << log4cpp::CategoryStream::ENDLINE; |
| 215 |
} |
} |
| 216 |
InputFile->seekg(initPos, std::ios::beg); |
InputFile->seekg(initPos, std::ios::beg); |
| 217 |
response = true; |
response = true; |
| 218 |
} else { |
} else { |
| 219 |
cat << log4cpp::Priority::ERROR << " WRONG CRC FOR HEADER " |
cat << log4cpp::Priority::ERROR << " WRONG CRC FOR HEADER " |
| 220 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< " " << log4cpp::CategoryStream::ENDLINE; |
| 221 |
|
InputFile->seekg(-(13), std::ios::cur); |
| 222 |
response = false; |
response = false; |
| 223 |
} |
} |
|
|
|
| 224 |
char tmpId1[4]; |
char tmpId1[4]; |
| 225 |
char tmpId2[4]; |
char tmpId2[4]; |
| 226 |
char tmpLength[12]; |
char tmpLength[12]; |
| 228 |
char tmpCRC[4]; |
char tmpCRC[4]; |
| 229 |
sprintf(tmpId1, "%02X", PacketId1); |
sprintf(tmpId1, "%02X", PacketId1); |
| 230 |
sprintf(tmpId2, "%02X", PacketId2); |
sprintf(tmpId2, "%02X", PacketId2); |
| 231 |
sprintf(tmpLength, "%06X", PacketLenght); |
sprintf(tmpLength, "%06X", Header->GetPscuHeader()->GetPacketLenght()); |
| 232 |
sprintf(tmpStart, "%X", ((long int)(InputFile->tellg()) - 16)); |
sprintf(tmpStart, "%X", ((long int)(InputFile->tellg()) - 16)); |
| 233 |
sprintf(tmpCRC, "%02X", CRC); |
sprintf(tmpCRC, "%02X", CRC); |
| 234 |
cat << log4cpp::Priority::INFO |
cat << log4cpp::Priority::INFO |
| 283 |
if (InputFile->eof()) { |
if (InputFile->eof()) { |
| 284 |
throw Exception("Extra bytes over the last packets"); |
throw Exception("Extra bytes over the last packets"); |
| 285 |
} else { |
} else { |
| 286 |
return 0; |
subIndex = 0; |
| 287 |
|
//return 0; |
| 288 |
} |
} |
| 289 |
//InputFile->seekg(-(subIndex+1), std::ios::cur); |
//InputFile->seekg(-(subIndex+1), std::ios::cur); |
| 290 |
//subIndex = 0; |
//subIndex = 0; |