From 87909fa28e55346e164f7c1ea3bec21aa9e1e01d Mon Sep 17 00:00:00 2001 From: markster Date: Fri, 21 Jun 2002 01:40:13 +0000 Subject: Version 0.1.12 from FTP git-svn-id: http://svn.digium.com/svn/asterisk/trunk@465 f38db490-d61c-443f-a65b-d21fe96a405b --- res/res_adsi.c | 338 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 221 insertions(+), 117 deletions(-) (limited to 'res/res_adsi.c') diff --git a/res/res_adsi.c b/res/res_adsi.c index e464c0151..11a23c987 100755 --- a/res/res_adsi.c +++ b/res/res_adsi.c @@ -99,27 +99,6 @@ static int adsi_generate(unsigned char *buf, int msgtype, char *msg, int msglen, } -#if 0 -static int adsi_careful_send(struct ast_channel *chan, unsigned char *buf, int len, int *remainder) -{ - int res; - fd_set fds; - while(len) { - FD_ZERO(&fds); - FD_SET(chan->fds[0], &fds); - select(chan->fds[0] + 1, NULL, &fds, NULL, NULL); - res = write(chan->fds[0], buf, len); - if (res < 1) { - ast_log(LOG_WARNING, "Failed to write: %s\n", strerror(errno)); - return -1; - } - buf += res; - len -= res; - } - return 0; -} - -#else static int adsi_careful_send(struct ast_channel *chan, unsigned char *buf, int len, int *remainder) { /* Sends carefully on a full duplex channel by using reading for @@ -190,7 +169,6 @@ static int adsi_careful_send(struct ast_channel *chan, unsigned char *buf, int l } return 0; } -#endif static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **msg, int *msglen, int *msgtype) { @@ -305,7 +283,7 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms break; else { retries++; - ast_log(LOG_DEBUG, "Retransmitting (%d), from %d\n", start + 1); + ast_log(LOG_DEBUG, "Retransmitting (%d), from %d\n", retries, start + 1); } } else { retries++; @@ -502,14 +480,15 @@ int adsi_download_connect(unsigned char *buf, unsigned char *service, unsigned /* Delimiter */ buf[bytes++] = 0xff; - for (x=0;x<4;x++) + for (x=0;x<4;x++) { buf[bytes++] = fdn[x]; + } for (x=0;x<4;x++) buf[bytes++] = sec[x]; - if (ver > -1) - buf[bytes++] = ver & 0xff; + buf[bytes++] = ver & 0xff; buf[1] = bytes - 2; + return bytes; } @@ -529,6 +508,158 @@ int adsi_disconnect_session(unsigned char *buf) } +int adsi_query_cpeid(unsigned char *buf) +{ + int bytes = 0; + buf[bytes++] = ADSI_QUERY_CPEID; + /* Reserve space for length */ + bytes++; + buf[1] = bytes - 2; + return bytes; +} + +int adsi_query_cpeinfo(unsigned char *buf) +{ + int bytes = 0; + buf[bytes++] = ADSI_QUERY_CONFIG; + /* Reserve space for length */ + bytes++; + buf[1] = bytes - 2; + return bytes; +} + +int adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen) +{ + int bytes = 0; + int res; + unsigned char current = 0; + int gotstar = 0; + int pos = 0; + memset(buf, 0, sizeof(buf)); + while(bytes <= maxlen) { + /* Wait up to a second for a digit */ + res = ast_waitfordigit(chan, 1000); + if (!res) + break; + if (res == '*') { + gotstar = 1; + continue; + } + /* Ignore anything other than a digit */ + if ((res < '0') || (res > '9')) + continue; + res -= '0'; + if (gotstar) + res += 9; + if (pos) { + pos = 0; + buf[bytes++] = (res << 4) | current; + } else { + pos = 1; + current = res; + } + gotstar = 0; + } + return bytes; +} + +int adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice) +{ + char buf[256]; + int bytes = 0; + int res; + bytes += adsi_data_mode(buf); + adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY); + + bytes = 0; + bytes += adsi_query_cpeid(buf); + adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY); + + /* Get response */ + memset(buf, 0, sizeof(buf)); + res = adsi_read_encoded_dtmf(chan, cpeid, 4); + if (res != 4) { + ast_log(LOG_WARNING, "Got %d bytes back of encoded DTMF, expecting 4\n", res); + res = 0; + } else { + res = 1; + } + + if (voice) { + bytes = 0; + bytes += adsi_voice_mode(buf, 0); + adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY); + /* Ignore the resulting DTMF B announcing it's in voice mode */ + ast_waitfordigit(chan, 1000); + } + return res; +} + +int adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice) +{ + char buf[256]; + int bytes = 0; + int res; + bytes += adsi_data_mode(buf); + adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY); + + bytes = 0; + bytes += adsi_query_cpeinfo(buf); + adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY); + + /* Get width */ + memset(buf, 0, sizeof(buf)); + res = ast_readstring(chan, buf, 2, 1000, 500, ""); + if (res < 0) + return res; + if (strlen(buf) != 2) { + ast_log(LOG_WARNING, "Got %d bytes of width, expecting 2\n", res); + res = 0; + } else { + res = 1; + } + if (width) + *width = atoi(buf); + /* Get height */ + memset(buf, 0, sizeof(buf)); + if (res) { + res = ast_readstring(chan, buf, 2, 1000, 500, ""); + if (res < 0) + return res; + if (strlen(buf) != 2) { + ast_log(LOG_WARNING, "Got %d bytes of height, expecting 2\n", res); + res = 0; + } else { + res = 1; + } + if (height) + *height= atoi(buf); + } + /* Get buttons */ + memset(buf, 0, sizeof(buf)); + if (res) { + res = ast_readstring(chan, buf, 1, 1000, 500, ""); + if (res < 0) + return res; + if (strlen(buf) != 1) { + ast_log(LOG_WARNING, "Got %d bytes of buttons, expecting 1\n", res); + res = 0; + } else { + res = 1; + } + if (buttons) + *buttons = atoi(buf); + } + if (voice) { + bytes = 0; + bytes += adsi_voice_mode(buf, 0); + adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY); + /* Ignore the resulting DTMF B announcing it's in voice mode */ + ast_waitfordigit(chan, 1000); + } + return res; +} + int adsi_data_mode(unsigned char *buf) { int bytes=0; @@ -544,6 +675,36 @@ int adsi_data_mode(unsigned char *buf) } +int adsi_clear_soft_keys(unsigned char *buf) +{ + int bytes=0; + + /* Message type */ + buf[bytes++] = ADSI_CLEAR_SOFTKEY; + + /* Reserve space for length */ + bytes++; + + buf[1] = bytes - 2; + return bytes; + +} + +int adsi_clear_screen(unsigned char *buf) +{ + int bytes=0; + + /* Message type */ + buf[bytes++] = ADSI_CLEAR_SCREEN; + + /* Reserve space for length */ + bytes++; + + buf[1] = bytes - 2; + return bytes; + +} + int adsi_voice_mode(unsigned char *buf, int when) { int bytes=0; @@ -719,53 +880,7 @@ int adsi_set_line(unsigned char *buf, int page, int line) static int total = 0; static int speeds = 0; -#if 0 -int adsi_channel_init(struct ast_channel *chan) -{ - char dsp[256]; - char keys[256]; - int bytes; - int x; - unsigned char *msgs[3]; - unsigned char keyd[6]; - int lens[3]; - int types[3]; - memset(dsp, 0, sizeof(dsp)); - memset(keys, 0, sizeof(keys)); - memset(msgs, 0, sizeof(msgs)); - - /* Start with initial display setup */ - bytes = 0; - bytes += adsi_connect_session(dsp, NULL, -1); - for (x=0;x