diff options
author | erin_yueh <erin_yueh@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2008-02-21 05:16:15 +0000 |
---|---|---|
committer | erin_yueh <erin_yueh@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2008-02-21 05:16:15 +0000 |
commit | 29a2f6a3b46afb00052a24b05232630acad3af70 (patch) | |
tree | 181b89e02491f52e5d375fa277521cd76382e2f3 | |
parent | 20adbe01bb4d7490436d0294de37b6c12624143b (diff) |
gsmd: get battery status (Sudharshan S)
git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@4091 99fdad57-331a-0410-800a-d7fa5415bdb3
-rw-r--r-- | include/gsmd/usock.h | 14 | ||||
-rw-r--r-- | include/libgsmd/misc.h | 2 | ||||
-rw-r--r-- | src/gsmd/usock.c | 42 | ||||
-rw-r--r-- | src/libgsmd/libgsmd_phone.c | 4 | ||||
-rw-r--r-- | src/libgsmd/libgsmd_pin.c | 2 | ||||
-rw-r--r-- | src/util/shell.c | 10 |
6 files changed, 65 insertions, 9 deletions
diff --git a/include/gsmd/usock.h b/include/gsmd/usock.h index 4263cad..7df22b2 100644 --- a/include/gsmd/usock.h +++ b/include/gsmd/usock.h @@ -139,6 +139,7 @@ enum gsmd_msg_phone { GSMD_PHONE_GET_MODEL = 5, GSMD_PHONE_GET_REVISION = 6, GSMD_PHONE_GET_SERIAL = 7, + GSMD_PHONE_GET_BATTERY = 8, }; enum gsmd_msg_modem { @@ -371,6 +372,14 @@ enum gsmd_toa_reserved { /* Length from 3GPP TS 04.08, Clause 10.5.4.7 */ +/* battery connection status from 3GPP TS 07.07 subclause 8.4 */ +enum gsmd_bat_conn_status { + GSMD_BAT_NORMAL = 0, + GSMD_BAT_NOT_POWERED = 1, + GSMD_BAT_NO_BAT = 2, + GSMD_BAT_POWER_FAULT = 3, +}; + #define GSMD_ADDR_MAXLEN 32 struct gsmd_addr { u_int8_t type; @@ -392,6 +401,11 @@ struct gsmd_voicemail { struct gsmd_addr addr; } __attribute__ ((packed)); +struct gsmd_battery_charge { + enum gsmd_bat_conn_status bcs; + u_int8_t bcl; +} __attribute__ ((packed)); + #define GSMD_ALPHA_MAXLEN 20 /* call status from 3GPP TS 07.07 clause 07.17 */ diff --git a/include/libgsmd/misc.h b/include/libgsmd/misc.h index 02483d3..884e294 100644 --- a/include/libgsmd/misc.h +++ b/include/libgsmd/misc.h @@ -71,4 +71,6 @@ extern int lgsm_get_serial(struct lgsm_handle *lh); extern int lgsm_voicemail_set(struct lgsm_handle *lh, const char *number); /* Get currently configured voice mail number */ extern int lgsm_voicemail_get(struct lgsm_handle *lh); +/* Get Battery Connection status and charge level */ +extern int lgsm_get_battery(struct lgsm_handle *lh); #endif diff --git a/src/gsmd/usock.c b/src/gsmd/usock.c index 2faf1fc..390f4bf 100644 --- a/src/gsmd/usock.c +++ b/src/gsmd/usock.c @@ -613,7 +613,7 @@ static int phone_powerdown_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) cmd->id, sizeof(ret), &ret); } -static int gsmd_get_manuf_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) +static int phone_get_manuf_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) { struct gsmd_user *gu = ctx; @@ -624,7 +624,7 @@ static int gsmd_get_manuf_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) cmd->id, strlen(resp) + 1, resp); } -static int gsmd_get_model_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) +static int phone_get_model_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) { struct gsmd_user *gu = ctx; @@ -635,7 +635,7 @@ static int gsmd_get_model_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) cmd->id, strlen(resp) + 1, resp); } -static int gsmd_get_revision_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) +static int phone_get_revision_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) { struct gsmd_user *gu = ctx; @@ -646,7 +646,7 @@ static int gsmd_get_revision_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) cmd->id, strlen(resp) + 1, resp); } -static int gsmd_get_serial_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) +static int phone_get_serial_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) { struct gsmd_user *gu = ctx; @@ -657,6 +657,28 @@ static int gsmd_get_serial_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) cmd->id, strlen(resp) + 1, resp); } +static int phone_get_battery_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) +{ + struct gsmd_user *gu = ctx; + struct gsmd_battery_charge gbs; + struct gsm_extrsp *er; + + DEBUGP("cmd = '%s', resp: '%s'\n", cmd->buf, resp); + er = extrsp_parse(gsmd_tallocs, resp); + if(!er) + return -ENOMEM; + /* +CBC: 0,0 */ + if((er->num_tokens == 2) && + er->tokens[0].type == GSMD_ECMD_RTT_NUMERIC && + er->tokens[1].type == GSMD_ECMD_RTT_NUMERIC ) { + gbs.bcs = er->tokens[0].u.numeric; + gbs.bcl = er->tokens[1].u.numeric; + } + talloc_free(er); + return gsmd_ucmd_submit(gu, GSMD_MSG_PHONE, GSMD_PHONE_GET_BATTERY, + cmd -> id, sizeof(gbs), &gbs); +} + static int usock_rcv_phone(struct gsmd_user *gu, struct gsmd_msg_hdr *gph, int len) { @@ -679,21 +701,23 @@ static int usock_rcv_phone(struct gsmd_user *gu, struct gsmd_msg_hdr *gph, break; case GSMD_PHONE_GET_MANUF: cmd = atcmd_fill("AT+CGMI", 7+1, - &gsmd_get_manuf_cb, gu, 0, NULL); + &phone_get_manuf_cb, gu, 0, NULL); break; case GSMD_PHONE_GET_MODEL: cmd = atcmd_fill("AT+CGMM", 7+1, - &gsmd_get_model_cb, gu, 0, NULL); + &phone_get_model_cb, gu, 0, NULL); break; case GSMD_PHONE_GET_REVISION: cmd = atcmd_fill("AT+CGMR", 7+1, - &gsmd_get_revision_cb, gu, 0, NULL); + &phone_get_revision_cb, gu, 0, NULL); break; case GSMD_PHONE_GET_SERIAL: cmd = atcmd_fill("AT+CGSN", 7+1, - &gsmd_get_serial_cb, gu, 0, NULL); + &phone_get_serial_cb, gu, 0, NULL); + break; + case GSMD_PHONE_GET_BATTERY: + cmd = atcmd_fill("AT+CBC", 6+1, &phone_get_battery_cb, gu, 0, NULL); break; - default: return -EINVAL; } diff --git a/src/libgsmd/libgsmd_phone.c b/src/libgsmd/libgsmd_phone.c index 18cd614..2c67e8e 100644 --- a/src/libgsmd/libgsmd_phone.c +++ b/src/libgsmd/libgsmd_phone.c @@ -70,3 +70,7 @@ int lgsm_get_serial(struct lgsm_handle *lh) return lgsm_send_simple(lh, GSMD_MSG_PHONE, GSMD_PHONE_GET_SERIAL); } +int lgsm_get_battery(struct lgsm_handle *lh) +{ + return lgsm_send_simple(lh, GSMD_MSG_PHONE, GSMD_PHONE_GET_BATTERY); +} diff --git a/src/libgsmd/libgsmd_pin.c b/src/libgsmd/libgsmd_pin.c index 8d50b67..98fcbcc 100644 --- a/src/libgsmd/libgsmd_pin.c +++ b/src/libgsmd/libgsmd_pin.c @@ -28,6 +28,8 @@ #include <gsmd/event.h> #include <libgsmd/libgsmd.h> +#include "lgsm_internals.h" + static const char *pin_type_names[__NUM_GSMD_PIN] = { [GSMD_PIN_READY] = "READY", [GSMD_PIN_SIM_PIN] = "SIM PIN", diff --git a/src/util/shell.c b/src/util/shell.c index 1bfff3e..af6f795 100644 --- a/src/util/shell.c +++ b/src/util/shell.c @@ -394,6 +394,8 @@ static int phone_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) { char *payload = (char *)gmh + sizeof(*gmh); int *intresult = (void *)gmh + sizeof(*gmh); + const struct gsmd_battery_charge *bc = (struct gsmd_battery_charge *) + ((void *) gmh + sizeof(*gmh)); switch (gmh->msg_subtype) { case GSMD_PHONE_GET_IMSI: @@ -423,6 +425,9 @@ static int phone_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) else printf("Modem down\n"); break; + case GSMD_PHONE_GET_BATTERY: + printf("<BCS>: %d <BCL>: %d \n", bc->bcs, bc->bcl); + break; default: return -EINVAL; } @@ -568,6 +573,7 @@ static void shell_help(void) "\tsn\tGet serial number\n" "\tcs\tGet Call status\n" "\tgp\tGet PIN status\n" + "\tcbc\tGet Battery status\n" "\tRh\tRelease all held calls (+CHLD=0)\n" "\tUDUB\tUser Determined User Busy (+CHLD=0)\n" "\tRa\tRelease all active calls (+CHLD=1)\n" @@ -987,6 +993,10 @@ int shell_main(struct lgsm_handle *lgsmh, int sync) ptr = strchr(buf, '='); lgsm_voice_fwd_erase(lgsmh, atoi(ptr+1)); pending_responses ++; + }else if ( !strncmp(buf, "cbc", 3)) { + printf("Battery Connection status and Battery Charge Level\n"); + lgsm_get_battery(lgsmh); + pending_responses++; }else { printf("Unknown command `%s'\n", buf); } |