コード例 #1
0
ファイル: PortListenerTest.cs プロジェクト: pengwin/AccelLib
        public void DataReceivingTest()
        {
            var portMock = new Mock<IBinaryPort>();
            portMock.Setup(foo => foo.ReadBytesBlock(1)).Returns(new byte[] {0xA}); // возвращаем сигнатуру
            // возвращаем тело пакета
            portMock.Setup(foo => foo.ReadBytesBlock(16)).Returns(new byte[]{0, 0, 0, 0, 0, 0, 52, 64, 0, 0, 0, 0, 0, 192, 82,192});
            var loggerStub = new LoggerStub();

            var target = new PortListener(portMock.Object, loggerStub);

            var expected = new AccelData(20.0, -75.0);
            var syncEvent = new AutoResetEvent(false);
            AccelData actual = null;

            target.AccelDataReceived += (sender, dataArgs) =>
                                       {
                                           syncEvent.Set();
                                           actual = dataArgs.Data;
                                       };

            target.StartListen();
            if (!syncEvent.WaitOne(5000)) // ждем события
            {
                Assert.Fail("Таймаут ожидания данных");
            }
            target.StopListen();

            Assert.AreEqual(expected.Ax, actual.Ax); // проверяем правильность разбора пакета
        }
コード例 #2
0
ファイル: AccelDataTest.cs プロジェクト: pengwin/AccelLib
        public void ConstructorWihoutParametersTest()
        {
            var target = new AccelData();

            Assert.AreEqual(0F,target.Ax);
            Assert.AreEqual(0F,target.Ay );
        }
コード例 #3
0
ファイル: AccelDataTest.cs プロジェクト: pengwin/AccelLib
        public void ConstructorWithParametersTest()
        {
            double ax = 10.0;
            double ay = 50.0;
            var target = new AccelData(ax,ay);

            Assert.AreEqual(ax, target.Ax);
            Assert.AreEqual(ay, target.Ay);
        }
コード例 #4
0
ファイル: AccelDataTest.cs プロジェクト: pengwin/AccelLib
        public void OperatorMinusTest()
        {
            var target1 = new AccelData(15.0, 75.0);
            var target2 = new AccelData(5.0, -150.0);

            var expected = new AccelData(10.0, 225.0);

            var actual = target1 - target2;

            Assert.AreEqual(expected.Ax, actual.Ax);
            Assert.AreEqual(expected.Ay, actual.Ay);
        }
コード例 #5
0
ファイル: AccelDataTest.cs プロジェクト: pengwin/AccelLib
        public void OperatorDivideTest()
        {
            var target = new AccelData(15.0, 75.0);
            var divizor = 5.0;

            var expected = new AccelData(3.0, 15.0);

            var actual = target/divizor;

            Assert.AreEqual(expected.Ax, actual.Ax);
            Assert.AreEqual(expected.Ay, actual.Ay);
        }
コード例 #6
0
ファイル: AccelDataTest.cs プロジェクト: pengwin/AccelLib
        public void FromBufferTest()
        {
            var target = new AccelData(15.0, 75.0);

            var expected = new AccelData(20.0, -75.0);

            var buffer = new DataBuffer(Endianness.LittleEndian);
            buffer.WriteDouble(20.0);
            buffer.WriteDouble(-75.0);

            target.FromBuffer(buffer);

            Assert.AreEqual(expected.Ax, target.Ax);
            Assert.AreEqual(expected.Ay, target.Ay);
        }
コード例 #7
0
        /// <summary>
        /// Возвращает список всех записанных данных акселерометра
        /// </summary>
        /// <returns></returns>
        public IList<AccelData> GetAccelData()
        {
            var result = new List<AccelData>();
            var command = new SqlCeCommand();
            command.Connection = _connection;
            command.CommandText = @"SELECT date,Ax,Ay FROM accel_data";
            var reader = command.ExecuteReader();
            while (reader.Read())
            {
                var data = new AccelData();
                data.Date = reader.GetDateTime(0);
                data.Ax = reader.GetDouble(1);
                data.Ay = reader.GetDouble(2);
                result.Add(data);
            }

            return result;
        }
コード例 #8
0
        public void GetAccelParamsByDateSpanTest()
        {
            _testDb.CreateDatabase();
            _testDb.InitTestSchema();
            _testDb.PopulateTestAccelParams();
            string databaseFile = _testDbFile;
            ILogger logger = new LoggerStub();
            var target = new LocalDatabaseStorage(databaseFile, logger);
            target.Open();
            var data = new AccelData(10.0, 50.0);
            data.Date = DateTime.Now;

            var actual = target.GetAccelParamsByDateSpan(new DateTime(2012, 1, 1) - TimeSpan.FromDays(10), new DateTime(2012, 1, 1));

            Assert.AreEqual(2, actual.Count);

            target.Close();
        }
コード例 #9
0
        public void SaveAccelDataTest()
        {
            string databaseFile = _testDbFile;
            ILogger logger = new LoggerStub();
            var target = new LocalDatabaseStorage(databaseFile, logger);
            target.Open();
            var data = new AccelData(10.0, 50.0);
            data.Date = DateTime.Now;

            target.SaveAccelData(data);

            var idCount = _testDb.GetIdCount("accel_data");
            Assert.AreEqual(idCount,1,"проверяем, что запись добавлена");
            Assert.AreEqual(1, data.Id, "проверяем, что изменен идентификатор записи в базе");

            target.Close();
        }
コード例 #10
0
        public void GetAccelParamsBySensorNumberTest()
        {
            _testDb.CreateDatabase();
            _testDb.InitTestSchema();
            _testDb.PopulateTestAccelParams();
            string databaseFile = _testDbFile;
            ILogger logger = new LoggerStub();
            var target = new LocalDatabaseStorage(databaseFile, logger);
            target.Open();
            var data = new AccelData(10.0, 50.0);
            data.Date = DateTime.Now;

            var actual = target.GetAccelParamsBySensorNumber(1);

            Assert.AreEqual(2, actual.Count);

            target.Close();
        }
コード例 #11
0
ファイル: AccelDataTest.cs プロジェクト: pengwin/AccelLib
        public void ToBufferTest()
        {
            var target = new AccelData(20.0, -75.0);

            var expected = new byte[] {0, 0, 0, 0, 0, 0,52,64,0,0,0,0,0,192,82,192};

            var buffer = new DataBuffer(Endianness.LittleEndian);

            target.ToBuffer(buffer);

            CollectionAssert.AreEqual(expected, buffer.RawData);
        }
コード例 #12
0
        /// <summary>
        /// Возвращает список данных акселерометра записанных в промежуток времени (границы промежутка включительно)
        /// </summary>
        /// <param name="from">начало промежутка</param>
        /// <param name="till">конец промежутка</param>
        /// <returns></returns>
        public IList<AccelData> GetAccelDataByDateSpan(DateTime from, DateTime till)
        {
            var result = new List<AccelData>();
            var command = new SqlCeCommand();
            command.Connection = _connection;
            command.CommandText = @"SELECT date,Ax,Ay FROM accel_data WHERE date >= @from AND date <= @till";
            command.Parameters.AddWithValue("@from", from);
            command.Parameters.AddWithValue("@till", till);
            var reader = command.ExecuteReader();
            while (reader.Read())
            {
                var data = new AccelData();
                data.Date = reader.GetDateTime(0);
                data.Ax = reader.GetDouble(1);
                data.Ay = reader.GetDouble(2);
                result.Add(data);
            }

            return result;
        }
コード例 #13
0
 /// <summary>
 /// Обновляет запись в базе
 /// </summary>
 /// <param name="data"></param>
 private void UpdateAccelData(AccelData data)
 {
     var command = new SqlCeCommand();
     command.Connection = _connection;
     command.CommandText = @"UPDATE accel_data SET date=@date,Ax=@Ax,Ay=@Ay WHERE id = @id";
     command.Parameters.AddWithValue("@id", data.Id);
     command.Parameters.AddWithValue("@date", data.Date);
     command.Parameters.AddWithValue("@Ax", data.Ax);
     command.Parameters.AddWithValue("@Ay", data.Ay);
     command.ExecuteNonQuery();
 }
コード例 #14
0
 /// <summary>
 /// Создает в базе запись
 /// </summary>
 /// <param name="data"></param>
 private void CreateAccelData(AccelData data)
 {
     var command = new SqlCeCommand();
     command.Connection = _connection;
     command.CommandText = @"INSERT INTO accel_data (date, Ax,Ay) VALUES(@date,@Ax,@Ay)";
     command.Parameters.AddWithValue("@date", data.Date);
     command.Parameters.AddWithValue("@Ax", data.Ax);
     command.Parameters.AddWithValue("@Ay", data.Ay);
     command.ExecuteNonQuery();
     command.CommandText = "SELECT @@IDENTITY";
     var id = command.ExecuteScalar();
     if (id != null)
     {
         data.Id = Convert.ToInt32((decimal)id); // записываем идентификатор записи в базе
     }
 }
コード例 #15
0
 /// <summary>
 /// Сохраняет в базе данные акселерометра
 /// </summary>
 /// <param name="data"></param>
 public void SaveAccelData(AccelData data)
 {
     if (data.Id > 0)
     {
         UpdateAccelData(data);
     }
     else
     {
         CreateAccelData(data);
     }
 }
コード例 #16
0
 /// <summary>
 /// Делает выборку по результатам калибровки для указанного идентификатора калибровочных параметров
 /// </summary>
 public CalibrationResult GetCalibrationResultByParams(AccelParams parameters)
 {
     var result = new CalibrationResult {Parameters = parameters};
     var command = new SqlCeCommand();
     command.Connection = _connection;
     command.CommandText = @"SELECT data.Id, data.date, data.Ax, data.Ay
                             FROM calibr_result result JOIN accel_data data
                                 ON (result.accelDataId = data.id)
                             WHERE result.accelParamsId = @paramsId";
     command.Parameters.AddWithValue("@paramsId", parameters.Id);
     var reader = command.ExecuteReader();
     while (reader.Read())
     {
         var data = new AccelData();
         data.Id = reader.GetInt32(0);
         data.Date = reader.GetDateTime(1);
         data.Ax = reader.GetDouble(2);
         data.Ay = reader.GetDouble(3);
         result.Clusters.Add(data);
     }
     return result;
 }