diff --git a/src/gsm.c b/src/gsm.c index 7d8df28..d3ae2b9 100644 --- a/src/gsm.c +++ b/src/gsm.c @@ -257,6 +257,8 @@ GSM * gsm_new(char const * device, unsigned int baudrate, unsigned int hwflow) if((gsm = malloc(sizeof(*gsm))) == NULL) return NULL; /* settings */ + if(device == NULL) + device = "/dev/modem"; gsm->device = strdup(device); gsm->baudrate = _new_baudrate(baudrate); 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) { char buf[256]; - + char const * error; + + error = _(": Unknown baudrate, assuming 115200"); switch(baudrate) { case 1200: @@ -328,9 +332,8 @@ static unsigned int _new_baudrate(unsigned int baudrate) case 921600: return B921600; default: - snprintf(buf, sizeof(buf), "%u%s", baudrate, - _(": Unknown baudrate")); - return phone_error(NULL, buf, baudrate); + snprintf(buf, sizeof(buf), "%u%s", baudrate, error); + return phone_error(NULL, buf, 115200); } } diff --git a/src/main.c b/src/main.c index 4641b8d..6f6f572 100644 --- a/src/main.c +++ b/src/main.c @@ -57,9 +57,9 @@ int main(int argc, char * argv[]) int o; Phone * phone; char const * device = NULL; - unsigned int baudrate = 115200; + unsigned int baudrate = 0; int retry = -1; - unsigned int hwflow = 0; + int hwflow = -1; char * p; setlocale(LC_ALL, ""); diff --git a/src/phone.c b/src/phone.c index 5a258cd..629e04d 100644 --- a/src/phone.c +++ b/src/phone.c @@ -201,12 +201,13 @@ static gboolean _on_plug_delete_event(gpointer data); static void _on_plug_embedded(gpointer data); Phone * phone_new(char const * device, unsigned int baudrate, int retry, - unsigned int hwflow) + int hwflow) { Phone * phone; GtkWidget * hbox; GdkEvent event; GdkEventClient * client = &event.client; + char const * p; #ifdef DEBUG 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 if((phone = malloc(sizeof(*phone))) == NULL) return NULL; - if(device == NULL) - device = "/dev/modem"; - phone->gsm = gsm_new(device, baudrate, hwflow); - phone->ui_source = 0; _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->tr_source = 0; memset(&phone->tracks, 0, sizeof(phone->tracks)); @@ -273,8 +288,6 @@ Phone * phone_new(char const * device, unsigned int baudrate, int retry, return NULL; } 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); _phone_set_operator(phone, _("Initializing...")); return phone; diff --git a/src/phone.h b/src/phone.h index 129b63d..e50194c 100644 --- a/src/phone.h +++ b/src/phone.h @@ -58,7 +58,7 @@ typedef enum _PhoneMessageShow /* functions */ Phone * phone_new(char const * device, unsigned int baudrate, int retry, - unsigned int hwflow); + int hwflow); void phone_delete(Phone * phone);