[PATCH 5/9] shared/hfp_at: Add function for getting number

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

 



It will fetch decimal value from AT command.
---
 src/shared/hfp_at.c | 40 ++++++++++++++++++++++++++++++++++++++++
 src/shared/hfp_at.h |  2 ++
 2 files changed, 42 insertions(+)

diff --git a/src/shared/hfp_at.c b/src/shared/hfp_at.c
index eff0a38..623dab3 100644
--- a/src/shared/hfp_at.c
+++ b/src/shared/hfp_at.c
@@ -206,6 +206,46 @@ bool hfp_at_process_data(struct hfp_at *hfp_at, const char *data,
 		return hfp_at_process_basic(hfp_at, data, user_data);
 }
 
+static void hfp_at_next_field(struct hfp_at *hfp_at, const char *data)
+{
+	if (data[hfp_at->offset] == ',')
+		hfp_at->offset++;
+}
+
+static void hfp_at_skip_whitespace(struct hfp_at *hfp_at, const char *data)
+{
+	while (data[hfp_at->offset] == ' ')
+		hfp_at->offset++;
+}
+
+bool hfp_at_get_number(struct hfp_at *hfp_at, const char *data, int *val)
+{
+	int temp = 0;
+	int i;
+
+	hfp_at_skip_whitespace(hfp_at, data);
+
+	i = hfp_at->offset;
+
+	while (data[i] >= '0' && data[i] <= '9') {
+		temp *= 10;
+		temp += data[i++] - '0';
+	}
+
+	if (i == hfp_at->offset)
+		return false;
+
+	if (val)
+		*val = temp;
+
+	hfp_at->offset = i;
+
+	hfp_at_skip_whitespace(hfp_at, data);
+	hfp_at_next_field(hfp_at, data);
+
+	return true;
+}
+
 struct hfp_at *hfp_at_new(const struct hfp_at_handler *handlers)
 {
 	struct hfp_at *hfp_at;
diff --git a/src/shared/hfp_at.h b/src/shared/hfp_at.h
index 0b628b5..2e2a757 100644
--- a/src/shared/hfp_at.h
+++ b/src/shared/hfp_at.h
@@ -42,5 +42,7 @@ struct hfp_at_handler {
 bool hfp_at_process_data(struct hfp_at *hfp_at, const char *data,
 							void *user_data);
 
+bool hfp_at_get_number(struct hfp_at *hfp_at, const char *data, int *val);
+
 struct hfp_at *hfp_at_new(const struct hfp_at_handler *handlers);
 void hfp_at_free(struct hfp_at *hfp_at);
-- 
1.8.5.3

--
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