def get_rtc(self) -> float: self._write_packet(UART_GET, UART_COMP_SHIMMER, UART_PROP_CURR_LOCAL_TIME) ticks = self._read_response_wformat_verify(UART_COMP_SHIMMER, UART_PROP_CURR_LOCAL_TIME, '<Q') return ticks2sec(ticks)
def test_ts_sync(self): sr = 5 ts = np.array([0, 5, 10, 15, 20, 25, 30, 35, 40, 45]) vbatt = np.array([93, 85, 78, 74, 71, 68, 65, 64, 10, 24]) samples = { EChannelType.TIMESTAMP: ts, EChannelType.VBATT: vbatt, } sync_index = np.array([0, len(ts) - 1]) sync_offset = np.array([1, 0]) m_br = Mock(spec=ShimmerBinaryReader) m_br.read_data.return_value = (samples, [sync_index, sync_offset]) type(m_br).sample_rate = PropertyMock(return_value=sr) type(m_br).has_sync = PropertyMock(return_value=True) type(m_br).has_global_clock = PropertyMock(return_value=False) type(m_br).start_timestamp = PropertyMock(return_value=0) reader = ShimmerReader(bin_reader=m_br, realign=False) reader.load_file_data() ts_sync_dev = ts - np.linspace(1, 0, len(ts)) exp_ts = ticks2sec(ts_sync_dev) act_ts = reader.timestamp self.assertEqual(len(exp_ts), len(act_ts)) np.testing.assert_almost_equal(act_ts, exp_ts) np.testing.assert_equal(vbatt, reader[EChannelType.VBATT])
def test_ts_unwrap(self): sr = 65 ts_dev = np.arange(0, 4 * (2 ** 24), sr) ts_dev_wrapped = ts_dev % 2 ** 24 ts = ticks2sec(ts_dev) vbatt = np.random.randint(0, 100 + 1, len(ts_dev)) m_br = Mock(spec=ShimmerBinaryReader) type(m_br).has_sync = PropertyMock(return_value=False) type(m_br).sample_rate = PropertyMock(return_value=sr) type(m_br).has_global_clock = PropertyMock(return_value=False) type(m_br).start_timestamp = PropertyMock(return_value=0) samples = { EChannelType.VBATT: vbatt, EChannelType.TIMESTAMP: ts_dev_wrapped, } m_br.read_data.return_value = (samples, []) reader = ShimmerReader(bin_reader=m_br) reader.load_file_data() ts_actual = reader.timestamp self.assertEqual(len(ts_actual), len(ts)) np.testing.assert_almost_equal(ts_actual, ts) np.testing.assert_equal(reader[EChannelType.VBATT], vbatt) np.testing.assert_equal(reader.timestamp, reader[EChannelType.TIMESTAMP])
def test_reader_alignment(self): sr = 5 ts_dev = np.array([0, 5, 10, 15, 21, 25, 29, 35]) ts = ticks2sec(ts_dev) vbatt = np.array([93, 85, 78, 74, 71, 68, 65, 64]) samples = { EChannelType.TIMESTAMP: ts_dev, EChannelType.VBATT: vbatt, } m_br = Mock(spec=ShimmerBinaryReader) m_br.read_data.return_value = (samples, []) type(m_br).sample_rate = PropertyMock(return_value=sr) type(m_br).has_sync = PropertyMock(return_value=False) type(m_br).has_global_clock = PropertyMock(return_value=False) type(m_br).start_timestamp = PropertyMock(return_value=0) reader = ShimmerReader(bin_reader=m_br) reader.load_file_data() ts_aligned = reader.timestamp self.assertEqual(len(ts_aligned), len(ts)) vbatt_aligned = reader[EChannelType.VBATT] np.testing.assert_equal(vbatt[ts_aligned == ts], vbatt_aligned[ts_aligned == ts])
def get_rtc(self) -> float: """Retrieve the current value of the real-time clock :return: A floating-point value representing the current value of the real-time clock as UNIX timestamp in seconds """ self._write_packet(UART_GET, UART_COMP_SHIMMER, UART_PROP_CURR_LOCAL_TIME) ticks = self._read_response_wformat_verify(UART_COMP_SHIMMER, UART_PROP_CURR_LOCAL_TIME, '<Q') return ticks2sec(ticks)
def get_config_rtc(self) -> float: """Get the value that was last set for the real-time clock Example: The real-time clock is set to a value of 42s. Subsequent calls to :meth:`get_rtc` will return v > 42s, while :meth:`get_config_rtc` will return 42s. :return: A floating-point value representing the last configured value for the real-time clock as UNIX timestamp in seconds """ self._write_packet(UART_GET, UART_COMP_SHIMMER, UART_PROP_RWC_CFG_TIME) ticks = self._read_response_wformat_verify(UART_COMP_SHIMMER, UART_PROP_RWC_CFG_TIME, '<Q') return ticks2sec(ticks)
def load_file_data(self): samples, sync_offsets = self._bin_reader.read_data() ts_raw = samples.pop(EChannelType.TIMESTAMP) ts_unwrapped = unwrap_device_timestamps(ts_raw) ts_sane = self._apply_clock_offsets(ts_unwrapped) if self._sync and self._bin_reader.has_sync: ts_sane = self._apply_synchronization(ts_sane, *sync_offsets) if self._pp: samples = self._process_signals(samples) ts_unaligned = ticks2sec(ts_sane) if self._realign and not self._is_spaced_equally(ts_sane): self._ts, self._ch_samples = self._realign_samples(ts_unaligned, samples) else: self._ts, self._ch_samples = ts_unaligned, samples
def test_ticks2sec(self): r = ticks2sec(32768) self.assertEqual(r, 1.0) r = ticks2sec(65536) self.assertEqual(r, 2.0)
def receive(self, ser: BluetoothSerial) -> any: t_ticks = ser.read_response(RWC_RESPONSE, arg_format="<Q") return ticks2sec(t_ticks)