#include #include #include #include DiveLog::DiveLog() { mExtraInfo=0; mBottomTime=0; mMaxDepthHi=0; mMaxDepthLo=0; mSurfaceTimeHi=0; mSurfaceTimeLo=0; mTotalAirConsumption=0; mEntryTime1=0; mEntryTime2=0; mEntryTime3=0; mEntryTime4=0; mWaterTemperature=0; } DiveLog::~DiveLog() { } bool DiveLog::operator<(const DiveLog &diveLog)const { return getEntryTime()(const DiveLog &diveLog)const { return getEntryTime()>diveLog.getEntryTime(); } bool DiveLog::operator==(const DiveLog &diveLog)const { SystemTime srcEntryTime(getEntryTime()); SystemTime dstEntryTime(diveLog.getEntryTime()); if(srcEntryTime.year()!=dstEntryTime.year())return false; if(srcEntryTime.month()!=dstEntryTime.month())return false; if(srcEntryTime.day()!=dstEntryTime.day())return false; if(srcEntryTime.hour()!=dstEntryTime.hour())return false; if(srcEntryTime.minute()!=dstEntryTime.minute())return false; if(srcEntryTime.second()!=dstEntryTime.second())return false; return true; } int DiveLog::getBottomTime(void)const { int bottomTime=(((mBottomTime>>4)*10))+(mBottomTime&0x0F); if(mExtraInfo&0x04)bottomTime+=100; return bottomTime; } int DiveLog::getMaxDepth(void)const { double maxDepth(((double)((mMaxDepthHi*256)+mMaxDepthLo)*10.00)/4096.00); return int((maxDepth*3.281)+.5); } int DiveLog::getAltitude(void)const { return 0; } int DiveLog::getWaterTemperature(void)const { return mWaterTemperature/4; } SystemTime DiveLog::getEntryTime(void)const { return DiveTime(mEntryTime1,mEntryTime2,mEntryTime3,mEntryTime4).getTime(); } Time DiveLog::getSurfaceTime(void)const { return Time(mSurfaceTimeHi,mSurfaceTimeLo); } String DiveLog::toString(void)const { String str; str+=String("Depth:")+String().fromInt(getMaxDepth())+String(" "); str+=String("Entry:")+getEntryTime().toString()+String(" "); str+=String("Temp:")+String().fromInt(getWaterTemperature())+String(" "); str+=String("Bottom")+String().fromInt(getBottomTime())+String(" "); str+=String("Surface:")+getSurfaceTime().toString(); return str; } bool DiveLog::readFrom(RawData &array,int &index) { try { mExtraInfo=array[index++]; mBottomTime=array[index++]; mMaxDepthHi=array[index++]; mMaxDepthLo=array[index++]; mSurfaceTimeHi=array[index++]; mSurfaceTimeLo=array[index++]; mTotalAirConsumption=array[index++]; mEntryTime1=array[index++]; mEntryTime2=array[index++]; mEntryTime3=array[index++]; mEntryTime4=array[index++]; mWaterTemperature=array[index++]; } catch(ArrayIndexOutOfBoundsException exception) { ::OutputDebugString(exception.toString()+String("\n")); return false; } return true; } bool DiveLog::readFrom(File &inFile) { if(!inFile.isOkay())return false; if(!inFile.read(&mExtraInfo,sizeof(mExtraInfo)))return false; if(!inFile.read(&mBottomTime,sizeof(mBottomTime)))return false; if(!inFile.read(&mMaxDepthHi,sizeof(mMaxDepthHi)))return false; if(!inFile.read(&mMaxDepthLo,sizeof(mMaxDepthLo)))return false; if(!inFile.read(&mSurfaceTimeHi,sizeof(mSurfaceTimeHi)))return false; if(!inFile.read(&mSurfaceTimeLo,sizeof(mSurfaceTimeLo)))return false; if(!inFile.read(&mTotalAirConsumption,sizeof(mTotalAirConsumption)))return false; if(!inFile.read(&mEntryTime1,sizeof(mEntryTime1)))return false; if(!inFile.read(&mEntryTime2,sizeof(mEntryTime2)))return false; if(!inFile.read(&mEntryTime3,sizeof(mEntryTime3)))return false; if(!inFile.read(&mEntryTime4,sizeof(mEntryTime4)))return false; if(!inFile.read(&mWaterTemperature,sizeof(mWaterTemperature)))return false; return true; } bool DiveLog::writeTo(File &outFile) { if(!outFile.isOkay())return false; if(!outFile.write(&mExtraInfo,sizeof(mExtraInfo)))return false; if(!outFile.write(&mBottomTime,sizeof(mBottomTime)))return false; if(!outFile.write(&mMaxDepthHi,sizeof(mMaxDepthHi)))return false; if(!outFile.write(&mMaxDepthLo,sizeof(mMaxDepthLo)))return false; if(!outFile.write(&mSurfaceTimeHi,sizeof(mSurfaceTimeHi)))return false; if(!outFile.write(&mSurfaceTimeLo,sizeof(mSurfaceTimeLo)))return false; if(!outFile.write(&mTotalAirConsumption,sizeof(mTotalAirConsumption)))return false; if(!outFile.write(&mEntryTime1,sizeof(mEntryTime1)))return false; if(!outFile.write(&mEntryTime2,sizeof(mEntryTime2)))return false; if(!outFile.write(&mEntryTime3,sizeof(mEntryTime3)))return false; if(!outFile.write(&mEntryTime4,sizeof(mEntryTime4)))return false; if(!outFile.write(&mWaterTemperature,sizeof(mWaterTemperature)))return false; return true; }