Ejemplo n.º 1
0
Archivo: spair.c Proyecto: daersc/spair
static void
parse_args(int argc, char **argv)
{
	int c;
	while ((c = getopt(argc, argv, CL_OPT_STRING)) != -1) {
		switch (c) {
		case 'h':
			print_version();
			print_help();
			exit(EXIT_SUCCESS);
		case 'v':
			print_version();
			exit(EXIT_SUCCESS);
		case 'p': {
			unsigned int count;
			if (!sscanf(optarg, "%u", &count)) {
				perror("Parsing argument failed");
				exit(EXIT_FAILURE);
			}
			print_pairing_table(count);
			exit(EXIT_SUCCESS);
		}
		case ':':
			fprintf(stderr, _("Option -%c requires an argument\n"), optopt);
			exit(EXIT_FAILURE);
		case '?':
			fprintf(stderr, _("Unrecognized option: '-%c'\n"), optopt);
			print_help();
			exit(EXIT_FAILURE);
		}
	}
}
Ejemplo n.º 2
0
/**
 * @brief Notify the application of the status of its request for the value of a
 *        NIB attribute
 *
 * @param Status              nwk status
 * @param NIBAttribute        NIBAttribute
 * @param NIBAttributeIndex   NIBAttributeIndex
 * @param NIBAttributeValue   Value of the NIB attribute.
 */
static void nlme_get_confirm(nwk_enum_t Status, nib_attribute_t NIBAttribute,
		uint8_t NIBAttributeIndex, void *NIBAttributeValue)
{   
	uint8_t channel;
	if (Status == NWK_SUCCESS) {
		switch (NIBAttribute) {
		case nwkPairingTable:
			if (node_status == WARM_STARTING) {
				pairing_table_t *table;
				table = (pairing_table_t *)NIBAttributeValue;
				if (table->DestinationLogicalChannel != 0) {
					number_of_paired_dev++;
				}
			} else {
				print_pairing_table(false, NIBAttributeValue,
						NIBAttributeIndex);
			}

#if (MAX_PAIRED_DEVICES > 1)
			if (NIBAttributeIndex < (MAX_PAIRED_DEVICES - 1)) {
				nlme_get_request(nwkPairingTable,
						NIBAttributeIndex + 1,
						(FUNC_PTR)nlme_get_confirm
						);
			} else {
				printf(
						"> Press Enter to return to main menu: \r\n");
				node_status = previous_node_status;
			}

#else
			printf("> Press Enter to return to main menu: \r\n");
			node_status = previous_node_status;
#endif
			break;

		case nwkPrivateChAgEdThreshold:
			memcpy(&nwk_Private_ChAgEdThreshold, NIBAttributeValue,
					1);
			nlme_get_request(nwkPrivateChAgScanInterval, 0,
					(FUNC_PTR)nlme_get_confirm
					);
			break;

		case nwkPrivateChAgScanInterval:
			memcpy(&nwk_Private_ChAgScanInterval, NIBAttributeValue,
					sizeof(uint32_t));
			nlme_get_request(nwkScanDuration, 0,
					(FUNC_PTR)nlme_get_confirm
					);
			break;

		case nwkScanDuration:
			memcpy(&nwk_ScanDuration, NIBAttributeValue, 1);
			node_status = IDLE;
			print_sub_mode_ch_ag_setup();
			break;
		case nwkBaseChannel:
		    channel = *((uint8_t *)NIBAttributeValue);
		    printf("channel %u\r\n",channel);
			break;

		default:
			break;
		}
	}
}
Ejemplo n.º 3
0
/**
 * @brief Handle keyboard input
 *
 * @param input_char       character typed from input device.
 */
static void handle_input(uint8_t input_char)
{
	/* We allow user input if we are either in IDLE state ot POWER_SAVE
	 * state
	 * In case of POWER_SAVE state, we allow only reset & disabling
	 * POWER_SAVE req*/
	if (((node_status != IDLE) && (node_status != POWER_SAVE)) ||
			((node_status == POWER_SAVE) &&
			(!((input_char == 'Y') || (input_char == 'R') ||
			(input_char == 'A') || (input_char == 'W') ||
			(input_char == 0x0D))))) {
		printf(
				"Node is in power save mode.Press (R) to Reset/Press (Y) to Disable power save mode.\r\n");
		return;
	}

	switch (input_char) {
	case 'Y':
		if (node_status == POWER_SAVE) {
			printf(
					"Leaving standby (power save mode). Press Enter to return to main menu.\r\n ");
			nlme_rx_enable_request(RX_DURATION_INFINITY,
					(FUNC_PTR)nlme_rx_enable_confirm
					);
			node_status = IDLE;
		} else {
			printf(
					"Entering standby (power save mode). Press Enter to return to main menu.\r\n ");
			nlme_rx_enable_request(nwkcMinActivePeriod,
					(FUNC_PTR)nlme_rx_enable_confirm
					);
			node_status = POWER_SAVE;
		}

		break;

	case 'R':
		printf("Reset node - \r\n");
		node_status = RESETTING;
		ch_ag_enabled = false;
		nlme_reset_request(true,
				(FUNC_PTR)nlme_reset_confirm
				);
		break;

	case 'S':
		printf("Start node - \r\n");
		node_status = STARTING;
		nlme_start_request(
				(FUNC_PTR)nlme_start_confirm
				);
		break;

	case 'P':
		printf("Push button pairing -\r\n");
		node_status = PUSH_BUTTON_PAIRING;
		sw_timer_start(led_timer,
				500000,
				SW_TIMEOUT_RELATIVE,
				(FUNC_PTR)led_handling,
				NULL);
		LED_On(LED_NWK_SETUP);
		{
			dev_type_t RecDevTypeList[DEVICE_TYPE_LIST_SIZE];
			profile_id_t RecProfileIdList[PROFILE_ID_LIST_SIZE];

			RecDevTypeList[0] = (dev_type_t)SUPPORTED_DEV_TYPE_0;
			RecProfileIdList[0] = SUPPORTED_PROFILE_ID_0;

			pbp_rec_pair_request(APP_CAPABILITIES, RecDevTypeList,
					RecProfileIdList,
					(FUNC_PTR)pbp_rec_pair_confirm
					);
		}
		break;

	case 'A':
		printf("All-in-one start; wait until done.\r\n");
		node_status = ALL_IN_ONE_START;
		printf("\tReset node - ");
		ch_ag_enabled = false;
		nlme_reset_request(true,
				(FUNC_PTR)nlme_reset_confirm
				);
		break;

	case 'W':
		previous_node_status = node_status;
		printf("Warm start - \r\n");
		node_status = WARM_STARTING;
		nlme_reset_request(false,
				(FUNC_PTR)nlme_reset_confirm
				);
		break;

	case 'T':
		previous_node_status = node_status;
		node_status = PRINTING_PAIRING_TABLE;
		print_pairing_table(true, NULL, 0);
		break;

	case 'U':
		node_status = UNPAIRING;
		print_unpair_submenu();
		break;

	case 'C':
		if (ch_ag_enabled) {
			ch_ag_enabled = false;
			nwk_ch_agility_request(AG_STOP,
					(FUNC_PTR)nwk_ch_agility_confirm
					);
			printf(" - Channel agility is stopped ...\r\n");
		} else {
			ch_ag_enabled = true;
			node_status = CH_AGILITY_EXECUTION;
			printf(" - Channel agility is started ...\r\n");
			nwk_ch_agility_request(AG_PERIODIC,
					(FUNC_PTR)nwk_ch_agility_confirm
					);
		}

		break;

	case 'O':
		/* Start getting the NIBs value */
		node_status = GETTING_CH_AG_NIBS;
		nlme_get_request(nwkPrivateChAgEdThreshold, 0,
				(FUNC_PTR)nlme_get_confirm
				);
		break;

	case 'B':
		print_ch_change_submenu();
		break;

	case 'D':
		print_vendor_data_submenu(BATTERY_STATUS_REQ);
		break;

	case 'V':
		print_vendor_data_submenu(FW_VERSION_REQ);
		break;

	case 'Z':
		print_vendor_data_submenu(ALIVE_REQ);
		break;

	default:
		print_main_menu();
		break;
	}
}