Exemplo n.º 1
0
        public void Draw(Graphics g)
        {
            int lastColumnDrawn = 0;

            for (int i = 0; (i < this.wocketsController._Sensors.Count); i++)
            {
                int receiverID = this.wocketsController._Sensors[i]._Receiver._ID;
                int plottedPoints = 0;

                if (this.wocketsController._Receivers[receiverID]._Status == Wockets.Receivers.ReceiverStatus.Connected)
                {
                    int currentHead = this.wocketsController._Sensors[i]._Decoder._Head;

                    //int decoderID = this.wocketsController._Sensors[i]._Decoder._ID;
                    //for (int j = this.plotFrom[decoderID]; (j < this.wocketsController._Decoders[decoderID]._Size); j++)
                    int tail = this.decoderTails[i];
                    //while(tail<=this.wocketsController._Sensors[i]._Decoder._Head)
                    AccelerationData data = ((AccelerationData)this.wocketsController._Sensors[i]._Decoder._Data[tail]);

                    if (this.mode == PlottingMode.Delayed) //wait until 3 seconds are there then plot 5 pts max
                    {
                        int counter = 0;
                        if ((tail < currentHead) && (currentHead < (this.wocketsController._Sensors[i]._Decoder._Data.Length - 1)))
                            counter = currentHead - tail;
                        else
                            counter = (this.wocketsController._Sensors[i]._Decoder._Data.Length - 1) - tail + currentHead;

                        if (counter > 360)
                            pointsToPlot[i] = 20;
                        else if (counter > 180)
                            pointsToPlot[i] = 10;
                        else
                            pointsToPlot[i] = 5;

                    }
                    while ((tail != currentHead) && (data.UnixTimeStamp > 0) && (data.UnixTimeStamp >= this.lastUnixTimestamps[i]))
                    {


                        if (skippedPoints > 0)
                        {
                            if ((tail % skippedPoints) != 0)
                            {
                                if (tail >= (this.wocketsController._Sensors[i]._Decoder._Data.Length - 1))
                                    tail = 0;
                                else
                                    tail++;
                                continue;
                            }
                        }

                        //check the data comes from the sensor i if the decoder is used with multiple sensors
                        if (data._SensorID == this.wocketsController._Sensors[i]._ID)
                        {
                            if (this.currentColumns[i] > lastColumnDrawn)
                                lastColumnDrawn = this.currentColumns[i];

                            if (this.currentColumns[i] >= this.plotAreaSize.Width - 1)
                            {
                                g.FillRectangle(PlotBackgroundBrush, 0, 0, this.plotAreaSize.Width + 10, this.plotAreaSize.Height);
                                requiresFullRedraw = true;
                                this.currentColumns[i] = 0;
                            }

                            if ((this.wocketsController._Sensors[data._SensorID])._Class == Wockets.Sensors.SensorClasses.HTCDiamondTouch)
                            {
                                if (this.wocketsController._Sensors.Count != 1)
                                {

                                    g.DrawEllipse(p[0], lastColumnDrawn, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._X), 2, 2);
                                    g.DrawEllipse(p[1], lastColumnDrawn, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._Y), 2, 2);
                                    g.DrawEllipse(p[2], lastColumnDrawn, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._Z), 2, 2);
                                }
                                else
                                {
                                    g.DrawLine(p[0], this.currentColumns[i], axisOffset[i] - (int)Math.Floor(scaleFactors[i] * previousVals[i][0]), this.currentColumns[i] + 1, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._X));
                                    g.DrawLine(p[1], this.currentColumns[i], axisOffset[i] - (int)Math.Floor(scaleFactors[i] * previousVals[i][1]), this.currentColumns[i] + 1, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._Y));
                                    g.DrawLine(p[2], this.currentColumns[i], axisOffset[i] - (int)Math.Floor(scaleFactors[i] * previousVals[i][2]), this.currentColumns[i] + 1, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._Z));
                                }
                                if (this.currentColumns[i] > lastColumn[data._SensorID])
                                    lastColumn[data._SensorID] = this.currentColumns[i];
                            }

                            else
                            {
                                g.DrawLine(p[0], this.currentColumns[i], axisOffset[i] - (int)Math.Floor(scaleFactors[i] * previousVals[i][0]), this.currentColumns[i] + 1, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._X));
                                g.DrawLine(p[1], this.currentColumns[i], axisOffset[i] - (int)Math.Floor(scaleFactors[i] * previousVals[i][1]), this.currentColumns[i] + 1, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._Y));
                                g.DrawLine(p[2], this.currentColumns[i], axisOffset[i] - (int)Math.Floor(scaleFactors[i] * previousVals[i][2]), this.currentColumns[i] + 1, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._Z));

                                if (this.currentColumns[i] > lastColumn[data._SensorID])
                                    lastColumn[data._SensorID] = this.currentColumns[i];

                            }

                            previousVals[i][0] = data._X;
                            previousVals[i][1] = data._Y;
                            previousVals[i][2] = data._Z;
                            previousTimes[i] = data.UnixTimeStamp;

                            this.currentColumns[i] = this.currentColumns[i] + 1;

                        }


                        this.lastUnixTimestamps[i] = data.UnixTimeStamp;
                        if (tail >= (this.wocketsController._Sensors[i]._Decoder._Data.Length - 1))
                            tail = 0;
                        else
                            tail++;

                        data = ((AccelerationData)this.wocketsController._Sensors[i]._Decoder._Data[tail]);
                        plottedPoints++;
                        if ((this.mode == PlottingMode.Delayed) && (plottedPoints == pointsToPlot[i]))
                            break;
                        else if (plottedPoints == 20)
                            break;
                    }
                    this.decoderTails[i] = currentHead;
                }

            }


            if (requiresFullRedraw)
            {
                aPanel.Invalidate();
                requiresFullRedraw = false;
                this.aPanel.Width = this.aPanel.Width;
                for (int k = 0; (k < this.wocketsController._Sensors.Count); k++)
                {
                    this.currentColumns[k] = 0;
                    lastColumn[k] = 0;
                    firstColumn[k] = 999999;
                }

            }
            else
                for (int k = 0; (k < this.wocketsController._Sensors.Count); k++)
                {
                    aPanel.Invalidate(new System.Drawing.Rectangle(firstColumn[k], 0, lastColumn[k] - firstColumn[k], plotAreaSize.Height));
                    firstColumn[k] = lastColumn[k];
                }

        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves data to a binary file
        /// </summary>
        public override void Save()
        {
            #if (PocketPC)
            if (_Saving)
            {

                #region Determine the head of the data buffer
                int currentHead = -1;
                currentHead = this._Decoder._Head;
                #endregion Determine the head of the data buffer

                #region Check if a new binary file need to be created

                DateTime now = DateTime.Now;
                if (presentHour != now.Hour) //((bw==null)||(presentHour != DateTime.Now.Hour)|| (presentMinute != DateTime.Now.Minute) || (presentSecond!= DateTime.Now.Second))
                {
                    if (bw != null)
                        bw.CloseFile();
                    presentHour = now.Hour;
                    presentMinute = now.Minute;
                    presentSecond = now.Second;
                    // Need to create a new directory and switch the file name
                    dayPath = DirectoryStructure.DayDirectoryToUse(this._RootStorageDirectory);

                    // Make sure hour directory exists
                    currentDataFile = dayPath + "\\" + presentHour + "\\";
                    if (!System.IO.Directory.Exists(currentDataFile))
                        System.IO.Directory.CreateDirectory(currentDataFile);

                    currentDataFile = currentDataFile + FILE_TYPE_PREFIX + "." +
                                   DirectoryStructure.GetDate() + "." + this._ID + "." + FILE_EXT;

                    bw = new ByteWriter(currentDataFile, true);
                    bw.OpenFile(32768);

                    // Ensure that the first data point in the new file will start
                    // with the full, rather than differential, timecode info.
                    isForceTimestampSave = true;
                }
                #endregion Check if a new binary file need to be created

                // Write data as long as the tail is not equal to the head
                while (tail != currentHead)
                {
                    #region Populate the acceleration data that need to be written
                    data = ((AccelerationData)this._Decoder._Data[tail]);
                    #endregion Populate the acceleration data that need to be written

                    #region Check for timestamp errors
                    aUnixTime = data.UnixTimeStamp;
                    if (aUnixTime < lastUnixTime)
                    {
                        lastUnixTime = aUnixTime;
                        Logger.Error("Accelerometer: Save: Data overwritten without saving Accelerometer.cs Save " + this._ID + " " + aUnixTime + " " + lastUnixTime);
                    }
                    #endregion Check for timestamp errors

                    #region Write Data
                    if (bw != null)
                    {
                        #region Write Timestamp
                        diffMS = (int)(aUnixTime - lastUnixTime);
                        if (isForceTimestampSave || (diffMS > 254) || (timeSaveCount == TIMESTAMP_AFTER_SAMPLES))
                        {

                            bw.WriteByte((byte)255);
                            WocketsTimer.GetUnixTimeBytes(aUnixTime, retBytes);
                            bw.WriteBytes(retBytes, 6);
                            timeSaveCount = 0;
                            isForceTimestampSave = false;
                        }
                        else
                        {
                            bw.WriteByte((byte)diffMS);
                            timeSaveCount++;
                        }
                        #endregion Write Timestamp

                        #region Write Raw Data
                        for (int j = 0; j < data._Length; j++)
                            bw.WriteByte(data.RawBytes[j]);
                        #endregion Write Raw Data
                    }
                    #endregion Write Data

                    #region Update Pointers, statistics and time stamps
                    lastUnixTime = aUnixTime;
                    this.tailUnixTimestamp = aUnixTime;
                    if (tail >= this._Decoder._BufferSize- 1)
                        tail = 0;
                    else
                        tail++;
                    this._SavedPackets++;
                    #endregion Update Pointers, statistics and time stamps

                }

                if ((bw != null) && (this._Flush))
                    bw.Flush();
            }
            #endif
        }
Exemplo n.º 3
0
        public void Draw(Graphics g)
        {


                int lastColumnDrawn = 0;

                for (int i = 0; (i < CurrentWockets._Controller._Sensors.Count); i++)
                {
                    int tail = this.decoderTails[i];
                    int currentHead = tail;

                    //Check if the decoder got reinitialized
                    if ((CurrentWockets._Controller._Decoders[i].TotalSamples == 0) && (this.decoderTails[i]!=0))
                        this.decoderTails[i] = 0;                    

                    currentHead = CurrentWockets._Controller._Sensors[i]._Decoder._Head;



                    while (tail != currentHead)
                    {
                        try{

                        
                        data = ((AccelerationData)CurrentWockets._Controller._Sensors[i]._Decoder._Data[tail]);

                        if (!((data.UnixTimeStamp > 0) && (data.UnixTimeStamp >= this.lastUnixTimestamps[i])))
                            break;


                        //check the data comes from the sensor i if the decoder is used with multiple sensors

                        if (this.currentColumns[i] > lastColumnDrawn)
                            lastColumnDrawn = this.currentColumns[i];

                        if (this.currentColumns[i] >= this.plotAreaSize.Width - 1)
                        {
                            g.FillRectangle(blueBrush, 0, 0, this.plotAreaSize.Width + 10, this.plotAreaSize.Height);
                            requiresFullRedraw = true;
                            this.currentColumns[i] = 0;
                        }


                        g.DrawLine(p[0], this.currentColumns[i], axisOffset[i] - (int)Math.Floor(scaleFactors[i] * previousVals[i][0]), this.currentColumns[i] + 1, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._X));
                        g.DrawLine(p[1], this.currentColumns[i], axisOffset[i] - (int)Math.Floor(scaleFactors[i] * previousVals[i][1]), this.currentColumns[i] + 1, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._Y));
                        g.DrawLine(p[2], this.currentColumns[i], axisOffset[i] - (int)Math.Floor(scaleFactors[i] * previousVals[i][2]), this.currentColumns[i] + 1, axisOffset[i] - (int)Math.Floor(scaleFactors[i] * data._Z));

                        if (this.currentColumns[i] > lastColumn[i])
                            lastColumn[i] = this.currentColumns[i];


                        previousVals[i][0] = data._X;
                        previousVals[i][1] = data._Y;
                        previousVals[i][2] = data._Z;
                        previousTimes[i] = data.UnixTimeStamp;

                        this.currentColumns[i] = this.currentColumns[i] + 1;




                        this.lastUnixTimestamps[i] = data.UnixTimeStamp;

                        if (tail >= (Wockets.Decoders.Accelerometers.WocketsDecoder.BUFFER_SIZE - 1))
                        {
                            tail = 0;

                        }
                        else
                            tail++;


                        }
                        catch (Exception e)
                        {
                        }
                    }
                    this.decoderTails[i] = currentHead;
                }




                if (requiresFullRedraw)
                {
                    aPanel.Invalidate();
                    requiresFullRedraw = false;
                    //aPanel.Width = this.aPanel.Width;
                    for (int k = 0; (k < CurrentWockets._Controller._Sensors.Count); k++)
                    {
                        this.currentColumns[k] = 0;
                        lastColumn[k] = 0;
                        firstColumn[k] = 999999;
                    }

                }
                else
                    for (int k = 0; (k < CurrentWockets._Controller._Sensors.Count); k++)
                    {
                        aPanel.Invalidate(new System.Drawing.Rectangle(firstColumn[k], 0, lastColumn[k] - firstColumn[k], plotAreaSize.Height));
                        firstColumn[k] = lastColumn[k];
                    }


        }