Esempio n. 1
0
        private void SendScooterLocation(int scooterId)
        {
            var trackingMessage = new TrackingMessage(
                scooterId, new Random().Next(1, 200));

            Task.Run(() => queue.SendMessageAsync(trackingMessage));
        }
Esempio n. 2
0
        private byte[] GetBytes(TrackingMessage m)
        {
            int    length = Marshal.SizeOf(m);
            IntPtr ptr    = Marshal.AllocHGlobal(length);

            byte[] myBuffer = new byte[length];

            Marshal.StructureToPtr(m, ptr, true);
            Marshal.Copy(ptr, myBuffer, 0, length);
            Marshal.FreeHGlobal(ptr);

            return(myBuffer);
        }
Esempio n. 3
0
    // When receives a new tracking message
    void OnTracking(NetworkMessage netMsg)
    {
        TrackingMessage trackMsg = netMsg.ReadMessage <TrackingMessage>();

        collectControllerData(trackMsg);

        if (currState == Initializing)
        {
            Debug.Log("Initializing...");
            // the first grip message seen is the right controller.
            if (trackMsg.grip)
            {
                // right controller hasn't been seen yet, so this id represents the right controller.
                if (controllerIDs[0] < 0)
                {
                    controllerIDs[0] = trackMsg.id;
                }
                else if (controllerIDs[1] < 0)   // right controller was already captured, but left wasn't.
                {
                    controllerIDs[1] = trackMsg.id;
                    // both controller IDs have now been captured.
                    Debug.Log("Right controller ID: " + controllerIDs[0] + ", left controller ID: " + controllerIDs[1]);
                    Debug.Log("Continuing to calibration mode...");
                    currState = Calibrating;
                    return;
                }
            }
        }


        if (currState == Calibrating)
        {
            //Debug.Log("Calibrating...");
            _controllerTrackerRight.transform.position = _currPositionRight;
            _controllerTrackerLeft.transform.position  = _currPositionLeft;
            handleCalibration();
            _currGripRight = false;
            return;
        }

        if (currState == Tracking)
        {
            Debug.Log("Tracking");
            // show current controller location.
            _controllerTrackerRight.transform.position = calibratedPos(_currPositionRight);
            _controllerTrackerLeft.transform.position  = calibratedPos(_currPositionLeft);
            return;
        }
    }
Esempio n. 4
0
        public void Insert(int scooterId, int locationId)
        {
            try
            {
                var trackingMessage = new TrackingMessage(
                    scooterId, locationId);

                Task.Run(() => queue.SendMessageAsync(trackingMessage));
                //this.trackingRepository.Insert(new Tracking(scooterId, locationId));
            }
            catch (ApplicationException appEx)
            {
                throw appEx;
            }
        }
Esempio n. 5
0
 void Update()
 {
     if (_updateCount % 5 == 0)
     {
         _position = transform.position;
         //Debug.Log("_updateCount: " + _updateCount + ", _position: " + _position + ", id: " + (int)trackedObject.index);
         TrackingMessage msg = new TrackingMessage
         {
             id         = _id,
             trigger    = _trigger,
             position   = _position,
             touchPad   = _touchPad = device.GetAxis(),
             grip       = _grip,
             padClicked = _padClicked,
             padTouched = _padTouched
         };
         _networkManager.sendMessage(MyNetworkManager.Tracking, msg);
         resetAll();
         _updateCount = 0;
     }
     _updateCount++;
 }
Esempio n. 6
0
    void collectControllerData(TrackingMessage trackMsg)
    {
        if (trackMsg.id == controllerIDs[0])
        {
            _currTriggerRight    = trackMsg.trigger;
            _currPositionRight   = trackMsg.position;
            _currGripRight       = trackMsg.grip;
            _currTouchpadRight   = trackMsg.touchPad;
            _currPadClickedRight = trackMsg.padClicked;
            _currPadTouchedRight = trackMsg.padTouched;
            //Debug.Log("Right, pos: " + _currPositionRight + ", trig: " + _currTriggerRight + ", pad: " + _currPadTouchedRight);
        }

        if (trackMsg.id == controllerIDs[1])
        {
            _currTriggerLeft    = trackMsg.trigger;
            _currPositionLeft   = trackMsg.position;
            _currGripLeft       = trackMsg.grip;
            _currTouchpadLeft   = trackMsg.touchPad;
            _currPadClickedLeft = trackMsg.padClicked;
            _currPadTouchedLeft = trackMsg.padTouched;
            //Debug.Log("Left, pos: " + _currPositionLeft + ", trig: " + _currTriggerLeft + ", pad: " + _currPadTouchedLeft);
        }
    }