Sunday, May 18, 2014

Asterisk and old Pay Phones

Today I want to talk you about a matter I have with an old Pay phone.
The less young among my readers may recall the old days when there was no mobile phone.
Those days if it happened you had to call someone, you used to go to a payphone booth and call.
During the 70s and early 80s in some Europeans countries among others, there were widespread usage of some special coins, telephone tokens. Those times, if you wanted to use one of those payphone, you also needed a telephone token.

Today's topic however, is not properly the payphone, it is instead the way old Pay Phones collect tokens, or to say it better how to reproduce it in a modern Asterisk based telephone system.
For today topic I focused on the only Pay Phone I have, the Italian U+I.

U+I stands for "urbane ed interurbane" (local calls and long distance call), is the first public phone in Italy by which you could call someone outside of your city without operator's support.
At that times, the signaling between central office and telephones was quite easy, they had only a twisted pair and quite simple technology. The signaling was done just by reversing polarity of the twisted pair.
Signals from central office side was something like

Duration meaning
>250ms end call
~50ms collect token
Continuous out of order

Also, from terminal side, the signaling were done using polarity reversal and interrupting local loop (Pulse dialing).
From terminal side, after the receipt of central office command "collect token", terminal had to invert polarity for 50ms, failing in doing so, was interpreted as "no more tokens" and than call was ended by central office.

Our goal is therefore invert polarity when we need to say to the payphone to collect the token.
My first thought was to use polarity reversal feature, if fits, due to its widespread we can use almost any ATA on the market to have it. Not properly suited for this task, though.
Lets see.
From wikipedia: "Modern loop start trunks also have methods of answer supervision and disconnect supervision to alert a foreign exchange office (FXO) interface that the remote party has answered or hung up. Answer supervision usually takes the form of the central office reversing the polarity of the line for the duration of the call when it has been answered. This condition is called Reverse Battery or battery reversal. Disconnect supervision can take the form of the polarity reversing back. [...]"
It is quite different from what we need; the specification states: momentarily polarity reversal each time payphone needs to collect tokens, using this feature we have a unique polarity reversal from connection to the end of the call.
Projecting this feature on our device, the Italian U+I, the result is an odd behaviour that may be sufficient for someone, but which is definitely not what we want. We may observe, when call connects, the phone collecting the token and also switch its status to "out of order". Call does not drop, it continues until you hang up, and finally when you hang up, due to polarity reversion, the device tries again to collect a token while revert its status in "on line".
To have the control of the line the way we want we can not use any standard feature, we have to control the line directly.
Asterisk controls DAHDI devices directly through chan_dahdi channel driver. It means that to implement the standard feature battery reversal, the way you have on standard connection it have to "manually" invert the polarity on the line.

Reviewing code I could write a new dialplan application Polarity().
Using this new dialplan application is now possible to collect the first token, the one usually collected when the called party answers the line.
Here a dialplan to do so.

[payphone]
exten => _X.,            1,              Set(GLOBAL(cchan)=${CHANNEL})
exten => _X.,            n,              Dial(dahdi/1/${EXTEN},30,G(payphone,ANSWERED,1));

exten => ANSWERED,       1,              Goto(ANSWERED1,1)
exten => ANSWERED,       n,              Goto(ANSWERED2,1)
exten => ANSWERED1,      1,              polarity2(${GLOBAL(cchan)}, 500)
exten => ANSWERED1,      n,              Answer()
exten => ANSWERED2,      1,              wait(1)
exten => ANSWERED2,      2,              Bridge(${GLOBAL(cchan)})


Though using this application is now possible to revert the polarity the way we need when call connects, because Asterisk structure, the dialplan application can not be used during a connected call, the incall token collection feature is therefore still missing.
In a not so distant future I'd like to add a flag to the Dial dialplan application to revert polarity at prefixed time intervals starting when called party answers the call.

No comments:

Post a Comment