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

📄 init.c

📁 采用MINIGUI开发的一套GUI界面
💻 C
字号:
/*
设备与通道信息初始化分2种情况

1.模拟
2.实时 情况

*/





#include     <stdio.h>        /*标准输入输出定义*/
#include     <stdlib.h>       /*标准函数库定义*/
#include     <unistd.h>       /*Unix 标准函数定义*/
#include     <sys/times.h>  
#include     <sys/types.h>  

#include     <sys/stat.h>   
#include     <sys/ioctl.h>             
                    
#include <minigui/common.h>           
#include <minigui/minigui.h>          
#include <minigui/gdi.h>            
#include <minigui/window.h>           
#include <minigui/control.h>          
#include <minigui/mgext.h>            
                    
#include <sys/types.h>            
#include <sys/shm.h>            
#include <sys/ipc.h>   
#include <sys/time.h>          
#include     <fcntl.h>        /*文件控制定义*/
#include     <termios.h>      /*PPSIX 终端控制定义*/
#include     <unistd.h>  
#include     <errno.h>        /*错误号定义*/
#include     <pthread.h>
#include     <math.h>         /*数学函数定义*/

#include <ctype.h>          
#include "common.h"           
#include "meter.h"
#include "init.h"
/*-------------1.模拟-------------------------------------*/

//没有板卡时候的  模拟注册信息
void DemoRegist(void )
{
int value;
	devicesinfo=(DEVICES_STRU *)malloc(16*sizeof(DEVICES_STRU ));
	channel_disp=(CHANDISP* )malloc(32*sizeof(CHANDISP));
	channel_conf=(CHANCONF* )malloc(32*sizeof(CHANCONF));
	doinfo=(DO_STRU* )malloc(16*sizeof(DO_STRU));    //最好16个
	bzero(devicesinfo,sizeof(*devicesinfo)); 
	bzero(channel_disp,sizeof(*channel_disp)); 
	bzero(doinfo,sizeof(*doinfo)); 
	
	//从文件中得到初始模拟和数学通道总数

	GetIntValueFromEtcFile("system.conf", "AI","Number",&value);
	ai_chan_sum=value;


}
//没有板卡时候的  模拟实时读取数据
void ReadDefaultValue(int gchannum,int index)
{
  int id;
int temp;
  float dot;
  float temp_pv ;
  int temp2;
  temp=1;
  for (id=0;id<gchannum;id++) 	
  	{
  	 	channel_disp[id].dev_id=1;//表示本通道信息来自于设备的id
if(index*10<640)
temp2=abs(320-index*10)+(id+1)*40;
else  temp2=abs((id+1)*60-320);
	 channel_disp[id].ipv=100+temp2;	
	 
 	channel_disp[id].dot=1;
	
	 channel_disp[id].oldpoint[index]=GetCurveHeight(id);
	 if(!bdispcurve)
	 	{
	 	channel_disp[id].point[index]=channel_disp[id].oldpoint[index];
	 	if(index>1)channel_disp[id].point[index-1]=channel_disp[id].oldpoint[index-1];
	 	if(index>2)channel_disp[id].point[index-2]=channel_disp[id].oldpoint[index-2];
	 	}
	  dot=channel_disp[id].dot;
	   temp_pv= (float)(channel_disp[id].ipv/(dot*10));	 
	   channel_disp[id].fpv=temp_pv;
	  gcvt(temp_pv,6,channel_disp[id].data); 
	
  	}
	 

}

//全局变量初始化
void Init( )
{
 int id;
int value;
	timer_stat=	(TIMERINFO* )malloc(6*sizeof(TIMERINFO));
	//---实时曲线----------------------	
	RealIndex=0;   //   实时点
	RealIndex_max=640;
	fullscr=0;
	interval=1;// 扫描间隔
	gzoom=1;   //实时曲线显示放大
	histzoom=1;
	bdispcurve=0;

	nowseconds=0;
	year=0;hour=0;minu=0;seco=0;mont=0;days=0;
	Commfd2=0;
	counter_temp=0;
	
//ToolTimerInit();
	bfresh_conf=0;
		//显示有关		
		//对AI 通道初始化
	 gdisp_mode=1;//默认为总浏览模式

 bLeftShow=0;		//左侧菜单是否在显示
	
 		
		 b_com_timeout=0;
		 
 //	bzero(channel_disp[id].point,640);
}
/*	----------------------------------------------------	
AI通道显示变量初始化
---------------------------------------------------*/
void AiChanInit( HWND hWnd)
{

HDC hdc;
unsigned char str_resource[10];
unsigned char str_goal[10];
unsigned char str[10];
int value;
  	int id;
  	gal_pixel rect_color_back;    
  	gal_pixel barcolor;
	bzero(str,sizeof(str_resource)); 
		
	hdc=GetClientDC(hWnd) ;
  for (id=0;id<ai_chan_sum;id++) 	
   	{      
   	sprintf(channel_disp[id].data,"test");  	
	
	 channel_disp[id].color_old=RGB2Pixel(hdc,30,128,(id%7)*64);//给显示块赋值颜色,TAG,unit
	 channel_disp[id].color= channel_disp[id].color_old;
  	sprintf(str_resource,"AI%d",(id+1));
  	}

}

void DiChanInit (void)
{
//先判断是否注册了
int dev_id;

   for(dev_id=0;dev_id<16;dev_id++)      	
   	{
	if(devicesinfo[dev_id].dev_type==2)
		{
		//从system.conf文件中读入DI 信息


		}
   	}



}


/*没有通讯时候的初始化*/
void MathChanInit( HWND hWnd)
{
int id;
HDC hdc;
unsigned char str_resource[10];
unsigned char str_goal[10];
int value;
unsigned char str[10];
hdc=GetClientDC(hWnd) ;
	GetIntValueFromEtcFile("system.conf", "MATH","Number",&value);
	math_chan_sum=value;

	
  for (id=ai_chan_sum;id<ai_chan_sum+math_chan_sum;id++) 	
  	{
	  strcpy(channel_disp[id].data,"test");  //   浮点转为字符串
 	channel_disp[id].color_old=RGB2Pixel(hdc,30,128,(id%7)*64);
 	channel_disp[id].color= channel_disp[id].color_old;



  	}

	gchannum=ai_chan_sum+math_chan_sum;
	gchanpage_sum=(gchannum/PCHAN_MAX)+1;//总共页面数
	gchanpage=1;//默认为第一个数字显示1个页面
  
  ReleaseDC(hdc);
}


/*
do 注册

*/
void DoRegist(void)
{
int id ;
 for(id=0;id<8;id++)    //假设16   DO
 	{
	doinfo[id].dev_id=5; //与DeviceDefaultReg中信息对应
	if(id%2==0)doinfo[id].flag=0;
	else doinfo[id].flag=1;
 	}
 for(id=8;id<16;id++)    //假设16   DO
 	{
	doinfo[id].dev_id=5; //与DeviceDefaultReg中信息对应
	if(id%2==0)doinfo[id].flag=1;
	else doinfo[id].flag=0;
 	}


}
/*
void ToolTimerInit(void)
{
int id ;
 for(id=0;id<6;id++)    
 	{
	 //与DeviceDefaultReg中信息对应
	if(id%2==0)timer_stat[id].flag=0;
	else timer_stat[id].flag=1;
 	}
}*/
//模拟设备注册
void DeviceDefaultReg(void)
{

int dev_id;

		dev_id=0;//  first=1	

   for(dev_id=0;dev_id<16;dev_id++)      	
   	{
    	devicesinfo[dev_id].dev_addr= dev_id+1;
       devicesinfo[dev_id].first_channel_id=0;
        devicesinfo[dev_id].dev_total_channel=6;
	devicesinfo[dev_id].enable=1;
	devicesinfo[dev_id].boudrate=4800;
	 //  1: ai  2:  di   3: do  4:  other
	 //test
	if(dev_id==4)
		{devicesinfo[dev_id].dev_type=2;
		sprintf(devicesinfo[dev_id].dev_name,"  DI 仪表");
		DiChanInit();
		}
	else if(dev_id==5)
		{devicesinfo[dev_id].dev_type=3;
		sprintf(devicesinfo[dev_id].dev_name," DO仪表");
			do_chan_sum=16;
			DoRegist();
		}
	else 
		{devicesinfo[dev_id].dev_type=1  ; 
	   	sprintf(devicesinfo[dev_id].dev_name,"wp仪表");
		}

   	}

   
}
//		设备中变量初始化
void DevInit()
{
b_wr_config=0;//设备组态通讯状态0:通讯处于时实PV值更新1:组态参数读写


}

void ConfigInit( void)
{
int  baudrate;
    int i;
    unsigned char str_resource[4];
    unsigned char str[20];
	bzero(str,sizeof(str)); 
	str_resource[4]='\0';
    //系统组态

 for (i=0;i<1;i++) 	
  	{

	

	
  	}
  	

}

/*从文件中得到组态原始信息*/




void  LoadBmp (void )
   {
    unsigned char buf[30]; 
	buf[0]='\0';
    sprintf(buf,"res/save.bmp");	    	LoadBitmap(HDC_SCREEN,&save_bmp ,buf);
    sprintf(buf,"res/normal.bmp");    	LoadBitmap(HDC_SCREEN,&lamp_bmp[0],buf);
    sprintf(buf,"res/flash.bmp");    	LoadBitmap(HDC_SCREEN,&lamp_bmp[1],buf);
    sprintf(buf,"res/alarm.bmp");    	LoadBitmap(HDC_SCREEN,&lamp_bmp[2],buf);
	sprintf(buf,"res/red.bmp");     	LoadBitmap(HDC_SCREEN,&staticbmp[0],buf);  
     sprintf(buf,"res/green.bmp");     	LoadBitmap(HDC_SCREEN,&staticbmp[1],buf);  
     sprintf(buf,"form/form1.bmp");     	LoadBitmap(HDC_SCREEN,&formulabmp[0],buf);  
     sprintf(buf,"form/form2.bmp");     	LoadBitmap(HDC_SCREEN,&formulabmp[1],buf);  
	 /*载入左边图片*/
    sprintf(buf,"res/up.bmp");    			LoadBitmap(HDC_SCREEN,&direction_bmp[0],buf);
    sprintf(buf,"res/down.bmp");   		LoadBitmap(HDC_SCREEN,&direction_bmp[1],buf);
    sprintf(buf,"res/left.bmp");   		 	LoadBitmap(HDC_SCREEN,&direction_bmp[2],buf);
    sprintf(buf,"res/right.bmp");   		 	LoadBitmap(HDC_SCREEN,&direction_bmp[3],buf);
	sprintf(buf,"res/enter.bmp");    		LoadBitmap(HDC_SCREEN,&direction_bmp[4],buf);
	sprintf(buf,"res/forward.bmp");   		LoadBitmap(HDC_SCREEN,&hist_bmp[0],buf);
    sprintf(buf,"res/forback.bmp");    		LoadBitmap(HDC_SCREEN,&hist_bmp[1],buf);
    sprintf(buf,"res/first.bmp");    			LoadBitmap(HDC_SCREEN,&hist_bmp[2],buf);
    sprintf(buf,"res/last.bmp");    			LoadBitmap(HDC_SCREEN,&hist_bmp[3],buf);
    sprintf(buf,"res/zoom.bmp");  		  	LoadBitmap(HDC_SCREEN,&hist_bmp[4],buf);	
  sprintf(buf,"res/return.bmp");   		 	LoadBitmap(HDC_SCREEN,&hist_bmp[5],buf);		
  sprintf(buf,"res/upanddown.bmp");   		LoadBitmap(HDC_SCREEN,&event_bmp[0],buf);
    sprintf(buf,"res/up.bmp");   		 	LoadBitmap(HDC_SCREEN,&event_bmp[1],buf);
    sprintf(buf,"res/down.bmp");    		LoadBitmap(HDC_SCREEN,&event_bmp[2],buf);
    sprintf(buf,"res/enter.bmp");    		LoadBitmap(HDC_SCREEN,&event_bmp[3],buf);
	//棒图图片
     sprintf(buf,"res/hh.bmp");     	LoadBitmap(HDC_SCREEN,&BarAlertBmp[0],buf); 
     sprintf(buf,"res/h.bmp");     	LoadBitmap(HDC_SCREEN,&BarAlertBmp[1],buf);  
     sprintf(buf,"res/l.bmp");     	LoadBitmap(HDC_SCREEN,&BarAlertBmp[2],buf); 
     sprintf(buf,"res/ll.bmp");     	LoadBitmap(HDC_SCREEN,&BarAlertBmp[3],buf);  



}





PCONTROL Control (HWND hWnd)
{
    PCONTROL pCtrl;

    pCtrl = (PCONTROL) hWnd;

    if (pCtrl && pCtrl->WinType == 0x12)
        return pCtrl;

    return NULL;
}


//#define BS_BITMAP           0x00000080L
#define BM_IMAGE_BITMAP         1

static int MybuttonWindowProc(HWND hWnd,int message,WPARAM wParam,LPARAM lParam)
{
	HDC hdc;
    	PCONTROL    pCtrl;
	gal_pixel btn_color;
	int bottom,top,right,left;
	RECT  prcClient;
	int have_bmp=0;
	static int status ;
    	pCtrl   = Control(hWnd);
switch(message)
    {
        case MSG_CREATE:
	{
          switch (pCtrl->dwStyle & BS_CONTENTMASK) {
              case BS_BITMAP:
               {	
		#ifdef DEBUG_MYBUTTON
                  printf("load bmp ok\n");
		#endif 	
                  pCtrl->dwAddData2 =  (DWORD) lParam;
             }
              break;  
              }
		  status=0;
         }
        break;
  		
	 case BM_GETIMAGE:
                    
                    #ifdef DEBUG_MYBUTTON
                    			printf(" BM_GETIMAGE  \n");
                    #endif 	 	
	 	
            if ((wParam == BM_IMAGE_BITMAP) && (pCtrl->dwStyle & BS_BITMAP))
                return (int)(BUTTON_DATA (pCtrl));
             
        break;
	  case BM_SETIMAGE:
                 #ifdef DEBUG_MYBUTTON
                 			printf(" BM_SETIMAGE  \n");
                 #endif 	
	
            if  ((wParam == BM_IMAGE_BITMAP) && (pCtrl->dwStyle & BS_BITMAP))
                    {
                 int oldImage = (int)BUTTON_DATA (pCtrl);
                 BUTTON_DATA (pCtrl) = (DWORD)lParam;
                 InvalidateRect (hWnd, NULL, TRUE);
                 return oldImage;
            }
        break;
	case MSG_SETFOCUS:
		break;
	case MSG_KILLFOCUS:
			break;			
        case MSG_KEYUP:
        {        
            if (wParam != SCANCODE_SPACE && wParam != SCANCODE_ENTER)
			break;			
        	}
       break;		
	  case MSG_KEYDOWN:
            if (wParam != SCANCODE_SPACE && wParam != SCANCODE_ENTER)
			break;	
	 break;			
    case MSG_COMMAND:

		break;
    case MSG_LBUTTONDOWN:
		status=1;
		SetCapture(hWnd);
		InvalidateRect(hWnd,NULL,TRUE);
		break;
    case MSG_LBUTTONUP:
		if(GetCapture()!=hWnd)break;
		status=0;
		ReleaseCapture( );
                InvalidateRect (hWnd, NULL, FALSE);
		break;
   case MSG_PAINT:
   		GetClientRect(hWnd, &prcClient); 
		hdc=BeginPaint(hWnd);	
			 
		left=prcClient.left;
		right=prcClient.right;
		top=prcClient.top;
		bottom=prcClient.bottom;
		 
		
		 SetBrushColor(hdc,PIXEL_black);
		 FillBox(hdc,left,top,right,bottom);
		if(status){//按下		
		SetBkMode(hdc,BM_TRANSPARENT);	
		SetBrushColor(hdc,PIXEL_lightgray);
		 FillBox(hdc,left,top,right,bottom);		 
  	 btn_color=RGB2Pixel(hdc,10,10,10);	
	 SetPenColor (hdc, btn_color);
	  Rectangle(hdc,left+3,top+3,right-5,bottom-5);  
        left++; top++; right--; bottom--;
  	 btn_color=RGB2Pixel(hdc,10,10,10);	
	 SetPenColor (hdc, btn_color);
	  Rectangle(hdc,left+1,top+1,right-3,bottom-3);  	
		
			if (pCtrl)
 	 FillBoxWithBitmap(hdc, left+5, top+5, right-10, bottom-10, (PBITMAP)(  pCtrl->dwAddData2));
	
			}
		else 
			{//弹起
		SetBrushColor(hdc,PIXEL_lightgray);
		 FillBox(hdc,left,top,right,bottom);
		//SetPenType(hdc,1);
	/* btn_color=RGB2Pixel(hdc,10,10,10);	
		SetPenColor(hdc,btn_color);
      		 Rectangle(hdc,0,0,74,74);  */
		 btn_color=RGB2Pixel(hdc,120,120,120);	
		SetPenColor(hdc,btn_color);
      		 Rectangle(hdc,left,top,right-3,bottom-3);  	
		 btn_color=RGB2Pixel(hdc,80,80,80);	
		SetPenColor(hdc,btn_color);
      		 Rectangle(hdc,left,top,right-2,bottom-2);  
		btn_color=RGB2Pixel(hdc,0,0,0);		 
		SetPenColor(hdc,btn_color);
      		 Rectangle(hdc,left,top,right-1,bottom-1);   
		SetPenColor(hdc,PIXEL_darkgray);
      		 Rectangle(hdc,left,top,right,bottom);  
	 if (pCtrl)		
		//printf("test bmp");
 	  FillBoxWithBitmap(hdc, left+4, top+4, right-8, bottom-8, (PBITMAP)(  pCtrl->dwAddData2));
			}
		EndPaint(hWnd,hdc);
		return 0;
	case MSG_DESTROY:
        break;
        default:
        break;		
		 
    }
return DefaultControlProc(hWnd,message,wParam,lParam);
}
BOOL RegisterMybutton(void)
{
WNDCLASS WndClass;
	WndClass.spClassName="mybutton";
	WndClass.dwStyle=0;
	WndClass.dwExStyle=0;
	
	WndClass.hCursor=GetSystemCursor(0);
	WndClass.WinProc	=MybuttonWindowProc;
	return RegisterWindowClass(&WndClass);
}


⌨️ 快捷键说明

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