?? cspeedview.cpp
字號:
// CSpeedView.cpp : implementation of the CCSpeedView class
//
#include "stdafx.h"
#include "CSpeed.h"
#include "CSpeedSet.h"
#include "CSpeedDoc.h"
#include "CSpeedView.h"
#include "SpeedCollect.h"
#include "RecordCurse.h"
#include "public.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PI 3.1415926
/////////////////////////////////////////////////////////////////////////////
// CCSpeedView
IMPLEMENT_DYNCREATE(CCSpeedView, CRecordView)
BEGIN_MESSAGE_MAP(CCSpeedView, CRecordView)
//{{AFX_MSG_MAP(CCSpeedView)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_TIMER()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_BN_CLICKED(IDC_BUTTON_SAVE_PARAM, OnButtonSaveParam)
ON_BN_CLICKED(IDC_BUTTON_BEGIN, OnButtonBegin)
ON_BN_CLICKED(IDC_WATCH_RECORD, OnWatchRecord)
ON_BN_CLICKED(IDC_CLEAR_ALARM, OnClearAlarm)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//CString GLastFname;
//CONTROLPARAM ControlParam;
/////////////////////////////////////////////////////////////////////////////
// CCSpeedView construction/destruction
int rpm_num=1;
double rpm;
double fr;
CCSpeedView::CCSpeedView()
: CRecordView(CCSpeedView::IDD)
{
//{{AFX_DATA_INIT(CCSpeedView)
m_pSet = NULL;
m_test_no = _T("");
m_alarm_rspeed = 2000.0;
m_set_r = 530.5;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CCSpeedView::~CCSpeedView()
{
}
void CCSpeedView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCSpeedView)
DDX_Text(pDX, IDC_TEST_NO, m_test_no);
DDX_Text(pDX, IDC_EDIT_ALARM_SPEED, m_alarm_rspeed);
DDX_Text(pDX, IDC_EDIT_R, m_set_r);
//}}AFX_DATA_MAP
}
BOOL CCSpeedView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CCSpeedView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_cSpeedSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
CFileFind finder;
if(finder.FindFile(GLastFname))
{
GetDocument()->OnOpenDocument(GLastFname);
GetDocument()->SetPathName(GLastFname);
trantoview();
}
SetTimer(1,5000,NULL);
}
/////////////////////////////////////////////////////////////////////////////
// CCSpeedView diagnostics
#ifdef _DEBUG
void CCSpeedView::AssertValid() const
{
CRecordView::AssertValid();
}
void CCSpeedView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CCSpeedDoc* CCSpeedView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCSpeedDoc)));
return (CCSpeedDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCSpeedView database support
CRecordset* CCSpeedView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CCSpeedView message handlers
int CCSpeedView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CRecordView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
nTime=0;
rpm=0;
sample_first = TRUE;
return 0;
}
CString m_time2;
void CCSpeedView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
char t_ch[3];
int t_h,t_m,t_s;
t_h=int(ControlParam.run_time/3600);
t_m=int((ControlParam.run_time-t_h*3600)/60);
t_s=int(ControlParam.run_time-t_h*3600-t_m*60);
m_time2="";
ftoat1(t_h,3,t_ch);
m_time2+=t_ch;
m_time2+=":";
ftoat1(t_m,2,t_ch);
m_time2+=t_ch;
m_time2+=":";
ftoat1(t_s,2,t_ch);
m_time2+=t_ch;
UpdateData(FALSE);
// Do not call CRecordView::OnPaint() for painting messages
}
void CCSpeedView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRecordView::OnTimer(nIDEvent);
}
void CCSpeedView::OnFileOpen()
{
// TODO: Add your command handler code here
char parfilepath[180];
CString ttt;
ttt.Format("%s\\param",exepath);
strcpy(parfilepath,ttt);
CFileDialog OpenDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT,"*.par|*.par||",NULL);
OpenDlg.m_ofn.lpstrInitialDir=parfilepath;
int retval=OpenDlg.DoModal();
CString filename;
CString filepath;
if(retval==IDOK)
{
filename=OpenDlg.GetFileName();
filepath=OpenDlg.GetPathName();
GLastFname=filepath;
GetDocument()->OnOpenDocument(filepath);
GetDocument()->SetPathName(filename);
trantoview();
}
}
void CCSpeedView::OnFileSave()
{
// TODO: Add your command handler code here
tranparam();
char lpFileName[180];
CString ttt;
ttt.Format("%s\\param\\%s.par",exepath,m_test_no);
strcpy(lpFileName,ttt);
WIN32_FIND_DATA FindFileData ;
HANDLE hFindFile=FindFirstFile(lpFileName,&FindFileData);
if(hFindFile==INVALID_HANDLE_VALUE)//不存在該文件
{
ControlParam.run_time = 0;
UpdateData(FALSE);
}
else
FindClose(hFindFile);
GLastFname = ttt;
GetDocument()->OnSaveDocument(ttt);
GetDocument()->SetPathName(ttt);
}
void CCSpeedView::OnFileSaveAs()
{
// TODO: Add your command handler code here
OnFileSave();
}
void CCSpeedView::OnButtonSaveParam()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_BUTTON_BEGIN)->EnableWindow(FALSE);
UpdateData();
ControlParam.OtherParam.r=m_set_r;
ControlParam.OtherParam.v_max=m_alarm_rspeed;
ControlParam.speed_model=m_test_no;
fr=ControlParam.OtherParam.r;
rpm = 2*PI*(ControlParam.OtherParam.r)/(rpm_num*1000.);
GetDlgItem(IDC_BUTTON_BEGIN)->EnableWindow(TRUE);
}
void CCSpeedView::OnButtonBegin()
{
// TODO: Add your control notification handler code here
int answer=MessageBox("請確保已經設置參數并保存","提示信息",MB_YESNOCANCEL);
if(answer!=IDYES) return;
KillTimer(1);
ControlParam.RunDataArray.start_num = 0;
SpeedCollect mdl;
mdl.DoModal();
IsStartTest=TRUE;
count = -1;
PostMessage(WM_COMMAND,ID_FILE_SAVE,0);
GetRunData(m_test_no);
UpdateData(FALSE);
SetTimer(1,200,NULL);
}
void CCSpeedView::OnWatchRecord()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
RecordCurse mdgl;
mdgl.DoModal();
}
void CCSpeedView::tranparam()
{
UpdateData(TRUE);
ControlParam.speed_model =m_test_no;
ControlParam.RunDataArray.data.RemoveAll();
ControlParam.RunDataArray.start_num = 0;
int len=ControlParam.RunDataArray.data.GetSize();
BOOL PLAY=TRUE;
int mode;
for(int n=0;n<len;n++)
{
mode=ControlParam.RunDataArray.data[n];
if(mode>9)
{
PLAY=FALSE;
break;
}
}
UpdateData(FALSE);
ControlParam.OtherParam.v_max=m_alarm_rspeed;
ControlParam.OtherParam.r=m_set_r;
}
void CCSpeedView::trantoview()
{
m_test_no = ControlParam.speed_model;
//環境參數:
m_alarm_rspeed=ControlParam.OtherParam.v_max;
m_set_r=ControlParam.OtherParam.r;
UpdateData(FALSE);
}
void CCSpeedView::GetRunData(CString filename)
{
CString ttt;
ttt.Format("%s\\data\\%s.ddx", exepath, filename);
CFile xzfile;
int ret;
ret = xzfile.Open(ttt, CFile::modeRead);
if(ret == NULL)
{
ControlParam.run_time = 0;
ret = xzfile.Open(ttt,CFile::modeCreate);
if(ret == NULL)
{
AfxMessageBox("Create File Default.");
return;
}
}
else
{
int file_num = xzfile.GetLength();
if(file_num < 1)
{
}
else
{
SPEEDSAMPLE mysearchcurve;
int mm = sizeof(SPEEDSAMPLE);
xzfile.Seek(-mm,CFile::end);
xzfile.Read((char*)&mysearchcurve,mm);
ControlParam.run_time = mysearchcurve.t;
}
}
xzfile.Close();
}
void CCSpeedView::timerProc()
{
if(IsSetSysParam)
return;
if(sample_first)
sample_first=FALSE;
////////按鈕檢測
int code;
code=0;
int kk;
int nn;
nn = nTime%20;
if(nn == 0)//200毫秒采樣1按鈕,采樣一組數據
{
kk=-1;
int i;
long NowInData= ~InportD(SysParam.basein+0); //6110 0x288
for(i=2;i<8;i++)
{
if((NowInData&(0x01<<(2*i))&&!(SampleParam.InData&(0x01<<(2*i)))))
{
kk=i;
}
}
SampleParam.InData = NowInData;
if(IsStartTest&&kk>=2&&kk<8)
{
// err_Lock.Lock();
SampleParam.InData = kk;
// err_Lock.Unlock();
}
if(kk==ALARMKEY)
{
code=ALARMSTOP;
}
}
if(SampleParam.speed_meas_v>ControlParam.OtherParam.v_max)
{
OutAlarmLampOn(TRUE);
}
if(code!=0)
FaultCode = code;
if(nTime >= 20)
{
nTime = 0;
}
nTime++;
}
void CCSpeedView::OnClearAlarm()
{
// TODO: Add your control notification handler code here
OutAlarmLampOn(FALSE);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -