Пример #1
0
        private DateTime RawQueryClock()
        {
            ConnectIfRequired();

            var queryPacket = GenerateEmptyPacketData();

            queryPacket[1] = 0x87;
            Thread.Sleep(25);
            if (WritePacket(queryPacket))
            {
                Thread.Sleep(25);
                queryPacket = UsbConn.ReadPacket(QuarterSecond);
                if (null != queryPacket)
                {
                    Swap(queryPacket, 4, 5);
                    DateTime dt;
                    return(DaqDataFileInfo.TryConvert7ByteDateTime(queryPacket, 2, out dt)
                                                ? dt
                                                : (
                               DaqDataFileInfo.TryConvertFrom7ByteDateTimeForce(queryPacket, 2, out dt)
                                                                ? dt
                                                                : default(DateTime)
                               )
                           );
                }
            }
            return(default(DateTime));
        }
Пример #2
0
        public void TryConvert7ByteDateTimeFromBytesInvalidSecondTest()
        {
            DateTime stamp;
            var      result = DaqDataFileInfo.TryConvert7ByteDateTime(new byte[] { 0x07, 0xda, 0x0b, 0x12, 0x03, 0x2e, 0x53 }, 0, out stamp);

            Assert.IsFalse(result);
            Assert.AreEqual(default(DateTime), stamp);
        }
Пример #3
0
        public void TryConvert7ByteDateTimeFromBytesTest()
        {
            DateTime stamp;
            var      result = DaqDataFileInfo.TryConvert7ByteDateTime(new byte[] { 0x07, 0xda, 0x0b, 0x12, 0x13, 0x2e, 0x03 }, 0, out stamp);

            Assert.IsTrue(result);
            Assert.AreEqual(new DateTime(2010, 11, 18, 19, 46, 3), stamp);
        }
Пример #4
0
 private static IEnumerable <PackedReading> GetPackedReadings(DaqDataFileInfo fileInfo)
 {
     using (var file = fileInfo.CreateReader()) {
         while (file.MoveNext())
         {
             yield return(file.Current);
         }
     }
 }
Пример #5
0
        public void ReadFirstThreeRecordsTest()
        {
            DateTime stamp;

            // setup the stamp variable to compare
            Assert.True(DaqDataFileInfo.TryConvert7ByteDateTime(
                            new byte[] { 0x07, 0xda, 0x03, 0x0f, 0x13, 0x1e, 0x17, 0xa5 },
                            0, out stamp
                            ));
            using (var stream = DaqDataFileTestUtility.CreateSampleDaqFileStream()) {
                using (var reader = new DaqDataFileReader(stream)) {
                    Assert.True(reader.MoveNext());
                    Assert.AreEqual(
                        PackedReadingValues.FromDeviceBytes(new byte[] {
                        0x00, 0x01, 0x09, 0x41, 0x33, 0x60, 0x00, 0x1f
                    }, 0),
                        reader.Current.Values
                        );
                    Assert.AreEqual(stamp.Add(new TimeSpan(0, 0, 0, 1)), reader.Current.TimeStamp);

                    Assert.True(reader.MoveNext());
                    Assert.AreEqual(
                        PackedReadingValues.FromDeviceBytes(new byte[] {
                        0x00, 0x01, 0x05, 0x41, 0x33, 0x60, 0x00, 0x1f
                    }, 0),
                        reader.Current.Values
                        );
                    Assert.AreEqual(stamp.Add(new TimeSpan(0, 0, 0, 2)), reader.Current.TimeStamp);

                    Assert.True(reader.MoveNext());
                    Assert.AreEqual(
                        PackedReadingValues.FromDeviceBytes(new byte[] {
                        0x00, 0x01, 0x09, 0x41, 0x33, 0x60, 0x00, 0x1f
                    }, 0),
                        reader.Current.Values
                        );
                    Assert.AreEqual(stamp.Add(new TimeSpan(0, 0, 0, 3)), reader.Current.TimeStamp);
                }
            }
        }
Пример #6
0
            private void ImportData(object o)
            {
                int doneCount    = 0;
                int failedCount  = 0;
                int successCount = 0;

                Action <int> reportProgress = null;

                if (o is BackgroundWorker)
                {
                    reportProgress = (o as BackgroundWorker).ReportProgress;
                }
                else
                {
                    reportProgress = x => { }
                };

                while (true)
                {
                    ImportDataSet currentSet = null;
                    lock (_queueLock) {
                        if (_importSetQueue.Count == 0)
                        {
                            if (null == _moveSetQueue)
                            {
                                _importSetQueue = null;
                                break;
                            }
                            Thread.Sleep(100);
                        }
                        else
                        {
                            currentSet = _importSetQueue.Dequeue();
                        }
                    }
                    if (null != currentSet)
                    {
                        bool savedData  = false;
                        int  lastAnemId = -1;
                        foreach (var file in currentSet.Files)
                        {
                            FileInfo fileLocation;
                            if (!currentSet.MovedToLocation.TryGetValue(file, out fileLocation))
                            {
                                fileLocation = file.Path;
                            }

                            if (null != fileLocation)
                            {
                                var currentFile = file.Path == fileLocation ? file : DaqDataFileInfo.Create(fileLocation);
                                try {
                                    var pushOk = _dataStore.Push(
                                        currentSet.Sensor.Name, GetPackedReadings(currentFile), _recordOverwrite);

                                    if (pushOk)
                                    {
                                        successCount++;
                                        savedData  = true;
                                        lastAnemId = file.Nid;
                                    }
                                    else
                                    {
                                        failedCount++;
                                    }
                                }
                                catch {
                                    failedCount++;
                                }
                            }
                        }
                        if (savedData)
                        {
                            _dataStore.SetLatestSensorNameForHardwareId(
                                currentSet.Sensor.Name,
                                ((char)(lastAnemId + (byte)('A'))).ToString()
                                );
                        }

                        System.Diagnostics.Debug.WriteLine("Importing..." + currentSet.Files.Count);
                        doneCount++;
                    }
                    lock (_queueLock) {
                        ImportProgress = doneCount / (double)MaxQueue;
                        reportProgress((int)(Progress * 100));
                    }
                }

                _message = null;
                if (failedCount > 0 || successCount == 0)
                {
                    _message = "Data import failed.";
                }
                else
                {
                    _message = "Data import completed successfully.";
                }

                lock (_queueLock) {
                    ImportProgress = 1.0;
                    reportProgress((int)(Progress * 100));
                }
            }
        }