form_Rtc32k.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:18k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- // form
- #ifndef _FORM_MAIN_H_
- #include "form_main.h"
- #endif
- #ifndef _FORM_RTC32K_H_
- #include "form_Rtc32k.h"
- #endif
- // misc
- #ifndef _MISC_H_
- #include "misc.h"
- #endif
- #ifndef _FILE_UTILS_H_
- #include "file_utils.h"
- #endif
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- #ifndef _BAND_UTILS_H_
- #include "band_utils.h"
- #endif
- #ifndef _MAN_DLL_H_
- #include "man_dll.h"
- #endif
- #ifndef _MAN_FDM_H_
- #include "man_fdm.h"
- #endif
- #ifndef _META_LAB_MSG_H_
- #include "meta_lab_msg.h"
- #endif
- // equipment
- #ifndef _RCT_CTRL_H_
- #include "rct_ctrl.h"
- #endif
- // RF
- #ifndef _RF_STOP_H_
- #include "rf_stop.h"
- #endif
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfrmRTC32k *frmRTC32k;
- //===========================================================================
- __fastcall TfrmRTC32k::TfrmRTC32k(TComponent* Owner)
- : TForm(Owner)
- {
- m_pCfg = NULL;
- m_sRfRtc.p_stLog = NULL;
- m_sRct.cmu.RM = NULL;
- m_sRct.cmu.base = NULL;
- m_sRct.cmu.gsm = NULL;
- m_sRct.cmu.dcs = NULL;
- m_sRct.cmu.pcs = NULL;
- m_sRct.cmu.gsm850 = NULL;
- m_sRct.cmu.s_gsm = NULL;
- m_sRct.cmu.s_dcs = NULL;
- m_sRct.cmu.s_pcs = NULL;
- m_sRct.cmu.s_gsm850 = NULL;
- m_sRct.age.vi = NULL;
- Init();
- }
- //---------------------------------------------------------------------------
- void TfrmRTC32k::Init(void)
- {
- m_bInit = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::FormCreate(TObject *Sender)
- {
- m_cbBand->ItemIndex = 0;
- m_cbTXTsc->ItemIndex = 5;
- m_cbEquipment->ItemIndex = 0;
- WindowProc = SubClassWndProc;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::FormActivate(TObject *Sender)
- {
- if (m_bInit)
- {
- m_bInit = false;
- m_sRfRtc.e_bb_id = frmMainSel->Get_FinalBBChip();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::FormDestroy(TObject *Sender)
- {
- if (NULL != m_sRfRtc.p_stLog)
- {
- delete m_sRfRtc.p_stLog;
- }
- if (NULL != m_pCfg)
- {
- delete m_pCfg;
- }
- }
- //============================================================================
- void _fastcall TfrmRTC32k::SubClassWndProc(Messages::TMessage &Message)
- {
- switch (Message.Msg)
- {
- case WM_ML_RCT_INIT_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment initialization fail";
- AnsiString as_msg = "Execution Fail : Equipment initialization";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RCT_SET_OPERATION_MODE_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment set operation mode fail";
- AnsiString as_msg = "Execution Fail : Equipment set operation mode";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RCT_SET_BAND_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment set band fail";
- AnsiString as_msg = "Execution Fail : Equipment set band";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RCT_SET_DOWNLINK_POWER_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment set downlink power fail";
- AnsiString as_msg = "Execution Fail : Equipment set downlink power";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RCT_SET_TCH_LEVEL_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment set TCH level fail";
- AnsiString as_msg = "Execution Fail : Equipment set TCH level";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RCT_SET_BCH_ARFCN_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment set BCH ARFCN fail";
- AnsiString as_msg = "Execution Fail : Equipment set BCH ARFCN";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RCT_SET_TCH_ARFCN_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment set TCH ARFCN fail";
- AnsiString as_msg = "Execution Fail : Equipment set TCH ARFCN";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RCT_SET_TCH_TIMESLOT_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment set TCH timeslot fail";
- AnsiString as_msg = "Execution Fail : Equipment set TCH timeslot";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RCT_SET_TSC_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment set TSC fail";
- AnsiString as_msg = "Execution Fail : Equipment set TSC";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RCT_SET_MS_TX_LEVEL_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Equipment set MS TX level fail";
- AnsiString as_msg = "Execution Fail : Equipment set MS TX level";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK);
- }
- break;
- case WM_ML_RF_SELECT_BAND_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Select band fail";
- AnsiString as_msg = "Execution Fail : Select band";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK );
- }
- break;
- case WM_ML_RF_AFC_CONTROL_FAIL:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" FB detection fail";
- AnsiString as_msg = "Execution Fail : FB detection";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK );
- }
- break;
- case WM_ML_RTC_PRINT_MSG:
- {
- FillRtc32KResult(false, Message.WParam);
- }
- break;
- case WM_ML_RTC_CLOCK_OUT_OF_RANGE_MSG:
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" RTC clock is out of range";
- AnsiString as_msg = "Execution Fail : RTC clock is out of range, RTC clock = " + Double_To_AnsiString(Message.WParam/100.0) + " Hz";
- Application->MessageBox(as_msg.c_str(), "FAIL", MB_OK );
- }
- break;
- default:
- {
- this->WndProc(Message);
- }
- break;
- }
- }
- //===========================================================================
- void TfrmRTC32k::ShowHintLabel(TControl *sender, char* hint)
- {
- TPoint pt0 = this->ClientOrigin;
- TPoint pt1 = sender->ClientOrigin;
- lblHint->Left = (pt1.x-pt0.x);
- lblHint->Top = (pt1.y-pt0.y)+sender->Height+3;
- lblHint->Caption = hint;
- lblHint->Visible = true;
- HintTimer->Enabled = true;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void TfrmRTC32k::CurrentPageLock(void)
- {
- m_btnStart->Enabled = false;
- m_btnStart->Tag = START_TAG;
- //m_btnNvramDB->Enabled = false;
- m_btnCfgFile->Enabled = false;
- m_btnLogFile->Enabled = false;
- }
- //---------------------------------------------------------------------------
- void TfrmRTC32k::CurrentPageReset(void)
- {
- m_btnStart->Enabled = true;
- m_btnStart->Tag = STOP_TAG;
- //m_btnNvramDB->Enabled = true;
- m_btnCfgFile->Enabled = true;
- m_btnLogFile->Enabled = true;
- }
- //===========================================================================
- void TfrmRTC32k::setup_log_file(AnsiString asFileName)
- {
- m_stLogFile->Caption = asFileName;
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Setup log file name successfully";
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::m_btnLogFileClick(TObject *Sender)
- {
- if (m_dlgSaveLog->Execute())
- {
- setup_log_file(m_dlgSaveLog->FileName);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::on_TerminateSuccess(TObject *Sender)
- {
- CloseRctHandle();
- CurrentPageReset();
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" RTC 32K clock tracking terminated successfully ";
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::on_TerminateFail(TObject *Sender)
- {
- CloseRctHandle();
- StopRf();
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" RTC 32K clock tracking terminated fail ";
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::on_TerminateByUser(TObject *Sender)
- {
- CloseRctHandle();
- StopRf();
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" RTC 32K clock tracking terminated by user ";
- }
- //---------------------------------------------------------------------------
- void TfrmRTC32k::CloseRctHandle(void)
- {
- CRCTCTRL rct_ctrl;
- if (AGILENT_8960 == m_sRct.device_type)
- {
- if (!rct_ctrl.RCT_dcl(&m_sRct))
- {
- return;
- }
- Sleep(50);
- if (!rct_ctrl.RCT_reset(&m_sRct))
- {
- return;
- }
- Sleep(50);
- if (!rct_ctrl.RCT_close(&m_sRct, BandIdx_To_FreqBandString(m_cbBand->ItemIndex)))
- {
- return;
- }
- }
- else // CMU 200
- {
- if (!rct_ctrl.RCT_sig_close(&m_sRct, BandIdx_To_FreqBandString(m_cbBand->ItemIndex)))
- {
- return;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::m_btnStartClick(TObject *Sender)
- {
- if (m_stCfgFile->Caption.AnsiCompareIC("") == 0)
- {
- Application->MessageBox("Please open configuration file.", "Warning", MB_OK);
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Please open configuration file ";
- return;
- }
- if (m_stLogFile->Caption.AnsiCompareIC("") == 0)
- {
- Application->MessageBox("Please setup log file.", "Warning", MB_OK );
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Please setup log file ";
- return;
- }
- if (NULL == m_sRfRtc.p_stLog)
- {
- m_sRfRtc.p_stLog = new TStringList;
- }
- if (NULL == m_sRfRtc.p_stLog)
- {
- Application->MessageBox("Allocate memory for log fail", "FAIL", MB_OK );
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Allocate memory for log fail ";
- return;
- }
- if (!DllMan->LoadAge1960DllFunctions(this->Handle) ||
- !DllMan->LoadVisa32DllFunctions(this->Handle)
- )
- {
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" Load equipment dll fail";
- Application->MessageBox(" Load equipment dll fail", "Fail", MB_OK);
- return;
- }
- CurrentPageLock();
- m_sRfRtc.hPostMsgDestHandle = this->Handle;
- m_sRfRtc.p_cfg = m_pCfg;
- m_sRfRtc.as_LogFile = m_stLogFile->Caption;
- m_sRfRtc.ne_onTermSuccess = on_TerminateSuccess;
- m_sRfRtc.ne_onTermByUser = on_TerminateByUser;
- m_sRfRtc.e_band = (E_BANDSEL)m_cbBand->ItemIndex;
- m_sRfRtc.s_arfcn = m_edtArfcn->Text.ToInt();
- m_sRfRtc.c_tsc = (char)m_cbTXTsc->ItemIndex;
- m_sRfRtc.s_pcl = m_edtPcl->Text.ToInt();
- m_sRfRtc.d_P_DL = atof(m_edtDnPower->Text.c_str());
- m_sRfRtc.ui_test_count = m_edtTestCount->Text.ToInt();
- m_sRfRtc.ui_period = m_edtPeriod->Text.ToInt();
- m_sRct.device_type = (E_DEVICE_TYPE)m_cbEquipment->ItemIndex;
- switch (m_cbBand->ItemIndex)
- {
- case BANDSEL_GSM900:
- {
- m_sRfRtc.as_FreqBand = "0x04";
- }
- break;
- case BANDSEL_DCS1800:
- {
- m_sRfRtc.as_FreqBand = "0x08";
- }
- break;
- case BANDSEL_PCS1900:
- {
- m_sRfRtc.as_FreqBand = "0x10";
- }
- break;
- case BANDSEL_GSM850:
- {
- m_sRfRtc.as_FreqBand = "0x02";
- }
- break;
- }
- CRCTCTRL rct_ctrl_obj;
- m_sRct.as_RCT = rct_ctrl_obj.RCT_DeviceTypeToString((E_DEVICE_TYPE) m_sRct.device_type);
- m_pt_Rtc32K = new CRFRTC(true, &m_sRfRtc, &m_sRct);
- m_pt_Rtc32K->FreeOnTerminate = true;
- m_pt_Rtc32K->OnTerminate = on_TerminateFail;
- m_pt_Rtc32K->Resume();
- FillRtc32KResult(true, 0);
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" RTC 32K clock tracking progressing ... ";
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::m_btnStopClick(TObject *Sender)
- {
- m_pt_Rtc32K->Terminate();
- StopRf();
- m_sbRtc32K->Panels->Items[0]->Text = (AnsiString)" RTC 32K clock tracking terminated by user ";
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void __fastcall TfrmRTC32k::edtTestCountCheck(TObject *Sender)
- {
- unsigned int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = "value shall be 1~4294967295 ";
- text = edit->Text;
- if (!IsValidMeasurementCount(text, data))
- {
- ShowHintLabel(edit, hint);
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::edtPeriodCheck(TObject *Sender)
- {
- unsigned int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = "value shall be 1000~4294967295 ";
- text = edit->Text;
- if (!IsValidPeriod(text, data))
- {
- ShowHintLabel(edit, hint);
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::HintTimerTimer(TObject *Sender)
- {
- HintTimer->Enabled = false;
- lblHint->Visible = false;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void __fastcall TfrmRTC32k::m_btnCfgFileClick(TObject *Sender)
- {
- if (m_dlgOpenCfg->Execute())
- {
- read_cfg_file(m_dlgOpenCfg->FileName);
- }
- }
- //---------------------------------------------------------------------------
- bool TfrmRTC32k::read_cfg_file(AnsiString asFileName)
- {
- if (NULL == m_pCfg)
- {
- m_pCfg = new TMETA_factory_cfg();
- }
- if (!m_pCfg->ReadFromIniFile(asFileName))
- {
- return false;
- }
- m_stCfgFile->Caption = asFileName;
- return true;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void TfrmRTC32k::StopRf(void)
- {
- CRFSTOP rf_stop_obj;
- rf_stop_obj.REQ_Start();
- CurrentPageReset();
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void TfrmRTC32k::FillRtc32KResult(bool b_title, int clock_mHz)
- {
- char str[512];
- if (b_title)
- {
- m_reResult->Lines->Clear();
- sprintf(str, " RTC clock (Hz) RTC clock/32768 ");
- m_reResult->Lines->Add(str);
- sprintf(str, "=====================================");
- m_reResult->Lines->Add(str);
- }
- else
- {
- double d_clock_Hz = clock_mHz/100.0;
- sprintf(str, " %.2f %.6f", d_clock_Hz, d_clock_Hz/32768.0);
- m_reResult->Lines->Add(str);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::m_cbBandChange(TObject *Sender)
- {
- short sdata;
- if (!frmMainSel->cbGSM850->Checked)
- {
- if (BANDSEL_GSM850 == (E_BANDSEL) m_cbBand->ItemIndex)
- {
- m_cbBand->ItemIndex = 0;
- Application->MessageBox("Please check GSM 850 on main menu", "FAILURE", MB_OK);
- }
- }
- E_BANDSEL CurBand = (E_BANDSEL) m_cbBand->ItemIndex;
- m_edtArfcnCheck(m_edtArfcn);
- if (!IsValidARFCN(m_edtArfcn->Text, CurBand, sdata))
- {
- m_edtArfcn->Text = IntToStr(Default_ARFCN[CurBand]);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::m_edtArfcnCheck(TObject *Sender)
- {
- short sdata;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[][256] =
- {
- " value shall be 0~124 or 975~1023 ",
- " value shall be 512~885 ",
- " value shall be 512~810 ",
- " value shall be 128~251 ",
- };
- E_BANDSEL CurBand = (E_BANDSEL) m_cbBand->ItemIndex;
- text = edit->Text;
- if (!IsValidARFCN(text, CurBand, sdata))
- {
- edit->Text = IntToStr(Default_ARFCN[CurBand]);
- ShowHintLabel(edit, hint[CurBand]);
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::m_edtPclCheck(TObject *Sender)
- {
- int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[][256] =
- {
- " value shall be 5~19 ",
- " value shall be 0~15 ",
- " value shall be 0~15 ",
- " value shall be 5~19 ",
- };
- text = edit->Text;
- if (text.AnsiCompare("") == 0)
- {
- return;
- }
- int CurBand = m_cbBand->ItemIndex;
- if (!IsValidPCL(text, CurBand, data))
- {
- ShowHintLabel(edit, hint[CurBand]);
- edit->Text = IntToStr(Default_PCL);
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmRTC32k::m_edtDnPowerCheck(TObject *Sender)
- {
- double data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = " downlink power is not valid ";
- text = edit->Text;
- if (!IsValidPower(text, data))
- {
- ShowHintLabel(edit, hint);
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------