using System.Collections.Generic; using Newtonsoft.Json.Linq; using o0.IMU; using o0.Geometry; using o0; public class AttitudeJson : JCUnityLib.CustomJson { public AttitudeJson() : base() { InitJsonClass<_9AxisPreProcessor>(() => new _9AxisPreProcessor(), "AccByteIndex", "GyrByteIndex", "MagByteIndex", "ByteToAcc", "ByteToGyr", "ByteToMag", "GyrCalibrater", "MagCalibrater", "ByteReverseMS" ); InitJsonClass(() => new MagnetometerAutoCalibrater(), "CountPerLength", "EllipsoidFitting", "FitCountLeft", "FitThreshold", "LastTimestamp", "Lock", "MaxCount", "NewBlock", "NewBlockAccumulation", "Variance", "VectorByBlock" ); InitJsonClass(() => new ByteToShorts(3), "ByteToShort" ); InitJsonClass>>(() => new MeanMaintainer>(), "Count", "Mean" ); InitJsonClass(() => new ByteToShortByVariance(), "Count", "Reverse", "Short", "ThresholdRate" ); InitJsonClass( o => { var to = (EllipsoidFitting)o; JToken jt = new JObject(); jt["Center"] = ToJTokenByImporter(to.Center); jt["CorrectMatrixArray"] = ToJTokenByImporter(to.CorrectMatrixArray); jt["Raduis"] = ToJTokenByImporter(to.Radius); return jt; }, jt => { var o = new EllipsoidFitting( (Vector)ParseByExporter(jt["Center"], typeof(Vector)), null, (Vector)ParseByExporter(jt["Radius"], typeof(Vector)) ); o.CorrectMatrixArray = (double[][])ParseByExporter(jt["CorrectMatrixArray"], typeof(double[][])); return o; } ); InitJsonClass, Vector>>( o => JToken.FromObject(o), jt => { var o = new Dictionary, Vector>(); foreach (JProperty item in jt) o[ParseByExporter>(JArray.Parse(item.Name))] = ParseByExporter>(item.Value); return o; } ); InitJsonClass>( o => JToken.FromObject(o), jt => new Vector(jt.ToObject()) ); InitJsonClass>( o => JToken.FromObject(o), jt => new Vector(jt.ToObject()) ); } }