⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moinorcentredlg.cpp

📁 无线图象监控系统(用VC++编程)用数据库ACCESS存储图象
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{   if(data==0x60)
{ CS=CS^data;
state=s2;
}
else if(data=0xff)
state=s1;
else
{CS=0;
state=idle;
}

return 0;
}

if(state==s2)
{ switch (data)
{
  case mode1: {framemode=mode1;
	  state=s3;
	  CString ss;
	  //ss.Format("framemode=%x",framemode);
	  //AfxMessageBox(ss);
	  break;
			  }
	  
  case mode3: {framemode=mode3;state=s3;break;}
	  
  default: {AfxMessageBox("s2帧格式错误");state=idle;}
}

CS=CS^data;
return 0;
}

if(state==s3)
{  CS=CS^data;
fpgaaddr=data;
fpgaaddr=fpgaaddr<<8;
state=s4;
return 0;
}

if(state==s4)
{  CS=CS^data;
fpgaaddr=fpgaaddr|(WORD)data;
state=s5;
return 0;
}
if(state==s5)
{
	CS=CS^data;
	centreaddr=data;
	state=s6;
	return 0;
}
if(state==s6)
{CS=CS^data;
state=s7;
return 0;
}

if(state==s7)
{
	CS=CS^data;
	switch(framemode)
	{
	case mode1:{ mst.mode1state=data;
		state=scs;
		break;
			   }
	case mode3:{//picmode=((WORD)data)<<8;
		         state=s8;break; 
			   }
	default: {CString ss;ss.Format("s7帧格式错误framemode=%x",framemode);AfxMessageBox(ss);state=idle;CS=0;}
	}
	return 0;
}

if(state==s8)
{  CS=CS^data;
//picmode=picmode|(WORD)data;
state=s9;
return 0;
}

if(state==s9)
{ CS=CS^data;
picnum=data;
jpegdata.RemoveAll();
state=spic;
return 0;
}

if(state==spic)
{
	if(data==0xff)
	{
		state=spic_ff;
		return 0;
	}
	else
		jpegdata.Add(data);
	return 0;
}

if(state==spic_ff)
{ //if1
	if(data==0x06)
	{//if2
	CString time;
//CByteArray dd;
//dd.g
	int kk=(pic_width/8)*(pic_height/8);

//CByteArray dcdct;
//CByteArray acdct;
//dcdct.SetSize(kk);
//acdct.SetSize(kk);
   LPBYTE dcdct=new BYTE[kk];
   LPBYTE acdct=new BYTE[kk];
 CByteArray* jpegcopy=new CByteArray;
 jpegcopy->Copy(jpegdata);

		if(color)
		{
  Colordctdecode(pic_width,pic_height,pic_width,jpegcopy,1,dcdct,acdct);

	}
		 else
			{
		graydctdecode(pic_width,pic_height,pic_width,jpegcopy,1,dcdct,acdct);
	
		}
	     jpegcopy->RemoveAll();
			delete jpegcopy;
		
COleDateTime mtime;
mtime=COleDateTime::GetCurrentTime();
time=mtime.Format("%Y-%B-%d_%H-%M-%S");
jpgfilename.Format("D:\\pic\\site%d_%s.jpg",SiteNum.GetAt(siteidindex),time);
//AfxMessageBox("jpegwrite");
jpgfile.Open(jpgfilename,CFile::modeCreate|CFile::modeWrite);
if(color)
{
jpgfile.Write(colorhead,623);
}
else
{
jpgfile.Write(blackhead,328);
}
jpgfile.Write(jpegdata.GetData(),jpegdata.GetSize());
BYTE endd[2]={0xff,0xd9};
jpgfile.Write(endd,2);
jpgfile.Close();

CJpeg newjpeg;
newjpeg.Load(jpgfilename);
CString matter;
CDib* pdst=newjpeg.GetDib();
HDIB hDIB=CopyHandle(pdst->m_hDib);
alarmid=10;
//船舶检测
BYTE newindex=SiteNum.GetAt(siteidindex);
int tid=newindex%9;
m_alarm[tid].EnableWindow(TRUE);
m_alarm[tid].SetIcon(IDI_GREEN);
if(oldjpgload[newindex])
{
	CMoinorCentreApp* pwnd=(CMoinorCentreApp*)AfxGetApp(); 
	if(pwnd->alarmst[newindex].onoff)
	{
	if(pwnd->alarmst[newindex].alramtype==0)
		{pdst->ChangeImageSize(160,120);
pdst->ChangeToGray();
CDib* oldbmp=oldjpg[newindex].GetDib()->Clone();
  oldbmp->ChangeImageSize(160,120);
oldbmp->ChangeToGray();
BOOL alarm;
alarm=pdst->AlarmDetect(oldbmp,pwnd->alarmst[newindex].alarmlevel);

		if(alarm)
			{sndPlaySound("MIX3.WAV", SND_ASYNC);
		     alarmid=newindex%9;
			}
		else
		{
			alarmid=10;
		}
		oldbmp->Destroy();
		}
	else
	{ pdst->ChangeToGray();
		CDib* oldbmp=oldjpg[newindex].GetDib()->Clone();
	     oldbmp->ChangeToGray();
	  if(oldbmp->GetHeight()==pdst->GetHeight())
	  {
		  CString message;
		  int minsize=pwnd->alarmst[newindex].objectminsize;
		 message="";
         pdst->BoatNumDetect(oldbmp,&(pwnd->ckbj),100,message);
	 //pdst->bjdetect(&(pwnd->ckbj),message);
		CDC* pdc=GetDC();
	  pdst->Display(pdc,600,300);
	     ReleaseDC(pdc);
	  m_message=message;
		  UpdateData(FALSE);
	  }
	  oldbmp->Destroy();
	}
	}


	}
//oldjpg[oldsiteindex].GetDib()->Destroy();
oldsiteindex=SiteNum.GetAt(siteidindex);
oldjpg[oldsiteindex].Load(jpgfilename);
oldjpgload[oldsiteindex]=TRUE;
//CJpeg jpegpic;
//jpegpic.Load(jpgfilename);
//HDIB hDIB=CopyHandle(jpegpic.GetDib()->GetHandle());

//pdst->Destroy();
onedib.Destroy();
onedib.Attach(hDIB);

int i=SiteNum.GetAt(siteidindex)%4;
//HDIB fdib=CopyHandle(hDIB);
fourdib[i].Destroy();
fourdib[i].Attach(hDIB);
//HDIB ndib=CopyHandle(fdib);
int j=SiteNum.GetAt(siteidindex)%9;
ninedib[j].Destroy();
ninedib[j].Attach(hDIB);
	
switch(DisplayMode)
{
case OneZoom: {CRect pic;
	        GetDlgItem(ID_PICTURE)->GetWindowRect(pic);
pic.InflateRect(50,50);
	         InvalidateRect(pic);
	
	onesitename.Format("监控点%d图像",SiteNum.GetAt(siteidindex));

	PostMessage(WM_DRAW,DisplayMode,SiteNum.GetAt(siteidindex));
	break;
			  }
case FourDsplay:{CRect pic;
	          // GetDlgItem(ID_PICTURE)->GetWindowRect(pic);
//pic.InflateRect(50,50);
	          //InvalidateRect(pic);

	             foursitename[i].Format("监控点%d图像",SiteNum.GetAt(siteidindex));
	PostMessage(WM_DRAW,i,SiteNum.GetAt(siteidindex));
	break;
				}	
case NineDsplay:{//CRect pic;
//	GetDlgItem(ID_PICTURE)->GetWindowRect(pic);
//pic.InflateRect(50,50);
	//InvalidateRect(pic);
	
	ninesitename[j].Format("监控点%d图像",SiteNum.GetAt(siteidindex));
PostMessage(WM_DRAW,j,SiteNum.GetAt(siteidindex));
	break;
				}
case TurnAll:{CRect pic;
	         GetDlgItem(ID_PICTURE)->GetWindowRect(pic);
pic.InflateRect(50,50);
	             InvalidateRect(pic);

    onesitename.Format("监控点%d图像",SiteNum.GetAt(siteidindex));
	PostMessage(WM_DRAW,DisplayMode,SiteNum.GetAt(siteidindex));
	break;
			 }
}

COleDateTime moldtime;
CDaoDatabase db;
db.Open("port.mdb");
CDaoTableDef tb(&db);
CString tablename;
tablename.Format("Site%d",SiteNum.GetAt(siteidindex));
tb.Open(tablename);
rs.Open(&tb,dbOpenDynaset);

if(!rs.IsOpen())rs.Open();
if(moldtime!=mtime)
{
rs.AddNew();
CByteArray dct;
for(int i=0;i<kk;i++)
dct.Add(dcdct[i]);
for(i=0;i<kk;i++)
dct.Add(acdct[i]);
COleVariant aVar(dct);
rs.SetFieldValue("[dct]",aVar);

dct.RemoveAll();
dct.FreeExtra();
rs.m_DateAndTime=mtime;
rs.m_picturepath=jpgfilename;
rs.m_happening=matter;
rs.Update();

}


rs.Close();
tb.Close();
db.Close();
delete dcdct;
delete acdct;
moldtime=mtime;
CS=0x00;
//CString ss;
//ss.Format("picnum=%x",picnum);
//AfxMessageBox(ss);

if(picnum==255)
{
	if(mst.monitortype!=OneMonitor)
	{
	siteidindex=++siteidindex%SiteNum.GetSize();
	//if(++siteidindex<SiteNum.GetSize())
	//Sleep(700);
	PostMessage(WM_SEND,mode0,SiteNum.GetAt(siteidindex));

	}
	else
	{//Sleep(700);
	PostMessage(WM_SEND,mode2,SiteNum.GetAt(siteidindex));
	}

}


state=idle;
}//if2
else
{
	jpegdata.Add(0xff);
	jpegdata.Add(data);
	state=spic;
}
return 0;
}


if(state==scs)
{if(CS==data)
state=overhigh;
else
{CString scstr;
scstr.Format("帧校验错误CS=%x",CS);
CS=0x00;
state=idle;
AfxMessageBox(scstr);
state=idle;
}
return 0;
}

if(state==overhigh )
{   
	if(data==0xff)
        
		state=overlow;
	else
		state=idle;
	return 0;
}

if(state==overlow )
{  
	if(data==0x06)
	{//IFDATA
		CS=0;
		if(mst.mode1state==0x00)		                                  
			//AfxMessageBox("模式1接受正确");
			PostMessage(WM_SEND,mode2,SiteNum.GetAt(siteidindex));
		//AfxMessageBox("fashong");
	} 
	
	state=idle;	
	CS=0;
	return 0;
}

}
LRESULT CMoinorCentreDlg::OnSend(WPARAM wParam,LPARAM lParam)
{
	switch(wParam)
	{
	case mode0:{char send[11]={framehigh,framelow,mode0,siteid[lParam]>>8,siteid[lParam],0x00,0x00,0x00,
				   framehigh^framelow^mode0^(siteid[lParam]>>8)^siteid[lParam]^0x00^0x00^0x00,0xff,0x06};
		CString ss;
						  //ss.Format("siteid=%x",siteid[lParam]);
						  //AfxMessageBox(ss);
						  m_bSerialPort.WriteToPort(send,11);//帧尾
						  
						  break;
			   }
	case mode2:{
	CFile jpeghead;
	jpeghead.Open(filefullname,CFile::modeRead);
	if(filefullname.Find("彩色",0)!=-1)
	{
	jpeghead.Read(colorhead,623);
	color=TRUE;
	}
	else
	{
	 jpeghead.Read(blackhead,328);
	 color=FALSE;
	}
	jpeghead.Close();
	   BYTE piccnum;
	   if(mst.monitortype==OneMonitor)
		   piccnum=picnummode;
	   else
		   piccnum=0;
		char pich=picmode>>8;
		char send[13]={framehigh,framelow,mode2,siteid[lParam]>>8,siteid[lParam],0x00,0x00,pich,picmode,piccnum,
				   framehigh^framelow^mode2^(siteid[lParam]>>8)^siteid[lParam]^0x00^0x00^pich^picmode^piccnum,0xff,0x06};
		m_bSerialPort.WriteToPort(send,13); 

			   }
	}
	
	return 0;
}

LRESULT CMoinorCentreDlg::OnDraw(WPARAM wParam,LPARAM lParam)
{       //AfxMessageBox("draw");
	 
CClientDC dc(GetDlgItem(ID_PICTURE));
if(lParam==100)
	{
CRect rectPicture;
::GetClientRect(this->GetDlgItem(ID_PICTURE)->m_hWnd,&rectPicture);
dc.FillRect(&rectPicture,&m_bkBrush);
	}
	externi=wParam;
	CRect rec;
	
	::GetClientRect(GetDlgItem(ID_PICTURE)->GetSafeHwnd(),&rec);
	switch(DisplayMode)
	{   case OneZoom:{
		GetDlgItem(ID_PICTURE)->ShowWindow(SW_SHOW);
		for(int i=0;i<9;i++)
	        GetDlgItem(ID_PIC[i])->ShowWindow(SW_HIDE);
		CDC* ZoomDC;
	ZoomDC=GetDlgItem(ID_PICTURE)->GetDC();
	//Invalidate();
	GetDlgItem(ID_PICTURE)->SetWindowText(onesitename);
	onedib.Display(ZoomDC,0,30,rec.Width(),rec.Height()-30,0,0,onedib.GetWidth(),onedib.GetHeight());
	ReleaseDC(ZoomDC);
	break;
	}
	case FourDsplay:{
		GetDlgItem(ID_PICTURE)->ShowWindow(SW_HIDE);
		for(int i=4;i<9;i++)
	        GetDlgItem(ID_PIC[i])->ShowWindow(SW_HIDE);
		for( i=0;i<4;i++)
		{
           GetDlgItem(ID_PIC[i])->ShowWindow(SW_SHOW);
                           
		}			
		 CRect rec;
            GetDlgItem(ID_PICTURE)->GetWindowRect(rec);
             ScreenToClient(&rec);
			int width=rec.Width()/2-10;
			int height=rec.Height()/2-10;
			GetDlgItem(ID_PIC[0])->MoveWindow(rec.TopLeft().x,rec.TopLeft().y,width,height);
			GetDlgItem(ID_PIC[1])->MoveWindow(rec.TopLeft().x+width+20,rec.TopLeft().y,width,height);        
			GetDlgItem(ID_PIC[2])->MoveWindow(rec.TopLeft().x,rec.TopLeft().y+height+20,width,height); 
		    GetDlgItem(ID_PIC[3])->MoveWindow(rec.TopLeft().x+width+20,rec.TopLeft().y+height+20,width,height); 
	          
		for(i=0;i<4;i++)
		{ 
		if(fourdib[i].m_hDib==NULL)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -