form_TDMB.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:32k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <stdio.h>
- #pragma hdrstop
- #ifndef _FORM_TDMB_H_
- #include "form_TDMB.h"
- #endif
- // misc
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- //---------------------------------------------------------------------------
- typedef enum
- {
- TDMB_STATUS_BAR_INDEX_STATUS = 0,
- TDMB_STATUS_BAR_INDEX_SENT_AND_TOTAL,
- TDMB_STATUS_BAR_INDEX_PERCENT
- }E_TDMB_STATUS_BAR_INDEX;
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfrmTDMB *frmTDMB;
- //===========================================================================
- static void CNF_TDMB_PowerOn(void)
- {
- frmTDMB->CNF_TDMB_PowerOn();
- }
- //---------------------------------------------------------------------------
- static void CNF_TDMB_SetFreq(void)
- {
- frmTDMB->CNF_TDMB_SetFreq();
- }
- //---------------------------------------------------------------------------
- static void CNF_TDMB_AutoScan(void)
- {
- frmTDMB->CNF_TDMB_AutoScan();
- }
- //---------------------------------------------------------------------------
- static void CNF_TDMB_GetSignal(void)
- {
- frmTDMB->CNF_TDMB_GetSignal();
- }
- //---------------------------------------------------------------------------
- static void CNF_TDMB_SelServiceOnly(void)
- {
- frmTDMB->CNF_TDMB_SelServiceOnly();
- }
- //---------------------------------------------------------------------------
- static void CNF_TDMB_RecordStream(void)
- {
- frmTDMB->CNF_TDMB_RecordStream();
- }
- //---------------------------------------------------------------------------
- static void CNF_TDMB_StopService(void)
- {
- frmTDMB->CNF_TDMB_StopService();
- }
- //===========================================================================
- __fastcall TfrmTDMB::TfrmTDMB(TComponent* Owner)
- : TForm(Owner)
- {
- Init();
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::Init(void)
- {
- m_bInit = true;
- m_bAction = false;
- m_bService = false;
- m_bRecordStream = false;
- m_btnSetChannel->Enabled = true;
- m_btnAutoScan->Enabled = true;
- m_btnSelectService->Enabled = true;
- m_btnStartRS->Enabled = true;
- m_btnStop->Enabled = false;
- Disable_AllTimer();
- m_btnStop->Enabled = false;
- m_tvServices->Items->Clear();
- ReDrawFields(TDMB_DRAW_MASK_SIGNAL);
- }
- //===========================================================================
- void __fastcall TfrmTDMB::FormShow(TObject *Sender)
- {
- Display_Channel((E_TDMB_BAND_T) m_cbBand->ItemIndex);
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmTDMB::FormActivate(TObject *Sender)
- {
- if (m_bInit)
- {
- m_bInit = false;
- m_TDMB_RF_Obj.ConfirmCallback = ::CNF_TDMB_PowerOn;
- m_TDMB_RF_Obj.REQ_Power_On_Start();
- CurrentPageLock();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmTDMB::FormClose(TObject *Sender, TCloseAction &Action)
- {
- Disable_AllTimer();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmTDMB::FormHide(TObject *Sender)
- {
- Disable_AllTimer();
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::Disable_AllTimer(void)
- {
- m_tmSingal->Enabled = false;
- m_tmService->Enabled = false;
- m_tmGetFile->Enabled = false;
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::CNF_TDMB_PowerOn(void)
- {
- E_METAAPP_RESULT_T state = m_TDMB_RF_Obj.Get_ConfirmState();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" TDMB module power on successfully";
- }
- break;
- case METAAPP_FAIL:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" TDMB module power on fail";
- Application->MessageBox("Execution Failure : TDMB module power on", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" TDMB module power on timeout";
- Application->MessageBox("Execution Timeout : TDMB module power on", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" TDMB module power on stop";
- }
- break;
- default:
- {
- }
- break;
- }
- CurrentPageReset();
- }
- //===========================================================================
- void TfrmTDMB::CurrentPageReset(void)
- {
- if (m_bService || m_bRecordStream)
- {
- m_btnStop->Enabled = true;
- }
- else
- {
- m_btnSetChannel->Enabled = true;
- m_btnAutoScan->Enabled = true;
- m_tvServices->Enabled = true;
- m_btnSelectService->Enabled = true;
- m_btnStartRS->Enabled = true;
- }
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::CurrentPageLock(void)
- {
- m_btnSetChannel->Enabled = false;
- m_btnAutoScan->Enabled = false;
- m_tvServices->Enabled = false;
- m_btnSelectService->Enabled = false;
- m_btnStartRS->Enabled = false;
- m_btnStop->Enabled = false;
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::ReDrawFields(E_TDMB_DRAW_MASK mask)
- {
- if (mask & TDMB_DRAW_MASK_CHANNEL)
- {
- Display_Channel((E_TDMB_BAND_T) m_cbBand->ItemIndex);
- }
- if (mask & TDMB_DRAW_MASK_FREQ_SERVICES)
- {
- Display_FreqEnsembleDB();
- }
- if (mask & TDMB_DRAW_MASK_SCAN_SERVICES)
- {
- Display_ScanEnsembleDB();
- }
- if (mask & TDMB_DRAW_MASK_SIGNAL)
- {
- if (m_bService || m_bRecordStream)
- {
- m_stSNR->Caption = IntToStr(m_sSignal.m_u2Snr);
- char str[256];
- sprintf(str, "%.2f", (m_sSignal.m_u2PreBer / 100.0));
- m_stPreBER->Caption = (AnsiString) str;
- AnsiString as = "-";
- as += IntToStr(m_sSignal.m_u2RSSI);
- m_stRSSI->Caption = as;
- }
- else
- {
- m_tmSingal->Enabled = false;
- m_stSNR->Caption = "N/A";
- m_stPreBER->Caption = "N/A";
- m_stRSSI->Caption = "N/A";
- }
- }
- }
- //===========================================================================
- void TfrmTDMB::Display_Channel(E_TDMB_BAND_T band)
- {
- m_cbChannel->Clear();
- switch (band)
- {
- case TDMB_KOREA_BAND_IDX:
- {
- AnsiString as_channel[] =
- {
- "7A (175.280 MHz)",
- "7B (177.008 MHz)",
- "7C (178.736 MHz)",
- "8A (181.280 MHz)",
- "8B (183.008 MHz)",
- "8C (184.736 MHz)",
- "9A (187.280 MHz)",
- "9B (189.008 MHz)",
- "9C (190.736 MHz)",
- "10A (193.280 MHz)",
- "10B (195.008 MHz)",
- "10C (196.736 MHz)",
- "11A (199.280 MHz)",
- "11B (201.008 MHz)",
- "11C (202.736 MHz)",
- "12A (205.280 MHz)",
- "12B (207.008 MHz)",
- "12C (208.736 MHz)",
- "13A (211.280 MHz)",
- "13B (213.008 MHz)",
- "13C (214.736 MHz)",
- };
- for (int i=0; i<TDMB_KOREA_BAND_CHANNEL_NUM; i++)
- {
- m_cbChannel->Items->Add(as_channel[i]);
- }
- }
- break;
- case TDMB_VHF_BAND3_IDX:
- {
- AnsiString as_channel[] =
- {
- "5A (174.928 MHz)",
- "5B (176.640 MHz)",
- "5C (178.352 MHz)",
- "5D (180.064 MHz)",
- "6A (181.936 MHz)",
- "6B (183.648 MHz)",
- "6C (185.360 MHz)",
- "6D (187.072 MHz)",
- "7A (188.928 MHz)",
- "7B (190.640 MHz)",
- "7C (192.352 MHz)",
- "7D (194.064 MHz)",
- "8A (195.936 MHz)",
- "8B (197.648 MHz)",
- "8C (199.360 MHz)",
- "8D (201.072 MHz)",
- "9A (202.928 MHz)",
- "9B (204.640 MHz)",
- "9C (206.352 MHz)",
- "9D (208.064 MHz)",
- "10A (209.936 MHz)",
- "10N (210.096 MHz)",
- "10B (211.648 MHz)",
- "10C (213.360 MHz)",
- "10D (215.072 MHz)",
- "11A (216.928 MHz)",
- "11N (217.088 MHz)",
- "11B (218.640 MHz)",
- "11C (220.352 MHz)",
- "11D (222.064 MHz)",
- "12A (223.936 MHz)",
- "12N (224.096 MHz)",
- "12B (225.648 MHz)",
- "12C (227.360 MHz)",
- "12D (229.072 MHz)",
- "13A (230.784 MHz)",
- "13B (232.496 MHz)",
- "13C (234.208 MHz)",
- "13D (235.776 MHz)",
- "13E (237.488 MHz)",
- "13F (239.200 MHz)"
- };
- for (int i=0; i<TDMB_VHF_BAND3_CHANNEL_NUM; i++)
- {
- m_cbChannel->Items->Add(as_channel[i]);
- }
- }
- break;
- case TDMB_LBAND_IDX:
- {
- AnsiString as_channel[] =
- {
- "LA (1452.960 MHz)",
- "LB (1454.672 MHz)",
- "LC (1456.384 MHz)",
- "LD (1458.096 MHz)",
- "LE (1459.808 MHz)",
- "LF (1461.520 MHz)",
- "LG (1463.232 MHz)",
- "LH (1464.944 MHz)",
- "LI (1466.656 MHz)",
- "LJ (1468.368 MHz)",
- "LK (1470.080 MHz)",
- "LL (1471.792 MHz)",
- "LM (1473.504 MHz)",
- "LN (1475.216 MHz)",
- "LO (1476.928 MHz)",
- "LP (1478.640 MHz)",
- "LQ (1480.352 MHz)",
- "LR (1482.064 MHz)",
- "LS (1483.776 MHz)",
- "LT (1485.488 MHz)",
- "LU (1487.200 MHz)",
- "LV (1488.912 MHz)",
- "LW (1490.624 MHz)"
- };
- for (int i=0; i<TDMB_LBAND_CHANNEL_NUM; i++)
- {
- m_cbChannel->Items->Add(as_channel[i]);
- }
- }
- break;
- case TDMB_CHINA_BAND_IDX:
- {
- AnsiString as_channel[] =
- {
- "(208.720 MHz)",
- "(209.936 MHz)",
- "(210.432 MHz)",
- "(211.648 MHz)",
- "(212.144 MHz)",
- "(213.360 MHz)",
- "(213.856 MHz)",
- "(215.072 MHz)",
- "(216.432 MHz)",
- "(218.144 MHz)",
- "(1458.096 MHz)",
- "(1459.808 MHz)",
- "(1470.080 MHz)",
- };
- for (int i=0; i<TDMB_CHINA_BAND_CHANNEL_NUM; i++)
- {
- m_cbChannel->Items->Add(as_channel[i]);
- }
- }
- break;
- default:
- {
- }
- break;
- }
- m_cbChannel->ItemIndex = 0;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void TfrmTDMB::Display_FreqEnsembleDB(void)
- {
- TTreeNode *p_tnCurrentEnsembleDB;
- TTreeNode *p_tnCurrentLabel;
- TTreeNode *p_tnCurrentServiceDB[TDMB_MAX_SERVICEDB_NUM];
- TTreeNode *p_tnEnsembleListDB;
- TTreeNode *p_tnEnsembleLabel[TDMB_MAX_ENSEMBLEDB_NUM];
- TTreeNode *p_tnServiceDB[TDMB_MAX_SERVICEDB_NUM];
- m_tvServices->Items->Clear();
- // Current Ensemble
- p_tnCurrentEnsembleDB = m_tvServices->Items->Add(NULL , "[Current Ensemble]");
- AnsiString as(m_sFreqEnsemble.m_rCurEnsembleDB.Label);
- char str[20];
- sprintf(str, "%.3f", m_sFreqEnsemble.m_rCurEnsembleDB.Frequency / 1000.0);
- AnsiString as_str(str);
- as += " CH = " + as_str + " MHz";
- p_tnCurrentLabel = m_tvServices->Items->AddChild(p_tnCurrentEnsembleDB, as);
- for (int i=0; i<m_sFreqEnsemble.m_rCurEnsembleDB.m_ucServiceDBNum; i++)
- {
- p_tnCurrentServiceDB[i] = m_tvServices->Items->AddChild(p_tnCurrentLabel, m_sFreqEnsemble.m_rCurEnsembleDB.m_rServiceDB[i].Label);
- for (int ch=0; ch<m_sFreqEnsemble.m_rCurEnsembleDB.m_rServiceDB[i].m_ucChannelDBNum; ch++)
- {
- sprintf(str, "0x%X", m_sFreqEnsemble.m_rCurEnsembleDB.m_rServiceDB[i].Id);
- as_str = str;
- as = "[DMB][Service ID:" + as_str +
- "][Channel ID:" + IntToStr(m_sFreqEnsemble.m_rCurEnsembleDB.m_rServiceDB[i].m_rChannelDB[ch].Id) +
- "][PL:" + IntToStr(m_sFreqEnsemble.m_rCurEnsembleDB.m_rServiceDB[i].m_rChannelDB[ch].PL) +
- "][" + IntToStr(m_sFreqEnsemble.m_rCurEnsembleDB.m_rServiceDB[i].m_rChannelDB[ch].BitRate) +
- "Kbps]";
- m_tvServices->Items->AddChild(p_tnCurrentServiceDB[i], as);
- }
- }
- // Ensemble List
- p_tnEnsembleListDB = m_tvServices->Items->Add(NULL , "[Ensemble List]");
- for (int en=0; en<m_sFreqEnsemble.m_ucEnsembleNum; en++)
- {
- as = m_sFreqEnsemble.m_rEnsembleDB[en].Label;
- sprintf(str, "%.3f", m_sFreqEnsemble.m_rEnsembleDB[en].Frequency / 1000.0);
- as_str = str;
- as += " CH = " + as_str + " MHz";
- p_tnEnsembleLabel[en] = m_tvServices->Items->AddChild(p_tnEnsembleListDB, as);
- for (int sv=0; sv<m_sFreqEnsemble.m_rEnsembleDB[en].m_ucServiceDBNum; sv++)
- {
- p_tnServiceDB[sv] = m_tvServices->Items->AddChild(p_tnEnsembleLabel[en], m_sFreqEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].Label);
- for (int ch=0; ch<m_sFreqEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].m_ucChannelDBNum; ch++)
- {
- sprintf(str, "0x%X", m_sFreqEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].Id);
- as_str = str;
- as = "[DMB][Service ID:" + as_str +
- "][Channel ID:" + IntToStr(m_sFreqEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].m_rChannelDB[ch].Id) +
- "][PL:" + IntToStr(m_sFreqEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].m_rChannelDB[ch].PL) +
- "][" + IntToStr(m_sFreqEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].m_rChannelDB[ch].BitRate) +
- "Kbps]";
- m_tvServices->Items->AddChild(p_tnServiceDB[sv], as);
- }
- }
- }
- }
- //--------------------------------------------------------------------------
- void TfrmTDMB::Display_ScanEnsembleDB(void)
- {
- TTreeNode *p_tnEnsembleListDB;
- TTreeNode *p_tnEnsembleLabel[TDMB_MAX_ENSEMBLEDB_NUM];
- TTreeNode *p_tnServiceDB[TDMB_MAX_SERVICEDB_NUM];
- m_tvServices->Items->Clear();
- // Ensemble List
- p_tnEnsembleListDB = m_tvServices->Items->Add(NULL , "[Ensemble List]");
- for (int en=0; en<m_sScanEnsemble.m_ucEnsembleNum; en++)
- {
- AnsiString as = m_sScanEnsemble.m_rEnsembleDB[en].Label;
- char str[20];
- sprintf(str, "%.3f", m_sScanEnsemble.m_rEnsembleDB[en].Frequency / 1000.0);
- AnsiString as_str(str);
- as += " CH = " + as_str + " MHz";
- p_tnEnsembleLabel[en] = m_tvServices->Items->AddChild(p_tnEnsembleListDB, as);
- for (int sv=0; sv<m_sScanEnsemble.m_rEnsembleDB[en].m_ucServiceDBNum; sv++)
- {
- p_tnServiceDB[sv] = m_tvServices->Items->AddChild(p_tnEnsembleLabel[en], m_sScanEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].Label);
- for (int ch=0; ch<m_sScanEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].m_ucChannelDBNum; ch++)
- {
- sprintf(str, "0x%X", m_sScanEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].Id);
- as_str = str;
- as = "[DMB][Service ID:" + as_str +
- "][Channel ID:" + IntToStr(m_sScanEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].m_rChannelDB[ch].Id) +
- "][PL:" + IntToStr(m_sScanEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].m_rChannelDB[ch].PL) +
- "][" + IntToStr(m_sScanEnsemble.m_rEnsembleDB[en].m_rServiceDB[sv].m_rChannelDB[ch].BitRate) +
- "Kbps]";
- m_tvServices->Items->AddChild(p_tnServiceDB[sv], as);
- }
- }
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void __fastcall TfrmTDMB::m_cbBandChange(TObject *Sender)
- {
- Display_Channel((E_TDMB_BAND_T) m_cbBand->ItemIndex);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void __fastcall TfrmTDMB::m_btnSetChannelClick(TObject *Sender)
- {
- m_bAction = true;
- unsigned int freq_khz = Get_TDMBFreqKHz();
- m_TDMB_RF_Obj.ConfirmCallback = ::CNF_TDMB_SetFreq;
- m_TDMB_RF_Obj.REQ_Set_Freq_Start((E_TDMB_BAND_T) m_cbBand->ItemIndex, freq_khz);
- CurrentPageLock();
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::CNF_TDMB_SetFreq(void)
- {
- E_METAAPP_RESULT_T state = m_TDMB_RF_Obj.Get_ConfirmState();
- m_bAction = false;
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- TDMB_SET_FREQ_CNF_T* p_ensemble = m_TDMB_RF_Obj.Get_FreqEnsembleResult();
- m_sFreqEnsemble = *p_ensemble;
- ReDrawFields(TDMB_DRAW_MASK_FREQ_SERVICES);
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Set frequency successfully";
- //m_tmSingal->Enabled = true;
- }
- break;
- case METAAPP_FAIL:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Set frequency fail";
- Application->MessageBox("Execution Failure : Set frequency", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Set frequency timeout";
- Application->MessageBox("Execution Timeout : Set frequency", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Set frequency stop";
- }
- break;
- default:
- {
- }
- break;
- }
- CurrentPageReset();
- }
- //---------------------------------------------------------------------------
- unsigned int TfrmTDMB::Get_TDMBFreqKHz(void)
- {
- unsigned int freq_khz;
- AnsiString as = m_cbChannel->Text;
- int pos1 = as.Pos("(");
- int pos2 = as.Pos("M");
- AnsiString as_freq_khz = as.SubString(pos1 + 1, pos2-pos1-2);
- freq_khz = atof(as_freq_khz.c_str()) * 1000;
- return freq_khz;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void __fastcall TfrmTDMB::m_btnAutoScanClick(TObject *Sender)
- {
- m_bAction = true;
- m_TDMB_RF_Obj.ConfirmCallback = ::CNF_TDMB_AutoScan;
- m_TDMB_RF_Obj.REQ_AutoScan_Start((E_TDMB_BAND_T) m_cbBand->ItemIndex);
- CurrentPageLock();
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::CNF_TDMB_AutoScan(void)
- {
- E_METAAPP_RESULT_T state = m_TDMB_RF_Obj.Get_ConfirmState();
- m_bAction = false;
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- TDMB_GET_ENSM_INFO_BY_AUTO_SCAN_CNF_T* p_ensemble = m_TDMB_RF_Obj.Get_ScanEnsembleResult();
- m_sScanEnsemble = *p_ensemble;
- ReDrawFields(TDMB_DRAW_MASK_SCAN_SERVICES);
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Auto scan successfully";
- //m_tmSingal->Enabled = true;
- }
- break;
- case METAAPP_FAIL:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Auto scan fail";
- Application->MessageBox("Execution Failure : Auto scan", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Auto scan timeout";
- Application->MessageBox("Execution Timeout : Auto scan", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Auto scan stop";
- }
- break;
- default:
- {
- }
- break;
- }
- CurrentPageReset();
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void __fastcall TfrmTDMB::m_tmSingalTimer(TObject *Sender)
- {
- if (!m_bAction)
- {
- m_bAction = true;
- if (!m_TDMB_RF_Obj.REQ_Get_Signal_Start())
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Get signal fail";
- Application->MessageBox("Execution Failure : Get signal", "FAILURE", MB_OK );
- m_tmSingal->Enabled = false;
- }
- m_bAction = false;
- TDMB_GET_SIGNAL_CNF_T* p_signal = m_TDMB_RF_Obj.Get_Signal();
- m_sSignal = *p_signal;
- ReDrawFields(TDMB_DRAW_MASK_SIGNAL);
- }
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::CNF_TDMB_GetSignal(void)
- {
- m_bAction = false;
- E_METAAPP_RESULT_T state = m_TDMB_RF_Obj.Get_ConfirmState();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- TDMB_GET_SIGNAL_CNF_T* p_signal = m_TDMB_RF_Obj.Get_Signal();
- m_sSignal = *p_signal;
- ReDrawFields(TDMB_DRAW_MASK_SIGNAL);
- }
- break;
- case METAAPP_FAIL:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Get signal fail";
- Application->MessageBox("Execution Failure : Get signal", "FAILURE", MB_OK );
- m_tmSingal->Enabled = false;
- }
- break;
- case METAAPP_TIMEOUT:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Get signal timeout";
- Application->MessageBox("Execution Timeout : Get signal", "TIMEOUT", MB_OK );
- m_tmSingal->Enabled = false;
- }
- break;
- case METAAPP_STOP:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Get signal stop";
- m_tmSingal->Enabled = false;
- }
- break;
- default:
- {
- }
- break;
- }
- //CurrentPageReset();
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- bool TfrmTDMB::Get_ServiceID(unsigned int &ch_kHz, unsigned int &ui_ServiceId, unsigned int &ui_SubChnId)
- {
- AnsiString as_sel;
- TTreeNode *p_tnSel;
- for (int i=0; i<m_tvServices->Items->Count; i++)
- {
- p_tnSel = m_tvServices->Items->Item[i];
- if (p_tnSel->Selected)
- {
- as_sel = p_tnSel->Text;
- break;
- }
- }
- int pos_sv_begin = as_sel.AnsiPos("Service ID:");
- int pos_chid_begin = as_sel.AnsiPos("Channel ID:");
- if ((!pos_sv_begin) || (!pos_chid_begin))
- {
- return false;
- }
- while (p_tnSel != NULL)
- {
- p_tnSel = p_tnSel->GetPrev();
- if (NULL == p_tnSel)
- {
- return false;
- }
- // channel
- int pos_ch_begin = p_tnSel->Text.AnsiPos("CH = ");
- int pos_ch_end = p_tnSel->Text.AnsiPos("MHz");
- if ((pos_ch_begin != 0) && (pos_ch_end != 0))
- {
- AnsiString as_ch = p_tnSel->Text.SubString(pos_ch_begin+5, pos_ch_end-pos_ch_begin-6);
- ch_kHz = atof(as_ch.c_str()) * 1000;
- break;
- }
- }
- // service ID
- pos_sv_begin += strlen("Service ID:");
- as_sel = as_sel.SubString(pos_sv_begin, as_sel.Length()-pos_sv_begin);
- int pos_sv_end = as_sel.AnsiPos("]");
- ui_ServiceId = as_sel.SubString(1, pos_sv_end -1).ToInt();
- // channel ID
- pos_chid_begin = pos_sv_end + strlen("Channel ID:") + 2;
- as_sel = as_sel.SubString(pos_chid_begin, as_sel.Length() - pos_chid_begin);
- int pos_ch_end = as_sel.AnsiPos("]");
- ui_SubChnId = as_sel.SubString(1, pos_ch_end -1).ToInt();
- return true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmTDMB::m_btnSelectServiceClick(TObject *Sender)
- {
- S_TDMB_SEL_SERV_ONLY_T serv_only;
- if (!Get_ServiceID(serv_only.ui_freq_khz, serv_only.req.m_u4ServiceId, serv_only.req.m_u4SubChnId))
- {
- return;
- }
- m_bAction = true;
- m_tmSingal->Enabled = false;
- m_TDMB_RF_Obj.ConfirmCallback = ::CNF_TDMB_SelServiceOnly;
- m_TDMB_RF_Obj.REQ_Select_Service_Only_Start(serv_only);
- CurrentPageLock();
- }
- //--------------------------------------------------------------------
- void TfrmTDMB::CNF_TDMB_SelServiceOnly(void)
- {
- m_bAction = false;
- E_METAAPP_RESULT_T state = m_TDMB_RF_Obj.Get_ConfirmState();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- m_tmSingal->Enabled = true;
- m_bService = true;
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Select service successfully";
- }
- break;
- case METAAPP_TDMB_DISK_FULL:
- {
- }
- break;
- case METAAPP_FAIL:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Select service fail";
- Application->MessageBox("Execution Failure : Select service", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Select service timeout";
- Application->MessageBox("Execution Timeout : Select service", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Select service stop";
- }
- break;
- default:
- {
- }
- break;
- }
- CurrentPageReset();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmTDMB::m_btnStartRSClick(TObject *Sender)
- {
- S_TDMB_SEL_SERV_T serv;
- if (!Get_ServiceID(serv.ui_freq_khz, serv.req.m_u4ServiceId, serv.req.m_u4SubChnId))
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString) " Invalid item click! Please select sub channel.";
- Application->MessageBox("Invalid item click! Please select sub channel.", "Warning", MB_OK);
- return;
- }
- if (!m_dlgService->Execute())
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString) " Save stream to file fail";
- Application->MessageBox("Execution Failure : Save stream to file", "FAILURE", MB_OK);
- return;
- }
-
- m_bAction = true;
- m_tmSingal->Enabled = false;
- serv.req.m_pcfilepath = m_dlgService->FileName.c_str();
- m_TDMB_RF_Obj.ConfirmCallback = ::CNF_TDMB_RecordStream;
- m_TDMB_RF_Obj.REQ_RecordStream_Start(serv);
- CurrentPageLock();
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::CNF_TDMB_RecordStream(void)
- {
- m_bAction = false;
- E_METAAPP_RESULT_T state = m_TDMB_RF_Obj.Get_ConfirmState();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Record stream progressing";
- m_tmSingal->Enabled = true;
- m_tmService->Enabled = true;
- m_bRecordStream = true;
- m_btnStop->Enabled = true;
- }
- break;
- case METAAPP_TDMB_DISK_FULL:
- {
- }
- break;
- case METAAPP_FAIL:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Record stream fail";
- Application->MessageBox("Execution Failure : Record stream", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Record stream timeout";
- Application->MessageBox("Execution Timeout : Record stream", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Record stream stop";
- }
- break;
- default:
- {
- }
- break;
- }
- CurrentPageReset();
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void __fastcall TfrmTDMB::m_btnStopClick(TObject *Sender)
- {
- m_TDMB_RF_Obj.ConfirmCallback = ::CNF_TDMB_StopService;
- m_TDMB_RF_Obj.REQ_Stop_Service_Start();
- m_tmGetFile->Enabled = true;
- m_bService = false;
- m_bRecordStream = false;
- m_tmSingal->Enabled = false;
- CurrentPageLock();
- m_sbTDMB->Panels->Items[TDMB_STATUS_BAR_INDEX_STATUS]->Text = " read record TS file from FAT progressing ";
- }
- //---------------------------------------------------------------------------
- void TfrmTDMB::CNF_TDMB_StopService(void)
- {
- m_tmService->Enabled = false;
- m_tmGetFile->Enabled = false;
- S_FAT_PROGRESS* p_progress = m_TDMB_RF_Obj.Get_FatProgress();
- m_pbService->Position = p_progress->percent;
- m_sbTDMB->Panels->Items[TDMB_STATUS_BAR_INDEX_SENT_AND_TOTAL]->Text = " " + IntToStr(p_progress->sent_bytes)+ " / " + IntToStr(p_progress->total_bytes)+ " bytes";
- m_sbTDMB->Panels->Items[TDMB_STATUS_BAR_INDEX_PERCENT]->Text = " " + IntToStr(p_progress->percent) + "%";
- CurrentPageReset();
- E_METAAPP_RESULT_T state = m_TDMB_RF_Obj.Get_ConfirmState();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Stop service successfully";
- // m_tmSingal->Enabled = true;
- }
- break;
- case METAAPP_FAIL:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Stop service fail";
- Application->MessageBox("Execution Failure : Stop service", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Stop service timeout";
- Application->MessageBox("Execution Timeout : Stop service", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- m_sbTDMB->Panels->Items[0]->Text = (AnsiString)" Stop service stop";
- }
- break;
- default:
- {
- }
- break;
- }
- }
- void __fastcall TfrmTDMB::m_tmGetFileTimer(TObject *Sender)
- {
- S_FAT_PROGRESS* p_progress = m_TDMB_RF_Obj.Get_FatProgress();
- m_pbService->Position = p_progress->percent;
- m_sbTDMB->Panels->Items[TDMB_STATUS_BAR_INDEX_SENT_AND_TOTAL]->Text = " " + IntToStr(p_progress->sent_bytes)+ " / " + IntToStr(p_progress->total_bytes)+ " bytes";
- m_sbTDMB->Panels->Items[TDMB_STATUS_BAR_INDEX_PERCENT]->Text = " " + IntToStr(p_progress->percent) + "%";
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmTDMB::m_tmServiceTimer(TObject *Sender)
- {
- S_TDMB_SEL_SERV_ERROR_RESULT* p_result = m_TDMB_RF_Obj.Get_SelServiceResult();
- if (p_result->b_valid)
- {
- if (TDMB_FAT_DISK_FULL == p_result->e_result)
- {
- m_tmService->Enabled = false;
- m_bRecordStream = false;
- Application->MessageBox("FAT disk full, read record TS file from FAT", "WARNING", MB_OK);
- m_sbTDMB->Panels->Items[TDMB_STATUS_BAR_INDEX_STATUS]->Text = " read record TS file from FAT progressing ";
- m_TDMB_RF_Obj.ConfirmCallback = ::CNF_TDMB_StopService;
- m_TDMB_RF_Obj.REQ_Stop_Service_Start();
- m_tmGetFile->Enabled = true;
- CurrentPageLock();
- }
- }
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------