110 lines
2.4 KiB
C++
110 lines
2.4 KiB
C++
#include <aladin/profiles.hpp>
|
|
#include <aladin/profiledata.hpp>
|
|
#include <aladin/bitmanip.hpp>
|
|
#include <common/stdio.hpp>
|
|
#include <common/file.hpp>
|
|
|
|
bool Profiles::readFrom(RawData &array,Information &info,CurrentStatus &status)
|
|
{
|
|
int index=0;
|
|
int endIndex;
|
|
int time;
|
|
WORD headerLength;
|
|
WORD depth;
|
|
BYTE warnings;
|
|
BYTE decoInfo;
|
|
double conversion=3.281;
|
|
|
|
try
|
|
{
|
|
while(true)
|
|
{
|
|
while(Marker!=array[index]&&index<array.size())index++;
|
|
if(index>array.size()||index>=0x5FF)break;
|
|
index++;
|
|
if(info.isNitroxOnly())index+=23;
|
|
else if(info.isO2())index+=24;
|
|
else index+=22;
|
|
time=20;
|
|
|
|
DiveProfile diveProfile;
|
|
endIndex=getNextMarkerPos(array,index);
|
|
while(index<endIndex&&Marker!=array[index])
|
|
{
|
|
depth=*((WORD*)&array[index]);
|
|
depth=BitManip::reverse(depth);
|
|
warnings=depth&0x3F;
|
|
depth>>=6;
|
|
depth=(int)((((double)depth*10.00/64.00)*conversion)+.5);
|
|
index+=sizeof(WORD);
|
|
if(index>=0x5FF)break;
|
|
ProfileData profileData(depth,time,warnings);
|
|
diveProfile.insert(&ProfileData(depth,time,warnings));
|
|
if(index>=endIndex)
|
|
{
|
|
index-=sizeof(WORD);
|
|
break;
|
|
}
|
|
if(depth==0)break;
|
|
if(!(time%60))
|
|
{
|
|
decoInfo=array[index];
|
|
index++;
|
|
}
|
|
time+=20;
|
|
}
|
|
if(!haveProfile(diveProfile))insert(&diveProfile);
|
|
}
|
|
}
|
|
catch(ArrayIndexOutOfBoundsException exception)
|
|
{
|
|
::OutputDebugString(exception.toString()+String("\n"));
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool Profiles::readFrom(File &inFile)
|
|
{
|
|
int count;
|
|
|
|
if(!inFile.isOkay())return false;
|
|
if(!inFile.read(&count,sizeof(count)))return false;
|
|
for(int index=0;index<count;index++)
|
|
{
|
|
DiveProfile diveProfile;
|
|
if(!diveProfile.readFrom(inFile))return false;
|
|
if(!haveProfile(diveProfile))insert(&diveProfile);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool Profiles::writeTo(File &outFile)
|
|
{
|
|
int count;
|
|
if(!outFile.isOkay())return false;
|
|
count=size();
|
|
if(!outFile.write(&count,sizeof(count)))return false;
|
|
for(int index=0;index<count;index++)
|
|
{
|
|
if(!operator[](index).writeTo(outFile))return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int Profiles::getNextMarkerPos(Array<BYTE> &array,int currIndex)
|
|
{
|
|
while(currIndex<array.size()&&array[currIndex]!=0xFF)currIndex++;
|
|
if(currIndex>=array.size())return array.size()-1;
|
|
return currIndex;
|
|
}
|
|
|
|
bool Profiles::haveProfile(DiveProfile &diveProfile)
|
|
{
|
|
for(int index=0;index<size();index++)
|
|
{
|
|
if(operator[](index)==diveProfile)return true;
|
|
}
|
|
return false;
|
|
}
|