Skip to contentSkip to conversation

add support of void parameters in CMER

PATCH In review Frédéric Danis 2 participants 4 messages Feb 24, 2011

lore
Share & tools
lore
#0 lore raw

v2 cover add support of void parameters in CMER

following commands are supported :
AT+CMER=3,0,0,1,0

OK
AT+CMER=3,0,0,1

OK
AT+CMER=3,,,1

OK
AT+CMER=3,,,1,

OK
AT+CMER=,,0,1,

OK
AT+CMER=3, ,,1

OK
AT+CMER=3,a,0,1

ERROR
AT+CMER=3,"a",0,1

ERROR
AT+CMER=3,

OK
AT+CMER=3

OK

Frédéric Danis (2):
gatchat: add g_at_result_iter_next_number_default API
emulator: add support of void parameters in CMER

 gatchat/gatresult.c |   30 ++++++++++++++++++++++++++++++
 gatchat/gatresult.h |    2 ++
 src/emulator.c      |   24 ++++++++++++------------
 3 files changed, 44 insertions(+), 12 deletions(-)
#1 lore raw

PATCH v2 1/2 gatchat: add g_at_result_iter_next_number_default API

---
 gatchat/gatresult.c |   30 ++++++++++++++++++++++++++++++
 gatchat/gatresult.h |    2 ++
 2 files changed, 32 insertions(+), 0 deletions(-)
gatchat/gatresult.c +30 -0
index 8a6dfae..f992486 100644
@@ -292,6 +292,36 @@ gboolean g_at_result_iter_next_number(GAtResultIter *iter, gint *number)
 	return TRUE;
 }
 
+gboolean g_at_result_iter_next_number_default(GAtResultIter *iter, gint dflt,
+						gint *number)
+{
+	unsigned int pos;
+	int len;
+	char *line;
+
+	if (iter == NULL)
+		return FALSE;
+
+	if (iter->l == NULL)
+		return FALSE;
+
+	line = iter->l->data;
+	len = strlen(line);
+
+	pos = skip_to_next_field(line, iter->line_pos, len);
+
+	if (pos != iter->line_pos) {
+		iter->line_pos = pos;
+
+		if (number)
+			*number = dflt;
+
+		return TRUE;
+	}
+
+	return g_at_result_iter_next_number(iter, number);
+}
+
 gboolean g_at_result_iter_next_range(GAtResultIter *iter, gint *min, gint *max)
 {
 	int pos;
gatchat/gatresult.h +2 -0
index a74741f..f498c86 100644
@@ -58,6 +58,8 @@ gboolean g_at_result_iter_next_string(GAtResultIter *iter, const char **str);
 gboolean g_at_result_iter_next_unquoted_string(GAtResultIter *iter,
 						const char **str);
 gboolean g_at_result_iter_next_number(GAtResultIter *iter, gint *number);
+gboolean g_at_result_iter_next_number_default(GAtResultIter *iter, gint dflt,
+						gint *number);
 gboolean g_at_result_iter_next_hexstring(GAtResultIter *iter,
 		const guint8 **str, gint *length);
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 2/2 emulator: add support of void parameters in CMER

In reply to Frédéric Danis
---
 src/emulator.c |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)
src/emulator.c +12 -12
index 9cd3252..20a575f 100644
@@ -312,7 +312,7 @@ static void cmer_cb(GAtServer *server, GAtServerRequestType type,
 	case G_AT_SERVER_REQUEST_TYPE_SET:
 	{
 		GAtResultIter iter;
-		int mode;
+		int mode = em->events_mode;
 		int ind = em->events_ind;
 		int val;
 
@@ -320,15 +320,15 @@ static void cmer_cb(GAtServer *server, GAtServerRequestType type,
 		g_at_result_iter_next(&iter, "");
 
 		/* mode */
-		if (g_at_result_iter_next_number(&iter, &mode) == FALSE)
+		if (!g_at_result_iter_next_number_default(&iter, mode, &mode))
 			goto fail;
 
 		if (mode != 0 && mode != 3)
 			goto fail;
 
 		/* keyp */
-		if (g_at_result_iter_next_number(&iter, &val) == FALSE) {
-			if (g_at_result_iter_skip_next(&iter) == FALSE)
+		if (!g_at_result_iter_next_number_default(&iter, 0, &val)) {
+			if (!g_at_result_iter_skip_next(&iter))
 				goto done;
 			goto fail;
 		}
@@ -337,8 +337,8 @@ static void cmer_cb(GAtServer *server, GAtServerRequestType type,
 			goto fail;
 
 		/* disp */
-		if (g_at_result_iter_next_number(&iter, &val) == FALSE) {
-			if (g_at_result_iter_skip_next(&iter) == FALSE)
+		if (!g_at_result_iter_next_number_default(&iter, 0, &val)) {
+			if (!g_at_result_iter_skip_next(&iter))
 				goto done;
 			goto fail;
 		}
@@ -347,18 +347,18 @@ static void cmer_cb(GAtServer *server, GAtServerRequestType type,
 			goto fail;
 
 		/* ind */
-		if (g_at_result_iter_next_number(&iter, &ind) == FALSE) {
-			if (g_at_result_iter_skip_next(&iter) == FALSE)
+		if (!g_at_result_iter_next_number_default(&iter, ind, &ind)) {
+			if (!g_at_result_iter_skip_next(&iter))
 				goto done;
 			goto fail;
 		}
 
-		if ((ind != 0) && (ind != 1))
+		if (ind != 0 && ind != 1)
 			goto fail;
 
 		/* bfr */
-		if (g_at_result_iter_next_number(&iter, &val) == FALSE) {
-			if (g_at_result_iter_skip_next(&iter) == FALSE)
+		if (!g_at_result_iter_next_number_default(&iter, 0, &val)) {
+			if (!g_at_result_iter_skip_next(&iter))
 				goto done;
 			goto fail;
 		}
@@ -367,7 +367,7 @@ static void cmer_cb(GAtServer *server, GAtServerRequestType type,
 			goto fail;
 
 		/* check that bfr is last parameter */
-		if (g_at_result_iter_skip_next(&iter) == TRUE)
+		if (g_at_result_iter_skip_next(&iter))
 			goto fail;
 
 done:
Signature · 1 line
1.7.1
#3 lore raw
In reply to Frédéric Danis

Hi Frédéric,

Quoted 32 lines · Frédéric Danis

following commands are supported :
AT+CMER=3,0,0,1,0

OK
AT+CMER=3,0,0,1

OK
AT+CMER=3,,,1

OK
AT+CMER=3,,,1,

OK
AT+CMER=,,0,1,

OK
AT+CMER=3, ,,1

OK
AT+CMER=3,a,0,1

ERROR
AT+CMER=3,"a",0,1

ERROR
AT+CMER=3,

OK
AT+CMER=3

OK

Quoted 9 lines

Frédéric Danis (2):
gatchat: add g_at_result_iter_next_number_default API
emulator: add support of void parameters in CMER

 gatchat/gatresult.c |   30 ++++++++++++++++++++++++++++++
 gatchat/gatresult.h |    2 ++
 src/emulator.c      |   24 ++++++++++++------------
 3 files changed, 44 insertions(+), 12 deletions(-)

Both patches have been applied, thanks.

Regards,
-Denis