예제 #1
0
/**@brief Function for adding the Bond Management Feature characteristic.
 *
 * @param[in]   p_bms       Bond Management Service structure.
 * @param[in]   p_bms_init  Information needed to initialize the service.
 *
 * @return  NRF_SUCCESS on success, otherwise an error code returned by @ref characteristic_add.
 */
static ret_code_t feature_char_add(nrf_ble_bms_t * p_bms, nrf_ble_bms_init_t const * p_bms_init)
{
    uint8_t                  encoded_feature[NRF_BLE_BMS_FEATURE_LEN];
    uint8_t                  init_value_len;
    ble_add_char_params_t    add_char_params;
    nrf_ble_bms_features_t * p_feature = &p_bms->feature;

    if ((p_feature->delete_all_auth) ||
        (p_feature->delete_all_but_requesting_auth) ||
        (p_feature->delete_requesting_auth))
    {
        VERIFY_PARAM_NOT_NULL(p_bms_init->evt_handler);
    }

    if ((p_feature->delete_requesting_auth) ||
        (p_feature->delete_requesting))
    {
        VERIFY_PARAM_NOT_NULL(p_bms_init->bond_callbacks.delete_requesting);
    }

    if ((p_feature->delete_all) ||
        (p_feature->delete_all_auth))
    {
        VERIFY_PARAM_NOT_NULL(p_bms_init->bond_callbacks.delete_all);
    }

    if ((p_feature->delete_all_but_requesting) ||
        (p_feature->delete_all_but_requesting_auth))
    {
        VERIFY_PARAM_NOT_NULL(p_bms_init->bond_callbacks.delete_all_except_requesting);
    }

    init_value_len = feature_encode(&p_bms->feature, encoded_feature);

    memset(&add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid            = BLE_UUID_BMS_FEATURE;
    add_char_params.char_props.read = true;
    add_char_params.max_len         = init_value_len;
    add_char_params.p_init_value    = encoded_feature;
    add_char_params.init_len        = init_value_len;
    add_char_params.read_access     = p_bms_init->bms_feature_sec_req;
    add_char_params.write_access    = SEC_NO_ACCESS;

    return characteristic_add(p_bms->service_handle, &add_char_params, &p_bms->feature_handles);
}
예제 #2
0
파일: feature.c 프로젝트: IlyaLab/kramtools
int main( int argc, char *argv[] ) {

	int exit_status = EXIT_FAILURE;
	const int FIELD_SEP
		= getenv("SEPARATOR")
		? getenv("SEPARATOR")[0]
		: '\t';

	struct feature f = {
		.length = 0,
		//.buf.num: NULL,
		.expect_row_labels =  true,
		.missing_data_regex = mtm_default_NA_regex,
		.interpret_prefix =   mtm_sclass_by_prefix,
		.max_cardinality =    32,
		.category_labels =    NULL
	};

	char  *line = NULL;
	size_t blen = 0;
	ssize_t llen;
	FILE *input = stdin;
	do {
		static const char *CHAR_OPTIONS 
			= "rm:k:v:?";
		static struct option LONG_OPTIONS[] = {

			{"nolabels",   0,0,'r'},
			{"missing",    1,0,'m'},
			{"maxcats",    1,0,'k'},

			{"verbosity",  1,0,'v'},
			{ NULL,        0,0, 0 }
		};

		int opt_offset = 0;
		const int c = getopt_long( argc, argv, CHAR_OPTIONS, LONG_OPTIONS, &opt_offset );
		switch (c) {

		case 'r': f.expect_row_labels  = false;        break;
		case 'm': f.missing_data_regex = optarg;       break;
		case 'k': f.max_cardinality    = atoi(optarg); break;
		case 'v':
			//opt_verbosity = atoi( optarg );
			break;
		case -1: // ...signals no more options.
			break;
		default:
			printf ("error: unknown option: %c\n", c );
			exit(-1);
		}
		if( -1 == c ) break;

	} while( true );

	if( optind < argc ) {
		const char *fname = argv[optind];
		input = fopen( fname, "r" );
		if( input == NULL )
			err( -1, "opening %s", fname );
	}

	// Note that getline will block until it sees a NL if input is a pipe.

	llen = getline( &line, &blen, input );

	// feature_encode expects NUL-terminated strings, stripped of CR/NL.

	if( line[llen-1] == '\n' ) line[--llen] = '\0';

	if( llen > 0 && line != NULL ) {

		int ec = MTM_OK;
		struct mtm_descriptor d;

		f.length 
			= feature_count_fields( line, FIELD_SEP )
			- ( f.expect_row_labels ? 1 : 0 );

		if( (ec = feature_alloc_encode_state( &f ) ) == 0 ) {

			if( (ec = feature_encode( line, &f, &d ) ) == 0 ) {

				_emit( line, &f, &d, stdout );
				exit_status = EXIT_SUCCESS;

			} else
				warnx( "error %d: feature_encode", ec );

			feature_free_encode_state( &f );

		} else
			warnx( "error %d: feature_alloc_encode_state", ec );

		free( line );

	} else
		warnx( "no input" );

	return exit_status;
}