コード例 #1
0
        private void Receive(IAsyncResult res)
        {
            if (_open) {
                var remoteIpEndPoint = new IPEndPoint(IPAddress.Any, ListenPort);
                byte[] receivedByteArray = _client.EndReceive(res, ref remoteIpEndPoint);
                var receivedString = Encoding.UTF8.GetString(receivedByteArray);
                string[] dataParsed = receivedString.Split(',');

                if (dataParsed.Length >= 5) {
                    //var timestamp = long.Parse(dataParsed[0], CultureInfo.InvariantCulture);
                    var sensorTypeInt = int.Parse(dataParsed[1], CultureInfo.InvariantCulture);

                    float x = float.Parse(dataParsed[2], CultureInfo.InvariantCulture);
                    float y = float.Parse(dataParsed[3], CultureInfo.InvariantCulture);
                    float z = float.Parse(dataParsed[4], CultureInfo.InvariantCulture);
                    var vector = new Vector3D(x, y, z);

                    SensorType sensorType;
                    bool found = SensorTypeIntToEnum.TryGetValue(sensorTypeInt, out sensorType);
                    if (found) {
                        var measurement = new Measurement(sensorType, vector);
                        _callback(measurement);
                    }
                }

                _client.BeginReceive(Receive, null);
            }
        }
コード例 #2
0
 private void ShowMeasurement(Measurement measurement)
 {
     switch (measurement.SensorType) {
         case SensorType.Accelerometer:
             Dispatcher.BeginInvoke((Action)(() => AccelerationVectorControl.UpdateVector(measurement.Value)));
             break;
         case SensorType.Gyroscope:
             Dispatcher.BeginInvoke((Action)(() => GyroscopeVectorControl.UpdateVector(measurement.Value)));
             break;
     }
 }