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

📄 alert_main.cpp~

📁 用linux开发的安防暴警的有关代码
💻 CPP~
📖 第 1 页 / 共 5 页
字号:
int delete_specific_RC(int id){	int ret;	uchar tbuf[20],rbuf[20];	tbuf[0]=0x07;		//length	tbuf[1]=0x01;		//dest	tbuf[2]=0x02;		//flag	tbuf[3]=0x03;		//data length	tbuf[4]=0xcb;		//data1----command :delete card	tbuf[5]=0x1;		//data2----1--specific	tbuf[6]=id;	tbuf[7]=checksum(tbuf,7);		//cksum	ret=communication_with_module(tbuf,rbuf);	if (ret!=0) 	{		printf("communication error\n");   		return -1;	}	if ((rbuf[4]!=0xcb)||(rbuf[5]!=0xd6))	 {		printf("refused\n");		return -2;	}	return 0;}int register_IDcard_enter(void){	int ret;	uchar tbuf[20],rbuf[20];	tbuf[0]=0x05;		//length	tbuf[1]=0x01;		//dest	tbuf[2]=0x02;		//flag	tbuf[3]=0x01;		//data length	tbuf[4]=0xc6;		//data	tbuf[5]=checksum(tbuf,5);	//cksum	ret=communication_with_module(tbuf,rbuf);	if (ret!=0) 	{		printf("communication error\n");   		return -1;	}	if ((rbuf[4]!=0xc6)||(rbuf[5]!=0xd6))	 {		printf("refused\n");		return -2;	}	return 0;}int register_IDcard_exit(void){	int ret;	uchar tbuf[20],rbuf[20];	tbuf[0]=0x05;		//length	tbuf[1]=0x01;		//dest	tbuf[2]=0x02;		//flag	tbuf[3]=0x01;		//data length	tbuf[4]=0xc7;		//data	tbuf[5]=checksum(tbuf,5);	//cksum	ret=communication_with_module(tbuf,rbuf);	if (ret!=0) 	{		printf("communication error\n");   		return -1;	}	if ((rbuf[4]!=0xc7)||(rbuf[5]!=0xd6))	 {		printf("refused\n");		return -2;	}	return 0;}int register_RC_enter(void){	int ret;	uchar tbuf[20],rbuf[20];	tbuf[0]=0x05;		//length	tbuf[1]=0x01;		//dest	tbuf[2]=0x02;		//flag	tbuf[3]=0x01;		//data length	tbuf[4]=0xc9;		//data	tbuf[5]=checksum(tbuf,5);	//cksum	ret=communication_with_module(tbuf,rbuf);	if (ret!=0) 	{		printf("communication error\n");   		return -1;	}	if ((rbuf[4]!=0xc9)||(rbuf[5]!=0xd6))	 {		printf("refused\n");		return -2;	}	return 0;}int register_RC_exit(void){	int ret;	uchar tbuf[20],rbuf[20];	tbuf[0]=0x05;		//length	tbuf[1]=0x01;		//dest	tbuf[2]=0x02;		//flag	tbuf[3]=0x01;		//data length	tbuf[4]=0xca;		//data	tbuf[5]=checksum(tbuf,5);	//cksum	ret=communication_with_module(tbuf,rbuf);	if (ret!=0) 	{		printf("communication error\n");   		return -1;	}	if ((rbuf[4]!=0xca)||(rbuf[5]!=0xd6))	 {		printf("refused\n");		return -2;	}	return 0;}int register_Wireless_enter(int cno){		int ret;	uchar tbuf[20],rbuf[20];	tbuf[0]=0x06;		//length	tbuf[1]=0x01;		//dest	tbuf[2]=0x02;		//flag	tbuf[3]=0x01;		//data length	tbuf[4]=0xcf;		//data	tbuf[5]=cno;	tbuf[6]=checksum(tbuf,6);	//cksum	ret=communication_with_module(tbuf,rbuf);	if (ret!=0) 	{		printf("communication error\n");   		return -1;	}	if ((rbuf[4]!=0xcf)||(rbuf[5]!=0xd6))	 {		printf("refused\n");		return -2;	}	return 0;}void refresh_defence_stat(){	if (PROFILES.alert_defence_stat==DEFENCE_OFF)	{			bt_main_defence_off->value(1);		bt_main_inner_defence_on->value(0);		bt_main_out_defence_on->value(0);	}		else if (PROFILES.alert_defence_stat==DEFENCE_INNER)	{		bt_main_inner_defence_on->value(1);		bt_main_out_defence_on->value(0);		bt_main_defence_off->value(0);	}	else//2	{		bt_main_out_defence_on->value(1);		bt_main_inner_defence_on->value(0);		bt_main_defence_off->value(0);	}	}intlock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len){        struct flock    lock;        lock.l_type = type;        lock.l_start = offset;        lock.l_whence = whence;        lock.l_len = len;        return( fcntl(fd, cmd, &lock) );}/***************************************************            输入:int	    输出:int	    功能:窗口的事件处理程序****************************************************/int handle_event(int e){	if(fl_xevent->type==ClientMessage)	{		return 1;	}	return 1;}void connect_server_timer_cb(void*){	Fl::remove_timeout(connect_server_timer_cb);	bt_comm_center_connect->activate();	bt_comm_box_connect->activate();	if (message_form&&message_form->shown())	{		return ;	}	if ((!comm_window)||(comm_window&&!comm_window->shown()))		return ;	InformDlg ("与服务器的联络超时!","联络失败");}void connect_control_timer_cb(void*){	Fl::remove_timeout(connect_control_timer_cb);	bt_comm_box_connect->activate();	bt_comm_center_connect->activate();	if (message_form&&message_form->shown())	{		return ;	}	if ((!comm_window)||(comm_window&&!comm_window->shown()))		return ;	InformDlg ("与集中控制器的联络超时!","联络失败");}intsend_sos_alert(void ){	return 0;}/************************************************       输入:void       输出:void       功能:验证数据目录是否存在,如果不存在,则建立*************************************************/voidvalid_alert_data(void){	WordList WD;	char path[128];	char *pointer;	struct stat mystat;	bzero(path,128);	//检测设置目录	WD.MakeGeneric (SETUP_DIR, '/');	for (int i=1;i<WD.Count;i++)		{			pointer=WD.Get(i);			sprintf(path,"%s/%s",path,pointer);			if (stat (path, &mystat) != 0)				if (mkdir (path, 0700)!=0)				{					InformDlg ("创建设置文件目录失败!","错误信息");					exit(1);				}		}	//检测设置文件	bzero(path,128);	sprintf(path,"%s/%s",SETUP_DIR,"setup.ini");	if (stat (path, &mystat) != 0)		{			//删除出错帐号以前的帐号目录和数据目录			char tmp[256];			sprintf(tmp,"%s/%s/*","rm -fr ",SETUP_DIR);			system(tmp);			//设置默认值			PREFERENCES.Set_char_tree ("general/password/root","88888888");			PREFERENCES.Set_char_tree ("general/password/user","123456");			PREFERENCES.Set_char_tree ("general/password/sos","sos");			PREFERENCES.Set_char_tree ("general/setup/alert_center_ip","127.0.0.1");			//保存默认值			PREFERENCES.Save (path);		}	bzero(path,128);	WD.Clear();	//检测声音目录	WD.MakeGeneric (SOUND_DIR, '/');	for (int i=1;i<WD.Count;i++)		{			pointer=WD.Get(i);			sprintf(path,"%s/%s",path,pointer);			if (stat (path, &mystat) != 0)				if (mkdir (path, 0700)!=0)				{					InformDlg ("创建声音文件目录失败!","错误信息");					exit(1);				}		}	bzero(path,128);	sprintf(path,"%s/%s",SOUND_DIR,LOCAL_TYPE_COMMON);	if (stat (path, &mystat) != 0)	{		if(symlink("/Xapp/sound",path)!=0)		{			InformDlg ("创建符号连接失败!","错误信息");			exit(1);		}	}	bzero(path,128);	sprintf(path,"%s/%s",SOUND_DIR,DIAL_TYPE_COMMON);	if (stat (path, &mystat) != 0)	{		if(symlink("/Xapp/sound",path)!=0)		{   			InformDlg ("创建符号连接失败!","错误信息");			exit(1);		}	}}void construct_profile_list(){	//初始化结构	PROFILES.dev_head=NULL;	PROFILES.dev_tail=NULL;	PROFILES.dev_count=0;	PROFILES.current_user_class=-1;	PROFILES.alert_defence_stat=0;		//debug	if (strlen(PREFERENCES.Get_char_tree ("general/password/root"))==0)		PREFERENCES.Set_char_tree ("general/password/root","88888888");	if (strlen(PREFERENCES.Get_char_tree ("general/password/user"))==0)		PREFERENCES.Set_char_tree ("general/password/user","123456");	if (strlen(PREFERENCES.Get_char_tree ("general/password/sos"))==0)		PREFERENCES.Set_char_tree ("general/password/sos","sos");	if (strlen(PREFERENCES.Get_char_tree ("general/setup/alert_center_ip"))==0)		PREFERENCES.Set_char_tree ("general/setup/alert_center_ip","127.0.0.1");	//公共	strncpy(PROFILES.password_root,PREFERENCES.Get_char_tree ("general/password/root"),sizeof(PROFILES.password_root)-1);	PROFILES.password_root[sizeof(PROFILES.password_root)-1]='\0';	strncpy(PROFILES.password_user,PREFERENCES.Get_char_tree ("general/password/user"),sizeof(PROFILES.password_user)-1);	PROFILES.password_user[sizeof(PROFILES.password_user)-1]='\0';	strncpy(PROFILES.password_sos,PREFERENCES.Get_char_tree ("general/password/sos"),sizeof(PROFILES.password_sos)-1);	PROFILES.password_sos[sizeof(PROFILES.password_sos)-1]='\0';	strncpy(PROFILES.alert_center_ip,PREFERENCES.Get_char_tree ("general/setup/alert_center_ip"),sizeof(PROFILES.alert_center_ip)-1);	PROFILES.alert_center_ip[sizeof(PROFILES.alert_center_ip)-1]='\0';	//设备	Var *Vdevice = PREFERENCES.Get_collection ("device");	WordList *Wdevice = Vdevice->GatherNames();	for (int i=0;i<Wdevice->Count;++i)	{		alert_device_t	*temp_device=new alert_device_t;		temp_device->next=NULL;		temp_device->pre=NULL;		temp_device->device_stat=0;		temp_device->device_enable=0;		temp_device->device_self_alert=0;		temp_device->device_id=atoi(Wdevice->Get(i));		temp_device->device_module=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("device_module"));		temp_device->alert_type=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_type"));		temp_device->device_type=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("device_type"));		strncpy(temp_device->device_name,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("device_name"),sizeof(temp_device->device_name)-1);		temp_device->device_name[sizeof(temp_device->device_name)-1]='\0';		temp_device->device_cno=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("device_CNO"));		strncpy(temp_device->device_position,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("device_position"),sizeof(temp_device->device_position)-1);		temp_device->device_position[sizeof(temp_device->device_position)-1]='\0';		temp_device->alert_local_enable=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_local_enable"));		strncpy(temp_device->alert_local_sound,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_local_sound"),sizeof(temp_device->alert_local_sound)-1);		temp_device->alert_local_sound[sizeof(temp_device->alert_local_sound)-1]='\0';		temp_device->alert_local_endure_time=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_local_endure_time"));		strncpy(temp_device->alert_local_txt,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_local_txt"),sizeof(temp_device->alert_local_txt)-1);		temp_device->alert_local_txt[sizeof(temp_device->alert_local_txt)-1]='\0';		temp_device->alert_auto_dial_enable=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_auto_dial_enable"));		temp_device->alert_auto_dial_repeat=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_auto_dial_repeat"));		temp_device->alert_auto_dial_interval_time=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_auto_dial_interval_time"));		strncpy(temp_device->alert_auto_dial_number1,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_auto_dial_number1"),sizeof(temp_device->alert_auto_dial_number1)-1);		temp_device->alert_auto_dial_number1[sizeof(temp_device->alert_auto_dial_number1)-1]='\0';		strncpy(temp_device->alert_auto_dial_number2,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_auto_dial_number2"),sizeof(temp_device->alert_auto_dial_number2)-1);		temp_device->alert_auto_dial_number2[sizeof(temp_device->alert_auto_dial_number2)-1]='\0';		strncpy(temp_device->alert_auto_dial_number3,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_auto_dial_number3"),sizeof(temp_device->alert_auto_dial_number3)-1);		temp_device->alert_auto_dial_number3[sizeof(temp_device->alert_auto_dial_number3)-1]='\0';		strncpy(temp_device->alert_auto_dial_number4,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_auto_dial_number4"),sizeof(temp_device->alert_auto_dial_number4)-1);		temp_device->alert_auto_dial_number4[sizeof(temp_device->alert_auto_dial_number4)-1]='\0';		strncpy(temp_device->alert_auto_dial_sound,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_auto_dial_sound"),sizeof(temp_device->alert_auto_dial_sound)-1);		temp_device->alert_auto_dial_sound[sizeof(temp_device->alert_auto_dial_sound)-1]='\0';		temp_device->alert_inform_center_enable=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_inform_center_enable"));		temp_device->alert_inform_center_repeat=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_inform_center_repeat"));		temp_device->alert_inform_center_interval_time=atoi(PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_inform_center_interval_time"));		strncpy(temp_device->alert_inform_center_para1,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_inform_center_para1"),sizeof(temp_device->alert_inform_center_para1)-1);		temp_device->alert_inform_center_para1[sizeof(temp_device->alert_inform_center_para1)-1]='\0';		strncpy(temp_device->alert_inform_center_para2,PREFERENCES.Get_collection("device")->Get_collection(Wdevice->Get(i))->Get_char("alert_inform_center_para2"),sizeof(temp_device->alert_inform_center_para2)-1);		temp_device->alert_inform_center_para2[sizeof(temp_device->alert_inform_center_para2)-1]='\0';		if (!PROFILES.dev_count)		{			temp_device->next=NULL;			temp_device->pre=NULL;			PROFILES.dev_head=temp_device;			PROFILES.dev_tail=temp_device;			PROFILES.dev_count++;		}		else		{			temp_device->pre=PROFILES.dev_tail;			PROFILES.dev_tail->next=temp_device;			PROFILES.dev_tail=temp_device;			PROFILES.dev_count++;		}	}	delete (Wdevice);}voiddump_gui_data_to_core(alert_device_t *op_dev){		if (!op_dev) {printf("NULL\n");return;}		strncpy(op_dev->device_name,ipt_device_name->value(),sizeof(op_dev->device_name)-1);		op_dev->device_name[sizeof(op_dev->device_name)-1]='\0';		chopwhitespace(op_dev->device_name);		strncpy(op_dev->device_position,ipt_device_position->value(),sizeof(op_dev->device_position)-1);		op_dev->device_position[sizeof(op_dev->device_position)-1]='\0';		chopwhitespace(op_dev->device_position);				strncpy(op_dev->alert_local_txt,wcbo_local_setup_message->value(),sizeof(op_dev->alert_local_txt)-1);		op_dev->alert_local_txt[sizeof(op_dev->alert_local_txt)-1]='\0';		chopwhitespace(op_dev->alert_local_txt);			strncpy(op_dev->alert_auto_dial_number1,wcbo_auto_dial_setup_tel1->value(),sizeof(op_dev->alert_auto_dial_number1)-1);		op_dev->alert_auto_dial_number1[sizeof(op_dev->alert_auto_dial_number1)-1]='\0';		chopwhitespace(op_dev->alert_auto_dial_number1);					strncpy(op_dev->alert_auto_dial_number2,wcbo_auto_dial_setup_tel2->value(),sizeof(op_dev->alert_auto_dial_number2)-1);		op_dev->alert_auto_dial_number2[sizeof(op_dev->alert_auto_dial_number1)-1]='\0';		chopwhitespace(op_dev->alert_auto_dial_number2);		strncpy(op_dev->alert_auto_dial_number3,wcbo_auto_dial_setup_tel3->value(),sizeof(op_dev->alert_auto_dial_number3)-1);		op_dev->alert_auto_dial_number3[sizeof(op_dev->alert_auto_dial_number3)-1]='\0';		chopwhitespace(op_dev->alert_auto_dial_number3);		strncpy(op_dev->alert_auto_dial_number4,wcbo_auto_dial_setup_tel4->value(),sizeof(op_dev->alert_auto_dial_number4)-1);		op_dev->alert_auto_dial_number4[sizeof(op_dev->alert_auto_dial_number4)-1]='\0';

⌨️ 快捷键说明

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