2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Get ADSI CPE ID
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
30 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
37 #include "asterisk/lock.h"
38 #include "asterisk/file.h"
39 #include "asterisk/logger.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/module.h"
43 #include "asterisk/adsi.h"
44 #include "asterisk/options.h"
46 static char *app
= "GetCPEID";
48 static char *synopsis
= "Get ADSI CPE ID";
50 static char *descrip
=
51 " GetCPEID: Obtains and displays ADSI CPE ID and other information in order\n"
52 "to properly setup zapata.conf for on-hook operations.\n";
55 static int cpeid_setstatus(struct ast_channel
*chan
, char *stuff
[], int voice
)
57 int justify
[5] = { ADSI_JUST_CENT
, ADSI_JUST_LEFT
, ADSI_JUST_LEFT
, ADSI_JUST_LEFT
};
63 return ast_adsi_print(chan
, tmp
, justify
, voice
);
66 static int cpeid_exec(struct ast_channel
*chan
, void *idata
)
69 struct ast_module_user
*u
;
70 unsigned char cpeid
[4];
73 int width
, height
, buttons
;
77 u
= ast_module_user_add(chan
);
79 for (x
= 0; x
< 4; x
++)
82 strcpy(data
[0], "** CPE Info **");
83 strcpy(data
[1], "Identifying CPE...");
84 strcpy(data
[2], "Please wait...");
85 res
= ast_adsi_load_session(chan
, NULL
, 0, 1);
87 cpeid_setstatus(chan
, data
, 0);
88 res
= ast_adsi_get_cpeid(chan
, cpeid
, 0);
91 if (option_verbose
> 2)
92 ast_verbose(VERBOSE_PREFIX_3
"Got CPEID of '%02x:%02x:%02x:%02x' on '%s'\n", cpeid
[0], cpeid
[1], cpeid
[2], cpeid
[3], chan
->name
);
95 strcpy(data
[1], "Measuring CPE...");
96 strcpy(data
[2], "Please wait...");
97 cpeid_setstatus(chan
, data
, 0);
98 res
= ast_adsi_get_cpeinfo(chan
, &width
, &height
, &buttons
, 0);
100 if (option_verbose
> 2)
101 ast_verbose(VERBOSE_PREFIX_3
"CPE has %d lines, %d columns, and %d buttons on '%s'\n", height
, width
, buttons
, chan
->name
);
107 snprintf(data
[1], 80, "CPEID: %02x:%02x:%02x:%02x", cpeid
[0], cpeid
[1], cpeid
[2], cpeid
[3]);
109 strcpy(data
[1], "CPEID Unknown");
111 snprintf(data
[2], 80, "Geom: %dx%d, %d buttons", width
, height
, buttons
);
113 strcpy(data
[2], "Geometry unknown");
114 strcpy(data
[3], "Press # to exit");
115 cpeid_setstatus(chan
, data
, 1);
117 res
= ast_waitfordigit(chan
, 1000);
125 ast_adsi_unload_session(chan
);
128 ast_module_user_remove(u
);
132 static int unload_module(void)
136 res
= ast_unregister_application(app
);
138 ast_module_user_hangup_all();
143 static int load_module(void)
145 return ast_register_application(app
, cpeid_exec
, synopsis
, descrip
);
148 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Get ADSI CPE ID");