有许多公司生产用于 Asterisk 的 PSTN 板卡。这些板卡需要安装驱动程序,这样 Linux才可以识别
它们 (DAHDI 包含了 Digium 的板卡驱动) 。 从这一点看, 配置是被 Asterisk module chan_dahdi 处理的。

 当安装电话板卡硬件时,请确保升级了  /etc/dahdi/modules  文件以使能与你的硬件适应的 modules,
然后通过初始化脚本(/etc/init.d/dahdi)重载DAHDI,你也可以使用 dahdi_genconf modules 命令生成  modules  文件

 要配置一张FXO板卡能够在Asterisk系统上工作,需要修改以下的两个文件:
  /etc/dahdi/system.conf //这个是DAHDI的配置文件,主要用来指定系统中可用的Channels
  /etc/asterisk/chan_dahdi.conf //这个主要是告诉Asterisk系统中有效的Channels以及它们各自使用的信令。

 下面假设我这里有一张DAHDI的板卡,上面有4个FXO端口,/etc/dahdi/system.conf的内容如下:
  
# Echo Cancellers
 回音抵消器
# ^^^^^^^^^^^^^^^
# DAHDI uses modular echo cancellers that are configured per channel. The echo
 DAHDI在每个通道上的回音抵消器是模块化的。
# cancellers are compiled and installed as part of the dahdi-linux package.
 回音抵消器作为dahdi-Linux包的一部分被编译和安装
# You can specify in this file the echo canceller to be used for each
 你可以在本文件中为每个通道指定其使用的回音抵消器
# channel. The default behavior is for there to be NO echo canceller on any
  默认每个通道上是没有任何回音抵消器的
# channel, so it is very important that you specify one here.
  所以你在这里设置回音抵消器是非常重要的。
# Valid echo cancellers are: hwec, mg2, kb1, sec2, and sec.
 可用的回音抵消器有:hwec   mg2  kb1  sec2   sec
# 'hwec' is a special echo canceller that should be used if hardware echo
hwec是一个特别的回音抵消器,如果硬件回音抵消器想在指定的通道上可用
# cancellation is desired on and available on the specified channels.

# If compiled, 'hpec' is also a valid echo canceller.
hpec也是一个可用的回音抵消器,如果编译了的话。
# To configure the default echo cancellers, use the format:
   配置默认的回音抵消器,用法如下:
# echocanceller=,
#
# Example:例如:
# Configure channels 1 through 8 to use the mg2 echo canceller
配置通道1到通道8使用mg2回音抵消器,如下:
#echocanceller=mg2,1-8
#
# And change channel 2 to use the kb1 echo canceller.
  通道2使用kb1回音抵消器,如下:
#echocanceller=kb1,2


  loadzone = us //我的理解是区域(国家的代码,两个字母如:中国=cn)的选择,然后板卡会根据你的区域来播放匹配的音乐如:拨号音、忙音等
  defaultzone = us //设置默认的区域
  fxsks = 1-4 //指定板卡上使用FXS信令的通道,也就是FXO端口有哪些。
  echocanceller=oslec,1-4 //指定通道1-4所使用的 回音抵消器

 一旦你的板卡上的channels被操作系统所识别,那么你就必须在/etc/asterisk/chan_dahdi.conf文件中来配置,以让asterisk来知道有哪些channels
在板卡上是可以使用的。/etc/asterisk/chan_dahdi.conf的内容如下:

/etc/asterisk/chan_dahdi.conf
  [channels]
  signalling = fxs_ks   //指定Channels所使用的信令为FXS_KS
  channel => 1-4 //定义可以使用的Channels为1、2、3、4
  context = fxo-incoming  //定义呼叫开始的context
 在这个例子中,我们告诉 Asterisk,系统中的头 4 个 DAHDI channels 是 FXO 端口

------------------------------------------------------------------------------------------------------------------
 在这个配置文件中还可以配置一个通道组group,然后把这些通道都加入到相应的组中。
Channels and Groups
There are three different kind of groups in Asterisk:
在Asterisk中有三种不同的Group
(1) group=blah
— This is used to bundle (typically trunk) interfaces together so that you can use something like Dial,Zap/g2/.... to use any of the channels in group 2.
 这种是用在中继线路中的,你可以用“Dial,Zap/g2/” 来使用group 2中的任何一个线路
(2) callgroup=blah
— This is a list of group memberships that you belong to for call pickup purposes
 
(3) pickupgroup=blah
— This is a list of groups that you are permitted to pickup in.

For #2 and #3, basically, you just dial *8# and you can pickup a ringing phone if you have a group in your pickupgroup that is in their callgroup.

hint: pickupgroup is for FXS interfaces while callgroup is for FXO interfaces.
-----------------------------------------------------------------------------------------------
group = 1
channel => 1-4
group = 1,2
channel => 5-6
group = 2,3
channel => 7-8
group = 4
channel => 9-12
group =
channel => 13-16


Channnels 1-4 are in just group 1.
Channels 5 and 6 are in groups 1 and 2.
Channels 7 and 8 are in groups 2 and 3.
Channels 9-12 are in group 4, and
Channels 13-16 are in no groups... so...


1,1,Dial,Zap/g1...would give you the first channel in the range 1-6 that was available.
 将会把group 1中可用的,第一个通道给你使用。
1,1,Dial,Zap/G1...would give you the largest channel in the range 1-6 that was available see http://www.voip-info.org/wiki/view/Asterisk+ZAP+channels.
 将会把group 1中可用的,最大的那个通道给你用。
1,1,Dial,Zap/g2...would give you the first channel in the range 5-8 that was available.

1,1,Dial,Zap/g3...would give you the first channel in the range 7-8 that was available

1,1,Dial,Zap/g4...would give you the first channel in the range 9-12 that was available.