using Aurora.Api; using Aurora.Api.Devices; using Aurora.Util.HislogPlus; using Hermes; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using System.Windows.Threading; using static AuroraHeightSensor.HeightSensor; namespace AuroraHeightSensor { class HeightSensorMock : IHeightSensor { Logger Log = new Logger("HeightSensorMock"); bool _IsConnected; private double _Min; private double _Max; public bool CheckConnected() { return _IsConnected; } //public int Connect(IConnConfig config) public int Activate(IConnConfig config) { _IsConnected = true; return E1.OK; } //public int Disconnect() public int Deactivate() { _IsConnected = false; return E1.OK; } public void SetRange(double min, double max) { _Min = min; _Max = max; } public int MeasureAll(out List SensorValue) { SensorValue = null; return E1.OK; } public int Measure(eChannel channel, out double value) { var rng = new Random(); value = _Min + rng.NextDouble() * (_Max - _Min); return E1.OK; } public int SetZero(eChannel channel, bool isSet = true) { return E1.OK; } public int SetLed(bool isOn) { return E1.OK; } public int SetZeroShift(eChannel channel) { return E1.OK; } public int SetZeroShiftReset(eChannel channel) { return E1.OK; } public int Reset(eChannel channel) { return E1.OK; } DispatcherTimer _TestTimer; bool _IsAutoTransmitOn = false; ICommand OnMeasured = null; public int StartStopAutoTransmit(bool isOn, ICommand callback) { if (isOn) { // Test Code _IsAutoTransmitOn = true; OnMeasured = callback; Log.E("Simul Start Auto Transmit"); if (_TestTimer == null) { _TestTimer = new DispatcherTimer(); _TestTimer.Tick += GenerateDummyResult; _TestTimer.Interval = TimeSpan.FromMilliseconds(1000); } if (_TestTimer != null) { _TestTimer.Start(); } } else { _IsAutoTransmitOn = false; if (_TestTimer != null) { _TestTimer.Stop(); } } return E1.OK; } public void GenerateDummyResult(object sender, EventArgs e) { if (_IsAutoTransmitOn) { //Log.I("OnReceive : " + args.ReceiveData.ToString()); // Handling Data //var parsingData = Parse(eCommand.ND, args.ReceiveData, out double value); //var test = BitConverter.ToString(args.ReceiveData).Replace("-", ""); //var test = Encoding.Default.GetString(args.ReceiveData).Skip(8 + 4).Take(4).ToString(); double value = new Random(DateTime.Now.Millisecond).NextDouble(); Log.V("Test Value : " + value.ToString("F3")); OnMeasured.Execute(value); } } } }