Beispiel #1
0
void cmd_uart_check(void)
{
	u8 rx_buff_tmp[40];

	
    if(rxd1_buff_cFlag)
    {
        rxd1_buff_cFlag = 0;

		for(u8 i=0;i<40;i++)
			rx_buff_tmp[i] = in_com_buff[i];

		
		for(u8 i=0;i<40;i++)
			in_com_buff[i] = 0;


        if(rx_buff_tmp[0] == 0xF1 && rx_buff_tmp[1] == 0xf1)
        {
           u8 type,data;
             type=rx_buff_tmp[2];
            data=rx_buff_tmp[4];
     
        switch(type)
        {
          case 0x02:
        if(data)
        {    device_work_data.para_type.device_power_state = 1;
            //airclean_power_onoff(1);
		}
        else
        {    device_work_data.para_type.device_power_state = 0;
            //airclean_power_onoff(0);
        }
        break;
         case 0x03:
           if(data==1||data==2)
            device_work_data.para_type.device_mode = data;
         
        break;
         case 0x04:
        if(data)
            device_work_data.para_type.high_pressur_state = 1;
        else
            device_work_data.para_type.high_pressur_state = 0;

        
        break;
          case 0x05:
        if(data)
            device_work_data.para_type.pht_work_state = 1;
        else
            device_work_data.para_type.pht_work_state = 0;

        //ac_pht_set(data);
 
        break;
         case 0x06:
        if((data<=0x0c)&&(data!=0))
            device_work_data.para_type.timing_state = data;
        else
            device_work_data.para_type.timing_state = 0;

        
        break;
         case 0x07:
        if(data<=3)
            device_work_data.para_type.wind_speed_state = data;
        //set_dc_motor_speed(data);

		//ac_ac_motor_set(data);
        break;

    default:
	break;

    }

     device_work_mode_check();  //收到主板按键显示命令
    			//delay_ms(50);
			//Ht1621Display(); 

            if(rx_buff_f1 == 0)
            {

		if(power_key_state == 0x01)                                  //电源开关变化发送数据
                {//power on
                    power_key_state = 0xff;
                    return_device_power_state_change(2,1);
                     time_tick_cnt1=0;
                }
                else if(power_key_state == 0x00)
                {//power off
                    power_key_state = 0xff;
                    return_device_power_state_change(2,0);
                    time_tick_cnt1=0;
                }

           

               else  if(mode_key_state == 0x01)                         //智能/手动/定时按键状态发送数据
                {//mode on
                    mode_key_state = 0xff;
                    return_device_power_state_change(3,1);
                    time_tick_cnt1=0;
                }
                else if(mode_key_state == 0x02)
                {//mode off
                    mode_key_state = 0xff;
                    return_device_power_state_change(3,2);
                    time_tick_cnt1=0;
                }


               else  if(PHT_key_state == 0x01)                           // 光氢按键按键状态发送数据
                {//mode on
                    PHT_key_state = 0xff;
                    return_device_power_state_change(5,1);
                    time_tick_cnt1=0;
                }
                else if(PHT_key_state == 0x00)
                {//mode off
                    PHT_key_state = 0xff;
                    return_device_power_state_change(5,0);
                    time_tick_cnt1=0;
                }
 
               else  if(workspeed_key_state == 0x01)                           //风速按键按键状态发送数据
                {//mode on
                    workspeed_key_state = 0xff;
                    return_device_power_state_change(7,1);
                    time_tick_cnt1=0;
                }
                
                else if(workspeed_key_state == 0x02)
                {//mode off
                    workspeed_key_state = 0xff;
                    return_device_power_state_change(7,2);
                    time_tick_cnt1=0;
                }
		   
                else if(workspeed_key_state == 0x03)
                {//mode off
                    workspeed_key_state = 0xff;
                    return_device_power_state_change(7,3);
                    time_tick_cnt1=0;
                }


			   
							 
               else  if(ESD_key_state == 0x01)                              //静电按键按键状态发送数据
                {//mode on
                    ESD_key_state = 0xff;
                    return_device_power_state_change(4,1);
                    time_tick_cnt1=0;
                }
                else if(ESD_key_state == 0x00)
                {//mode off
                    ESD_key_state = 0xff;
                    return_device_power_state_change(4,0);
                    time_tick_cnt1=0;
                }

		
               else if(time_tick_cnt1> TICKS_PER_SECOND1)
               	{
                return_device_power_state_change(1,0);
		time_tick_cnt1=0;
               	}

            }
             

        }


         if(rx_buff_tmp[0] == 0xF2 && rx_buff_tmp[1] == 0xf2 )
        {
		//rx_buff_f1 = 1;
            device_work_data.para_type.house1_co2 = (u16)rx_buff_tmp[12]<<8;
			device_work_data.para_type.house1_co2 += (u16)rx_buff_tmp[13];
			
			device_work_data.para_type.house1_pm2_5 = (u16)rx_buff_tmp[10]<<8;
			device_work_data.para_type.house1_pm2_5 +=(u16)rx_buff_tmp[11];


            device_work_data.para_type.house2_co2 = (u16)rx_buff_tmp[16]<<8;
			device_work_data.para_type.house2_co2	+= (u16)rx_buff_tmp[17];
			
			device_work_data.para_type.house2_pm2_5 = (u16)rx_buff_tmp[14]<<8;
			device_work_data.para_type.house2_pm2_5	+= (u16)rx_buff_tmp[15];


            device_work_data.para_type.house3_co2 = (u16)rx_buff_tmp[20]<<8;
			device_work_data.para_type.house3_co2	+=(u16)rx_buff_tmp[21];
			
			device_work_data.para_type.house3_pm2_5 = (u16)rx_buff_tmp[18]<<8;
			device_work_data.para_type.house3_pm2_5+= (u16)rx_buff_tmp[19];

			

            device_work_data.para_type.house4_co2 = (u16)rx_buff_tmp[24]<<8;
			device_work_data.para_type.house4_co2+=(u16)rx_buff_tmp[25];
			
			device_work_data.para_type.house4_pm2_5 = (u16)rx_buff_tmp[22]<<8;
			device_work_data.para_type.house4_pm2_5+=(u16)rx_buff_tmp[23];

			

            device_work_data.para_type.house5_co2 = (u16)rx_buff_tmp[28]<<8;
			device_work_data.para_type.house5_co2+=(u16)rx_buff_tmp[29];
			
			device_work_data.para_type.house5_pm2_5 = (u16)rx_buff_tmp[26]<<8;
			device_work_data.para_type.house5_pm2_5+=(u16)rx_buff_tmp[27];

			device_work_data.para_type.fault_state = rx_buff_tmp[30];

			
                	 //ljy start 160303 
	     		device_work_data.para_type.device_power_state = rx_buff_tmp[4];
                     device_work_data.para_type.device_mode = rx_buff_tmp[5];
                      device_work_data.para_type.wind_speed_state = rx_buff_tmp[6];
                      device_work_data.para_type.high_pressur_state = rx_buff_tmp[7];
			device_work_data.para_type.pht_work_state = rx_buff_tmp[8];
                  //ljy end 160303
                  

#if 0
// 以下部分为收到主板关机命令后,将关闭显示屏,在主函数中仍然需要检测电源按键
//如果 device_work_data.para_type.device_power_state 为0的时候,屏幕将关闭,直到收到 device_work_data.para_type.device_power_state为1才开启屏幕
//或者直到按显示板的电源键才开开启显示
			if(device_power_state_pre==0xff || device_power_state_pre!= device_work_data.para_type.device_power_state)
			{
				if(device_work_data.para_type.device_power_state == 0)
				{
				
					onoff_device_set(OFF);

				}
				else
				{
					onoff_device_set(ON);
				}

				device_power_state_pre = device_work_data.para_type.device_power_state;
			}
#endif

			device_work_mode_check();  //收到主板按键显示命令
			fault_check();                          //收到主板故障代码命令
                    
			
     
        }

    }

}
Beispiel #2
0
/*
** Write all of the buffered data to the pipe now.
**
** We can of course call this in order to flush out query code,
** but it is more often called by the other routines when the
** buffer becomes full.
*/
int printer_flush(void)
	{
	const char *function = "printer_flush";
	int total, remain;
	char *wptr;			/* pointer to current position in buffer */
	int rval;
	fd_set wfds, rfds;	/* file descriptor sets for select() */
	struct timeval sleep_time;
	int readyfds;
	int setsize;		/* first parameter for select() */

	DODEBUG_INTERFACE_GRITTY(("%s()", function));

	/* Do control-D counting stuff? */
	if(printer.Jobbreak == JOBBREAK_CONTROL_D && printer.Feedback)
		{
		char *p;

		remain = BUFSIZE - wbuf_space;
		wptr = wbuf;

		/* Count the number of control-Ds in the block we are sending
		   adding them to the running total of unacknowledged control-Ds. */
		while(remain && (p = (char*)memchr(wptr, 0x04, remain)))
			{
			control_d_count++;
			remain -= (p - wptr + 1);
			wptr = p + 1;
			}
		}

	total = remain = (BUFSIZE - wbuf_space);	/* compute bytes now in buffer */
	wptr = wbuf;								/* start of buffer */

	/* Compute the size of the select() file
	   descriptor set. */
	setsize = intstdin > intstdout ? intstdin : intstdout;
	setsize++;

	/* We will continue to call write() until our buffer is empty. */
	while(remain > 0)
		{
		/* Track stalls in this block. */
		writemon_start("WRITE");

		/* How long should we sleep?  Note that we will break out of
		   this loop when it is time to do a write(). */
		while(writemon_sleep_time(&sleep_time, 0))
			{
			FD_ZERO(&rfds);
			FD_ZERO(&wfds);
			FD_SET(intstdout, &rfds);
			FD_SET(intstdin, &wfds);

			fault_check();

			if((readyfds = select(setsize, &rfds, &wfds, NULL, &sleep_time)) < 0)
				{
				if(errno == EINTR)
					{
					/*fault_check();*/
					continue;
					}
				fatal(EXIT_PRNERR, "%s(): select() failed, errno=%d (%s)", function, errno, gu_strerror(errno));
				}

			if(readyfds > 0)
				{
				/* If there is data to read from the printer, */
				if(FD_ISSET(intstdout, &rfds))
					{
					fault_check();
					feedback_reader();
					}

				/* If space to write to pipe, drop out to write() code. */
				else if(FD_ISSET(intstdin, &wfds))
					{
					break;
					}

				/* If it is anything else, something is very wrong. */
				else
					{
					fatal(EXIT_PRNERR_NORETRY, "%s(): assertion failed", function);
					}
				}
			}

		/* Call write(), restarting it if it is interupted.
		   by a signal such as SIGALRM or SIGCHLD. */
		while((rval = write(intstdin, wptr, remain)) < 0)
			{
			/* Handle interuption by signals. */
			if(errno == EINTR)
				{
				DODEBUG_INTERFACE_GRITTY(("%s(): write() interupted", function));
				fault_check();
				DODEBUG_INTERFACE_GRITTY(("%s(): restarting write()", function));
				continue;
				}

			/* If wasn't really ready, */
			if(errno == EAGAIN)
				continue;

			/* If we can't write because the pipe is broken, that means that
			   the interface (or possible a RIP) died.  Wait 10 seconds to
			   allow time for SIGCHLD to be received.  When it is,
			   fault_check() will process the last of the output from the
			   interface or RIP and terminate pprdrv. */
			if(errno == EPIPE)
				{
				int x;
				DODEBUG_INTERFACE(("Pipe write error, Waiting 10 seconds for SIGCHLD"));
				for(x=0; x<10; x++)
					{
					fault_check();
					sleep(1);
					}
				fatal(EXIT_PRNERR, "%s(): unexplained EPIPE", function);
				}

			fatal(EXIT_PRNERR, "%s(): write failed, errno=%d (%s)", function, errno, gu_strerror(errno));
			}

		DODEBUG_INTERFACE_GRITTY(("%s(): wrote %d bytes: \"%.*s\"", function, rval, rval, wptr));

		remain -= rval; /* reduce length left to write */
		wptr += rval;	/* move pointer forward */

		/* If this isn't a banner page, update the "Progress:"
		   line in the queue file. */
		if(doing_primary_job)
			progress_bytes_sent(rval);

		/* If we were stalled, we aren't anymore.  Let writemon know so that if it
		   told people we were stalled, it can tell them the condition is cleared. */
		writemon_unstalled("WRITE");

		/* If we wanted to throttle the bandwidth consumption, we could pause here. */
		#if 0
		usleep(25000);
		#endif
		}

	bptr = wbuf;
	wbuf_space = BUFSIZE;

	DODEBUG_INTERFACE_GRITTY(("%s(): done, %d bytes total", function, total));

	return total;
	} /* end of printer_flush() */