Seite 1 von 1

CAPI-Monitor

Verfasst: 05.04.2011 14:37
von bobobo
etwas um mittels Capi Telefonie Funktionen abzufragen
(Es funktioniert z.B. mit dem Capi-Treiber von Fritz-Boxen oder -Karten)

Code: Alles auswählen

;########################################
;author : andreas 
;minimal CAPI-Monitor ; etwas getunt für PB 4.51
;########################################
;Mehr INFO's
;http://www.capi.org/pages/downloads.php
;########################################
Global IsCapi.l, AppID.l

#CAPI_ALERT = $1
#CAPI_CONNECT = $2
#CAPI_DISCONNECT = $4
#CAPI_LISTEN = $5

#CAPI_REQ = $80; { request from application to CAPI               }
#CAPI_CONF = $81; { CAPI confirms a request                        }
#CAPI_IND = $82; { CAPI indicates an incoming event               }
#CAPI_RESP = $83; { application confirms reception if incoming e.  }

;Default value For Controller (i.e. in LISTEN_REQ)
#ctrDefault = 1

;Info-Mask For LISTEN_REQ
#imaDefault = $007F;  { = imMaskAll }
#imaCause = $0001
#imaDateTime = $0002
#imaDisplay = $0004
#imaUserUserInfo = $0008
#imaCallProgression = $0010
#imaFacility = $0020
#imaCharging = $0040
#imaMaskAll = $007F

;CIP-Mask For LISTEN_REQ
#cipDefault = $1FFF03FE;  { sets all Bits }
#cipAnyMatch = $00000001;  { in CONNECT_IND look for BC, HLC u. LLC }
#cipSpeech = $00000002;  { speech }
#cipUnrestDigitalInfo = $00000004;  { unrestricted digital information }
#cipRestDigitalInfo = $00000008;  { restricted digital information }
#cip31kHzAudio = $00000010;  { 3.1 kHz audio }
#cip70kHzAudio = $00000020;  { 7.0 kHz audio }
#cipVideo = $00000040;  { video }
#cipPacketMode = $00000080;  { packet mode }
#cip56kBits = $00000100;  { 56 kBit/s rate adaptation }
#cipUnrestDigitalInfoTA = $00000200;  { unrestricted digital information with tones/announcements }
;{ 10..15 reserved }
#cipTelephony = $00010000;  { telephony }
#cipFaxGroup3 = $00020000;  { fax group 2/3 }
#cipFaxGroup4Class1 = $00040000;  { fax group 4 class 1 }
#cipTeletexbm = $00080000;  { Teletex service (basic and mixed), fax group 4 class 2 }
#cipTeletexbp = $00100000;  { Teletex service (basic and processable) }
#cipTeletexb = $00200000;  { Teletex service (basic) }
#cipVideotex = $00400000;  { Videotex }
#cipTelex = $00800000;  { Telex }
#cipX400 = $01000000;  { message handling systems according X.400 }
#cipX200 = $02000000;  { OSI applications according X.200 }
#cip7kHzTelephony = $04000000;  { 7 kHz Telephony }
#cipF721First = $08000000;  { Video Telephony F.721, first connection }
#cipF721Second = $10000000;  { Video Telephony F.721, second connection }

;CIP-Mask2 For LISTEN_REQ
#cip2Default = 0; { reserved }

;CIP Values For CONNECT_IND
#civNoProfile = 0; { no predefined profile }
#civSpeech = 1; { speech - i.e. ISDN telephone}
#civUnrestDigitalInfo = 2; { unrestricted digital information }
#civRestDigitalInfo = 3; { restricted digital information }
#civ31kHzAudio = 4; { 3.1 kHz audio, i.e. analog telephone }
#civ70kHzAudio = 5; { 7.0 kHz audio }
#civVideo = 6; { video }
#civPacketMode = 7; { packet mode }
#civ56kBits = 8; { 56 kBit/s rate adaptation }
#civUnrestDigitalInfoTA = 9; { unrestricted digital information with tones/announcements }
;{ 10..15 reserved }
#civTelephony = 16; { telephony }
#civFaxGroup3 = 17; { fax group 2/3 }
#civFaxGroup4Class1 = 18; { fax group 4 class 1 }
#civTeletexbm = 19; { Teletex service (basic and mixed), fax group 4 class 2 }
#civTeletexbp = 20; { Teletex service (basic and processable) }
#civTeletexb = 21; { Teletex service (basic) }
#civVideotex = 22; { Videotex }
#civTelex = 23; { Telex }
#civX400 = 24; { message handling systems according X.400 }
#civX200 = 25; { OSI applications according X.200 }
#civ7kHzTelephony = 26; { 7 kHz Telephony }
#civF721First = 27; { Video Telephony F.721, first connection }
#civF721Second = 28; { Video Telephony F.721, second connection }

;Parameter Reject For CONNECT_RESP
#rjeAcceptCall = $0000
#rjeIgnoreCall = $0001; { other devices can accept the call }
#rjeNormalClear = $0002; { hang up }
#rjeUserBusy = $0003; { busy }
#rjeIncompDest = $0007; { incompatible destination }
#rjeUndefined = $FFFF; { not Capi defined }

Structure ListenREQ
  Lenght.w
  AppID.w
  Command.b
  Subcommand.b
  Message_Number.w
  Controller.l
  InfoMask.l
  CIPMask.l
  CIPMas2.l
  CallingParty.b
  CallingPartySub.b
EndStructure

Structure AlertREQ
  Lenght.w
  AppID.w
  Command.b
  Subcommand.b
  Message_Number.w
  PLCI.l
  BCI.w
  kpf.b
  uud.b
  fda.b
EndStructure

Structure ConnectResp
  Length.w
  AppID.w
  Command.b
  Subcommand.b
  Message_Number.b
  PLCI.l
  Reject.w
  BProtocol.l
  ConnectedNumber.l
  ConnectedSubaddress.l
  LLC.b
  AdditionalInfo.b
EndStructure

Structure DisconnectReq
  Length.w
  AppID.w
  Command.b
  Subcommand.b
  Message_Number.w
  PLCI.l
  b1.b
EndStructure

Procedure SaveList(Text$)
  OpenFile(0,"Capi_Log.Log")
  FileSeek(0,Lof(0))
  WriteStringN(0,Text$)
  CloseFile(0)
EndProcedure

Procedure ReadList()
  If ReadFile(0,"Capi_Log.Log")
    Repeat
      Text$ = ReadString(0)
      If Text$ > ""
        AddGadgetItem(6,0,"")
        SetGadgetItemText(6,0,StringField(Text$,1,";"),0)
        SetGadgetItemText(6,0,StringField(Text$,2,";"),1)
        SetGadgetItemText(6,0,StringField(Text$,3,";"),2)
        SetGadgetItemText(6,0,StringField(Text$,4,";"),3)
      EndIf
    Until Text$ = ""
    CloseFile(0)
  EndIf
EndProcedure

Procedure TimerProc(hwnd,msg,wParam,lParam)
  Protected Retval.l,IsMessage.l
  Retval = 0
  *CapiBuffer = AllocateMemory(3072)
  IsMessage = CallFunction(0,"CAPI_GET_MESSAGE",AppID,@*CapiBuffer)
  If IsMessage = 0
    If PeekB(*CapiBuffer+4) = #CAPI_DISCONNECT;Verbindung getrennt
      ;--auf Wiedersehen sagen
      Disconnect.DisconnectReq
      Disconnect\Length = SizeOf(DisconnectReq)
      Disconnect\AppID = AppID
      Disconnect\Command = #CAPI_DISCONNECT
      Disconnect\Subcommand = #CAPI_RESP
      Disconnect\Message_Number = 0
      Disconnect\PLCI = PeekL(*CapiBuffer+8)
      CallFunction(0,"CAPI_PUT_MESSAGE",AppID,Disconnect)
      SetGadgetText(1,"Warte auf Anruf")
      
    EndIf
    If PeekB(*CapiBuffer+4) = #CAPI_CONNECT
      LaengeMSN = PeekB(*CapiBuffer+14);Länge der MSN
      Gerufene_Nummer$ = PeekS(*CapiBuffer+16,LaengeMSN-1)
      Laenge_Anrufernummer = PeekB(*CapiBuffer+(LaengeMSN+15));Länge der Rufnummer des Anrufers
      Anrufer_Nummer$ = "0"+PeekS(*CapiBuffer+(LaengeMSN+18),Laenge_Anrufernummer)
      SetGadgetText(1,"Online")
      AddGadgetItem(6,0,"")
      SetGadgetItemText(6,0,Gerufene_Nummer$,0)
      SetGadgetItemText(6,0,Anrufer_Nummer$,1)
      SetGadgetItemText(6,0,FormatDate("%hh:%ii:%ss", Date()),2)
      SetGadgetItemText(6,0,FormatDate("%dd"+"."+"%mm"+"."+"%yyyy", Date()),3)
      SaveList(Gerufene_Nummer$+";"+Anrufer_Nummer$+";"+FormatDate("%hh:%ii:%ss", Date())+";"+FormatDate("%dd"+"."+"%mm"+"."+"%yyyy", Date()))
      
      ;--Alerting einschalten:
      AlertREQ.AlertREQ
      AlertREQ\Lenght = SizeOf(AlertREQ)
      AlertREQ\AppID = AppID
      AlertREQ\Command = #CAPI_ALERT
      AlertREQ\Subcommand = #CAPI_REQ
      AlertREQ\Message_Number = 0
      AlertREQ\PLCI = PeekL(*CapiBuffer+8)
      AlertREQ\BCI = 0
      AlertREQ\kpf = 0
      AlertREQ\uud = 0
      AlertREQ\fda = 0
      CallFunction(0,"CAPI_PUT_MESSAGE",AppID,AlertREQ)
      
      ;--Antworten
      ConnectResp.ConnectResp
      ConnectResp\Length = SizeOf(ConnectResp)
      ConnectResp\AppID = AppID
      ConnectResp\Command = #CAPI_CONNECT
      ConnectResp\Subcommand = #CAPI_RESP
      ConnectResp\Message_Number = 0
      ConnectResp\PLCI = PeekL(*CapiBuffer+8)
      ConnectResp\Reject = #rjeAcceptCall
      ConnectResp\BProtocol = 0
      ConnectResp\ConnectedNumber = 0
      ConnectResp\ConnectedSubaddress = 0
      ConnectResp\LLC = 0
      ConnectResp\AdditionalInfo = 0
      CallFunction(0,"CAPI_PUT_MESSAGE",AppID,ConnectResp)
    EndIf
    
  EndIf
  FreeMemory(*CapiBuffer)
  ProcedureReturn RetVal
EndProcedure

If OpenWindow(0,0,0,400,300,"minimal Capimonitor",#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ButtonGadget(0, 10, 10, 200, 20, "Ende")
  TextGadget(1, 10, 40,250,20,"Warte auf Anruf")
  ListIconGadget(6, 10,60,380,200,"MSN",76,#PB_ListIcon_GridLines)
  AddGadgetColumn(6, 1,"Anrufer",120)
  AddGadgetColumn(6, 2,"Zeit",90)
  AddGadgetColumn(6, 3,"Datum",90)
  ReadList()
  IsCapi = OpenLibrary(0,"Capi2032.dll")
  If IsCapi
    CallFunction(0,"CAPI_REGISTER",3072,2,7,2048,@AppID)
    ;3072 Byte Puffergröße
    ;Max. 2 logische Verbindungen
    ;Max. 7 Datenblocks
    ;Max. 2048 Byte Daten
    ListenReq.ListenREQ
    ListenReq\Lenght = SizeOf(ListenREQ)
    ListenReq\AppID = AppID
    ListenReq\Command = #CAPI_LISTEN
    ListenReq\Subcommand = #CAPI_REQ
    ListenReq\Message_Number = 0
    ListenReq\Controller = #ctrDefault
    ListenReq\InfoMask = #imaDefault
    ListenReq\CIPMask = #cipAnyMatch
    ListenReq\CIPMas2 = #cip2Default
    ListenReq\CallingParty = 0
    ListenReq\CallingPartySub = 0
    CallFunction(0,"CAPI_PUT_MESSAGE",AppID,@ListenReq)
  Else
    SetGadgetText(1,"No CAPI")
  EndIf
  
  SetTimer_(WindowID(0),1,500,@TimerProc())
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            KillTimer_(WindowID(0),1)
            If IsCapi
              CallFunction(0,"CAPI_RELEASE",AppID)
              CloseLibrary(0)
            EndIf
            SendMessage_(WindowID(0),#WM_CLOSE,0,0)
        EndSelect
      Case #PB_Event_CloseWindow
        quit = 1
    EndSelect
  Until quit = 1
EndIf