Re: [PATCHv3 3/6] shared/hfp: Add get_number implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Marcin,

> User can call this function with hfp_gw_result, which will
> be passed to prefix handler.
> ---
> src/shared/hfp.c | 33 +++++++++++++++++++++++++++++++++
> src/shared/hfp.h |  2 ++
> 2 files changed, 35 insertions(+)
> 
> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
> index 8feaf16..d168ac4 100644
> --- a/src/shared/hfp.c
> +++ b/src/shared/hfp.c
> @@ -218,6 +218,39 @@ done:
> 	return true;
> }
> 
> +static void next_field(struct hfp_gw_result *result)
> +{
> +	if (result->data[result->offset] == ',')
> +		result->offset++;
> +}
> +
> +bool hfp_gw_result_get_number(struct hfp_gw_result *result, int *val)
> +{
> +	int temp = 0;
> +	int i;

	int i, tmp = 0;

> +
> +	skip_whitespace(result);
> +
> +	i = result->offset;
> +
> +	while (result->data[i] >= '0' && result->data[i] <= '9') {
> +		temp *= 10;
> +		temp += result->data[i++] - '0’;

	tmp = (tmp * 10) + (result->data[i++] - ‘0’;

This should be the cheaper operation since tmp does not need be reevaluated twice.

Are we going to support negative number? I do not even remember if they are valid in AT commands. Has been too long. Might also go straight to unsigned int *val in that case.

Regards

Marcel

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux