Beispiel #1
0
        //-------------------------------------------------------------------------

        /**
         *  Sends a 11 bit CAN data frame.
         *
         *  @param      msg         CAN message
         *
         *  @return                 success (true/false)
         */
        public override bool sendMessage(CANMessage msg)
        {
            this.AddToCanTrace("Sending message: " + msg.getID().ToString("X4") +
                               " " + msg.getData().ToString("X16"));

            try
            {
                caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();
                frame.id          = msg.getID();
                frame.length      = msg.getLength();
                frame.data        = msg.getData();
                frame.is_extended = 0;
                frame.is_remote   = 0;

                this.combi.CAN_SendMessage(ref frame);

                this.AddToCanTrace("Message sent successfully");
                return(true);
            }

            catch (Exception e)
            {
                this.AddToCanTrace("Message failed to send: " + e.Message);
                return(false);
            }
        }
        //-------------------------------------------------------------------------

        /**
         *  Handles incoming messages.
         */
        private void read_messages()
        {
            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();
            Console.WriteLine("Start reading messages");
            // main loop
            while (true)
            {
                // check tor thread termination request
                Debug.Assert(this.term_mutex != null);
                lock (this.term_mutex)
                {
                    if (this.term_requested)
                    {
                        // exit
                        Console.WriteLine("Reader thread ended");
                        return;
                    }
                }

                // receive messages
                if (this.combi.CAN_GetMessage(ref frame, 1000))
                {
                    // convert message
                    //if (this.MessageContainsInformationForRealtime(frame.id))
                    {
                        this.in_msg.setID(frame.id);
                        this.in_msg.setLength(frame.length);
                        this.in_msg.setData(frame.data);

                        // pass message to listeners
                        lock (this.m_listeners)
                        {
                            AddToCanTrace("RX: " + frame.data.ToString("X16"));
                            foreach (ICANListener listener in this.m_listeners)
                            {
                                listener.handleMessage(this.in_msg);
                            }
                        }
                    }
                    // pass message to realtime
                    //if (this.MessageContainsInformationForRealtime(this.in_msg.getID()))
                    {
                        // TODO
                        // CastInformationEvent(this.in_msg); // <GS-05042011> re-activated this function
                    }
                }
            }
        }
Beispiel #3
0
        //-------------------------------------------------------------------------

        /**
         *  Handles incoming messages.
         */
        private void read_messages()
        {
            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();

            // main loop
            while (true)
            {
                // check tor thread termination request
                Debug.Assert(this.term_mutex != null);
                lock (this.term_mutex)
                {
                    if (this.term_requested)
                    {
                        // exit
                        return;
                    }
                }

                // receive messages
                if (this.combi.CAN_GetMessage(ref frame, 1000))
                {
                    // convert message
                    this.in_msg.setID(frame.id);
                    this.in_msg.setLength(frame.length);
                    this.in_msg.setData(frame.data);

                    // pass message to listeners
                    lock (this.m_listeners)
                    {
                        foreach (ICANListener listener in this.m_listeners)
                        {
                            listener.handleMessage(this.in_msg);
                        }
                    }

                    // pass message to realtime
                    if (this.MessageContainsInformationForRealtime(this.in_msg.getID()))
                    {
                        // TODO
                    }
                }
            }
        }
Beispiel #4
0
        //---------------------------------------------------------------------------------------------

        /**
         *  Handles incoming messages.
         */
        private void read_messages()
        {
            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();

            // main loop
            while (true)
            {
                // check for thread termination request
                Debug.Assert(this.term_mutex != null);
                lock (this.term_mutex)
                {
                    if (this.term_requested)
                    {
                        // exit
                        Console.WriteLine("Reader thread ended");
                        return;
                    }
                }

                // receive messages
                if (this.combi.CAN_GetMessage(ref frame, 1000))
                {
                    if (acceptMessageId(frame.id))
                    {
                        // convert message
                        this.in_msg.setID(frame.id);
                        this.in_msg.setLength(frame.length);
                        this.in_msg.setData(frame.data);

                        // pass message to listeners
                        lock (this.m_listeners)
                        {
                            AddToCanTrace("RX: " + frame.id.ToString("X4") + " " + frame.data.ToString("X16"));
                            foreach (ICANListener listener in this.m_listeners)
                            {
                                listener.handleMessage(this.in_msg);
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        //-------------------------------------------------------------------------

        /**
         *  Waits for arrival of a specific CAN message or any message if ID = 0.
         *
         *  @param      a_canID     message ID
         *  @param      timeout     timeout, ms
         *  @param      canMsg      message
         *
         *  @return                 message ID
         */
        public uint waitForMessage(uint a_canID, uint timeout,
                                   out CANMessage canMsg)
        {
            canMsg = new CANMessage();
            Debug.Assert(canMsg != null);
            canMsg.setID(0);

            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();
            if (this.combi.CAN_GetMessage(ref frame, timeout) &&
                (frame.id == a_canID || a_canID == 0))
            {
                // message received
                canMsg.setID(frame.id);
                canMsg.setLength(frame.length);
                canMsg.setData(frame.data);

                return(frame.id);
            }

            // timed out
            return(0);
        }
Beispiel #6
0
        //---------------------------------------------------------------------------------------------

        /**
         *  Handles incoming messages.
         */
        private void read_messages()
        {
            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();

            // main loop
            while (true)
            {
                // check for thread termination request
                Debug.Assert(term_mutex != null);
                lock (term_mutex)
                {
                    if (term_requested)
                    {
                        // exit
                        logger.Debug("Reader thread ended");
                        return;
                    }
                }

                // receive messages
                if (combi.CAN_GetMessage(ref frame, 1000))
                {
                    if (acceptMessageId(frame.id))
                    {
                        // convert message
                        in_msg.setID(frame.id);
                        in_msg.setLength(frame.length);
                        in_msg.setData(frame.data);

                        receivedMessage(in_msg);
                    }
                }
                else
                {
                    Thread.Sleep(1);
                }
            }
        }
Beispiel #7
0
        //---------------------------------------------------------------------------------------------
        /**
        Handles incoming messages.
        */
        private void read_messages()
        {
            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();

            // main loop
            while (true)
            {
            // check for thread termination request
            Debug.Assert(this.term_mutex != null);
            lock (this.term_mutex)
            {
                if (this.term_requested)
                {
                    // exit
                    Console.WriteLine("Reader thread ended");
                    return;
                }
            }

            // receive messages
            if (this.combi.CAN_GetMessage(ref frame, 1000))
            {
                if (acceptMessageId(frame.id))
                {
                    // convert message
                    this.in_msg.setID(frame.id);
                    this.in_msg.setLength(frame.length);
                    this.in_msg.setData(frame.data);

                    // pass message to listeners
                    lock (this.m_listeners)
                    {
                        AddToCanTrace("RX: " + frame.id.ToString("X4") + " " + frame.data.ToString("X16"));
                        foreach (ICANListener listener in this.m_listeners)
                        {
                            listener.handleMessage(this.in_msg);
                        }
                    }
                }
            }
            }
        }
Beispiel #8
0
        //---------------------------------------------------------------------------------------------
        /**
        Waits for arrival of a specific CAN message or any message if ID = 0.

        @param      a_canID     message ID
        @param      timeout     timeout, ms
        @param      canMsg      message

        @return                 message ID
        */
        public override uint waitForMessage(uint a_canID, uint timeout,
        out CANMessage canMsg)
        {
            canMsg = new CANMessage();
            Debug.Assert(canMsg != null);
            canMsg.setID(0);

            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();
            if (this.combi.CAN_GetMessage(ref frame, timeout) &&
            (frame.id == a_canID || a_canID == 0))
            {
            // message received
            canMsg.setID(frame.id);
            canMsg.setLength(frame.length);
            canMsg.setData(frame.data);

            return frame.id;
            }

            // timed out
            return 0;
        }
Beispiel #9
0
        //---------------------------------------------------------------------------------------------
        /**
        Handles incoming messages.
        */
        private void read_messages()
        {
            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();

            // main loop
            while (true)
            {
            // check for thread termination request
            Debug.Assert(term_mutex != null);
            lock (term_mutex)
            {
                if (term_requested)
                {
                    // exit
                    logger.Debug("Reader thread ended");
                    return;
                }
            }

            // receive messages
            if (combi.CAN_GetMessage(ref frame, 1000))
            {
                if (acceptMessageId(frame.id))
                {
                    // convert message
                    in_msg.setID(frame.id);
                    in_msg.setLength(frame.length);
                    in_msg.setData(frame.data);

                    receivedMessage(in_msg);
                }
            }
            else
            {
                Thread.Sleep(1);
            }
            }
        }
        //-------------------------------------------------------------------------
        /**
        Handles incoming messages.
        */
        private void read_messages()
        {
            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();

            // main loop
            while (true)
            {
            // check tor thread termination request
            Debug.Assert(this.term_mutex != null);
            lock (this.term_mutex)
            {
                if (this.term_requested)
                {
                    // exit
                    return;
                }
            }

            // receive messages
            if (this.combi.CAN_GetMessage(ref frame, 1000))
            {
                // convert message
                this.in_msg.setID(frame.id);
                this.in_msg.setLength(frame.length);
                this.in_msg.setData(frame.data);

                // pass message to listeners
                lock (this.m_listeners)
                {
                    foreach (ICANListener listener in this.m_listeners)
                    {
                        listener.handleMessage(this.in_msg);
                    }
                }

                // pass message to realtime
                if (this.MessageContainsInformationForRealtime(this.in_msg.getID()))
                {
                    // TODO
                }
            }
            }
        }
        //---------------------------------------------------------------------------------------------
        /**
        Handles incoming messages.
        */
        private void read_messages()
        {
            caCombiAdapter.caCANFrame frame = new caCombiAdapter.caCANFrame();
            Console.WriteLine("Start reading messages");
            // main loop
            while (true)
            {
            // check tor thread termination request
            Debug.Assert(this.term_mutex != null);
            lock (this.term_mutex)
            {
                if (this.term_requested)
                {
                    // exit
                    Console.WriteLine("Reader thread ended");
                    return;
                }
            }

            // receive messages
            if (this.combi.CAN_GetMessage(ref frame, 1000))
            {
                // convert message
                if (this.MessageContainsInformationForRealtime(frame.id))
                {
                    this.in_msg.setID(frame.id);
                    this.in_msg.setLength(frame.length);
                    this.in_msg.setData(frame.data);

                    // pass message to listeners
                    lock (this.m_listeners)
                    {
                        AddToCanTrace("RX: " + frame.id.ToString("X4")+ " " + frame.data.ToString("X16"));
                        foreach (ICANListener listener in this.m_listeners)
                        {
                            listener.handleMessage(this.in_msg);
                        }

                    }
                }
                // pass message to realtime
                //if (this.MessageContainsInformationForRealtime(this.in_msg.getID()))
                {
                    // TODO
                   // CastInformationEvent(this.in_msg); // <GS-05042011> re-activated this function
                }
            }
            }
        }