Commit aeca1a4e authored by Vincent's avatar Vincent 💩

Working on new diveReader

parent 19e90fbd
using DiveLogUploader;
using LibDiveComputer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static LibDiveComputer.Context;
public class ProgressEventArgs : EventArgs {
public int Maximum;
public int Current;
public class DeviceEventArgs : EventArgs {
public Device Device;
public Context Context;
}
public class ProgressEventArgs : DeviceEventArgs {
public uint Maximum;
public uint Current;
public float Ratio { get { return (float)Current / Maximum; } }
public int Precent { get { return (int)Math.Round(Ratio * 100); } }
}
public class DeviceInfoEventArgs : EventArgs {
public class DeviceInfoEventArgs : DeviceEventArgs {
public uint Model;
public uint Firmware;
public uint Serial;
}
public class DeviceClockEventArgs : EventArgs {
public class DeviceClockEventArgs : DeviceEventArgs {
public uint DevTime;
public long SysTime;
}
public class DiveEventArgs : EventArgs {
public class DiveEventArgs : DeviceEventArgs {
public Dive Dive;
}
public class CompleteEventArgs : EventArgs {
public class CompleteEventArgs : DeviceEventArgs {
}
public class StateChangedEventArgs : DeviceEventArgs {
public ReadingState State;
}
public class LogEntryEventArgs : DeviceEventArgs {
public dc_loglevel_t Loglevel;
public string File;
public uint Line;
public string Function;
public string Message;
}
public enum ReadingState {
Started,
Waiting,
Reading,
Complete,
}
namespace DiveLogUploader {
......@@ -36,16 +62,101 @@ namespace DiveLogUploader {
public delegate void ClockInfoHandle(object source, DeviceClockEventArgs args);
public delegate void DiveHandle(object source, DiveEventArgs args);
public delegate void CompleteHandle(object source, CompleteEventArgs args);
public delegate void LogMessageHandle(object source, LogEntryEventArgs args);
public delegate void StateChangeHandle(object source, StateChangedEventArgs args);
public class DiveReader {
public const dc_loglevel_t DefaultLogLevel = dc_loglevel_t.DC_LOGLEVEL_ERROR;
public event ProgressHandle OnProgress;
public event DeviceInfoHandle OnDeviceInfo;
public event ClockInfoHandle OnDeviceClock;
public event DiveHandle OnDive;
public event CompleteHandle OnComplete;
public event LogMessageHandle OnLogMessage;
public event StateChangeHandle OnStateChange;
public dc_loglevel_t Loglevel = DefaultLogLevel;
public string SerialPort;
public Descriptor deviceDescriptor;
private Context CreateContext() {
var ctx = new Context();
ctx.logfunc = (IntPtr context, dc_loglevel_t loglevel, string file, uint line, string function, string message, IntPtr userdata) => {
OnLogMessage?.Invoke(this, new LogEntryEventArgs {
Loglevel = loglevel,
File = file,
Function = function,
Line = line,
Message = message
});
};
ctx.loglevel = Loglevel;
return ctx;
}
public string Fingerprint = null;
public void Read() {
var ctx = CreateContext();
var device = new Device(ctx, deviceDescriptor, SerialPort);
device.OnWaiting += () => {
OnStateChange?.Invoke(this, new StateChangedEventArgs {
Context = ctx,
Device = device,
State = ReadingState.Waiting,
});
};
device.OnDeviceInfo += (devInfo) => {
OnDeviceInfo?.Invoke(this, new DeviceInfoEventArgs {
Context = ctx,
Device = device,
Firmware = devInfo.firmware,
Model = devInfo.model,
Serial = devInfo.serial,
});
};
device.OnClock += (clock) => {
OnStateChange?.Invoke(this, new StateChangedEventArgs {
Context = ctx,
Device = device,
State = ReadingState.Reading,
});
OnDeviceClock?.Invoke(this, new DeviceClockEventArgs {
Context = ctx,
Device = device,
DevTime = clock.devtime,
SysTime = clock.systime
});
};
device.OnProgess += (prog) => {
OnProgress?.Invoke(this, new ProgressEventArgs {
Context = ctx,
Device = device,
Current = prog.current,
Maximum = prog.maximum
});
};
device.OnDive += (data, size, fingerprint, fsize, udata) => {
OnDive?.Invoke(this, new DiveEventArgs {
Dive = Dive.Parse(device, data, fingerprint)
});
};
OnStateChange?.Invoke(this, new StateChangedEventArgs {
Context = ctx,
Device = device,
State = ReadingState.Started,
});
device.Start();
OnComplete?.Invoke(this, new CompleteEventArgs {
Context = ctx,
Device = device,
});
OnStateChange?.Invoke(this, new StateChangedEventArgs {
Context = ctx,
Device = device,
State = ReadingState.Complete,
});
}
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -117,13 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="DivecomputerWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="SaveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>185, 17</value>
</metadata>
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>316, 17</value>
<value>18, 15</value>
</metadata>
</root>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment