Device, hardware flow and retry come from the configuration file if not given

This commit is contained in:
Pierre Pronchery 2010-05-12 14:44:57 +00:00
parent eb727c8b55
commit 754a5dbb7f
4 changed files with 30 additions and 14 deletions

View File

@ -257,6 +257,8 @@ GSM * gsm_new(char const * device, unsigned int baudrate, unsigned int hwflow)
if((gsm = malloc(sizeof(*gsm))) == NULL) if((gsm = malloc(sizeof(*gsm))) == NULL)
return NULL; return NULL;
/* settings */ /* settings */
if(device == NULL)
device = "/dev/modem";
gsm->device = strdup(device); gsm->device = strdup(device);
gsm->baudrate = _new_baudrate(baudrate); gsm->baudrate = _new_baudrate(baudrate);
gsm->retry = 1000; gsm->retry = 1000;
@ -292,7 +294,9 @@ GSM * gsm_new(char const * device, unsigned int baudrate, unsigned int hwflow)
static unsigned int _new_baudrate(unsigned int baudrate) static unsigned int _new_baudrate(unsigned int baudrate)
{ {
char buf[256]; char buf[256];
char const * error;
error = _(": Unknown baudrate, assuming 115200");
switch(baudrate) switch(baudrate)
{ {
case 1200: case 1200:
@ -328,9 +332,8 @@ static unsigned int _new_baudrate(unsigned int baudrate)
case 921600: case 921600:
return B921600; return B921600;
default: default:
snprintf(buf, sizeof(buf), "%u%s", baudrate, snprintf(buf, sizeof(buf), "%u%s", baudrate, error);
_(": Unknown baudrate")); return phone_error(NULL, buf, 115200);
return phone_error(NULL, buf, baudrate);
} }
} }

View File

@ -57,9 +57,9 @@ int main(int argc, char * argv[])
int o; int o;
Phone * phone; Phone * phone;
char const * device = NULL; char const * device = NULL;
unsigned int baudrate = 115200; unsigned int baudrate = 0;
int retry = -1; int retry = -1;
unsigned int hwflow = 0; int hwflow = -1;
char * p; char * p;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");

View File

@ -201,12 +201,13 @@ static gboolean _on_plug_delete_event(gpointer data);
static void _on_plug_embedded(gpointer data); static void _on_plug_embedded(gpointer data);
Phone * phone_new(char const * device, unsigned int baudrate, int retry, Phone * phone_new(char const * device, unsigned int baudrate, int retry,
unsigned int hwflow) int hwflow)
{ {
Phone * phone; Phone * phone;
GtkWidget * hbox; GtkWidget * hbox;
GdkEvent event; GdkEvent event;
GdkEventClient * client = &event.client; GdkEventClient * client = &event.client;
char const * p;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\", %u)\n", __func__, (device != NULL) fprintf(stderr, "DEBUG: %s(\"%s\", %u)\n", __func__, (device != NULL)
@ -214,11 +215,25 @@ Phone * phone_new(char const * device, unsigned int baudrate, int retry,
#endif #endif
if((phone = malloc(sizeof(*phone))) == NULL) if((phone = malloc(sizeof(*phone))) == NULL)
return NULL; return NULL;
if(device == NULL)
device = "/dev/modem";
phone->gsm = gsm_new(device, baudrate, hwflow);
phone->ui_source = 0;
_new_config(phone); _new_config(phone);
if(phone->config != NULL)
{
if(device == NULL)
device = config_get(phone->config, NULL, "device");
p = config_get(phone->config, NULL, "baudrate");
if(baudrate == 0 && p != NULL)
baudrate = strtoul(p, NULL, 10);
p = config_get(phone->config, NULL, "hwflow");
if(hwflow < 0 && p != NULL)
hwflow = strtoul(p, NULL, 10);
p = config_get(phone->config, NULL, "retry");
if(retry < 0 && p != NULL)
retry = strtoul(p, NULL, 10);
}
phone->gsm = gsm_new(device, baudrate, hwflow);
if(retry >= 0)
gsm_set_retry(phone->gsm, retry);
phone->ui_source = 0;
phone->signal = -1; phone->signal = -1;
phone->tr_source = 0; phone->tr_source = 0;
memset(&phone->tracks, 0, sizeof(phone->tracks)); memset(&phone->tracks, 0, sizeof(phone->tracks));
@ -273,8 +288,6 @@ Phone * phone_new(char const * device, unsigned int baudrate, int retry,
return NULL; return NULL;
} }
phone->ui_source = g_idle_add(_new_idle, phone); phone->ui_source = g_idle_add(_new_idle, phone);
if(retry >= 0)
gsm_set_retry(phone->gsm, retry);
gsm_set_callback(phone->gsm, _phone_gsm_event, phone); gsm_set_callback(phone->gsm, _phone_gsm_event, phone);
_phone_set_operator(phone, _("Initializing...")); _phone_set_operator(phone, _("Initializing..."));
return phone; return phone;

View File

@ -58,7 +58,7 @@ typedef enum _PhoneMessageShow
/* functions */ /* functions */
Phone * phone_new(char const * device, unsigned int baudrate, int retry, Phone * phone_new(char const * device, unsigned int baudrate, int retry,
unsigned int hwflow); int hwflow);
void phone_delete(Phone * phone); void phone_delete(Phone * phone);