It is easy to use DIDs with SIP and BRI lines as they send there own number in the call messaging. When using FXO lines though, this has to be done based on hardware indexes. This can be done in FreePBX with zaptel trunks quite easily but as the chan_pika trunks are only supported as custom trunks, this functionality is not available through the GUI.

This thread is to show you how to do it by editing the asterisk config files by hand. For this example I will assign a DID of 1234567 for FXO line 1 and a DID of 5551234 for FXO line 2.

To get our PIKA FXO trunks to behave like zaptel ones, add the following to the /etc/asterisk/extensions_custom.conf file. Do not add it to /etc/asterisk/extensions_additional.conf file because this file is overwritten every time changes are applied in the FreePBX GUI. The /etc/asterisk/extensions_custom.conf file is not over written.

NOTE: The "**" below should be a close curly brace. For some reason the forum replaces them.

Code:
[macro-from-pika-fxo-1]
include => macro-from-pika-fxo-1-custom
exten => s,1,Noop(Entering macro-from-pika-fxo-1 with DID = ${DID** and setting to: 1234567)
exten => s,n,Set(__FROM_DID=1234567)
exten => s,n,Goto(from-trunk,1234567,1)

; end of [macro-from-pika-fxo-1]

[macro-from-pika-fxo-2]
include => macro-from-pika-fxo-2-custom
exten => s,1,Noop(Entering macro-from-pika-fxo-2 with DID = ${DID** and setting to: 5551234)
exten => s,n,Set(__FROM_DID=5551234)
exten => s,n,Goto(from-trunk,5551234,1)

; end of [macro-from-pika-fxo-2]


[from-pika-fxo]
include => from-pika-fxo-custom
exten => _X.,1,Set(DID=${EXTEN**)
exten => _X.,n,Goto(s,1)
exten => s,1,Noop(Entering from-pika-fxo with DID == ${DID**)
exten => s,n,Ringing()
exten => s,n,Set(DID=${IF($["${DID**"= ""]?s:${DID**)**)
exten => s,n,Noop(DID is now ${DID**)
exten => s,n,Set(CHAN=${CHANNEL:4**)
exten => s,n,Set(CHAN=${CUT(CHAN,/,3)**)
exten => s,n,Macro(from-pika-fxo-${CHAN**,${DID**,1)
exten => s,n,Noop(Returned from Macro from-pika-fxo-${CHAN**)
exten => s,n,Goto(from-pstn,${DID**,1)
exten => fax,1,Goto(ext-fax,in_fax,1)

; end of [from-pika-fxo]
Now you need to go into the /etc/asterisk/pika.conf file and change the context to from-pika-fxo instead of from-pstn as highlighted below.

Code:
[fxo]
gp_group=0
conf_ref=TRUNK_23800186
context=from-pika-fxo  
extension=s
Now you need to create your incoming routes for the two DIDs you just created using the FreePBX GUI and apply configuration changes. You can now route based on the FXO line the call comes in.

If you want to create additional DID numbers for your other PIKA FXO lines, just add additional macro-from-pika-fxo-# as shown above where # is the line number. Any line that does not have a macro-from-pika-fxo-# associated with it will route through the from-pstn context the way it did before.

Hope this helps,
Skar