📄 getversionmfcdlg.cpp
字号:
// getversionMFCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "getversionMFC.h"
#include "getversionMFCDlg.h"
/********************************************************************************/
#include <tchar.h>
#include <stdio.h>
#include <windows.h>
#include "SmsCtrlLib.h"
#include <iostream>
/********************************************************************************/
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CgetversionMFCDlg dialog
/*********************************************************************************/
HANDLE hEventInit;
HANDLE hEventTuneComplete;
HANDLE hEventAddPIDComplete;
HANDLE hEventRemovePIDComplete;
HANDLE hEventGetStatisticsComplete;
SmsHostApiDeviceHandle hDevice;
SMSHOSTLIB_ERR_CODES_E g_lastError;
SMSHOSTLIB_STATISTICS_ST g_statistics;
FILE * g_outFile = NULL;
void DataCallback(void* ClientPtr,
UINT32 ServiceHandle,
UINT8* pBuffer,
UINT32 BufferSize );
void CallbackFunction(
void* ClientContext,
SMSHOSTLIB_MSG_TYPE_RES_E MsgType,
SMSHOSTLIB_ERR_CODES_E ErrCode,
void* pPayload,
UINT32 PayloadLen);
// Macro for checking the return value of an API call
#define VALIDATE_RETVAL(retval,strName) \
if (retval == SMSHOSTLIB_ERR_OK) \
{ \
} \
else \
{ \
return ; \
}
// Macro for checking the return value of an API call
#define VALIDATE_RETVAL_SILENT(retval,strName) \
if (retval == SMSHOSTLIB_ERR_OK) \
{ \
} \
else \
{ \
return ; \
}
// Macro to wait on a callback of an asynchronous function
#define WAIT_CALLBACK(eventName,timeout) \
dwWaitResult = WaitForSingleObject(eventName,timeout); \
if (dwWaitResult != WAIT_OBJECT_0) \
{ \
return ; \
} \
if (g_lastError != SMSHOSTLIB_ERR_OK) \
{ \
return ; \
}
/*********************************************************************************/
CgetversionMFCDlg::CgetversionMFCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CgetversionMFCDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CgetversionMFCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, m_EditFreq);
}
BEGIN_MESSAGE_MAP(CgetversionMFCDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CgetversionMFCDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CgetversionMFCDlg::OnBnClickedButton2)
END_MESSAGE_MAP()
// CgetversionMFCDlg message handlers
BOOL CgetversionMFCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CgetversionMFCDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
DRA::RelayoutDialog(
AfxGetInstanceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_GETVERSIONMFC_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_GETVERSIONMFC_DIALOG));
}
#endif
/*****************************************************************************
*
*
*
******************************************************************************/
void CgetversionMFCDlg::OnBnClickedButton1()
{
#if 0
// TODO: 在此添加控件通知处理程序代码
CString strAppFileName;
CString strAppOutPutFileName;
LPTSTR ptsAppFileName=_T("");
LPPROCESS_INFORMATION lppiProcInfo=NULL;
/************************************************************************************
*
* 执行应用程序
*
*************************************************************************************/
//strAppFileName=ptsAppFileName;
//MessageBox(strAppFileName);
strAppFileName=_T("\\program files\\sianosmsutils\\getversion.exe");
strAppOutPutFileName=_T("\\program files\\sianosmsutils\\getversion_output.txt");
::CreateProcess(strAppFileName,strAppOutPutFileName,NULL,NULL,FALSE,INHERIT_CALLER_PRIORITY,NULL,NULL,NULL,lppiProcInfo);
#endif
}
void CgetversionMFCDlg::GetTvDataTest(int iFreqPoint)
{
SMSHOSTLIB_ERR_CODES_E retval;
bool bDemodulatorLocked;
DWORD dwWaitResult;
// basic setup (OS-dependant)
hEventInit = CreateEvent(NULL,FALSE,FALSE,NULL);
hEventTuneComplete = CreateEvent(NULL,FALSE,FALSE,NULL);
hEventAddPIDComplete = CreateEvent(NULL,FALSE,FALSE,NULL);
hEventRemovePIDComplete = CreateEvent(NULL,FALSE,FALSE,NULL);
hEventGetStatisticsComplete = CreateEvent(NULL,FALSE,FALSE,NULL);
// Init the control library
SMSHOSTLIB_API_INITLIB_PARAMS_ST initparams;
initparams.Size = sizeof(SMSHOSTLIB_API_INITLIB_PARAMS_ST);
initparams.pCtrlCallback = CallbackFunction;
initparams.pDataCallback = DataCallback;
initparams.CommType = SMSHOSTLIB_COMM_SDIO;
initparams.pCommParam = NULL;
// In the following directory we will store data extracted from the streams, it should be
// set to a directory that exists on the disk. Currently it is unused in the DVB-T standard:
initparams.WorkingDirectory =
"c:\\Program Files\\Siano Mobile Silicon Utilities";
initparams.IsSupportMultInstances = TRUE;
retval = SmsHostApiLibInit(&initparams);
VALIDATE_RETVAL(retval,"InitLib");
// Enumerate connected devices and choose the first one
UINT nDevices;
SmsHostApiDeviceData_ST deviceData;
retval = SmsHostApiGetDevicesList(1,&nDevices,&deviceData);
VALIDATE_RETVAL(retval,"GetDevicesList");
// cout << nDevices << " device(s) returned." << endl;
// Init the device
retval = SmsHostApiDeviceInit_Req(deviceData.DeviceName,SMSHOSTLIB_DEVMD_DVBT,12000000,NULL,&hDevice);
VALIDATE_RETVAL(retval,"InitDevice");
WAIT_CALLBACK(hEventInit,10000);
// Tune the SMS to a specific frequency/bandwidth
SMSHOSTLIB_FREQ_BANDWIDTH_ET bandwidth = BW_8_MHZ;
retval = SmsHostApiTune_Req(hDevice,iFreqPoint/* 722000000 */,bandwidth);
VALIDATE_RETVAL(retval,"Tune");
WAIT_CALLBACK(hEventTuneComplete,1000);
// Check if we have found a transmission. For this we will get the
// working statistics from the SMS and check whether the demodulator
// is locked on a transmission. Note that this alone is not enough to
// actually determine whether a transmission is a proper DVB-T transmission,
// for example it might be DVB-H (in which case we will have to check whether
// time-slicing is enabled on the transmission)
bDemodulatorLocked = false;
for (int i = 0; i < 10 && !bDemodulatorLocked; i++)
{
Sleep(50);
retval = SmsHostApiGetStatistics_Req(hDevice);
VALIDATE_RETVAL_SILENT(retval,"GetStatistics");
WAIT_CALLBACK(hEventGetStatisticsComplete,1000);
if (g_statistics.IsDemodLocked == 1)
{
bDemodulatorLocked = true;
}
}
if (!bDemodulatorLocked)
{
//cout << "No transmission found, aborting!" << endl;
return ;//return 1;
}
// After a successful tune, some of the DVB-T data (the parts describing
// the transport stream, such as PSI/SI tables) will automatically start streaming in through
// the callback function. We need to parse the data (not done in this
// sample code) and then add filters on PIDs relevant to us, for example PIDs
// related to a certain program, in order to get the data associated with them.
UINT32 pid = 161;
retval = SmsHostApiAddPidFilter_Req(hDevice,pid);
VALIDATE_RETVAL(retval,"AddPID");
WAIT_CALLBACK(hEventAddPIDComplete,1000);
// Prepare an output file
g_outFile = fopen("dump.ts","wb");
// Sleep for a while and gather data
int nSecondsSleep = 10;
//cout << "Sleeping " << nSecondsSleep << " seconds..." << endl;
Sleep(nSecondsSleep * 1000);
// Remove the filter on the EPG's PID to stop receiving its data
retval = SmsHostApiRemovePidFilter_Req(hDevice,pid);
VALIDATE_RETVAL(retval,"RemovePID");
WAIT_CALLBACK(hEventRemovePIDComplete,1000);
// Clean up
fclose(g_outFile);
g_outFile = NULL;
SmsHostApiLibTerminate();
CloseHandle(hEventTuneComplete);
CloseHandle(hEventInit);
CloseHandle(hEventAddPIDComplete);
CloseHandle(hEventRemovePIDComplete);
CloseHandle(hEventGetStatisticsComplete);
}
void CallbackFunction(
void* ClientContext, //!< Context of client
SMSHOSTLIB_MSG_TYPE_RES_E MsgType, //!< Response type
SMSHOSTLIB_ERR_CODES_E ErrCode, //!< Response success code
void* pPayload, //!< Response payload
UINT32 PayloadLen) //!< Response payload length
{
g_lastError = ErrCode;
switch(MsgType)
{
case SMSHOSTLIB_MSG_INIT_DEVICE_RES:
// Device has completed initialization
SetEvent(hEventInit);
break;
case SMSHOSTLIB_MSG_ADD_PID_FILTER_RES:
SetEvent(hEventAddPIDComplete);
break;
case SMSHOSTLIB_MSG_REMOVE_PID_FILTER_RES:
SetEvent(hEventRemovePIDComplete);
break;
case SMSHOSTLIB_MSG_TUNE_RES:
SetEvent(hEventTuneComplete);
break;
case SMSHOSTLIB_MSG_GET_STATISTICS_RES:
memcpy(&g_statistics,pPayload,sizeof(SMSHOSTLIB_STATISTICS_ST));
SetEvent(hEventGetStatisticsComplete);
break;
}
}
// Callback function for data. This function will be called whenever data
// is received from the device.
void DataCallback(void* ClientPtr,
UINT32 ServiceHandle,
UINT8* pBuffer,
UINT32 BufferSize )
{
if (g_outFile != NULL)
{
fwrite(pBuffer,1,BufferSize,g_outFile);
}
}
void CgetversionMFCDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
CString strFreq;
int ifreq=0;
m_EditFreq.GetWindowTextW(strFreq);
ifreq=::_ttoi(strFreq);
GetTvDataTest(ifreq);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -