Ejemplo n.º 1
0
/**
 * @brief Main function of the device application
 */
int main(void)
{
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	irq_initialize_vectors();
	board_init();
	sysclk_init();

	sw_timer_init();

	if(MAC_SUCCESS != wpan_init())
	{
		app_alert();
	}

    /* Initialize LEDs. */
    LED_On(LED_START);         // indicating application is started
    LED_Off(LED_NWK_SETUP);    // indicating node is associated
    LED_Off(LED_DATA);         // indicating successfull data transmission

	cpu_irq_enable();

#ifdef SIO_HUB
    /* Initialize the serial interface used for communication with terminal program. */
   sio2host_init();

    /* To make sure the hyper terminal gets connected to the system */
    sio2host_getchar();

    printf("\nNobeacon_Application\r\n\n");
    printf("\nDevice\r\n\n");
#endif /* SIO_HUB */

	sw_timer_get_id(&APP_TIMER_LED_OFF);
	sw_timer_get_id(&APP_TIMER_POLL_DATA);

	wpan_mlme_reset_req(true);

	while (true)
	{
		wpan_task();
	}
}
Ejemplo n.º 2
0
/**
 * @brief Print the unpairing submenu to the terminal program
 */
static void print_unpair_submenu(void)
{
	char input_char;

	printf("Which device should be unpaired? Pairing Ref = \r\n");
	input_char = (char)sio2host_getchar();

	if ((input_char >= '0') && (input_char <= '9')) {
		uint8_t pair_ref = input_char - 0x30;
		nlme_unpair_request(pair_ref,
				(FUNC_PTR)nlme_unpair_confirm
				);
	} else {
		node_status = IDLE;
		printf("Unknown paring reference\r\n");
		printf("> Press Enter to return to main menu:\r\n ");
	}
}
Ejemplo n.º 3
0
/**
 * @brief Prints the sub menu for the base channel change.
 */
static void print_ch_change_submenu(void)
{
	char input_char[3] = {0, 0, 0};
	uint8_t channel;
	uint8_t i;
	uint8_t input;

#if (RF_BAND == BAND_900)
	printf("Enter new base channel (1, 4, or 7): \r\n");
#else
	printf("Enter new base channel (15, 20, or 25): \r\n");
#endif

	for (i = 0; i < 3; i++) {
		input = (char)sio2host_getchar();
		if (isdigit(input)) {
			input_char[i] = input;
		} else {
			break;
		}
	}
	channel = atol(input_char);

#if (RF_BAND == BAND_900)
	if ((channel == 1) || (channel == 4) || (channel == 7))
#else
	if ((channel == 15) || (channel == 20) || (channel == 25))
#endif
	{
		nlme_set_request(nwkBaseChannel, 0, &channel,
				(FUNC_PTR)nlme_set_confirm
				);

		node_status = BASE_CHANNEL_CHANGE;
	} else {
		printf(
				"Entered channel is not valid - press Enter to return to main menu.\r\n ");
		return;
	}
}
Ejemplo n.º 4
0
/**
 * @brief This function is used to print the vendor data submenu on the
 *hyperterminal.
 *
 * @param Vcmd Vendor command id to be requested.
 *
 */
static void print_vendor_data_submenu(vendor_cmd_id_t Vcmd)
{
	char input_char;

	printf("Which device should be asked? Pairing Ref = \r\n");
	input_char = (char)sio2host_getchar();
	printf("\r\n");

	if ((input_char >= '0') && (input_char <= '9')) {
		uint8_t PairingRef = input_char - 0x30;

		uint16_t VendorId = NWKC_VENDOR_IDENTIFIER;
		profile_id_t ProfileId = PROFILE_ID_ZRC;
		uint8_t nsdu = (uint8_t)Vcmd;
		vendor_data_request(PairingRef, ProfileId,
				VendorId, 1, &nsdu,
				TXO_UNICAST | TXO_DST_ADDR_IEEE | TXO_ACK_REQ | TXO_SEC_REQ | TXO_MULTI_CH | TXO_CH_NOT_SPEC |
				TXO_VEND_SPEC);
	} else {
		node_status = IDLE;
		printf("Unknown paring reference\r\n\r\n");
		printf("> Press Enter to return to main menu: \r\n");
	}
}
Ejemplo n.º 5
0
/**
 * @brief Prints the sub menu for the channel agility.
 */
static void print_sub_mode_ch_ag_setup(void)
{
	int8_t input_char;
	uint8_t input;

	printf("\n");
	printf(
			"Configuration of channel agility, select a configration parameter\r\n");
	printf("(Scan interval > 4*scan duration)\r\n\r\n");
	printf("(F) : Noise threshold, current value: %d\r\n",
			nwk_Private_ChAgEdThreshold);
	printf("(G) : Scan interval, current value: 0x%.8lX\r\n",
			nwk_Private_ChAgScanInterval);
	printf("(E) : Scan duration, current value: %d\r\n", nwk_ScanDuration);
	printf(">\r\n");
	/* Check for incoming characters from terminal program. */
	while (1) {
		input_char = sio2host_getchar_nowait();
		if (input_char != -1) {
			break;
		}
	}

	switch (toupper(input_char)) {
	case 'F': /* Noise Threshold */
	{
		char input_char2[3] = {0, 0, 0};
		uint8_t threshold;
		printf(
				"Enter new noise threshold (Valid Range:0 = -91dBm to 84 = -35dBm).\r\n");
		printf("Default: 10 = -80 dBm, new value: \r\n");
		for (uint8_t i = 0; i < 2; i++) {
			input = (char)sio2host_getchar();
			if (isdigit(input)) {
				input_char2[i] = input;
			} else if (input == 0x0D) {
				break;
			} else {
				printf("Invalid value. \r\n\r\n");
				printf(
						"> Press Enter to return to main menu:\r\n ");
				return;
			}
		}
		threshold = atol(input_char2);
		if (threshold <= 84) {
			nlme_set_request(nwkPrivateChAgEdThreshold, 0,
					&threshold,
					(FUNC_PTR)nlme_set_confirm
					);
		} else {
			printf("Invalid threshold value. \r\n\r\n");
			printf("> Press Enter to return to main menu:\r\n ");
			return;
		}
	}
	break;

	case 'G':   /* Scan interval */
	{
		char input_char2[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
		char input_char3[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
		uint32_t threshold = 0;
		printf(
				"Enter new scan interval (0x00000000 ... 0xFFFFFFFF), enter 32-bit value \r\n");
		printf(
				"Default: 0x00393870 symbols = 60 sec, new value: 0x \r\n");
		for (uint8_t i = 0; i < 8; i++) {
			input = (char)sio2host_getchar();
			input = (uint8_t)toupper(input);
			if (((input >= '0') && (input <= '9')) ||
					((input >= 'A') && (input <= 'F'))) {
				input_char2[i] = input;
			} else {
				if (input == 0x0D) {
					break;
				} else {
					printf("Invalid value. \r\n\r\n");
					printf(
							"> Press Enter to return to main menu:\r\n ");
					return;
				}
			}
		}

		for (uint8_t i = 7; i > 0; i--) {
			if (input_char2[i] != 0x00) {
				memcpy(&input_char3[7 - i], input_char2, i + 1);
				break;
			}
		}
		for (uint8_t i = 0; i < 8; i++) {
			if (input_char3[i] != 0x00) {
				if ((input_char3[i] >= '0') &&
						(input_char3[i] <=
						'9')) {
					input_char3[i] -= '0';
				} else {
					input_char3[i] -= 55;
				}

				threshold += (uint32_t)input_char3[i] <<
						((7 - i) * 4);
			}
		}
		nlme_set_request(nwkPrivateChAgScanInterval, 0,
				(uint8_t *)&threshold,
				(FUNC_PTR)nlme_set_confirm
				);
	}
	break;

	case 'E':
	{
		char input_char2[3] = {0, 0, 0};
		uint8_t scan_dur;
		printf(
				"Enter new scan duration (0 = 30 msec, 6 = 1 sec, 14 = 14 min).\r\n");
		printf("Default: 6 = 1 sec, new value: \r\n");
		for (uint8_t i = 0; i < 2; i++) {
			input = (char)sio2host_getchar();
			if (isdigit(input)) {
				input_char2[i] = input;
			} else if (input == 0x0D) {
				break;
			} else {
				printf("Invalid value. \r\n\r\n");
				printf(
						"> Press Enter to return to main menu:\r\n ");
				return;
			}
		}
		scan_dur = atol(input_char2);
		if ((scan_dur >= 0) && (scan_dur <= 14)) {
			nlme_set_request(nwkScanDuration, 0, &scan_dur,
					(FUNC_PTR)nlme_set_confirm
					);
		} else {
			printf("Invalid value. \r\n\r\n");
			printf("> Press Enter to return to main menu:\r\n ");
			return;
		}
	}
	break;

	default:
		printf("Invalid input\r\n");
	}
	printf("\r\n\r\n");
	printf("> Press Enter to return to main menu:\r\n ");
}
Ejemplo n.º 6
0
/**
 * @brief Main function of the coordinator application
 *
 * This function initializes the MAC, initiates a MLME reset request
 * (@ref wpan_mlme_reset_req()), and implements a the main loop.
 */
int main(void)
{	
	irq_initialize_vectors();
	#if SAMD20
	system_init();
	delay_init();
	#else
	sysclk_init();

	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
	#endif
	#ifdef SIO_HUB
		sio2host_init();
	#endif
	sw_timer_init();

	if (MAC_SUCCESS != wpan_init()) {
		app_alert();
	}

	/* Initialize LEDs. */
	LED_On(LED_START);     /* indicating application is started */
	LED_Off(LED_NWK_SETUP); /* indicating network is started */
	LED_Off(LED_DATA);     /* indicating data transmission */

	cpu_irq_enable();

#ifdef SIO_HUB
	/* Initialize the serial interface used for communication with terminal
	 *program. */

	/* To make sure the Hyper Terminal Connected to the system*/
	sio2host_getchar();

#ifdef BEACON_SUPPORT
printf("\nBeacon_Application\r\n\n");
#else
printf("\nNO Beacon_Application\r\n\n");
#endif
	printf("\nCoordinator\r\n\n");
	print_stack_app_build_features();
#endif /* SIO_HUB */

	sw_timer_get_id(&APP_TIMER_INDIRECT_DATA);
	sw_timer_get_id(&APP_TIMER_BCN_PAYLOAD_UPDATE);
	sw_timer_get_id(&APP_TIMER_BC_DATA);
	#ifdef GTS_SUPPORT
	sw_timer_get_id(&APP_TIMER_GTS_DATA);
    #endif
	/*
	 * Reset the MAC layer to the default values.
	 * This request will cause a mlme reset confirm message ->
	 * usr_mlme_reset_conf
	 */
	wpan_mlme_reset_req(true);

#ifdef GPIO_PUSH_BUTTON_0
	dst_addr.AddrMode = 2;
	dst_addr.PANId = DEFAULT_PAN_ID;
#endif /* GPIO_PUSH_BUTTON_0 */

	while (true) {
		wpan_task();
#ifdef GPIO_PUSH_BUTTON_0
		if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_0)) {
			delay_ms(DEBOUNCE_DELAY_MS);
			if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_0)) {
				dst_addr.Addr.short_address = BROADCAST;
				wpan_mcps_data_req(FCF_SHORT_ADDR, &dst_addr,
						strlen(broadcast_payload),
						(uint8_t *)&broadcast_payload, 1,
						WPAN_TXOPT_OFF);
			}
		}

#endif /* GPIO_PUSH_BUTTON_0 */
	}
}
Ejemplo n.º 7
0
/**
 * @brief Main function of the device application
 */
int main(void)
{
    irq_initialize_vectors();
#if SAMD || SAMR21
    system_init();
    delay_init();
#else
    sysclk_init();

    /* Initialize the board.
     * The board-specific conf_board.h file contains the configuration of
     * the board initialization.
     */
    board_init();
#endif
#ifdef SIO_HUB
    sio2host_init();
#endif
    sw_timer_init();

    if (MAC_SUCCESS != wpan_init()) {
        app_alert();
    }

    /* Initialize LEDs. */
    LED_On(LED_START);     /* indicating application is started */
    LED_Off(LED_NWK_SETUP); /* indicating network is started */
    LED_Off(LED_DATA);     /* indicating data transmission */
    cpu_irq_enable();
#ifdef SIO_HUB

    /* Initialize the serial interface used for communication with terminal
     * program. */

    /* To Make sure the Hyper Terminal to the System */
    sio2host_getchar();

    printf("\nBeacon_Application\r\n\n");
    printf("\nDevice\r\n\n");
    print_stack_app_build_features();
#endif

    sw_timer_get_id(&APP_TIMER);

    wpan_mlme_reset_req(true);
#ifdef ENABLE_SLEEP
    sw_timer_get_id(&APP_TIMER_SLEEP);
#endif
    LED_Off(LED_NWK_SETUP);
    while (true) {
        wpan_task();
#if (defined ENABLE_SLEEP || defined RTC_SLEEP)
        /* Requesting MAC for Sleep Duration*/
        sleep_time = mac_ready_to_sleep();
        if ((sleep_time > (uint32_t)APP_GUARD_TIME_US)) {
            /*Entering Power save Mode when the sleep duration is
             * above the guard time*/
            enter_sleep(sleep_time);
        }
#endif
    }
}