Files
Work/aladin/scraps.txt
2024-08-07 09:12:07 -04:00

418 lines
12 KiB
Plaintext

void SerialDlg::testDevice(void)
{
CommControl commControl;
BYTE prefix(0xFF);
GlobalData<BYTE> rcvBuffer;
GlobalData<BYTE> sndBuffer;
BYTE codeBytes[]={0x8E,0x00,0xFF,0xCE,0x10,0x00,0x6F,0x2C,0xCC,0x33,0x0C,0xA7,0x2B,0xE7,0x2D,0x1F,0x2E,0x20,0xFC,0xA6,0x2F,0x4C,0x1F,0x2E,0x80,0xFC,0xA7,0x2F,0x7E,0x00,0x0F};
sndBuffer.size(256);
sndBuffer.setZero();
rcvBuffer.size(sndBuffer.size());
rcvBuffer.setZero();
::memcpy(&sndBuffer[0],codeBytes,sizeof(codeBytes));
if(IDCANCEL==::MessageBox(*this,"This operation will overwrite the contents of MCU RAM with the ECHO program.","WARNING",MB_OKCANCEL))return;
if(!commControl.open(getCommPort())){mStatusBar->setText("Error opening port.");return;}
if(!commControl.setDeviceControlBlock(getCommSettings())){mStatusBar->setText("Failed to apply settings.");return;}
mStatusBar->setText("waiting for break signal....please reset the device.");
if(!commControl.waitForBreak()){mStatusBar->setText("timeout waiting for break.");return;}
mStatusBar->setText("break received, loading code...");
commControl.write(&prefix,sizeof(prefix));
commControl.clearReceiveQueue();
commControl.write(sndBuffer);
mStatusBar->setText("Waiting for response.");
if(!commControl.waitForData()){mStatusBar->setText("Timeout reached for receive.");return;}
commControl.readFully(rcvBuffer);
if(::memcmp(&rcvBuffer[0],&sndBuffer[0],sndBuffer.size()))
{
mStatusBar->setText("Failed to verify program load.");
return;
}
::Sleep(250);
if(!echo(commControl))mStatusBar->setText("Received unexpected results from program.");
else mStatusBar->setText("The program has been verified, all tests successful.");
return;
}
bool SerialDlg::echo(CommControl &commControl)
{
BYTE sndByte('a');
BYTE rcvByte=0;
DWORD rcvCount(0);
String str;
if(!commControl.isOkay())
{
if(!commControl.open(getCommPort())){mStatusBar->setText("Unable to open comm port.");mStatusBar->setText("Error opening port.");return false;}
if(!commControl.setDeviceControlBlock(getCommSettings())){mStatusBar->setText("Failed to apply settings.");return false;}
}
commControl.clearError();
while('z'!=rcvByte)
{
CommStatus commStatus;
commControl.write(&sndByte,sizeof(sndByte));
if(commControl.waitForData())
{
rcvByte=0;
commControl.read(&rcvByte,sizeof(rcvByte));
str+=rcvByte;
mStatusBar->setText(str);
if(!rcvCount&&rcvByte!='b')
{
mStatusBar->setText("Unexpected character in input stream.");
return false;
}
sndByte++;
rcvCount++;
}
}
::Sleep(250);
return true;
}
String SerialDlg::getByteString(BYTE charByte)
{
String str;
::sprintf(str.str(),"char:%d(0x%08lx)",(int)charByte,(int)charByte);
return str;
}
unsigned long DiveLog::getEntryTimeLong(void)const
{
return mEntryTime1*Math::power(2,24)+mEntryTime2*Math::power(2,16)+mEntryTime3*Math::power(2,8)+mEntryTime4;
}
/*
bool Profile::readFrom(Array<BYTE> &array,Information &info,CurrentStatus &status)
{
int index=0;
int endIndex;
int time;
WORD headerLength;
WORD depthAt20;
BYTE warningAt20;
WORD depthAt40;
BYTE warningAt40;
WORD depthAt60;
BYTE warningAt60;
BYTE decoInfo;
double conversion;
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;
DiveProfile diveProfile;
insert(&diveProfile);
endIndex=getNextMarkerPos(array,index);
while(index<endIndex&&Marker!=array[index])
{
depthAt20=*((WORD*)&array[index]);
depthAt20=BitManip::reverse(depthAt20);
warningAt20=depthAt20&0x3F;
depthAt20>>=6;
// depthAt20=depthAt20*10/64;
index+=sizeof(WORD);
if(index>=0x5FF)break;
diveProfile.insert(&ProfileData(depthAt20*conversion,time,warningAt20));
::OutputDebugString(String("Time:")+String().fromInt(time)+String(" Depth:")+String().fromInt(depthAt20*conversion)+String("\n"));
time+=20;
if(index>=endIndex)
{
index-=sizeof(WORD);
break;
}
if(depthAt20==0)break;
depthAt40=*((WORD*)&array[index]);
depthAt40=BitManip::reverse(depthAt40);
warningAt40=depthAt40&0x3F;
depthAt40>>=6;
depthAt40=depthAt40*10/64;
index+=sizeof(WORD);
if(index>=0x5FF)break;
diveProfile.insert(&ProfileData(depthAt40*conversion,time,warningAt40));
::OutputDebugString(String("Time:")+String().fromInt(time)+String(" Depth:")+String().fromInt(depthAt40*conversion)+String("\n"));
time+=20;
if(index>=endIndex)
{
index-=sizeof(WORD);
break;
}
depthAt60=*((WORD*)&array[index]);
depthAt60=BitManip::reverse(depthAt60);
warningAt60=depthAt60&0x3F;
depthAt60>>=6;
depthAt60=depthAt60*10/64;
index+=sizeof(WORD);
if(index>=0x5FF)break;
diveProfile.insert(&ProfileData(depthAt60,time,warningAt60));
::OutputDebugString(String("Time:")+String().fromInt(time)+String(" Depth:")+String().fromInt(depthAt60*conversion)+String("\n"));
time+=20;
if(index>=endIndex)
{
index-=sizeof(WORD);
break;
}
decoInfo=array[index];
index++;
}
::OutputDebugString("*********************************************************\n");
}
}
catch(ArrayIndexOutOfBoundsException exception)
{
::OutputDebugString(exception.toString()+String("\n"));
return false;
}
return true;
} */
/* Worksheet worksheet;
// Worksheet load;
// int rows(10);
// int cols(10);
// worksheet.setDimensions(rows,cols);
worksheet.open("d:\\parts\\lotus\\a.wk1");
worksheet.save("d:\\mysheet.wk1");
// worksheet.open("d:\\divelog.123"); */
/* File outFile("c:\\aladin2.dat","wb");
File outFile2("c:\\aladin2.txt","wb");
outFile.write(syncBuff,sizeof(syncBuff));
outFile.write(rcvBuff,sizeof(rcvBuff));
Block<String> strLines;
FormatLines::hexasciiLines(strLines,(BYTE*)rcvBuff,sizeof(rcvBuff));
for(index=0;index<strLines.size();index++)
{
outFile2.writeLine(strLines[index]);
}
outFile.close(); */
void DiveDlg::addDiveLog(Worksheet &worksheet,const LogBook &logBook,int startRow,int startCol)
{
worksheet.setAt(startRow,startCol+(5/2),"DiveLog");
worksheet.setAt(startRow,startCol,"Entry Time");
worksheet.setAt(startRow,startCol+1,"Max Depth");
worksheet.setAt(startRow,startCol+2,"Bottom Time");
worksheet.setAt(startRow,startCol+3,"Surface Time");
worksheet.setAt(startRow,startCol+4,"Temperature");
for(int index=0;index<logBook.size();index++)
{
const DiveLog &diveLog=((LogBook&)logBook)[index];
startRow++;
worksheet.setAt(startRow,startCol,diveLog.getEntryTime().toString());
worksheet.setAt(startRow,startCol+1,diveLog.getMaxDepth());
worksheet.setAt(startRow,startCol+2,diveLog.getBottomTime());
worksheet.setAt(startRow,startCol+3,diveLog.getSurfaceTime().toString());
worksheet.setAt(startRow,startCol+4,diveLog.getWaterTemperature());
}
}
void DiveDlg::addProfile(Worksheet &worksheet,const Profile &profile,int startRow,int startCol)
{
int sRow(startRow);
for(int pIndex=0;pIndex<profile.size();pIndex++)
{
DiveProfile &diveProfile=((Block<DiveProfile>&)profile)[pIndex];
sRow=startRow;
String strTitle(String("Profile_")+String().fromInt(pIndex+1));
worksheet.setAt(sRow++,startCol,strTitle);
worksheet.setAt(sRow,startCol,"Time");
worksheet.setAt(sRow++,startCol+1,"Depth");
for(int diveIndex=0;diveIndex<diveProfile.size();diveIndex++)
{
ProfileData &profileData=diveProfile[diveIndex];
worksheet.setAt(sRow,startCol,profileData.getStageTime());
worksheet.setAt(sRow++,startCol+1,profileData.getDepth());
}
startCol+=2;
}
}
// if(!control.waitForData(1000))
// {
// progress.setText("No data arriving on port...");
// return false;
// }
/*bool Aladin::openRaw(const String &strPathFileName)
{
BYTE header[4];
mIsOkay=false;
File inFile;
if(!inFile.open(strPathFileName,"rb"))return false;
if(!inFile.read(header,sizeof(header)))return false;
if(::memcmp(header,"UUU\0",sizeof(header)))return false;
if(!inFile.read(&mRawData[0],mRawData.size()))return false;
mIsOkay=readRaw(mRawData);
mCanSaveRaw=true;
return mIsOkay;
}*/
#include <common/catmull.hpp>
void OwnerDrawGraph::setData(DiveProfile &diveProfile)
{
Block<ProfileData> &profileData=(Block<ProfileData> &)diveProfile;
Array<FloatPairs> dstPairs;
double wRatio=(double)width()/(double)profileData.size();
double hRatio=(double)height()/getMaxDepth(profileData);
double x=wRatio;
::OutputDebugString(String("Width:")+String().fromInt(width())+String(" entries:")+String().fromInt(profileData.size())+String(" Ratio:")+String().fromDouble(wRatio)+String("\n"));
splineData(profileData,dstPairs,wRatio);
::OutputDebugString(String("Width:")+String().fromInt(width())+String(" entries:")+String().fromInt(profileData.size())+String(" Ratio:")+String().fromDouble(wRatio)+String("\n"));
mDIBitmap->setBits(0);
/* for(int index=0;index<profileData.size();index++)
{
ProfileData &pData=profileData[index];
mDIBitmap->line(Point(x,0),Point(x,(int)(double)pData.getDepth()*(double)hRatio),RGB888(0,255,0));
x+=wRatio;
} */
for(int index=0;index<dstPairs.size();index++)
{
FloatPairs &fp=dstPairs[index];
// ProfileData &pData=profileData[index];
mDIBitmap->line(Point(x,0),Point(x,(int)fp.row()*(double)hRatio),RGB888(0,255,0));
x+=2;
// x+=wRatio;
}
}
void OwnerDrawGraph::splineData(Block<ProfileData> &profileData,Array<FloatPairs> &dstPairs,double wRatio)
{
CatmullRom catmullRom;
Array<FloatPairs> srcPairs;
srcPairs.size(width());
dstPairs.size(width());
::OutputDebugString(String("Entries:")+String().fromInt(profileData.size())+String(" \n"));
for(int index=0;index<srcPairs.size();index++)
{
// ::OutputDebugString(String().fromInt(index/wRatio)+String("\n"));
srcPairs[index]=FloatPairs(index,profileData[index/wRatio].getDepth());
dstPairs[index]=FloatPairs(index,0.00);
}
catmullRom.performSpline(srcPairs,dstPairs);
for(index=0;index<dstPairs.size();index++)
{
::OutputDebugString(String("col:")+String().fromInt(index)+String(" row:")+String().fromInt() );
}
}
void OwnerDrawGraph::setLabels(double hRatio,double wRatio,int maxDepth)
{
String strPoints;
Point p1;
Point p2;
int hashWidth=3;
RGB888 hashColor(255,255,255);
for(int depth=0;depth<=maxDepth;depth+=10)
{
p1=Point(0,(int)(double)depth*(double)hRatio);
p2=Point(hashWidth,(int)(double)depth*(double)hRatio);
if(!p1.y())p1.y(1);
if(!p2.y())p2.y(1);
p1.y(height()-p1.y());
p2.y(height()-p2.y());
::sprintf(strPoints.str(),"(%d,%d)->(%d,%d)\n",p1.x(),p1.y(),p2.x(),p2.y());
::OutputDebugString(strPoints.str());
mDIBitmap->line(p1,p2,hashColor);
// if(!depth)break;
}
/*
p1=Point(0,(int)(double)depth*(double)hRatio);
p2=Point(5,(int)(double)depth*(double)hRatio);
p1.y(height()-p1.y());
p2.y(height()-p2.y());
if(p1.y()<=0)p1.y(1);
if(p2.y()<=0)p2.y(1);
mDIBitmap->line(p1,p2,RGB888(0,255,0));
*/
}
/*
void OwnerDrawGraph::setData(DiveProfile &diveProfile)
{
Block<ProfileData> &profileData=(Block<ProfileData> &)diveProfile;
double wRatio=(double)width()/(double)profileData.size();
double hRatio=(double)height()/getMaxDepth(profileData);
double x=wRatio;
mDIBitmap->setBits(0);
for(int index=0;index<profileData.size();index++)
{
ProfileData &pData=profileData[index];
mDIBitmap->line(Point(x,0),Point(x,(int)(double)pData.getDepth()*(double)hRatio),RGB888(0,255,0));
x+=wRatio;
}
mHasData=true;
}
*/