Skip to content

Commit c189b9e

Browse files
committed
DFLogBuffer: rename
LogBrowse: support instances
1 parent 0e42938 commit c189b9e

24 files changed

+278
-132
lines changed

Controls/Loading.cs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.ComponentModel;
33
using System.Reflection;
4+
using System.Threading;
45
using System.Windows.Forms;
56
using MissionPlanner.Utilities;
67
using log4net;
@@ -38,44 +39,53 @@ public Loading()
3839
{
3940
if (Instance.IsHandleCreated)
4041
{
41-
42-
MainV2.instance.Invoke((MethodInvoker) delegate { ((Form) Instance).Close(); });
43-
44-
Instance = null;
42+
MainV2.instance.BeginInvoke((MethodInvoker) delegate
43+
{
44+
if (Instance == null)
45+
return;
46+
uiSemaphoreSlim.Wait();
47+
try
48+
{
49+
((Form) Instance).Close();
50+
}
51+
finally
52+
{
53+
uiSemaphoreSlim.Release();
54+
}
55+
Instance = null;
56+
});
4557
}
4658
}
4759
}
4860
}
4961
}
5062

63+
static SemaphoreSlim uiSemaphoreSlim = new SemaphoreSlim(1, 1);
64+
5165
/// <summary>
5266
/// Create a new dialog or use an existing one if its still valid
5367
/// </summary>
5468
/// <param name="Text"></param>
5569
/// <returns></returns>
5670
public static void ShowLoading(string Text, IWin32Window owner = null)
5771
{
58-
//if (MainV2.MONO)
59-
{
60-
log.Info(Text);
61-
//return;
62-
}
63-
64-
// ensure we only have one instance at a time
65-
lock (locker)
72+
log.Info(Text);
73+
// create form on ui thread
74+
MainV2.instance.BeginInvokeIfRequired((Action) delegate
6675
{
67-
if (Instance != null && !Instance.IsDisposed)
76+
uiSemaphoreSlim.Wait();
77+
try
6878
{
69-
Instance.Text = Text;
70-
return;
71-
}
79+
if (Instance != null && !Instance.IsDisposed)
80+
{
81+
Instance.Text = Text;
82+
return;
83+
}
84+
85+
log.Info("Create Instance");
7286

73-
log.Info("Create Instance");
74-
// create form on ui thread
75-
MainV2.instance.Invoke((MethodInvoker) delegate
76-
{
7787
Loading frm = new Loading();
78-
if(owner == null)
88+
if (owner == null)
7989
frm.TopMost = true;
8090
frm.StartPosition = FormStartPosition.CenterParent;
8191
frm.Closing += Frm_Closing;
@@ -88,8 +98,12 @@ public static void ShowLoading(string Text, IWin32Window owner = null)
8898
ThemeManager.ApplyThemeTo(frm);
8999
frm.Show(owner);
90100
frm.Focus();
91-
});
92-
}
101+
}
102+
finally
103+
{
104+
uiSemaphoreSlim.Release();
105+
}
106+
});
93107
}
94108

95109
private static void Frm_Closing(object sender, CancelEventArgs e)

Controls/fftui.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private void myButton1_Click(object sender, EventArgs e)
149149
if (!File.Exists(ofd.FileName))
150150
return;
151151

152-
var file = new CollectionBuffer(File.OpenRead(ofd.FileName));
152+
var file = new DFLogBuffer(File.OpenRead(ofd.FileName));
153153

154154
int bins = (int) NUM_bins.Value;
155155

@@ -337,7 +337,7 @@ private void BUT_log2_Click(object sender, EventArgs e)
337337
if (!File.Exists(ofd.FileName))
338338
return;
339339

340-
var file = new CollectionBuffer(File.OpenRead(ofd.FileName));
340+
var file = new DFLogBuffer(File.OpenRead(ofd.FileName));
341341

342342
int bins = (int) NUM_bins.Value;
343343

@@ -549,7 +549,7 @@ private void but_fftimu_Click(object sender, EventArgs e)
549549
if (!File.Exists(ofd.FileName))
550550
return;
551551

552-
var file = new CollectionBuffer(File.OpenRead(ofd.FileName));
552+
var file = new DFLogBuffer(File.OpenRead(ofd.FileName));
553553

554554
int bins = (int)NUM_bins.Value;
555555

@@ -735,7 +735,7 @@ private void but_ISBH_Click(object sender, EventArgs e)
735735
if (!File.Exists(ofd.FileName))
736736
return;
737737

738-
var file = new CollectionBuffer(File.OpenRead(ofd.FileName));
738+
var file = new DFLogBuffer(File.OpenRead(ofd.FileName));
739739

740740
int bins = (int)NUM_bins.Value;
741741

ExtLibs/Utilities/BinaryLog.cs

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ object[] logEntryObjects(byte packettype, Stream br)
442442
}
443443
}
444444
}
445-
445+
446446
private object[] ProcessMessageObjects(byte[] message, string name, string format)
447447
{
448448
char[] form = format.ToCharArray();
@@ -548,25 +548,55 @@ private object[] ProcessMessageObjects(byte[] message, string name, string forma
548548
return answer.ToArray();
549549
}
550550

551+
public enum TypeSize
552+
{
553+
a = 2*32,
554+
b = 1,
555+
B = 1,
556+
c = 2,
557+
C = 2,
558+
d = 8,
559+
e = 4,
560+
E = 4,
561+
f = 4,
562+
h = 2,
563+
H = 2,
564+
i = 4,
565+
I = 4,
566+
L = 4,
567+
M = 1,
568+
N = 16,
569+
n = 4,
570+
q = 8,
571+
Q = 8,
572+
Z = 64,
573+
}
574+
551575
private log_format_cache[] packettypecache = new log_format_cache[256];
552576

553-
/*
554-
105  +Format characters in the format string for binary log messages
555-
106  + b : int8_t
556-
107  + B : uint8_t
557-
108  + h : int16_t
558-
109  + H : uint16_t
559-
110  + i : int32_t
560-
111  + I : uint32_t
561-
112  + f : float
562-
* d : double
563-
113  + N : char[16]
564-
114  + c : int16_t * 100
565-
115  + C : uint16_t * 100
566-
116  + e : int32_t * 100
567-
117  + E : uint32_t * 100
568-
118  + L : uint32_t latitude/longitude
569-
a : short[32]
570-
119  + */
577+
/*
578+
https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Logger/LogStructure.h
579+
Format characters in the format string for binary log messages
580+
a : int16_t[32]
581+
b : int8_t
582+
B : uint8_t
583+
c : int16_t * 100
584+
C : uint16_t * 100
585+
d : double
586+
e : int32_t * 100
587+
E : uint32_t * 100
588+
f : float
589+
h : int16_t
590+
H : uint16_t
591+
i : int32_t
592+
I : uint32_t
593+
L : int32_t latitude/longitude
594+
M : uint8_t flight mode
595+
N : char[16]
596+
n : char[4]
597+
q : int64_t
598+
Q : uint64_t
599+
Z : char[64]
600+
*/
571601
}
572602
}

ExtLibs/Utilities/DFLog.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace MissionPlanner.Utilities
1515
/// </summary>
1616
public class DFLog
1717
{
18+
internal readonly DFLogBuffer _dfLogBuffer;
1819
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
1920

2021
public struct Label
@@ -49,6 +50,22 @@ public DateTime time
4950
}
5051
}
5152

53+
public string instance
54+
{
55+
get
56+
{
57+
var typeno = parent.logformat[msgtype].Id;
58+
59+
if (!parent._dfLogBuffer.InstanceType.ContainsKey(typeno))
60+
return "";
61+
62+
var unittypes = parent._dfLogBuffer.FMTU[typeno].Item1;
63+
64+
int colinst = unittypes.IndexOf("#") + 1;
65+
return raw[colinst].ToString();
66+
}
67+
}
68+
5269
string[] _items;
5370
public string[] items
5471
{
@@ -418,6 +435,11 @@ public List<DFItem> ReadLog(string fn)
418435

419436
long msoffset = 0;
420437

438+
public DFLog(DFLogBuffer dfLogBuffer)
439+
{
440+
_dfLogBuffer = dfLogBuffer;
441+
}
442+
421443
public List<DFItem> ReadLog(Stream fn)
422444
{
423445
Clear();
@@ -648,7 +670,7 @@ public int FindMessageOffset(string linetype, string find)
648670
return -1;
649671
}
650672

651-
public long GetLineNoFromTime(CollectionBuffer logdata, DateTime p1)
673+
public long GetLineNoFromTime(DFLogBuffer logdata, DateTime p1)
652674
{
653675
DateTime last = DateTime.MaxValue;
654676

ExtLibs/Utilities/CollectionBuffer.cs renamed to ExtLibs/Utilities/DFLogBuffer.cs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,25 @@
99

1010
namespace MissionPlanner.Utilities
1111
{
12-
public class CollectionBuffer : IEnumerable<String>, IDisposable
12+
public class DFLogBuffer : IEnumerable<String>, IDisposable
1313
{
1414
// used for binary log line conversion
1515
BinaryLog binlog = new BinaryLog();
1616

1717
// used for fmt messages
18-
public DFLog dflog { get; } = new DFLog();
18+
public DFLog dflog { get; }
1919

2020
Stream basestream;
2121
private int _count;
2222
List<uint> linestartoffset = new List<uint>();
2323

24+
/// <summary>
25+
/// Type and offsets
26+
/// </summary>
2427
List<uint>[] messageindex = new List<uint>[256];
28+
/// <summary>
29+
/// Type and line numbers
30+
/// </summary>
2531
List<uint>[] messageindexline = new List<uint>[256];
2632

2733
bool binary = false;
@@ -31,8 +37,9 @@ public class CollectionBuffer : IEnumerable<String>, IDisposable
3137
int indexcachelineno = -1;
3238
String currentindexcache = null;
3339

34-
public CollectionBuffer(Stream instream)
40+
public DFLogBuffer(Stream instream)
3541
{
42+
dflog = new DFLog(this);
3643
for (int a = 0; a < messageindex.Length; a++)
3744
{
3845
messageindex[a] = new List<uint>();
@@ -45,7 +52,7 @@ public CollectionBuffer(Stream instream)
4552
}
4653
else
4754
{
48-
Console.WriteLine("CollectionBuffer: not seekable - copying to memorystream");
55+
Console.WriteLine("DFLogBuffer: not seekable - copying to memorystream");
4956
basestream = new MemoryStream((int)instream.Length);
5057
instream.CopyTo(basestream);
5158
basestream.Position = 0;
@@ -66,7 +73,7 @@ public CollectionBuffer(Stream instream)
6673
basestream.Position = 0;
6774
DateTime start = DateTime.Now;
6875
setlinecount();
69-
Console.WriteLine("CollectionBuffer-linecount: " + Count + " time(ms): " + (DateTime.Now - start).TotalMilliseconds);
76+
Console.WriteLine("DFLogBuffer-linecount: " + Count + " time(ms): " + (DateTime.Now - start).TotalMilliseconds);
7077
basestream.Position = 0;
7178
}
7279

@@ -164,7 +171,7 @@ void setlinecount()
164171
{
165172
try
166173
{
167-
FMT[int.Parse(item["Type"])] = new Tuple<int, string, string, string>(
174+
FMT[int.Parse(item["Type"])] = (
168175
int.Parse(item["Length"].Trim()),
169176
item["Name"].Trim(),
170177
item["Format"].Trim(),
@@ -181,10 +188,32 @@ void setlinecount()
181188
{
182189
FMTU[int.Parse(item["FmtType"])] =
183190
new Tuple<string, string>(item["UnitIds"].Trim(), item["MultIds"].Trim());
191+
192+
if (item["UnitIds"].Trim().Contains("#"))
193+
{
194+
InstanceType[int.Parse(item["FmtType"])] =
195+
(item["UnitIds"].Trim().IndexOf("#"), new List<string>());
196+
}
184197
}
185198
catch { }
186199
}
187200

201+
foreach (var b in InstanceType)
202+
{
203+
int a = 0;
204+
foreach (var item in GetEnumeratorType(FMT[b.Key].name))
205+
{
206+
var instancevalue = item.raw[b.Value.index + 1].ToString();
207+
208+
if (!b.Value.value.Contains(instancevalue))
209+
b.Value.value.Add(instancevalue);
210+
211+
if (a > 2000)
212+
break;
213+
a++;
214+
}
215+
}
216+
188217
foreach (var item in GetEnumeratorType("UNIT"))
189218
{
190219
try
@@ -280,8 +309,10 @@ private void BuildUnitMultiList()
280309
}
281310

282311
public List<Tuple<string,string,string,double>> UnitMultiList = new List<Tuple<string, string, string, double>>();
312+
public Dictionary<int, (int index, List<string> value)> InstanceType = new Dictionary<int, (int index, List<string> value)>();
283313

284-
public Dictionary<int, Tuple<int, string, string, string>> FMT { get; set; } = new Dictionary<int, Tuple<int, string, string, string>>();
314+
public Dictionary<int, (int length, string name, string format, string columns)> FMT { get; set; } =
315+
new Dictionary<int, (int, string, string, string)>();
285316
public Dictionary<int, Tuple<string, string>> FMTU { get; set; } = new Dictionary<int, Tuple<string, string>>();
286317

287318
public Dictionary<char, string> Unit { get; set; } = new Dictionary<char, string>();
@@ -410,7 +441,6 @@ public bool IsReadOnly
410441
{
411442
yield return this[(long)position];
412443
position++;
413-
414444
}
415445
}
416446

ExtLibs/Utilities/DFLogScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void setParameterValue(int argumentIndex, double argumentValue)
139139
}
140140
}
141141

142-
public static List<Tuple<DFLog.DFItem, double>> ProcessExpression(DFLog dflog, CollectionBuffer logdata, string expression)
142+
public static List<Tuple<DFLog.DFItem, double>> ProcessExpression(DFLog dflog, DFLogBuffer logdata, string expression)
143143
{
144144
List<Tuple<DFLog.DFItem, double>> answer = new List<Tuple<DFLog.DFItem, double>>();
145145

0 commit comments

Comments
 (0)