Exemple #1
0
/* The main TSCH process */
PROCESS_THREAD(tsch_process, ev, data)
{
  static struct pt scan_pt;

  PROCESS_BEGIN();

  while(1) {

    while(!tsch_is_associated) {
      if(tsch_is_coordinator) {
        /* We are coordinator, start operating now */
        tsch_start_coordinator();
      } else {
        /* Start scanning, will attempt to join when receiving an EB */
        PROCESS_PT_SPAWN(&scan_pt, tsch_scan(&scan_pt));
      }
    }

    /* We are part of a TSCH network, start slot operation */
    tsch_slot_operation_start();

    /* Yield our main process. Slot operation will re-schedule itself
     * as long as we are associated */
    PROCESS_YIELD_UNTIL(!tsch_is_associated);

    /* Will need to re-synchronize */
    tsch_reset();
  }

  PROCESS_END();
}
Exemple #2
0
PROCESS_THREAD(shell_owtest_process, ev, data) {
	int err;

	PROCESS_BEGIN();

	// Attempt to acquire 1-Wire lock
	while (!ow_lock()) {
		PROCESS_PAUSE();
	}

	// Reset the bus
	err = ow_reset();
	if (err < 0) {
		shell_output_P(&owtest_command, PSTR("Bus reset failed.\n"));
		PROCESS_EXIT();
	}
	else if (err == 0) {
		shell_output_P(&owtest_command, PSTR("No presence detected.\n"));
		PROCESS_EXIT();
	}

	// Start the search
	err = ow_search_first(&search, 0);
	do {
		if (err < 0) {
			shell_output_P(&owtest_command, PSTR("Search error: %d\n"), err);
			PROCESS_EXIT();
		}
		else if (err == 0) {
			shell_output_P(&owtest_command, PSTR("No devices found.\n"));
			break;
		}

		// Print search result
		shell_output_P(&owtest_command,
			PSTR("Found: %02x.%02x%02x%02x%02x%02x%02x\n"),
			search.rom_no.family, // family code
			search.rom_no.id[0], search.rom_no.id[1], search.rom_no.id[2],
			search.rom_no.id[3], search.rom_no.id[4], search.rom_no.id[5]);

		// If it's a DS18B20, read it
		if (search.rom_no.family == 0x28) {
			shell_output_P(&owtest_command, PSTR("Reading temperature...\n"));
			PROCESS_PT_SPAWN(&ow_pt, read_temp(&ow_pt, &search.rom_no));
		}

		// If we found the last device on the bus, break out of the loop
		if (search.last_device_flag) {
			break;
		}

		// Find the next device on the bus
		err = ow_search_next(&search);
	} while (1);

	// Relinquish bus lock
	ow_unlock();

	shell_output_P(&owtest_command, PSTR("Search complete.\n"));

	PROCESS_END();
}