⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mop.cpp

📁 通过PC并口模拟I2C信号
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}

int Cmop::CP_from_CP10(int CP10)
{
	int charge_pump_current[10]={155,330,690,1450};
	return charge_pump_current[CP10];
}

long Cmop::step_from_R43210(int R43210)
{
	long step;
	long R43,R210;
	long Ratio=0;
	R43=(R43210>>3)&0x03;
	R210=R43210&0x07;
//	R43=(byte[3]>>3)&0x03;
//	R210=byte[3]&0x07;
	if(R43==0) Ratio=16;
	if(R43==1) Ratio=20;
	if(R43==2) Ratio=24;
	if(R43==3) Ratio=28;
	if( (R210>=3)&&(R210<=6) ) Ratio*=long(pow(2,(R210-3)));
	else Ratio=0;
	long xtal;
	xtal=((CMainFrame*)m_pParent)->pt.xtal;//[Hz]
//	if(Ratio!=0) step=xtal/Ratio;//minimum Ratio=16
	if(Ratio>0) step=long( double(xtal)/double(Ratio) +.5);//minimum Ratio=16
	else step=-1;
	return step;
}

CString Cmop::band_from_BS10P3210(int BS10, int P3210)
{
	//V0.01[050802]
	CString band="";
	if((BS10==0)&&(P3210==1)) band=BAND[0];
	if((BS10==1)&&(P3210==2)) band=BAND[1];
	if((BS10==2)&&(P3210==4)) band=BAND[2];
	if((BS10==3)&&(P3210==0)) band=BAND[3];
	return band;

	/*
	CString band="";
	if((BS10==0)&&(P3210==1)) band="Low";
	if((BS10==1)&&(P3210==2)) band="Mid";
	if((BS10==2)&&(P3210==4)) band="High";
//	if((BS10==2)&&(P3210==3)) band="High";
	if((BS10==3)&&(P3210==0)) band="ALL off";
	return band;
	*/
}

void Cmop::set_dialog_cp()
{
	m_cp.Format("%d",CP_from_byte( ((CMainFrame*)m_pParent)->pt.byte ));
	UpdateData(FALSE);
}

void Cmop::set_dialog_step()
{
	long step;
	step=step_from_byte( ((CMainFrame*)m_pParent)->pt.byte );
	m_step.Format("%.3lf",double(step)/1000.);
	UpdateData(FALSE);
}

void Cmop::set_dialog_band()
{
	m_band=band_from_byte( ((CMainFrame*)m_pParent)->pt.byte );
	UpdateData(FALSE);
}

//-----read dialog property
void Cmop::calculate_byte_from_dialog()
{
	get_dialog();

	//freq
	calculate_byte_from_freq(((CMainFrame*)m_pParent)->pt.freq);

	//CP
	int CP10;
	CP10=calculate_CP10_from_charge_pump_current( ((CMainFrame*)m_pParent)->pt.charge_pump_current );
	if(CP10!=-1) calculate_byte_from_CP10(CP10);
	else MessageBox("CP10?");

	//pll setp
	int R43210;
	R43210=calculate_R43210_from_step(((CMainFrame*)m_pParent)->pt.pll_step); //Hz
	if(R43210!=-1) calculate_byte_from_R43210(R43210);
	else MessageBox("R43210?");

	//band
	int BS10P3210;
	BS10P3210=calculate_BS10P3210_from_band(((CMainFrame*)m_pParent)->pt.band);
	if(BS10P3210!=-1) calculate_byte_from_BS10P3210(BS10P3210);
	else MessageBox("BS10P3210?");

	//agc threshold
	int AT210;
	AT210=calculate_AT210_from_agc_threshold(((CMainFrame*)m_pParent)->pt.agc_threshold);
	if(AT210!=-1) calculate_byte_from_AT210(AT210);
	else MessageBox("AT210?");

	/*
	calculate_byte_from_dialog_freq();//xxxxx
	calculate_byte_from_dialog_cp();//xxxxx
	calculate_byte_from_dialog_step();//xxxxx
	calculate_byte_from_dialog_band();//xxxxx
	*/
}

//-----freq
//		void Cmop::calculate_byte_from_dialog_freq()
//		{
//			double data;
//			long freq;
//			UpdateData(TRUE);
//			sscanf(m_freq,"%lf",&data);//MHz
//			freq=long(data*1000000.);//Hz
//			((CMainFrame*)m_pParent)->pt.freq=freq;
//			calculate_byte_from_freq(freq);
//		}

void Cmop::calculate_byte_from_freq(long freq)
{
	//V0.01[050802]
	long DIVIDER;
	//DIVIDER
	DIVIDER=calculate_DIVIDER_from_freq(freq);
	if(DIVIDER!=-1) calculate_byte_from_DIVIDER(DIVIDER);
	else MessageBox("DIVIDER?");
	//band
	calculate_byte_from_freq_band(freq);
	//charge pump
	calculate_byte_from_freq_CP(freq);
	calculate_byte_from_freq_LO_trim(freq);


	/*
	long DIVIDER;
	DIVIDER=calculate_DIVIDER_from_freq(freq);
	if(DIVIDER!=-1) calculate_byte_from_DIVIDER(DIVIDER);
	else MessageBox("DIVIDER?");
	*/

}


long Cmop::calculate_DIVIDER_from_freq(long freq)
{
	((CMainFrame*)m_pParent)->pt.freq=freq;
	long DIVIDER;
	long step;
	long if_freq;
	step=step_from_byte(((CMainFrame*)m_pParent)->pt.byte);
	if_freq=((CMainFrame*)m_pParent)->pt.if_freq;
	DIVIDER=long(double(freq+if_freq)/double(step)+0.5);
	return DIVIDER;
}

void Cmop::calculate_byte_from_DIVIDER(long DIVIDER)
{
	((CMainFrame*)m_pParent)->pt.byte[1]=(DIVIDER>>8)&0x7F;
	((CMainFrame*)m_pParent)->pt.byte[2]=DIVIDER&0xFF;
}


//-----CP
//	void Cmop::calculate_byte_from_dialog_cp()
//	{
//		int chage_pumpu_current;
//		UpdateData(TRUE);
//		sscanf(m_cp,"%d",&chage_pumpu_current);
//		int CP10;
//		CP10=calculate_CP10_from_charge_pump_current(chage_pumpu_current);
//		if(CP10!=-1) calculate_byte_from_CP10(CP10);
//		else MessageBox("CP10?");
//	}

int Cmop::calculate_CP10_from_charge_pump_current(int charge_pump_current)
{
	int i=0;
	int CP10=-1;
	do{
		if(charge_pump_current==CP_from_CP10(i)) {
			CP10=i;
			break;
		}
		i++;
	}while(i<=3);
	return CP10;
}

void Cmop::calculate_byte_from_CP10(int CP10)
{
	int data;
	data=((CMainFrame*)m_pParent)->pt.byte[3];
	data&=0x9F;
	data|=(CP10<<5);
	((CMainFrame*)m_pParent)->pt.byte[3]=data;
}


//-----step
//	void Cmop::calculate_byte_from_dialog_step()
//	{
//		double step;
//		UpdateData(TRUE);
//		sscanf(m_step,"%lf",&step);
//		int R43210;
//		R43210=calculate_R43210_from_step(long(step*1000.)); //Hz
//		if(R43210!=-1) calculate_byte_from_R43210(R43210);
//		else MessageBox("R43210?");
//
//	}

int Cmop::calculate_R43210_from_step(long step)
{
	int R43210=-1;
	int i=0;
	do{
		if(step==step_from_R43210(i)) {
			R43210=i;
			break;
		}
		i++;
	}while(i<=0x3F);

	return R43210;
}

void Cmop::calculate_byte_from_R43210(int R43210)
{
	int data;
	data=((CMainFrame*)m_pParent)->pt.byte[3];
	data&=0xE0;
	data|=R43210;
	((CMainFrame*)m_pParent)->pt.byte[3]=data;
}

//-----band
//void Cmop::calculate_byte_from_dialog_band()
//{
//	UpdateData(TRUE);
//	int BS10P3210;
//	BS10P3210=calculate_BS10P3210_from_band(m_band);
//	if(BS10P3210!=-1) calculate_byte_from_BS10P3210(BS10P3210);
//	else MessageBox("BS10P3210?");
//}

int Cmop::calculate_BS10P3210_from_band(CString band)
{
	int BS10P3210=-1;
	int i=0;
	do{
		if(band==band_from_BS10P3210( (i>>4)&0x03,i&0x0F)) {
			BS10P3210=i;
			break;
		}
		i++;
	}while(i<=0x30);
	return BS10P3210;
}

void Cmop::calculate_byte_from_BS10P3210(int BS10P3210)
{
	int data;
	int BS10,P3210;
	BS10=(BS10P3210>>4)&0x03;
	P3210=BS10P3210&0x0F;
	data=((CMainFrame*)m_pParent)->pt.byte[4];
	data&=0x30;
	data|=(BS10<<6);
	data|=P3210;
	((CMainFrame*)m_pParent)->pt.byte[4]=data;
}

void Cmop::OnKillfocusCOMBOcp() 
{
	calculate_byte_from_dialog();
	set_dialog();
}

void Cmop::OnKillfocusCOMBOfreq() 
{
	//V0.01[050802]
	//freq
	get_dialog_freq();
	calculate_byte_from_freq(((CMainFrame*)m_pParent)->pt.freq);
	set_dialog();

	/*
	calculate_byte_from_dialog();
	set_dialog();
	*/

}

void Cmop::OnKillfocusCOMBOstep() 
{
	calculate_byte_from_dialog();
	set_dialog();
}

void Cmop::OnKillfocusCOMBOband() 
{
	calculate_byte_from_dialog();
	set_dialog();
}

//-----
int Cmop::pll_getdata(int byte1)
{
	return ((CMainFrame*)m_pParent)->pll_getdata(byte1);
}

void Cmop::OnKillfocusCOMBOapplication() 
{
	UpdateData(TRUE);
	re_load_initial_file(m_application);
	((CMainFrame*)m_pParent)->pt.application=m_application;

	//re-calculate byte value
//	calculate_byte_from_dialog();
	set_dialog();
}

void Cmop::re_load_initial_file(CString application)
{
	CString file_name;
	int index;
	index=((CMainFrame*)m_pParent)->index_from_application(application);
	//read inital setting from initial file
	file_name=((CMainFrame*)m_pParent)->pa.Application_File_Name[index];
	((CMainFrame*)m_pParent)->set_parameter_from_config_file(file_name);
	((CMainFrame*)m_pParent)->pa.index=index;
}



void Cmop::calculate_byte_from_freq_step(int pol)
{
	long DIVIDER;
	long freq,step;
	step=((CMainFrame*)m_pParent)->pt.freq_step;
	freq=((CMainFrame*)m_pParent)->pt.freq+step*pol;
	((CMainFrame*)m_pParent)->pt.freq=freq;
	DIVIDER=calculate_DIVIDER_from_freq(freq);
	if(DIVIDER!=-1) calculate_byte_from_DIVIDER(DIVIDER);
	else MessageBox("DIVIDER?");
}

void Cmop::get_dialog()
{
	get_dialog_freq();
	double data;
	int charge_pump_current;
	long pll_step;
	CString band;
	CString application;
	UpdateData(TRUE);
	//CP
	sscanf(m_cp,"%d",&charge_pump_current);
	//PLL STEP
	sscanf(m_step,"%lf",&data);
	pll_step=long(data*1000.);
	//BAND
	band=m_band;
	//APPLICATION
	application=m_application;
	//
	((CMainFrame*)m_pParent)->pt.charge_pump_current=charge_pump_current;
	((CMainFrame*)m_pParent)->pt.pll_step=pll_step;
	((CMainFrame*)m_pParent)->pt.band=band;
	((CMainFrame*)m_pParent)->pt.application=application;

	//V0.02[050804]
	int agc_threshold;
	sscanf(m_agc_threshold,"%d",&agc_threshold);
	((CMainFrame*)m_pParent)->pt.agc_threshold=agc_threshold;

}


void Cmop::get_dialog_freq()
{
	double data;
	long freq;
	long freq_step;
	UpdateData(TRUE);
	//freq
	sscanf(m_freq,"%lf",&data);			//MHz
	freq=long(data*1000000.);			//Hz
	((CMainFrame*)m_pParent)->pt.freq=freq;
	//freq ste;
	sscanf(m_freq_step,"%lf",&data);	//MHz
	freq_step=long(data*1000000.);		//Hz
	((CMainFrame*)m_pParent)->pt.freq_step=freq_step;
}

void Cmop::OnSetfocusbyteS() 
{
//	CEdit* pE=(CEdit*)GetDlgItem(IDC_byteS);
//	pE->SetMargins(5,5);
//	CButton* pB=(CButton*)GetDlgItem(IDC_BUTTON_read);
//	pB->SetProperty(1,1);
	
}


CString Cmop::band_from_freq(long freq)
{
	//V0.03[050831] Japan
	//set band with center frequency(analog offset)
	CString band;

	long if_freq;
	if_freq=((CMainFrame*)m_pParent)->pt.if_freq;
	long freq_vco;
	freq_vco=freq+if_freq;
	long if_freq_center;
	if_freq_center=57000000; //IF(57MHz) [center/digital] 

	//band : freq(173MHz/405MHz) + IF(57MHz) [center] 
	if( freq_vco<(173000000+if_freq_center) )		band=BAND[0];
	else if( freq_vco<(405000000+if_freq_center) ) band=BAND[1];
	else					band=BAND[2];
	return band;

//	CString band;
//	if(freq<162000000)		band=BAND[0];
//	else if(freq<426000000) band=BAND[1];
//	else					band=BAND[2];
//	return band;
}

void Cmop::calculate_byte_from_freq_band(long freq)
{
	int BS10P3210;
	BS10P3210=calculate_BS10P3210_from_band(band_from_freq(freq));
	if(BS10P3210!=-1) calculate_byte_from_BS10P3210(BS10P3210);
	else MessageBox("BS10P3210?");
}

void Cmop::calculate_byte_from_freq_CP(long freq)
{
	int C10=0x00;
	//Low
	if(freq<FREQ_RANGE[0]) {
		C10=CP_from_CP10(0);
	}
	else if(freq<FREQ_RANGE[1]) {
		C10=CP_from_CP10(1);
	}
	//Mid
	else if(freq<FREQ_RANGE[2]) {
		C10=CP_from_CP10(0);
	}
	else if(freq<FREQ_RANGE[3]) {
		C10=CP_from_CP10(1);
	}
	else if(freq<FREQ_RANGE[4]) {
		C10=CP_from_CP10(2);
	}
	else if(freq<FREQ_RANGE[5]) {
		C10=CP_from_CP10(3);
	}
	//High
	else if(freq<FREQ_RANGE[6]) {
		C10=CP_from_CP10(1);
	}
	else if(freq<FREQ_RANGE[7]) {
		C10=CP_from_CP10(2);
	}
	else  {
		C10=CP_from_CP10(3);
	}

	((CMainFrame*)m_pParent)->pt.byte[3]&=0x9F;
	((CMainFrame*)m_pParent)->pt.byte[3]|=(calculate_CP10_from_charge_pump_current(C10)<<5);
}

void Cmop::calculate_byte_from_freq_LO_trim(long freq)
{
	int LO10=0x01;
	if(FREQ_RANGE[6]<=freq) {
		LO10=0x03;
	}
	((CMainFrame*)m_pParent)->pt.byte[5]&=0x3F;
	((CMainFrame*)m_pParent)->pt.byte[5]|=(LO10<<6);
}




//V0.02[050804]

void Cmop::OnKillfocusCOMBOagcthreshold() 
{
	calculate_byte_from_dialog();
	set_dialog();
}

void Cmop::init_dialog_combo_agc_threshold()
{
	CString t;
	int i=0;
	CComboBox* pCB=(CComboBox*)GetDlgItem(IDC_COMBO_agc_threshold);
	do{
		t.Format("%d",AGC_THRESHOLD[i]);
		if(t!="") pCB->AddString(t);
		i++;
	}while(AGC_THRESHOLD[i]>0);
}

void Cmop::set_dialog_agc_threshold()
{
	m_agc_threshold.Format("%d",agc_threshold_from_byte( ((CMainFrame*)m_pParent)->pt.byte ));
	UpdateData(FALSE);
}

int Cmop::agc_threshold_from_byte(int *byte)
{
	int AT210;
	AT210=byte[5]&0x07;
	return  AGC_THRESHOLD[AT210];
}

int Cmop::calculate_AT210_from_agc_threshold(int agc_threshold)
{
	int AT210=-1;
	int i=0;
	do{
		if(agc_threshold==AGC_THRESHOLD[i]) {
			AT210=i;
			break;
		}
		i++;
	}while(AGC_THRESHOLD[i]>0);
	return AT210;
}


void Cmop::calculate_byte_from_AT210(int AT210)
{
	int data;
	data=((CMainFrame*)m_pParent)->pt.byte[5];
	data&=0xF8;
	data|=AT210;
	((CMainFrame*)m_pParent)->pt.byte[5]=data;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -