public void Append(SensorItem e) { try { if (!isAppending) { isAppending = true; var message = $"{e.timestamp:yyyy-MM-dd HH:mm:ss.fffffffzzz},{e.aX:F8},{e.aY:F8},{e.aZ:F8},{e.avX:F8},{e.avY:F8},{e.avZ:F8},{e.qW:F8},{e.qX:F8},{e.qY:F8},{e.qZ:F8},{e.lat:F8},{e.lon:F8},{e.speed:F8},{e.alt:F8},{e.incl:F8}"; //,{CommonState.LocationData.LastAltitude},{CommonState.Account.LapSummary.ActivityMetrics.Slope},{CommonState.LocationData.LastPosition.Latitude},{CommonState.LocationData.LastPosition.Longitude}"; buffer.Add(message); totalCount++; if (buffer.Count > BUFFER_SIZE) { Debug.WriteLine($"***SAVING... ID={Id} TAG={Tag} {totalCount}"); Save(); buffer.Clear(); } if (Id != SensorKit.HUB_SENSOR_ID) { Debug.WriteLine($"***APPEND MODEL... ID={Id} TAG={Tag} {message}"); } } } catch (Exception x) { Debug.WriteLine(x); } isAppending = false; }
private SensorItem BytesToSensorData(byte[] bArray) { SensorItem reading = null; try{ if (bArray != null && bArray.Length >= 12) { //foreach (var b in bArray) //{ // Debug.Write($"{b:X2}-"); //} //Debug.WriteLine(""); // convert values to float bool isRecognized = false; var dataType = BitConverter.ToChar(bArray, 0); Quaternion q = new Quaternion(); double ax = 0.0; double ay = 0.0; double az = 0.0; double lat = 0.0; double lon = 0.0; double speed = 0.0; double altitude = 0.0; double incline = 0.0; if (dataType == 'Q' || (char)bArray[0] == 'Q') { q = new Quaternion { X = BitConverter.ToSingle(bArray, 1), Y = BitConverter.ToSingle(bArray, 5), Z = BitConverter.ToSingle(bArray, 9), W = BitConverter.ToSingle(bArray, 13) }; isRecognized = true; } else if (dataType == 'A' || (char)bArray[0] == 'A') { ax = BitConverter.ToSingle(bArray, 1); ay = BitConverter.ToSingle(bArray, 5); az = BitConverter.ToSingle(bArray, 9); isRecognized = true; } if (isRecognized) { if (Controller.FusionData != null) { lat = Controller.FusionData.lat; lon = Controller.FusionData.lon; speed = Controller.FusionData.speed; altitude = Controller.FusionData.alt; incline = Controller.FusionData.incl; } reading = new SensorItem { timestamp = DateTimeOffset.Now, aX = az, aY = ay, aZ = az, qX = q.X, qY = q.Y, qZ = q.Z, qW = q.W, lat = lat, lon = lon, speed = speed, alt = altitude, incl = incline }; Debug.WriteLine($"*** {Data.Name} Q X:{reading.qX} Y:{reading.qY} Z:{reading.qZ} W:{reading.qW} A: X:{reading.aX} Y:{reading.aY} Z:{reading.aZ}"); return(reading); } } }catch (Exception x) { Debug.WriteLine(x); } return(null); }