Skip to content

Commit

Permalink
dflog: convert to use collectionbuffer dflog
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Jun 27, 2016
1 parent 90e5276 commit 0aa0060
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 78 deletions.
70 changes: 34 additions & 36 deletions GeoRef/georefimage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ private enum PROCESSING_MODE
private Label label28;
private List<int> JXL_StationIDs = new List<int>();

DFLog dflog = new DFLog();

public Georefimage()
{
InitializeComponent();
Expand Down Expand Up @@ -227,30 +225,24 @@ private Dictionary<long, VehicleLocation> readGPSMsgInLog(string fn)
float currentSAlt = 0f;
int a = 0;

foreach (var item in sr.GetEnumeratorType(new string[] { "FMT", "GPS", "GPS2", "ATT", "CTUN", "RFND" }))
foreach (var item in sr.GetEnumeratorType(new string[] { "GPS", "GPS2", "ATT", "CTUN", "RFND" }))
{
// Look for GPS Messages. However GPS Messages do not have Roll, Pitch and Yaw
// So we have to look for one ATT message after having read a GPS one

if (item.msgtype == "FMT")
{
dflog.FMTLine(sr[item.lineno]);
continue;
}

var gpstouse = UseGpsorGPS2();

if (item.msgtype == gpstouse)
{
if (!dflog.logformat.ContainsKey(gpstouse))
if (!sr.dflog.logformat.ContainsKey(gpstouse))
continue;

int latindex = dflog.FindMessageOffset(gpstouse, "Lat");
int lngindex = dflog.FindMessageOffset(gpstouse, "Lng");
int altindex = dflog.FindMessageOffset(gpstouse, "Alt");
int raltindex = dflog.FindMessageOffset(gpstouse, "RAlt");
int latindex = sr.dflog.FindMessageOffset(gpstouse, "Lat");
int lngindex = sr.dflog.FindMessageOffset(gpstouse, "Lng");
int altindex = sr.dflog.FindMessageOffset(gpstouse, "Alt");
int raltindex = sr.dflog.FindMessageOffset(gpstouse, "RAlt");
if (raltindex == -1)
raltindex = dflog.FindMessageOffset(gpstouse, "RelAlt");
raltindex = sr.dflog.FindMessageOffset(gpstouse, "RelAlt");

VehicleLocation location = new VehicleLocation();

Expand Down Expand Up @@ -286,9 +278,9 @@ private Dictionary<long, VehicleLocation> readGPSMsgInLog(string fn)
}
else if (item.msgtype == "ATT")
{
int Rindex = dflog.FindMessageOffset("ATT", "Roll");
int Pindex = dflog.FindMessageOffset("ATT", "Pitch");
int Yindex = dflog.FindMessageOffset("ATT", "Yaw");
int Rindex = sr.dflog.FindMessageOffset("ATT", "Roll");
int Pindex = sr.dflog.FindMessageOffset("ATT", "Pitch");
int Yindex = sr.dflog.FindMessageOffset("ATT", "Yaw");

if (Rindex != -1)
currentRoll = float.Parse(item.items[Rindex], CultureInfo.InvariantCulture);
Expand All @@ -299,7 +291,7 @@ private Dictionary<long, VehicleLocation> readGPSMsgInLog(string fn)
}
else if (item.msgtype == "CTUN")
{
int SAltindex = dflog.FindMessageOffset("CTUN", "SAlt");
int SAltindex = sr.dflog.FindMessageOffset("CTUN", "SAlt");

if (SAltindex != -1)
{
Expand All @@ -308,7 +300,7 @@ private Dictionary<long, VehicleLocation> readGPSMsgInLog(string fn)
}
else if (item.msgtype == "RFND")
{
int SAltindex = dflog.FindMessageOffset("RFND", "Dist1");
int SAltindex = sr.dflog.FindMessageOffset("RFND", "Dist1");

if (SAltindex != -1)
{
Expand Down Expand Up @@ -380,29 +372,24 @@ private Dictionary<long, VehicleLocation> readCAMMsgInLog(string fn)
// DataFlash Log
else
{
float currentSAlt = 0;
using (var sr = new CollectionBuffer(File.OpenRead(fn)))
{
int a = 0;
while (!sr.EndOfStream)
foreach (var item in sr.GetEnumeratorType(new string[] { "CAM", "RFND" }))
{
a++;
string line = sr.ReadLine();

var item = dflog.GetDFItemFromLine(line, a);

if (item.msgtype == "CAM")
{
int latindex = dflog.FindMessageOffset("CAM", "Lat");
int lngindex = dflog.FindMessageOffset("CAM", "Lng");
int altindex = dflog.FindMessageOffset("CAM", "Alt");
int raltindex = dflog.FindMessageOffset("CAM", "RelAlt");
int latindex = sr.dflog.FindMessageOffset("CAM", "Lat");
int lngindex = sr.dflog.FindMessageOffset("CAM", "Lng");
int altindex = sr.dflog.FindMessageOffset("CAM", "Alt");
int raltindex = sr.dflog.FindMessageOffset("CAM", "RelAlt");

int rindex = dflog.FindMessageOffset("CAM", "Roll");
int pindex = dflog.FindMessageOffset("CAM", "Pitch");
int yindex = dflog.FindMessageOffset("CAM", "Yaw");
int rindex = sr.dflog.FindMessageOffset("CAM", "Roll");
int pindex = sr.dflog.FindMessageOffset("CAM", "Pitch");
int yindex = sr.dflog.FindMessageOffset("CAM", "Yaw");

int gtimeindex = dflog.FindMessageOffset("CAM", "GPSTime");
int gweekindex = dflog.FindMessageOffset("CAM", "GPSWeek");
int gtimeindex = sr.dflog.FindMessageOffset("CAM", "GPSTime");
int gweekindex = sr.dflog.FindMessageOffset("CAM", "GPSWeek");

VehicleLocation p = new VehicleLocation();

Expand All @@ -419,8 +406,19 @@ private Dictionary<long, VehicleLocation> readCAMMsgInLog(string fn)
p.Roll = float.Parse(item.items[rindex], CultureInfo.InvariantCulture);
p.Yaw = float.Parse(item.items[yindex], CultureInfo.InvariantCulture);

p.SAlt = currentSAlt;

list[ToMilliseconds(p.Time)] = p;
}
else if (item.msgtype == "RFND")
{
int SAltindex = sr.dflog.FindMessageOffset("RFND", "Dist1");

if (SAltindex != -1)
{
currentSAlt = float.Parse(item.items[SAltindex]);
}
}
}
}
}
Expand Down
68 changes: 26 additions & 42 deletions Utilities/fftui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,14 @@ private void myButton1_Click(object sender, EventArgs e)
double[] freqt = null;
double samplerate = 0;

Log.DFLog dflog = new Log.DFLog();

while (!file.EndOfStream)
foreach (var item in file.GetEnumeratorType(new string[] { "ACC1", "GYR1" }))
{
var item = dflog.GetDFItemFromLine(file.ReadLine(), 0);

if (item.msgtype == "ACC1")
{
int offsetAX = dflog.FindMessageOffset("ACC1", "AccX");
int offsetAY = dflog.FindMessageOffset("ACC1", "AccY");
int offsetAZ = dflog.FindMessageOffset("ACC1", "AccZ");
int offsetTime = dflog.FindMessageOffset("ACC1", "TimeUS");
int offsetAX = file.dflog.FindMessageOffset("ACC1", "AccX");
int offsetAY = file.dflog.FindMessageOffset("ACC1", "AccY");
int offsetAZ = file.dflog.FindMessageOffset("ACC1", "AccZ");
int offsetTime = file.dflog.FindMessageOffset("ACC1", "TimeUS");

double time = double.Parse(item.items[offsetTime])/1000.0;

Expand All @@ -202,10 +198,10 @@ private void myButton1_Click(object sender, EventArgs e)
}
else if (item.msgtype == "GYR1")
{
int offsetGX = dflog.FindMessageOffset("GYR1", "GyrX");
int offsetGY = dflog.FindMessageOffset("GYR1", "GyrY");
int offsetGZ = dflog.FindMessageOffset("GYR1", "GyrZ");
int offsetTime = dflog.FindMessageOffset("ACC1", "TimeUS");
int offsetGX = file.dflog.FindMessageOffset("GYR1", "GyrX");
int offsetGY = file.dflog.FindMessageOffset("GYR1", "GyrY");
int offsetGZ = file.dflog.FindMessageOffset("GYR1", "GyrZ");
int offsetTime = file.dflog.FindMessageOffset("ACC1", "TimeUS");

double time = double.Parse(item.items[offsetTime])/1000.0;

Expand Down Expand Up @@ -336,12 +332,8 @@ private void BUT_log2_Click(object sender, EventArgs e)
for (int a = 0; a < alldata.Length; a++)
alldata[a] = new datastate();

Log.DFLog dflog = new Log.DFLog();

while (!file.EndOfStream)
foreach (var item in file.GetEnumeratorType(new string[] { "ACC1", "GYR1", "ACC2", "GYR2", "ACC3", "GYR3", "ACC4", "GYR4" }))
{
var item = dflog.GetDFItemFromLine(file.ReadLine(), 0);

if (item.msgtype == null)
{
continue;
Expand All @@ -352,10 +344,10 @@ private void BUT_log2_Click(object sender, EventArgs e)
int sensorno = int.Parse(item.msgtype.Substring(3)) - 1 + 3;
alldata[sensorno].type = item.msgtype;

int offsetAX = dflog.FindMessageOffset(item.msgtype, "AccX");
int offsetAY = dflog.FindMessageOffset(item.msgtype, "AccY");
int offsetAZ = dflog.FindMessageOffset(item.msgtype, "AccZ");
int offsetTime = dflog.FindMessageOffset(item.msgtype, "TimeUS");
int offsetAX = file.dflog.FindMessageOffset(item.msgtype, "AccX");
int offsetAY = file.dflog.FindMessageOffset(item.msgtype, "AccY");
int offsetAZ = file.dflog.FindMessageOffset(item.msgtype, "AccZ");
int offsetTime = file.dflog.FindMessageOffset(item.msgtype, "TimeUS");

double time = double.Parse(item.items[offsetTime])/1000.0;

Expand All @@ -374,10 +366,10 @@ private void BUT_log2_Click(object sender, EventArgs e)
int sensorno = int.Parse(item.msgtype.Substring(3)) - 1;
alldata[sensorno].type = item.msgtype;

int offsetGX = dflog.FindMessageOffset(item.msgtype, "GyrX");
int offsetGY = dflog.FindMessageOffset(item.msgtype, "GyrY");
int offsetGZ = dflog.FindMessageOffset(item.msgtype, "GyrZ");
int offsetTime = dflog.FindMessageOffset(item.msgtype, "TimeUS");
int offsetGX = file.dflog.FindMessageOffset(item.msgtype, "GyrX");
int offsetGY = file.dflog.FindMessageOffset(item.msgtype, "GyrY");
int offsetGZ = file.dflog.FindMessageOffset(item.msgtype, "GyrZ");
int offsetTime = file.dflog.FindMessageOffset(item.msgtype, "TimeUS");

double time = double.Parse(item.items[offsetTime])/1000.0;

Expand Down Expand Up @@ -503,21 +495,13 @@ private void but_fftimu_Click(object sender, EventArgs e)
for (int a = 0; a < alldata.Length; a++)
alldata[a] = new datastate();

Log.DFLog dflog = new Log.DFLog();

foreach (var item in file.GetEnumeratorType(new string[] {"FMT","IMU","IMU2","IMU3"}))
foreach (var item in file.GetEnumeratorType(new string[] {"IMU","IMU2","IMU3"}))
{
if (item.msgtype == null)
{
continue;
}

if (item.msgtype == "FMT")
{
dflog.FMTLine(file[item.lineno]);
continue;
}

if (item.msgtype.StartsWith("IMU"))
{
int sensorno = 0;
Expand All @@ -530,10 +514,10 @@ private void but_fftimu_Click(object sender, EventArgs e)

alldata[sensorno+3].type = item.msgtype +" A";

int offsetAX = dflog.FindMessageOffset(item.msgtype, "AccX");
int offsetAY = dflog.FindMessageOffset(item.msgtype, "AccY");
int offsetAZ = dflog.FindMessageOffset(item.msgtype, "AccZ");
int offsetTime = dflog.FindMessageOffset(item.msgtype, "TimeUS");
int offsetAX = file.dflog.FindMessageOffset(item.msgtype, "AccX");
int offsetAY = file.dflog.FindMessageOffset(item.msgtype, "AccY");
int offsetAZ = file.dflog.FindMessageOffset(item.msgtype, "AccZ");
int offsetTime = file.dflog.FindMessageOffset(item.msgtype, "TimeUS");

double time = double.Parse(item.items[offsetTime]) / 1000.0;

Expand All @@ -550,9 +534,9 @@ private void but_fftimu_Click(object sender, EventArgs e)
//gyro
alldata[sensorno].type = item.msgtype + " G";

int offsetGX = dflog.FindMessageOffset(item.msgtype, "GyrX");
int offsetGY = dflog.FindMessageOffset(item.msgtype, "GyrY");
int offsetGZ = dflog.FindMessageOffset(item.msgtype, "GyrZ");
int offsetGX = file.dflog.FindMessageOffset(item.msgtype, "GyrX");
int offsetGY = file.dflog.FindMessageOffset(item.msgtype, "GyrY");
int offsetGZ = file.dflog.FindMessageOffset(item.msgtype, "GyrZ");

if (time != alldata[sensorno].lasttime)
alldata[sensorno].timedelta = alldata[sensorno].timedelta * 0.99 +
Expand Down

0 comments on commit 0aa0060

Please sign in to comment.