[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Start script on incoming calls
From: |
Daniele Forsi |
Subject: |
Re: Start script on incoming calls |
Date: |
Wed, 11 Jan 2006 00:21:36 +0100 |
User-agent: |
Mozilla Thunderbird 1.0.7 (X11/20050923) |
I wrote:
you can use gnokiid enabling caller id
this, of course, would be used for older phones such as that owned by the OP
a more compatible alternative would be using libgnokii
if you compile the attached program, you can use with any supported
phone like this:
#!/bin/bash
while true; do
result=$(./wait-a-call)
if [ "$?" -eq "0" ]; then
echo "NUMBER: $result"
else
echo "ERROR: $?"
fi
done
it quits after each incoming call to be as simple as possible
it is like gnokii --monitor once
only much simpler (it works for me)
--
Daniele
/*
This is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 file; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Copyright 2006 by Daniele Forsi
compile with
gcc -Wall -o wait-a-call wait-a-call.c -lgnokii
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gnokii.h>
/* prepare for i18n */
#define _(x) x
struct gn_statemachine state;
gn_data data;
int done = 0;
void incoming_call(gn_call_status call_status, gn_call_info *call_info, struct
gn_statemachine *state) {
/* check for !done since sometimes this gets called more than once with
GN_CALL_Incoming */
if ((call_status == GN_CALL_Incoming) && !done) {
printf("%s\n", call_info->number);
done = 1;
}
}
int main(int argc, char *argv[])
{
gn_error error;
if (argc != 1) {
printf(_("Usage:\n %s <without arguments>\nVersion 0.2 by
Daniele Forsi\nPurpose: wait for a call, print caller number to stdout, then
exit\n"), argv[0]);
exit(1);
}
gn_data_clear(&data);
/* Read config file */
if (gn_cfg_read_default() < 0)
exit(2);
if (!gn_cfg_phone_load("", &state))
exit(2);
/* Connect to phone */
if ((error = gn_gsm_initialise(&state)) != GN_ERR_NONE) {
fprintf(stderr, _("Telephone interface init failed: %s
Quitting.\n"), gn_error_print(error));
exit(3);
}
/* Set up so that we get notified of incoming calls */
data.call_notification = incoming_call;
gn_sm_functions(GN_OP_SetCallNotification, &data, &state);
fprintf(stderr, _("Waiting for a call.\n"));
while (1) {
switch (error = gn_call_check_active(&state)) {
case GN_ERR_NONE:
case GN_ERR_UNHANDLEDFRAME:
break;
default:
fprintf(stderr, "%s\n", gn_error_print(error));
exit(4);
}
if (done) break;
sleep(1);
}
/* Close connection */
gn_sm_functions(GN_OP_Terminate, NULL, &state);
return 0;
}