示例#1
0
portTASK_FUNCTION(task_decawave, pvParameters) {
	UNUSED(pvParameters);

	int i = 0;
	int toggle = 1;
	int ranging = 0;
	uint8 dataseq[40];
	double range_result = 0;
	double avg_result = 0;
	uint8 dataseq1[40];
	uint8 command = 0x0;

	led_off(LED_ALL); //turn off all the LEDs

	peripherals_init();

	spi_peripheral_init();

	Sleep(1000); //wait for LCD to power on

	printf("DECAWAVE        \r\n");
	printf(SOFTWARE_VER_STRING);
	printf("\r\n");

	Sleep(1000);

	port_DisableEXT_IRQ(); //disable ScenSor IRQ until we configure the device

	printf("DECAWAVE  RANGE\r\n");

	led_off(LED_ALL);

	int testresult = inittestapplication();
	if (testresult < 0) {
		led_on(LED_ALL); //to display error....
		printf("ERROR\r\n");
		printf("INIT FAIL %d\r\n", testresult);
		for (;;) {
		}
	}

	//sleep for 5 seconds displaying "Decawave"
	i = 30;
	while (i--) {
		if (i & 1)
			led_off(LED_ALL);
		else
			led_on(LED_ALL);

		Sleep(200);
	}
	i = 0;
	led_off(LED_ALL);

	if (is_tag) {
		instance_mode = TAG;
		printf("TAG\r\n");
	} else {
		instance_mode = ANCHOR;
		printf("ANCHOR\r\n");
#if (DR_DISCOVERY == 1)
		printf("DR_DISCOVER == 1\r\n");
#else
		printf("DR_DISCOVER == 0\r\n");
#endif
	}

	if (instance_mode == TAG) {
		//if TA_SW1_2 is on use fast ranging (fast 2wr)
		if (use_fast2wr) {
			printf("Fast Tag Ranging\r\n");
		} else {
			printf("TAG BLINK %llX\r\n", instance_get_addr());
		}
	} else {
		printf("AWAITING POLL\r\n");
	}

	port_EnableEXT_IRQ(); //enable ScenSor IRQ before starting

	// main loop
	while (1) {

		//ERIC: Delay irq handling...will this work?
		uint32_t bail = 0;
		if (irq_set) {
			do {
				if (bail++ > 2000) {
					printf("BAIL!\r\n");
					Sleep(10);
					for (;;) {
					}
				}
				instance_process_irq(0);
			} while (port_CheckEXT_IRQ() == 1);
			irq_set = 0x00;
		}

		instance_run();

		if (instancenewrange()) {
			ranging = 1;
			//send the new range information to LCD and/or USB
			range_result = instance_get_idist();
#if (DR_DISCOVERY == 0)
			if(instance_mode == ANCHOR)
#endif
			avg_result = instance_get_adist();
			//set_rangeresult(range_result);

			printf("LAST: %4.2f m   ", range_result);
#if (DR_DISCOVERY == 0)
			if(instance_mode == ANCHOR)
			printf("AVG8: %4.2f m", avg_result);
			else
			printf("%llx", instance_get_anchaddr());
#else
			printf("AVG8: %4.2f m\r\n", avg_result);
#endif
		}

		if (ranging == 0) {
			if (instance_mode != ANCHOR) {
				if (instancesleeping()) {
					if (toggle) {
						printf("AWAITING RESPONSE\r\n");
					} else {
						toggle = 1;
						printf("TAG BLINK %llX\r\n", instance_get_addr());
					}
				}

				if (instanceanchorwaiting() == 2) {
					ranging = 1;
					printf("RANGING WITH %016llX\r\n", instance_get_anchaddr());
				}
			} else {
				if (instanceanchorwaiting()) {
					toggle += 2;

					if (toggle > 300000) {
						if (toggle & 0x1) {
							toggle = 0;
							printf("AWAITING POLL\r\n");
						} else {
							toggle = 1;
#if (DR_DISCOVERY == 1)
							printf("DISCOVERY MODE ");
#else
							printf("NON DISCOVERY ");
#endif
							printf("%llX\r\n", instance_get_addr());
						}
//						print_status();
					}

				} else if (instanceanchorwaiting() == 2) {
					printf("RANGING WITH %llX", instance_get_tagaddr());
				}
			}
		}
	}
}
示例#2
0
int main(int argc, char *argv[])
{
    fcs_dbm_variant_type_t local_variant = FCS_DBM_VARIANT_2FC_FREECELL;
    const long delta_limit = 100000;
    const int max_num_elements_in_cache = 8000000;
    const char *filename = argv[1];
    FILE *const fh = fopen(filename, "r");
    if (fh == NULL)
    {
        fc_solve_err("Could not open file '%s' for input.\n", filename);
    }
    const fcs_user_state_str_t user_state = read_state(fh);
    fcs_state_keyval_pair_t init_state_pair;
    fc_solve_initial_user_state_to_c(
        user_state.s, &init_state_pair, FREECELLS_NUM, STACKS_NUM, 1, NULL);

    fcs_dbm_solver_instance_t instance;

    instance_init(
        &instance, local_variant, &init_state_pair, max_num_elements_in_cache);

#define LOG_FILENAME "fc-solve-pseudo-dfs.log.txt"

    {
        FILE *const last_line_fh = popen(("tail -1 " LOG_FILENAME), "r");

        if (last_line_fh)
        {
            long count_num_processed;
            if (fscanf(last_line_fh, "At %ld iterations Coords=[",
                    &count_num_processed) == 1)
            {
                instance__load_coords_from_fh(&instance, last_line_fh);
                /*
                 * instance__inspect_new_state increments count_num_processed
                 * so let's set it after loading the coordinates.
                 * */
                instance.count_num_processed = count_num_processed;
            }
        }
        pclose(last_line_fh);
    }

    instance.max_count_num_processed =
        instance.count_num_processed + delta_limit;

    while (instance.max_count_num_processed % delta_limit != 0)
    {
        instance.max_count_num_processed +=
            delta_limit - (instance.max_count_num_processed % delta_limit);
    }

    while (instance.should_terminate == DONT_TERMINATE)
    {
        instance_run(&instance);

        FILE *const log_fh = fopen(LOG_FILENAME, "at");
        instance__print_coords_to_log(&instance, log_fh);
        fclose(log_fh);

        instance.max_count_num_processed =
            instance.count_num_processed + delta_limit;
    }

    if (instance.should_terminate == SOLUTION_FOUND_TERMINATE)
    {
        printf("%s\n", "Solution was found.");
    }
    else
    {
        printf("%s\n", "I could not solve it.");
    }

    instance_free(&instance);

    return 0;
}
示例#3
0
/**
 * Application entry point.
 */
int main(void)
{
	int prijem=0;
	uint32 device_id;
    /* Start with board specific hardware init. */
    peripherals_init();

    spi_peripheral_init();

        Sleep(1000); //wait for LCD to power on

        initLCD();

    /* Display application name on LCD. */
    setLCDline1( 234);
   // Sleep(1000);
    usb_init();
    //Sleep(1000);
   // lcd_display_str("connected");
    /* Reset and initialise DW1000.
      * For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum
      * performance. */
     reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */

     SPI_ChangeRate(SPI_BaudRatePrescaler_32);
    // spi_set_rate_low();
  //   uint32 temp = dwt_read32bitoffsetreg(AON_ID,AON_WCFG_OFFSET);
     dwt_initialise(DWT_LOADUCODE);


   //  dwt_configuresleepcnt(sleep16);  //needed for LPL
   //  dwt_configuresleep(DWT_LOADUCODE | DWT_LOADOPSET | DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_WK | DWT_SLP_EN); //needed for LPL
     SPI_ChangeRate(SPI_BaudRatePrescaler_4);
     //spi_set_rate_high();


   //  dwt_configure(&config);
     /* Loop forever receiving frames. */
       /* while (1)
        {
        	led_on(LED_ALL);
        	Sleep(100);
        	led_off(LED_ALL);
        	Sleep(100);

        	push_over_usb("nikola",6);
        	setLCDline1( 123);



        }*/

     s1switch = is_button_low(0) << 1 // is_switch_on(TA_SW1_2) << 2
     		| is_switch_on(TA_SW1_3) << 2
     		| is_switch_on(TA_SW1_4) << 3
     		| is_switch_on(TA_SW1_5) << 4
 		    | is_switch_on(TA_SW1_6) << 5
     		| is_switch_on(TA_SW1_7) << 6
     		| is_switch_on(TA_SW1_8) << 7;



     port_EnableEXT_IRQ();
     while(1){

    	 setLCDline1(123);
    	 deca_sleep(1000);

    	 device_id= inittestapplication(s1switch);
    	 setLCDline1(instance_data[0].mode);
    	 if(instance_mode == TAG){
    		 setLCDline1(1);
    	 }
    	 else if(instance_mode==ANCHOR){
    		 setLCDline1(2);
    	 }
    	 else {
    		 setLCDline1(3);
    	 }
    	 deca_sleep(1000);
    	// instance_run();

    	 //setLCDline1(message);
    	 instance_run();

     }





}