⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcicard.pas

📁 由内线接电话终端
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    ChIndexType        : word; //通道逻辑号(低11bit)(0--2047)+ChType(高5bit)      : 5;  //通道类型(见CHTYPE定义)
    LinkChIndexType    : word; //相关的另一个通道逻辑号(低11bit)(0--2047)+ unsigned short LinkChType(高5bit)  : 5; //相关的另一个通道的线路类型
    DataLen            : byte;  //0表示没有后面的大union部分,否则表示union的实际有效长度
                                //1--255表示有后面的大union部分
    DataSpec           : byte; //数据描述
                               // DataSpec低5bit;     //被叫长度(0--31)
                                // 主叫长度(0--31)= DataLen>MAXCALLLEN?DataLen-MAXCALLLEN:0;
//只有当 DataLen >0  时有效
    DataB : array[0..255] of byte;
    {
       union
       [
        struct
        [
          char  Called[MAXCALLLEN];	//被叫号码(0--31)
          char  Caller[MAXCALLLEN];    //主叫号码(0--31)
         ]
	 unsigned char  DataB[256];
	 unsigned short DataW[128];
       ]
    }
end;
type
  PRMSG =^RMSG ;

TMSG = class  //相当于c++的类结构
 public
  Msg : RMSG; //实际操作的数据对象
 public
  constructor Create();overload;
  constructor Create(pMsg : PRMSG);overload;//拷贝构造
  procedure Clear();
  procedure InitDataLen(datalen:word);
  procedure InitCallNull();
  procedure SetToNullMsg(datalen:word); //设置为空消息
  function  AddByte(data:byte):word;
  function  AddWord(data:word):word;
  function  AddStr(data:string):word;

  function  IsNullMsg():word;


  ///////used for call msg
  function  GetCalledLen():word;
  function  GetCallerLen():word;
  procedure SetCalledLen(len:word);
  procedure SetCallerLen(len:word);
  procedure ClearCalled();
  procedure ClearCaller();
  procedure AppendCaller(code:char);overload;
  procedure AppendCalled(code:char);overload;
  procedure AppendCalledTerm();
  procedure AppendCallerTerm();
  procedure AppendCaller(const phone:string);overload;
  procedure AppendCalled(const phone:string);overload;
  function  GetCalled():pchar;
  function  GetCaller():pchar;
  function  DsOfMsg():word;//消息的大小(双字表示)
  function  GetMsgNameStr(IsUpMsg:byte):string;//取消息的字符串解释
  function  GetChTypeNameStr():string;//取通道类型的名字
 private
  function  GetMsgType():byte;
  procedure SetMsgType(const Value: byte);
  function  GetMsgFunction():byte;
  procedure SetMsgFunction(const Value: byte);
  function  GetChIndex():word;
  procedure SetChIndex(const Value: word);
  function  GetChType():word;
  procedure SetChType(const Value: word);
  function  GetLinkChIndex():word;
  procedure SetLinkChIndex(const Value: word);
  function  GetLinkChType():word;
  procedure SetLinkChType(const Value: word);

 public
  property MsgType : byte  read GetMsgType write SetMsgType;
  property MsgFunction : byte  read GetMsgFunction write SetMsgFunction;
  property ChIndex : word  read GetChIndex write SetChIndex;
  property ChType : word  read GetChType write SetChType;
  property LinkChIndex : word  read GetLinkChIndex write SetLinkChIndex;
  property LinkChType : word  read GetLinkChType write SetLinkChType;
end;

///以下为DLL的函数说明
//long  __stdcall PCIGetCardNum(); //检测目前实际存在并激活的卡的数目
Function  PCIGETCARDNUM() : Longint; stdcall;external 'PCICARD.DLL' ;

//long  __stdcall PCIGetConfigCardNum();//返回配置文件中设置使用的卡数目
Function  PCIGETCONFIGCARDNUM() : Longint; stdcall;external 'PCICARD.DLL' ;

//long  __stdcall GetCardHardwareSerial(long cardno); //返回对应位置的卡的硬件序列号
Function  PCIGETCARDHARDWARESERIAL(CARDNO:Longint) : Longint; stdcall;external 'PCICARD.DLL' ;

{  GETCARDHARDWARESERIAL 函数返回结果的位域意义
    bit[15.. 0] = CardHardwareSerialNo // 实际的本卡硬件序列号
    bit[19..16] = CardHardwareLine     // 硬件支持的通道数目
	                                   // 数字线:1--8 表示支持1--8个E1
									   // 模拟线:1--6 表示支持4--24线(以4线为单位)
    bit[23..20] = CardHardwareRes      // 卡上带有的资源类型bit3=fsk,bit2=fax
    bit[27..24] = CardSwitch           //卡号(卡上跳线开关号0--15)
	bit[31..28] = CardHardwareFlag     //卡类型标志(1=4线模拟卡,2=数字卡,3=24线模拟卡)
}
//long  __stdcall GetCardHardwareType(long cardno); //返回对应位置的卡的硬件类型
Function  PCIGETCARDHARDWARETYPE(CARDNO:Longint) : Longint; stdcall;external 'PCICARD.DLL' ;

//long  __stdcall PCIGETLOGICCHNUM(long CHTYPE); //获取指定类型线路配置的逻辑通道数目
Function  PCIGETLOGICCHNUM(CHTYPE:Longint) : Longint; stdcall;external 'PCICARD.DLL' ;

//long  __stdcall PCIGETTOTALLOGICCHNUM(); //获取系统中所有类型线路配置的逻辑通道数目总和
Function  PCIGETTOTALLOGICCHNUM() : Longint; stdcall;external 'PCICARD.DLL' ;

//long  __stdcall PCIGrabMsg(RMSG *pmsg,unsigned short msgnum);//不阻塞接收消息(不论是否收到消息,函数都返回)
Function  PCIGRABMSG(PMSG:pointer;MSGNUM:word) : Longint; stdcall;external 'PCICARD.DLL' ;

//long  __stdcall PCISendMsg(RMSG *pmsg); //不阻塞发送消息(不论是否发送成功消息,函数都返回)
Function  PCISENDMSG(PMSG:pointer) : Longint; stdcall;external 'PCICARD.DLL' ;

function GetChTypeName(chtype:word):string;//取通道类型的名字

implementation

  uses SysUtils;

  constructor TMSG.Create();
  begin
    Clear();
  end;

  constructor TMSG.Create(pMsg : PRMSG);//拷贝构造
  begin
    move(pmsg^,Msg,8);
    if(pMsg.DataLen>0)then
      move(pmsg.DataB, Msg.DataB,pMsg.DataLen);
  end;


  procedure TMSG.Clear();
  begin
    Msg.MsgTypeFunction:=0;
    Msg.Param:=0;
    Msg.ChIndexType:=0;
    Msg.LinkChIndexType:=0;
    Msg.DataLen:=0;
    Msg.DataSpec:=0;
  end;

  procedure TMSG.InitDataLen(datalen:word);
  begin
    Msg.DataLen:=datalen;
  end;

  procedure TMSG.InitCallNull();
  begin
    Msg.DataLen:=0;
    Msg.DataSpec:=0;
  end;

  procedure TMSG.SetToNullMsg(datalen:word); //设置为空消息
  begin
    Clear();
    InitDataLen(datalen);
  end;

  function TMSG.AddByte(data:byte):word;
  begin
    if(Msg.DataLen=255) then
      result:=0
    else
    begin
      Msg.DataB[Msg.DataLen]:=data;
      Msg.DataLen:=      Msg.DataLen+1;
      result:=1;
    end;
  end;

  function TMSG.AddWord(data:word):word;
  begin
    if(Msg.DataLen>=254) then
      result:=0
    else
    begin
      Msg.DataB[Msg.DataLen]:=data and $FF;
      Msg.DataLen:=Msg.DataLen+1;
      Msg.DataB[Msg.DataLen]:=data shr 8;
      Msg.DataLen:=Msg.DataLen+1;
      result:=2;
    end;
  end;

  function  TMSG.AddStr(data:string):word;
  var
    len:word;
  begin
    result:=0;
    len:=length(data);
    if(len+Msg.DataLen>=255)then
	exit;
    strlcopy(@(Msg.DataB[Msg.DataLen]),pchar(data),len);
    Msg.DataLen:=Msg.DataLen+len+1;
    result:=len+1;
  end;

  function  TMSG.GetCalledLen():word;
  begin
    result := Msg.DataSpec mod MAXCALLLEN;
  end;

  function  TMSG.GetCallerLen():word;
  begin
    if(Msg.DataLen > MAXCALLLEN ) then
      result:= Msg.DataLen-MAXCALLLEN
    else
      result:=0;
  end;

  procedure TMSG.SetCalledLen(len:word);
  begin
    Msg.DataSpec := len mod MAXCALLLEN;
    if(0=GetCallerLen()) then//原来无主叫号码,调整总长度
      Msg.DataLen:=Msg.DataSpec ;
  end;

  procedure TMSG.SetCallerLen(len:word);
  begin
    if(len>0)then
      Msg.DataLen:=MAXCALLLEN+(len mod MAXCALLLEN)
    else
      Msg.DataLen:=Msg.DataSpec;
  end;

  procedure TMSG.ClearCalled();
  begin
    SetCalledLen(0);
  end;

  procedure TMSG.ClearCaller();
  begin
    SetCallerLen(0);
  end;

  procedure TMSG.AppendCaller(code:char);
  var
    len:word;
  begin
    len:=GetCallerLen();
    if(len<MAXCALLLEN-1)then
    begin
      Msg.DataB[MAXCALLLEN+len]:=ord(code);//caller
      len:=len+1;
      SetCallerLen(len);
      Msg.DataB[MAXCALLLEN+len]:=0;//caller
    end;
  end;

  procedure TMSG.AppendCalled(code:char);
  var
    len:word;
  begin
    len:=GetCalledLen();
    if(len<MAXCALLLEN-1)then
    begin
      Msg.DataB[len]:=ord(code);//called
      len:=len+1;
      SetCalledLen(len);
      Msg.DataB[len]:=0;//called
    end;
  end;

  procedure TMSG.AppendCalledTerm();
  var
    len:word;
  begin
    len:=GetCalledLen();
    if(len>0)then //当长度为0时,不能使用Called
      if(len<MAXCALLLEN)then
        Msg.DataB[len]:=0;//called
  end;

  procedure TMSG.AppendCallerTerm();
  var
    len:word;
  begin
    len:=GetCallerLen();
    if(len>0) then //当长度为0时,不能使用Caller
      if(len<MAXCALLLEN)then
        Msg.DataB[MAXCALLLEN+len]:=0;//caller
  end;

  procedure TMSG.AppendCaller(const phone:string);
  var
    l,len:word;
  begin
    len:=length(phone);
    if(len>0)then
    begin
      l:=GetCallerLen();
      if(l+len>(MAXCALLLEN-1)) then
        len:=MAXCALLLEN-1-l;
      strlcopy(@(Msg.DataB[MAXCALLLEN+l]),pchar(phone),len);
      SetCallerLen(len+l);
    end;
  end;

  procedure TMSG.AppendCalled(const phone:string);
  var
    l,len:word;
  begin
    len:=length(phone);
    if(len>0)then
    begin
       l:=GetCalledLen();
       if(l+len>(MAXCALLLEN-1))then
	 len:=MAXCALLLEN-1-l;
       strlcopy(@(Msg.DataB[l]), pchar(phone),len);
       SetCalledLen(len+l);
    end;
  end;

  function  TMSG.GetCalled():pchar;
  begin
    if(GetCalledLen()>0)then
      result:=@Msg.DataB[0]
    else
      result:='';//注意当长度为0时,不能使用called
  end;

  function  TMSG.GetCaller():pchar;
  begin
    if(GetCallerLen()>0)then
      result:=@Msg.DataB[MAXCALLLEN]
    else
      result:='';//注意当长度为0时,不能使用caller
  end;

  function  TMSG.DsOfMsg():word;//消息的大小(双字表示)
  begin
    result:= 2+(word(Msg.DataLen)+3)div 4;
  end;

  function  TMSG.GetMsgType():byte;
  begin
    result:=Msg.MsgTypeFunction and $F;
  end;
  procedure TMSG.SetMsgType(const Value: byte);
  begin
    Msg.MsgTypeFunction:=(Msg.MsgTypeFunction and $F0) or (Value and $0F);
  end;

  function  TMSG.GetMsgFunction():byte;
  begin
    result:=Msg.MsgTypeFunction shr 4;
  end;

  procedure TMSG.SetMsgFunction(const Value: byte);
  begin
    Msg.MsgTypeFunction:=(Msg.MsgTypeFunction and $0F) or (Value shl 4);
  end;

  function  TMSG.GetChIndex():word;
  begin
    result:=Msg.ChIndexType and $7FF;
  end;
  procedure TMSG.SetChIndex(const Value: word);
  begin
    Msg.ChIndexType:=(Msg.ChIndexType and $F800) or (Value and $7FF);
  end;

  function  TMSG.GetChType():word;
  begin
    result:=Msg.ChIndexType shr 11;
  end;
  procedure TMSG.SetChType(const Value: word);
  begin
    Msg.ChIndexType:=(Msg.ChIndexType and $7FF) or (Value shl 11);
  end;

  function  TMSG.GetLinkChIndex():word;
  begin
    result:=Msg.LinkChIndexType and $7FF;
  end;
  procedure TMSG.SetLinkChIndex(const Value: word);
  begin
    Msg.LinkChIndexType:=(Msg.LinkChIndexType and $F800) or (Value and $7FF);
  end;

  function  TMSG.GetLinkChType():word;
  begin
    result:=Msg.LinkChIndexType shr 11;
  end;
  procedure TMSG.SetLinkChType(const Value: word);
  begin
    Msg.LinkChIndexType:=(Msg.LinkChIndexType and $7FF) or (Value shl 11);
  end;

  function  TMSG.IsNullMsg():word;
  begin
    if(GetMsgType=MSG_NULL)then
      result:=1
    else
      result:=0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -