* [PATCH 5/7] cdmamodem: Add Signal Strength Support
@ 2011-02-08 21:04 Dara Spieker-Doyle
2011-02-09 22:58 ` Rajesh.Nagaiah
0 siblings, 1 reply; 4+ messages in thread
From: Dara Spieker-Doyle @ 2011-02-08 21:04 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 7226 bytes --]
---
Makefile.am | 3 +-
drivers/cdmamodem/cdmamodem.c | 2 +
drivers/cdmamodem/cdmamodem.h | 2 +
drivers/cdmamodem/network-registration.c | 211 ++++++++++++++++++++++++++++++
4 files changed, 217 insertions(+), 1 deletions(-)
create mode 100644 drivers/cdmamodem/network-registration.c
diff --git a/Makefile.am b/Makefile.am
index c245b4c..272e28d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -257,7 +257,8 @@ builtin_modules += cdmamodem
builtin_sources += drivers/cdmamodem/cdmamodem.h \
drivers/cdmamodem/cdmamodem.c \
drivers/cdmamodem/voicecall.c \
- drivers/cdmamodem/devinfo.c
+ drivers/cdmamodem/devinfo.c \
+ drivers/cdmamodem/network-registration.c
endif
builtin_modules += g1
diff --git a/drivers/cdmamodem/cdmamodem.c b/drivers/cdmamodem/cdmamodem.c
index 9eddd88..492f1f0 100644
--- a/drivers/cdmamodem/cdmamodem.c
+++ b/drivers/cdmamodem/cdmamodem.c
@@ -36,6 +36,7 @@ static int cdmamodem_init(void)
{
cdma_voicecall_init();
cdma_devinfo_init();
+ cdma_netreg_init();
return 0;
}
@@ -44,6 +45,7 @@ static void cdmamodem_exit(void)
{
cdma_voicecall_exit();
cdma_devinfo_exit();
+ cdma_netreg_exit();
}
OFONO_PLUGIN_DEFINE(cdmamodem, "CDMA AT modem driver", VERSION,
diff --git a/drivers/cdmamodem/cdmamodem.h b/drivers/cdmamodem/cdmamodem.h
index 4365bec..a1fbf65 100644
--- a/drivers/cdmamodem/cdmamodem.h
+++ b/drivers/cdmamodem/cdmamodem.h
@@ -25,3 +25,5 @@ extern void cdma_voicecall_init(void);
extern void cdma_voicecall_exit(void);
extern void cdma_devinfo_init(void);
extern void cdma_devinfo_exit(void);
+extern void cdma_netreg_init(void);
+extern void cdma_netreg_exit(void);
diff --git a/drivers/cdmamodem/network-registration.c b/drivers/cdmamodem/network-registration.c
new file mode 100644
index 0000000..4135fe1
--- /dev/null
+++ b/drivers/cdmamodem/network-registration.c
@@ -0,0 +1,211 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2011 Nokia Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <glib.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/cdma-netreg.h>
+
+#include "gatchat.h"
+#include "gatresult.h"
+
+#include "cdmamodem.h"
+
+/* Time interval in seconds between CSQ polls */
+#define CSQ_INTERVAL 5
+
+struct cdma_netreg_data {
+ GAtChat *chat;
+ unsigned int vendor;
+ unsigned int csq_source;
+};
+
+static gboolean cdma_get_next_number(const char *line, gint *number)
+{
+ int pos;
+ int end;
+ int len;
+ int value = 0;
+
+ len = strlen(line);
+
+ pos = 0;
+ end = pos;
+
+ while (line[end] >= '0' && line[end] <= '9') {
+ value = value * 10 + (int)(line[end] - '0');
+ end += 1;
+ }
+
+ if (pos == end)
+ return FALSE;
+
+ pos = skip_to_next_field(line, end, len);
+
+ if (number)
+ *number = value;
+
+ return TRUE;
+}
+
+static void cdma_csq_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct cb_data *cbd = user_data;
+ ofono_cdma_netreg_strength_cb_t cb = cbd->cb;
+ const char *prefix = cbd->user;
+ struct ofono_error error;
+ const char *attr;
+ int strength = -1;
+
+ decode_at_error(&error, g_at_result_final_response(result));
+
+ if (!ok) {
+ cb(&error, -1, cbd->data);
+ return;
+ }
+
+ if (at_util_parse_attr(result, prefix, &attr) == FALSE) {
+ CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+ return;
+ }
+
+ cdma_get_next_number(attr, &strength);
+
+ DBG("csq_cb: %d", strength);
+
+ cb(&error, at_util_convert_signal_strength(strength), cbd->data);
+}
+
+static void cdma_signal_strength(struct ofono_cdma_netreg *netreg,
+ ofono_cdma_netreg_strength_cb_t cb, void *data)
+{
+ struct cdma_netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+ struct cb_data *cbd = cb_data_new(cb, data);
+
+ cbd->user = "AT+CSQ";
+
+ if (g_at_chat_send(nd->chat, "AT+CSQ", NULL,
+ cdma_csq_cb, cbd, g_free) > 0)
+ return;
+
+ g_free(cbd);
+
+ CALLBACK_WITH_FAILURE(cb, -1, data);
+}
+
+static gboolean cdma_poll_csq(gpointer user_data);
+
+static void cdma_poll_csq_cb(const struct ofono_error *error, int strength,
+ void *data)
+{
+ struct ofono_cdma_netreg *netreg = data;
+ struct cdma_netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+
+ if(error->type == OFONO_ERROR_TYPE_NO_ERROR)
+ ofono_cdma_netreg_strength_notify(netreg, strength);
+
+ /* Initiate the next poll */
+ nd->csq_source = g_timeout_add_seconds(CSQ_INTERVAL, cdma_poll_csq, netreg);
+}
+
+static gboolean cdma_poll_csq(gpointer user_data)
+{
+ struct ofono_cdma_netreg *netreg = user_data;
+ struct cdma_netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+ struct cb_data *cbd = cb_data_new(cdma_poll_csq_cb, netreg);
+
+ cbd->user = "AT+CSQ";
+
+ g_at_chat_send(nd->chat, "AT+CSQ", NULL, cdma_csq_cb, cbd, g_free);
+
+ nd->csq_source = 0;
+
+ return FALSE;
+}
+
+static gboolean cdma_netreg_register(gpointer user_data)
+{
+ struct ofono_cdma_netreg *netreg = user_data;
+ struct cdma_netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+
+ ofono_cdma_netreg_register(netreg);
+
+ nd->csq_source = g_timeout_add_seconds(CSQ_INTERVAL, cdma_poll_csq, netreg);
+
+ return FALSE;
+}
+
+static int cdma_netreg_probe(struct ofono_cdma_netreg *netreg,
+ unsigned int vendor, void *data)
+{
+ GAtChat *chat = data;
+ struct cdma_netreg_data *nd;
+
+ nd = g_new0(struct cdma_netreg_data, 1);
+
+ nd->chat = g_at_chat_clone(chat);
+ nd->vendor = vendor;
+
+ ofono_cdma_netreg_set_data(netreg, nd);
+ g_idle_add(cdma_netreg_register, netreg);
+
+ return 0;
+}
+
+static void cdma_netreg_remove(struct ofono_cdma_netreg *netreg)
+{
+ struct cdma_netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+
+ if (nd->csq_source)
+ g_source_remove(nd->csq_source);
+
+ ofono_cdma_netreg_set_data(netreg, NULL);
+
+ g_at_chat_unref(nd->chat);
+ g_free(nd);
+}
+
+static struct ofono_cdma_netreg_driver driver = {
+ .name = "cdmamodem",
+ .probe = cdma_netreg_probe,
+ .remove = cdma_netreg_remove,
+ .strength = cdma_signal_strength,
+};
+
+void cdma_netreg_init(void)
+{
+ ofono_cdma_netreg_driver_register(&driver);
+}
+
+void cdma_netreg_exit(void)
+{
+ ofono_cdma_netreg_driver_unregister(&driver);
+}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH 5/7] cdmamodem: Add Signal Strength Support
2011-02-08 21:04 Dara Spieker-Doyle
@ 2011-02-09 22:58 ` Rajesh.Nagaiah
0 siblings, 0 replies; 4+ messages in thread
From: Rajesh.Nagaiah @ 2011-02-09 22:58 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1747 bytes --]
Hi Dara,
> -----Original Message-----
> From: ofono-bounces(a)ofono.org
> [mailto:ofono-bounces(a)ofono.org] On Behalf Of Dara Spieker-Doyle
> Sent: 08 February 2011 13:05
> To: ofono(a)ofono.org
> Subject: [PATCH 5/7] cdmamodem: Add Signal Strength Support
>
> +static gboolean cdma_get_next_number(const char *line, gint
> *number) {
> + int pos;
> + int end;
> + int len;
> + int value = 0;
> +
> + len = strlen(line);
> +
> + pos = 0;
> + end = pos;
> +
> + while (line[end] >= '0' && line[end] <= '9') {
> + value = value * 10 + (int)(line[end] - '0');
> + end += 1;
> + }
> +
> + if (pos == end)
> + return FALSE;
> +
> + pos = skip_to_next_field(line, end, len);
> +
> + if (number)
> + *number = value;
> +
> + return TRUE;
> +}
> +
This is a duplicate of g_at_result_iter_next_number().
Why cant use this function instead of cdma_get_next_number() ?
> +static void cdma_csq_cb(gboolean ok, GAtResult *result, gpointer
> +user_data) {
> + struct cb_data *cbd = user_data;
> + ofono_cdma_netreg_strength_cb_t cb = cbd->cb;
> + const char *prefix = cbd->user;
> + struct ofono_error error;
> + const char *attr;
> + int strength = -1;
> +
> + decode_at_error(&error, g_at_result_final_response(result));
> +
> + if (!ok) {
> + cb(&error, -1, cbd->data);
> + return;
> + }
> +
> + if (at_util_parse_attr(result, prefix, &attr) == FALSE) {
> + CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
> + return;
> + }
> +
> + cdma_get_next_number(attr, &strength);
> +
> + DBG("csq_cb: %d", strength);
> +
> + cb(&error, at_util_convert_signal_strength(strength),
> cbd->data); }
Refer csq_cb() implementation in /drivers/atmodem/network-registration.c
BR,
Rajesh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 5/7] cdmamodem: Add Signal Strength Support
@ 2011-02-10 2:54 Dara Spieker-Doyle
0 siblings, 0 replies; 4+ messages in thread
From: Dara Spieker-Doyle @ 2011-02-10 2:54 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2928 bytes --]
Hi Rajesh
On 02/09/2011 02:58 PM, ext Rajesh.Nagaiah(a)elektrobit.com wrote:
> Hi Dara,
>
>> -----Original Message-----
>> From: ofono-bounces(a)ofono.org
>> [mailto:ofono-bounces(a)ofono.org] On Behalf Of Dara Spieker-Doyle
>> Sent: 08 February 2011 13:05
>> To: ofono(a)ofono.org
>> Subject: [PATCH 5/7] cdmamodem: Add Signal Strength Support
>>
>
>> +static gboolean cdma_get_next_number(const char *line, gint
>> *number) {
>> + int pos;
>> + int end;
>> + int len;
>> + int value = 0;
>> +
>> + len = strlen(line);
>> +
>> + pos = 0;
>> + end = pos;
>> +
>> + while (line[end]>= '0'&& line[end]<= '9') {
>> + value = value * 10 + (int)(line[end] - '0');
>> + end += 1;
>> + }
>> +
>> + if (pos == end)
>> + return FALSE;
>> +
>> + pos = skip_to_next_field(line, end, len);
>> +
>> + if (number)
>> + *number = value;
>> +
>> + return TRUE;
>> +}
>> +
>
> This is a duplicate of g_at_result_iter_next_number().
> Why cant use this function instead of cdma_get_next_number() ?
This is different from g_at_result_iter_next_number() in that it takes a
raw response line to parse rather than the result iterator. The AT
syntax format of the response from this CDMA device does not follow the
GSM standard AT syntax format.
>
>> +static void cdma_csq_cb(gboolean ok, GAtResult *result, gpointer
>> +user_data) {
>> + struct cb_data *cbd = user_data;
>> + ofono_cdma_netreg_strength_cb_t cb = cbd->cb;
>> + const char *prefix = cbd->user;
>> + struct ofono_error error;
>> + const char *attr;
>> + int strength = -1;
>> +
>> + decode_at_error(&error, g_at_result_final_response(result));
>> +
>> + if (!ok) {
>> + cb(&error, -1, cbd->data);
>> + return;
>> + }
>> +
>> + if (at_util_parse_attr(result, prefix,&attr) == FALSE) {
>> + CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
>> + return;
>> + }
>> +
>> + cdma_get_next_number(attr,&strength);
>> +
>> + DBG("csq_cb: %d", strength);
>> +
>> + cb(&error, at_util_convert_signal_strength(strength),
>> cbd->data); }
>
> Refer csq_cb() implementation in /drivers/atmodem/network-registration.c
>
If you are referring to the AT result iterator use in the atmodem csq
callback:- we cannot use that here due to the response format of this
CDMA device not being the same as the GSM standard.
The prefix in this case is not in the same line as the actual response
line, so I opted to use the same algorithm as attr_cb() in
/drivers/cdmamodem/devinfo for now and re-use at_util_parse_attr(),
taking the last line as the response.
This could well need to be extended for alternative CDMA AT devices
added in the future, as the CDMA AT syntax is not standardised.
Cheers
Dara
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH 5/7] cdmamodem: Add Signal Strength Support
[not found] <4D535000.1000301@gmail.com>
@ 2011-02-10 4:16 ` Rajesh.Nagaiah
0 siblings, 0 replies; 4+ messages in thread
From: Rajesh.Nagaiah @ 2011-02-10 4:16 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 3518 bytes --]
Hi Dara,
> -----Original Message-----
> From: Dara Spieker-Doyle [mailto:dara.spiekerdoyle(a)gmail.com]
>
> Hi Rajesh
>
> On 02/09/2011 02:58 PM, ext Rajesh.Nagaiah(a)elektrobit.com wrote:
>
> > Hi Dara,
> >
> >> -----Original Message-----
> >> From: ofono-bounces(a)ofono.org
> >> [mailto:ofono-bounces(a)ofono.org] On Behalf Of Dara Spieker-Doyle
> >> Sent: 08 February 2011 13:05
> >> To: ofono(a)ofono.org
> >> Subject: [PATCH 5/7] cdmamodem: Add Signal Strength Support
> >>
> >
> >> +static gboolean cdma_get_next_number(const char *line, gint
> >> *number) {
> >> + int pos;
> >> + int end;
> >> + int len;
> >> + int value = 0;
> >> +
> >> + len = strlen(line);
> >> +
> >> + pos = 0;
> >> + end = pos;
> >> +
> >> + while (line[end]>= '0'&& line[end]<= '9') {
> >> + value = value * 10 + (int)(line[end] - '0');
> >> + end += 1;
> >> + }
> >> +
> >> + if (pos == end)
> >> + return FALSE;
> >> +
> >> + pos = skip_to_next_field(line, end, len);
> >> +
> >> + if (number)
> >> + *number = value;
> >> +
> >> + return TRUE;
> >> +}
> >> +
> >
> > This is a duplicate of g_at_result_iter_next_number().
> > Why cant use this function instead of cdma_get_next_number() ?
>
> This is different from g_at_result_iter_next_number() in that
> it takes a raw response line to parse rather than the result
> iterator. The AT syntax format of the response from this CDMA
> device does not follow the GSM standard AT syntax format.
>
> >
> >> +static void cdma_csq_cb(gboolean ok, GAtResult *result, gpointer
> >> +user_data) {
> >> + struct cb_data *cbd = user_data;
> >> + ofono_cdma_netreg_strength_cb_t cb = cbd->cb;
> >> + const char *prefix = cbd->user;
> >> + struct ofono_error error;
> >> + const char *attr;
> >> + int strength = -1;
> >> +
> >> + decode_at_error(&error, g_at_result_final_response(result));
> >> +
> >> + if (!ok) {
> >> + cb(&error, -1, cbd->data);
> >> + return;
> >> + }
> >> +
> >> + if (at_util_parse_attr(result, prefix,&attr) == FALSE) {
> >> + CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
> >> + return;
> >> + }
> >> +
> >> + cdma_get_next_number(attr,&strength);
> >> +
> >> + DBG("csq_cb: %d", strength);
> >> +
> >> + cb(&error, at_util_convert_signal_strength(strength),
> >> cbd->data); }
> >
> > Refer csq_cb() implementation in
> > /drivers/atmodem/network-registration.c
> >
>
> If you are referring to the AT result iterator use in the atmodem csq
> callback:- we cannot use that here due to the response format
> of this CDMA device not being the same as the GSM standard.
> The prefix in this case is actually not in the same line as
> the actual response line, so I just opted to use the same
> algorithm as attr_cb() in /drivers/cdmamodem/devinfo for now
> and re-use at_util_parse_attr(), taking the last line as the response.
> This could well need to be extended for alternative CDMA AT
> devices added in the future, as the CDMA AT syntax is not
> standardised.
Can you send whats the actual result of AT+CSQ from the modem ?
If the last line is going to be only one number value, then you
can use some utility function to convert that string to a numeric value,
rather than duplicating g_at_result_iter_next_number() logic.
BR,
Rajesh
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-02-10 4:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-10 2:54 [PATCH 5/7] cdmamodem: Add Signal Strength Support Dara Spieker-Doyle
[not found] <4D535000.1000301@gmail.com>
2011-02-10 4:16 ` Rajesh.Nagaiah
-- strict thread matches above, loose matches on Subject: below --
2011-02-08 21:04 Dara Spieker-Doyle
2011-02-09 22:58 ` Rajesh.Nagaiah
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.