[asterisk-commits] russell: branch russell/callerid_cli r112320 - /team/russell/callerid_cli/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 1 15:55:41 CDT 2008


Author: russell
Date: Tue Apr  1 15:55:40 2008
New Revision: 112320

URL: http://svn.digium.com/view/asterisk?view=rev&rev=112320
Log:
Add an untested callerid analyze CLI command which will read a file and try to process it for callerid

Modified:
    team/russell/callerid_cli/main/callerid.c

Modified: team/russell/callerid_cli/main/callerid.c
URL: http://svn.digium.com/view/asterisk/team/russell/callerid_cli/main/callerid.c?view=diff&rev=112320&r1=112319&r2=112320
==============================================================================
--- team/russell/callerid_cli/main/callerid.c (original)
+++ team/russell/callerid_cli/main/callerid.c Tue Apr  1 15:55:40 2008
@@ -38,6 +38,7 @@
 #include "asterisk/callerid.h"
 #include "asterisk/fskmodem.h"
 #include "asterisk/utils.h"
+#include "asterisk/cli.h"
 
 struct callerid_state {
 	fsk_data fskd;
@@ -108,6 +109,87 @@
 	}
 }
 
+static char *cli_callerid_analyze(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	FILE *f;
+	const char *fn;
+	unsigned char buf[256];
+	struct callerid_state *cid_state;
+	int samples;
+	int res = 0;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "callerid analyze";
+		e->usage =
+			"Usage: callerid analyze <file>\n"
+			"       Read an audio dump for CallerID information.  Generally,\n"
+			"this is a dump from ztmonitor.  However, you must feed the file in\n"
+			"as ulaw.  You can use asterisk to convert the file.\n"
+			"   *CLI> convert /tmp/dump.raw /tmp/dump.ulaw\n"
+			"\n"
+			"";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != e->args + 1)
+		return CLI_SHOWUSAGE;
+
+	fn = a->argv[e->args];
+
+	if (!strcasestr(fn, ".ulaw")) {
+		ast_cli(a->fd, "File must be in ulaw format (and have a .ulaw extension).\n");
+		return CLI_FAILURE;
+	}
+
+	if (!(f = fopen(fn, "r"))) {
+		ast_cli(a->fd, "Unable to open '%s' for reading.\n", fn);
+		return CLI_FAILURE;
+	}
+
+	if (!(cid_state = callerid_new(CID_SIG_BELL))) {
+		fclose(f);
+		return CLI_FAILURE;
+	}
+
+	while ((samples = fread(buf, 1, sizeof(buf), f))) {
+		res = callerid_feed(cid_state, buf, samples, AST_FORMAT_ULAW);
+
+		if (res < 0) {
+			ast_cli(a->fd, "Error processing CallerID dump\n");
+			break;
+		} else if (res > 0) {
+			break;
+		}
+	}
+
+	if (res == 0) {
+		ast_cli(a->fd, "Finished reading callerid data, but nothing found\n");
+	} else if (res > 0) {
+		char *name = NULL, *num = NULL;
+		int flags = 0;
+
+		callerid_get(cid_state, &num, &name, &flags);
+
+		ast_cli(a->fd, "CallerID detection successful!\n"
+			"=== Name:   '%s'\n"
+			"=== Number: '%s'\n"
+			"=== Flags:  '%d'\n",
+			S_OR(name, ""), S_OR(num, ""), flags);
+	}
+
+	fclose(f);
+	callerid_free(cid_state);
+
+	return (res < 0) ? CLI_FAILURE : CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_callerid[] = {
+	AST_CLI_DEFINE(cli_callerid_analyze, "Analyze an audio dump that contains a CallerID FSK spill"),
+};
+
 /*! \brief Initialize stuff for inverse FFT */
 void callerid_init(void)
 {
@@ -121,6 +203,8 @@
 	casdi1 = sin(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
 	casdr2 = cos(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
 	casdi2 = sin(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
+
+	ast_cli_register_multiple(cli_callerid, ARRAY_LEN(cli_callerid));
 }
 
 struct callerid_state *callerid_new(int cid_signalling)




More information about the asterisk-commits mailing list