Ejemplo n.º 1
0
void __attribute__((noreturn)) serial_recv_task(struct vcom * vcom)
{
	struct serial_dev * serial = vcom->serial;
	struct usb_cdc_class * cdc = vcom->cdc;
	uint8_t buf[VCOM_BUF_SIZE];
	int len;

	DCC_LOG1(LOG_TRACE, "[%d] started.", thinkos_thread_self());

	/* wait for line configuration */
	usb_cdc_acm_lc_wait(cdc);

	/* enable serial */
	serial_enable(serial);

	for (;;) {
		len = serial_read(serial, buf, VCOM_BUF_SIZE, 1000);
		if (len > 0) {
//			dbg_write(buf, len);
			if (vcom->mode == VCOM_MODE_CONVERTER) {
				led_flash(LED_AMBER, 50);
				usb_cdc_write(cdc, buf, len);
			}
			if (vcom->mode == VCOM_MODE_SDU_TRACE) {
				led_flash(LED_AMBER, 50);
				sdu_decode(buf, len);
			}
#if RAW_TRACE
			if (len == 1)
				DCC_LOG1(LOG_TRACE, "RX: %02x", buf[0]);
			else if (len == 2)
				DCC_LOG2(LOG_TRACE, "RX: %02x %02x", 
						 buf[0], buf[1]);
			else if (len == 3)
				DCC_LOG3(LOG_TRACE, "RX: %02x %02x %02x", 
						 buf[0], buf[1], buf[2]);
			else if (len == 4)
				DCC_LOG4(LOG_TRACE, "RX: %02x %02x %02x %02x", 
						 buf[0], buf[1], buf[2], buf[3]);
			else if (len == 5)
				DCC_LOG5(LOG_TRACE, "RX: %02x %02x %02x %02x %02x", 
						 buf[0], buf[1], buf[2], buf[3], buf[4]);
			else if (len == 6)
				DCC_LOG6(LOG_TRACE, "RX: %02x %02x %02x %02x %02x %02x", 
						 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
			else if (len == 7)
				DCC_LOG7(LOG_TRACE, "RX: %02x %02x %02x %02x %02x %02x %02x ",
						 buf[0], buf[1], buf[2], buf[3], 
						 buf[4], buf[5], buf[6]);
			else
				DCC_LOG8(LOG_TRACE, "RX: %02x %02x %02x %02x %02x %02x "
						 "%02x %02x ...", buf[0], buf[1], buf[2], buf[3], 
						 buf[4], buf[5], buf[6], buf[7]);
#endif
#if SDU_TRACE
			RX(buf, len);
#endif
		}
	}
}
Ejemplo n.º 2
0
int main(void)
{

	unsigned short LSensor;
	unsigned short RSensor;

	const unsigned short MainCycle = 60;
	Init(MainCycle);

	 led_flash(3,100);

	      while(1){
	        LSensor=ADRead(0);
	        RSensor=ADRead(1);
	        if (LSensor >=256 && RSensor >=256){//両センサ=黒=seisi
	       	       	          GD_LED;
	       	       	          qstop(100);
	       	       	          break;
	       	       	        }
	        if(LSensor> 256){//左カーブ
	          D_LED;
	          left(100);
	        }
	        if(RSensor>256){//右カーブ
	          G_LED;
	          right(100);
	        }
	        if (LSensor <=256 && RSensor <=256){//両センサ=白=直進
	          OFF_LED;
	          forword(100);
	        }


	     }//while
}//main
Ejemplo n.º 3
0
Archivo: main.c Proyecto: eleqian/WiDSO
int main(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

    // disable JTAG,use SWD only
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

    timebase_init();
    led_init();
    vcp_init();
    
    // for debug use
    if (!key_is_pressed()) {
        USB_HW_Config();
        USB_Init();
    }

    led_flash(1000, 100, 0);

    while (1) {
        led_update();
        if (bDeviceState == CONFIGURED)
        {
            if (key_is_pressed()) {
                GPIO_ResetBits(GPIOB, GPIO_Pin_2);
                GPIO_ResetBits(GPIOB, GPIO_Pin_1);
                while (key_is_pressed());
                GPIO_SetBits(GPIOB, GPIO_Pin_2);
            }
        }
    }
}
Ejemplo n.º 4
0
static void processButton(s_button* button, bool isPressed)
{
	button->pressed <<= 1;
	if(isPressed)
	{
		button->pressed |= 1;
		if(button->pressed >= BTN_IS_PRESSED)
		{
			button->pressedTime = millis(); // this should only be set once!		

			if(!button->funcDone && button->onPress != NULL && button->onPress())
			{
				button->funcDone = true;
				buzzer_buzz(BTN_PRESS_TONETIME, BTN_PRESS_TONE, VOL_UI);
				led_flash(LED_GREEN, LED_FLASH_FAST, LED_BRIGHTNESS_MAX);
			}
		}
	}
	else
	{
		button->pressed <<= 1;
		if(button->pressed <= BTN_NOT_PRESSED)
			button->funcDone = false;
	}	
}
Ejemplo n.º 5
0
static ssize_t diag_led_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
	struct led_t *led = PDE_DATA(file_inode(file));
	char cmd[5];
	size_t len;
	int p;

	len = min(count, sizeof(cmd) - 1);
	if (copy_from_user(cmd, buf, len))
		return -EFAULT;

	cmd[len] = 0;

	p = (led->polarity == NORMAL ? 0 : 1);
	if (cmd[0] == 'f') {
		led->flash = 1;
		led_flash(0);
	} else {
		led->flash = 0;
		if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_EXTIF) {
			led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
			set_led_extif(led);
		} else if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_SHIFT) {
			led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
			set_led_shift(led);
		} else {
			bcm47xx_gpio_outen(led->gpio, led->gpio);
			bcm47xx_gpio_control(led->gpio, 0);
			bcm47xx_gpio_out(led->gpio, ((p ^ (cmd[0] == '1')) ? led->gpio : 0));
		}
	}
	return count;
}
Ejemplo n.º 6
0
Archivo: utils.c Proyecto: AEUG/400plus
void beep() {
	if (DPData.beep) {
		eventproc_RiseEvent("RequestBuzzer");
		SleepTask(EVENT_WAIT);
	}

	led_flash(BEEP_LED_LENGTH);
}
Ejemplo n.º 7
0
static void fanfare( uint8_t n, int millis ) 
{
    for( uint8_t i=0; i<n; i++ ) {
        led_flash();
        for( int j=0; j<millis; j++) {
            _delay_ms(1); // why does _delay_ms(millis) load extra 900 bytes?
        }
    }
}
Ejemplo n.º 8
0
void __attribute__((noreturn)) usb_recv_task(struct vcom * vcom)
{
	struct serial_dev * serial = vcom->serial;
	usb_cdc_class_t * cdc = vcom->cdc;
	uint8_t buf[VCOM_BUF_SIZE];
	int len;

	DCC_LOG1(LOG_TRACE, "[%d] started.", thinkos_thread_self());
	DCC_LOG2(LOG_TRACE, "vcom->%p, cdc->%p", vcom, cdc);

	for (;;) {
		len = usb_cdc_read(cdc, buf, VCOM_BUF_SIZE, 1000);
		if (vcom->mode == VCOM_MODE_CONVERTER) {
			if (len > 0) {
				led_flash(LED_RED, 50);
				serial_write(serial, buf, len);
#if RAW_TRACE
				if (len == 1)
					DCC_LOG1(LOG_TRACE, "TX: %02x", buf[0]);
				else if (len == 2)
					DCC_LOG2(LOG_TRACE, "TX: %02x %02x", 
							 buf[0], buf[1]);
				else if (len == 3)
					DCC_LOG3(LOG_TRACE, "TX: %02x %02x %02x", 
							 buf[0], buf[1], buf[2]);
				else if (len == 4)
					DCC_LOG4(LOG_TRACE, "TX: %02x %02x %02x %02x", 
							 buf[0], buf[1], buf[2], buf[3]);
				else if (len == 5)
					DCC_LOG5(LOG_TRACE, "TX: %02x %02x %02x %02x %02x", 
							 buf[0], buf[1], buf[2], buf[3], buf[4]);
				else if (len == 6)
					DCC_LOG6(LOG_TRACE, "TX: %02x %02x %02x %02x %02x %02x", 
							 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
				else if (len == 7)
					DCC_LOG7(LOG_TRACE, "TX: %02x %02x %02x %02x %02x %02x %02x ",
							 buf[0], buf[1], buf[2], buf[3], 
							 buf[4], buf[5], buf[6]);
				else
					DCC_LOG8(LOG_TRACE, "TX: %02x %02x %02x %02x %02x %02x "
							 "%02x %02x ...", buf[0], buf[1], buf[2], buf[3], 
							 buf[4], buf[5], buf[6], buf[7]);
#endif
#if SDU_TRACE
				TX(buf, len);
#endif
				//			dbg_write(buf, len);
			}
		} else {
			// forward to service input
			vcom_service_input(vcom, buf, len);
		}
	}
}
Ejemplo n.º 9
0
Archivo: dps.c Proyecto: miaofng/ulp
void main()
{
	sys_init();
	dps_init();
        led_flash(LED_RED);
	lv_enable(0);
	printf("dps v1.0, SW: %s %s\n\r", __DATE__, __TIME__);
	while(1){
		sys_update();
	}
}
Ejemplo n.º 10
0
Archivo: o2pt.c Proyecto: miaofng/ulp
int main(void)
{
	sys_init();
	o2pt_init();
	led_flash(LED_GREEN);
	printf("o2pt v1.0, build: %s %s\n\r", __DATE__, __TIME__);

	while(1) {
		sys_update();
		o2pt_update();
	}
}
Ejemplo n.º 11
0
int main(void) {

	mcu_setup();
	spi_setup();

	while(1) {
		volatile int i = 5000;
		while(i)
			i--;
		if(0xAA == spi_tx_lpm_iu(0xAA)) {
			led_flash();
		}
	}
}
Ejemplo n.º 12
0
static display_t draw()
{
	static bool invert;
	static millis_t lastStrobe;

	if(strobe)
	{
		millis_t now = millis();
		if(now - lastStrobe >= strobe)
		{
			lastStrobe = now;
			invert = !invert;
			oled_setInvert(invert);
			led_flash(invert ? LED_GREEN : LED_RED, 20, 255);
		}
		return DISPLAY_BUSY;
	}

	oled_setInvert(true);
	led_flash(LED_GREEN, 100, 255);
	led_flash(LED_RED, 100, 255);

	return DISPLAY_DONE;
}
Ejemplo n.º 13
0
void device_led_default(struct ss_device * dev, uint32_t ctl)
{
	if (dev->ledno) {
		DCC_LOG2(LOG_INFO, "dev=%d ctl=0x%x", dev->addr, ctl);

		/* Poll LED state */
		if ((ctl & 0x5) == 0x5) {
			led_flash(dev->ledno - 1, 64);
		} else if ((ctl & 0x4) == 0x4) {
			led_on(dev->ledno - 1);
		} else
			led_off(dev->ledno - 1);
	}

	if ((ctl & 0x4) == 0x4)
		dev->led = 1;
	else
		dev->led = 0;
}
Ejemplo n.º 14
0
/**
 * Gyroscope presission automatic bias null calibration
 */
void adis_recalibrate_gyros( void ) {
	unsigned char tmp[2]; // Temporary variable
	unsigned char addr[2]; // Address to TEMP_OUT
	addr[0] = 0xbe; // This is the address for restoring factory calibration
	addr[1] = 0x10; // This is the data portion, wich the IMU ignores when readiing
	memcpy(tmp,addr,2); // Copy address to temporay variable
	spi0_send(tmp,1,ADIS_CS); // Send data
	printf("The gyros are being recalibrated.\n\rDON'T TOUCH THE IMU! FFS\n\r"); // Print the recieved data
	led_flash(0);
	led_set(0);
	for(int i = 30; i>0 ; i--){
		printf("%i second(s) left\n\r",i);
		vTaskDelay(1000/portTICK_RATE_MS);
	}
	led_clear(0);
	led_set(1);
	vTaskDelay(500/portTICK_RATE_MS);
	led_clear(1);
	printf("The gyros have been recalibrated.\n\r"); // Print the recieved data
}
Ejemplo n.º 15
0
/*****************************************************************************
 Function    : LOS_EvbUartInit
 Description : enable the device on the dev baord
 Input       : None
 Output      : None
 Return      : None
 *****************************************************************************/
void LOS_EvbUartInit(void)
{
#ifdef GD32F150R8   
    /* initialize the LEDs */
    led_init();
    
    /* configure systick */
    //systick_config();
    
    /* flash the LEDs for 1 time */
    led_flash(1);
    
    /* configure EVAL_COM2 */
    gd_eval_COMinit(EVAL_COM1);
    
    /* configure TAMPER key */
    gd_eval_keyinit(KEY_WAKEUP, KEY_MODE_GPIO);  
    
#endif
    return;
}
Ejemplo n.º 16
0
void start_armboot()
{
    led_flash();
    uart_init();
    putstr("Lab 4:\r\n");
    putstr("Hello World!\r\n");
    

    while(1)
    {
        char ch;
        print_menu();
        ch = getchar();
        switch(ch)
        {
            case '1':
                NOR_check_id();
                break;
            case '2':
                putstr("Which block do you want to erase?(0..9)?\r\n");
                ch = getchar();
		if(ch == '0')
		    putstr("Do you want to erase me? y/n\r\n");
		    ch = getchar();
		    if(ch == 'y'||ch == 'Y')
			NOR_erase_block(0);
		else
		    NOR_erase_block(ch - '0');
                break;
	    case '3':
		putstr("Here is a nand demo\r\n");
                nand_demo();
		break;
        }
    }
}
Ejemplo n.º 17
0
int main(void)
{
	init();

	sei();

	if(wdt_wasReset())
		resetError();

	buzzer_buzz(200, TONE_4KHZ, VOL_UI);
	led_flash(LED_GREEN, 50, 255);

	watchface_setFace(watchface_normal);
	watchface_loadFace();
/*
	while(1)
	{
		buzzer_buzzb(200,TONE_5KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_4KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_2_5KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_2KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_4KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_5KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_2_5KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_2KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_3_5KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_4KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_3KHZ, VOL_UI);
		buzzer_buzzb(250,TONE_2KHZ, VOL_UI);
		buzzer_buzzb(250,TONE_2KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_4KHZ, VOL_UI);
		buzzer_buzzb(200,TONE_4KHZ, VOL_UI);
	}
*/
	while(1)
	{
		bool timeUpt = time_update();
		if(pwrmgr_userActive())
		{
			if(timeUpt && timeData.secs == 0)
				battery_update();
			buttons_update();
		}

		buzzer_update();
		led_update();
		stopwatch_update();

		if(pwrmgr_userActive())
		{
			alarm_update();
			display_update();
		}

//		freeRAM();

		wdt_update();

		pwrmgr_update();
	}
}
Ejemplo n.º 18
0
int main( void )
{    
    _delay_ms(100);
    // set clock speed
    CLKPR = _BV( CLKPCE );                 // enable clock prescale change
    CLKPR = 0;                             // full speed (8MHz);

#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || \
      defined(__AVR_ATtiny85__)

    // set up periodic timer for state machine ('script_tick')
    TCCR0B = _BV( CS02 ) | _BV(CS00); // start timer, prescale CLK/1024
    TIFR   = _BV( TOV0 );          // clear interrupt flag
    TIMSK  = _BV( TOIE0 );         // enable overflow interrupt

    // set up output pins   
    PORTB = INPI2C_MASK;          // turn on pullups 
    DDRB  = LED_MASK;             // set LED port pins to output

#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || \
      defined(__AVR_ATtiny84__)

    // set up periodic timer for state machine ('script_tick')
    //TCCR0B = _BV( CS02 ) | _BV(CS00); // start timer, prescale CLK/1024
    //TIFR0  = _BV( TOV0 );          // clear interrupt flag
    //TIMSK0 = _BV( TOIE0 );         // enable overflow interrupt
    // set up output pins   
    PORTA = INPI2C_MASK;          // turn on pullups 
    DDRA  = 0xFF; //LEDA_MASK;            // set LED port pins to output
    DDRB  = 0xFF; //LEDB_MASK;            // set LED port pins to output
    
#endif
    
    fanfare( 3, 300 );

#if 0
    // test for ATtiny44/84 MaxM
    fanfare( 3, 300 );

    IRsend_enableIROut();

    while( 1 ) {
        _delay_ms(10);
        IRsend_iroff();
        _delay_ms(10);
        IRsend_iron();
    }

    /*
    uint8_t f = OCR1B;
    while( 1 ) {
        _delay_ms(10);
        f++; 
        if( f== OCR1A ) f=0;  // OCR1A == period
        OCR1B = f;            // OCR1B == duty cycle (0-OCR1A)
    }
    */
#endif

#if 0
    // test timing of script_tick
    _delay_ms(2000);
    sei();
    _delay_ms(500);  // this should cause script_tick to equal 15
    uint8_t j = script_tick;
    for( int i=0; i<j; i++ ) {
        led_flash();
        _delay_ms(300);
    }
#endif

    //////  begin normal startup

    uint8_t boot_mode      = eeprom_read_byte( &ee_boot_mode );
    uint8_t boot_script_id = eeprom_read_byte( &ee_boot_script_id );
    uint8_t boot_reps      = eeprom_read_byte( &ee_boot_reps );
    //uint8_t boot_fadespeed = eeprom_read_byte( &ee_boot_fadespeed );
    uint8_t boot_timeadj   = eeprom_read_byte( &ee_boot_timeadj );

    // initialize i2c interface
    uint8_t i2c_addr = eeprom_read_byte( &ee_i2c_addr );
    if( i2c_addr==0 || i2c_addr>0x7f) i2c_addr = I2C_ADDR;  // just in case

    i2c_addrs[0] = i2c_addr;
    for( uint8_t i = 1; i<slaveAddressesCount; i++ ) {
        i2c_addrs[i] = i2c_addrs[0] + i;
    }
    usiTwiSlaveInit( i2c_addrs );

    timeadj    = boot_timeadj;
    if( boot_mode == BOOT_PLAY_SCRIPT ) {
        play_script( boot_script_id, boot_reps, 0 );
    }

    sei();                      // enable interrupts

#if 0
    basic_tests();
#endif

    RB_Init();
    // This loop runs forever. 
    // If the TWI Transceiver is busy the execution will just 
    // continue doing other operations.
    for(;;) {
        handle_i2c();
        handle_inputs();
        handle_script();
        handle_ir_queue();
    }
    
} // end
Ejemplo n.º 19
0
void audio_io_task(void)
{
	sndbuf_t * out_buf;
	sndbuf_t * in_buf;
	uint32_t ts = 0;
	int i;

	tracef("%s(): <%d> started...", __func__, thinkos_thread_self());

	tonegen_init(&tonegen, 0, 0);
	spectrum_init(&audio_tx_sa, SAMPLE_RATE);
	spectrum_init(&audio_rx_sa, SAMPLE_RATE);

	for (;;) {
#if DISABLE_JITBUF
		out_buf = xfr_buf;
#else
		out_buf = jitbuf_dequeue(&audio_drv.jitbuf);
#endif

		if (audio_drv.tone_mode == TONE_DAC) {
			if (out_buf == NULL) {
				if ((out_buf = sndbuf_alloc()) != NULL)
					tonegen_apply(&tonegen, out_buf);
				else
					out_buf = (sndbuf_t *)&sndbuf_zero;
			}
		} else {
			if (out_buf == NULL) {
#if 0
			tracef("%s(): out_buf == NULL!", __func__);
#endif
				out_buf = (sndbuf_t *)&sndbuf_zero;
			}
		}

		spectrum_rec(&audio_tx_sa, out_buf);

		in_buf = i2s_io(out_buf);

  		for (i = 0; i < SNDBUF_LEN; i++)
		    in_buf->data[i] = FxaIirApply(&iir_hp_120hz, in_buf->data[i]);
//		    in_buf->data[i] = FxaIirApply(&iir_hp_240hz, in_buf->data[i]);

		led_flash(LED_I2S, 100);

		if (in_buf != &sndbuf_null) {
			if (audio_drv.tone_mode == TONE_ADC)
				tonegen_apply(&tonegen, in_buf);

			spectrum_rec(&audio_rx_sa, in_buf);
		}

		if (audio_drv.stream_enabled) {
#if ENABLE_G711
			if (g711_alaw_send(0, in_buf, ts) < 0) {
				tracef("%s(): net_send() failed!", __func__);
			}
#else
			if (audio_send(0, in_buf, ts) < 0) {
				tracef("%s(): net_send() failed!", __func__);
			}
#endif
			led_flash(LED_NET, 100);
		}

		ts += SNDBUF_LEN;

		sndbuf_free(in_buf);
		sndbuf_free(out_buf);
	}
}
Ejemplo n.º 20
0
void *client_thread(void *arg)
{
	cJSON *root = NULL;
	char buffer[512] = {0};
	dev_tt dev;
	DEV_ADD_RETURN ret_add_dev = DEV_ADD_OK;
	BOOL ret = FALSE;
	char cityid[20] = {0};
	fd_set pending_data;
	struct timeval block_time;
	if (arg == NULL) {
		return NULL;
	}
	int *fd = arg;

	FD_ZERO(&pending_data);
	FD_SET(*fd,&pending_data);
	block_time.tv_sec = 5;
	block_time.tv_usec = 0;

	/*if client connect and not send message in 5 seconds,we will close the connection*/
	if (select((*fd) + 1, &pending_data, NULL, NULL, &block_time) > 0) {
		if (FD_ISSET(*fd, &pending_data)) {
			if (read(*fd, buffer, sizeof(buffer)) < 0) {
				close(*fd);
				return NULL;
			}
		}
	} 
	
	led_flash(LED_FOR_NETWORK, 1, 3);
	DEBUG_MSG("Network receive:%s\n", buffer);
	root = cJSON_Parse(buffer);//parse json
	if (root == NULL) {
		return NULL;
	}
	memset(&dev, 0, sizeof(dev_tt));
	char *who			= cJSON_GetObjectItem(root, "param0")->valuestring;
	dev.user_action 		= cJSON_GetObjectItem(root, "param1")->valuestring;
	dev.basic_info.mac		= cJSON_GetObjectItem(root, "param2")->valuestring;
	dev.basic_info.name 		= cJSON_GetObjectItem(root, "param3")->valuestring;
	dev.type 				= cJSON_GetObjectItem(root, "param4")->valuestring;
	dev.dev_cmd 			= cJSON_GetObjectItem(root, "param5")->valuestring;
	dev.basic_info.groupname	= cJSON_GetObjectItem(root, "param6")->valuestring;
	char *param1			= cJSON_GetObjectItem(root, "param7")->valuestring;
	char *param2			= cJSON_GetObjectItem(root, "param8")->valuestring;
	
	if (who == NULL || dev.user_action == NULL || dev.basic_info.mac==NULL ||dev.basic_info.name== NULL||dev.dev_cmd==NULL||dev.basic_info.groupname==NULL) {
		close(*fd);
		return NULL;
	}
	USER_ACTION user_action_type = (USER_ACTION)atoi(dev.user_action);
	switch (user_action_type) {
	case ACTION_DEV_ADD:
		dev.basic_info.name 		= strtok(dev.basic_info.name,":");//contains unicode
		dev.basic_info.unicode 	= strtok(NULL,":");
		dev.type = param2;
		if (dev.basic_info.name == NULL ||dev.basic_info.unicode == NULL) {
			break;
		}
		DEBUG_MSG("ADD:name= %s,unicode= %s\n",dev.basic_info.name,dev.basic_info.unicode);
		ret_add_dev = AddDevToStaticTable(dev.basic_info.mac,dev.basic_info.name,dev.basic_info.unicode,dev.basic_info.groupname,atoi(param1),atoi(dev.type));
		if (ret_add_dev==DEV_ADD_OK) {
			write(*fd, SOCKET_RESPONSE_YES, strlen(SOCKET_RESPONSE_YES));
			send_broadcast(who, user_action_type, dev.basic_info.name);
		} else if (ret_add_dev == DEV_MAC_EXIST) {
			write(*fd,SOCKET_RESPONSE_MAC_EXIST, strlen(SOCKET_RESPONSE_MAC_EXIST));
		} else if (ret_add_dev == DEV_NAME_EXIST) {
			write(*fd,SOCKET_RESPONSE_NAME_EXIST, strlen(SOCKET_RESPONSE_NAME_EXIST));
		}
		break;
	case ACTION_DEV_REMOVE:
		ret = RemoveDevFromStaticTable(dev.basic_info.mac,dev.basic_info.name);
		if (ret) {
			send_broadcast(who,user_action_type,dev.basic_info.name);
		}
		goto response_client;
		break;
	case ACTION_DEV_ADD_GROUP:
		ret = AddDevGroupName(dev.basic_info.groupname);
		goto response_client;
		break;
	case ACTION_DEV_EDIT:
		{
			char *oldname = param1;
			dev.basic_info.name = strtok(dev.basic_info.name,":");
			dev.basic_info.unicode = strtok(NULL,":");
			if (dev.basic_info.name == NULL ||dev.basic_info.unicode == NULL||oldname==NULL) {
				break;			
			}
			DEBUG_MSG("UPDATE:oldname = %s newname= %s,unicode= %s\n",oldname,dev.basic_info.name,dev.basic_info.unicode);
			ret = UpdateDevDisplayName(dev.basic_info.mac, oldname,dev.basic_info.name,dev.basic_info.unicode);
			if (ret) {
				send_broadcast(who,user_action_type,dev.basic_info.name);
			}
			goto response_client;
		}
		break;
	case ACTION_GET_ALARM_LIST:
		GetAlarmAllList();
		write(*fd,get_alarm_alllist(),strlen(get_alarm_alllist()));
		break;
	case ACTION_GET_DEV_LIST:
		GetDeviceList();
		write(*fd,get_dev_list(),strlen(get_dev_list()));
		break;
	case ACTION_GET_CITY_ID:
		//char *name = dev.basic_info.name;
		memset(cityid,0,sizeof(cityid));
		if (GetCityIDByName(dev.basic_info.name, cityid)) {
			write(*fd,cityid,strlen(cityid));
		} else {
			write(*fd,SOCKET_RESPONSE_NO,strlen(SOCKET_RESPONSE_NO));
		}
		break;
	case ACTION_DEV_CONTROL:
		if (app_status.is_uart_ok) {
			ret = ForwardControlToUart(dev.basic_info.mac,dev.basic_info.name,(DEV_TYPE_INDEX)(atoi(dev.type)),atoi(dev.dev_cmd),atoi(param1));
		} else {
			ret = FALSE;
		}
		goto response_client;
		break;
	case ACTION_SEND_MSG:
		if (app_status.is_sms_ok) {
			ret = sms.send(dev.basic_info.mac,dev.basic_info.name);
		} else {
			ret = FALSE;
		}
		goto response_client;
		break;
	case ACTION_ALARM_ADD:
		//mac as the value(email or mobile value)
		ret = AddAlarmItem((ALARM_TYPE)(atoi(dev.type)), dev.basic_info.mac);
		goto response_client;
		break;
	case ACTION_ALARM_LOCK:
		ret = ChangeAlarmItemToState(ALARM_LOCK,(ALARM_TYPE)(atoi(dev.type)), dev.basic_info.mac);
		goto response_client;
		break;
	case ACTION_ALARM_UNLOCK:
		ret = ChangeAlarmItemToState(ALARM_UNLOCK,(ALARM_TYPE)(atoi(dev.type)), dev.basic_info.mac);
		goto response_client;
		break;
	case ACTION_ALARM_DELETE:
		ret = DeleteFromAlarmTable((ALARM_TYPE)(atoi(dev.type)), dev.basic_info.mac);
		goto response_client;
		break;
	case ACTION_GET_ALL_GROUP_NAME:
		GetAllGroupName();
		write(*fd , get_group_list(), strlen(get_group_list()));
		break;
	case ACTION_UPDATE_DEV_GROUP:
		ret = UpdateDevGroupName(dev.basic_info.mac,dev.basic_info.name,dev.basic_info.groupname);
		goto response_client;
		break;
	case ACTION_SET_GROUP_ID:
		{
			groupInfo_t group_info;
			memset(&group_info,0,sizeof(&group_info));
			strcpy(group_info.group_id,dev.basic_info.mac);
			strcpy(group_info.group_name,dev.basic_info.name);
			ret = SetFamilyGroupInfo(group_info);
			goto response_client;
		}
		break;
	case ACTION_GET_GROUP_ID:
		{
			groupInfo_t group_info;
			memset(&group_info,0,sizeof(&group_info));
			if (GetFamilyGroupInfo(&group_info)) {
					char buf[1024] = {0};
					sprintf(buf,"%s,%s,",group_info.group_id,group_info.group_name);
					write(*fd,buf,strlen(buf));
			} else {
				write(*fd,"_FAIL_",strlen("_FAIL_"));
			}
		}
		break;
	case ACTION_ADD_TIMERTASK:
		{
			timertask_item_t item;
			DEBUG_MSG("add timertask!\n");
			memset(&item,0,sizeof(&item));
			strcpy(item.dev_mac,dev.basic_info.mac);
			strcpy(item.dev_name,dev.basic_info.name);
			strcpy(item.happen_time ,param1);
			item.period		=	atoi(dev.type);
			item.action		=	atoi(dev.dev_cmd);
			item.tipinfo		=	atoi(dev.basic_info.groupname);
			item.howlong		=	atoi(param2);
			DEBUG_MSG("action = %d, howlong = hour:%2d,minute:%2d\n",item.action,(item.howlong)/100,(item.howlong)%100);
			ret = AddOneTimerTask(item);
			if (ret && item.howlong > 0) {
				TimeAdd(item.happen_time,item.howlong/100, item.howlong%100, item.happen_time);
				if (item.action == CMD_SW_OPEN) {
					item.action = CMD_SW_CLOSE;
				} else {
					item.action = CMD_SW_OPEN;
				}
				item.howlong = 0;//avoid repeat
				ret = AddOneTimerTask(item);
			}
			goto response_client;
		}
		break;
	case ACTION_DELETE_TIMERTASK:
		{
			int timertask_id = 0;
			ret = DeleteOneTimerTaskByID(timertask_id);
			goto response_client;
		}
		break;
	case ACTION_GET_TIMERTASK_INFO:
		GetAllTimerTaskInfo();
		write(*fd,g_timertask_info,strlen(g_timertask_info));
		break;
	case ACTION_SW_GET_STATE:
		{
			char buffer[10] = {0};
			enum control_cmd state = SWGetCurrentState(dev.basic_info.mac,dev.basic_info.name,atoi(param1));
			sprintf(buffer,"%d", state);
			write(*fd,buffer,strlen(buffer));
		}
		break;
	case ACTION_QUIT:
		close(*fd);
		return NULL;
	default:
		break;
	}
	close(*fd);
	return NULL;
response_client:
	if (ret) {
		write(*fd, SOCKET_RESPONSE_YES, strlen(SOCKET_RESPONSE_YES));
	} else {
		write(*fd, SOCKET_RESPONSE_NO, strlen(SOCKET_RESPONSE_NO));
	}
	close(*fd);
	return NULL;
}
Ejemplo n.º 21
0
void ict_Init(void)
{
	led_Init();
	led_flash(LED_GREEN);

	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	GPIO_InitTypeDef GPIO_InitStructure;
	ADC_InitTypeDef ADC_InitStructure;
	DAC_InitTypeDef DAC_InitStructure;

	RCC_ADCCLKConfig(RCC_PCLK2_Div8); /*72Mhz/8 = 9Mhz*/
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE| RCC_APB2Periph_GPIOD|
		RCC_APB2Periph_GPIOC| RCC_APB2Periph_GPIOA, ENABLE);

	// IO config

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(GPIOE, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOD, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_4|
		GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	// DAC config
	DAC_StructInit(&DAC_InitStructure);
	DAC_Init(DAC_Channel_1, &DAC_InitStructure);
	DAC_Cmd(DAC_Channel_1, ENABLE);

	DAC_StructInit(&DAC_InitStructure);
	DAC_Init(DAC_Channel_2, &DAC_InitStructure);
	DAC_Cmd(DAC_Channel_2, ENABLE);

	/* ADC1 config, Power Ouput Voltage sampling,
	V1 = ADC1_CH2 = PA2 = ADC123_IN2
	V2 = ADC2_CH7 = PA7 = ADC12_IN7
	*/
	ADC_DeInit(ADC1);
	ADC_StructInit(&ADC_InitStructure);
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
	ADC_InitStructure.ADC_ScanConvMode = ENABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_InitStructure.ADC_NbrOfChannel = 0;
	ADC_Init(ADC1, &ADC_InitStructure);

	ADC_InjectedSequencerLengthConfig(ADC1, 4);
	ADC_InjectedChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_55Cycles5); //9Mhz/(71.5 + 12.5) = 107.1Khz
	ADC_InjectedChannelConfig(ADC1, ADC_Channel_7, 2, ADC_SampleTime_55Cycles5);
	ADC_InjectedChannelConfig(ADC1, ADC_Channel_1, 3, ADC_SampleTime_55Cycles5); //I0
	ADC_InjectedChannelConfig(ADC1, ADC_Channel_6, 4, ADC_SampleTime_55Cycles5); //I1
	ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);
	ADC_Cmd(ADC1, ENABLE);

	ADC_ResetCalibration(ADC1);
	while (ADC_GetResetCalibrationStatus(ADC1));
	ADC_StartCalibration(ADC1);
	while (ADC_GetCalibrationStatus(ADC1));
	ADC_SoftwareStartInjectedConvCmd(ADC1, ENABLE);

	/* ADC2 config, current sampling & over current protection
	 * I1 = ADC1_CH1 = PA1 = ADC123_IN1
	 */
	ADC_DeInit(ADC2);
	ADC_StructInit(&ADC_InitStructure);
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_Init(ADC2, &ADC_InitStructure);

	ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_71Cycles5); //9Mhz/(71.5 + 12.5) = 107.1Khz

	ADC_Cmd(ADC2, ENABLE);
	ADC_ResetCalibration(ADC2);
	while (ADC_GetResetCalibrationStatus(ADC2));
	ADC_StartCalibration(ADC2);
	while (ADC_GetCalibrationStatus(ADC2));

	ADC_AnalogWatchdogThresholdsConfig(ADC2, mA2d(100), 0x000);
	ADC_AnalogWatchdogSingleChannelConfig(ADC2, ADC_Channel_1);
	ADC_AnalogWatchdogCmd(ADC2, ADC_AnalogWatchdog_SingleRegEnable);

	NVIC_InitTypeDef NVIC_InitStructure;
	NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	//START
	ADC_ITConfig(ADC2, ADC_IT_AWD, ENABLE);
	ADC_SoftwareStartConvCmd(ADC2, ENABLE);

	/* ADC3 config, current sampling & over current protection
	 * I2 = ADC2_CH6 = PA6 = ADC12_IN6
	 */
	ADC_DeInit(ADC3);
	ADC_StructInit(&ADC_InitStructure);
	ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
	ADC_InitStructure.ADC_ScanConvMode = DISABLE;
	ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_Init(ADC3, &ADC_InitStructure);

	ADC_RegularChannelConfig(ADC3, ADC_Channel_6, 1, ADC_SampleTime_71Cycles5); //9Mhz/(71.5 + 12.5) = 107.1Khz

	ADC_Cmd(ADC3, ENABLE);
	ADC_ResetCalibration(ADC3);
	while (ADC_GetResetCalibrationStatus(ADC3));
	ADC_StartCalibration(ADC3);
	while (ADC_GetCalibrationStatus(ADC3));
	ADC_SoftwareStartConvCmd(ADC3, ENABLE);

	ADC_AnalogWatchdogThresholdsConfig(ADC3, mA2d(100),0x000);
	ADC_AnalogWatchdogSingleChannelConfig(ADC3, ADC_Channel_6);
	ADC_AnalogWatchdogCmd(ADC3, ADC_AnalogWatchdog_SingleRegEnable);

	NVIC_InitStructure.NVIC_IRQChannel = ADC3_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	//START
	ADC_ITConfig(ADC3, ADC_IT_AWD, ENABLE);
	ADC_SoftwareStartConvCmd(ADC3, ENABLE);

	// TIM config
	TIM_TimeBaseStructure.TIM_Period = 100 - 1; //Fclk = 10KHz /100  = 100Hz
	TIM_TimeBaseStructure.TIM_Prescaler = 7200 - 1; //prediv to 72MHz to 10KHz
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
	TIM_ClearFlag(TIM2, TIM_FLAG_Update);
	TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
	TIM_Cmd(TIM2, ENABLE);

	NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	GPIO_ResetBits(GPIOD, GPIO_Pin_12);
	GPIO_ResetBits(GPIOD, GPIO_Pin_13);

	mbi5025_Init(&ict_mbi5025);
	mbi5025_EnableOE(&ict_mbi5025);
}
Ejemplo n.º 22
0
void led_signal(uint8 narrow, uint8 wide)
{
    led_flash(narrow, false);
    led_flash(wide,   true);
    os_sleep(200);
}
Ejemplo n.º 23
0
Archivo: motor.c Proyecto: miaofng/ulp
void motor_Update(void)
{
	short speed, torque_ref, speed_pid;

	vsm_Update();
	smo_Update();
	speed = smo_GetSpeed();
	speed_pid = pid_GetRef(pid_speed);

	switch (stm) {
		case MOTOR_IDLE:
			break;

		case MOTOR_START_OP:
			led_flash(LED_RED);
			led_flash(LED_GREEN);
			smo_Start();
			vsm_Start();
			stm = MOTOR_START;

			//soft start???
			torque_ref = motor->start_torque;
			pid_SetRef(pid_flux, 0); /*Id = 0 control method*/
			pid_SetRef(pid_torque, torque_ref);
			break;
			
		case MOTOR_START:
			/*only for debug purpose*/
			pwm1_Set(smo_GetSpeed()*100);
			pwm2_Set(smo_GetAngle());
			
			if(smo_IsLocked()) {
				stm = MOTOR_RUN;
				led_off(LED_RED);
				led_flash(LED_GREEN);
			}
			if(speed_pid == 0) {
				stm = MOTOR_STOP_OP;
				led_on(LED_RED);
				led_on(LED_GREEN);
			}
			break;

		case MOTOR_RUN:
			/*only for debug purpose*/
			pwm1_Set(smo_GetSpeed()*100);
			pwm2_Set(smo_GetAngle());
			
			if((speed_pid == 0) && (speed < motor->start_speed)) {
				stm = MOTOR_STOP_OP;
				led_on(LED_RED);
				led_on(LED_GREEN);
				break;
			}

			/*speed pid*/
			torque_ref = pid_Calcu(pid_speed, speed);
			pid_SetRef(pid_flux, 0); /*Id = 0 control method*/
			pid_SetRef(pid_torque, torque_ref);
			break;

		case MOTOR_STOP_OP:
			vsm_Stop(); /*note: It's not a brake!!!*/
			stop_timer = time_get(MOTOR_STOP_PERIOD);
			stm = MOTOR_STOP;
			break;
			
		case MOTOR_STOP:
			if(time_left(stop_timer) < 0) {
				stm = MOTOR_IDLE;
				led_off(LED_RED);
				led_on(LED_GREEN);
			}
			break;

		default:
			led_on(LED_RED);
			led_off(LED_GREEN);
			printf("SYSTEM ERROR!!!\n");
	}
}
Ejemplo n.º 24
0
int main(void)
{
    unsigned char* loadbuffer;
    int buffer_size;
    int rc;
    int(*kernel_entry)(void);

    led_init();
    clear_leds(LED_ALL);
    /* NB: something in system_init() prevents H-JTAG from downloading */
/*    system_init(); */ 
    kernel_init();
/*    enable_interrupt(IRQ_FIQ_STATUS); */
    backlight_init();
    lcd_init();
    lcd_setfont(FONT_SYSFIXED);
    button_init();
    dma_init();
    
    uart_init();
    uart_init_device(DEBUG_UART_PORT);

/*    mini2440_test(); */  
        
    /* Show debug messages if button is pressed */
    int touch_data;
    if(button_read_device(&touch_data) & BUTTON_MENU) 
        verbose = true;
        
    printf("Rockbox boot loader");
    printf("Version " RBVERSION);

    rc = storage_init();
    if(rc)
    {
        reset_screen();
        error(EATA, rc, true);
    }

    disk_init(IF_MD(0));
    rc = disk_mount_all();
    if (rc<=0)
    {
        error(EDISK,rc, true);
    }

    printf("Loading firmware");

    /* Flush out anything pending first */
    commit_discard_idcache();

    loadbuffer = (unsigned char*) 0x31000000;
    buffer_size = (unsigned char*)0x31400000 - loadbuffer;

    rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
    if(rc <= 0)
        error(EBOOTFILE, rc, true);

    printf("Loaded firmware %d\n", rc);
    
/*    storage_close(); */
    system_prepare_fw_start();

    commit_discard_idcache();
    kernel_entry = (void*) loadbuffer;
    rc = kernel_entry();
        
    /* end stop - should not get here */
    led_flash(LED_ALL, LED_NONE);
    while (1); /* avoid warning */
}
Ejemplo n.º 25
0
void power_off(void)
{
    /* we don't have any power control, user must do it */
    led_flash (LED_NONE, LED_ALL);
    while (1);
}
Ejemplo n.º 26
0
void cm_pushD(u8 c)
{
 #ifdef _TEST_UARTS_
     if(c=='0')
        led_off(3);
     if(c=='1')
        led_on(3);
     if(c=='F')
        led_flash(3);
#endif               

      if(RFlagD == RF_DATABUF)               {     //checksum found
                infrmD[FRM_POS_CKSUM] = c;
                infrmD[FRM_POS_HEAD2] = 0x68;                
                infrmD[FRM_POS_HEAD1] = 0xfe;                
                RFlagD = RF_CKSUM;                 //wait for the main program to handle it and clear the flag to IDLE                       
                return;
      }
      if(RFlagD == RF_DATALEN)               {     //databuf found
                infrmD[FRM_POS_DBUF+buf_cntD] = c;
                buf_cntD += 1;
                if(buf_cntD >= infrmD[FRM_POS_DLEN])
                        RFlagD = RF_DATABUF;
                return;
      }
      if(RFlagD == RF_CMD)                 {     //datalen found
                if(c <= CM_INBUF_MAX){
                        infrmD[FRM_POS_DLEN] = c;
                        buf_cntD = 0;
                        RFlagD = RF_DATALEN;
                }       
                return;                         
      }
      if(RFlagD == RF_ADDRTO)                 {     //cmd found
                infrmD[FRM_POS_CMD] = c;
                RFlagD = RF_CMD; 
                return;
      }      
      if(RFlagD == RF_ADDRFROM)                 {     //addr_to found
                infrmD[FRM_POS_TO] = c;
                RFlagD = RF_ADDRTO; 
                return;
      }
      if(RFlagD == RF_HEAD2)                 {     //addr_from found
                infrmD[FRM_POS_FROM] = c;
                RFlagD = RF_ADDRFROM;
                return;
      }
      if((RFlagD == RF_HEAD1) && (c == 0x68)){     //head2 found
                RFlagD = RF_HEAD2;
                return;
      }
      if((RFlagD == RF_HEAD1) && (c == 0xfe)){     //double head1
                RFlagD = RF_HEAD1;
                return;
      }
      if((RFlagD == RF_IDLE) && (c == 0xfe)){      //first byte
                RFlagD = RF_HEAD1;
                return;
      }                
      RFlagD = RF_IDLE;
}