Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using ANTReporting;
- namespace FireAnt
- {
- class Program
- {
- static bool filterHR = true;
- static bool filterCadence = true;//true;
- const int readingsPerSecond = 10;
- const int MAX_ZERO_HRS_TO_OMIT = readingsPerSecond * 3;
- static int zeroHRCount = 0;
- private static int zeroCadenceCount = 0;
- private static int MAX_RPM_ZEROS_TO_OMIT = readingsPerSecond * 3;
- static void Main(string[] args)
- {
- try
- {
- if (!File.Exists("ANTDevicesDescription.txt"))
- File.WriteAllText("ANTDevicesDescription.txt", Resources.ANTDevicesDescription);
- int numSensorsForCadence = 2;
- float minCadence = 10f;
- if (args.Length >= 1)
- numSensorsForCadence = int.Parse(args[1]);
- if (args.Length >= 2)
- minCadence = float.Parse(args[2]);
- ANTReporter reporter = null;
- try
- {
- reporter = new ANTReporter(numSensorsForCadence, minCadence);
- }
- catch(Exception e)
- {
- if (reporter != null)
- reporter.CloseANTReporter();
- Console.WriteLine(e.Message+ "\n"+e.StackTrace);
- Console.ReadLine();
- return;
- }
- Stopwatch sw = new Stopwatch();
- sw.Start();
- float hr = 0;
- float hrMonitorDeviceNumber = 0;
- float cadenceSensorDeviceNumber = 0;
- float lastValidHR = 0;
- float lastValidCadence = 0;
- float cadence = 0;
- using (var logWriter = File.CreateText("FireAnt.log"))
- {
- while (true)
- {
- hr = reporter.IsHeartRateMonitorConnected() ? reporter.GetHeartRate() : 0;
- hrMonitorDeviceNumber = reporter.GetHRDeviceNumber();
- if (reporter.IsBikeConnected())
- {
- cadence = reporter.GetBikeCadence();
- lastValidCadence = cadence;
- zeroCadenceCount = 0;
- }
- else
- {
- //Console.Write("####### ");
- //-----------------------------------------------
- // FILTERING CADENCE
- if (filterCadence)
- {
- zeroCadenceCount++;
- if (zeroCadenceCount > MAX_RPM_ZEROS_TO_OMIT)
- {
- lastValidCadence = 0;
- }
- cadence = lastValidCadence;
- }
- else
- cadence = 0;
- }
- cadenceSensorDeviceNumber = reporter.GetCadenceSensorDeviceNumber();
- var s = hr + " " + cadence;
- //Main Console Write
- Console.WriteLine("{0} {1}", hr, reporter.SmoothCadence);
- //Console.Write(s+" "); //Non filtered
- //-----------------------------------------------
- // FILTERING HEART RATE
- if (filterHR )
- {
- if (hr != 0)
- {
- lastValidHR = hr;
- zeroHRCount = 0;
- }
- else
- {
- zeroHRCount++;
- if (zeroHRCount > MAX_ZERO_HRS_TO_OMIT)
- {
- lastValidHR = 0;
- }
- }
- hr = lastValidHR;
- }
- //-----------------------------------------------
- s = Math.Round(hr) + " " + Math.Round(cadence);
- //Console.WriteLine(s);
- //Console.WriteLine(s + " (hrmId: " + hrMonitorDeviceNumber + ", bikeId: " + cadenceSensorDeviceNumber + ")"); //Filtered
- if (sw.ElapsedMilliseconds >= 1000)
- {
- logWriter.WriteLine(s);
- logWriter.Flush();
- sw.Reset();
- sw.Start();
- }
- Thread.Sleep(1000 / readingsPerSecond);
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement