Example #1
0
    void OnGUI()
    {
        GUI.skin.textArea.fontSize = 10;
        GUI.skin.button.fontSize   = 32;
        GUI.skin.toggle.fontSize   = 32;
        GUI.skin.label.fontSize    = 32;



        string data = "";

        data += StateToString(_state) + "\n";
        if (_connected)
        {
            if (_state == States.None)
            {
                if (_dataBytes != null)
                {
                    data += "getting bytes\n";
                    data += BluetoothBytes.MakeFromBytes(_dataBytes).ToHex();
                }
            }
        }
        GUI.TextArea(new Rect(0, Screen.height - 200, Screen.width, 200), data);
    }
Example #2
0
    public static int InfoForNodeSequence(string nodeIdSequence, BluetoothBytes rawData, int infoStartIndex, int infoLengthInBytes)
    {
        byte[] rawDataBytes = rawData.ToBytes();
        int    nodeIndex    = rawData.FindHex(nodeIdSequence);

        byte[] nodeInfoBytes = new byte[infoLengthInBytes];
        for (int i = 0; i < infoLengthInBytes; i++)
        {
            nodeInfoBytes[i] = rawDataBytes[nodeIndex + infoStartIndex + nodeIdSequence.Length / 2 + i];
        }
        return(BluetoothBytes.BytesToInt(nodeInfoBytes));
    }
Example #3
0
    public static int[] Position(BluetoothBytes bluetoothBytes, int startIndex = 1, int coordinateByteLength = 4)
    {
        List <byte> bytes  = bluetoothBytes.ToBytes().ToList();
        List <int>  coords = new List <int>();

        for (int i = startIndex; i < bytes.Count - 1; i += coordinateByteLength)
        {
            coords.Add(BluetoothBytes.BytesToInt(bytes.GetRange(i, coordinateByteLength).ToArray()));
        }
        coords.Add(bytes.Last());
        return(coords.ToArray());
    }
Example #4
0
    void GetAnchorDistancesForTestPoint(int testPointIndex)
    {
        BluetoothConnector.States bluetoothConnectorAction = BluetoothConnector.currentAction();
        bool bluetoothConnectorSuccess = BluetoothConnector.actionSuccessful();

        if (bluetoothConnectorAction == BluetoothConnector.States.Subscribe && bluetoothConnectorSuccess)
        {
            BluetoothBytes bluetoothBytes = CurrentBluetoothBytes();
            foreach (string anchorName in AnchorNames)
            {
                int distance = DistanceUtil.DistanceToNode(anchorName, bluetoothBytes);
                anchorToTestPoints[anchorName][testPointIndex] = (double)distance;
            }
        }
    }
Example #5
0
    IEnumerator PushAnchorPositions()
    {
        BluetoothConnector.Disconnect();
        yield return(new WaitUntil(() => BluetoothConnector.currentState() == BluetoothConnector.States.Disconnected));

        BluetoothConnector.Reset();

        foreach (string anchorName in AnchorNames)
        {
            Debug.Log("pushing anchor " + anchorName);
            BluetoothBytes positionBytes = BluetoothBytes.MakeFromLocation((int)anchorPositions[anchorName][0], (int)anchorPositions[anchorName][1], (int)anchorPositions[anchorName][2], 100);
            Debug.Log("would push " + positionBytes.ToHex());
            byte[] anchorPositionBytes = positionBytes.ToBytes();
            BluetoothConnector.InitializeAction(anchorName, ServiceUUID, WriteCharacteristic, BluetoothConnector.States.Write, bytesToWrite: anchorPositionBytes);
            BluetoothConnector.StartProcess();
            yield return(new WaitUntil(() => BluetoothConnector.actionSuccessful()));

            BluetoothConnector.Disconnect();
            yield return(new WaitUntil(() => BluetoothConnector.currentState() == BluetoothConnector.States.Disconnected));

            BluetoothConnector.Reset();
        }
    }
Example #6
0
    public static BluetoothBytes MakeFromLocation(int x, int y, int z, int quality)
    {
        BluetoothBytes newBluetoothBytes = new BluetoothBytes(x, y, z, quality);

        return(newBluetoothBytes);
    }
Example #7
0
    public static BluetoothBytes MakeFromBytes(byte[] bytes)
    {
        BluetoothBytes newBluetoothBytes = new BluetoothBytes(bytes);

        return(newBluetoothBytes);
    }
Example #8
0
    public static BluetoothBytes MakeFromHex(string _hexString)
    {
        BluetoothBytes newBluetoothBytes = new BluetoothBytes(_hexString);

        return(newBluetoothBytes);
    }
Example #9
0
    /*
     * void shiftAnchorCoordinatesToPositive()
     * {
     *  double minX = double.MaxValue;
     *  double minY = double.MaxValue;
     *  foreach (string anchorName in AnchorNames)
     *  {
     *      if (anchorPositions[anchorName][0] > minX)
     *          minX = anchorPositions[anchorName][0];
     *          minX = anchorPositions[anchorName][0];
     *      if (anchorPositions[anchorName][1] > minY)
     *          minY = anchorPositions[anchorName][1];
     *          minY = anchorPositions[anchorName][1];
     *  }
     *  if (minX < 0)
     *      foreach (string anchorName in AnchorNames)
     *      {
     *          anchorPositions[anchorName][0] += -minX;
     *          testAnchorPositions[anchorName][0] += -minX;
     *      }
     *  if (minY < 0)
     *      foreach (string anchorName in AnchorNames)
     *      {
     *          anchorPositions[anchorName][1] += -minY;
     *          testAnchorPositions[anchorName][1] += -minY;
     *      }
     * }
     */

    BluetoothBytes CurrentBluetoothBytes()
    {
        return(BluetoothBytes.MakeFromBytes(BluetoothConnector.currentBytes()));
    }
Example #10
0
 public static int QualityToNode(string nodeName, BluetoothBytes distanceData)
 {
     //Debug.Log(distanceData.ToHex());
     return(InfoForNodeSequence(NodeNameToNodeId(nodeName), distanceData, 4, 1));
 }
Example #11
0
 public static int DistanceToNode(string nodeName, BluetoothBytes distanceData)
 {
     return(InfoForNodeSequence(NodeNameToNodeId(nodeName), distanceData, 0, 4));
 }