Exemplo n.º 1
0
    /// <summary>
    /// Method to parse and send an event when Pose Data is transfer from smart device
    /// </summary>
    /// <param name="recBuffer">The data that was recieved from the smart device</param>
    private void HandlePoseData(byte[] recBuffer)
    {
        Stream          stream    = new MemoryStream(recBuffer);
        BinaryFormatter formatter = new BinaryFormatter();

        if (SDK_BUILD_NO == 1)           //support in case we do not want acceleration data being streamed
        {
            PoseSerializer poseData = (PoseSerializer)formatter.Deserialize(stream);

            if (OnPoseData != null)
            {
                OnPoseData(poseData.V3, poseData.Q);
            }
        }
        else             //stream of acceleration data
        {
            PoseSerializerWithAcceleration poseData = (PoseSerializerWithAcceleration)formatter.Deserialize(stream);

            if (OnPoseData != null)
            {
                OnPoseData(poseData.Position, poseData.Rotation);
            }

            if (OnAccelerationData != null)
            {
                OnAccelerationData(poseData.Acceleration);
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Method to parse and send an event when Pose Data is transfer from smart device
    /// </summary>
    /// <param name="connectionID">The id of the device that connected</param>
    /// <param name="recBuffer">The data that was recieved from the smart device</param>
    private void HandlePoseData(int connectionID, byte[] recBuffer)
    {
        Stream          stream    = new MemoryStream(recBuffer);
        BinaryFormatter formatter = new BinaryFormatter();
        PoseSerializerWithAcceleration poseData = (PoseSerializerWithAcceleration)formatter.Deserialize(stream);

        if (OnPoseData != null)
        {
            OnPoseData(connectionID, poseData.Position, poseData.Rotation);
        }

        if (OnAccelerationData != null)
        {
            OnAccelerationData(connectionID, poseData.Acceleration);
        }
    }
Exemplo n.º 3
0
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;

        byte[]           recBuffer  = new byte[MAX_RECIEVE_SIZE];
        int              bufferSize = MAX_RECIEVE_SIZE;
        int              dataSize;
        byte             error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);

        Array.Resize <byte> (ref recBuffer, dataSize);        //resize to how much data was received

        switch (recData)
        {
        case NetworkEventType.ConnectEvent:
            break;

        case NetworkEventType.DataEvent:
            if (channelId == myReiliableChannelId)
            {
                HandleRPC(recBuffer);
            }
            else if (channelId == myReliableFramentedChannelId)
            {
                HandleBigRPC(recBuffer);
            }

            break;

        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;

        default:         //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviConnectionID > 0)           //we are connected to a device
        {
            byte[]          buffer              = new byte[BUFFER_SIZE];
            Stream          stream              = new MemoryStream(buffer);
            BinaryFormatter formatter           = new BinaryFormatter();
            PoseSerializerWithAcceleration pose = new PoseSerializerWithAcceleration();
            pose.Fill(TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation, Input.acceleration);
            formatter.Serialize(stream, pose);
            NetworkTransport.Send(socketID, naviConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error);              //send full buffer

            foreach (Touch t in Input.touches)
            {
                buffer = new byte[BUFFER_SIZE];
                stream = new MemoryStream(buffer);

                RPCSerializer rpc = new RPCSerializer();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args       = new object[1];
                TouchSerializer ts = new TouchSerializer();
                ts.Fill(t);
                rpc.args [0] = ts;
                formatter.Serialize(stream, rpc);
                NetworkTransport.Send(socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }

            SendKeyboardText();

            if (Screen.orientation != prevOrientation)
            {
                SendCurrentSize();
                prevOrientation = Screen.orientation;
            }
        }
    }
Exemplo n.º 4
0
    /// <summary>
    ///  Handles sending all data to the VR display, this includes pose data via the naviPoseconnection and touch data via the rpcConnection
    /// It also handles receiving any data from the VR display. Currently, it just listens for which connection should send which type of data
    /// </summary>
    void Update()
    {
        int recHostId;
        int connectionId;
        int channelId;
        byte[] recBuffer = new byte[MAX_RECIEVE_SIZE];
        int bufferSize = MAX_RECIEVE_SIZE;
        int dataSize;
        byte error;
        NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
        Array.Resize<byte> (ref recBuffer, dataSize); //resize to how much data was received

        switch (recData)
        {
        case NetworkEventType.ConnectEvent:
            break;
        case NetworkEventType.DataEvent:
            if (channelId == myReiliableChannelId) {
                HandleRPC (recBuffer);
            } else if (channelId == myReliableFramentedChannelId) {
                HandleBigRPC (recBuffer);
            }

            break;
        case NetworkEventType.DisconnectEvent:
            OnDisconnect(connectionId);
            break;
        default: //i.e. NetworkEventType.ConnectEvent, NetworkEventType.Nothing:\
            break;
        }

        if (naviConnectionID > 0) { //we are connected to a device
            byte[] buffer = new byte[BUFFER_SIZE];
            Stream stream = new MemoryStream (buffer);
            BinaryFormatter formatter = new BinaryFormatter ();
            PoseSerializerWithAcceleration pose = new PoseSerializerWithAcceleration ();
            pose.Fill (TransformManagerInterface.Instance.transform.position, TransformManagerInterface.Instance.transform.rotation, Input.acceleration);
            formatter.Serialize (stream, pose);
            NetworkTransport.Send (socketID, naviConnectionID, myUnreliableChannelId, buffer, BUFFER_SIZE, out error); //send full buffer

            foreach (Touch t in Input.touches) {
                buffer = new byte[BUFFER_SIZE];
                stream = new MemoryStream (buffer);

                RPCSerializer rpc = new RPCSerializer ();
                rpc.methodName = TOUCH_METHOD_ID;
                rpc.args = new object[1];
                TouchSerializer ts = new TouchSerializer ();
                ts.Fill (t);
                rpc.args [0] = ts;
                formatter.Serialize (stream, rpc);
                NetworkTransport.Send (socketID, naviConnectionID, myReiliableChannelId, buffer, BUFFER_SIZE, out error);
            }

            SendKeyboardText ();

            if (Screen.orientation != prevOrientation) {
                SendCurrentSize ();
                prevOrientation = Screen.orientation;
            }
        }
    }