Beispiel #1
0
        /// <summary>
        /// Eine Capi-Nachricht an den Capi-Treiber senden
        /// </summary>
        /// <param name="message"></param>
        public void SendMessage(CapiOutMessage loMessage)
        {
            // Ist Verbunden?
            if (!this.m_Connected)
            {
                throw new Exception("CAPI is not connected.");
            }

            loMessage.Header.AppID         = m_AppID;
            loMessage.Header.MessageNumber = (byte)m_MessageNumber; // Nächste Sequenznummer zuweisen

            m_MessageNumber++;                                      // Sequenznummer hochzählen
            if (m_MessageNumber >= UInt16.MaxValue)
            {
                m_MessageNumber = UInt16.MinValue;     // Capi-Message-Nummern haben nur 16 Bit
            }
            byte[] lbBuffer = loMessage.AsByteArray(); // Header als Byte-Array zurückgeben

            // Speicherbereich reservieren
            IntPtr loPtr = Marshal.AllocHGlobal(lbBuffer.Length);

            Marshal.Copy(lbBuffer, 0, loPtr, lbBuffer.Length);

            // Nachricht senden
            int liResult = CAPI_PUT_MESSAGE(this.m_AppID, loPtr);

            Marshal.FreeHGlobal(loPtr); // Speicher freigeben
        }
Beispiel #2
0
 protected void onReceive(CapiInMessage loInMessage, CapiOutMessage loOutMessage)
 {
     if (OnReceive != null)
     {
         OnReceive(this, new ReceiveArgs(loInMessage, loOutMessage));
     }
 }
Beispiel #3
0
 public ReceiveArgs(CapiInMessage loInMessage, CapiOutMessage loOutMessage)
 {
     m_InMessage  = loInMessage;
     m_OutMessage = loOutMessage;
 }
Beispiel #4
0
 public ReceiveArgs(CapiInMessage loInMessage)
 {
     m_InMessage  = loInMessage;
     m_OutMessage = null;
 }
Beispiel #5
0
        /// <summary>
        /// Thread-In-Routine
        /// </summary>
        private void MessageInThread()
        {
            CapiInMessage  loInMessage  = null;
            CapiOutMessage loOutMessage = null;

            while (Active)
            {
                CAPI_WAIT_FOR_SIGNAL((int)this.m_AppID);

                // Neue Nachricht auslesen
                IntPtr loPtr    = IntPtr.Zero;
                int    liResult = CAPI_GET_MESSAGE(this.m_AppID, out loPtr);

                int    liSize = (int)Marshal.ReadByte(loPtr);
                byte[] lbMsg  = new byte[liSize];

                Marshal.Copy(loPtr, lbMsg, 0, liSize);
                CapiMessageHeader loHeader = new CapiMessageHeader(lbMsg, 0);

                if (loHeader.SubCommand == CapiMessages_SubCommands_Enum.CONF)
                {
                    switch (loHeader.Command)
                    {
                    // Messages concerning the signaling protocol
                    case CapiMessages_Commands_Enum.CONNECT:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new CONNECT_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.DISCONNECT:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new DISCONNECT_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.ALERT:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new ALERT_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.INFO:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new INFO_CONF(lbMsg, 0);
                    }
                    break;


                    // Messages concerning logical connections
                    case CapiMessages_Commands_Enum.CONNECT_B3:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new CONNECT_B3_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.DISCONNECT_B3:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new DISCONNECT_B3_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.DATA_B3:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new DATA_B3_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.RESET_B3:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new RESET_B3_CONF(lbMsg, 0);
                    }
                    break;


                    // Administrative and other messages
                    case CapiMessages_Commands_Enum.LISTEN:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new LISTEN_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.FACILITY:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new FACILITY_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.SELECT_B_PROTOCOL:     // local confirmation of the request
                    {
                        loInMessage = (CapiInMessage) new SELECT_B_PROTOCOL_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.MANUFACTURER:     // manufacturer-specific operation
                    {
                        loInMessage = (CapiInMessage) new MANUFACTURER_CONF(lbMsg, 0);
                    }
                    break;

                    case CapiMessages_Commands_Enum.INTEROPERABILITY:     // interoperability operation
                    {
                        loInMessage = (CapiInMessage) new INTEROPERABILITY_CONF(lbMsg, 0);
                    }
                    break;


                    default:
                        throw new Exception("Unknown message received as confimation.");
                    }

                    loInMessage.Header = loHeader;

                    onReceive(loInMessage, null);
                }


                // Messages needed to be replied
                else if (loHeader.SubCommand == CapiMessages_SubCommands_Enum.IND)
                {
                    switch (loHeader.Command)
                    {
                    // Messages concerning the signaling protocol
                    case CapiMessages_Commands_Enum.CONNECT:     // indicates an incoming physical connection
                    {
                        loInMessage  = (CapiInMessage) new CONNECT_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new CONNECT_RESP();
                        //// Preparing
                    }
                    break;

                    case CapiMessages_Commands_Enum.CONNECT_ACTIVE:     // indicates the activation of a physical connection
                    {
                        loInMessage  = (CapiInMessage) new CONNECT_ACTIVE_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new CONNECT_ACTIVE_RESP();
                        //// Preparing
                    }
                    break;

                    case CapiMessages_Commands_Enum.DISCONNECT:     // indicates the clearing of a physical connection
                    {
                        loInMessage  = (CapiInMessage) new DISCONNECT_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new DISCONNECT_RESP();
                        //// Preparing
                    }
                    break;

                    case CapiMessages_Commands_Enum.INFO:     // indicates specified signaling information
                    {
                        loInMessage  = (CapiInMessage) new INFO_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new INFO_RESP();
                        //// Preparing
                    }
                    break;


                    // Messages concerning logical connections
                    case CapiMessages_Commands_Enum.CONNECT_B3:     // indicates an incoming logical connection
                    {
                        loInMessage  = (CapiInMessage) new CONNECT_B3_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new CONNECT_B3_RESP();
                        //// Preparing
                    }
                    break;

                    case CapiMessages_Commands_Enum.CONNECT_B3_ACTIVE:     // indicates the activation of a logical connection
                    {
                        loInMessage  = (CapiInMessage) new CONNECT_B3_ACTIVE_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new CONNECT_B3_ACTIVE_RESP();
                        //// Preparing
                    }
                    break;

                    case CapiMessages_Commands_Enum.CONNECT_B3_T90_ACTIVE:     // indicates switching from T.70NL to T.90NL
                    {
                        loInMessage  = (CapiInMessage) new CONNECT_B3_T90_ACTIVE_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new CONNECT_B3_T90_ACTIVE_RESP();
                        //// Preparing
                    }
                    break;

                    case CapiMessages_Commands_Enum.DISCONNECT_B3:     // indicates the clearing down of a logical connection
                    {
                        loInMessage  = (CapiInMessage) new DISCONNECT_B3_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new DISCONNECT_B3_RESP();
                        //// Preparing
                    }
                    break;

                    case CapiMessages_Commands_Enum.DATA_B3:     // indicates incoming data over a logical connection
                    {
                        loInMessage  = (CapiInMessage) new DATA_B3_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new DATA_B3_RESP();
                        //// Preparing
                    }
                    break;

                    case CapiMessages_Commands_Enum.RESET_B3:     // indicates the resetting of a logical connection
                    {
                        loInMessage  = (CapiInMessage) new RESET_B3_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new RESET_B3_RESP();
                        //// Preparing
                    }
                    break;


                    // Administrative and other messages
                    case CapiMessages_Commands_Enum.FACILITY:     // indicates additional facilities (e.g. ext. equipment)
                    {
                        loInMessage  = (CapiInMessage) new FACILITY_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new FACILITY_RESP();

                        ((FACILITY_RESP)loOutMessage).Controller_PLCI_NCCI = ((FACILITY_IND)loInMessage).Controller_PLCI_NCCI;
                        ((FACILITY_RESP)loOutMessage).FacilitySelector     = ((FACILITY_IND)loInMessage).FacilitySelector;
                        ////
                        //// Preparing
                    }
                    break;

                    case CapiMessages_Commands_Enum.MANUFACTURER:     // manufacturer-specific operation
                    {
                        loInMessage  = (CapiInMessage) new MANUFACTURER_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new MANUFACTURER_RESP();

                        ((MANUFACTURER_RESP)loOutMessage).Controller = ((MANUFACTURER_IND)loInMessage).Controller;
                        ((MANUFACTURER_RESP)loOutMessage).ManuID     = ((MANUFACTURER_IND)loInMessage).ManuID;
                        //// Manufacturer dependend data; may need to extend
                    }
                    break;

                    case CapiMessages_Commands_Enum.INTEROPERABILITY:     // interoperability operation
                    {
                        loInMessage  = (CapiInMessage) new INTEROPERABILITY_IND(lbMsg, 0);
                        loOutMessage = (CapiOutMessage) new INTEROPERABILITY_RESP();

                        //// Preparing
                    }
                    break;


                    default:
                        throw new Exception("Unknown message received as indication.");
                    }

                    loOutMessage.Header.AppID         = loHeader.AppID;
                    loOutMessage.Header.MessageNumber = loHeader.MessageNumber;

                    onReceive(loInMessage, loOutMessage);
                }
                else
                {
                    throw new Exception("Unknown message received.");
                }
            }
        }