📄 bluedlg.cpp
字号:
// BLUEDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BLUE.h"
#include "BLUEDlg.h"
#include "testengine.h"
#include "decl-32.h"
#include <time.h>
#include "Ponbox.h"
#pragma comment(lib, "testengine.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBLUEDlg dialog
CBLUEDlg::CBLUEDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBLUEDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBLUEDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CBLUEDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBLUEDlg)
DDX_Control(pDX, IDC_COMBO1, m_micdata);
DDX_Control(pDX, IDC_EDIT_STATUS, m_editstatus);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBLUEDlg, CDialog)
//{{AFX_MSG_MAP(CBLUEDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CONNECTDUT, OnConnectdut)
ON_EN_CHANGE(IDC_EDIT_STATUS, OnChangeEdit1)
ON_BN_CLICKED(IDC_MODIFYPRO, OnModifypro)
ON_BN_CLICKED(IDC_DISPLAYSTATUS, OnDisplaystatus)
ON_CBN_EDITCHANGE(IDC_COMBO1, OnEditchangeCombo1)
ON_BN_CLICKED(IDC_modify_micgain, Onmodifymicgain)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBLUEDlg message handlers
BOOL CBLUEDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
m_DUT = 0;
m_transport=0;
m_micdata.SetCurSel(8);
return TRUE; // return TRUE unless you set the focus to a control
}
void CBLUEDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CBLUEDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CBLUEDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CBLUEDlg::Connectdut()
{
if (m_DUT!=0)
{
closeTestEngine(m_DUT);
m_DUT=0;
}
m_DUT=initTestEngineSpi(1,1,0);
if(m_DUT==0)
{m_out ="连接蓝牙测试设备失败\r\n";}
else
{m_out ="连接蓝牙测试设备成功\r\n";}
m_editstatus.SetWindowText(m_out);
}
const uint16 PSKEY_DEVICE_NAME = 264;
const int PSKEY_CODEC_IN_GAIN = 440;
const uint16 PSKEY_FIXED_PIN = 859;
#define PSKEY_USER16 16
void CBLUEDlg::OnConnectdut()
{
// TODO: Add your control notification handler code here
m_out = "正在连接蓝牙测试设备.......\r\n";
m_out += "请稍后....\r\n";
m_editstatus.SetWindowText(m_out);
m_editstatus.UpdateWindow();
//m_edittime.SetWindowText(m_out);
m_transport = 0;
Connectdut();
}
void CBLUEDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CBLUEDlg::OnModifypro()
{
// TODO: Add your control notification handler code here
m_transport=0;
Connectdut();
if(m_DUT==0)
return;
//change the deviece name
//uint16 name[]={0x424E,0x3348,0x3933,0x53};
uint16 name[]={16974,13128,14643,83};
int result=psWrite(m_DUT,PSKEY_DEVICE_NAME,PS_STORES_DEFAULT,5,name);
if(result==0)
{
m_out+= "蓝牙设备名称修改失败\r\n";
m_editstatus.SetWindowText(m_out);
}
else
{
m_out+= "蓝牙设备名称修改成功\r\n";
m_editstatus.SetWindowText(m_out);
}
//change the connect pin
uint16 pin[]= {56, 56, 56, 56};
result=psWrite(m_DUT,PSKEY_FIXED_PIN,PS_STORES_DEFAULT,4,pin);
if(result==0)
{
m_out+= "蓝牙设备密码修改失败\r\n";
m_editstatus.SetWindowText(m_out);
}
else
{
m_out+= "蓝牙设备密码修改成功\r\n";
m_editstatus.SetWindowText(m_out);
}
//chenge the bd adrress
time_t day = (CTime::GetCurrentTime()).GetDay() ;
time_t month = (CTime::GetCurrentTime()).GetMonth() ;
time_t time = (CTime::GetCurrentTime()).GetTime() ;
unsigned long lap1=time;
unsigned long uap1=day;
unsigned long nap1=month;
result=psWriteBdAddr(m_DUT,lap1,uap1,nap1);
if(result==0)
{
m_out+= "蓝牙设备地址修改失败\r\n";
m_editstatus.SetWindowText(m_out);
}
else
{
m_out+= "蓝牙设备地址修改成功\r\n";
m_editstatus.SetWindowText(m_out);
}
}
void CBLUEDlg::OnDisplaystatus()
{
// TODO: Add your control notification handler code here
m_transport=0;
Connectdut();
if(m_DUT==0)
return;
int i,k,j=0;
char strbuf[64];
uint16 data[16];
uint16 KEYSIZE;
psSize(m_DUT,PSKEY_DEVICE_NAME,PS_STORES_IFR,&KEYSIZE);
//read device name
psRead(m_DUT,PSKEY_DEVICE_NAME,PS_STORES_IFR,16,data,&KEYSIZE);
for( i = 0; i < KEYSIZE; i ++)
{
int tmp1,tmp2;
k = j+1;
tmp1 = (int)(data[i]/256);
tmp2 = (int)(data[i]%256);
strbuf[j] = (char)(tmp2);
strbuf[k] = (char)(tmp1);
j = j+2;
}
strbuf[k+1] = '\0';
m_out += "设备名称: ";
m_out += strbuf;
m_out += "\r\n";
//read fixed pin
for(i=0;i<KEYSIZE;i++)
{strbuf[i]=0;}
uint16 KEYSIZE1;
psRead(m_DUT,PSKEY_FIXED_PIN,PS_STORES_IFR,16,data,&KEYSIZE1);
m_out += "设备连接密码: ";
for(i=0 ; i< KEYSIZE1 ; i++)
{
strbuf[i] = (char)data[i];
}
m_out += strbuf ;
m_out += "\r\n";
//read bt adress
uint32 lap2 = 0;
uint32 uap2 = 0;
uint32 nap2 = 0;
for(i=0;i<KEYSIZE;i++)
{strbuf[i]=0;}
psReadBdAddr(m_DUT, (uint32 *)&lap2, (uint8 *)&uap2, (uint16 *)&nap2);
//read nap2
itoa(nap2 , strbuf , 16);
m_out += "设备蓝牙地址:\r\n";
m_out += "lap:uap:nap -- ";
strbuf[i] ='\0';
m_out += "000";
m_out += strbuf;
//read uap2
for(i=0;i<KEYSIZE;i++)
{strbuf[i]=0;}
itoa(uap2 , strbuf , 16);
strbuf[i] ='\0';
m_out += ':';
if(uap2 < 16)
m_out += "0";
m_out += strbuf;
//read lap2
for(i=0;i<KEYSIZE;i++)
{strbuf[i]=0;}
itoa(lap2 , strbuf , 16) ;
m_out += ':';
m_out += strbuf;
m_out += "\r\n";
//read mic gain
uint16 mic ;
psRead(m_DUT , PSKEY_CODEC_IN_GAIN , PS_STORES_I , 16 , (uint16 *)&mic ,&KEYSIZE );
m_out += "麦克风增益: ";
for(i=0 ; i< KEYSIZE ; i++)
{
strbuf[i] = 0;
}
itoa(mic , strbuf , 10);
m_out += strbuf ;
m_out.MakeUpper();
m_editstatus.SetWindowText(m_out);
closeTestEngine(m_DUT);
}
void CBLUEDlg::OnEditchangeCombo1()
{
// TODO: Add your control notification handler code here
}
extern CString pin1;
//change mic value
void CBLUEDlg::Onmodifymicgain()
{
// TODO: Add your control notification handler code here
m_transport = 0;
Connectdut();
if(m_DUT==0)
return;
CPonbox box;
box.DoModal();
if(pin1 == "000000")
{ uint16 m = m_micdata.GetCurSel();
int result=psWrite(m_DUT , PSKEY_CODEC_IN_GAIN , PS_STORES_I, 1 ,&m);
if(result==0)
{
m_out = "麦克风增益修改失败\r\n";
}
else
{
m_out += "麦克风增益修改为: ";
m_micdata.GetLBText( m , m_out);
m_out += "\r\n";
m_out += "麦克风增益修改成功";
}
}
else
{
m_out += "请输入正确的密码";
}
m_editstatus.SetWindowText(m_out);
closeTestEngine(m_DUT);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -