Пример #1
0
        /// <summary>
        /// Determines if the outgoing message is local, or needs to be routed through
        /// the node manager.
        /// </summary>
        /// <param name="msg">the outgoing message wrapped in a Send wrapper.</param>
        public void sendMessage(ref Send msg)
        {
            // Pull the destination ID
            JausAddress destination = new JausAddress((ushort)msg.getBody().getSendRec().getDestinationID().getSubsystemID(),
                                                      (byte)msg.getBody().getSendRec().getDestinationID().getNodeID(),
                                                      (byte)msg.getBody().getSendRec().getDestinationID().getComponentID());

            // If the destination is local, loopback to the route message function
            if (destination.get() == jausAddress.get())
            {
                Receive message = new Receive();
                message.getBody().getReceiveRec().getSourceID().setSubsystemID(jausAddress.getSubsystemID());
                message.getBody().getReceiveRec().getSourceID().setNodeID(jausAddress.getNodeID());
                message.getBody().getReceiveRec().getSourceID().setComponentID(jausAddress.getComponentID());
                message.getBody().getReceiveRec().getMessagePayload().set(msg.getBody().getSendRec().getMessagePayload().getLength(),
                                                                          msg.getBody().getSendRec().getMessagePayload().getData());

                routeMessage(message);
            }
            // Otherwise, forward the message to NodeManager
            else
            {
                JrErrorCode ret = JuniorAPI.JrSend((int)jrHandle, destination.get(),
                                                   (uint)msg.getBody().getSendRec().getMessagePayload().getLength(),
                                                   msg.getBody().getSendRec().getMessagePayload().getData());
            }
        }
Пример #2
0
 /// <summary>
 /// Constructor. Connects with nodeManager and sets up variables.
 /// </summary>
 /// <param name="jausAddress">The JausAddress of the current component.</param>
 public JausRouter(JausAddress jausAddress, InternalEventHandler ieHandler)
 {
     this.jausAddress = jausAddress;
     this.ieHandler   = ieHandler;
     jrHandle         = 0;
     if (JuniorAPI.JrConnect((int)jausAddress.get(), "nm.cfg", ref jrHandle) != 0)
     {
         Console.WriteLine("UNABLE TO CONNECT TO THE NODE MANAGER.  IS IT RUNNING?");
     }
 }
Пример #3
0
 /// <summary>
 /// Constructor. Connects with nodeManager and sets up variables.
 /// </summary>
 /// <param name="jausAddress">The JausAddress of the current component.</param>
 public JausRouter(JausAddress jausAddress, InternalEventHandler ieHandler)
 {
     this.jausAddress = jausAddress;
     this.ieHandler = ieHandler;
     jrHandle = 0;
     if (JuniorAPI.JrConnect((int)jausAddress.get(), "nm.cfg", ref jrHandle) != 0)
     {
         Console.WriteLine("UNABLE TO CONNECT TO THE NODE MANAGER.  IS IT RUNNING?");
     }
 }
Пример #4
0
        public virtual bool isLocalComponent(JausAddress address)
        {
            bool ret = JausAddressModulePINVOKE.JausAddress_isLocalComponent__SWIG_1(swigCPtr, JausAddress.getCPtr(address));

            if (JausAddressModulePINVOKE.SWIGPendingException.Pending)
            {
                throw JausAddressModulePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Пример #5
0
        /// <summary>
        /// Wraps the message buffer into a Send wrapper and sends it through
        /// the JausRouter.
        /// </summary>
        /// <param name="bufsize">the size of the given buffer in bytes</param>
        /// <param name="buffer">the bytes from the message to be sent</param>
        /// <param name="dest">the destination of the message</param>
        protected void sendJausMessage(uint bufsize, byte[] buffer, JausAddress dest)
        {
            Send response = new Send();

            response.getBody().getSendRec().getMessagePayload().set((int)bufsize, buffer);
            response.getBody().getSendRec().getDestinationID().setSubsystemID(dest.getSubsystemID());
            response.getBody().getSendRec().getDestinationID().setNodeID(dest.getNodeID());
            response.getBody().getSendRec().getDestinationID().setComponentID(dest.getComponentID());
            //Console.WriteLine("Sending response msg " + BitConverter.ToInt16(b, 0));
            jausRouter.sendMessage(ref response);
        }
        public virtual void sendManagementMessageAction(MenuItemEntered msg)
        {
            Resume resume_msg = new Resume();
            Standby standby_msg = new Standby();
            SetEmergency set_emergency_msg = new SetEmergency();
            ClearEmergency clear_emergency_msg = new ClearEmergency();
            QueryStatus query_status_msg = new QueryStatus();
            ReleaseControl release_control_msg = new ReleaseControl();
            Shutdown shutdown_msg = new Shutdown();

            JausAddress dest = new JausAddress(jausRouter.getJausAddress().getSubsystemID(),
                      jausRouter.getJausAddress().getNodeID(),
                      (byte)160);

            switch (msg.getMenuItemEnteredBody().getMenuItemEnteredRecord().getSelection())
            {
            case 1:
            Console.WriteLine("Sending Resume");
            sendJausMessage(resume_msg, dest);
            break;
            case 2:
            Console.WriteLine("Sending Standby");
            sendJausMessage(standby_msg, dest);
            break;
            case 3:
            Console.WriteLine("Sending SetEmergency");
            sendJausMessage(set_emergency_msg, dest);
            break;
            case 4:
            Console.WriteLine("Sending ClearEmergency");
            sendJausMessage(clear_emergency_msg, dest);
            break;
            case 5:
            Console.WriteLine("Sending QueryStatus");
            sendJausMessage(query_status_msg, dest);
            break;
            case 6:
            Console.WriteLine("Sending Shutdown");
            sendJausMessage(shutdown_msg, dest);
            break;
            case 7:
            Console.WriteLine("Sending ReleaseControl");
            sendJausMessage(release_control_msg, dest);
            break;
            case 8:
            Console.WriteLine("Sending Terminate");
            terminateServiceAction();
            break;
            default:
            Console.WriteLine("Unknown input: " + msg.getMenuItemEnteredBody().getMenuItemEnteredRecord().getSelection());
            break;
            }
        }
Пример #7
0
        /// <summary>
        /// Encodes the given message into a buffer and prepares to send it.
        /// </summary>
        /// <param name="msg">The message to be sent</param>
        /// <param name="dest">The address to which the message is going.</param>
        protected void sendJausMessage(Message msg, JausAddress dest)
        {
            // Encode the message
            uint bufsize = (uint)msg.getSize();

            byte[] buffer = new byte[bufsize];
            int    pos    = 0;

            msg.encode(buffer, pos);
            // and send...
            sendJausMessage(bufsize, buffer, dest);
        }
        public virtual bool isControllingClient(Receive.Body.ReceiveRec transportData)
        {
            JausAddress requester = new JausAddress((ushort)transportData.getSourceID().getSubsystemID(),
                                            (byte)transportData.getSourceID().getNodeID(),
                                            (byte)transportData.getSourceID().getComponentID());

            if ((currentController != null) &&
            (requester.getSubsystemID() == currentController.getSubsystemID() &&
            requester.getNodeID() == currentController.getNodeID() &&
            requester.getComponentID() == currentController.getComponentID()))
            {
            return true;
            }
            return false;
        }
Пример #9
0
        public void updateJausID(JausAddress jausAddress, bool allowWildcards = false)
        {
            // Request to change our JAUS ID.  This means we have to close the current connection
            // to junior, and recreate it.  But first we need to stop the receive thread.
            stop();
            JuniorAPI.JrDisconnect((int)jrHandle);
            this.jausAddress = jausAddress;
            jrHandle         = 0;
            int jWildcards = allowWildcards ? 1 : 0;

            if (JuniorAPI.JrConnect((int)jausAddress.get(), "nm.cfg", ref jrHandle, jWildcards) != 0)
            {
                Console.WriteLine("UNABLE TO CONNECT TO THE NODE MANAGER.  IS IT RUNNING?");
            }

            start();
        }
Пример #10
0
        /// <summary>
        /// Checks the C++ framework for incoming messages, routing them as needed.
        /// </summary>
        public override void run()
        {
            int  priority = 0;
            uint source   = 0;
            int  flags    = 0;
            uint bufsize  = 0;

            byte[] buffer;
            ushort msg_id = 0;

            //runLock._lock();
            isRunning = true;
            //runLock.unlock();

            while (isRunning)
            {
                buffer = JuniorAPI.JrReceive((int)jrHandle, ref source, ref priority, ref flags, ref msg_id);
                if (buffer != null & buffer.Length > 0)
                {
                    if (!isRunning)
                    {
                        break;
                    }
                    bufsize = (uint)buffer.Length;
                    byte[] tmpBuff = new byte[buffer.Length];
                    for (int i = 0; i < buffer.Length; i++)
                    {
                        tmpBuff[i] = buffer[i];
                    }
                    buffer = null;
                    Receive     message = new Receive();
                    JausAddress sender  = new JausAddress(source);

                    message.getBody().getReceiveRec().setSrcSubsystemID(sender.getSubsystemID());
                    message.getBody().getReceiveRec().setSrcNodeID(sender.getNodeID());
                    message.getBody().getReceiveRec().setSrcComponentID(sender.getComponentID());
                    message.getBody().getReceiveRec().getMessagePayload().set(bufsize, tmpBuff);
                    routeMessage(message);
                }
                else
                {
                    //OS.JrSleep(1); //throttle
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Wraps the message buffer into a Send wrapper and sends it through
        /// the JausRouter.
        /// </summary>
        /// <param name="bufsize">the size of the given buffer in bytes</param>
        /// <param name="buffer">the bytes from the message to be sent</param>
        /// <param name="dest">the destination of the message</param>
        protected void sendJausMessage(uint bufsize, byte[] buffer, JausAddress dest, bool force = false)
        {
            // We need to have a complete JAUS ID (no wildcards)
            // to send any messages, unless that message is specifically forced
            // to send by the calling application
            if (jausRouter.getJausAddress().containsWildcards() && !force)
            {
                Console.WriteLine("Can't send message when ID contains wildcards");
                return;
            }

            Send response = new Send();

            response.getBody().getSendRec().getMessagePayload().set((int)bufsize, buffer);
            response.getBody().getSendRec().getDestinationID().setSubsystemID(dest.getSubsystemID());
            response.getBody().getSendRec().getDestinationID().setNodeID(dest.getNodeID());
            response.getBody().getSendRec().getDestinationID().setComponentID(dest.getComponentID());
            //Console.WriteLine("Sending response msg " + BitConverter.ToInt16(b, 0));
            jausRouter.sendMessage(ref response);
        }
Пример #12
0
 internal static HandleRef getCPtr(JausAddress obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
        public virtual void StoreAddressAction(Receive.Body.ReceiveRec transportData)
        {
            Console.WriteLine( "Storing address of controlling component as " +
            (ushort)transportData.getSourceID().getSubsystemID(),
            (byte)transportData.getSourceID().getNodeID(),
            (byte)transportData.getSourceID().getComponentID());

            currentController = new JausAddress((ushort)transportData.getSourceID().getSubsystemID(),
                                           (byte)transportData.getSourceID().getNodeID(),
                                           (byte)transportData.getSourceID().getComponentID());
        }
        public virtual void SendAction(string arg0, string arg1, Receive.Body.ReceiveRec transportData)
        {
            if (arg0.CompareTo("RejectControl") == 0)
            {
            RejectControl reject_msg = new RejectControl();
            if (arg1.CompareTo("CONTROL_RELEASED") == 0) reject_msg.getBody().getRejectControlRec().setResponseCode(0);
            if (arg1.CompareTo("NOT_ACCEPTED") == 0) reject_msg.getBody().getRejectControlRec().setResponseCode(1);

            // Now send it to the requesting component
            JausAddress sender = new JausAddress((ushort)transportData.getSourceID().getSubsystemID(),
                                            (byte)transportData.getSourceID().getNodeID(),
                                            (byte)transportData.getSourceID().getComponentID());

            sendJausMessage(reject_msg, sender);

            }

            else if (arg0.CompareTo("ConfirmControl") == 0)
            {
            ConfirmControl confirm_msg = new ConfirmControl();
            byte responseCode = 0;
            if (arg1.CompareTo("CONTROL_ACCEPTED") == 0) responseCode = 0;
            if (arg1.CompareTo("NOT_AVAILABLE") == 0) responseCode = 1;
            if (arg1.CompareTo("INSUFFICIENT_AUTHORITY") == 0) responseCode = 2;
            Console.WriteLine("Sending ConfirmControl with argument " + arg1);
            confirm_msg.getBody().getConfirmControlRec().setResponseCode(responseCode);

            // Now send it to the requesting component
            JausAddress sender = new JausAddress((ushort)transportData.getSourceID().getSubsystemID(),
                                            (byte)transportData.getSourceID().getNodeID(),
                                            (byte)transportData.getSourceID().getComponentID());
            sendJausMessage(confirm_msg, sender);
            }
            else if (arg0.CompareTo("ReportControl") == 0)
            {
            ReportControl control_msg = new ReportControl();
            control_msg.getBody().getReportControlRec().setSubsystemID((ushort)(
                                         (currentController == null) ? 0 : currentController.getSubsystemID()));
            control_msg.getBody().getReportControlRec().setNodeID((byte)(
                                    (currentController == null) ? 0 : currentController.getNodeID()));
            control_msg.getBody().getReportControlRec().setComponentID((byte)(
                                         (currentController == null) ? 0 : currentController.getComponentID()));

            // Now send it to the requesting component
            JausAddress sender = new JausAddress((ushort)transportData.getSourceID().getSubsystemID(),
                                            (byte)transportData.getSourceID().getNodeID(),
                                            (byte)transportData.getSourceID().getComponentID());
            sendJausMessage(control_msg, sender);
            }
        }
Пример #15
0
        public virtual void SendAction(string arg0, Receive.Body.ReceiveRec transportData)
        {
            if (arg0.CompareTo("ReportStatus") == 0)
            {
            ReportStatus status_msg = new ReportStatus();

            // Get the state from the context.  Note that since we are inside a transition, the "current state"
            // is ill-defined.  We instead use the state we left to execute this transition.  Recall that the state
            // is actually an amalgamation of all parent states, we're only concerned with the management
            string currentState = context.PreviousState.Name;  //getPreviousState().getName();
            if (currentState.Contains("_"))
            currentState = currentState.Substring(currentState.LastIndexOf("_") + 1);
            if (currentState.CompareTo("Init") == 0) status_msg.getBody().getReportStatusRec().setStatus(0);
            if (currentState.CompareTo("Ready") == 0) status_msg.getBody().getReportStatusRec().setStatus(1);
            if (currentState.CompareTo("Standby") == 0) status_msg.getBody().getReportStatusRec().setStatus(2);
            if (currentState.CompareTo("Shutdown") == 0) status_msg.getBody().getReportStatusRec().setStatus(3);
            if (currentState.CompareTo("Failure") == 0) status_msg.getBody().getReportStatusRec().setStatus(4);
            if (currentState.CompareTo("Emergency") == 0) status_msg.getBody().getReportStatusRec().setStatus(5);

            Console.WriteLine("Sending ReportStatus: " + currentState);

            // Now send it to the requesting component
            JausAddress sender = new JausAddress((ushort)transportData.getSourceID().getSubsystemID(),
                                               (byte)transportData.getSourceID().getNodeID(),
                                               (byte)transportData.getSourceID().getComponentID());
            sendJausMessage(status_msg, sender);
            }
        }
Пример #16
0
        /// <summary>
        /// Checks the C++ framework for incoming messages, routing them as needed.
        /// </summary>
        public override void run()
        {
            int priority = 0;
            uint source = 0;
            int flags =0;
            uint bufsize = 0;
            byte[] buffer;
            ushort msg_id = 0;
            //runLock._lock();
            isRunning = true;
            //runLock.unlock();

            while(isRunning)
            {
                buffer = JuniorAPI.JrReceive((int) jrHandle, ref source, ref priority, ref flags, ref msg_id);
                if( buffer != null & buffer.Length > 0)
                {
                    if(!isRunning)
                    {
                        break;
                    }
                    bufsize = (uint) buffer.Length;
                    Receive message = new Receive();
                    JausAddress sender = new JausAddress(source);

                    message.getBody().getReceiveRec().getSourceID().setSubsystemID(sender.getSubsystemID());
                    message.getBody().getReceiveRec().getSourceID().setNodeID(sender.getNodeID());
                    message.getBody().getReceiveRec().getSourceID().setComponentID(sender.getComponentID());
                    message.getBody().getReceiveRec().getMessagePayload().set((int) bufsize, buffer);
                    routeMessage(message);
                }
                else
                {
                    //OS.JrSleep(1); //throttle
                }
            }
        }
Пример #17
0
 /// <summary>
 /// Wraps the message buffer into a Send wrapper and sends it through
 /// the JausRouter.
 /// </summary>
 /// <param name="bufsize">the size of the given buffer in bytes</param>
 /// <param name="buffer">the bytes from the message to be sent</param>
 /// <param name="dest">the destination of the message</param>
 protected void sendJausMessage(uint bufsize, byte[] buffer, JausAddress dest)
 {
     Send response = new Send();
     response.getBody().getSendRec().getMessagePayload().set((int)bufsize, buffer);
     response.getBody().getSendRec().getDestinationID().setSubsystemID(dest.getSubsystemID());
     response.getBody().getSendRec().getDestinationID().setNodeID(dest.getNodeID());
     response.getBody().getSendRec().getDestinationID().setComponentID(dest.getComponentID());
     //Console.WriteLine("Sending response msg " + BitConverter.ToInt16(b, 0));
     jausRouter.sendMessage(ref response);
 }
Пример #18
0
 /// <summary>
 /// Encodes the given message into a buffer and prepares to send it.
 /// </summary>
 /// <param name="msg">The message to be sent</param>
 /// <param name="dest">The address to which the message is going.</param>
 protected void sendJausMessage(Message msg, JausAddress dest)
 {
     // Encode the message
     uint bufsize = (uint) msg.getSize();
     byte[] buffer = new byte[bufsize];
     int pos = 0;
     msg.encode(buffer, pos);
     // and send...
     sendJausMessage (bufsize, buffer, dest);
 }
Пример #19
0
 internal static HandleRef getCPtr(JausAddress obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
Пример #20
0
 public virtual bool isLocalComponent(JausAddress address)
 {
     bool ret = JausAddressModulePINVOKE.JausAddress_isLocalComponent__SWIG_1(swigCPtr, JausAddress.getCPtr(address));
     if (JausAddressModulePINVOKE.SWIGPendingException.Pending) throw JausAddressModulePINVOKE.SWIGPendingException.Retrieve();
     return ret;
 }
Пример #21
0
        /// <summary>
        /// Determines if the outgoing message is local, or needs to be routed through
        /// the node manager.
        /// </summary>
        /// <param name="msg">the outgoing message wrapped in a Send wrapper.</param>
        public void sendMessage(ref Send msg)
        {
            // Pull the destination ID
            JausAddress destination = new JausAddress((ushort) msg.getBody().getSendRec().getDestinationID().getSubsystemID(),
                                                      (byte) msg.getBody().getSendRec().getDestinationID().getNodeID(),
                                                      (byte) msg.getBody().getSendRec().getDestinationID().getComponentID());
            // If the destination is local, loopback to the route message function
            if(destination.get() == jausAddress.get())
            {
                Receive message = new Receive();
                message.getBody().getReceiveRec().getSourceID().setSubsystemID(jausAddress.getSubsystemID());
                message.getBody().getReceiveRec().getSourceID().setNodeID(jausAddress.getNodeID());
                message.getBody().getReceiveRec().getSourceID().setComponentID(jausAddress.getComponentID());
                message.getBody().getReceiveRec().getMessagePayload().set(msg.getBody().getSendRec().getMessagePayload().getLength(),
                                                                      msg.getBody().getSendRec().getMessagePayload().getData());

                routeMessage(message);
            }
            // Otherwise, forward the message to NodeManager
            else
            {
                JrErrorCode ret = JuniorAPI.JrSend((int) jrHandle, destination.get(),
                                                   (uint) msg.getBody().getSendRec().getMessagePayload().getLength(),
                                                   msg.getBody().getSendRec().getMessagePayload().getData());
            }
        }
        public virtual void sendRequestControlAction()
        {
            // what should really happen here is that an internal event is called, so that
            // the send happens inside of a sendAction(), rather than here.

            // Now, we need to send a RequestComponentControl to the management service
            RequestControl request_control_msg = new RequestControl();
            request_control_msg.getBody().getRequestControlRec().setAuthorityCode(200);

            // send a message, to this subsystem, this node, component 11.
            // Again, discovery should be used to find the JAUS ID of the service we want to
            // address, rather than hardcoding the address
            JausAddress dest = new JausAddress(jausRouter.getJausAddress().getSubsystemID(),
                      jausRouter.getJausAddress().getNodeID(),
                      (byte)160);
            sendJausMessage(request_control_msg, dest);
        }