00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "asterisk.h"
00033
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 413586 $")
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
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
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 '%02x:%02x:%02x:%02x' on '%s'\n",
00091 (unsigned)cpeid[0], (unsigned)cpeid[1], (unsigned)cpeid[2],
00092 (unsigned)cpeid[3], chan->name);
00093 }
00094 if (res > -1) {
00095 strcpy(data[1], "Measuring CPE...");
00096 strcpy(data[2], "Please wait...");
00097 cpeid_setstatus(chan, data, 0);
00098 res = ast_adsi_get_cpeinfo(chan, &width, &height, &buttons, 0);
00099 if (res > -1) {
00100 ast_verb(3, "CPE has %d lines, %d columns, and %d buttons on '%s'\n", height, width, buttons, chan->name);
00101 gotgeometry = 1;
00102 }
00103 }
00104 if (res > -1) {
00105 if (gotcpeid)
00106 snprintf(data[1], 80, "CPEID: %02x:%02x:%02x:%02x",
00107 (unsigned)cpeid[0], (unsigned)cpeid[1],
00108 (unsigned)cpeid[2], (unsigned)cpeid[3]);
00109 else
00110 strcpy(data[1], "CPEID Unknown");
00111 if (gotgeometry)
00112 snprintf(data[2], 80, "Geom: %dx%d, %d buttons", width, height, buttons);
00113 else
00114 strcpy(data[2], "Geometry unknown");
00115 strcpy(data[3], "Press # to exit");
00116 cpeid_setstatus(chan, data, 1);
00117 for(;;) {
00118 res = ast_waitfordigit(chan, 1000);
00119 if (res < 0)
00120 break;
00121 if (res == '#') {
00122 res = 0;
00123 break;
00124 }
00125 }
00126 ast_adsi_unload_session(chan);
00127 }
00128 }
00129
00130 return res;
00131 }
00132
00133 static int unload_module(void)
00134 {
00135 return ast_unregister_application(app);
00136 }
00137
00138 static int load_module(void)
00139 {
00140 return ast_register_application_xml(app, cpeid_exec);
00141 }
00142
00143 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get ADSI CPE ID",
00144 .load = load_module,
00145 .unload = unload_module,
00146 .nonoptreq = "res_adsi",
00147 );