[Asterisk-cvs] zaptel wcfxs.c,1.79,1.80 zaptel.h,1.35,1.36

markster at lists.digium.com markster at lists.digium.com
Tue Aug 3 14:50:07 CDT 2004


Update of /usr/cvsroot/zaptel
In directory localhost.localdomain:/tmp/cvs-serv7026

Modified Files:
	wcfxs.c zaptel.h 
Log Message:
Merge polarity reversal detection (bug #9)


Index: wcfxs.c
===================================================================
RCS file: /usr/cvsroot/zaptel/wcfxs.c,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- wcfxs.c	26 Jul 2004 19:15:10 -0000	1.79
+++ wcfxs.c	3 Aug 2004 18:36:07 -0000	1.80
@@ -228,6 +228,7 @@
 
 #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 @@
 			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 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 @@
 	} 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 @@
 #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)

Index: zaptel.h
===================================================================
RCS file: /usr/cvsroot/zaptel/zaptel.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- zaptel.h	28 Jul 2004 13:35:55 -0000	1.35
+++ zaptel.h	3 Aug 2004 18:36:07 -0000	1.36
@@ -771,6 +771,9 @@
 /* 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 */
 




More information about the svn-commits mailing list