static Constants() { IntPtr str = new IntPtr(); CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 1)); VersionNumber = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetIntConstant(ref VersionMajor, 2)); CheckErrorCode(Api.YOGI_GetIntConstant(ref VersionMinor, 3)); CheckErrorCode(Api.YOGI_GetIntConstant(ref VersionPatch, 4)); CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 5)); DefaultAdvInterfaces = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 6)); DefaultAdvAddress = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetIntConstant(ref DefaultAdvPort, 7)); long t = -1; CheckErrorCode(Api.YOGI_GetLongLongConstant(ref t, 8)); DefaultAdvInterval = Duration.FromNanoseconds(t); CheckErrorCode(Api.YOGI_GetLongLongConstant(ref t, 9)); DefaultConnectionTimeout = Duration.FromNanoseconds(t); int n = -1; CheckErrorCode(Api.YOGI_GetIntConstant(ref n, 10)); DefaultLoggerVerbosity = (Verbosity)n; CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 11)); DefaultLogTimeFormat = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 12)); DefaultLogFormat = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetIntConstant(ref MaxMessagePayloadSize, 13)); CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 14)); DefaultTimeFormat = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 15)); DefaultInfiniteDurationString = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 16)); DefaultDurationFormat = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 17)); DefaultInvalidHandleString = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetStringConstant(ref str, 18)); DefaultObjectFormat = Marshal.PtrToStringAnsi(str); CheckErrorCode(Api.YOGI_GetIntConstant(ref MinTxQueueSize, 19)); CheckErrorCode(Api.YOGI_GetIntConstant(ref MaxTxQueueSize, 20)); CheckErrorCode(Api.YOGI_GetIntConstant(ref DefaultTxQueueSize, 21)); CheckErrorCode(Api.YOGI_GetIntConstant(ref MinRxQueueSize, 22)); CheckErrorCode(Api.YOGI_GetIntConstant(ref MaxRxQueueSize, 23)); CheckErrorCode(Api.YOGI_GetIntConstant(ref DefaultRxQueueSize, 24)); }
public void OperatorPlus_NonZero() { Assert.AreEqual(3000001L, (threeMillion + Duration.Epsilon).ToInt64Nanoseconds(), "3,000,000 + 1"); Assert.AreEqual(0L, (Duration.Epsilon + Duration.FromNanoseconds(-1)).ToInt64Nanoseconds(), "1 + (-1)"); Assert.AreEqual(-49999999L, (negativeFiftyMillion + Duration.Epsilon).ToInt64Nanoseconds(), "-50,000,000 + 1"); }
public void Nanoseconds() { Assert.AreEqual(Duration.FromNanoseconds(2), 2.Nanoseconds()); Assert.AreEqual(Duration.FromNanoseconds(2), 2L.Nanoseconds()); Assert.AreEqual(Duration.FromNanoseconds(2.5), 2.5.Nanoseconds()); }
public void BclCompatibleTick_Zero() { Assert.AreEqual(0, Duration.FromTicks(0).BclCompatibleTicks); Assert.AreEqual(0, Duration.FromNanoseconds(99L).BclCompatibleTicks); Assert.AreEqual(0, Duration.FromNanoseconds(-99L).BclCompatibleTicks); }
public void Int64Conversions(long int64Nanos) { var nanoseconds = Duration.FromNanoseconds(int64Nanos); Assert.AreEqual(int64Nanos, nanoseconds.ToInt64Nanoseconds()); }
/// <inheritdoc cref="Duration.FromNanoseconds(double?)"/> public static Duration?Nanoseconds(this decimal?value) => Duration.FromNanoseconds(value == null ? (double?)null : Convert.ToDouble(value.Value));
public void FromDecimalNanoseconds() { Duration.FromNanoseconds(long.MaxValue + 100M).Consume(); }
void Recompute() { pv.Model.Series.Clear(); var sb = new StringBuilder(); var accelBase = "1-cos(t)"; var accelOverDuration = accelBase.Substitute("t", $"(t/(d/2)*2*pi)"); var accelCoeff = $"s / abs({accelOverDuration.Integrate("t").Substitute("t", "(d/2)")})"; var accel = $"({accelCoeff}) * ({accelOverDuration})"; var accelInt = accel.Integrate("t"); var speed = accelInt; var speedAtHalf = accelInt.Substitute("t", "(d/2)"); var speedInt = speed.Integrate("t"); var posAtZero = speedInt.Substitute("t", 0); var pos = $"({speedInt})-{(posAtZero)}"; var posAtHalf = pos.Substitute("t", "(d/2)"); var targetspeed = $"{pos.ToString()}=x".Substitute("t", "d/2").Solve("s"); var deAccelBase = "cos(t)-1"; var deAccelOverDuration = deAccelBase.Substitute("t", $"(t/(d/2)*2*pi)"); var deAccelCoeff = $"s / abs({deAccelOverDuration.Integrate("t").Substitute("t", "(d/2)")})"; var deAccel = $"({deAccelCoeff})*({deAccelOverDuration})"; var deAccelInt = deAccel.Integrate("t"); var deSpeedAtZero = deAccelInt.Substitute("t", 0); var deSpeedAtHalf = deAccelInt.Substitute("t", "(d/2)"); var deSpeed = $"({deAccelInt})-({deSpeedAtZero})+({speedAtHalf})"; var deSpeedInt = deSpeed.Integrate("t"); var dePosAtZero = deSpeedInt.Substitute("t", 0); var dePos = $"({deSpeedInt})-({dePosAtZero})+({posAtHalf})"; var t = Duration.FromSeconds(0); var t_step = m.Duration / m.RenderPts; var accelDataSet = new List <PlotData>(); var speedDataSet = new List <PlotData>(); var posDataSet = new List <PlotData>(); var deAccelDataSet = new List <PlotData>(); var deSpeedDataSet = new List <PlotData>(); var dePosDataSet = new List <PlotData>(); var accelCompiled = accel .Substitute("s", m.TargetSpeed.RevolutionsPerSecond) .Substitute("d", m.Duration.Seconds) .Compile("t"); var deAccelCompiled = deAccel .Substitute("s", m.TargetSpeed.RevolutionsPerSecond) .Substitute("d", m.Duration.Seconds) .Compile("t"); var speedCompiled = speed .Substitute("s", m.TargetSpeed.RevolutionsPerSecond) .Substitute("d", m.Duration.Seconds) .Compile("t"); var deSpeedCompiled = deSpeed .Substitute("s", m.TargetSpeed.RevolutionsPerSecond) .Substitute("d", m.Duration.Seconds) .Compile("t"); var posCompiled = pos .Substitute("s", m.TargetSpeed.RevolutionsPerSecond) .Substitute("d", m.Duration.Seconds) .Compile("t"); var dePosCompiled = dePos .Substitute("s", m.TargetSpeed.RevolutionsPerSecond) .Substitute("d", m.Duration.Seconds) .Compile("t"); var halfDuration = m.Duration / 2; var timeTol = Duration.FromNanoseconds(1); while (t.LessThanOrEqualsTol(timeTol, m.Duration)) { if (t.LessThanOrEqualsTol(timeTol, halfDuration)) { accelDataSet.Add(new PlotData( t.Seconds, double.Parse(accelCompiled.Substitute(t.Seconds).Real.ToString()))); speedDataSet.Add(new PlotData( t.Seconds, double.Parse(speedCompiled.Substitute(t.Seconds).Real.ToString()))); posDataSet.Add(new PlotData( t.Seconds, double.Parse(posCompiled.Substitute(t.Seconds).Real.ToString()))); } if (t.GreatThanOrEqualsTol(timeTol, halfDuration)) { deAccelDataSet.Add(new PlotData( t.Seconds, double.Parse(deAccelCompiled.Substitute((t - halfDuration).Seconds).Real.ToString()))); deSpeedDataSet.Add(new PlotData( t.Seconds, double.Parse(deSpeedCompiled.Substitute((t - halfDuration).Seconds).Real.ToString()))); dePosDataSet.Add(new PlotData( t.Seconds, double.Parse(dePosCompiled.Substitute((t - halfDuration).Seconds).Real.ToString()))); } t += t_step; } var accelSerie = new OxyPlot.Series.LineSeries() { Title = "Accel (rps2)", DataFieldX = "x", DataFieldY = "y", ItemsSource = accelDataSet, Color = OxyColor.Parse("#9ccc65") }; pv.Model.Series.Add(accelSerie); var deAccelSerie = new OxyPlot.Series.LineSeries() { Title = "DeAccel (rps2)", DataFieldX = "x", DataFieldY = "y", ItemsSource = deAccelDataSet, Color = OxyColor.Parse("#6b9b37") }; pv.Model.Series.Add(deAccelSerie); var speedSerie = new OxyPlot.Series.LineSeries() { Title = "Speed (rps)", DataFieldX = "x", DataFieldY = "y", ItemsSource = speedDataSet, Color = OxyColor.Parse("#42a5f5") }; pv.Model.Series.Add(speedSerie); var deSpeedSerie = new OxyPlot.Series.LineSeries() { Title = "DeSpeed (rps)", DataFieldX = "x", DataFieldY = "y", ItemsSource = deSpeedDataSet, Color = OxyColor.Parse("#0077c2") }; pv.Model.Series.Add(deSpeedSerie); var posSerie = new OxyPlot.Series.LineSeries() { Title = "Pos (rev)", DataFieldX = "x", DataFieldY = "y", ItemsSource = posDataSet, Color = OxyColor.Parse("#ef5350") }; pv.Model.Series.Add(posSerie); var dePosSerie = new OxyPlot.Series.LineSeries() { Title = "DePos (rev)", DataFieldX = "x", DataFieldY = "y", ItemsSource = dePosDataSet, Color = OxyColor.Parse("#b61827") }; pv.Model.Series.Add(dePosSerie); pv.Model.Annotations.Clear(); var note = new OxyPlot.Annotations.ArrowAnnotation { StartPoint = new DataPoint(m.Duration.Seconds / 2, m.TargetSpeed.RevolutionsPerSecond * 1.3), EndPoint = new DataPoint(m.Duration.Seconds / 2, m.TargetSpeed.RevolutionsPerSecond), Text = "targetspeed" }; pv.Model.Annotations.Add(note); pv.ResetAllAxes(); foreach (var x in pv.Model.Axes) { x.MajorGridlineStyle = LineStyle.Dot; } pv.InvalidatePlot(); tboxLog.Text = sb.ToString(); }
public void Ticks_Zero() { Assert.AreEqual(0, Duration.FromTicks(0).Ticks); Assert.AreEqual(0, Duration.FromNanoseconds(99L).Ticks); Assert.AreEqual(0, Duration.FromNanoseconds(-99L).Ticks); }
public Duration FromBigIntegerNanoseconds() { return(Duration.FromNanoseconds(long.MaxValue + (BigInteger)100)); }
/// <summary> /// Advances the clock by the given number of nanoseconds. /// </summary> /// <param name="nanoseconds">The number of nanoseconds to advance the clock by (or if negative, the number to move it back /// by).</param> public void AdvanceNanoseconds(long nanoseconds) { Advance(Duration.FromNanoseconds(nanoseconds)); }
public Duration FromInt64Nanoseconds() { return(Duration.FromNanoseconds(int.MaxValue + 1L)); }
public static Duration PlusNanoseconds(this Duration duration, double nanoseconds) { return(duration.Plus(Duration.FromNanoseconds(nanoseconds))); }
public static Duration PlusMicroseconds(this Duration duration, double microseconds) { return(duration.Plus(Duration.FromNanoseconds(microseconds * 1000))); }
/// <inheritdoc cref="Duration.FromNanoseconds(double?)"/> public static Duration?Nanoseconds(this float?value) => Duration.FromNanoseconds(value);
public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner) { var nanoseconds = (long?)NHibernateUtil.Int64.NullSafeGet(rs, names[0], session); return(nanoseconds == null ? (object)null : Duration.FromNanoseconds(nanoseconds.Value)); }
/// <inheritdoc cref="Duration.FromNanoseconds(double)"/> public static Duration Nanoseconds(this decimal value) => Duration.FromNanoseconds(Convert.ToDouble(value));
public void IntervalAsDuration() { using var conn = OpenConnection(); using var cmd = new NpgsqlCommand("SELECT @p1, @p2", conn); // PG has microsecond precision, so sub-microsecond values are stripped var expected = Duration.FromDays(5) + Duration.FromMinutes(4) + Duration.FromSeconds(3) + Duration.FromMilliseconds(2) + Duration.FromNanoseconds(1500); cmd.Parameters.Add(new NpgsqlParameter("p1", NpgsqlDbType.Interval) { Value = expected }); cmd.Parameters.AddWithValue("p2", expected); using var reader = cmd.ExecuteReader(); reader.Read(); for (var i = 0; i < 2; i++) { Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(Period))); Assert.That(reader.GetFieldValue <Duration>(i), Is.EqualTo(expected - Duration.FromNanoseconds(500))); } }
public void FromInt64Nanoseconds() { Duration.FromNanoseconds(int.MaxValue + 1L).Consume(); }
public void NumberToNanosecondsTest() => Assert.Equal(Duration.FromNanoseconds(2), 2.Nanoseconds());
/// <inheritdoc cref="Duration.FromNanoseconds(UnitsNet.QuantityValue)" /> public static Duration Nanoseconds <T>(this T value) => Duration.FromNanoseconds(Convert.ToDouble(value));
/// <summary> /// Returns a <see cref="Duration"/> representing the given number of units. /// </summary> internal Duration ToDuration(long units) => units >= -maxLongUnits && units <= maxLongUnits ? Duration.FromNanoseconds(units *unitNanoseconds) : Duration.FromNanoseconds(units * (decimal)unitNanoseconds);
public void BinarySerialization() { TestHelper.AssertBinaryRoundtrip(Duration.FromNanoseconds(123456789L)); }
public static Duration?Nanoseconds <T>(this T?value) where T : struct => Duration.FromNanoseconds(value == null ? (double?)null : Convert.ToDouble(value.Value));
public void OperatorMultiplication_MethodEquivalents() { Assert.AreEqual(Duration.FromNanoseconds(-50000) * 1000, Duration.Multiply(Duration.FromNanoseconds(-50000), 1000)); Assert.AreEqual(1000 * Duration.FromNanoseconds(-50000), Duration.Multiply(1000, Duration.FromNanoseconds(-50000))); Assert.AreEqual(Duration.FromNanoseconds(-50000) * 1000d, Duration.Multiply(Duration.FromNanoseconds(-50000), 1000d)); }
/// <inheritdoc cref="Duration.FromNanoseconds(double)"/> public static Duration Nanoseconds(this long value) => Duration.FromNanoseconds(value);
// value is the number of microseconds from 2000-01-01T00:00:00. // Unfortunately NodaTime doesn't have Duration.FromMicroseconds(), so we decompose into milliseconds // and nanoseconds internal static Instant Decode(long value) => Instant2000 + Duration.FromMilliseconds(value / 1000) + Duration.FromNanoseconds(value % 1000 * 1000);
/// <inheritdoc cref="Duration.FromNanoseconds(double?)"/> public static Duration?Nanoseconds(this double?value) => Duration.FromNanoseconds(value);
public void OperatorMinusInstant_NonZero() { Assert.AreEqual(2999999L, (threeMillion - one).ToInt64Nanoseconds(), "3,000,000 - 1"); Assert.AreEqual(2L, (one - Instant.FromUntrustedDuration(Duration.FromNanoseconds(-1L))).ToInt64Nanoseconds(), "1 - (-1)"); Assert.AreEqual(-50000001L, (negativeFiftyMillion - one).ToInt64Nanoseconds(), "-50,000,000 - 1"); }
protected override Duration Unwrap(long value) => Duration.FromNanoseconds(value);