00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef ESMFILE_H
00011 #define ESMFILE_H
00012 #include <vector>
00013 #include <string>
00014 #include <iostream>
00015 #include "esmfilehead.h"
00016 #include "reporter.h"
00017 #include "block.h"
00018 #include "cardblocks.h"
00019 #include "vufactory.h"
00020 #include "typedefs.h"
00021 #include "time.h"
00022
00023 block::ptr Factory(iter start){
00024 if(start[0] == 0x76) return block::ptr(vuFactory(start));
00025 else return tlvblock::Factory(start);
00026 }
00027
00028 class esmfile : public esmfilehead{
00029 public:
00030 typedef std::vector<block::ptr> subray;
00031 typedef subray::const_iterator subiter;
00032 string name(){
00033 return title + ", " + first.datestr() + " to " + last.datestr();
00034 }
00035
00036 subray blocks;
00037 esmfile(const string& filename) : esmfilehead(filename) {
00038 iter filewalker = content.begin();
00039 while(filewalker < content.end()){
00040 block::ptr p(Factory(filewalker));
00041 blocks.push_back(p);
00042 filewalker += p->size();
00043 }
00044 for(subiter i = blocks.begin(); i < blocks.end(); ++i) (*i)->reportstuff(*this);
00045 #ifndef HAVE_NO_CRYPTO
00046 if(CAcert && devicecert){
00047 string filename("EC_PK.bin");
00048 if(!file_exists(filename)) filename = PREFIX "/share/readesm/EC_PK.bin";
00049 if(file_exists(filename)){
00050 if(CAcert->verify(filename))
00051 if(devicecert->verify(*CAcert))
00052 for(subiter i = blocks.begin(); i < blocks.end(); ++i) (*i)->checksig(devicecert->key);
00053 } else {
00054 std::cerr << "Cannot verify certificates and signatures: European main certificate file not found or not openable.";
00055 }
00056 }
00057 #endif
00058 }
00059 friend reporter& operator<<(reporter& report, const esmfile& e){
00060 report.bigblockstart("Statistics");
00061 report.single(tr("Statistics for") + " " + e.title, true);
00062 report.single(formatRange(e.first,e.last));
00063 report("Recorded days",e.daycount);
00064 report("Overall driven distance", stringify(e.drivenkm) + " km");
00065 report("Overall driving time", formatMinutes(e.drivenminutes));
00066 report("Average distance per day", stringify(e.drivenkm / e.daycount) + " km");
00067 report("Average time driven per day", formatMinutes(e.drivenminutes / e.daycount) + " (" + stringify(100*e.drivenminutes / (e.daycount*24*60)) + "%)");
00068 report("Average speed when driving", stringify(e.drivenkm * 60 / e.drivenminutes) + " km/h");
00069 report.bigblockend();
00070
00071 for(subiter i = e.blocks.begin(); i < e.blocks.end(); ++i) report << **i;
00072 return report;
00073 }
00074 };
00075
00076 #endif