Beispiel #1
0
/**
用于检测yeelink上的指定开关的状态,从而进行对灯的操纵。
**/
void yeelink_ser(){
	while(1){
		pthread_mutex_lock(&mutex);
		if(NULL==s_info){	//启动后第一次检测
			s_info=get_switch_info(device_id,switch_id);
			if(NULL==s_info){
				pthread_mutex_unlock(&mutex);
				continue;
			}else{
				change_light_state_1(s_info,yeelight);   //change_light_state(s_info,yeelight);
			}

		}
		else{	
			struct switch_info *s_i=get_switch_info(device_id,switch_id);	//获取最新的开关信息
			if(NULL==s_i){
				pthread_mutex_unlock(&mutex);
				continue;
			}else if(strcmp(s_i->timestamp,s_info->timestamp)!=0){	//开关状态发生变化
				change_light_state_1(s_i,yeelight);                 //change_light_state(s_i,yeelight);
			}
			
			free(s_info->timestamp);
			free(s_info);
			s_info=s_i;
			
		}
		pthread_mutex_unlock(&mutex);
		usleep(800000); 
	}
};
Beispiel #2
0
void vpr_pack(INP t_vpr_setup vpr_setup, INP t_arch arch) {
	clock_t begin, end;
	float inter_cluster_delay = UNDEFINED, Tdel_opin_switch, Tdel_wire_switch,
			Tdel_wtoi_switch, R_opin_switch, R_wire_switch, R_wtoi_switch,
			Cout_opin_switch, Cout_wire_switch, Cout_wtoi_switch,
			opin_switch_del, wire_switch_del, wtoi_switch_del, Rmetal, Cmetal,
			first_wire_seg_delay, second_wire_seg_delay;
	begin = clock();
	vpr_printf(TIO_MESSAGE_INFO, "Initialize packing.\n");

	/* If needed, estimate inter-cluster delay. Assume the average routing hop goes out of 
	 a block through an opin switch to a length-4 wire, then through a wire switch to another
	 length-4 wire, then through a wire-to-ipin-switch into another block. */

	if (vpr_setup.PackerOpts.timing_driven
			&& vpr_setup.PackerOpts.auto_compute_inter_cluster_net_delay) {
		opin_switch_del = get_switch_info(arch.Segments[0].opin_switch,
				Tdel_opin_switch, R_opin_switch, Cout_opin_switch);
		wire_switch_del = get_switch_info(arch.Segments[0].wire_switch,
				Tdel_wire_switch, R_wire_switch, Cout_wire_switch);
		wtoi_switch_del = get_switch_info(
				vpr_setup.RoutingArch.wire_to_ipin_switch, Tdel_wtoi_switch,
				R_wtoi_switch, Cout_wtoi_switch); /* wire-to-ipin switch */
		Rmetal = arch.Segments[0].Rmetal;
		Cmetal = arch.Segments[0].Cmetal;

		/* The delay of a wire with its driving switch is the switch delay plus the 
		 product of the equivalent resistance and capacitance experienced by the wire. */

#define WIRE_SEGMENT_LENGTH 4
		first_wire_seg_delay = opin_switch_del
				+ (R_opin_switch + Rmetal * WIRE_SEGMENT_LENGTH / 2)
						* (Cout_opin_switch + Cmetal * WIRE_SEGMENT_LENGTH);
		second_wire_seg_delay = wire_switch_del
				+ (R_wire_switch + Rmetal * WIRE_SEGMENT_LENGTH / 2)
						* (Cout_wire_switch + Cmetal * WIRE_SEGMENT_LENGTH);
		inter_cluster_delay = 4
				* (first_wire_seg_delay + second_wire_seg_delay
						+ wtoi_switch_del); /* multiply by 4 to get a more conservative estimate */
	}

	try_pack(&vpr_setup.PackerOpts, &arch, vpr_setup.user_models,
			vpr_setup.library_models, vpr_setup.Timing, inter_cluster_delay);
	end = clock();
#ifdef CLOCKS_PER_SEC
	vpr_printf(TIO_MESSAGE_INFO, "Packing took %g seconds.\n",
			(float) (end - begin) / CLOCKS_PER_SEC);
	vpr_printf(TIO_MESSAGE_INFO, "Packing completed.\n");
#else
	vpr_printf(TIO_MESSAGE_INFO, "Packing took %g seconds.\n", (float)(end - begin) / CLK_PER_SEC);
#endif
	fflush(stdout);
}
Beispiel #3
0
/*
检测灯的状态,将灯的状态映射到yeelink的开关传感器
*/
void yeelight_ser(){
	int state;
	char* r;
	struct switch_info *s_i;
	
	while(1){
		sleep(1);
		pthread_mutex_lock(&mutex);
		state=check_light_state_1(yeelight);	//检测灯的状态   check_light_state(yeelight);
		s_i=get_switch_info(device_id,switch_id);	//获取最新的开关信息
		
		/*
			当灯的状态和当前yeelink的开关状态一致的时候不修改yeelink上的开关,
			目的是尽量减少状态的同步操作,防止冲突。
		*/
		if(s_i==NULL||
			state==ERROR||
			s_i->state==state||
			strcmp(s_i->timestamp,s_info->timestamp))	//如果最后一次执行或同步到的时间戳和开关当前的时间戳不同
		{
			if(NULL!=s_i){
				free(s_i->timestamp);
				free(s_i);
			}
			pthread_mutex_unlock(&mutex);
			continue;
		}
		
		r=change_switch_state(device_id,switch_id,state);	//同步状态
		free(r);
		free(s_i->timestamp);
		free(s_i);

		s_i=get_switch_info(device_id,switch_id);	//再次获取开关状态
		if(NULL!=s_i){
			s_info=s_i;
		}

		pthread_mutex_unlock(&mutex);
	}
};