Ejemplo n.º 1
0
bool CHHMRInst::CreateInstrument(void)
{
//	TRACE("CHHMRInst::CreateInstrument()\n");
//	ASSERT(m_pName != NULL);
//	ASSERT(m_pButton != NULL);

	BOOL result = FALSE;

	//find if port exists if it doesn't return false;
	if (!UpdateParams(false))
		return false;

	//char port[32];
	//bool bCameraDo = false;

	//create CHHMRInst object -- we won't actually have a window
	//the window will be in a non-modal dialog box 

	CString cs = AfxRegisterWndClass(NULL, NULL, NULL, NULL);

	result = CreateEx(
			0,               //DWORD dwExStyle, 
			(LPCTSTR)cs,     //LPCTSTR lpszClassName, 
			m_pName,         //LPCTSTR lpszWindowName, 
			0,               //DWORD dwStyle, 
			CRect(0,0,0,0),  //const RECT& rect, 
			NULL,            //CWnd* pParentWnd, 
			0                //UINT nID, 
			);

	bool bParallelPortSetupStatusOK = true;

	if (result) 
	{
		//HHMRs don't have bbm so don't display numeric
		//Don't care on the radix input....
		m_pButton->put_DisplayNumericString(VARIANT_FALSE,0);
		m_pButton->put_FaceColor(COLOR_PAUSE);
		m_pButton->put_Flash(VARIANT_FALSE);

		//no time flag status for HHMR

		//get the other flag status
		m_iFlagOthr = GetPrivateProfileInt(m_pName,FLAGOTHR,-1,m_szIniFile);
		if (m_iFlagOthr == 1)
			m_pButton->ShowIcon_Frown(VARIANT_TRUE);

		//get the comm flag status
		m_iFlagComm = GetPrivateProfileInt(m_pName,FLAGCOMM,-1,m_szIniFile);
		if (m_iFlagComm == 1)
			m_pButton->ShowIcon_Error(VARIANT_TRUE);

		//create each of the pages we'll need in the property sheet
		m_pSummaryPage     = new CHHMRSummary(IDD_HHMRSUMMARY, this);
		m_pDataStatus      = new CHHMRDataStat(IDD_HHMRDATASTATUS_PAGE, this);//m_szIniFile);
		m_pModParams       = new CHHMRModParam(IDD_HHMRMODPARAMS_PAGE,this);
		m_pLegend		   = new CLegend();
		m_pCamera		   = new CHHMRConfig2(IDD_HHMRCONFIG,this);

		//create the user interface dialog box for this instrument
		m_pPropertySheet   = new CHHMRPropertySheet(LPCTSTR(m_pName),this, m_szIniFile);

		m_pPropertySheet->AddPage(m_pSummaryPage);
		m_pPropertySheet->AddPage(m_pDataStatus);
		m_pPropertySheet->AddPage(m_pModParams);
		m_pPropertySheet->AddPage(m_pCamera);
		m_pPropertySheet->AddPage(m_pLegend);

		DWORD dwStyle = 
			WS_POPUP | WS_CAPTION | DS_MODALFRAME |
			WS_MINIMIZEBOX|WS_OVERLAPPED|WS_SYSMENU;

		m_pPropertySheet->Create(this,dwStyle,0);

		m_pPropertySheet->RestartAutoCloseTimer();

		m_pSummaryPage->SetPropertySheet(m_pPropertySheet);
		m_pDataStatus->SetPropertySheet(m_pPropertySheet);
		m_pModParams->SetPropertySheet((CHHMRPropertySheet*)m_pPropertySheet);
		m_pCamera->SetPropertySheet(m_pPropertySheet,false);

		//necessary because PropertySheet doesn't creat a page until 
		//  it needs to display it.  So force it to create them all
		for (int i = m_pPropertySheet->GetPageCount();i>=0;i--)
			m_pPropertySheet->SetActivePage(i-1);

		char szTemp[MAX_PATH];
		GetModuleFileName(AfxGetInstanceHandle(),szTemp,sizeof(szTemp));
		char *c = strrchr(szTemp,'\\');//find the last "\"
		*c = '\0';						//make it null
		strcat(szTemp,"\\");
		
		CString cTemp(szTemp);
		cTemp += m_pName;
		cTemp += ".rtf";
		if (_access(cTemp,4))
		{
			cTemp = szTemp;
			cTemp += "HHMR.rtf";
			if (_access(cTemp,4))
			{
				cTemp = 
				"Instrument Button Colors...\n"
				"GREEN_ICON\nNormal state.\n"
				"---------------------------\n"
				"YELLOW_ICON\nA command has been sent from MIC to the instrument and MIC is waiting for a response.\n"
				"---------------------------\n"
				"RED_ICON\nCommunications Failure! A command has been sent and resent but no acceptable response has been received back from the instrument.\n"
				"---------------------------\n"
				"WHITE_ICON\nFLASHING to previous color. The disk is full or the instrument has a failure which is causing data loss\n"
				"---------------------------\n"
				"GRAY_ICON\nMIC has been instructed not to talk to the instrument.  In all cases this state will eventuall revert to a normal operational state.\n"
				"===========================\n"
				"\n"
				"Instrument Button ICONs...\n"
				"SQUARE_ICON Square: One or more of the tabbed pages have a data item out of tolerance or a configuration mismatch.\n"
				"---------------------------\n"
				"CLOCK_ICON Clock: The difference between MIC's time and the instrument's time is greater than the user set tolerance.\n"
				"---------------------------\n"
				"FLAG_ICON Flag:  MIC has sent and resent a command with no acceptable response and consequently commanded a long break reset in an attempt to reinitialize the instrument or a Hard Checksum Error occurred.\n"
				"---------------------------\n"
				"BELL_ICON Bell: The instrument is currently reporting a \"Measurement Interval of Interest\" or equivalent.\n"	
				"---------------------------\n"
				"FACE_ICON Face: The instrument has reported either a power problem or a battery backed up memory problem.\n"	
				"---------------------------\n"
				"FLOPPY_ICON Floppy Disk & Flashing: MIC has stopped writing to disk and talking to the instrument.  This can be caused by the hard drive being too full, the maximum use of the hard drive set too low, or disk write failure.\n"
				"---------------------------\n"
				"SKULL_ICON Skull and Cross Bones: The instrument has repeatedly failed to respond to commands and long break resets.  MIC will attempt to reset it every 15 minutes or instrument is in a state which is causing DATA LOSS.\n"
				"---------------------------\n"
				"BOMB_ICON Bomb: Configuration Error.  MIC is not configured correctly. Edit the MIC.INI file or delete the instrument object and recreate it to correct this problem.\n";
			}
		}
		m_pLegend->SetText((LPSTR)LPCSTR(cTemp));


		UpdateStrings();

		//set the time to start data collecting 
		SetTimer(TIMER_PAUSE,m_iPauseMax,NULL);

		char port[32];
		bool bCameraDo = false;
		GetPrivateProfileString(m_pName,"CAMERA_PORT","NONE",port,sizeof(port),m_szIniFile);
		for (unsigned int ui = 0; ui < strlen(port); ui++)
				port[ui]=(char)toupper(port[ui]);

		m_pPropertySheet->SetLimits(
				m_lRealThresh,
				m_lTotalThresh,
				m_lTotal1Thresh,
				m_lTotalLThresh,
				m_lSigmaThresh,
				m_dMaxCompress,
				m_dCountTimeUnit,
//				m_dCountTimeExp,
				m_dHighV,
				m_dGateWidth,
				m_dPreDelay,
				m_dHighVoltH, m_dHighVoltL,
				m_cCameraRealorTotals,
//				m_lCameraThreshold,
				bCameraDo = (port[0] == 'P'),
				m_pID);

			//reset the mod params page
			m_pModParams->OnModparamsReset();

		m_dCurrent_State = 1000;
		m_dTick_Count = 0;
		m_dTickToInquire = 0;

		bParallelPortSetupStatusOK = SetupParallelPort(true);

		//register this instument with the com object 
		//note that the DIALOGBOX gets registered -- so that it will receive 
		//the data coming from the port.  We may want to change this to a 
		//separate CWndThread window later on if the interface gets sluggish

		VARIANT_BOOL vbResult;

		m_pComm->RegisterISO(
			(ULONG)m_pPropertySheet->m_hWnd,
			m_iNode,
			STANDARD_ISO,
			VARIANT_FALSE,  //not OOB
			&vbResult);

		m_bGoodRegister = (vbResult == VARIANT_TRUE);

		m_dRetransmit		= 0;		//no retransmitions yet
		m_dLongBreak		= 0;		//not in long break

		//SCR 118
		//EstablishVersionString();

		//tell the files that mic is starting for this instrument
		m_pPropertySheet->WriteToFile(
			TO_CEV | TO_PFM, 
			(m_bNormalShutdown)?TYPE_START:TYPE_ABNORMAL);

	}  //if(result)
	
	return (m_bGoodRegister && bParallelPortSetupStatusOK);
}
Ejemplo n.º 2
0
void CDPlot::FlyOneLine(CDGeometry &cGeometry, CDVector3 cStartPoint, CDVector3 cFlyDirection, double  dPixelWdith, int nColorType, vector<int> &vOneLinePixels, bool &bIsLowResolution )
{
	//set start position and fly direction
	m_OPlotPaticleState.p_dPos[ 0 ] = cStartPoint._x;
	m_OPlotPaticleState.p_dPos[ 1 ] = cStartPoint._y;
	m_OPlotPaticleState.p_dPos[ 2 ] = cStartPoint._z;

	m_OPlotPaticleState.p_dDir[ 0 ] = cFlyDirection._x;
	m_OPlotPaticleState.p_dDir[ 1 ] = cFlyDirection._y;
	m_OPlotPaticleState.p_dDir[ 2 ] = cFlyDirection._z;

	//Reset Pixels
	//OneLinePixels: Pixels array of one flying line
	int nPixelsNum = vOneLinePixels.size();
	for (int j = 0; j < nPixelsNum; j++)
	{
		if (m_nColorType == SURF) 
			vOneLinePixels[j] = 1;//White color, cell surface is to be changed to black
		else
			vOneLinePixels[j] = -1;//default mat color is void, need to be filled one by one
	}
	//Locate initial particle position for tracking
	m_OPlotPaticleState.ClearLevel();
	m_OPlotPaticleState.p_nCELL = cGeometry.LocateParticle(m_OPlotPaticleState, 0,m_OPlotPaticleState.p_dPos,m_OPlotPaticleState.p_dDir);
	if(m_OPlotPaticleState.p_nCELL == -1) // cannot locate position//Wrong Geometry
	{
		Output.OutputMessage([&](){sprintf(Output.p_sPrintStr,"failed to locate initial plotting point: Pos = %.15f %.15f %.15f. Check if the up-left vertex is on a defined surface (latticed)\n",
			m_OPlotPaticleState.p_dPos[0],m_OPlotPaticleState.p_dPos[1],m_OPlotPaticleState.p_dPos[2]);},CDOutput::_ERROR);			
	} 

	double dDTB = -1.0;////////// distance to cell boundary
	double dFlyLengthTot = 0.0;
	int i_pixels = 0;//pixel num of current point

	while (true)
	{
		CDVector3 cTemp(m_OPlotPaticleState.p_dPos[0]-cStartPoint._x,m_OPlotPaticleState.p_dPos[1]-cStartPoint._y,m_OPlotPaticleState.p_dPos[2]-cStartPoint._z);
		dFlyLengthTot = cTemp.GetVecLength() ;//calculate total distance to start point, to avoid numerical error, 20130705
		i_pixels = int( (dFlyLengthTot + dPixelWdith/2.0)/dPixelWdith );				
		if ( (i_pixels >= nPixelsNum) || (i_pixels <0) )break;

		//Mat Plot PixelMatrix, elements are color index, skipped cells are same with its left neighbor element
		if ( nColorType == MAT || nColorType == MAT_SURF)
		{
			m_OPlotPaticleState.p_nMAT = cGeometry.GetCellMat(m_OPlotPaticleState.p_vLocCellsU);
			if (nColorType == MAT)
			{
				vOneLinePixels[i_pixels] = m_OPlotPaticleState.p_nMAT + 1;//mat color
			}
			else if(nColorType == MAT_SURF)
			{
				if (i_pixels == 0)//first element of a new line
				{
					vOneLinePixels[i_pixels] = m_OPlotPaticleState.p_nMAT + 1;//i_width = 0
				}
				else
				{
					if (m_OPlotPaticleState.p_bIsCellChanged)vOneLinePixels[i_pixels] = 0;//Surface is Black
					if( (i_pixels+1) < nPixelsNum )vOneLinePixels[i_pixels+1] = m_OPlotPaticleState.p_nMAT + 1;//Next element is mat color
				}
			}
		}

		if ( nColorType == CELL || nColorType == CELL_SURF)
		{
			
			int nCell = m_OPlotPaticleState.p_nCELL;
			if (nColorType == CELL)
			{
				vOneLinePixels[i_pixels] = nCell + 1;//CELL color
			}
			else if(nColorType == CELL_SURF)
			{
				if (i_pixels == 0)//first element of a new line
				{
					vOneLinePixels[i_pixels] = nCell + 1;//i_width = 0
				}
				else
				{
					if (m_OPlotPaticleState.p_bIsCellChanged)vOneLinePixels[i_pixels] = 0;//Surface is Black
					if( (i_pixels+1) < nPixelsNum )vOneLinePixels[i_pixels+1] = nCell + 1;//Next element is cell color
				}
			}
		}
		//Cell Plot PixelMatrix, surfaces are black, shipped are WHITE
		if (nColorType == SURF)
		{
			if (m_OPlotPaticleState.p_bIsCellChanged)
			{
				if (i_pixels > 0)
				{	
					vOneLinePixels[i_pixels] = 0;//0 black
				}
			}
		}	

		/////////////////////////// Calculate distance to boundary ////////////////////
		if (i_pixels == 0) m_OPlotPaticleState.p_nBoundSURF = 0;  //// particle is NOT on surface at the beginning  
		dDTB = cGeometry.CalcDistToBound(m_OPlotPaticleState);	
		if(dDTB > 0)
		{
			if (bIsLowResolution == false)
			{
				if(dDTB < m_dDeltaWidth1) bIsLowResolution = true;//distance of surfaces is less than pixel width
			}
			/////////////////// Move particle forward to surface, find neighbor cell////////////////////
			m_OPlotPaticleState.FlyByLength( dDTB ); 
			cGeometry.FindNextCell(m_OPlotPaticleState);
		}
		else if(dDTB <= 0)//infinite distance, beyond the image boundary
		{
			// check points on surf or not
			CDVector3 cPosTemp(m_OPlotPaticleState.p_dPos[0],m_OPlotPaticleState.p_dPos[1],m_OPlotPaticleState.p_dPos[2]);
			bool bOnSurf = CheckOnSurf(cGeometry, cPosTemp, cFlyDirection);
			// if on surface, fly one pixel, else fly out of image
			int nFlyPixels = bOnSurf?1:nPixelsNum;
			m_OPlotPaticleState.FlyByLength( dPixelWdith * nPixelsNum ); 		
		}
	}

	return;
}
Ejemplo n.º 3
0
	bool HUGEINT::operator >= (const int n) const{
		HUGEINT cTemp(n);
		return cTemp <= *this;
	}
Ejemplo n.º 4
0
	bool HUGEINT::operator <= (const int n) const{
		HUGEINT cTemp(n);
		return *this <= cTemp;
	}
Ejemplo n.º 5
0
	HUGEINT HUGEINT::operator % (const HUGEINT & a)const{
		HUGEINT cTemp(*this);
		cTemp %= a;
		return cTemp;
	}
Ejemplo n.º 6
0
	HUGEINT& HUGEINT::operator %= (const int n){
		HUGEINT cTemp(n);
		*this %= cTemp;
		return *this;
	}