public GraphData Readbuffer(graphtype type,float fstart, float fend,int gpoints) { #region stream_switch switch (type) { case graphtype.Altitude: stream = Altitude; maxstream = AltitudeMax; minstream = AltitudeMin; break; case graphtype.Altitude_p: stream = Altitude; maxstream = AltitudeMax; minstream = AltitudeMin; break; case graphtype.Ax: stream = Ax; maxstream = AxMax; minstream = AxMin; break; case graphtype.Ay: stream = Ay; maxstream = AyMax; minstream = AyMin; break; case graphtype.Az: stream = Az; maxstream = AzMax; minstream = AzMin; break; case graphtype.Latitude: stream = Latitude; maxstream = LatitudeMax; minstream = LatitudeMin; break; case graphtype.Latitude_p: stream = Latitude_p; maxstream = LatitudeMax; minstream = LatitudeMin; break; case graphtype.Longitude: stream = Longitude; maxstream = LongitudeMax; minstream = LongitudeMin; break; case graphtype.Longitude_p: stream = Longitude_p; maxstream = LongitudeMax; minstream = LongitudeMin; break; case graphtype.PDOP: stream = PDOP; maxstream = PDOPMax; minstream = PDOPMin; break; case graphtype.State: stream = state; maxstream = minstream = state; break; case graphtype.Temperature: stream = Temperature; maxstream = minstream = Temperature; break; case graphtype.UsedStats: stream = UsedStats; maxstream = minstream = UsedStats; break; case graphtype.VisibleStats: stream = VisibleStats; maxstream = minstream = VisibleStats; break; case graphtype.Vx: stream = Vx; maxstream = VxMax; minstream = VxMin; break; case graphtype.Vx_p: stream = Vx_p; maxstream = VxMax; minstream = VxMin; break; case graphtype.Vy: stream = Vy; maxstream = VyMax; minstream = VyMin; break; case graphtype.Vy_p: stream = Vy_p; maxstream = VyMax; minstream = VyMin; break; case graphtype.Vz: stream = Vz; maxstream = VzMax; minstream = VzMin; break; case graphtype.Vz_p: stream = Vz_p; maxstream = VzMax; minstream = VzMin; break; case graphtype.X: stream = X; maxstream = XMax; minstream = XMin; break; case graphtype.X_p: stream = X_p; maxstream = XMax; minstream = XMin; break; case graphtype.Y: stream = Y; maxstream = YMax; minstream = YMin; break; case graphtype.Y_p: stream = Y_p; maxstream = YMax; minstream = YMin; break; case graphtype.Z: stream = Z; maxstream = ZMax; minstream = ZMin; break; case graphtype.Z_p: stream = Z_p; maxstream = ZMax; minstream = ZMin; break; case graphtype.A: stream = A; maxstream = AMin; minstream = AMax; break; case graphtype.V: stream = V; maxstream = VMax; minstream = VMin; break; case graphtype.V_p: stream = V_p; maxstream = VMax; minstream = VMin; break; } #endregion GraphData tempgraphdata = new GraphData(gpoints); if (stream.Length > 0) { stream.Position = Functions.QuantizePosition(fstart * stream.Length); maxstream.Position = minstream.Position = Functions.QuantizePosition(fstart * minstream.Length); timestream.Position = Functions.QuantizePosition6bit(fstart * timestream.Length); var db = (float)((fend - fstart) * stream.Length / gpoints); var tdb = (float)((fend - fstart) * timestream.Length / gpoints); var mdb = (float)((fend - fstart) * maxstream.Length); var counter = 0; int extflag = 1; float pos = stream.Position; float tpos = timestream.Position; byte[] byt = new byte[4]; byte[] tbyt = new byte[6]; while (true) { double t; if (type == graphtype.State || type == graphtype.Temperature) { t = stream.ReadByte(); pos += db; stream.Position = (int)(pos); } else { stream.Read(byt, 0, 4); if (type != graphtype.UsedStats && type != graphtype.VisibleStats) t = Functions.BytetoFloat(byt); else t = Functions.BytetoFloatOther(byt); pos += db; stream.Position = Functions.QuantizePosition(pos); } timestream.Read(tbyt,0,6); tpos += tdb; timestream.Position = Functions.QuantizePosition6bit(tpos); tempgraphdata.x[counter] = (double)stream.Position/stream.Length;//(double)stream.Position / stream.Length; tempgraphdata.y[counter] = t; var tempt = Functions.ReadDateTime(tbyt); if (counter == 0) tempgraphdata.date[counter] = tempt; else { if (tempgraphdata.date[counter - 1] > tempt) tempgraphdata.date[counter] = tempgraphdata.date[counter - 1]; else tempgraphdata.date[counter] = tempt; } if (counter++ >= gpoints - 1) break; if (stream.Position >= stream.Length - 3 && type != graphtype.State && type != graphtype.Temperature) { for (int i = counter; i < gpoints; i++) { tempgraphdata.x[i] = (double)counter / gpoints; tempgraphdata.y[i] = t; tempgraphdata.date[i] = Functions.ReadDateTime(tbyt); } break; } else if (stream.Position >= stream.Length - 1 && type == graphtype.State && type == graphtype.Temperature) { for (int i = counter; i < gpoints; i++) { tempgraphdata.x[i] = (double)counter / gpoints; tempgraphdata.y[i] = t; tempgraphdata.date[i] = Functions.ReadDateTime(tbyt); } break; } } while (extflag >= 0) { if (maxstream.Length <= 0) { tempgraphdata.max.Add(0); tempgraphdata.min.Add(0); break; } maxstream.Read(byt, 0, 4); var tempmax = Functions.BytetoFloat(byt); tempgraphdata.max.Add(tempmax); minstream.Read(byt, 0, 4); var tempmin = Functions.BytetoFloat(byt); tempgraphdata.min.Add(tempmin); float Percent = (float)maxstream.Position / (float)maxstream.Length; if (Percent >= fend || Percent >= 1f) extflag = -1; } } return tempgraphdata; }
//Legacy /* public void PlotGraph() { int counter=0; float i = fmin/7000f; double temp = 0; var dt = delta / 7000f; for (counter = 0; counter < Globals.Databuffercount; counter++) { if (counter >= dbuffer.X.Count) { for (int j = counter; j < Globals.Databuffercount; j++) { ylist[j] = temp; xlist[j] = (double)i; i += dt; } break; } var index = dbuffer.statcounter[counter]; if (index != -1) { switch (selectedtype) { case graphtype.X: temp = dbuffer.X[index]; break; case graphtype.Y: temp = dbuffer.Y[index]; break; case graphtype.Z: temp = dbuffer.Z[index]; break; case graphtype.Vx: temp = dbuffer.Vx[index]; break; case graphtype.Vy: temp = dbuffer.Vy[index]; break; case graphtype.Vz: temp = dbuffer.Vz[index]; break; case graphtype.Ax: temp = dbuffer.Ax[index]; break; case graphtype.Ay: temp = dbuffer.Ay[index]; break; case graphtype.Az: temp = dbuffer.Az[index]; break; case graphtype.Latitude: temp = dbuffer.Latitude[index]; break; case graphtype.Longitude: temp = dbuffer.Longitude[index]; break; case graphtype.Altitude: temp = dbuffer.Altitude[index]; break; case graphtype.PDOP: temp = dbuffer.PDOP[index]; break; case graphtype.State: temp = dbuffer.state[index]; break; case graphtype.Temperature: temp = dbuffer.Temperature[index]; break; case graphtype.UsedStats: temp = dbuffer.NumOfUsedSats[index]; break; case graphtype.VisibleStats: temp = dbuffer.NumOfVisibleSats[index]; break; } } ylist[counter] = temp; xlist[counter] = (double)i; i += dt; } // if (counter < 1000) //{ // ylist[counter] = 0; // xlist[counter] = max; // } Chart1.ChartGroups[0].ChartData.SeriesList[0].X.CopyDataIn(xlist); Chart1.ChartGroups[0].ChartData.SeriesList[0].Y.CopyDataIn(ylist); } */ public void PlotGraph(GraphData data) { xlist = data.x; ylist = data.y; tlist = data.date; double[] time = new double[Globals.Databuffercount]; for (int i = 0; i < Globals.Databuffercount; i++) time[i] = (data.date[i] == emptytime) ? double.NaN : (double)tlist[i].Ticks; if (fmax - fmin > 0.02f && selectedtype != graphtype.State && selectedtype != graphtype.Temperature && selectedtype != graphtype.UsedStats && selectedtype != graphtype.VisibleStats) { double[] max = Functions.FindMaxes(data.max); double[] min = Functions.FindMins(data.min); Chart1.ChartGroups[0].ChartData.SeriesList[0].X.CopyDataIn(time); Chart1.ChartGroups[0].ChartData.SeriesList[0].Y.CopyDataIn(data.y); Chart1.ChartGroups[0].ChartData.SeriesList[1].X.CopyDataIn(time); Chart1.ChartGroups[0].ChartData.SeriesList[1].Y.CopyDataIn(max); Chart1.ChartGroups[0].ChartData.SeriesList[2].X.CopyDataIn(time); Chart1.ChartGroups[0].ChartData.SeriesList[2].Y.CopyDataIn(min); } else { Chart1.ChartGroups[0].ChartData.SeriesList[0].X.CopyDataIn(time); Chart1.ChartGroups[0].ChartData.SeriesList[0].Y.CopyDataIn(data.y); Chart1.ChartGroups[0].ChartData.SeriesList[1].X.Clear(); Chart1.ChartGroups[0].ChartData.SeriesList[1].Y.Clear(); Chart1.ChartGroups[0].ChartData.SeriesList[2].X.Clear(); Chart1.ChartGroups[0].ChartData.SeriesList[2].Y.Clear(); } }