All pastes #24670 Raw Edit

Unnamed

public text v1 · immutable
#24670 ·published 2005-10-05 13:42 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO.Ports;
 
using IEncoder = Unigone.Asn1RT.IEncoder;
using IDecoder = Unigone.Asn1RT.IDecoder;
using Asn1Exception = Unigone.Asn1RT.Asn1Exception;
using DefaultAsn1PrintWriter = Unigone.Asn1RT.IO.DefaultAsn1PrintWriter;
using ByteArray = Unigone.Asn1RT.Util.ByteArray;
 
using CSTAp3;
using CSTAp3.Remote_Operations_Information_Objects;
using CSTAp3.Remote_Operations_Generic_ROS_PDUs;
using CSTAp3.Remote_Operations_Useful_Definitions;
using CSTAp3.ACSE_1;
using CSTAp3.CSTA_send_user_information;
using CSTAp3.CSTA_call_back_call_related;
using CSTAp3.CSTA_call_back_message_non_call_related;
using CSTAp3.CSTA_call_back_message_call_related;
using CSTAp3.CSTA_data_call_types;
using CSTAp3.CSTA_error_definition;
using CSTAp3.CSTA_security;
using CSTAp3.CSTA_status_reporting;
using CSTAp3.CSTA_application_context_information;
using CSTAp3.CSTA_call_connection_identifiers;
using CSTAp3.CSTA_call_control;
using CSTAp3.CSTA_capability_exchange;
using CSTAp3.CSTA_call_detail_record;
using CSTAp3.CSTA_charge_info;
using CSTAp3.CSTA_connection_states;
using CSTAp3.CSTA_data_collection;
using CSTAp3.CSTA_device_feature_types;
using CSTAp3.CSTA_device_identifiers;
using CSTAp3.CSTA_escape_types;
using CSTAp3.CSTA_event_causes;
using CSTAp3.CSTA_event_report_definitions;
using CSTAp3.CSTA_extension_types;
using CSTAp3.CSTA_media_services;
using CSTAp3.CSTA_physical_device_feature;
using CSTAp3.CSTA_switching_function_objects;
using CSTAp3.CSTA_alternate_call;
using CSTAp3.CSTA_answer_call;
using CSTAp3.CSTA_camp_on_call;
using CSTAp3.CSTA_clear_call;
using CSTAp3.CSTA_clear_connection;
using CSTAp3.CSTA_conference_call;
using CSTAp3.CSTA_consultation_call;
using CSTAp3.CSTA_deflect_call;
using CSTAp3.CSTA_dial_digits;
using CSTAp3.CSTA_directed_pickup_call;
using CSTAp3.CSTA_group_pickup_call;
using CSTAp3.CSTA_hold_call;
using CSTAp3.CSTA_intrude_call;
using CSTAp3.CSTA_join_call;
using CSTAp3.CSTA_make_call;
using CSTAp3.CSTA_make_predictive_call;
using CSTAp3.CSTA_offered_event;
using CSTAp3.CSTA_originated_event;
using CSTAp3.CSTA_park_call;
using CSTAp3.CSTA_queued_event;
using CSTAp3.CSTA_reconnect_call;
using CSTAp3.CSTA_retrieve_call;
using CSTAp3.CSTA_service_initiated_event;
using CSTAp3.CSTA_single_step_conference;
using CSTAp3.CSTA_single_step_transfer;
using CSTAp3.CSTA_transfer_call;
using CSTAp3.CSTA_transferred_event;
using CSTAp3.CSTA_bridged_event;
using CSTAp3.CSTA_call_cleared_event;
using CSTAp3.CSTA_conferenced_event;
using CSTAp3.CSTA_connection_cleared_event;
using CSTAp3.CSTA_delivered_event;
using CSTAp3.CSTA_digits_dialed_event;
using CSTAp3.CSTA_diverted_event;
using CSTAp3.CSTA_established_event;
using CSTAp3.CSTA_failed_event;
using CSTAp3.CSTA_held_event;
using CSTAp3.CSTA_network_capabilities_changed_event;
using CSTAp3.CSTA_network_reached_event;
using CSTAp3.CSTA_play_event;
using CSTAp3.CSTA_play_message;
using CSTAp3.CSTA_query_voice_attribute;
using CSTAp3.CSTA_record_event;
using CSTAp3.CSTA_record_message;
using CSTAp3.CSTA_reposition;
using CSTAp3.CSTA_resume;
using CSTAp3.CSTA_retrieved_event;
using CSTAp3.CSTA_review;
using CSTAp3.CSTA_review_event;
using CSTAp3.CSTA_set_voice_attribute;
using CSTAp3.CSTA_stop;
using CSTAp3.CSTA_stop_event;
using CSTAp3.CSTA_suspend;
using CSTAp3.CSTA_suspend_play_event;
using CSTAp3.CSTA_suspend_record_event;
using CSTAp3.CSTA_synthesize_message;
using CSTAp3.CSTA_voice_attributes_change_event;
using CSTAp3.CSTA_back_in_service_event;
using CSTAp3.CSTA_call_detail_records_notification;
using CSTAp3.CSTA_call_detail_records_report;
using CSTAp3.CSTA_change_system_status_filter;
using CSTAp3.CSTA_concatenate_message;
using CSTAp3.CSTA_delete_message;
using CSTAp3.CSTA_device_capabilities_changed_event;
using CSTAp3.CSTA_escape_register;
using CSTAp3.CSTA_escape_register_abort;
using CSTAp3.CSTA_escape_register_cancel;
using CSTAp3.CSTA_escape_service;
using CSTAp3.CSTA_get_logical_device_information;
using CSTAp3.CSTA_get_physical_device_information;
using CSTAp3.CSTA_get_switching_function_capabilities;
using CSTAp3.CSTA_get_switching_function_devices;
using CSTAp3.CSTA_out_of_service_event;
using CSTAp3.CSTA_private_event;
using CSTAp3.CSTA_private_data_version_selection;
using CSTAp3.CSTA_request_system_status;
using CSTAp3.CSTA_send_stored_call_detail_records;
using CSTAp3.CSTA_start_call_detail_records_transmission;
using CSTAp3.CSTA_stop_call_detail_records;
using CSTAp3.CSTA_switching_function_devices;
using CSTAp3.CSTA_switching_function_capabilities_changed;
using CSTAp3.CSTA_switching_function_devices_changed;
using CSTAp3.CSTA_system_register_abort;
using CSTAp3.CSTA_system_register_cancel;
using CSTAp3.CSTA_system_status;
using CSTAp3.CSTA_system_register;
using CSTAp3.CSTA_agent_busy_event;
using CSTAp3.CSTA_agent_logged_off_event;
using CSTAp3.CSTA_agent_logged_on_event;
using CSTAp3.CSTA_agent_not_ready_event;
using CSTAp3.CSTA_agent_ready_event;
using CSTAp3.CSTA_agent_working_after_call_event;
using CSTAp3.CSTA_auto_answer_event;
using CSTAp3.CSTA_auto_work_mode_event;
using CSTAp3.CSTA_call_back_event;
using CSTAp3.CSTA_call_back_message_event;
using CSTAp3.CSTA_cancel_call_back;
using CSTAp3.CSTA_cancel_call_back_message;
using CSTAp3.CSTA_caller_id_status_event;
using CSTAp3.CSTA_do_not_disturb_event;
using CSTAp3.CSTA_forwarding_event;
using CSTAp3.CSTA_get_auto_work_mode;
using CSTAp3.CSTA_get_agent_state;
using CSTAp3.CSTA_get_auto_answer;
using CSTAp3.CSTA_get_caller_id_status;
using CSTAp3.CSTA_get_do_not_disturb;
using CSTAp3.CSTA_get_forwarding;
using CSTAp3.CSTA_get_last_number_dialed;
using CSTAp3.CSTA_get_routeing_mode;
using CSTAp3.CSTA_routeing_mode_event;
using CSTAp3.CSTA_set_auto_work_mode;
using CSTAp3.CSTA_set_agent_state;
using CSTAp3.CSTA_set_auto_answer;
using CSTAp3.CSTA_set_caller_id_status;
using CSTAp3.CSTA_set_do_not_disturb;
using CSTAp3.CSTA_set_forwarding;
using CSTAp3.CSTA_set_routeing_mode;
using CSTAp3.CSTA_attach_media_service;
using CSTAp3.CSTA_call_back_non_call_related;
using CSTAp3.CSTA_detach_media_service;
using CSTAp3.CSTA_fast_data;
using CSTAp3.CSTA_io_register;
using CSTAp3.CSTA_io_register_abort;
using CSTAp3.CSTA_io_register_cancel;
using CSTAp3.CSTA_media_attached_event;
using CSTAp3.CSTA_media_detached_event;
using CSTAp3.CSTA_data_path_resumed;
using CSTAp3.CSTA_data_path_suspended;
using CSTAp3.CSTA_re_route_request;
using CSTAp3.CSTA_resume_data_path;
using CSTAp3.CSTA_route_request;
using CSTAp3.CSTA_route_end_request;
using CSTAp3.CSTA_route_register_abort;
using CSTAp3.CSTA_route_register_cancel;
using CSTAp3.CSTA_route_register;
using CSTAp3.CSTA_route_reject;
using CSTAp3.CSTA_Route_select_request;
using CSTAp3.CSTA_route_used_request;
using CSTAp3.CSTA_send_broadcast_data;
using CSTAp3.CSTA_send_data;
using CSTAp3.CSTA_send_multicast_data;
using CSTAp3.CSTA_start_data_path;
using CSTAp3.CSTA_stop_data_collection;
using CSTAp3.CSTA_stop_data_path;
using CSTAp3.CSTA_suspend_data_collection;
using CSTAp3.CSTA_suspend_data_path;
using CSTAp3.CSTA_button_information_event;
using CSTAp3.CSTA_button_press_event;
using CSTAp3.CSTA_data_collected;
using CSTAp3.CSTA_data_collection_resumed;
using CSTAp3.CSTA_data_collection_suspended;
using CSTAp3.CSTA_display_updated_event;
using CSTAp3.CSTA_get_lamp_information;
using CSTAp3.CSTA_get_lamp_mode;
using CSTAp3.CSTA_get_microphone_gain;
using CSTAp3.CSTA_get_microphone_mute;
using CSTAp3.CSTA_get_message_waiting_indicator;
using CSTAp3.CSTA_get_ringer_status;
using CSTAp3.CSTA_get_speaker_mute;
using CSTAp3.CSTA_get_speaker_volume;
using CSTAp3.CSTA_hookswitch_event;
using CSTAp3.CSTA_lamp_mode_event;
using CSTAp3.CSTA_message_waiting_event;
using CSTAp3.CSTA_microphone_gain_event;
using CSTAp3.CSTA_microphone_mute_event;
using CSTAp3.CSTA_resume_data_collection;
using CSTAp3.CSTA_ringer_status_event;
using CSTAp3.CSTA_set_button_information;
using CSTAp3.CSTA_set_display;
using CSTAp3.CSTA_set_hookswitch_status;
using CSTAp3.CSTA_set_lamp_mode;
using CSTAp3.CSTA_set_ringer_status;
using CSTAp3.CSTA_set_speaker_mute;
using CSTAp3.CSTA_set_speaker_volume;
using CSTAp3.CSTA_speaker_mute_event;
using CSTAp3.CSTA_speaker_volume_event;
using CSTAp3.CSTA_start_data_collection;
using CSTAp3.CSTA_associate_data;
using CSTAp3.CSTA_button_press;
using CSTAp3.CSTA_call_information_event;
using CSTAp3.CSTA_cancel_telephony_tones;
using CSTAp3.CSTA_charging_event;
using CSTAp3.CSTA_change_monitor_filter;
using CSTAp3.CSTA_digits_generated_event;
using CSTAp3.CSTA_generate_digits;
using CSTAp3.CSTA_generate_telephony_tones;
using CSTAp3.CSTA_get_auditory_apparatus_information;
using CSTAp3.CSTA_get_button_information;
using CSTAp3.CSTA_get_display;
using CSTAp3.CSTA_get_hookswitch_status;
using CSTAp3.CSTA_monitor_start;
using CSTAp3.CSTA_monitor_stop;
using CSTAp3.CSTA_accept_call;
using CSTAp3.CSTA_service_completion_failure_event;
using CSTAp3.CSTA_set_microphone_gain;
using CSTAp3.CSTA_set_microphone_mute;
using CSTAp3.CSTA_set_message_waiting_indicator;
using CSTAp3.CSTA_snapshot_call;
using CSTAp3.CSTA_snapshot_call_data;
using CSTAp3.CSTA_snapshot_device;
using CSTAp3.CSTA_snapshot_device_data;
using CSTAp3.CSTA_telephony_tones_generated_event;
 
namespace CSTA_test
{
    class Program
    {
        private SerialPort port = new SerialPort("COM1", 19200, Parity.None, 8, StopBits.One);
        private Thread receptionThread;
        private const int RECEPTION_BUFFER_LENGTH = 1024;
        private long invokeId;
 
        IEncoder encoder;
        IDecoder decoder;
 
        static void Main(string[] args)
        {
            Program c = new Program();
        }
 
        
        public Program()
        {
            port.Open();
            // Odpalamy wątek odbierające dane z centrali
            ThreadStart receptionStart = new ThreadStart(ReceptionProc);
            receptionThread = new Thread(receptionStart);
            receptionThread.Name = "Reception from PBX";
            receptionThread.Start();
            
            /*
            byte[] pdu = new byte[5];
            pdu[0] = (byte)0x10;
            pdu[1] = (byte)0x02;
            pdu[2] = (byte)0x10;
            pdu[3] = (byte)0x03;
            pdu[4] = (byte)0x13;
            sendData(pdu);
            */
 
            encoder = CSTAp3Factory.CreateEncoder();
            decoder = CSTAp3Factory.CreateDecoder();
 
            sendMakeCall("100", "108");
 
        }
 
        private void sendMakeCall(string callingDeviceNumber, string calledDeviceNumber)
        {
            // MakeCallArgument creation and filling...
            MakeCallArgument mca = new MakeCallArgument();
            mca.CallingDevice.DeviceIdentifier.DialingNumber = callingDeviceNumber;
            mca.CalledDirectoryNumber.DeviceIdentifier.DialingNumber = calledDeviceNumber;
 
            // ROS creation and filling...
            ROS rOS = new ROS();
            rOS.Invoke.InvokeId.Present = invokeId++;
            rOS.Invoke.Opcode.SetValue(makeCall_object.operationCode);
            rOS.Invoke.Argument = mca;
 
            try
            {
                // make sure it is valid
                rOS.Validate();
                // Encode data.
                // The encoder can also be used with a System.IO.Stream. Please refer to the User Guide.
                encoder.Encode(rOS);
            }
            catch (Asn1Exception ex)
            {
                System.Console.Out.WriteLine("ERROR WHILE CODING MakeCall : " + ex.Message);
                return;
            }
            // get data from encoder
            byte[] data = encoder.Data;
 
            // dump data
            System.Console.Out.WriteLine("sending MakeCall from <" + callingDeviceNumber + "> to <" + calledDeviceNumber + ">");
            System.Console.Out.WriteLine(ByteArray.ByteArrayToHexString(data, " ", 16));
 
            // print MakeCall to the console
            System.Console.Out.WriteLine(rOS.ToString());
 
            sendData(data);
        }
 
 
 
        public void ReceptionProc()
        {
            while (true)
            {
                Thread.Sleep(1500);
                byte[] c = new byte[256];
                port.Read(c, 0, 256);
                Console.WriteLine("-");
            }
 
        }
 
        private void sendData(byte[] pdu)
        {
            byte[] data = new byte[pdu.Length + 5];
            data[0] = (byte) 0x10;
            data[1] = (byte) 0x02;
 
            Array.Copy(pdu, 0, data, 2, pdu.Length);
 
            data[data.Length - 3] = (byte)0x10;
            data[data.Length - 2] = (byte)0x03;
 
            //checksum
            int i;
            for (i = 0; i < pdu.Length + 2; i++)
            {
                data[data.Length - 1] += (byte)data[2 + i];
            }
            port.Write(data, 0, data.Length);
        }
 
    }
}
 
 
LOG:
 
IOCTL_SERIAL_SET_LINE_CONTROL   Serial0    SUCCESS     StopBits: 1 Parity: NONE WordLength: 8       
IOCTL_SERIAL_SET_CHAR   Serial0    SUCCESS     EOF:1a ERR:0 BRK:0 EVT:1a XON:11 XOFF:13     
IOCTL_SERIAL_SET_HANDFLOW       Serial0        SUCCESS Shake:0 Replace:0 XonLimit:1024 XoffLimit:1024   
IOCTL_SERIAL_CLR_DTR    Serial0     SUCCESS            
IOCTL_SERIAL_SET_TIMEOUTS       Serial0        SUCCESS RI:-1 RM:-1 RC:-2 WM:0 WC:0      
IOCTL_SERIAL_SET_WAIT_MASK      Serial0       SUCCESS        Mask: RXCHAR RXFLAG CTS DSR RLSD BRK ERR RING   
IOCTL_SERIAL_SET_QUEUE_SIZE     Serial0      SUCCESS       InSize: 4096 OutSize: 2048     
IOCTL_SERIAL_WAIT_ON_MASK       Serial0        SUCCESS  
IRP_MJ_WRITE    Serial0     SUCCESS      Length 29: 10 02 A1 16 02 01 00 02 01 0A 30 0E 30 05 80 03 31 30 30 30 05     
IOCTL_SERIAL_WAIT_ON_MASK       Serial0        SUCCESS  
IOCTL_SERIAL_WAIT_ON_MASK       Serial0        CANCELLED              
IRP_MJ_READ     Serial0      SUCCESS       Length 2: 10 30        
IRP_MJ_READ     Serial0      CANCELLED     Length 256   
IRP_MJ_CLEANUP  Serial0   SUCCESS        
IRP_MJ_CLOSE    Serial0     SUCCESS