Device, hardware flow and retry come from the configuration file if not given
This commit is contained in:
parent
eb727c8b55
commit
754a5dbb7f
11
src/gsm.c
11
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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, "");
|
||||
|
27
src/phone.c
27
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;
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user