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.

Friday, May 16, 2014

I2C driver for Sharp LM167511 lcd display

Recently I got into my hand this old digital phone.


The phone is part of a proprietary system of the early 90s, not so much useful today, but the display seems to be still useful, so I took apart it from the rest, and I begun to test its behaviour.
Display is branded Sharp model LM167511 and it is controled by the OKI MSM6262 chip.
The other 2 components present on the PCB are column drivers T6A39, not particulary interesting to control it.There's not a lot of documentation about this display provided by Sharp nor anyone else, and googling for its name you can only find an old post of a spanish guy asking if someone knows how to use it.
Using a multimeter and the datasheet of the OKI chip I mapped the chip pin on the control headers.


The most hard part has been understand how to use V5.
I thought to use it, in the same way I used to use V0 on the hd44780, the OKI chip expects a negative power on that pin! I got help on that.
But after that it was a piece of cake.
To control it I used an Arduino board and the following circuit:

The display has 7 lines of 16 characters each.
It also has a quite weird memory mapping. The followings are the first character address for each row:
0x08,0x48,0x88,0xc8,0x18,0x98
and this some code I wrote to drive this display.
LM167511.cpp
LM167511.h
sharp_expi2c.ino
that's all.




Sunday, January 5, 2014

SendFSK

Happy new year!

This is an early release of the new version of app_fsk , in which is finally implemented the SendFSK function. Now there should be all it's needed to send and receive messages between two asterisk using only telephone lines. As early release, I'm sure it's full of bugs, so please notify me any weird behaviour you may notice, I'll do my best to fix it.

Here an example for a test using the two apps on the same machine.

[default]
exten => 100, 1, Noop(Incoming call is just arrived on fsk receive number)
exten => 100, n, Answer()
exten => 100, n, ReceiveFSK(msg)
exten => 100, n, Noop(Message received ${msg})
exten => 100, n, Set(f1=${CUT(msg,#,1)})
exten => 100, n, Set(f2=${CUT(msg,#,2)})
exten => 100, n, Set(f3=${CUT(msg,#,3)})
exten => 100, n, Noop(f1: ${f1})
exten => 100, n, Noop(f2: ${f2})
exten => 100, n, Noop(f3: ${f3})
exten => 100, n, wait(5)
exten => 100, n, Hangup()
exten => 200, 1, Noop(Incoming call is just arrived on fsk send number)
exten => 200, n, Progress()
exten => 200, n, Wait(1)
exten => 200, n, Answer()
exten => 200, n, Wait(5)
exten => 200, n, SendFSK(Field1#Field2#Field3)
exten => 200, n, Wait(5)
exten => 200, n, Hangup()

...and here a call file to be used with the previous dialplan.

Channel:local/100@default
Callerid: "FSKer" <0000>
Maxretries:3
Waittime:45
Context: default
Extension: 200

Saturday, December 28, 2013

app_fsk add a flag.

In this second release I decided to add a flag to this application. When you receive a FSK message you can now end the Receive application when data carrier is lost and not only when you got an hangup. Default behaviour is "end when data carrier is lost", if you want to revert to old behaviour and keep application to receive until it got an hangup, just add the "h" flag. New verison can be downloaded here (app_fsk.c)

For your reference I Bell103 encoded  a simple message: "field1#field2#field3" in wav which can be used to test the application.

An example of dialplan might be:

exten => 200,   1,      Answer()
exten => 200,   n,      ReceiveFSK(msg)
exten => 200,   n,      Noop(Message received ${msg})
exten => 200,   n,      Set(f1=${CUT(msg,#,1)})
exten => 200,   n,      Set(f2=${CUT(msg,#,2)})
exten => 200,   n,      Set(f3=${CUT(msg,#,3)})
exten => 200,   n,      Noop(f1: ${f1})
exten => 200,   n,      Noop(f2: ${f2})
exten => 200,   n,      Noop(f3: ${f3})
exten => 200,   n,      Hangup()

exten => h,     1,      Noop(Got hangup)
exten => h,     n,      Noop(Message ${msg} processed on hangup)
exten => h,     n,      Set(f1=${CUT(msg,#,1)})
exten => h,     n,      Set(f2=${CUT(msg,#,2)})
exten => h,     n,      Set(f3=${CUT(msg,#,3)})
exten => h,     n,      Noop(f1: ${f1}) 
exten => h,     n,      Noop(f2: ${f2})
exten => h,     n,      Noop(f3: ${f3})
exten => h,     n,      Hangup()

Friday, December 27, 2013

App_fsk first release

I got, for some reasons, the need to communicate with an Asterisk server which has no internet connection.
So I decided to revive old days, when every digital communication had to be done using telephone lines.
I started coding something that one day, when it will be finally finished, will be called app_fsk.
In my mind, app_fsk should be composed by 2 applications: SendFSK, and ReceiveFSK.
Those two raw tools should be used to send and receive digital messages using POTS lines.
Current implementation has only ReceiveFSK implemented.
It is already usable but its behaviour is a little weird.
It only supports Bell103 FSK modulation, and I agree with anyone would say nowdays 300bps are ridiculous.
it receive fsk message until channel hangs up. Therefore is possible to interact with received message only in the hangup extension (exten => h).
If in spite of that someone wants to give a try, please do it. app_fsk.c
To build app_fsk, just drop the .c file into the apps directory of the Asterisk source code.
app_fsk needs SpanDSP built with option for test programs "--enable-tests".
Also you need to modify standard asterisk mekeopts and include -lspandsp-sim in the SPANDSP_LIB line.
Any feedback would be appreciated.