app_getcpeid.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief Get ADSI CPE ID
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  * 
00025  * \ingroup applications
00026  */
00027 
00028 /*** MODULEINFO
00029    <support_level>extended</support_level>
00030  ***/
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 429683 $")
00035 
00036 #include "asterisk/lock.h"
00037 #include "asterisk/file.h"
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041 #include "asterisk/adsi.h"
00042 
00043 /*** DOCUMENTATION
00044    <application name="GetCPEID" language="en_US">
00045       <synopsis>
00046          Get ADSI CPE ID.
00047       </synopsis>
00048       <syntax />
00049       <description>
00050          <para>Obtains and displays ADSI CPE ID and other information in order
00051          to properly setup <filename>dahdi.conf</filename> for on-hook operations.</para>
00052       </description>
00053    </application>
00054  ***/
00055 static char *app = "GetCPEID";
00056 
00057 static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
00058 {
00059    int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT };
00060    char *tmp[5];
00061    int x;
00062    for (x=0;x<4;x++)
00063       tmp[x] = stuff[x];
00064    tmp[4] = NULL;
00065    return ast_adsi_print(chan, tmp, justify, voice);
00066 }
00067 
00068 static int cpeid_exec(struct ast_channel *chan, const char *idata)
00069 {
00070    int res=0;
00071    unsigned char cpeid[4];
00072    int gotgeometry = 0;
00073    int gotcpeid = 0;
00074    int width, height, buttons;
00075    char *data[4];
00076    unsigned int x;
00077 
00078    for (x = 0; x < 4; x++)
00079       data[x] = ast_alloca(80);
00080 
00081    strcpy(data[0], "** CPE Info **");
00082    strcpy(data[1], "Identifying CPE...");
00083    strcpy(data[2], "Please wait...");
00084    res = ast_adsi_load_session(chan, NULL, 0, 1);
00085    if (res > 0) {
00086       cpeid_setstatus(chan, data, 0);
00087       res = ast_adsi_get_cpeid(chan, cpeid, 0);
00088       if (res > 0) {
00089          gotcpeid = 1;
00090          ast_verb(3, "Got CPEID of '%02hhx:%02hhx:%02hhx:%02hhx' on '%s'\n",
00091             cpeid[0], cpeid[1], cpeid[2], cpeid[3], ast_channel_name(chan));
00092       }
00093       if (res > -1) {
00094          strcpy(data[1], "Measuring CPE...");
00095          strcpy(data[2], "Please wait...");
00096          cpeid_setstatus(chan, data, 0);
00097          res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
00098          if (res > -1) {
00099             ast_verb(3, "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, ast_channel_name(chan));
00100             gotgeometry = 1;
00101          }
00102       }
00103       if (res > -1) {
00104          if (gotcpeid)
00105             snprintf(data[1], 80, "CPEID: %02hhx:%02hhx:%02hhx:%02hhx",
00106                cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
00107          else
00108             strcpy(data[1], "CPEID Unknown");
00109          if (gotgeometry) 
00110             snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons);
00111          else
00112             strcpy(data[2], "Geometry unknown");
00113          strcpy(data[3], "Press # to exit");
00114          cpeid_setstatus(chan, data, 1);
00115          for(;;) {
00116             res = ast_waitfordigit(chan, 1000);
00117             if (res < 0)
00118                break;
00119             if (res == '#') {
00120                res = 0;
00121                break;
00122             }
00123          }
00124          ast_adsi_unload_session(chan);
00125       }
00126    }
00127 
00128    return res;
00129 }
00130 
00131 static int unload_module(void)
00132 {
00133    return ast_unregister_application(app);
00134 }
00135 
00136 static int load_module(void)
00137 {
00138    return ast_register_application_xml(app, cpeid_exec);
00139 }
00140 
00141 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get ADSI CPE ID",
00142       .support_level = AST_MODULE_SUPPORT_EXTENDED,
00143       .load = load_module,
00144       .unload = unload_module,
00145       .nonoptreq = "res_adsi",
00146       );

Generated on Thu Apr 16 06:27:09 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6