config file options to define phone parameters
This commit is contained in:
parent
03f76b6a26
commit
1036bd84f2
@ -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;
|
||||
|
23
yasnd.c
23
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");
|
||||
|
3
yasnd.h
3
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
|
||||
|
Loading…
Reference in New Issue
Block a user