-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec8a329
commit 58eafb6
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- Setup ----------------------------------------------------------------------- | ||
|
||
$ cd "$TESTDIR" | ||
$ EXAMPLEDIR=../mytoolit/examples | ||
|
||
-- Check Read Data Example ----------------------------------------------------- | ||
|
||
Read and store data for five seconds | ||
|
||
$ python $EXAMPLEDIR/store_data.py | ||
|
||
The file should approximately store 47620 (9524 · 5) values | ||
|
||
$ h5dump -d acceleration -H test.hdf5 | | ||
> grep 'DATASPACE SIMPLE' | | ||
> sed -E 's/.*DATASPACE SIMPLE \{ \( ([0-9]+) .*/\1/' | ||
4[5-9]\d{3} (re) | ||
|
||
-- Cleanup --------------------------------------------------------------------- | ||
|
||
$ rm test.hdf5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Read and store some acceleration data of STH with device name Test-STH""" | ||
|
||
# -- Imports ------------------------------------------------------------------ | ||
|
||
from asyncio import run | ||
from functools import partial | ||
from pathlib import Path | ||
from time import time | ||
|
||
from mytoolit.can import Network | ||
from mytoolit.can.streaming import StreamingConfiguration | ||
from mytoolit.measurement import convert_raw_to_g, Storage | ||
|
||
# -- Functions ---------------------------------------------------------------- | ||
|
||
|
||
async def store_streaming_data(identifier): | ||
async with Network() as network: | ||
await network.connect_sensor_device(identifier) | ||
|
||
sensor_range = await network.read_acceleration_sensor_range_in_g() | ||
conversion_to_g = partial(convert_raw_to_g, max_value=sensor_range) | ||
|
||
# Read data for five seconds | ||
start = time() | ||
end = start + 5 | ||
filepath = Path("test.hdf5") | ||
stream_first = StreamingConfiguration(first=True) | ||
|
||
with Storage(filepath, channels=stream_first) as storage: | ||
# Store acceleration range as metadata | ||
storage.add_acceleration_meta( | ||
"Sensor_Range", f"± {sensor_range / 2} g₀" | ||
) | ||
async with network.open_data_stream(first=True) as stream: | ||
async for data, _ in stream: | ||
# Convert from ADC bit value into multiples of g | ||
data.apply(conversion_to_g) | ||
# Store in data file | ||
storage.add_streaming_data(data) | ||
if time() > end: | ||
break | ||
|
||
|
||
# -- Main --------------------------------------------------------------------- | ||
|
||
if __name__ == "__main__": | ||
run(store_streaming_data(identifier="Test-STH")) |