// HwProtocol_demoDlg.cpp : implementation file // #include "stdafx.h" #include "HwProtocol_demo.h" #include "HwProtocol_demoDlg.h" #include "HwProtocol_DLL.h" //#include "HikPlayMpeg4.h" #include "plaympeg4.h" #pragma comment(lib,"PlayCtrl.lib") #pragma comment(lib,"HwProtocol.lib") #include #define BUF4M 4*1024*1024 HWND PLAYBACKWIN = NULL; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif using namespace std; void CALLBACK VpsEventCallBack(long hDev, T_VPSEVENT EventInfo); void CALLBACK AlarmCallBack(long hDev,byte AlarmType,long AlarmState); void CALLBACK dPlayBackDataCallBack(long PlayBackId,int VideoType,char * buf,long buflen,long dwUser); void CALLBACK dRealDataCallBack(long RealId,int VideoType,char * buf,long buflen,long dwUser); long SockHandle[10]; long PlayHandle = -1; long RealHandle = -1; T_tPlayFile gbfiledata; ///////////////////////////////////////////////////////////////////////////// // 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() ///////////////////////////////////////////////////////////////////////////// // CHwProtocol_demoDlg dialog CHwProtocol_demoDlg::CHwProtocol_demoDlg(CWnd* pParent /*=NULL*/) : CDialog(CHwProtocol_demoDlg::IDD, pParent) { //{{AFX_DATA_INIT(CHwProtocol_demoDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CHwProtocol_demoDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CHwProtocol_demoDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CHwProtocol_demoDlg, CDialog) //{{AFX_MSG_MAP(CHwProtocol_demoDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_HwPtcLogin, OnHwPtcLogin) ON_BN_CLICKED(IDC_HwPtcLogout, OnHwPtcLogout) ON_BN_CLICKED(IDC_GetVideoPara, OnGetVideoPara) ON_BN_CLICKED(IDC_GetWorkSheet, OnGetWorkSheet) ON_BN_CLICKED(IDC_HwPtcGetAlarmSetting, OnHwPtcGetAlarmSetting) ON_BN_CLICKED(IDC_HwPtcGetDevWorkState, OnHwPtcGetDevWorkState) ON_BN_CLICKED(IDC_HwPtcGetMotionDetect, OnHwPtcGetMotionDetect) ON_BN_CLICKED(IDC_HwPtcGetMaskInfo, OnHwPtcGetMaskInfo) ON_BN_CLICKED(IDC_HwPtcGetDevUserInfo, OnHwPtcGetDevUserInfo) ON_BN_CLICKED(IDC_HwPtcGetVideoColor, OnHwPtcGetVideoColor) ON_BN_CLICKED(IDC_HwPtcGetDecoderPara, OnHwPtcGetDecoderPara) ON_BN_CLICKED(IDC_HDDINFO, OnHddinfo) ON_WM_DESTROY() ON_BN_CLICKED(IDC_Other, OnOther) ON_BN_CLICKED(IDC_POWEROFF, OnPoweroff) ON_BN_CLICKED(IDC_POWER, OnPower) ON_BN_CLICKED(IDC_Version, OnVersion) ON_BN_CLICKED(IDC_PTZDIR, OnPtzdir) ON_BN_CLICKED(IDC_PTZLEN, OnPtzlen) ON_BN_CLICKED(IDC_PTZPERSET, OnPtzperset) ON_BN_CLICKED(IDC_AlarmOut, OnAlarmOut) ON_BN_CLICKED(IDC_AlarmIn, OnAlarmIn) ON_BN_CLICKED(IDC_StartRecord, OnStartRecord) ON_BN_CLICKED(IDC_DecoderAddr, OnDecoderAddr) ON_BN_CLICKED(IDC_VideoLevel, OnVideoLevel) ON_BN_CLICKED(IDC_RemoteUserLogin, OnRemoteUserLogin) ON_BN_CLICKED(IDC_AddPerSet, OnAddPerSet) ON_BN_CLICKED(IDC_DetailRecordType, OnDetailRecordType) ON_BN_CLICKED(IDC_WorkSheet, OnWorkSheet) ON_BN_CLICKED(IDC_Decorder, OnDecorder) ON_BN_CLICKED(IDC_ISVideoLost, OnISVideoLost) ON_BN_CLICKED(IDC_SetVpsEventCallback, OnSetVpsEventCallback) ON_BN_CLICKED(IDC_NormalLog, OnNormalLog) ON_BN_CLICKED(IDC_VpsEventLog, OnVpsEventLog) ON_BN_CLICKED(IDC_CHECKTIME, OnChecktime) ON_BN_CLICKED(IDC_ChkNetState, OnChkNetState) ON_BN_CLICKED(IDC_VPSCENTER, OnVpscenter) ON_BN_CLICKED(IDC_OsType, OnOsType) ON_BN_CLICKED(IDC_SetAlarmCallBack, OnSetAlarmCallBack) ON_BN_CLICKED(IDC_Temp, OnTemp) ON_BN_CLICKED(IDC_NETPARA, OnNetpara) ON_BN_CLICKED(IDC_MakeKeyFrame, OnMakeKeyFrame) ON_BN_CLICKED(IDC_TEST, OnTest) ON_BN_CLICKED(IDC_STOPTEST, OnStoptest) ON_WM_TIMER() ON_BN_CLICKED(IDC_CHECKDVRTIME, OnCheckdvrtime) ON_BN_CLICKED(IDC_GETALARMSTATE, OnGetalarmstate) ON_BN_CLICKED(IDC_AUTOZOOMIN, OnAutozoomin) ON_BN_CLICKED(IDC_GETLOG, OnGetlog) ON_BN_CLICKED(IDC_KeyFrame, OnKeyFrame) ON_BN_CLICKED(IDC_FINDFILE, OnFindfile) ON_BN_CLICKED(IDC_PLAYFILE, OnPlayfile) ON_BN_CLICKED(IDC_PLAYCLOSE, OnPlayclose) ON_BN_CLICKED(IDC_GetPlayPos, OnGetPlayPos) ON_BN_CLICKED(IDC_SetPlayPos, OnSetPlayPos) ON_BN_CLICKED(IDC_PLAYSIZE, OnPlaysize) ON_BN_CLICKED(IDC_FF, OnFf) ON_BN_CLICKED(IDC_SF, OnSf) ON_BN_CLICKED(IDC_SetAlarmOut, OnSetAlarmOut) ON_BN_CLICKED(IDC_RealPlay, OnRealPlay) ON_BN_CLICKED(IDC_RealStop, OnRealStop) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CHwProtocol_demoDlg message handlers BOOL CHwProtocol_demoDlg::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 HwPtcInit(); // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CHwProtocol_demoDlg::OnDestroy() { CDialog::OnDestroy(); HwPtcRelease(); // TODO: Add your message handler code here } void CHwProtocol_demoDlg::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 CHwProtocol_demoDlg::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 CHwProtocol_demoDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CALLBACK AlarmCallBack(long hDev,byte AlarmType,long AlarmState) { TRACE("AlarmType:%d AlarmState:%d",AlarmType,AlarmState); } void CALLBACK VpsEventCallBack(long hDev, T_VPSEVENT EventInfo) { // int i; // TRACE("Device:%d",hDev); // TRACE("Channel:%d",EventInfo.Channel); // TRACE("EventType:%d",EventInfo.EventType); // TRACE("EventNo:%d",EventInfo.EventNo); // TRACE("ObjectID:%d",EventInfo.ObjectID); // TRACE("bytDay:%d",EventInfo.byteDay); // TRACE("SHour:%d",EventInfo.SHour); // TRACE("SMinute:%d",EventInfo.SMinute); // TRACE("SSecond:%d",EventInfo.SSecond); // TRACE("EHour:%d",EventInfo.EHour); // TRACE("EMinute:%d",EventInfo.EMinute); // TRACE("ESecond:%d",EventInfo.ESecond); // TRACE("chrDate:%s",EventInfo.chrDate); // TRACE("StaySeconds:%d",EventInfo.StaySeconds); // TRACE("ObjLeft:%d",EventInfo.ObjLeft); // TRACE("ObjTop:%d",EventInfo.ObjTop); // TRACE("ObjRight:%d",EventInfo.ObjRight); // TRACE("ObjBottom:%d",EventInfo.ObjBottom); // TRACE("FilePath:%s",EventInfo.FilePath); // TRACE("RecordFileName:%s",EventInfo.RecordFileName); // TRACE("PictureName:%s",EventInfo.PictureName); // // TRACE("ScoutChannel:%d",EventInfo.ScoutChannel); // TRACE("FileScoutPath:%s",EventInfo.FileScoutPath); // TRACE("RecordScoutFileName:%s",EventInfo.RecordScoutFileName); // TRACE("PictureScoutName:%s",EventInfo.PictureScoutName); // TRACE("AreaPoints:%d",EventInfo.AreaPointsNum); // for(i=0;i0) { T_UserInfo TempUsInfo; //strcpy(TempUsInfo.UserName,TempUserInfoList.User[0].UserName); strcpy(TempUsInfo.UserName,"1"); strcpy(TempUsInfo.UserPwd,"0"); TempUsInfo.UserPro= 3; strcpy(TempUsInfo.UserDetail,"Normal User "); if(HwPtcSetDevUserInfo(SockHandle[0],Type_UsChg,TempUsInfo)) { AfxMessageBox("OK"); } else { TRACE("HwPtcSetDevUserInfo FALSE %d",GetLastNetError()); } } TRACE("QueueCount %d",HwPtcGetMsgCount()); } void CHwProtocol_demoDlg::OnHwPtcGetVideoColor() { // TODO: Add your control notification handler code here T_RVideoColor TmpPara; if(HwPtcGetVideoColor(SockHandle[0],1,&TmpPara) ) { TRACE("bytWin %d\n",TmpPara.bytWin); TRACE("bytBright %d\n",TmpPara.bytBright); TRACE("bytContrast %d\n",TmpPara.bytContrast); TRACE("bytSaturation %d\n",TmpPara.bytSaturation); TRACE("bytHue %d\n",TmpPara.bytHue); TRACE("OK\n"); TmpPara.bytBright = 127; TmpPara.bytContrast = 127; TmpPara.bytSaturation = 64; TmpPara.bytHue = 0; } else { TRACE("FALSE %d\n",GetLastNetError()); } TRACE("QueueCount %d",HwPtcGetMsgCount()); if(HwPtcSetVideoColor(SockHandle[0],TmpPara)) { AfxMessageBox("OK"); } else { TRACE("HwPtcGetVideoColor FALSE %d",GetLastNetError()); } TRACE("QueueCount %d",HwPtcGetMsgCount()); } void CHwProtocol_demoDlg::OnHwPtcGetDecoderPara() { // TODO: Add your control notification handler code here T_DecoderPara decoderPara; if(HwPtcGetDecoderPara(SockHandle[0],1,&decoderPara)) { TRACE("BaudRate=%d\n",decoderPara.lngBaudRate); TRACE("DataBit=%d\n",decoderPara.bytDataBit); TRACE("Decoder Addr=%d\n",decoderPara.bytDecAddr); TRACE("Decoder Protocol=%d\n",decoderPara.bytDecPrtc); TRACE("StopBit=%d\n",decoderPara.bytStopBit); TRACE("ParityBit=%d\n",decoderPara.bytParityBit); // decoderPara.bytDecPrtc = 3; } else { TRACE("HwPtcGetDecoderPara FALSE %d\n",GetLastNetError()); } TRACE("QueueCount %d",HwPtcGetMsgCount()); decoderPara.lngBaudRate = 9600; if(HwPtcSetDecoderPara(SockHandle[0],1,decoderPara)) { AfxMessageBox("OK"); } else { TRACE("HwPtcSetDecoderPara FALSE %d",GetLastNetError()); } TRACE("QueueCount %d",HwPtcGetMsgCount()); } void CHwProtocol_demoDlg::OnHddinfo() { // TODO: Add your control notification handler code here T_HDDINFOList HddPara; if(HwPtcGetHDDInfo(SockHandle[0],&HddPara)) { TRACE("DiskNumber=%d\n",HddPara.byteDiskNumber); TRACE("TotalVolume=%d\n",HddPara.lngTotalVolume); TRACE("TotalFreeSpace=%d\n",HddPara.lngTotalFreeSpace); for(int i=0;i=0) HwPtcStopPlayBack(PlayHandle); PLAYBACKWIN = this->GetDlgItem(IDC_PLAY)->GetSafeHwnd(); PlayM4_SetStreamOpenMode(10,STREAME_FILE); PlayHandle = HwPtcPlayBackByTime(SockHandle[0],8888,2,&gbfiledata); if(PlayHandle>=0) { HwPtcSetPlayDataCallBack(PlayHandle,dPlayBackDataCallBack,11); HwPtcPlayBackStart(PlayHandle); } } void CALLBACK dPlayBackDataCallBack(long PlayBackId,int VideoType,char * buf,long buflen,long dwUser) { //Sleep(100); TRACE("PlayBackId:%d VideoType:%d User:%d",PlayBackId,VideoType,dwUser); if(VideoType==1) { PlayM4_OpenStream(10,(BYTE*)buf,buflen,BUF4M); PlayM4_Play(10, PLAYBACKWIN); } if(VideoType==2) { while((BUF4M - PlayM4_GetSourceBufferRemain(10))=0) { PlayM4_Stop(10); PlayM4_CloseStream(10); HwPtcStopPlayBack(PlayHandle); } } void CHwProtocol_demoDlg::OnGetPlayPos() { // TODO: Add your control notification handler code here long Pos = 0; if(PlayHandle>=0) { HwPtcPlayBackGetPos(PlayHandle,&Pos); TRACE("Play Pos:%d",Pos); } } void CHwProtocol_demoDlg::OnSetPlayPos() { // TODO: Add your control notification handler code here long Pos = 25; if(PlayHandle>=0) { HwPtcPlayBackSetPos(PlayHandle,Pos); TRACE("Play Pos:%d",Pos); } } void CHwProtocol_demoDlg::OnPlaysize() { // TODO: Add your control notification handler code here if(PlayHandle>=0) { long Size = 0; HwPtcPlayBackGetFileSize(PlayHandle,&Size); TRACE("Size:%d",Size); } } void CHwProtocol_demoDlg::OnFf() { // TODO: Add your control notification handler code here PlayM4_Fast(10); } void CHwProtocol_demoDlg::OnSf() { // TODO: Add your control notification handler code here PlayM4_Slow(10); } void CHwProtocol_demoDlg::OnSetAlarmOut() { // TODO: Add your control notification handler code here if(HwPtcSetAlarmOutState(SockHandle[0],1,1)==FALSE) { AfxMessageBox("Failed"); } } void CHwProtocol_demoDlg::OnRealPlay() { // TODO: Add your control notification handler code here RealHandle = HwPtcRealPlay(SockHandle[0],6050,0,0,3000); if(RealHandle <0) return; PLAYBACKWIN = this->GetDlgItem(IDC_PLAY)->GetSafeHwnd(); HwPtcRegisterRealDataCallBack(RealHandle,dRealDataCallBack,0); HwPtcRealCapture(RealHandle); } void CHwProtocol_demoDlg::OnRealStop() { // TODO: Add your control notification handler code here HwPtcRealStop(RealHandle); PlayM4_Stop(10); } void CALLBACK dRealDataCallBack(long RealId,int VideoType,char * buf,long buflen,long dwUser) { //TRACE("VideoType:%d BufLen:%d",VideoType,buflen); if(VideoType == 1) { PlayM4_SetStreamOpenMode(10,0); PlayM4_OpenStream(10,(BYTE*)buf,buflen,1024*1024*2); PlayM4_Play(10,PLAYBACKWIN); } else { PlayM4_InputData(10,(BYTE*)buf,buflen); } }