59 #define ALMRCV_CONFIG "alarmreceiver.conf"
60 #define ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID"
69 static const char app[] =
"AlarmReceiver";
122 res =
ast_db_get(db_family, key, value,
sizeof(value) - 1);
125 ast_verb(4,
"AlarmReceiver: Creating database entry %s and setting to 1\n", key);
131 sscanf(value,
"%30u", &v);
134 ast_verb(4,
"AlarmReceiver: New value for %s: %u\n", key, v);
136 snprintf(value,
sizeof(value),
"%u", v);
141 ast_verb(4,
"AlarmReceiver: database_increment write error\n");
155 for (i = 0; i <
len; i++) {
156 val = loudness * sin((freq * 2.0 *
M_PI * (*x)++)/8000.0);
180 unsigned char buf[640];
213 ast_verb(4,
"AlarmReceiver: Failed to write frame on %s\n", chan->
name);
242 struct timeval lastdigittime;
248 ast_verb(4,
"AlarmReceiver: DTMF Digit Timeout on %s\n", chan->
name);
249 ast_debug(1,
"AlarmReceiver: DTMF timeout on chan %s\n",chan->
name);
255 ast_debug(1,
"Waitfor returned %d\n", r);
293 digit_string[i] =
'\0';
327 ast_strftime(timestamp,
sizeof(timestamp), time_stamp_format, &now);
329 res = fprintf(logfile,
"\n\n[metadata]\n\n");
331 res = fprintf(logfile,
"PROTOCOL=%s\n", signalling_type);
334 res = fprintf(logfile,
"CALLINGFROM=%s\n", cl);
337 res = fprintf(logfile,
"CALLERNAME=%s\n", cn);
340 res = fprintf(logfile,
"TIMESTAMP=%s\n\n", timestamp);
343 res = fprintf(logfile,
"[events]\n\n");
346 ast_verb(3,
"AlarmReceiver: can't write metadata\n");
347 ast_debug(1,
"AlarmReceiver: can't write metadata\n");
362 if (fprintf(logfile,
"%s\n", event->
data) < 0)
385 strncat(workstring, event_file,
sizeof(workstring) - strlen(workstring) - 1);
388 fd = mkstemp(workstring);
391 ast_verb(3,
"AlarmReceiver: can't make temporary file\n");
392 ast_debug(1,
"AlarmReceiver: can't make temporary file\n");
397 logfile = fdopen(fd,
"w");
402 while ((!res) && (elp != NULL)) {
407 if (fflush(logfile) == EOF)
410 if (fclose(logfile) == EOF)
434 int got_some_digits = 0;
435 int events_received = 0;
438 static char digit_map[15] =
"0123456789*#ABC";
439 static unsigned char digit_weights[15] = {10,1,2,3,4,5,6,7,8,9,11,12,13,14,15};
444 ast_verb(4,
"AlarmReceiver: Waiting for first event from panel\n");
447 if (got_some_digits == 0) {
449 ast_verb(4,
"AlarmReceiver: Sending 1400Hz 100ms burst (ACK)\n");
454 ast_verb(4,
"AlarmReceiver: Sending 2300Hz 100ms burst (ACK)\n");
461 if (events_received == 0) {
466 ast_verb(4,
"AlarmReceiver: ACK retries during this call: %d\n", ack_retries);
470 ast_verb(4,
"AlarmReceiver: App exiting...\n");
477 ast_verb(2,
"AlarmReceiver: Incomplete string: %s, trying again...\n", event);
479 if (!got_some_digits) {
488 ast_verb(2,
"AlarmReceiver: Received Event %s\n", event);
489 ast_debug(1,
"AlarmReceiver: Received event: %s\n", event);
493 for (j = 0, checksum = 0; j < 16; j++) {
494 for (i = 0; i <
sizeof(digit_map); i++) {
495 if (digit_map[i] == event[j])
502 checksum += digit_weights[i];
505 ast_verb(2,
"AlarmReceiver: Bad DTMF character %c, trying again\n", event[j]);
511 checksum = checksum % 15;
515 ast_verb(2,
"AlarmReceiver: Nonzero checksum\n");
516 ast_debug(1,
"AlarmReceiver: Nonzero checksum\n");
522 if (strncmp(event + 4,
"18", 2)) {
523 if (strncmp(event + 4,
"98", 2)) {
525 ast_verb(2,
"AlarmReceiver: Wrong message type\n");
526 ast_debug(1,
"AlarmReceiver: Wrong message type\n");
548 for(elp = *ehead; elp->
next != NULL; elp = elp->
next)
557 if ((res == 0) && (log_individual_events))
579 char signalling_type[64] =
"";
583 ast_verb(4,
"AlarmReceiver: Setting read and write formats to ULAW\n");
599 ast_verb(4,
"AlarmReceiver: Answering channel\n");
606 ast_verb(4,
"AlarmReceiver: Waiting for connection to stabilize\n");
621 if ((!res) && (log_individual_events == 0))
622 res =
log_events(chan, signalling_type, event_head);
628 ast_debug(1,
"Alarmreceiver: executing: %s\n", event_app);
635 for (elp = event_head; (elp != NULL);) {
657 ast_verb(4,
"AlarmReceiver: No config file\n");
670 toneloudness = atoi(p);
671 if(toneloudness < 100)
673 if(toneloudness > 8192)
681 if(fdtimeout > 10000)
696 log_individual_events =
ast_true(p);
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
union ast_frame_subclass subclass
Main Channel structure associated with a channel.
char * str
Subscriber phone number (Malloced)
#define AST_MODULE_INFO_STANDARD(keystr, desc)
int ast_safe_system(const char *s)
Safely spawn an external program while closing file descriptors.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static char event_file[14]
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
struct ast_party_caller caller
Channel Caller ID information.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
int ast_db_get(const char *family, const char *key, char *out, int outlen)
Get key value specified by family/key.
Support for translation of data formats. translate.c.
struct ast_party_name name
Subscriber name.
Convenient Signal Processing routines.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Configuration File Parser.
char * str
Subscriber name (Malloced)
static int write_metadata(FILE *logfile, char *signalling_type, struct ast_channel *chan)
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
static int send_tone_burst(struct ast_channel *chan, float freq, int duration, int tldn)
static void database_increment(char *key)
int ast_unregister_application(const char *app)
Unregister an application.
#define ast_verb(level,...)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
static int receive_ademco_contact_id(struct ast_channel *chan, const void *data, int fdto, int sdto, int tldn, event_node_t **ehead)
Custom localtime functions for multiple timezones.
struct ast_party_id id
Caller party ID.
int ast_set_write_format(struct ast_channel *chan, format_t format)
Sets write format on channel chan Set write format for channel to whichever component of "format" is ...
static int alarmreceiver_exec(struct ast_channel *chan, const char *data)
int ast_set_read_format(struct ast_channel *chan, format_t format)
Sets read format on channel chan Set read format for channel to whichever component of "format" is be...
#define ast_debug(level,...)
Log a DEBUG message.
u-Law to Signed linear conversion
General Asterisk PBX channel definitions.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
#define ast_config_load(filename, flags)
Load a config file.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
static void make_tone_burst(unsigned char *data, float freq, float loudness, int len, int *x)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Core PBX routines and definitions.
static char event_app[128]
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
enum ast_channel_state _state
const ast_string_field name
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
static int load_config(void)
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Structure used to handle boolean flags.
static int load_module(void)
static int write_event(FILE *logfile, event_node_t *event)
static int log_individual_events
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int length, int fdto, int sdto)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ADEMCO_CONTACT_ID
static char time_stamp_format[128]
int ast_answer(struct ast_channel *chan)
Answer a channel.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
Data structure associated with a single frame of data.
static char event_spool_dir[128]
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
enum ast_frame_type frametype
unsigned char valid
TRUE if the name information is valid/present.
#define CONFIG_STATUS_FILEINVALID
static int log_events(struct ast_channel *chan, char *signalling_type, event_node_t *event)
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s, .'s, and -'s...
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
union ast_frame::@172 data
static char db_family[128]
Persistant data storage (akin to *doze registry)
unsigned char valid
TRUE if the number information is valid/present.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
static int unload_module(void)
struct ast_party_number number
Subscriber phone number.