using iq2dev.com.IQCommLib;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iq2dev.com.iqCommLib.EMC;
using iq2dev.com.IQCommLib.Example;
using System.Threading;

namespace iqCommLib.Example
{
    static internal class EmcTesterExample
    {
		public static void EmcDeviceTester_Example(ProtocolCommunicator protocolCommunicator)
		{
			Stopwatch timer = new Stopwatch();
			timer.Start();

			EmcDeviceTester.StartAsDeviceTester(protocolCommunicator, 600, 10);
			EmcDeviceTester.ResetCounters(protocolCommunicator);

			while (timer.ElapsedMilliseconds < 10000)
			{
				var counters = EmcDeviceTester.ReadCounters(protocolCommunicator);
				Program.LoggingEvent($"Checksum error counter : {counters.ChecksumErrorCounter}");
				Program.LoggingEvent($"Invalid error counter : {counters.InvalidResponseCounter}");
				Program.LoggingEvent($"No response error counter : {counters.NoResponseCounter}");
				Program.LoggingEvent($"M-SEQ counter : {counters.MseqCounter}");
				Thread.Sleep(1000);
			}

			//it is required to reboot iqInterface after using EMC test
			protocolCommunicator.writeIQCommPar(IQPar.IQParRebootDevice, new List<byte>() { 0 });

			timer.Stop();
			Program.LoggingEvent($"Time: {timer.Elapsed.TotalSeconds} seconds");
		}
	}
}
