-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve stored calibration data (#17)
* Added new commands * WIP * wip * - Moved examples to examples folder - Tests added for getAllCalibration class - Changes reformatted using PEP8
- Loading branch information
1 parent
4085bc7
commit 4a208b1
Showing
8 changed files
with
328 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import time | ||
|
||
from serial import Serial | ||
|
||
from pyshimmer import ShimmerBluetooth, DEFAULT_BAUDRATE, DataPacket | ||
|
||
|
||
def stream_cb(pkt: DataPacket) -> None: | ||
print(f'Received new data packet: ') | ||
for chan in pkt.channels: | ||
print(f'channel: ' + str(chan)) | ||
print(f'value: ' + str(pkt[chan])) | ||
print('') | ||
|
||
def main(args=None): | ||
serial = Serial('/dev/rfcomm42', DEFAULT_BAUDRATE) | ||
shim_dev = ShimmerBluetooth(serial) | ||
|
||
shim_dev.initialize() | ||
|
||
dev_name = shim_dev.get_device_name() | ||
print(f'My name is: {dev_name}') | ||
|
||
info = shim_dev.get_firmware_version() | ||
print("- firmware: [" + str(info[0]) + "]") | ||
print("- version: [" + str(info[1].major) + "." + str(info[1].minor) + "." + str(info[1].rel) + "]") | ||
|
||
shim_dev.add_stream_callback(stream_cb) | ||
|
||
shim_dev.start_streaming() | ||
time.sleep(5.0) | ||
shim_dev.stop_streaming() | ||
|
||
shim_dev.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,19 @@ | ||
from serial import Serial | ||
|
||
from pyshimmer import ShimmerDock, DEFAULT_BAUDRATE, fmt_hex | ||
|
||
|
||
def main(args=None): | ||
serial = Serial('/dev/ttyECGdev', DEFAULT_BAUDRATE) | ||
|
||
print(f'Connecting docker') | ||
shim_dock = ShimmerDock(serial) | ||
|
||
mac = shim_dock.get_mac_address() | ||
print(f'Device MAC: {fmt_hex(mac)}') | ||
|
||
shim_dock.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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
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,85 @@ | ||
# pyshimmer - API for Shimmer sensor devices | ||
# Copyright (C) 2023 Lukas Magel, Manuel Fernandez-Carmona | ||
|
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
|
||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import struct | ||
from typing import List | ||
|
||
from pyshimmer.util import fmt_hex | ||
|
||
|
||
class AllCalibration: | ||
|
||
def __init__(self, reg_bin: bytes): | ||
self._num_bytes = 84 | ||
self._sensor_bytes = 21 | ||
self._num_sensors = 4 | ||
|
||
if len(reg_bin) < self._num_bytes: | ||
raise ValueError( | ||
f'All calibration data must have length {self._num_bytes}') | ||
|
||
self._reg_bin = reg_bin | ||
|
||
def __str__(self) -> str: | ||
def print_sensor(sens_num: int) -> str: | ||
return f'Sensor {sens_num + 1:2d}\n' + \ | ||
f'\tOffset bias: {self.get_offset_bias(sens_num)}\n' + \ | ||
f'\tSensitivity: {self.get_sensitivity(sens_num)}\n' + \ | ||
f'\tAlignment Matrix: {self.get_ali_mat(sens_num)}\n' | ||
|
||
obj_str = f'' | ||
for i in range(0, self._num_sensors): | ||
obj_str += print_sensor(i) | ||
|
||
reg_bin_str = fmt_hex(self._reg_bin) | ||
obj_str += f'Binary: {reg_bin_str}\n' | ||
|
||
return obj_str | ||
|
||
@property | ||
def binary(self): | ||
return self._reg_bin | ||
|
||
def __eq__(self, other: "AllCalibration") -> bool: | ||
return self._reg_bin == other._reg_bin | ||
|
||
def _check_sens_num(self, sens_num: int) -> None: | ||
if not 0 <= sens_num < (self._num_sensors): | ||
raise ValueError(f'Sensor num must be 0 to {self._num_sensors-1}') | ||
|
||
def get_offset_bias(self, sens_num: int) -> List[int]: | ||
self._check_sens_num(sens_num) | ||
start_offset = sens_num * self._sensor_bytes | ||
end_offset = start_offset + 6 | ||
ans = list(struct.unpack( | ||
'>hhh', self._reg_bin[start_offset:end_offset])) | ||
return ans | ||
|
||
def get_sensitivity(self, sens_num: int) -> List[int]: | ||
self._check_sens_num(sens_num) | ||
start_offset = sens_num * self._sensor_bytes + 6 | ||
end_offset = start_offset + 6 | ||
ans = list(struct.unpack( | ||
'>hhh', self._reg_bin[start_offset:end_offset])) | ||
return ans | ||
|
||
def get_ali_mat(self, sens_num: int) -> List[int]: | ||
self._check_sens_num(sens_num) | ||
start_offset = sens_num * self._sensor_bytes + 12 | ||
end_offset = start_offset + 9 | ||
ans = list(struct.unpack( | ||
'>bbbbbbbbb', self._reg_bin[start_offset:end_offset])) | ||
return ans |
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
Oops, something went wrong.