summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2004-08-03 18:36:07 +0000
committermarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2004-08-03 18:36:07 +0000
commitf4cfabc0a3838eda41669f7e0f63782aa8cefd88 (patch)
tree05546c9304ae9c23764d780915b898d7743911e4
parent59d533b18bc76fb3b08c284dfe9fe84b124003e4 (diff)
Merge polarity reversal detection (bug #9)
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@447 5390a7c7-147a-4af0-8ec9-7488f05a26cb
-rwxr-xr-xwcfxs.c38
-rwxr-xr-xwctdm.c38
-rwxr-xr-xzaptel.h3
3 files changed, 71 insertions, 8 deletions
diff --git a/wcfxs.c b/wcfxs.c
index 2b771c4..b59712b 100755
--- a/wcfxs.c
+++ b/wcfxs.c
@@ -228,6 +228,7 @@ static struct fxo_mode {
#define RING_DEBOUNCE 64 /* Ringer Debounce (in ms) */
#define BATT_DEBOUNCE 64 /* Battery debounce (in ms) */
+#define POLARITY_DEBOUNCE 64 /* Polarity debounce (in ms) */
#define BATT_THRESH 3 /* Anything under this is "no battery" */
#define OHT_TIMER 6000 /* How long after RING to retain OHT */
@@ -284,6 +285,9 @@ struct wcfxs {
int battdebounce[NUM_CARDS];
int nobatttimer[NUM_CARDS];
int battery[NUM_CARDS];
+ int lastpol[NUM_CARDS];
+ int polarity[NUM_CARDS];
+ int polaritydebounce[NUM_CARDS];
} fxo;
struct {
int oldrxhook[NUM_CARDS];
@@ -1399,7 +1403,8 @@ static inline void wcfxs_voicedaa_check_hook(struct wcfxs *wc, int card)
{
static int count = 0;
if (!(count++ % 100)) {
- printk("Card %d: Voltage: %d\n", card + 1, b);
+ printk("Card %d: Voltage: %d Debounce %d\n", card + 1,
+ b, wc->mod.fxo.battdebounce[card]);
}
}
#endif
@@ -1431,7 +1436,8 @@ static inline void wcfxs_voicedaa_check_hook(struct wcfxs *wc, int card)
} else if (abs(b) > BATT_THRESH) {
if (!wc->mod.fxo.battery[card] && !wc->mod.fxo.battdebounce[card]) {
if (debug)
- printk("BATTERY on %d/%d!\n", wc->span.spanno, card + 1);
+ printk("BATTERY on %d/%d (%s)!\n", wc->span.spanno, card + 1,
+ (b < 0) ? "-" : "+");
#ifdef ZERO_BATT_RING
if (wc->onhook) {
wc->onhook = 0;
@@ -1442,18 +1448,42 @@ static inline void wcfxs_voicedaa_check_hook(struct wcfxs *wc, int card)
#else
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
#endif
- wc->mod.fxo.battery[card] = 1;
wc->mod.fxo.nobatttimer[card] = 0;
wc->mod.fxo.battdebounce[card] = BATT_DEBOUNCE;
} else if (wc->mod.fxo.battery[card])
wc->mod.fxo.battdebounce[card] = BATT_DEBOUNCE;
+
+ if (wc->mod.fxo.lastpol[card] >= 0) {
+ if (b < 0) {
+ wc->mod.fxo.lastpol[card] = -1;
+ wc->mod.fxo.polaritydebounce[card] = POLARITY_DEBOUNCE;
+ }
+ }
+ if (wc->mod.fxo.lastpol[card] <= 0) {
+ if (b > 0) {
+ wc->mod.fxo.lastpol[card] = 1;
+ wc->mod.fxo.polaritydebounce[card] = POLARITY_DEBOUNCE;
+ }
+ }
} else {
/* It's something else... */
wc->mod.fxo.battdebounce[card] = BATT_DEBOUNCE;
}
if (wc->mod.fxo.battdebounce[card])
wc->mod.fxo.battdebounce[card]--;
-
+ if (wc->mod.fxo.polaritydebounce[card]) {
+ wc->mod.fxo.polaritydebounce[card]--;
+ if (wc->mod.fxo.polaritydebounce[card] < 1) {
+ if (wc->mod.fxo.lastpol[card] != wc->mod.fxo.polarity[card]) {
+ printk("%lu Polarity reversed (%d -> %d)\n", jiffies,
+ wc->mod.fxo.polarity[card],
+ wc->mod.fxo.lastpol[card]);
+ if (wc->mod.fxo.polarity[card])
+ zt_qevent_lock(&wc->chans[card], ZT_EVENT_POLARITY);
+ wc->mod.fxo.polarity[card] = wc->mod.fxo.lastpol[card];
+ }
+ }
+ }
}
static inline void wcfxs_proslic_check_hook(struct wcfxs *wc, int card)
diff --git a/wctdm.c b/wctdm.c
index 2b771c4..b59712b 100755
--- a/wctdm.c
+++ b/wctdm.c
@@ -228,6 +228,7 @@ static struct fxo_mode {
#define RING_DEBOUNCE 64 /* Ringer Debounce (in ms) */
#define BATT_DEBOUNCE 64 /* Battery debounce (in ms) */
+#define POLARITY_DEBOUNCE 64 /* Polarity debounce (in ms) */
#define BATT_THRESH 3 /* Anything under this is "no battery" */
#define OHT_TIMER 6000 /* How long after RING to retain OHT */
@@ -284,6 +285,9 @@ struct wcfxs {
int battdebounce[NUM_CARDS];
int nobatttimer[NUM_CARDS];
int battery[NUM_CARDS];
+ int lastpol[NUM_CARDS];
+ int polarity[NUM_CARDS];
+ int polaritydebounce[NUM_CARDS];
} fxo;
struct {
int oldrxhook[NUM_CARDS];
@@ -1399,7 +1403,8 @@ static inline void wcfxs_voicedaa_check_hook(struct wcfxs *wc, int card)
{
static int count = 0;
if (!(count++ % 100)) {
- printk("Card %d: Voltage: %d\n", card + 1, b);
+ printk("Card %d: Voltage: %d Debounce %d\n", card + 1,
+ b, wc->mod.fxo.battdebounce[card]);
}
}
#endif
@@ -1431,7 +1436,8 @@ static inline void wcfxs_voicedaa_check_hook(struct wcfxs *wc, int card)
} else if (abs(b) > BATT_THRESH) {
if (!wc->mod.fxo.battery[card] && !wc->mod.fxo.battdebounce[card]) {
if (debug)
- printk("BATTERY on %d/%d!\n", wc->span.spanno, card + 1);
+ printk("BATTERY on %d/%d (%s)!\n", wc->span.spanno, card + 1,
+ (b < 0) ? "-" : "+");
#ifdef ZERO_BATT_RING
if (wc->onhook) {
wc->onhook = 0;
@@ -1442,18 +1448,42 @@ static inline void wcfxs_voicedaa_check_hook(struct wcfxs *wc, int card)
#else
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
#endif
- wc->mod.fxo.battery[card] = 1;
wc->mod.fxo.nobatttimer[card] = 0;
wc->mod.fxo.battdebounce[card] = BATT_DEBOUNCE;
} else if (wc->mod.fxo.battery[card])
wc->mod.fxo.battdebounce[card] = BATT_DEBOUNCE;
+
+ if (wc->mod.fxo.lastpol[card] >= 0) {
+ if (b < 0) {
+ wc->mod.fxo.lastpol[card] = -1;
+ wc->mod.fxo.polaritydebounce[card] = POLARITY_DEBOUNCE;
+ }
+ }
+ if (wc->mod.fxo.lastpol[card] <= 0) {
+ if (b > 0) {
+ wc->mod.fxo.lastpol[card] = 1;
+ wc->mod.fxo.polaritydebounce[card] = POLARITY_DEBOUNCE;
+ }
+ }
} else {
/* It's something else... */
wc->mod.fxo.battdebounce[card] = BATT_DEBOUNCE;
}
if (wc->mod.fxo.battdebounce[card])
wc->mod.fxo.battdebounce[card]--;
-
+ if (wc->mod.fxo.polaritydebounce[card]) {
+ wc->mod.fxo.polaritydebounce[card]--;
+ if (wc->mod.fxo.polaritydebounce[card] < 1) {
+ if (wc->mod.fxo.lastpol[card] != wc->mod.fxo.polarity[card]) {
+ printk("%lu Polarity reversed (%d -> %d)\n", jiffies,
+ wc->mod.fxo.polarity[card],
+ wc->mod.fxo.lastpol[card]);
+ if (wc->mod.fxo.polarity[card])
+ zt_qevent_lock(&wc->chans[card], ZT_EVENT_POLARITY);
+ wc->mod.fxo.polarity[card] = wc->mod.fxo.lastpol[card];
+ }
+ }
+ }
}
static inline void wcfxs_proslic_check_hook(struct wcfxs *wc, int card)
diff --git a/zaptel.h b/zaptel.h
index f1a1fa7..b3d5483 100755
--- a/zaptel.h
+++ b/zaptel.h
@@ -771,6 +771,9 @@ struct zt_tone_def { /* Structure for zone programming */
/* Timer event -- ping ready */
#define ZT_EVENT_TIMER_PING 16
+/* Polarity reversal event */
+#define ZT_EVENT_POLARITY 17
+
#define ZT_EVENT_PULSEDIGIT (1 << 16) /* This is OR'd with the digit received */
#define ZT_EVENT_DTMFDIGIT (1 << 17) /* Ditto for DTMF */