📄 gyroscope_sdlg.cpp
字号:
// Gyroscope_sDlg.cpp : implementation file
//
#include "math.h"
#include "stdafx.h"
#include "Gyroscope_s.h"
#include "Gyroscope_sDlg.h"
#include "math.h"
#define N 32
#define L 4
#define M 40
#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()
/////////////////////////////////////////////////////////////////////////////
// CGyroscope_sDlg dialog
CGyroscope_sDlg::CGyroscope_sDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGyroscope_sDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGyroscope_sDlg)
m_expState = _T("");
m_xGyro = _T("");
m_yGyro = _T("");
m_zGyro = _T("");
m_xJiaG = _T("");
m_yJiaG = _T("");
m_zJiaG = _T("");
m_xTemp = _T("");
m_yTemp = _T("");
m_zTemp = _T("");
m_time = _T("");
m_xDenoiseSignal = _T("");
m_xSourceSignal = _T("");
m_yDenoiseSignal = _T("");
m_ySourceSignal = _T("");
m_zDenoiseSignal = _T("");
m_zSourceSignal = _T("");
m_channelNumber = -1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_num=0;
bt=0;
m_str="";
n=0;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CGyroscope_sDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGyroscope_sDlg)
DDX_Text(pDX, IDC_EXP_STATE, m_expState);
DDX_Control(pDX, IDC_MSCOMM1, m_Comm);
DDX_Text(pDX, IDC_GYRO_X, m_xGyro);
DDX_Text(pDX, IDC_GYRO_Y, m_yGyro);
DDX_Text(pDX, IDC_GYRO_Z, m_zGyro);
DDX_Text(pDX, IDC_JIAG_X, m_xJiaG);
DDX_Text(pDX, IDC_JIAG_Y, m_yJiaG);
DDX_Text(pDX, IDC_JIAG_Z, m_zJiaG);
DDX_Text(pDX, IDC_TEMP_X, m_xTemp);
DDX_Text(pDX, IDC_TEMP_Y, m_yTemp);
DDX_Text(pDX, IDC_TEMP_Z, m_zTemp);
DDX_Text(pDX, IDC_TIME, m_time);
DDX_Text(pDX, IDC_X_DENOISE_SIGNAL, m_xDenoiseSignal);
DDX_Text(pDX, IDC_X_SOURCE_SIGNAL, m_xSourceSignal);
DDX_Text(pDX, IDC_Y_DENOISE_SIGNAL, m_yDenoiseSignal);
DDX_Text(pDX, IDC_Y_SOURCE_SIGNAL, m_ySourceSignal);
DDX_Text(pDX, IDC_Z_DENOISE_SIGNAL, m_zDenoiseSignal);
DDX_Text(pDX, IDC_Z_SOURCE_SIGNAL, m_zSourceSignal);
DDX_Radio(pDX, IDC_RADIO1, m_channelNumber);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGyroscope_sDlg, CDialog)
//{{AFX_MSG_MAP(CGyroscope_sDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGyroscope_sDlg message handlers
BOOL CGyroscope_sDlg::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_channelNumber = 2;
InitComm(); //串口初始化
extern CFile m_file1,m_file2,m_file3,m_file4,m_file5,m_file6;
m_file1.Open("X轴源信号.txt",CFile::modeCreate|CFile::modeWrite);
m_file2.Open("Y轴源信号.txt",CFile::modeCreate|CFile::modeWrite);
m_file3.Open("Z轴源信号.txt",CFile::modeCreate|CFile::modeWrite);
m_file4.Open("X轴降噪信号.txt",CFile::modeCreate|CFile::modeWrite);
m_file5.Open("Y轴降噪信号.txt",CFile::modeCreate|CFile::modeWrite);
m_file6.Open("Z轴降噪信号.txt",CFile::modeCreate|CFile::modeWrite);
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CGyroscope_sDlg::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 CGyroscope_sDlg::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 CGyroscope_sDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CGyroscope_sDlg::InitComm() //串口初始化
{
m_Comm.SetCommPort(2);
m_Comm.SetInputMode(1);
m_Comm.SetSettings("115200,n,8,1");
m_Comm.SetRThreshold(1);
m_Comm.SetInBufferSize(1024);
m_Comm.SetOutBufferSize(1024);
m_Comm.SetInBufferCount(0);
if(!m_Comm.GetPortOpen())
{
m_Comm.SetPortOpen(TRUE);
}
}
BEGIN_EVENTSINK_MAP(CGyroscope_sDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CGyroscope_sDlg)
ON_EVENT(CGyroscope_sDlg, IDC_MSCOMM1, 1 /* OnComm */, OnOnCommMscomm1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CGyroscope_sDlg::OnOnCommMscomm1()
{
// TODO: Add your control notification handler code here
UpdateData();
VARIANT variant_inp;
COleSafeArray safearray_inp;
LONG len=0,k=0;
BYTE rxdata[2048]; //设置BYTE数组 An 8-bit integerthat is not signed.
CString strtemp,str,strRec,strTime;
CString strFile1,strFile2,strFile3,strFile4,strFile5,strFile6; //用于文件操作
float fxGyro,fyGyro,fzGyro; //当接收完32个值后,用于存放新进来的值
float op2,op3;
CString strT_xGyro,strT_yGyro,strT_zGyro;
CString m_xBenchmark,m_yBenchmark,m_zBenchmark;
// CString strT;
if(m_Comm.GetCommEvent()==2) //事件值为2表示接收缓冲区内有字符
{ ////////以下你可以根据自己的通信协议加入处理代码
variant_inp=m_Comm.GetInput(); //读缓冲区
safearray_inp=variant_inp;
len=safearray_inp.GetOneDimSize();
for(k=0;k<len;k++)
safearray_inp.GetElement(&k,rxdata+k);//转换为BYTE型数组
for(k=0;k<len;k++) //将数组转换为Cstring型变量
{
BYTE bt=*(char*)(rxdata+k); //字符型
strtemp.Format("%c",bt); //将字符送入临时变量strtemp存放
strRec+=strtemp; //加入接收编辑框对应字符串
}
}
m_str=m_str+strRec; //为防止通信出错,把最终整条指令赋给m_str
if(m_str.GetLength()==73)
{
extern CFile m_file1,m_file2,m_file3,m_file4,m_file5,m_file6;
m_file1.SeekToEnd;
m_file2.SeekToEnd;
m_file3.SeekToEnd;
m_file4.SeekToEnd;
m_file5.SeekToEnd;
m_file6.SeekToEnd;
str=m_str;
m_expState=m_str;
strRec.Empty();
m_str.Empty();
// char ch;
// ch=str.GetAt(0);
switch(m_channelNumber)
{
case 2:if(m_num<32)
{
m_xGyro=str.Mid(1,6);
m_xJiaG=str.Mid(7,6);
m_xTemp=str.Mid(13,6);
m_xBenchmark=str.Mid(19,6);
m_yGyro=str.Mid(25,6);
m_yJiaG=str.Mid(31,6);
m_yTemp=str.Mid(37,6);
m_yBenchmark=str.Mid(43,6);
m_zGyro=str.Mid(49,6);
m_zJiaG=str.Mid(55,6);
m_zTemp=str.Mid(61,6);
m_zBenchmark=str.Mid(67,6);
/////////////////////////////////////////////////////////////////
strFile1=m_xGyro;
strFile2=m_yGyro;
strFile3=m_zGyro;
strFile1+="\r\n";
strFile2+="\r\n";
strFile3+="\r\n";
extern CFile m_file1,m_file2,m_file3;
m_file1.Write(strFile1,strFile1.GetLength());
m_file2.Write(strFile2,strFile2.GetLength());
m_file3.Write(strFile3,strFile3.GetLength());
strFile1.Empty();
strFile2.Empty();
strFile3.Empty();
///////////////////////////////////////////////////////////////////
extern float gyroscope1[32],gyroscope2[32],gyroscope3[32];
gyroscope1[m_num]=atof(m_xGyro);
gyroscope2[m_num]=atof(m_yGyro);
gyroscope3[m_num]=atof(m_zGyro);
m_num++;
UpdateData(FALSE);
}
else
{
extern CFile m_file1,m_file2,m_file3,m_file4,m_file5,m_file6;
m_xGyro=str.Mid(1,6);
m_xJiaG=str.Mid(7,6);
m_xTemp=str.Mid(13,6);
m_xBenchmark=str.Mid(19,6);
m_yGyro=str.Mid(25,6);
m_yJiaG=str.Mid(31,6);
m_yTemp=str.Mid(37,6);
m_yBenchmark=str.Mid(43,6);
m_zGyro=str.Mid(49,6);
m_zJiaG=str.Mid(55,6);
m_zTemp=str.Mid(61,6);
m_zBenchmark=str.Mid(67,6);
///////////////////////////////////////////////////////////////
strFile1=m_xGyro;
strFile2=m_yGyro;
strFile3=m_zGyro;
strFile1+="\r\n";
strFile2+="\r\n";
strFile3+="\r\n";
m_file1.Write(strFile1,strFile1.GetLength());
m_file2.Write(strFile2,strFile2.GetLength());
m_file3.Write(strFile3,strFile3.GetLength());
strFile1.Empty();
strFile2.Empty();
strFile3.Empty();
///////////////////////////////////////////////////////////////
fxGyro=atof(m_xGyro);
fyGyro=atof(m_yGyro);
fzGyro=atof(m_zGyro);
extern float gyroscope1[32],gyroscope2[32],gyroscope3[32];
SYSTEMTIME t1,t2;
GetSystemTime(&t1);
op1=TI_Denoise(gyroscope1);
op2=TI_Denoise(gyroscope2);
op3=TI_Denoise(gyroscope3);
GetSystemTime(&t2);
int ms;
ms=t2.wMilliseconds-t1.wMilliseconds;
strTime.Format("%d",ms);
strT_xGyro.Format("%f",op1);
strT_yGyro.Format("%f",op2);
strT_zGyro.Format("%f",op3);
///////////////////////////////////////////////////////////////
strFile4=strT_xGyro;
strFile5=strT_yGyro;
strFile6=strT_zGyro;
strFile4+="\r\n";
strFile5+="\r\n";
strFile6+="\r\n";
m_file4.Write(strFile4,strFile4.GetLength());
m_file5.Write(strFile5,strFile5.GetLength());
m_file6.Write(strFile6,strFile6.GetLength());
strFile4.Empty();
strFile5.Empty();
strFile6.Empty();
/////////////////////////////////////////////////////////////////
if(n<10)
{
m_xSourceSignal+=m_xGyro;
m_xSourceSignal+="\r\n";
m_xDenoiseSignal+=strT_xGyro;
m_xDenoiseSignal+="\r\n";
m_ySourceSignal+=m_yGyro;
m_ySourceSignal+="\r\n";
m_yDenoiseSignal+=strT_yGyro;
m_yDenoiseSignal+="\r\n";
m_zSourceSignal+=m_zGyro;
m_zSourceSignal+="\r\n";
m_zDenoiseSignal+=strT_zGyro;
m_zDenoiseSignal+="\r\n";
m_time+=strTime;
m_time+="\r\n";
}
else
{
m_xSourceSignal.Empty();
m_xDenoiseSignal.Empty();
m_xSourceSignal+=m_xGyro;
m_xSourceSignal+="\r\n";
m_xDenoiseSignal+=strT_xGyro;
m_xDenoiseSignal+="\r\n";
m_ySourceSignal.Empty();
m_yDenoiseSignal.Empty();
m_ySourceSignal+=m_yGyro;
m_ySourceSignal+="\r\n";
m_yDenoiseSignal+=strT_yGyro;
m_yDenoiseSignal+="\r\n";
m_zSourceSignal.Empty();
m_zDenoiseSignal.Empty();
m_zSourceSignal+=m_zGyro;
m_zSourceSignal+="\r\n";
m_zDenoiseSignal+=strT_zGyro;
m_zDenoiseSignal+="\r\n";
m_time.Empty();
m_time+=strTime;
m_time+="\r\n";
n=0;
}
for(int j=0;j<31;j++)
{ gyroscope1[j]=gyroscope1[j+1];
gyroscope2[j]=gyroscope2[j+1];
gyroscope3[j]=gyroscope3[j+1];
}
gyroscope1[31]=fxGyro;
gyroscope2[31]=fyGyro;
gyroscope3[31]=fzGyro;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -