public static async Task Aggregator( FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { DTOs.IsPrimeRequest request = new DTOs.IsPrimeRequest(); FPGA.Signal <bool> deserialized = new FPGA.Signal <bool>(); Drivers.JSON.DeserializeFromUART <DTOs.IsPrimeRequest>(ref request, RXD, deserialized); Sequential handler = () => { bool result = false; uint source = request.value; // TODO: member access is not supported in function call SequentialMath.IsPrime((uint)source, out result); DTOs.IsPrimeResponse response = new DTOs.IsPrimeResponse(); response.value = request.value; response.result = (byte)((result == true) ? 1 : 0); Drivers.JSON.SerializeToUART <DTOs.IsPrimeResponse>(ref response, TXD); }; FPGA.Config.OnSignal(deserialized, handler); }
public static async Task Aggregator( FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { Sequential handler = () => { while (true) { byte start = UART.Read(115200, RXD); ulong result = 0; SequentialMath.Fibonacci(start, out result); for (byte i = 0; i < 8; i++) { byte data = (byte)result; UART.Write(115200, data, TXD); result = result >> 8; } } }; const bool trigger = true; FPGA.Config.OnSignal(trigger, handler); }
public static float DeltaVInclinationOrbit(float mass, float innerRadius, float outerRadius, float inclination) { var vApogee = SequentialMath.Sqrt(2 * FPGAOrbitalCalcConstants.G * mass * (innerRadius / outerRadius) * (1 / (innerRadius + outerRadius))); var vOrbital = VOrbit(mass, outerRadius); var cosInc = FPGATrigonometry.Cos(inclination); var deltaV = SequentialMath.Sqrt(vApogee * vApogee + vOrbital * vOrbital - 2 * vApogee * vOrbital * cosInc); return(deltaV); }
public static float DeltaVInclinationOrbitOptimized(float mass, float innerRadius, float outerRadius, float inclination) { var vApogeeSquared = 2 * FPGAOrbitalCalcConstants.G * mass * (innerRadius / outerRadius) * (1 / (innerRadius + outerRadius)); var vOrbitalSquared = VOrbitSquared(mass, outerRadius); var cosInc = FPGATrigonometry.Cos(inclination); var vCos = SequentialMath.Sqrt(vApogeeSquared * vOrbitalSquared * cosInc * cosInc); var deltaV = SequentialMath.Sqrt(vApogeeSquared + vOrbitalSquared - 2 * vCos); return(deltaV); }
public static void Average(ushort[] buff, out ushort average) { uint sum = 0; for (int i = 0; i < buff.Length; i++) { ushort tmp = 0; tmp = buff[i]; sum += tmp; } uint result = 0, remainder = 0; // TODO: length accessor in cast //uint denominator = (uint)buff.Length; SequentialMath.DivideUnsigned <uint>(sum, 10, out result, out remainder); average = (ushort)result; }
public static async Task Aggregator( FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { Sequential handler = () => { FPU.FPUScopeNoSync(); while (true) { UART.ReadFloat(115200, RXD, out float source); var result = SequentialMath.InitialApproximation(source); UART.WriteFloat(115200, result, TXD); } }; FPGA.Config.OnStartup(handler); }
public static async Task Aggregator( FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { Sequential handler = () => { while (true) { byte start = UART.Read(115200, RXD); for (uint counter = 0; counter < 100; counter++) { ulong fib = 0; SequentialMath.Fibonacci(counter, out fib); if (fib > uint.MaxValue) { break; } bool isPrime = false; SequentialMath.IsPrime((uint)fib, out isPrime); if (isPrime) { for (byte i = 0; i < 4; i++) { byte data = (byte)fib; UART.Write(115200, data, TXD); fib = fib >> 8; } } } } }; const bool trigger = true; FPGA.Config.OnSignal(trigger, handler); }
public static async Task Aggregator( FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { DTOs.DividerRequest request = new DTOs.DividerRequest(); FPGA.Signal <bool> deserialized = new FPGA.Signal <bool>(); Drivers.JSON.DeserializeFromUART <DTOs.DividerRequest>(ref request, RXD, deserialized); Sequential processingHandler = () => { ulong result, remainder; SequentialMath.DivideUnsigned <ulong>(request.Numerator, request.Denominator, out result, out remainder); DTOs.DividerResponse response = new DTOs.DividerResponse(); response.Result = result; response.Remainder = remainder; Drivers.JSON.SerializeToUART <DTOs.DividerResponse>(ref response, TXD); }; FPGA.Config.OnSignal(deserialized, processingHandler); }
public static float VEsc(float mass, float radius) { return(SequentialMath.Sqrt(FPGAOrbitalCalcConstants.TwoG * mass / radius)); }
static float DeltaVTerm2(float innerRadius, float outerRadius) { return(SequentialMath.Sqrt(2 * outerRadius / (innerRadius + outerRadius))); }
static float DeltaVTerm1(float mass, float radius) { return(SequentialMath.Sqrt(FPGAOrbitalCalcConstants.G * mass / radius)); }
public static float[] FactorialArray() { return(Enumerable.Range(0, 10).Select(i => (float)SequentialMath.Factorial(i)).ToArray()); }