Detect if a call is ongoing
This commit is contained in:
parent
0f1244eb5f
commit
efe5e8811e
25
src/gsm.c
25
src/gsm.c
@ -173,6 +173,7 @@ static int _gsm_trigger_cmti(GSM * gsm, char const * result);
|
||||
static int _gsm_trigger_connect(GSM * gsm, char const * result,
|
||||
gboolean * answered);
|
||||
static int _gsm_trigger_cops(GSM * gsm, char const * result);
|
||||
static int _gsm_trigger_cpas(GSM * gsm, char const * result);
|
||||
static int _gsm_trigger_cpbr(GSM * gsm, char const * result);
|
||||
static int _gsm_trigger_cpin(GSM * gsm, char const * result);
|
||||
static int _gsm_trigger_creg(GSM * gsm, char const * result);
|
||||
@ -202,6 +203,7 @@ static GSMTrigger _gsm_triggers[] =
|
||||
GSM_TRIGGER("+CMTI: ", cmti),
|
||||
GSM_TRIGGER("CONNECT", connect),
|
||||
GSM_TRIGGER("+COPS: ", cops),
|
||||
GSM_TRIGGER("+CPAS: ", cpas),
|
||||
GSM_TRIGGER("+CPBR: ", cpbr),
|
||||
GSM_TRIGGER("+CPIN: ", cpin),
|
||||
GSM_TRIGGER("+CREG: ", creg),
|
||||
@ -503,6 +505,10 @@ int gsm_event(GSM * gsm, GSMEventType type, ...)
|
||||
event->operator.operator = va_arg(ap, char const *);
|
||||
event->operator.lai = va_arg(ap, unsigned int);
|
||||
break;
|
||||
case GSM_EVENT_TYPE_PHONE_ACTIVITY:
|
||||
event->phone_activity.activity = va_arg(ap,
|
||||
GSMPhoneActivity);
|
||||
break;
|
||||
case GSM_EVENT_TYPE_REGISTRATION:
|
||||
event->registration.n = va_arg(ap, unsigned int);
|
||||
event->registration.stat = va_arg(ap, unsigned int);
|
||||
@ -580,6 +586,13 @@ int gsm_is_functional(GSM * gsm)
|
||||
}
|
||||
|
||||
|
||||
/* gsm_is_phone_active */
|
||||
int gsm_is_phone_active(GSM * gsm)
|
||||
{
|
||||
return gsm_modem_is_phone_active(gsm->modem);
|
||||
}
|
||||
|
||||
|
||||
/* gsm_is_pin_needed */
|
||||
int gsm_is_pin_needed(GSM * gsm)
|
||||
{
|
||||
@ -1188,6 +1201,18 @@ static int _gsm_trigger_cops(GSM * gsm, char const * result)
|
||||
}
|
||||
|
||||
|
||||
/* gsm_trigger_cpas */
|
||||
static int _gsm_trigger_cpas(GSM * gsm, char const * result)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, result);
|
||||
#endif
|
||||
if(sscanf(result, "%u", &gsm->event.phone_activity.activity) != 1)
|
||||
return 1;
|
||||
return _gsm_event_send(gsm, GSM_EVENT_TYPE_PHONE_ACTIVITY);
|
||||
}
|
||||
|
||||
|
||||
/* _gsm_trigger_cpbr */
|
||||
static int _gsm_trigger_cpbr(GSM * gsm, char const * result)
|
||||
{
|
||||
|
17
src/gsm.h
17
src/gsm.h
@ -47,6 +47,7 @@ typedef enum _GSMEventType
|
||||
GSM_EVENT_TYPE_MESSAGE_LIST,
|
||||
GSM_EVENT_TYPE_MESSAGE_SENT,
|
||||
GSM_EVENT_TYPE_OPERATOR,
|
||||
GSM_EVENT_TYPE_PHONE_ACTIVITY,
|
||||
GSM_EVENT_TYPE_REGISTRATION,
|
||||
GSM_EVENT_TYPE_SIGNAL_LEVEL,
|
||||
GSM_EVENT_TYPE_SIM_PIN_VALID,
|
||||
@ -103,6 +104,14 @@ typedef enum _GSMOperatorMode
|
||||
GSM_OPERATOR_MODE_MANUAL_WITH_FALLBACK = 4
|
||||
} GSMOperatorMode;
|
||||
|
||||
typedef enum _GSMPhoneActivity
|
||||
{
|
||||
GSM_PHONE_ACTIVITY_READY = 0,
|
||||
GSM_PHONE_ACTIVITY_UNKNOWN = 2,
|
||||
GSM_PHONE_ACTIVITY_RINGING = 3,
|
||||
GSM_PHONE_ACTIVITY_CALL = 4
|
||||
} GSMPhoneActivity;
|
||||
|
||||
typedef enum _GSMPriority
|
||||
{
|
||||
GSM_PRIORITY_LOW = 0, GSM_PRIORITY_NORMAL, GSM_PRIORITY_HIGH,
|
||||
@ -214,6 +223,13 @@ typedef union _GSMEvent
|
||||
unsigned int lai;
|
||||
} operator;
|
||||
|
||||
/* GSM_EVENT_TYPE_PHONE_ACTIVITY */
|
||||
struct
|
||||
{
|
||||
GSMEventType type;
|
||||
GSMPhoneActivity activity;
|
||||
} phone_activity;
|
||||
|
||||
/* GSM_EVENT_TYPE_REGISTRATION */
|
||||
struct
|
||||
{
|
||||
@ -280,6 +296,7 @@ int gsm_fetch_signal_level(GSM * gsm);
|
||||
|
||||
/* queries */
|
||||
int gsm_is_functional(GSM * gsm);
|
||||
int gsm_is_phone_active(GSM * gsm);
|
||||
int gsm_is_pin_needed(GSM * gsm);
|
||||
int gsm_is_pin_valid(GSM * gsm);
|
||||
int gsm_is_registered(GSM * gsm);
|
||||
|
@ -294,6 +294,15 @@ int gsm_modem_is_functional(GSMModem * gsmm)
|
||||
}
|
||||
|
||||
|
||||
/* gsm_modem_is_phone_active */
|
||||
int gsm_modem_is_phone_active(GSMModem * gsmm)
|
||||
{
|
||||
char const cmd[] = "AT+CPAS";
|
||||
|
||||
return (gsm_queue(gsmm->gsm, cmd) != NULL) ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
/* gsm_modem_is_pin_needed */
|
||||
int gsm_modem_is_pin_needed(GSMModem * gsmm)
|
||||
{
|
||||
|
10
src/modem.h
10
src/modem.h
@ -51,22 +51,26 @@ int gsm_modem_call_last(GSMModem * gsmm, GSMCallType calltype);
|
||||
int gsm_modem_enter_sim_pin(GSMModem * gsmm, char const * code);
|
||||
|
||||
int gsm_modem_get_contact_list(GSMModem * gsmm);
|
||||
int gsm_modem_get_contacts(GSMModem * gsmm, unsigned int start, unsigned int end);
|
||||
int gsm_modem_get_contacts(GSMModem * gsmm, unsigned int start,
|
||||
unsigned int end);
|
||||
int gsm_modem_get_message_list(GSMModem * gsmm);
|
||||
int gsm_modem_get_messages(GSMModem * gsmm, unsigned int start, unsigned int end);
|
||||
int gsm_modem_get_messages(GSMModem * gsmm, unsigned int start,
|
||||
unsigned int end);
|
||||
int gsm_modem_get_model(GSMModem * gsmm);
|
||||
int gsm_modem_get_operator(GSMModem * gsmm);
|
||||
int gsm_modem_get_registration(GSMModem * gsmm);
|
||||
int gsm_modem_get_signal_level(GSMModem * gsmm);
|
||||
|
||||
int gsm_modem_is_functional(GSMModem * gsmm);
|
||||
int gsm_modem_is_phone_active(GSMModem * gsmm);
|
||||
int gsm_modem_is_pin_needed(GSMModem * gsmm);
|
||||
int gsm_modem_is_pin_valid(GSMModem * gsmm);
|
||||
int gsm_modem_is_registered(GSMModem * gsmm);
|
||||
|
||||
int gsm_modem_reset(GSMModem * gsmm);
|
||||
|
||||
int gsm_modem_send_message(GSMModem * gsmm, char const * number, char const * text);
|
||||
int gsm_modem_send_message(GSMModem * gsmm, char const * number,
|
||||
char const * text);
|
||||
|
||||
int gsm_modem_set_call_presentation(GSMModem * gsmm, gboolean set);
|
||||
int gsm_modem_set_echo(GSMModem * gsmm, gboolean echo);
|
||||
|
23
src/phone.c
23
src/phone.c
@ -1398,6 +1398,7 @@ static void _phone_track(Phone * phone, PhoneTrack what, gboolean track)
|
||||
/* callbacks */
|
||||
/* phone_gsm_event */
|
||||
static int _gsm_event_error(Phone * phone, GSMEvent * event);
|
||||
static int _gsm_event_phone_activity(Phone * phone, GSMPhoneActivity activity);
|
||||
static void _on_sim_pin_valid_response(GtkWidget * widget, gint response,
|
||||
gpointer data);
|
||||
|
||||
@ -1437,6 +1438,7 @@ static int _phone_gsm_event(GSMEvent * event, gpointer data)
|
||||
gsm_set_operator_mode(phone->gsm,
|
||||
GSM_OPERATOR_MODE_AUTOMATIC);
|
||||
gsm_set_registration_report(phone->gsm, report);
|
||||
gsm_is_phone_active(phone->gsm);
|
||||
_phone_track(phone, PHONE_TRACK_CONTACT_LIST, TRUE);
|
||||
_phone_track(phone, PHONE_TRACK_MESSAGE_LIST, TRUE);
|
||||
return 0;
|
||||
@ -1464,6 +1466,9 @@ static int _phone_gsm_event(GSMEvent * event, gpointer data)
|
||||
case GSM_EVENT_TYPE_OPERATOR:
|
||||
_phone_set_operator(phone, event->operator.operator);
|
||||
return 0;
|
||||
case GSM_EVENT_TYPE_PHONE_ACTIVITY:
|
||||
return _gsm_event_phone_activity(phone,
|
||||
event->phone_activity.activity);
|
||||
case GSM_EVENT_TYPE_REGISTRATION:
|
||||
return 0; /* we also get a status update about it */
|
||||
case GSM_EVENT_TYPE_SIGNAL_LEVEL:
|
||||
@ -1529,6 +1534,24 @@ static int _gsm_event_error(Phone * phone, GSMEvent * event)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _gsm_event_phone_activity(Phone * phone, GSMPhoneActivity activity)
|
||||
{
|
||||
switch(activity)
|
||||
{
|
||||
case GSM_PHONE_ACTIVITY_CALL:
|
||||
phone_show_call(phone, TRUE, PHONE_CALL_ESTABLISHED);
|
||||
break;
|
||||
case GSM_PHONE_ACTIVITY_READY:
|
||||
case GSM_PHONE_ACTIVITY_UNKNOWN:
|
||||
break; /* nothing to do */
|
||||
case GSM_PHONE_ACTIVITY_RINGING:
|
||||
phone_show_call(phone, TRUE, PHONE_CALL_OUTGOING, NULL,
|
||||
NULL);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _on_sim_pin_valid_response(GtkWidget * widget, gint response,
|
||||
gpointer data)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user