void SerialDlg::testDevice(void) { CommControl commControl; BYTE prefix(0xFF); GlobalData rcvBuffer; GlobalData 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 &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]&&indexarray.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>=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 strLines; FormatLines::hexasciiLines(strLines,(BYTE*)rcvBuff,sizeof(rcvBuff)); for(index=0;index&)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 void OwnerDrawGraph::setData(DiveProfile &diveProfile) { Block &profileData=(Block &)diveProfile; Array 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;indexline(Point(x,0),Point(x,(int)(double)pData.getDepth()*(double)hRatio),RGB888(0,255,0)); x+=wRatio; } */ for(int index=0;indexline(Point(x,0),Point(x,(int)fp.row()*(double)hRatio),RGB888(0,255,0)); x+=2; // x+=wRatio; } } void OwnerDrawGraph::splineData(Block &profileData,Array &dstPairs,double wRatio) { CatmullRom catmullRom; Array srcPairs; srcPairs.size(width()); dstPairs.size(width()); ::OutputDebugString(String("Entries:")+String().fromInt(profileData.size())+String(" \n")); for(int index=0;index(%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=(Block &)diveProfile; double wRatio=(double)width()/(double)profileData.size(); double hRatio=(double)height()/getMaxDepth(profileData); double x=wRatio; mDIBitmap->setBits(0); for(int index=0;indexline(Point(x,0),Point(x,(int)(double)pData.getDepth()*(double)hRatio),RGB888(0,255,0)); x+=wRatio; } mHasData=true; } */