Exemplo n.º 1
0
    /// <summary>
    /// Sends a byte alongside a command, for commands that need a byte, such as getting previous reccam parameters config
    /// </summary>
    /// <param name="module"></param>
    /// <param name="action"></param>
    /// <param name="number"></param>
    /// <returns></returns>
    public bool sendCommand(byte module, byte action, int number)
    {
        byte[] header_bytes = new byte[7] {
            (byte)'A', module, action, 0, 0, 0, 0
        };
        NetMQMessage req_msg = new NetMQMessage();

        byte[] bytesNumber = BitConverter.GetBytes(number);
        for (int i = 3; i < 7; i++)
        {
            header_bytes[i] = bytesNumber[i - 3];
        }
        req_msg.Append(header_bytes);
        //req_msg.Append((byte)number);
        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo?

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        return(true);
    }
Exemplo n.º 2
0
        public IMessage MessageGateWayRequest(string StdMessageName, string destClassName, Dictionary <string, string> dicParam, uint attach, int timeout)
        {
            StdMessage message = new StdMessage(StdMessageName);

            foreach (string strKey in dicParam.Keys)
            {
                message.Parameters.Add(strKey, dicParam[strKey]);
            }

            int l_TimeOut = timeout == 0 ? m_GatewayTimeout : timeout;

            m_GatewaySync.Reset();
            m_GatewayResult = null;
            m_GatewaySendId = this.m_Gateway.Request(destClassName, message, attach);
            if (m_GatewaySendId == 0)
            {
                return(null);
            }
            if (!m_GatewaySync.WaitOne(l_TimeOut, true))
            {
                m_GatewaySendId = 0;
                return(null);
            }
            return(m_GatewayResult.UserMessage);
        }
Exemplo n.º 3
0
    /// <summary>
    /// Command to download files
    /// </summary>
    /// <param name="module"></param>
    /// <param name="action"></param>
    /// <param name="offset"></param>
    /// <param name="size"></param>
    /// <param name="fileName">It must end in \0</param>
    /// <returns></returns>
    public bool sendTwoPartCommand(byte module, byte action, ulong offset, ulong size, string fileName)
    {
        byte[] header_bytes = new byte[19];
        header_bytes[0] = (byte)'A';
        header_bytes[1] = module;
        header_bytes[2] = action;
        byte[] bytesConverted = BitConverter.GetBytes(offset);
        for (int i = 0; i < bytesConverted.Length; i++)
        {
            header_bytes[3 + i] = bytesConverted[i];
        }
        bytesConverted = BitConverter.GetBytes(size);
        for (int i = 0; i < bytesConverted.Length; i++)
        {
            header_bytes[11 + i] = bytesConverted[i];
        }
        NetMQMessage req_msg = new NetMQMessage();

        req_msg.Append(header_bytes);
        req_msg.Append(fileName);
        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo?

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        return(true);
    }
Exemplo n.º 4
0
    /*
     * public bool sendTwoPartCommand(byte module, byte action, int number)
     * {
     *  byte[] header_bytes = new byte[3] { (byte)'A', module, action };
     *  NetMQMessage req_msg = new NetMQMessage();
     *  req_msg.Append(header_bytes);
     *  req_msg.Append((byte)number);
     *  NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo?
     *
     *  reqSrv = new ReliableExternalClient(
     *      GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
     *  if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
     *  {
     *      UnityEngine.Debug.Log("Client: server not respoding");
     *      return false;
     *  }
     *
     *  return true;
     * }
     */
    /// <summary>
    /// Command to send the matrix to the server
    /// </summary>
    /// <param name="matrix"></param>
    /// <returns></returns>
    public bool sendCommand(RegistrationMatrix matrix)
    {
        byte[]       header_bytes = new byte[68];
        NetMQMessage req_msg      = new NetMQMessage();

        header_bytes[0] = (byte)'A';
        header_bytes[1] = matrix.MatrixHeader.module;
        header_bytes[2] = matrix.MatrixHeader.action;
        header_bytes[3] = matrix.rowMajor;
        for (int i = 0; i < 16; i++)
        {
            byte[] aux = BitConverter.GetBytes(matrix.elems[i]);
            header_bytes[i * 4 + 4] = aux[0];
            header_bytes[i * 4 + 5] = aux[1];
            header_bytes[i * 4 + 6] = aux[2];
            header_bytes[i * 4 + 7] = aux[3];
        }
        req_msg.Append(header_bytes);

        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo?

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        return(true);
    }
Exemplo n.º 5
0
    /// <summary>
    /// This one is to delete pointclouds
    /// </summary>
    /// <param name="module"></param>
    /// <param name="action"></param>
    /// <param name="pointCloudID"></param>
    /// <returns></returns>
    public bool sendCommand(byte module, byte action, PointCloudID pointCloudID)
    {
        byte[] header_bytes = new byte[17];
        header_bytes[0]  = (byte)'A';
        header_bytes[1]  = module;
        header_bytes[2]  = action;
        header_bytes[3]  = (byte)' ';
        header_bytes[16] = pointCloudID.heading;
        byte[] iArray = BitConverter.GetBytes(pointCloudID.i);
        byte[] jArray = BitConverter.GetBytes(pointCloudID.j);
        byte[] kArray = BitConverter.GetBytes(pointCloudID.k);


        for (int i = 4; i < 8; i++)
        {
            header_bytes[i + 1 * 0] = iArray[i - 4];
            header_bytes[i + 1 * 4] = jArray[i - 4];
            header_bytes[i + 1 * 8] = kArray[i - 4];
        }
        NetMQMessage req_msg = new NetMQMessage();

        req_msg.Append(header_bytes);

        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo?

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        return(true);
    }
Exemplo n.º 6
0
    /// <summary>
    /// Sets drone filter. Only pozyx used this
    /// </summary>
    /// <param name="module"></param>
    /// <param name="action"></param>
    /// <param name="space"></param>
    /// <param name="updatePeriod"></param>
    /// <param name="movementFreedom"></param>
    /// <returns></returns>
    public bool sendSetDroneFilter(byte module, byte action, byte space, float updatePeriod, Int32 movementFreedom)
    {
        byte[] header_bytes = new byte[12] {
            (byte)'A', module, action, 0, 0, 0, 0, 0, 0, 0, 0, 0
        };
        byte[] convertedUpdatePeriod    = BitConverter.GetBytes(updatePeriod);
        byte[] convertedMovementFreedom = BitConverter.GetBytes(movementFreedom);

        System.Buffer.BlockCopy(convertedUpdatePeriod, 0, header_bytes, 4, 4);
        System.Buffer.BlockCopy(convertedMovementFreedom, 0, header_bytes, 8, 4);

        NetMQMessage req_msg = new NetMQMessage();

        req_msg.Append(header_bytes);
        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo?

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        return(true);
    }
Exemplo n.º 7
0
    /// <summary>
    /// Sends z camera offset
    /// </summary>
    /// <param name="module"></param>
    /// <param name="action"></param>
    /// <param name="camInfo"></param>
    /// <returns></returns>
    public bool sendCommand(byte module, byte action, ServerMessages.DroneCamInfo camInfo)
    {
        byte[] data_bytes = new byte[31]; // { (byte)'A', module, action, data.id, data.order, data.position };
        data_bytes[0] = (byte)'A';
        data_bytes[1] = module;
        data_bytes[2] = action;
        byte[] converted = BitConverter.GetBytes(camInfo.camPos.x);
        for (int i = 0; i < 4; i++)
        {
            data_bytes[i + 4] = converted[i];
        }
        converted = BitConverter.GetBytes(camInfo.camPos.y);
        for (int i = 0; i < 4; i++)
        {
            data_bytes[i + 8] = converted[i];
        }
        converted = BitConverter.GetBytes(camInfo.camPos.z);
        for (int i = 0; i < 4; i++)
        {
            data_bytes[i + 12] = converted[i];
        }
        NetMQMessage req_msg = new NetMQMessage();

        req_msg.Append(data_bytes);

        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        // Just after the request the atreyu server must respond with a notification
        // (ACK, UNKNOWN_MODULE, or UNDEFINED_MODULE) through the same 'requests' socket.
        if (StdMessage.isStdNotification(ref resp_msg) && StdMessage.getMessageAction(ref resp_msg) != (byte)NotificationType.ACK)
        {
            if (module == (byte)Modules.STD_COMMANDS_MODULE)
            {
                UnityEngine.Debug.Log(
                    String.Format("Client: STD command was not accepted {0}", new StdMessage(module, action).to_string()));
            }
            else if (module == (byte)Modules.POSITIONING_MODULE)
            {
                UnityEngine.Debug.Log(
                    String.Format("Client: POSITIONING_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string()));
            }
            else if (module == (byte)Modules.POINTCLOUD_MODULE)
            {
                UnityEngine.Debug.Log(
                    String.Format("Client: POINTCLOUD_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string()));
            }
            return(false);
        }

        return(true);
    }
Exemplo n.º 8
0
    public bool sendAndReceive(ref NetMQ.Msg req_msg, ref NetMQ.Msg resp_msg)
    {
        if (socket == null)
        {
            reconnect();
        }

        StdMessage m = new StdMessage(req_msg.Data[1], req_msg.Data[2]);

        NetMQ.Msg copy = new NetMQ.Msg();
        bool      ok   = false;

        for (uint i = 0; i < retries; i++)
        {
            copy.Copy(ref req_msg);

            // send
            if (!socket.TrySend(ref copy, TimeSpan.FromMilliseconds(min_trysend_ms), false))
            {
                ok = false;
                UnityEngine.Debug.Log("ReliableExternalClient: could not send");
                break;

                //TODO: clear enqueued messages when server is offline
            }
            //UnityEngine.Debug.Log("ReliableExternalClient: request sent " + m.to_string());

            // receive
            if (socket.TryReceive(ref resp_msg, timeout))
            {
                ok = true;
                // UnityEngine.Debug.Log("ReliableExternalClient: response received "
                //+ new StdMessage(resp_msg.Data[1], resp_msg.Data[2]).to_string());
                break;
            }

            //UnityEngine.Debug.Log(String.Format("ReliableExternalClient: no response from server {0}. Retrying", srvAddress));
            reconnect();
        }

        if (!ok)
        {
            UnityEngine.Debug.Log(String.Format("ReliableExternalClient: server {0} seems to be offline. Abandoning", srvAddress));
        }

        copy.Close();
        socket.Dispose();  //call Dispose on all sockets before cleanup the netmq context
        socket.Close();

        socket = null;

        if (socket == null)
        {
            UnityEngine.Debug.Log("ReliableExternalClient: socket closed and null");
        }

        return(ok);
    }
Exemplo n.º 9
0
        private void frmCreateMessage_SaveClicked(object sender, EventArgs e)
        {
            _message = new StdMessage();

            _message.MessageText = _edtMensaje.Text;
            _message.StationIdTo = Convert.ToInt32(_cmbStation.SelectedValue);
            _message.StationIdFrom = _StationIdFrom;
            _message.MessageTypeId = 1;
            _message.CreationDate = DateTime.Now;
            _message.CreationBy = 1;

            this.DialogResult = DialogResult.OK;
            this.Hide();
        }
Exemplo n.º 10
0
    //No one uses this
    public bool sendThreePartCommand(byte module, byte action, byte[] data1, int size1, byte[] data2, int size2)
    {
        byte[] header_bytes = new byte[3] {
            (byte)'A', module, action
        };

        NetMQMessage req_msg = new NetMQMessage();

        req_msg.Append(header_bytes);
        req_msg.Append(data1);
        req_msg.Append(data2);
        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo?

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        // Just after the request the atreyu server must respond with a notification
        // (ACK, UNKNOWN_MODULE, or UNDEFINED_MODULE) through the same 'requests' socket.

        /*
         * if (StdMessage.isStdNotification(ref resp_msg) && StdMessage.getMessageAction(ref resp_msg) != (byte)NotificationType.ACK)
         * {
         *  if (module == (byte)Modules.STD_COMMANDS_MODULE)
         *  {
         *      UnityEngine.Debug.Log(
         *          String.Format("Client: STD command was not accepted {0}", new StdMessage(module, action).to_string()));
         *  }
         *  else if (module == (byte)Modules.POSITIONING_MODULE)
         *  {
         *      UnityEngine.Debug.Log(
         *          String.Format("Client: POSITIONING_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string()));
         *  }
         *  else if (module == (byte)Modules.POINTCLOUD_MODULE)
         *  {
         *      UnityEngine.Debug.Log(
         *          String.Format("Client: POINTCLOUD_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string()));
         *  }
         *  return false;
         * }
         */

        return(true);
    }
Exemplo n.º 11
0
    /// <summary>
    /// Command to load a plan on the Plan executor
    /// </summary>
    /// <param name="loadPlan"></param>
    /// <param name="guid"></param>
    /// <returns></returns>
    public bool sendTwoPartCommand(LoadPlan loadPlan, string guid)
    {
        byte[] header_bytes = new byte[4] {
            (byte)'A', loadPlan.PlanHeader.module, loadPlan.PlanHeader.action, loadPlan.indexPath
        };
        NetMQMessage req_msg = new NetMQMessage();

        req_msg.Append(header_bytes);
        req_msg.Append(guid);
        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo?

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        return(true);
    }
Exemplo n.º 12
0
    /// <summary>
    /// Send parameters of the reccam which aren't bytes. Convert the value to send to 4 bytes
    /// </summary>
    /// <param name="module"></param>
    /// <param name="action"></param>
    /// <param name="config"></param>
    /// <param name="valueByte1"></param>
    /// <param name="valueByte2"></param>
    /// <param name="valueByte3"></param>
    /// <param name="valueByte4"></param>
    /// <returns></returns>
    public bool sendCommand(byte module, byte action, byte config, byte valueByte1, byte valueByte2, byte valueByte3, byte valueByte4)
    {
        byte[] header_bytes = new byte[8] {
            (byte)'A', module, action, config, valueByte1, valueByte2, valueByte3, valueByte4
        };
        NetMQMessage req_msg = new NetMQMessage();

        req_msg.Append(header_bytes);

        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response ## la respuesta de dos partes sigue siendo de este tipo?

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        return(true);
    }
Exemplo n.º 13
0
    /// <summary>
    /// Command to send a module and an action
    /// </summary>
    /// <param name="module">The module to send. See messagecodes</param>
    /// <param name="action">The action that belongs to the module</param>
    /// <returns></returns>
    public bool SendCommand(byte module, byte action)
    {
        NetMQ.Msg req_msg  = new StdMessage(module, action).to_Msg();
        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        // Just after the request the atreyu server must respond with a notification
        // (ACK, UNKNOWN_MODULE, or UNDEFINED_MODULE) through the same 'requests' socket.
        if (StdMessage.isStdNotification(ref resp_msg) && StdMessage.getMessageAction(ref resp_msg) != (byte)NotificationType.ACK)
        {
            if (module == (byte)Modules.STD_COMMANDS_MODULE)
            {
                UnityEngine.Debug.Log(
                    String.Format("Client: STD command was not accepted {0}", new StdMessage(module, action).to_string()));
            }
            else if (module == (byte)Modules.POSITIONING_MODULE)
            {
                UnityEngine.Debug.Log(
                    String.Format("Client: POSITIONING_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string()));
            }
            else if (module == (byte)Modules.POINTCLOUD_MODULE)
            {
                UnityEngine.Debug.Log(
                    String.Format("Client: POINTCLOUD_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string()));
            }
            return(false);
        }

        return(true);
    }
Exemplo n.º 14
0
    /// <summary>
    /// Command to send anchors to calibration
    /// </summary>
    /// <param name="module"></param>
    /// <param name="action"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    public bool sendCommand(byte module, byte action, ServerMessages.IPSFrameAnchorData[] data)
    {
        NetMQMessage req_msg = new NetMQMessage();

        byte[] header_bytes = new byte[8]; // { (byte)'A', module, action, data.id, data.order, data.position };
        header_bytes[0] = (byte)'A';
        header_bytes[1] = module;
        header_bytes[2] = action;
        header_bytes[3] = 0;
        byte[] converted = BitConverter.GetBytes(data.Length);
        System.Buffer.BlockCopy(converted, 0, header_bytes, 4, 4);
        req_msg.Append(header_bytes);

        for (int j = 0; j < data.Length; j++)
        {
            byte[] data_bytes = new byte[17];
            UnityEngine.Debug.Log("Anchor ID: " + data[j].id);
            converted = BitConverter.GetBytes(data[j].id);
            System.Buffer.BlockCopy(converted, 0, data_bytes, 0, 4);

            converted = BitConverter.GetBytes((int)data[j].position.x);
            System.Buffer.BlockCopy(converted, 0, data_bytes, 4, 4);

            converted = BitConverter.GetBytes((int)data[j].position.y);
            System.Buffer.BlockCopy(converted, 0, data_bytes, 8, 4);

            converted = BitConverter.GetBytes((int)data[j].position.z);
            System.Buffer.BlockCopy(converted, 0, data_bytes, 12, 4);

            data_bytes[16] = data[j].order;
            req_msg.Append(data_bytes);
        }

        NetMQ.Msg resp_msg = new StdMessage(0x00, 0x00).to_Msg();  // it will be filled when receiving the response

        reqSrv = new ReliableExternalClient(
            GlobalSettings.Instance.getRequestPort(), TimeSpan.FromMilliseconds(1000), 3);
        if (!reqSrv.sendAndReceive(ref req_msg, ref resp_msg))
        {
            UnityEngine.Debug.Log("Client: server not respoding");
            return(false);
        }

        // Just after the request the atreyu server must respond with a notification
        // (ACK, UNKNOWN_MODULE, or UNDEFINED_MODULE) through the same 'requests' socket.
        if (StdMessage.isStdNotification(ref resp_msg) && StdMessage.getMessageAction(ref resp_msg) != (byte)NotificationType.ACK)
        {
            if (module == (byte)Modules.STD_COMMANDS_MODULE)
            {
                UnityEngine.Debug.Log(
                    String.Format("Client: STD command was not accepted {0}", new StdMessage(module, action).to_string()));
            }
            else if (module == (byte)Modules.POSITIONING_MODULE)
            {
                UnityEngine.Debug.Log(
                    String.Format("Client: POSITIONING_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string()));
            }
            else if (module == (byte)Modules.POINTCLOUD_MODULE)
            {
                UnityEngine.Debug.Log(
                    String.Format("Client: POINTCLOUD_MODULE command was not accepted {0}", new StdMessage(ref resp_msg).to_string()));
            }
            return(false);
        }

        return(true);
    }