Files
Work/aladin/hold/profiles.cpp
2024-08-07 09:12:07 -04:00

81 lines
2.1 KiB
C++

#include <aladin/profiles.hpp>
#include <aladin/profiledata.hpp>
#include <aladin/bitmanip.hpp>
#include <common/stdio.hpp>
bool Profiles::readFrom(Array<BYTE> &array,Information &info,CurrentStatus &status)
{
int index=0;
int endIndex;
int time;
WORD headerLength;
WORD depth;
BYTE warnings;
BYTE decoInfo;
double conversion=3.281;
remove();
try
{
while(true)
{
while(Marker!=array[index]&&index<array.size())index++; // locate start marker
if(index>array.size()||index>=0x5FF)break;
// String string;
// ::sprintf(string,"Reading profile at offset: %d (0x%08lx) %02lx,%02lx,%02lx \n",index,index,(int)array.elementAt(index),(int)array.elementAt(index+1),(int)array.elementAt(index+2));
// ::OutputDebugString(string);
index++;
if(info.isNitroxOnly())index+=23;
else if(info.isO2())index+=24;
else index+=22;
time=20;
insert(&DiveProfile());
DiveProfile &diveProfile=operator[](size()-1);
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));
// ::OutputDebugString(String("Time:")+String().fromInt(time)+String(" Depth:")+String().fromInt(depth)+String("\n"));
if(index>=endIndex)
{
index-=sizeof(WORD);
break;
}
if(depth==0)break;
if(!(time%60))
{
decoInfo=array[index];
index++;
}
time+=20;
}
// ::OutputDebugString("*********************************************************\n");
}
}
catch(ArrayIndexOutOfBoundsException exception)
{
::OutputDebugString(exception.toString()+String("\n"));
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;
}