Hi Lars,

So why not just run iter_next_range in a loop?  it actually understands both
lists and ranges.  See cind_support_cb() for an example.

Ok, I can do this i a loop if you want.

+       /* if min1 == max1 we had no range but a list and that
+        * means we are interested in the last number of that list*/
+       if (min1 == max1) {
+               while (!g_at_result_iter_close_list(&iter)) {
+                       if (!g_at_result_iter_next_number(&iter, &max1))
+                               break;
+               }
+       }
+
+       if (!g_at_result_iter_skip_next(&iter)) {
+               two_arguments = false;
+               goto out;
+       }

Not sure what this is doing?  isn't +CGEREP just two lists ?  According to 
27.007:
"+CGEREP: (list of supported <mode>s),(list of supported <bfr>s)"

Well, we have to deal with very different +CGEREP results. For example
on the quectel EC21 I get this:

"+CGEREP: (0-2),(0,1)"

and on the quectel M95 I get this:

"+CGEREP: (0,1)"

So what the code does is this:
It tries to parse a range with

g_at_result_iter_next_range(&iter, &min1, &max1)

Now two things can happen: It either parsed the range "(0-2)" then we
have min1 != max1, or it tried to parse a list "(0,1)". This time
iter_next_range() breaks on the comma ',' and exits with
min1 == max1 == 0. Then we know, we did not find the maximum value yet
and we enter the loop:

▸··▸·······while (!g_at_result_iter_close_list(&iter)) {
▸··▸·······▸·······if (!g_at_result_iter_next_number(&iter, &max1))
▸··▸·······▸·······▸·······break;
▸··▸·······}

This does then loop to the end of the list until iter_close_list()
becomes true, which is at the closing paranthesis ')'. max1 then
contains the last item in that list (which we suspect to be the
maximum value).

So in theory this could be written like:
int max = -1;
iter_open_list(&iter);

while (iter_next_range(&iter, &max1, &max2)) {
        if (max2 > max)
                max = max2;
}

iter_close_list(&iter);


Now we have min1 and max1 in both cases(list and range). Now if

g_at_result_iter_skip_next()

fails, we are at the end of the AT result and we had only one argument
to +CGEREP or we start trying to parse the second argument also. (See
below.)

At the end we construct our AT+CGEREP= string depending on if we had
two or only one argument.

or you could take the above code I suggested followed by something like:

if (!iter_open_list(&iter)) {
        twoargs = false;
        goto done;
}

while (iter_next_range(...)) {
...
}

iter_close_list(&iter);

...

Regards,
-Denis
_______________________________________________
ofono mailing list -- ofono@ofono.org
To unsubscribe send an email to ofono-le...@ofono.org

Reply via email to