コード例 #1
0
        /// <summary>
        /// Determine and create the directory where the raw data is saved in 1-hour chunks.
        /// </summary>
        private void DetermineFilePath()
        {
            if (isActive)
            {
                if (presentHour != DateTime.Now.Hour)
                {
                    if (bwPLFormat != null)
                    {
                        bwPLFormat.CloseFile();
                    }
                    presentHour = DateTime.Now.Hour;
                    // Need to create a new directory and switch the file name
                    dayPath = DirectoryStructure.DayDirectoryToUse(aRootPathName);

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

                    currentDataFile = currentDataFile + FILE_TYPE_MONIKER + "." +
                                      DirectoryStructure.GetDate() + "." + COMP_ID + "." + FILE_EXT;

                    bwPLFormat = new ByteWriter(currentDataFile, true);
                    bwPLFormat.OpenFile();

                    // Ensure that the first data point in the new file will start
                    // with the full, rather than differential, timecode info.
                    isForceTimestampSave = true;
                }
            }
        }
コード例 #2
0
ファイル: Accelerometer.cs プロジェクト: katadam/wockets
        /// <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
        }