summaryrefslogtreecommitdiff
path: root/fxstest.c
diff options
context:
space:
mode:
authorKevin P. Fleming <kpfleming@digium.com>2008-05-23 14:21:58 +0000
committerKevin P. Fleming <kpfleming@digium.com>2008-05-23 14:21:58 +0000
commit3403af6f5eba79740c98abb2678f9a66ef5a8190 (patch)
tree93415a9598e5363284832757de0596988a421aa6 /fxstest.c
parentdb9cffbffeedcde4ee52027160b96a2548262c5d (diff)
initial copy
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@4335 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'fxstest.c')
-rw-r--r--fxstest.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/fxstest.c b/fxstest.c
new file mode 100644
index 0000000..ad1e4e6
--- /dev/null
+++ b/fxstest.c
@@ -0,0 +1,144 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include "kernel/zaptel.h"
+#include "tonezone.h"
+#include "kernel/wctdm.h"
+
+static int tones[] = {
+ ZT_TONE_DIALTONE,
+ ZT_TONE_BUSY,
+ ZT_TONE_RINGTONE,
+ ZT_TONE_CONGESTION,
+ ZT_TONE_DIALRECALL,
+};
+
+int main(int argc, char *argv[])
+{
+ int fd;
+ int res;
+ int x;
+ if (argc < 3) {
+ fprintf(stderr, "Usage: fxstest <zap device> <cmd>\n"
+ " where cmd is one of:\n"
+ " stats - reports voltages\n"
+ " regdump - dumps ProSLIC registers\n"
+ " tones - plays a series of tones\n"
+ " polarity - tests polarity reversal\n"
+ " ring - rings phone\n");
+ exit(1);
+ }
+ fd = open(argv[1], O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
+ exit(1);
+ }
+ if (!strcasecmp(argv[2], "ring")) {
+ fprintf(stderr, "Ringing phone...\n");
+ x = ZT_RING;
+ res = ioctl(fd, ZT_HOOK, &x);
+ if (res) {
+ fprintf(stderr, "Unable to ring phone...\n");
+ } else {
+ fprintf(stderr, "Phone is ringing...\n");
+ sleep(2);
+ }
+ } else if (!strcasecmp(argv[2], "polarity")) {
+ fprintf(stderr, "Twiddling polarity...\n");
+ x = 0;
+ res = ioctl(fd, ZT_SETPOLARITY, &x);
+ if (res) {
+ fprintf(stderr, "Unable to polarity...\n");
+ } else {
+ fprintf(stderr, "Polarity is forward...\n");
+ sleep(2);
+ x = 1;
+ ioctl(fd, ZT_SETPOLARITY, &x);
+ fprintf(stderr, "Polarity is reversed...\n");
+ sleep(5);
+ x = 0;
+ ioctl(fd, ZT_SETPOLARITY, &x);
+ fprintf(stderr, "Polarity is forward...\n");
+ sleep(2);
+ }
+ } else if (!strcasecmp(argv[2], "tones")) {
+ int x = 0;
+ for (;;) {
+ res = tone_zone_play_tone(fd, tones[x]);
+ if (res)
+ fprintf(stderr, "Unable to play tone %d\n", tones[x]);
+ sleep(3);
+ x=(x+1) % (sizeof(tones) / sizeof(tones[0]));
+ }
+ } else if (!strcasecmp(argv[2], "stats")) {
+ struct wctdm_stats stats;
+ res = ioctl(fd, WCTDM_GET_STATS, &stats);
+ if (res) {
+ fprintf(stderr, "Unable to get stats on channel %s\n", argv[1]);
+ } else {
+ printf("TIP: %7.4f Volts\n", (float)stats.tipvolt / 1000.0);
+ printf("RING: %7.4f Volts\n", (float)stats.ringvolt / 1000.0);
+ printf("VBAT: %7.4f Volts\n", (float)stats.batvolt / 1000.0);
+ }
+ } else if (!strcasecmp(argv[2], "regdump")) {
+ struct wctdm_regs regs;
+ int numregs = NUM_REGS;
+ memset(&regs, 0, sizeof(regs));
+ res = ioctl(fd, WCTDM_GET_REGS, &regs);
+ if (res) {
+ fprintf(stderr, "Unable to get registers on channel %s\n", argv[1]);
+ } else {
+ for (x=60;x<NUM_REGS;x++) {
+ if (regs.direct[x])
+ break;
+ }
+ if (x == NUM_REGS)
+ numregs = 60;
+ printf("Direct registers: \n");
+ for (x=0;x<numregs;x++) {
+ printf("%3d. %02x ", x, regs.direct[x]);
+ if ((x % 8) == 7)
+ printf("\n");
+ }
+ if (numregs == NUM_REGS) {
+ printf("\n\nIndirect registers: \n");
+ for (x=0;x<NUM_INDIRECT_REGS;x++) {
+ printf("%3d. %04x ", x, regs.indirect[x]);
+ if ((x % 6) == 5)
+ printf("\n");
+ }
+ }
+ printf("\n\n");
+ }
+ } else if (!strcasecmp(argv[2], "setdirect") ||
+ !strcasecmp(argv[2], "setindirect")) {
+ struct wctdm_regop regop;
+ int val;
+ int reg;
+ if ((argc < 5) || (sscanf(argv[3], "%i", &reg) != 1) ||
+ (sscanf(argv[4], "%i", &val) != 1)) {
+ fprintf(stderr, "Need a register and value...\n");
+ } else {
+ regop.reg = reg;
+ regop.val = val;
+ if (!strcasecmp(argv[2], "setindirect")) {
+ regop.indirect = 1;
+ regop.val &= 0xff;
+ } else {
+ regop.indirect = 0;
+ }
+ res = ioctl(fd, WCTDM_SET_REG, &regop);
+ if (res)
+ fprintf(stderr, "Unable to get registers on channel %s\n", argv[1]);
+ else
+ printf("Success.\n");
+ }
+ } else
+ fprintf(stderr, "Invalid command\n");
+ close(fd);
+ return 0;
+}