From 1036bd84f23a8e9544f392c6dcb3def1b3fa50c3 Mon Sep 17 00:00:00 2001 From: Sergey Popov Date: Mon, 12 Dec 2011 14:10:05 +0400 Subject: [PATCH] config file options to define phone parameters --- yasnd-gammu.c | 6 +++--- yasnd.c | 23 ++++++++++++++++++++++- yasnd.h | 3 +++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/yasnd-gammu.c b/yasnd-gammu.c index 881274b..883d841 100644 --- a/yasnd-gammu.c +++ b/yasnd-gammu.c @@ -25,10 +25,10 @@ bool gammu_init() GSM_Config *gammu_cfg = GSM_GetConfig(state_machine, 0); // first, free old values and set new one free(gammu_cfg->Device); - gammu_cfg->Device = strdup("/dev/ttyACM0"); + gammu_cfg->Device = strdup(phone_device); free(gammu_cfg->Connection); - gammu_cfg->Connection = strdup("at"); - strcpy(gammu_cfg->Model, "at"); + gammu_cfg->Connection = strdup(phone_connection); + strcpy(gammu_cfg->Model, phone_model); /* We care only about first configuration */ GSM_SetConfigNum(state_machine, 1); return true; diff --git a/yasnd.c b/yasnd.c index 9df8154..f6771f0 100644 --- a/yasnd.c +++ b/yasnd.c @@ -17,6 +17,9 @@ host_decl* hosts=NULL; // structure with hosts' definitions int hosts_count=0; // count of hosts int debug_flag=0; bool sms_send_enable=false; // send or not send alerts via SMS +char* phone_device=NULL; // phone device for gammu, for example: "/dev/ttyACM0" +char* phone_model=NULL; // gammu phone model, for example: "at" +char* phone_connection=NULL; // gammu phone connection type, for example: "at" char* recipient_number=NULL; // recipient of sms alerts void log_debug(const char *message,int verbosity) @@ -48,6 +51,9 @@ void init() CFG_STR_LIST("hosts", "{}", CFGF_NONE), CFG_SIMPLE_INT("debug", &debug_flag), CFG_SIMPLE_BOOL("sms_send_enable", &sms_send_enable), + CFG_SIMPLE_STR("phone_device", &phone_device), + CFG_SIMPLE_STR("phone_model", &phone_connection), + CFG_SIMPLE_STR("phone_connection", &phone_model), CFG_SIMPLE_STR("sms_recipient", &recipient_number), CFG_END() }; @@ -58,9 +64,24 @@ void init() log_event("Error parsing config file"); exit(EXIT_FAILURE); } - // if SMS sending is enabled, recipient address must also be defined + // if SMS sending is enabled, all of phone parameters must be explicitly defined if (sms_send_enable) { + if (phone_model==NULL) + { + log_event("Error: phone model is not defined in config file"); + exit(EXIT_FAILURE); + } + if (phone_connection==NULL) + { + log_event("Error: phone connection type is not defined in config file"); + exit(EXIT_FAILURE); + } + if (phone_device==NULL) + { + log_event("Error: phone device is not defined in config file"); + exit(EXIT_FAILURE); + } if (recipient_number==NULL) { log_event("Error: no recipient for sms alerts defined in config file"); diff --git a/yasnd.h b/yasnd.h index c1a80bd..1bf3fac 100644 --- a/yasnd.h +++ b/yasnd.h @@ -27,5 +27,8 @@ extern int debug_flag; extern GSM_Error error; // structure to store possible gammu errors extern GSM_StateMachine *state_machine; // structure to interact with mobile phones extern char* recipient_number; +extern char* phone_device; // phone device for gammu, for example: "/dev/ttyACM0" +extern char* phone_model; // gammu phone model, for example: "at" +extern char* phone_connection; // gammu phone connection type, for example: "at" #endif