alarm.c
来自「采用MINIGUI开发的一套GUI界面」· C语言 代码 · 共 865 行 · 第 1/2 页
C
865 行
}static void ForwardDate(HWND hDlg){ unsigned char buff[20]; long t; switch (period){ case DAY : { t = GetSecond(); t += 86400; SecondToTime(t); sprintf(buff, "%02d/%02d/%04d", report_date.month,report_date.day ,report_date.year); SetDlgItemText(hDlg, ALARM_DATE,buff); }break; case MONTH: { if (report_date.month == 12){ report_date.month = 1; report_date.year++; } else report_date.month++; sprintf(buff, "%04d年%02d月",report_date.year,report_date.month); SetDlgItemText(hDlg, ALARM_DATE,buff); }break; case WEEK: { t = GetSecond(); t += 86400*7; SecondToTime(t); sprintf(buff, "%02d/%02d/%04d", report_date.month,report_date.day ,report_date.year); SetDlgItemText(hDlg, ALARM_DATE,buff); }break; }}static void BackDate(HWND hDlg){ unsigned char buff[20]; long t; switch (period){ case DAY: { t = GetSecond(); t -= 86400; SecondToTime(t); sprintf(buff, "%02d/%02d/%04d", report_date.month,report_date.day ,report_date.year); SetDlgItemText(hDlg, ALARM_DATE,buff); }break; case MONTH: { if (report_date.month == 1){ report_date.month = 12; report_date.year--; } else report_date.month--; sprintf(buff, "%04d年%02d月",report_date.year,report_date.month); SetDlgItemText(hDlg, ALARM_DATE,buff); }break; case WEEK: { t = GetSecond(); t -= 86400*7; SecondToTime(t); sprintf(buff, "%02d/%02d/%04d", report_date.month,report_date.day ,report_date.year); SetDlgItemText(hDlg, ALARM_DATE,buff); }break; }}DealAlarm(){ //通知 小喇叭闪 //判断警报类型 ,改变方块、曲线 颜色 //根据 通道状态写报警文件:警报登陆}/****************************************** 功能:得到警报类型 入口:通道id号 出口:暗含id号及报警类型的整数 格式为 id*7 + alarmtype *********************************************/unsigned int GetAlarmType(int id){ float fpv; float h; float hh; float l; float ll; fpv = channel_conf[id].fpv; h = channel_conf[id].h_alarm; hh = channel_conf[id].hh_alarm; l = channel_conf[id].l_alarm; ll = channel_conf[id].ll_alarm;//gcvt(temp_pv,6,channel_conf[id].data); if((channel_conf[id].hh_enabled) && (fpv>=hh)) return (id*7 + HIHI); else if((channel_conf[id].h_enabled) && (fpv>=h)) return (id*7 + HI); else if((channel_conf[id].ll_enabled) && (fpv<=ll)) return (id*7 + LOLO); else if((channel_conf[id].l_enabled) && (fpv<=l)) return (id*7 + LO); else return (id*7 + NORMAL);}// 处理报警条目/*alarm_state: 7种alarm_num: Listview中行号*/BOOL DealAlarmReport(HWND hDlg,unsigned int alarm_type){ unsigned short old_type; unsigned short new_type; unsigned short type; unsigned int alarm_num; int id; id = alarm_type/7; new_type = alarm_type%7; old_type = channel_conf[id].alarm_state; if(old_type == new_type) return 0; if(new_type == NORMAL) { alarm_num = channel_conf[id].alarm_num; AlarmSolve(hDlg ,alarm_num); //警报解决,恢复正常 } else AlarmHappen(hDlg,new_type,id);//添加报警条目 channel_conf[id].alarm_state = new_type; return 1;}static void AlarmHappenTest (HWND hDlg)//PALARMTABLE alarm ,{ int i, j; char buff1[10]; char buff2[10]; char startTime[15]; time_t t; struct tm* tm; time(&t); tm = localtime(&t); sprintf(startTime, "%02d/%02d %02d:%02d:%02d", tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); alarm_number++; item.nItem = alarm_number; SendMessage (hDlg, LVM_ADDITEM, 0, (LPARAM) & item); subdata.nItem =alarm_number; sprintf (buff2, "%.2f", 10.250); sprintf (buff1, "%d ", alarm_number); //sprintf (buff2, "%d ", id); for (j = 1; j <= ALARM_LIST; j++) { subdata.subItem = j; switch(j){ case 1 : subdata.pszText = buff1;break; case 2 : subdata.pszText = "hihi警报";break; case 3 : subdata.pszText = "AL1";break; case 4 : subdata.pszText = startTime;break; case 5 : subdata.pszText = "haha";break; case 6 : subdata.pszText = buff2;break; } SendMessage (hDlg, LVM_SETITEMCOLOR, alarm_number, PIXEL_green); SendMessage (hDlg, LVM_FILLSUBITEM, 0, (LPARAM) & subdata); }}static void AlarmHappen (HWND hDlg, unsigned short palarm_type,int id)//PALARMTABLE alarm ,{ int i, j; char buff1[10]; char buff2[10]; char startTime[15]; time_t t; struct tm* tm; time(&t); tm = localtime(&t); sprintf(startTime, "%02d/%02d %02d:%02d:%02d", tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); alarm_number++; channel_conf[id].alarm_num = alarm_number; item.nItem = alarm_number; SendMessage (hDlg, LVM_ADDITEM, 0, (LPARAM) & item); //printf("enter alarm ! "); //printf("alarmtype= % s \n",(*alarm_type) + palarm_type); subdata.nItem =alarm_number; sprintf (buff2, "%.2f", channel_conf[id].fpv); sprintf (buff1, "%d ", alarm_number); //sprintf (buff2, "%d ", id); for (j = 1; j <= ALARM_LIST; j++) { subdata.subItem = j; switch(j){ case 1 : subdata.pszText = buff1;break; case 2 : subdata.pszText = alarm_type[palarm_type];break; case 3 : subdata.pszText = channel_conf[id].name;break; case 4 : subdata.pszText = startTime;break; case 5 : subdata.pszText = "";break; case 6 : subdata.pszText = buff2;break; } SendMessage (hDlg, LVM_SETITEMCOLOR, alarm_number, PIXEL_red); SendMessage (hDlg, LVM_FILLSUBITEM, 0, (LPARAM) & subdata); }}static void AlarmInit (HWND hDlg){ FILE *fp; time_t t; struct tm* tm; LVCOLOUM lvcol; int i; static unsigned char * alarm_caption [ALARM_LIST] = { "序号", "型式", "来源", "发生时间","清除时间","数值" }; static unsigned char * report_caption [REPORT_LIST] = { "No", "型式", "名称", "数值","单位" }; int width1[6] = {45,120,70,120,120,75}; int width2[6] = {50,110,90,220,80}; /*write listview headline*/ for (i = 1; i <= ALARM_LIST; i++) { lvcol.nCols = i; lvcol.pszHeadText = alarm_caption[i-1]; lvcol.width = width1[i-1]; SendMessage (GetDlgItem (hDlg, ALARM_ALERT_LIST), LVM_ADDCOLUMN, 0, (LPARAM) &lvcol); } for (i = 1; i <= REPORT_LIST; i++) { lvcol.nCols = i; lvcol.pszHeadText = report_caption[i-1]; lvcol.width = width2[i-1]; SendMessage (GetDlgItem (hDlg, ALARM_REPORT_LIST), LVM_ADDCOLUMN, 0, (LPARAM) &lvcol); } RowY = 1; alarm_number = 0; period = DAY; time(&t); tm = localtime(&t); report_date.year = tm->tm_year + 1900; report_date.month = tm->tm_mon+1; report_date.day = tm->tm_mday; sprintf(date, "%02d/%02d/%04d",tm->tm_mon+1,tm->tm_mday,tm->tm_year + 1900); SetDlgItemText(hDlg, ALARM_DATE,date); fp = fopen("alarmfile","wb+"); fclose(fp); fp = fopen("reportfile","wb+"); fclose(fp);}static void DownloadItem (HWND hDlg ){ int i, j; FILE *fp; unsigned char buff[20]; if((fp = fopen("alarmfile","ab+")) == NULL){ printf("can't open the file\n"); } else printf("can open the file\n"); if(IsWindowVisible (hDlg)){ for( i=1; i<= alarm_number; i++){ subdata.nItem = i; for (j = 1; j <= ALARM_LIST; j++) { subdata.subItem = j; //// SendMessage (hDlg, LVM_GETSUBITEMTEXT, 0, (LPARAM)&subdata) ; // sprintf(buff,"%s",subdata.pszText); // printf("%s\n",buff); // printf("sizeof(subdata.pszText)=%d\n",strlen(subdata.pszText)); fwrite(&subdata.pszText,strlen(subdata.pszText),1,fp); } } } fclose(fp); AlarmClear(hDlg); }static void AlarmSolve (HWND hDlg ,int num){ int i; gal_pixel alarm_bkcol; alarm_bkcol = RGB2Pixel(GetClientDC (hDlg),0,100,12); InvalidateRect (hDlg, NULL, FALSE); SendMessage (hDlg, LVM_SETITEMCOLOR, num, PIXEL_green);}static void AlarmOver (HWND hDlg ,int num){ int i; unsigned char endTime[15]; time_t t; struct tm* tm; gal_pixel alarm_bkcol; alarm_bkcol = RGB2Pixel(GetClientDC (hDlg),127,49,12); time(&t); tm = localtime(&t); sprintf(endTime, "%02d/%02d %02d:%02d:%02d", tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); subdata.nItem = num; subdata.subItem =5; subdata.pszText = endTime; InvalidateRect (hDlg, NULL, FALSE); SendMessage (hDlg, LVM_FILLSUBITEM, 0, (LPARAM)&subdata) ; SendMessage (hDlg,LVM_SETITEMCOLOR, num, alarm_bkcol) ;}static void AlarmClear (HWND hDlg ){SendMessage(hDlg, MSG_VSCROLL, SB_THUMBTRACK,0); SendMessage (hDlg, LVM_DELALLITEM, 0, 0) ;alarm_number = 0;}void DlgConfAlert(HWND hWnd){ DlgEvent.controls = CtrlEvent; DialogBoxIndirectParam (&DlgEvent, hWnd, EventProc, 0L);}//根据时间得到秒数void SecondToTime(long seconds){time_t t; struct tm *time ; //char *strtime;// strtime=(char*)malloc(20*sizeof(char)); t=(time_t)seconds; // t=1169861118; time=gmtime(&t); // strtime=ctime(&t); report_date.year = time->tm_year+1900; report_date.month = time->tm_mon+1; report_date.day = time->tm_mday;// return strtime;}long GetSecond(void){ struct timeval tv; struct timezone tz; time_t t; struct tm nowtime; nowtime.tm_sec=0;/* Seconds.[0-60] (1 leap second)*/ nowtime.tm_min=0;/* Minutes.[0-59] */ nowtime.tm_hour=1;/* Hours. [0-23] */ nowtime.tm_mday=report_date.day;/* Day.[1-31] */ nowtime.tm_mon=report_date.month-1;/* Month. [0-11] */ nowtime.tm_year= report_date.year-1900 ;/* Year+ 1900.*/ nowtime.tm_isdst=-1 ;// -1:不关心 1:夏令时间 ,不夏令时候0 t=mktime(&nowtime); return (long)t;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?