Sun Aug 6 15:02:24 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

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  * \ingroup applications
00024  */
00025 
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <unistd.h>
00029 #include <string.h>
00030 
00031 #include "asterisk.h"
00032 
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00034 
00035 #include "asterisk/lock.h"
00036 #include "asterisk/file.h"
00037 #include "asterisk/logger.h"
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041 #include "asterisk/adsi.h"
00042 #include "asterisk/options.h"
00043 
00044 static char *tdesc = "Get ADSI CPE ID";
00045 
00046 static char *app = "GetCPEID";
00047 
00048 static char *synopsis = "Get ADSI CPE ID";
00049 
00050 static char *descrip =
00051 "  GetCPEID: Obtains and displays ADSI CPE ID and other information in order\n"
00052 "to properly setup zapata.conf for on-hook operations.\n";
00053 
00054 STANDARD_LOCAL_USER;
00055 
00056 LOCAL_USER_DECL;
00057 
00058 static int cpeid_setstatus(struct ast_channel *chan, char *stuff[], int voice)
00059 {
00060    int justify[5] = { ADSI_JUST_CENT, ADSI_JUST_LEFT, ADSI_JUST_LEFT, ADSI_JUST_LEFT };
00061    char *tmp[5];
00062    int x;
00063    for (x=0;x<4;x++)
00064       tmp[x] = stuff[x];
00065    tmp[4] = NULL;
00066    return adsi_print(chan, tmp, justify, voice);
00067 }
00068 
00069 static int cpeid_exec(struct ast_channel *chan, void *idata)
00070 {
00071    int res=0;
00072    struct localuser *u;
00073    unsigned char cpeid[4];
00074    int gotgeometry = 0;
00075    int gotcpeid = 0;
00076    int width, height, buttons;
00077    char data[4][80];
00078    char *stuff[4];
00079 
00080    LOCAL_USER_ADD(u);
00081    stuff[0] = data[0];
00082    stuff[1] = data[1];
00083    stuff[2] = data[2];
00084    stuff[3] = data[3];
00085    memset(data, 0, sizeof(data));
00086    strncpy(stuff[0], "** CPE Info **", sizeof(data[0]) - 1);
00087    strncpy(stuff[1], "Identifying CPE...", sizeof(data[1]) - 1);
00088    strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1);
00089    res = adsi_load_session(chan, NULL, 0, 1);
00090    if (res > 0) {
00091       cpeid_setstatus(chan, stuff, 0);
00092       res = adsi_get_cpeid(chan, cpeid, 0);
00093       if (res > 0) {
00094          gotcpeid = 1;
00095          if (option_verbose > 2)
00096             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);
00097       }
00098       if (res > -1) {
00099          strncpy(stuff[1], "Measuring CPE...", sizeof(data[1]) - 1);
00100          strncpy(stuff[2], "Please wait...", sizeof(data[2]) - 1);
00101          cpeid_setstatus(chan, stuff, 0);
00102          res = adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
00103          if (res > -1) {
00104             if (option_verbose > 2)
00105                ast_verbose(VERBOSE_PREFIX_3 "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name);
00106             gotgeometry = 1;
00107          }
00108       }
00109       if (res > -1) {
00110          if (gotcpeid)
00111             snprintf(stuff[1], sizeof(data[1]), "CPEID: %02x:%02x:%02x:%02x", cpeid[0], cpeid[1], cpeid[2], cpeid[3]);
00112          else
00113             strncpy(stuff[1], "CPEID Unknown", sizeof(data[1]) - 1);
00114          if (gotgeometry) 
00115             snprintf(stuff[2], sizeof(data[2]), "Geom: %dx%d, %d buttons", width, height, buttons);
00116          else
00117             strncpy(stuff[2], "Geometry unknown", sizeof(data[2]) - 1);
00118          strncpy(stuff[3], "Press # to exit", sizeof(data[3]) - 1);
00119          cpeid_setstatus(chan, stuff, 1);
00120          for(;;) {
00121             res = ast_waitfordigit(chan, 1000);
00122             if (res < 0)
00123                break;
00124             if (res == '#') {
00125                res = 0;
00126                break;
00127             }
00128          }
00129          adsi_unload_session(chan);
00130       }
00131    }
00132    LOCAL_USER_REMOVE(u);
00133    return res;
00134 }
00135 
00136 int unload_module(void)
00137 {
00138    int res;
00139 
00140    res = ast_unregister_application(app);
00141 
00142    STANDARD_HANGUP_LOCALUSERS;
00143 
00144    return res; 
00145 }
00146 
00147 int load_module(void)
00148 {
00149    return ast_register_application(app, cpeid_exec, synopsis, descrip);
00150 }
00151 
00152 char *description(void)
00153 {
00154    return tdesc;
00155 }
00156 
00157 int usecount(void)
00158 {
00159    int res;
00160    STANDARD_USECOUNT(res);
00161    return res;
00162 }
00163 
00164 char *key()
00165 {
00166    return ASTERISK_GPL_KEY;
00167 }

Generated on Sun Aug 6 15:02:24 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.2