//---------------------------------------------------------
CWKSP_Table * CWKSP_Table_Manager::Get_Data(CSG_Table *pObject)
{
	for(int i=0; i<Get_Count(); i++)
	{
		if( pObject == Get_Data(i)->Get_Object() )
		{
			return( Get_Data(i) );
		}
	}

	return( NULL );
}
//---------------------------------------------------------
CWKSP_PointCloud * CWKSP_PointCloud_Manager::Get_Data(CSG_PointCloud *pObject)
{
	for(int i=0; i<Get_Count(); i++)
	{
		if( pObject == Get_Data(i)->Get_Object() )
		{
			return( Get_Data(i) );
		}
	}

	return( NULL );
}
Ejemplo n.º 3
0
//---------------------------------------------------------
bool CSG_Vector::Multiply(const CSG_Vector &Vector)
{
	if( Get_N() == Vector.Get_N() && Get_N() == 3 )
	{
		CSG_Vector	v(*this);

		Get_Data()[0]	= v[1] * Vector[2] - v[2] * Vector[1];
		Get_Data()[1]	= v[2] * Vector[0] - v[0] * Vector[2];
		Get_Data()[2]	= v[0] * Vector[1] - v[1] * Vector[0];

		return( true );
	}

	return( false );
}
Ejemplo n.º 4
0
//---------------------------------------------------------
double CSG_Vector::Get_Angle(const CSG_Vector &Vector) const
{
	if( Get_N() > Vector.Get_N() )
	{
		return( Vector.Get_Angle(*this) );
	}

	int		i;
	double	A, B, z, *Z	= Get_Data();

	if( (A = Get_Length()) > 0.0 && (B = Vector.Get_Length()) > 0.0 )
	{
		for(i=0, z=0.0; i<Get_N(); i++)
		{
			z	+= Vector[i] * Z[i];
		}

		for(i=Get_N(); i<Vector.Get_N(); i++)
		{
			z	+= Vector[i];
		}

		return( acos(z / (A * B)) );
	}

	return( 0.0 );
}
Ejemplo n.º 5
0
int main(int argc, char* argv[]) {
    pid_t traced_process;
    struct user_regs_struct regs, newregs;
    long ins;
    /* init 0x80, int 3 */
    char code[] = {
        0xcd, 0x80, 0xcc, 0};
    char backup[4];
    if (argc != 2) {
        fprintf(stdout, "%s <pid to be traced> ",
                argv[0], argv[1]);
        exit(1);
    }
    traced_process = atoi(argv[1]);
    ptrace(PTRACE_ATTACH, traced_process, NULL, NULL);
    wait(NULL);
    ptrace(PTRACE_GETREGS, traced_process, NULL, &regs);
    /* copy Instructions into a backup variable */
    Get_Data(traced_process, regs.rip, backup, 3);
    /* put the breakpoint */
    Put_Data(traced_process, regs.rip, code, 3);
    /* let the process continue and execute the int 3 Instruction */
    ptrace(PTRACE_CONT, traced_process, NULL, NULL);
    wait(NULL);
    fprintf(stdout, "The process stopped, putting back "
            "the originak Instructions ");
    fprintf(stdout, "Press <enter> to continue ");
    getchar();
    Put_Data(traced_process, regs.rip, backup, 3);
    /* setting the rip back to the original
     * Instruction to let the process continue */
    ptrace(PTRACE_SETREGS, traced_process, NULL, &regs);
    ptrace(PTRACE_DETACH, traced_process, NULL, NULL);
    return 0;
}
Ejemplo n.º 6
0
float Gyro_To_Angle(unsigned char REG_Address,float Q)
{
	float Gyro;
	Gyro = Get_Data(REG_Address);	     
	Gyro = -(Gyro-Q)/16.4*0.01;         //去除零点偏移,积分计算角速度值,负号为方向处理
	//Angle_g = Angle_a + Gyro*0.01 - Q;
	return Gyro;
}
Ejemplo n.º 7
0
//---------------------------------------------------------
CSG_String CSG_Vector::asString(int Width, int Precision, bool bScientific)	const
{
	CSG_String	s;

	for(int i=0; i<Get_N(); i++)
	{
		s	+= SG_Get_Double_asString(Get_Data(i), Width, Precision, bScientific) + "\n";
	}

	return( s );
}
Ejemplo n.º 8
0
//---------------------------------------------------------
bool CSG_Vector::Add_Row(double Value)
{
	if( m_Array.Inc_Array() )
	{
		Get_Data()[Get_N() - 1]	= Value;

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
CWKSP_Shapes * CWKSP_Shapes_Manager::Add_Data(CSG_Shapes *pObject)
{
	CWKSP_Shapes	*pItem	= Get_Data(pObject);

	if( pItem == NULL && pObject != NULL && pObject->is_Valid() )
	{
		pItem	= _Get_Shapes_Type(pObject->Get_Type())->Add_Data(pObject);
	}

	return( pItem );
}
//---------------------------------------------------------
CWKSP_PointCloud * CWKSP_PointCloud_Manager::Add_Data(CSG_PointCloud *pObject)
{
	CWKSP_PointCloud	*pItem	= Get_Data(pObject);

	if( pItem == NULL && pObject != NULL )
	{
		Add_Item(pItem = new CWKSP_PointCloud(pObject));
	}

	return( pItem );
}
//---------------------------------------------------------
CWKSP_Grids * CWKSP_Grid_Manager::Add_Data(CSG_Grids *pGrids)
{
	CWKSP_Grids	*pItem	= Get_Data(pGrids);

	if( pItem == NULL && pGrids != NULL && pGrids->is_Valid() )
	{
		pItem	= _Get_System(pGrids->Get_System())->Add_Grids(pGrids);
	}

	return( pItem );
}
//---------------------------------------------------------
CWKSP_Table * CWKSP_Table_Manager::Add_Data(CSG_Table *pObject)
{
	CWKSP_Table	*pItem	= Get_Data(pObject);

	if( pItem == NULL && pObject != NULL )
	{
		Add_Item(pItem = new CWKSP_Table(pObject));
	}

	return( pItem );
}
Ejemplo n.º 13
0
//---------------------------------------------------------
bool CSG_Vector::Assign(const CSG_Vector &Vector)
{
	if( Create(Vector.Get_N()) )
	{
		memcpy(Get_Data(), Vector.Get_Data(), Get_N() * sizeof(double));

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
CWKSP_Grid * CWKSP_Grid_Manager::Add_Data(CSG_Grid *pObject)
{
	CWKSP_Grid	*pItem	= Get_Data(pObject);

	if( pItem == NULL && pObject != NULL && pObject->is_Valid() )
	{
		pItem	= _Get_System(pObject->Get_System())->Add_Data(pObject);
	}

	return( pItem );
}
Ejemplo n.º 15
0
void Init_AD7490(void)
{
unsigned char tempdata[2];


port_init_spi();
dummy_spi();							//required to write FF to the ADC on inital					  
dummy_spi();							//power up (mode dependant).

tempdata[0]=0x90;					 	 	 //ADD3 ... ADD0 (channel Vin), PM1, PM0 (mode 1 - powered)
tempdata[1]=0x82;							 //shadow (0, no seq), WEAK (pullup enabled, 1), range (low, 1), 
								         //CODING (binary, 1), data[0] = spi low byte, data[1] = spi high byte,
Get_Data(tempdata);							 //write ADC config word


tempdata[0]=0xB4;						 	 //write to the shadow register, to enable sequenced 
tempdata[1]=0x1F;						     //conversion on 9 i/p channels (Vin0, ... , Vin8)
								         
Get_Data(tempdata);							 //write ADC shadow word
delay_us(10);
}
Ejemplo n.º 16
0
float Accel_To_Angle(unsigned char REG_Address,float Q)   //输入IIC地址和零点误差,输出计算后的角度值
{
	float Angle,Accel;
	Accel = Get_Data(REG_Address);
	Angle = (Accel - Q) /16384;   //计算角度(弧度)
	Angle = Angle*1.54*180/3.14;  //换算成角度
	if(Angle > 100)
	{
		Angle -= 360;
	}
	return Angle;
}
Ejemplo n.º 17
0
bool CSG_Vector::Create(int n, double *Data)
{
	if( n > 0 )
	{
		if( m_Array.Set_Array(n) )
		{
			if( Data )
			{
				memcpy(Get_Data(), Data, n * sizeof(double));
			}
			else
			{
				memset(Get_Data(),    0, n * sizeof(double));
			}

			return( true );
		}
	}

	Destroy();

	return( false );
}
Ejemplo n.º 18
0
//---------------------------------------------------------
bool CSG_Vector::Add_Rows(int nRows)
{
	if( nRows > 0 && m_Array.Set_Array(Get_N() + nRows) )
	{
		for(int i=Get_N()-nRows; i<Get_N(); i++)
		{
			Get_Data()[i]	= 0.0;
		}

		return( true );
	}

	return( false );
}
Ejemplo n.º 19
0
//---------------------------------------------------------
bool CSG_Vector::Multiply(double Scalar)
{
	if( Get_N() > 0 )
	{
		for(int i=0; i<Get_N(); i++)
		{
			Get_Data()[i]	*= Scalar;
		}

		return( true );
	}

	return( false );
}
Ejemplo n.º 20
0
//---------------------------------------------------------
bool CSG_Vector::Subtract(const CSG_Vector &Vector)
{
	if( Get_N() == Vector.Get_N() && Get_N() > 0 )
	{
		for(int i=0; i<Get_N(); i++)
		{
			Get_Data()[i]	-= Vector.Get_Data()[i];
		}

		return( true );
	}

	return( false );
}
Ejemplo n.º 21
0
//---------------------------------------------------------
double CSG_Vector::Multiply_Scalar(const CSG_Vector &Vector) const
{
	double	z	= 0.0;

	if( Get_N() == Vector.Get_N() )
	{
		for(int i=0; i<Get_N(); i++)
		{
			z	+= Get_Data()[i] * Vector[i];
		}
	}

	return( z );
}
Ejemplo n.º 22
0
//---------------------------------------------------------
bool CSG_Vector::Set_Unity(void)
{
	double	Length;

	if( (Length = Get_Length()) > 0.0 )
	{
		for(int i=0; i<Get_N(); i++)
		{
			Get_Data()[i]	/= Length;
		}

		return( true );
	}

	return( false );
}
Ejemplo n.º 23
0
//---------------------------------------------------------
double CSG_Vector::Get_Length(void) const
{
	if( Get_N() > 0 )
	{
		double	z	= 0.0, *Z	= Get_Data();

		for(int i=0; i<Get_N(); i++)
		{
			z	+= Z[i] * Z[i];
		}

		return( sqrt(z) );
	}

	return( 0.0 );
}
Ejemplo n.º 24
0
//---------------------------------------------------------
bool CSG_Vector::is_Equal(const CSG_Vector &Vector) const
{
	if( Get_N() == Vector.Get_N() )
	{
		for(int i=0; i<Get_N(); i++)
		{
			if( Get_Data(i) != Vector.Get_Data(i) )
			{
				return( false );
			}
		}

		return( true );
	}

	return( false );
}
Ejemplo n.º 25
0
//---------------------------------------------------------
bool CWindeffect_Correction::Fit_Scaling_Factor(int x, int y, double &B, double B_min, double B_max, double B_Step)
{
	CSG_Simple_Statistics	Statistics[3];

	CSG_Matrix	Data;

	if( !Get_Data(x, y, Data, Statistics[OBS]) )
	{
		return( false );
	}

	//-----------------------------------------------------
	double	dMin	= -1.0;

	for(double iB=B_min; iB<=B_max; iB+=B_Step)
	{
		int	i;

		Statistics[COR].Create(true);	// reset

		for(i=0; i<Data.Get_NRows(); i++)
		{
			Statistics[COR]	+= Get_Wind_Corr(iB, Data[i][BND], Data[i][WND]);
		}

		Statistics[VAL].Create(false);	// reset

		for(i=0; i<Data.Get_NRows(); i++)
		{
			Statistics[VAL]	+= Statistics[OBS].Get_Mean() * Statistics[COR].Get_Value(i) / Statistics[COR].Get_Mean();
		}

		double	d	= fabs(Statistics[VAL].Get_StdDev() - Statistics[OBS].Get_StdDev());

		if( dMin < 0.0 || dMin > d )
		{
			B		= iB;
			dMin	= d;
		}
	}

	return( dMin >= 0.0 );
}
Ejemplo n.º 26
0
int main(int argc, char **argv) {
    int rank, size, m, n, local_m, local_n, last_add;
    int play;
	char file[20];
    int Recv_size, Send_size;//размеры принимаемых и отправляемых сообщений
    int Gens;//количество поколений
    int dst, src, tag;
	int *Local_World, *Global_World, *Tmp_Buf;
	int i,j,k,l;
	MPI_Status status;
	
	// подключение mpi
    MPI_Init(&argc, &argv);

	// Узнаем ранк процессора и количество процессоров
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);    

	
	Get_Data(&m,&n,&Gens,rank);//считываем входные данные (размеры игрового поля m - количество строк, n - столбцы)
	
	if(rank==0)
	{
		
		Global_World=Mem_Alloc(m+2,n+2);//выделение памяти под всю таблицу
		
		Init_World(Global_World,"input.txt", m, n);//заполнение таблицы
		
		//Draw_World("test1.txt",Global_World,m+2,n+2);
		
		Distrib(Global_World,m,n,size);//рассылка каждому процессору своей рабочей области (кроме нулевого естественно)
		
		local_n=n/size+2;
		local_m=m+2;
		
		Local_World=Mem_Alloc(local_m,local_n);
		
		for(i=0;i<local_m;i++)
			for(j=0;j<local_n;j++)
				Local_World[i*local_n+j]=Global_World[i*(n+2)+j];
		//Draw_World("test2.txt",Local_World,local_m,local_n);
		for(k=0;k<Gens;k++)
		{
			play=1;
			for(l=1;l<size;l++)
				MPI_Send(&play,1,MPI_INT,l,l,MPI_COMM_WORLD);
			
			Life(Local_World,local_m,local_n);
			
			//Draw_World("test3.txt",Local_World,local_m,local_n);
			
			Tmp_Buf=Mem_Alloc(local_m,1);//выделение памяти под массив для обменов	
			Send_size=local_m;			
			Recv_size=local_m;
			
			/* прием последнего столбца с последнего процессора на 0 */
			Receive(&src,&tag,size-1,0);
			MPI_Recv(Tmp_Buf,Recv_size,MPI_INT,src,tag,MPI_COMM_WORLD,&status);
			
			for(i=0;i<local_m;i++)
				Local_World[i*local_n]=Tmp_Buf[i];
			/* -------------------------------------------------------- */
			
			/* отправка последнего столбца из 0 процессора на 1 */
			for(i=0;i<local_m;i++)
				Tmp_Buf[i]=Local_World[i*local_n+local_n-2];
				
			Send(&dst,&tag,1,0);
			MPI_Send(Tmp_Buf,Send_size,MPI_INT,dst,tag,MPI_COMM_WORLD);
			/* -------------------------------------------------------- */	
			
			/* прием первого столбца с 1 процессора на 0 */
			
			Receive(&src,&tag,1,0);
			MPI_Recv(Tmp_Buf,Recv_size,MPI_INT,src,tag,MPI_COMM_WORLD,&status);
			
			for(i=0;i<local_m;i++)
				Local_World[i*local_n+local_n-1]=Tmp_Buf[i];				
			/* -------------------------------------------------------- */
			
			/* отправка 1 столбца в 0 процессоре на последний процессор */
			for(i=0;i<local_m;i++)
				Tmp_Buf[i]=Local_World[i*local_n+1];
			Tmp_Buf[0]=Local_World[0]; //возьня с уголками
			Tmp_Buf[local_m-1]=Local_World[(local_m-1)*local_n];
			
			Send(&dst,&tag,size-1,0);
			MPI_Send(Tmp_Buf,Send_size,MPI_INT,dst,tag,MPI_COMM_WORLD);
			/* -------------------------------------------------------- */		
			free(Tmp_Buf);
		}
		play=0;
		for(l=1;l<size;l++)//рассылка этого флага остальным процессорам
		{
			Send(&dst,&tag,l,l);
			MPI_Send(&play,1,MPI_INT,dst,tag,MPI_COMM_WORLD);
		}

		for(i=0;i<local_m;i++)
			for(j=0;j<local_n;j++)
				Global_World[i*(n+2)+j]=Local_World[i*local_n+j];
		free(Local_World);
		
		//Draw_World("test_f.txt",Global_World,m+2,n+2);
		
		for(k=1;k<size;k++)//прием с каждого процессора соответствуещей части от всего игрового поля
		{
			if(k==size-1)
				last_add=n%size;
			else
				last_add=0;
			
			local_n+=last_add;

			Local_World=Mem_Alloc(local_m,local_n);			

			Recv_size=local_m*local_n;
				
			Receive(&src,&tag,k,k+1);
			MPI_Recv(Local_World,Recv_size,MPI_INT,src,tag,MPI_COMM_WORLD,&status);

			for(i=0;i<local_m;i++)
				for(j=0;j<local_n;j++)
					Global_World[i*(n+2)+(j+(local_n-2)*k)]=Local_World[i*local_n+j];

			free(Local_World);
		}
		Draw_World("test_final.txt",Global_World,m+2,n+2);
		free(Global_World);		
	}
	else
	{
		local_m=m+2;
		if(rank!=size-1)
			local_n=n/size+2;
		else
			local_n=n/size+2+n%size;

		Recv_size=local_m*local_n;

		Local_World=Mem_Alloc(local_m,local_n);
		
		Receive(&src,&tag,0,rank);
		MPI_Recv(Local_World,Recv_size,MPI_INT,src,tag,MPI_COMM_WORLD,&status);//прием соответствующей части от всего игрового поля
		
		//Draw_World("testiyuiasdfhjas.txt",Local_World,local_m,local_n);

		Tmp_Buf=Mem_Alloc(local_m,1);

		Recv_size=local_m;
		Send_size=local_m;
		
		Receive(&src,&tag,0,rank);
		MPI_Recv(&play,1,MPI_INT,src,tag,MPI_COMM_WORLD,&status);//прием флага play
		
		while(play)
		{
			Life(Local_World,local_m,local_n);
			//myprint("test4.txt",play);

			if(rank>0 && rank<size-1)
			{
				/* прием последнего столбца с предыдущего процессора на текущий */
				Receive(&src,&tag,rank-1,0);
				MPI_Recv(Tmp_Buf,Recv_size,MPI_INT,src,tag,MPI_COMM_WORLD,&status);
				for(i=0;i<local_m;i++)
					Local_World[i*local_n]=Tmp_Buf[i];
				/* -------------------------------------------------------- */
				
				/* отправка последнего столбца из текущего процессора на следующий */
				for(i=0;i<local_m;i++)
					Tmp_Buf[i]=Local_World[i*local_n+local_n-2];
				
				Send(&dst,&tag,rank+1,0);
				MPI_Send(Tmp_Buf,Send_size,MPI_INT,dst,tag,MPI_COMM_WORLD);
				/* -------------------------------------------------------- */
				
				/* прием первого столбца со следующего процессора на текущий */

				Receive(&src,&tag,rank+1,0);
				MPI_Recv(Tmp_Buf,Recv_size,MPI_INT,src,tag,MPI_COMM_WORLD,&status);

				for(i=0;i<local_m;i++)
					Local_World[i*local_n+local_n-1]=Tmp_Buf[i];
				/* -------------------------------------------------------- */
				
				/* отправка первого столбца из текущего процессора на предыдущий */
				for(i=0;i<local_m;i++)
					Tmp_Buf[i]=Local_World[i*local_n+1];
					
				Send(&dst,&tag,rank-1,0);
				MPI_Send(Tmp_Buf,Send_size,MPI_INT,dst,tag,MPI_COMM_WORLD);
				/* -------------------------------------------------------- */
			}
			if(rank==size-1)
			{
				/* отправка последнего столбца из последнего процессора на 0 */
				for(i=0;i<local_m;i++)
					Tmp_Buf[i]=Local_World[i*local_n+local_n-2];
				Tmp_Buf[0]=Local_World[local_n-1];
				Tmp_Buf[local_m-1]=Local_World[(local_m-1)*local_n+(local_n-1)];

				Send(&dst,&tag,0,0);
				MPI_Send(Tmp_Buf,Send_size,MPI_INT,dst,tag,MPI_COMM_WORLD);
				/* -------------------------------------------------------- */

				/* прием последнего столбца с предпоследнего процессора на последний (текущий) */

				Receive(&src,&tag,rank-1,0);
				MPI_Recv(Tmp_Buf,Recv_size,MPI_INT,src,tag,MPI_COMM_WORLD,&status);
				for(i=0;i<local_m;i++)
					Local_World[i*local_n]=Tmp_Buf[i];
				/* -------------------------------------------------------- */

				/* отправка первого столбца из последнего процессора на предпоследний */
				for(i=0;i<local_m;i++)
					Tmp_Buf[i]=Local_World[i*local_n+1];
					
				Send(&dst,&tag,rank-1,0);
				MPI_Send(Tmp_Buf,Send_size,MPI_INT,dst,tag,MPI_COMM_WORLD);
				/* -------------------------------------------------------- */				
				
				/* прием первого столбца с 0 процессора на последний */
				
				Receive(&src,&tag,0,0);
				MPI_Recv(Tmp_Buf,Recv_size,MPI_INT,src,tag,MPI_COMM_WORLD,&status);
				for(i=0;i<local_m;i++)
					Local_World[i*local_n+local_n-1]=Tmp_Buf[i];
				/* -------------------------------------------------------- */				
				
			}
			Receive(&src,&tag,0,rank);
			MPI_Recv(&play,1,MPI_INT,src,tag,MPI_COMM_WORLD,&status);//прием флага play
		}
		//Draw_World("test_piska.txt",Local_World,local_m,local_n);

		Send_size=local_n*local_m;
		Send(&dst,&tag,0,rank+1);
		MPI_Send(Local_World,Send_size,MPI_INT,dst,tag,MPI_COMM_WORLD);//отправка соответствующей части на 0 процессор

		free(Tmp_Buf);
	}  
    MPI_Finalize();

    return 0;
}
Ejemplo n.º 27
0
*cdecl cpx_init( XCPB *Xcpb )
{
    OBJECT *tree;
    int    i;

    appl_init();

    currez = Getrez();				/* find current resolution */
    xcpb = Xcpb;
    vhandle = xcpb->handle;
    if( xcpb->booting )
    {
      /* Read in the default settings and set the hardware */
      cur_value = save_vars;
      Init_Speed();
      Init_Block2();
      Set_Data();
      return( ( CPXINFO *)TRUE );  
    }
    else
    {

       open_vwork();
       close_vwork();
       numcol = work_out[13];			/* size of CLUT */
       
       AES_Version = _GemParBlk.global[0];
        
       if( !xcpb->SkipRshFix )
          (*xcpb->rsh_fix)( NUM_OBS, NUM_FRSTR, NUM_FRIMG, NUM_TREE,
                           rs_object, rs_tedinfo, rs_strings, rs_iconblk,
                           rs_bitblk, rs_frstr, rs_frimg, rs_trindex,
                           rs_imdope );
       /*
        * Get the current settings of the hardware and store them
        * in the current GEN structure
        */
       cur_value = save_vars;
       Init_Speed();
       Init_Block2();
       Get_Data();
       push_data();
       cpxinfo.cpx_call   = cpx_call;
       cpxinfo.cpx_draw   = NULL;
       cpxinfo.cpx_wmove  = NULL;
       cpxinfo.cpx_timer  = NULL;
       cpxinfo.cpx_key    = NULL;
       cpxinfo.cpx_button = NULL;
       cpxinfo.cpx_m1 	  = NULL;
       cpxinfo.cpx_m2	  = NULL;
       cpxinfo.cpx_hook	  = NULL;
       cpxinfo.cpx_close  = NULL;

       if( !xcpb->SkipRshFix )
       {
        if(( AES_Version >= 0x0330 )
	    && ( numcol > LWHITE ) )
        {
         tree = ( OBJECT *)rs_trindex[ GENERAL ];
         MakeActivator( GENERAL, GSAVE );
         MakeActivator( GENERAL, GOK );
         MakeActivator( GENERAL, GCANCEL );
	 ObH( GSAVE )    = 16;
	 ObH( GOK )      = 16;
	 ObH( GCANCEL )  = 16;
	 ObIndex( B4 ) &= 0xff00ffffL;

	 ObX( GSAVE ) += 1;
	 ObY( GSAVE ) += 2;
	 ObW( GSAVE ) -= 2;
	 ObH( GSAVE ) -= 3;

	 ObX( GOK ) += 1;
	 ObY( GOK ) += 2;
	 ObW( GOK ) -= 2;
	 ObH( GOK ) -= 3;

	 ObX( GCANCEL ) += 1;
	 ObY( GCANCEL ) += 2;
	 ObW( GCANCEL ) -= 2;
	 ObH( GCANCEL ) -= 3;

	 ObX( LRESP ) += 2;
	 ObX( RRESP ) -= 2;
	 for( i = RESPBASE; i <= LRESP; i++ )
	 {
	    MakeActivator( GENERAL, i );
	    ObH( i ) = 16;
	    if( ( ObType( i ) & 0x00ff ) == G_BOXTEXT )
	      TedColor( i ) = ( TedColor( i ) & 0xff70 ) | LWHITE | 0x70;
	    
	    if( ( ObType( i ) & 0x00ff ) == G_BOXCHAR )
	      ObIndex( i ) = ( ObIndex( i ) & 0xffffff70 ) | LWHITE | 0x70;

	   if( i == RESPBASE )	   
	   {
	     ObX( i ) = ObX( LRESP ) + ObW( LRESP ) + 5;
	     ObW( i ) = ( ObX( RRESP ) - 5 ) - ObX( i );
	   }
	      
	 }   
	 ObIndex( B6 ) &= 0xff00ffffL;
	 ObIndex( B7 ) &= 0xffffff70L;


	 ObX( LREPEAT ) += 2;
	 ObX( RREPEAT ) -= 2;	 
	 for( i = LREPEAT; i <= KREPEAT; i++ )
	 {
	    MakeActivator( GENERAL, i );
	    ObH( i ) = 16;
	    if( ( ObType( i ) & 0x00ff ) == G_BOXTEXT )
	      TedColor( i ) = ( TedColor( i ) & 0xff70 ) | LWHITE | 0x70;

	    if( ( ObType( i ) & 0x00ff ) == G_BOXCHAR )
	      ObIndex( i ) = ( ObIndex( i ) & 0xffffff70 ) | LWHITE | 0x70;

	    if( i == REPTBASE )	   
	    {
	      ObX( i ) = ObX( LREPEAT ) + ObW( LREPEAT ) + 5;
	      ObW( i ) = ( ObX( RREPEAT ) - 5 ) - ObX( i );
	    }

	 }   
	 ObIndex( B8 ) &= 0xff00ffffL;
	 ObIndex( B9 ) &= 0xffffff70L;
	 
	 ObIndex( B0 ) &= 0xffffff70L;
	 MakeActivator( GENERAL, STATUS );
	 ObX( STATUS ) += 1;
	 ObY( STATUS ) += 2;
	 ObW( STATUS ) -= 2;
	 ObH( STATUS ) -= 4;


	 MakeActivator( GENERAL, DOUBLE );
	 ObX( DOUBLE ) += 1;
	 ObY( DOUBLE ) += 1;
	 ObW( DOUBLE ) -= 2;
	 ObH( DOUBLE ) -= 2;
         TedColor( DOUBLE ) = ( TedColor( DOUBLE ) & 0xFF70 ) | LWHITE | 0x70;
	 ObIndex( B5 ) &= 0xff00ff70L;	 	 

	 ObIndex( B1 ) = ( ObIndex( B1 ) & 0xffffff70L ) | LWHITE | 0x70;
	 ObIndex( B2 ) = ( ObIndex( B1 ) & 0xffffff70L ) | LWHITE | 0x70;
	 ObIndex( B3 ) &= 0xffffff70L;

         TedColor( BLK1TXT ) = ( TedColor( BLK1TXT ) & 0xFF70 );
	 ObIndex( BLK1 ) &= 0xffffff70L;
	 tree[(BLK1TXT)].ob_spec.tedinfo->te_thickness = 0;
	 
         TedColor( BLK2TXT ) = ( TedColor( BLK2TXT ) & 0xFF70 );
	 ObIndex( BLK2 ) &= 0xffffff70L;
	 tree[(BLK2TXT)].ob_spec.tedinfo->te_thickness = 0;
	 
         tree = ( OBJECT *)rs_trindex[ PARTZ ];
         MakeActivator( PARTZ, STATOK );
        }
       } /*        if( !xcpb->SkipRshFix )*/

       return( &cpxinfo );
    }
}
Ejemplo n.º 28
0
void CModbusPollView::Fresh_Data(){
	 /*
		-1:no connection
		-2:create write error
		-3:create read error
		-4:time out error
		-5:crc error
		*/
		//SetPaneString(1,g_StrConnection);
	if (!g_online)
	{
		m_connectionState.SetWindowText(L"NO CONNECTION");
		m_connectionState.SetStringFontSize(12);
		COLORREF cf=RGB(255,0,0);
		m_connectionState.SetStringColor(cf);
		//return;
	} 
	else
	{
		if (m_MultiReadReturnType==-1)
		{
			m_connectionState.SetWindowText(L"NO CONNECTION");
			m_connectionState.SetStringFontSize(12);
			COLORREF cf=RGB(255,0,0);
			m_connectionState.SetStringColor(cf);
			//return;
		}
		else if (m_MultiReadReturnType==-2)
		{
			m_connectionState.SetWindowText(L"Write Error");
			m_connectionState.SetStringFontSize(12);
			COLORREF cf=RGB(255,0,0);
			m_connectionState.SetStringColor(cf);
			//return;
		}
		else if (m_MultiReadReturnType==-3)
		{
			m_connectionState.SetWindowText(L"Read Error");
			m_connectionState.SetStringFontSize(12);
			COLORREF cf=RGB(255,0,0);
			m_connectionState.SetStringColor(cf);
			//return;
		}
		else if (m_MultiReadReturnType==-4)
		{
			m_connectionState.SetWindowText(L"Timeout Error");
			m_connectionState.SetStringFontSize(12);
			COLORREF cf=RGB(255,0,0);
			m_connectionState.SetStringColor(cf);
			//return;
		}
		else if (m_MultiReadReturnType==-5)
		{
			m_connectionState.SetWindowText(L"CRC Error");
			m_connectionState.SetStringFontSize(12);
			COLORREF cf=RGB(255,0,0);
			m_connectionState.SetStringColor(cf);
			//return;
		}
		else
		{
              m_connectionState.SetWindowText(L"Connected");
			  m_connectionState.SetStringFontSize(12);
			  COLORREF cf=RGB(100,100,0);
			  m_connectionState.SetStringColor(cf);
			  //SetPaneString(1,L"Connected");
		}
		
// 		m_connectionState.SetStringFontSize(14);
// 		COLORREF cf=RGB(0,0,0);
// 		m_connectionState.SetStringColor(cf);
	}
	

	//m_Tx_Rx.SetWindowText(strTemp);

	CString strTemp;
	if (m_Function==0)
	{
		m_MBPoll_Function=3;
	} 
	else if (m_Function==1)
	{
		m_MBPoll_Function=6;
	}
	else if (m_Function==2)
	{
		m_MBPoll_Function=16;
	}
	else
	{
		m_MBPoll_Function=3;
	}
	CString Stemp;
	//Stemp.Format(_T("Tx=%ld  Err=%d  ID=%d  F=%2d  SR=%d ms"),m_Tx,m_Err,m_Slave_ID,m_MBPoll_Function,m_Scan_Rate);
	Stemp.Format(_T("Tx=%ld:  "),m_Tx);
	strTemp+=Stemp;
	Stemp.Format(_T("Err=%d:  "),m_Err);
	strTemp+=Stemp;
	Stemp.Format(_T("ID=%d:  "),m_Slave_ID);
	strTemp+=Stemp;
	Stemp.Format(_T("F=%02d:  "),m_MBPoll_Function);
	strTemp+=Stemp;
	Stemp.Format(_T("Tx=%dms  "),m_Scan_Rate);
	strTemp+=Stemp;

	m_Tx_Rx.SetWindowText(strTemp);
	m_Tx_Rx.SetStringFontSize(15);
	CString showmodelname;
 	if (m_isgetmodel)
 	{
		
		//Model Name:
		showmodelname=_T("Model Name:");
		m_modelib.SetWindowText(showmodelname);
		m_modelib.SetStringFontSize(13);
		CString showslaveid;
		showslaveid.Format(_T("ID:%d"),m_modeldata[0]);
		m_SlaveIDRichEditCtrl.SetWindowText(showslaveid);
		m_SlaveIDRichEditCtrl.SetStringFontSize(13);
	}
	if (m_cur_modelNo!=m_modeldata[0])
	{
	  m_ischangedAddress=TRUE;
	}
	//Initial_RegName();
	COLORREF  cf=RGB(255,255,255);
/*	m_modelname=GetProductName(m_modeldata[1]);*/
	if (m_modelname.IsEmpty())
	{

		m_ModelNameRichEdit.SetReadOnly(FALSE);
		m_ModelNameRichEdit.SetBackgroundColor(FALSE,cf);
	}
	else
	{
	   if (m_ischangeModelName)
	   {
		   m_ModelNameRichEdit.SetReadOnly(FALSE);
		   m_ModelNameRichEdit.SetBackgroundColor(FALSE,cf);
	   } 
	   else
	   {
		   

		   cf=RGB(212,208,200);
		   m_ModelNameRichEdit.SetReadOnly(TRUE);
		   m_ModelNameRichEdit.SetBackgroundColor(FALSE,cf);
		   showmodelname.Format(_T("%s"),m_cur_modelName.GetBuffer());
		   m_ModelNameRichEdit.SetWindowText(showmodelname);
		   m_ModelNameRichEdit.SetStringFontSize(13);
	   }
	    
	}
	

	if (m_Rows==0)
	{
		m_data_rows=10;
	}
	else if (m_Rows==1)
	{
		m_data_rows=20;
	}
	else if (m_Rows==2)
	{
		m_data_rows=50;
	}
	else if (m_Rows==3)
	{
		m_data_rows=100;
	}
	else 
	{
		m_data_rows=m_Quantity;
	}
	m_data_cols=m_Quantity/m_data_rows;
	if (m_Quantity%m_data_rows!=0)
	{
		m_data_cols+=1;
	} 
	/*
	  m_Grid_Type_1:
	  m_Hide_Alias_Columns=0;
	  m_Address_Cell=0;
	  m_PLC_Addresses=0;

	  m_Grid_Type_2:
	  m_Hide_Alias_Columns=0;
	  m_Address_Cell=0;
	  m_PLC_Addresses=1;

	  m_Grid_Type_3:
	  m_Hide_Alias_Columns=0;
	  m_Address_Cell=1;
	  m_PLC_Addresses=0;


	  m_Grid_Type_4:
	  m_Hide_Alias_Columns=0;
	  m_Address_Cell=1;
	  m_PLC_Addresses=1;

	  m_Grid_Type_3:
	  m_Hide_Alias_Columns=1;
	  m_Address_Cell=0;
	  m_PLC_Addresses=0;

	  m_Grid_Type_3:
	  m_Hide_Alias_Columns=1;
	  m_Address_Cell=0;
	  m_PLC_Addresses=1;

	  m_Grid_Type_3:
	  m_Hide_Alias_Columns=1;
	  m_Address_Cell=1;
	  m_PLC_Addresses=0;


	  m_Grid_Type_3:
	  m_Hide_Alias_Columns=1;
	  m_Address_Cell=1;
	  m_PLC_Addresses=1;
	  
	*/
    /*
	如果 m_Hide_Alias=0;
	m_grid_cols=2*m_data_cols+1;
	m_grid_rows=m_data_rows+1;

	如果 m_Hide_Alias=1;
	m_grid_cols=m_data_cols+1;
	m_grid_rows=m_data_rows+1;
	*/

	if (m_Hide_Alias_Columns!=0)
	{
	m_grid_cols=2*m_data_cols+1;
	m_grid_rows=m_data_rows+1;
	} 
	else
	{
	m_grid_cols=3*m_data_cols+1;
	m_grid_rows=m_data_rows+1;
	}
	m_MsDataGrid.put_Cols(m_grid_cols);
	m_MsDataGrid.put_Rows(m_grid_rows);

	CString index;
	CString DataTemp;
	int Index;
	int Index_start,Index_end,row;
	//写下标
	if (m_PLC_Addresses==1)
	{
		Index_start=1;
		Index_end=m_MsDataGrid.get_Rows();

	} 
	else
	{
		Index_start=0;
		Index_end=m_MsDataGrid.get_Rows()-1;
	}
	row=1;
	for (int i=Index_start;i<Index_end;i++)
	{
		index.Format(_T("%d"),i);
		m_MsDataGrid.put_TextMatrix(row,0,index);
		row++;
	}
	//把索引隐藏掉
	m_MsDataGrid.put_ColWidth(0,0);
	//这里主要是不要显示index行,如果要显示的话,就要把这行屏蔽掉,就可以了
	//Modbus Poll的
	if (m_Hide_Alias_Columns!=0)
	{
		 //初始化第0行
		for (int i=1;i<m_MsDataGrid.get_Cols();i++)
		{
			index.Format(_T("%d"),m_address+(i-1)*(m_MsDataGrid.get_Rows()-1));
			m_MsDataGrid.put_TextMatrix(0,i,index);
		}
		
// 			for (int j=1;j<m_MsDataGrid.get_Cols();j++)
// 			{
// 				for (int i=1;i<m_MsDataGrid.get_Rows();i++)
// 				{
// 					Index=(j-1)*(m_MsDataGrid.get_Rows()-1)+(i-1);
// 					if (Index<=m_Quantity)
// 					{
// 						m_MsDataGrid.put_TextMatrix(i,j,Get_Data(Index));
// 					}
// 				}
// 			}


 			for (int i=1;i<m_MsDataGrid.get_Cols();i++)
 			{
 				for (int j=0;j<m_MsDataGrid.get_Rows();j++)
 				{
 
 					if (j==0)
 					{
 						//初始化第0行
 						if (i%2==1)
 						{
 							index=L"Address";
 							m_MsDataGrid.put_TextMatrix(0,i,index);
 						} 
 						else
 						{
 							index=L"Value";
 							m_MsDataGrid.put_TextMatrix(0,i,index);
 						}
 					} 
 					else
 					{
					    if (i%2==0)
					    {
						Index=(i/2-1)*(m_MsDataGrid.get_Rows()-1)+(j-1);
					    } 
					    else
					    {
						Index=(i/2)*(m_MsDataGrid.get_Rows()-1)+(j-1);
					    }
  						
  						if (i%2==1)//Add
  						{
  							if (Index<=m_Quantity)
  							{
  								CString StrTemp;
  								StrTemp.Format(_T("%d"),Get_Reg_Add(Index));
  								m_MsDataGrid.put_TextMatrix(j,i,StrTemp);
  							}
  						}
  						else//Value
  						{
  							if (Index<=m_Quantity)
  							{
  								m_MsDataGrid.put_TextMatrix(j,i,Get_Data(Index));
  							}
  						}
 					}
 				}
 			}
	}
	else{
		//初始化行
		for (int i=1;i<m_MsDataGrid.get_Cols();i++)
		{

			
			 
			for (int j=0;j<m_MsDataGrid.get_Rows();j++)
			{
                 if (j==0)
                 {
					 //初始化第0行
					 if((i%3)==1)
					 {
						 index=L"Description";
						 m_MsDataGrid.put_TextMatrix(0,i,index);
					 } 
					else if ((i%3)==2)
					 {
						 index=L"Address";
						 m_MsDataGrid.put_TextMatrix(0,i,index);
					 } 
					 else if ((i%3)==0)
					 {
						 index=L"Value";
						 m_MsDataGrid.put_TextMatrix(0,i,index);
					 }
					 
                 } 
                 else
                 {
					 if ((i%3)==1)
					 {
						 Index=((i+2)/3-1)*(m_MsDataGrid.get_Rows()-1)+(j-1);
						 m_MsDataGrid.put_TextMatrix(j,i, m_Alias[Index]);

					 }
					 else if ((i%3)==2)
					 {
						 Index=((i+1)/3-1)*(m_MsDataGrid.get_Rows()-1)+(j-1);
						 if (Index<=m_Quantity)
						 {
							 CString StrTemp;
							 StrTemp.Format(_T("%d"),Get_Reg_Add(Index));
							 m_MsDataGrid.put_TextMatrix(j,i,StrTemp);
							 
						 }
						 
					 }
					 else if ((i%3)==0)
					 {
						 Index=(i/3-1)*(m_MsDataGrid.get_Rows()-1)+(j-1);
						 if (Index<=m_Quantity)
						 {
							 m_MsDataGrid.put_TextMatrix(j,i,Get_Data(Index));
						 }
					 }


				 }
			}
		}
	}

   
      
     if(g_Draw_dlg!=NULL)  //&& g_Draw_dlg->IsWindowVisible()
     {
        
         for (vector<Registers_Infor>::iterator it=g_vectRegisters.begin();it!=g_vectRegisters.end();)
         {
             RegPoint pt ;
             pt.Time_offset=g_Time_Offset;
             pt.Value_offset=(unsigned short )m_DataBuffer[it->address-m_address];
             it->Reg_Point.push_back(pt);
             ++it;
         }
         g_Time_Offset+=5;
         if (g_Time_Offset%10==0)
         {
            ::PostMessage(g_Draw_dlg->m_hWnd,MY_FRESH_DRAW_GRAPHIC,0,0);
            Sleep(200);   //响应绘图
         } 
       
     }
     else
     {
        
     }
    
/////////////////记录数据 Txt 
	if (!m_logText)
	{
		if (!m_logTextPath.IsEmpty())
		{
			CString Data;
			 
				CString TxtString=Get_Now();
				Data.Format(_T("<%04d>"),m_address);
				TxtString+=Data;
				TxtString+=_T("    ");
				for (int i=0;i<m_Quantity;i++)
				{

					Data.Format(_T("%d    "),m_DataBuffer[i]);
					TxtString+=Data;

				}
				TxtString+=_T("\n");
				m_default_file.WriteString(TxtString);
			 
	 	}
		
		
	}
	CString str;
	if (!m_logExcel)
	{
	   ++m_curexcelrow;

	   str=Get_Now();
	   m_rgMyRge.SetItem(_variant_t((long)m_curexcelrow),_variant_t((long)1),_variant_t(str));
	   for (int i=0;i<m_Quantity;i++)
	   {
		   str.Format(_T("%d"),m_DataBuffer[i]);
		   m_rgMyRge.SetItem(_variant_t((long)m_curexcelrow),_variant_t((long)i+2),_variant_t(str));
	   }

	}
	// 	CString str;
// 	str = _T("医疗机构许可证信息查询结果");
// 	rgMyRge.SetItem(_variant_t((long)1),_variant_t((long)2),_variant_t(str)); 
// 	str = _T("许可证编号");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)1),_variant_t(str)); 
// 	str = _T("机构名称");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)2),_variant_t(str)); 
// 	str = _T("经营性质");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)3),_variant_t(str));
// 	str = _T("经济性质");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)4),_variant_t(str));
// 	str = _T("负责人");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)5),_variant_t(str));
// 	str = _T("法人代表");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)6),_variant_t(str));
// 	str = _T("诊疗科目");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)7),_variant_t(str));
// 	str =_T( "地址");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)8),_variant_t(str));
// 	str = _T("电话");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)8),_variant_t(str));
// 	str = _T("发证日期");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)9),_variant_t(str));
// 	str = _T("有效期截止");
// 	rgMyRge.SetItem(_variant_t((long)2),_variant_t((long)10),_variant_t(str));
// 	
// 	
// 	
// 	//ExcelApp.SetVisible(true); 
// 	
// 	
// 	 
// 	rgMyRge.AttachDispatch(wsMysheet.GetCells());
// 
// 
// 	for (int i = 0; i < 200; i++)
// 	{
// 
// 
//         rgMyRge1.AttachDispatch(rgMyRge.GetItem(COleVariant((long)3+i), COleVariant((long)3+i)).pdispVal, TRUE);
//         rgMyRge1.AttachDispatch(rgMyRge1.GetEntireRow(), TRUE);
// 
//         rgMyRge2.AttachDispatch(rgMyRge.GetItem(COleVariant((long)2+i), COleVariant((long)1+i)).pdispVal, TRUE);
//         rgMyRge2.AttachDispatch(rgMyRge2.GetEntireRow(), TRUE);
// 
//         rgMyRge2.Copy(covOptional);
//         rgMyRge1.Insert(COleVariant((long)3+i));
// 
// 		Sleep(2000);
// 		/*rgMyRge2.Copy(covOptional);
// 		rgMyRge1.Insert(COleVariant(1L));*/
// 	}
	//for (int i = 0; i < 5; i++)
	//{
	//	rgMyRge1.Insert(COleVariant(1L));
	//}
	
	//wbMyBook.PrintPreview(_variant_t(false)); 
	//释放对象 
	
	 
}