Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHIM3-331 Unit tests for Shimmer Bluetooth communication protocol #20

Merged
merged 48 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
cf41212
SHIM3-331 ground work for BT commands unit tests
marknolan Apr 15, 2024
e299699
SHIM3-331 #time 4d updating get/set commands for unit tests
bhavanarallapalli Apr 26, 2024
c1b698c
Revert "SHIM3-331 #time 4d updating get/set commands for unit tests"
bhavanarallapalli Apr 26, 2024
82ca4c4
SHIM3-331 #time 3d rectified byte allocation and minor changes
bhavanarallapalli May 9, 2024
9b1857f
SHIM-331 #time 3d updated set logic and get byte changes
bhavanarallapalli May 21, 2024
4ff5fbf
SHIM3-331 #time 3h tidying up and adding setUp() at the start
bhavanarallapalli May 28, 2024
e448e27
SHIM3-331 #time 3d writing set command logic and clean up
bhavanarallapalli Jun 10, 2024
3c59428
SHIM3-331 #time 1d putting together all set cases.
bhavanarallapalli Jun 11, 2024
cde82df
SHIM3-331 #time 3d adding missing Set/Get command bytes
bhavanarallapalli Jun 18, 2024
fb6a131
SHIM3-331 #time 1d tidying up and changes to set test cases and reset
bhavanarallapalli Jun 20, 2024
9bbd7ea
SHIM3-331 #time 1h simplifying code
marknolan Jun 20, 2024
44f67c4
SHIM3-331 #time 10m typo fix & updating 4th set function to new approach
marknolan Jun 20, 2024
d57abff
SHIM3-331 #time 1.5h further work on bt unit test get commands
marknolan Jun 20, 2024
953b075
SHIM3-331 #time 10m all but one get commands working
marknolan Jun 20, 2024
0bcee44
SHIM3-331 #time 5m all get commands working
marknolan Jun 20, 2024
e8ec1b4
SHIM3-331 #time 2h modifying set cases
bhavanarallapalli Jun 21, 2024
b7e90c9
SHIM3-331 #time 1h all get commands working properly now
marknolan Jun 21, 2024
819251a
Merge remote-tracking branch 'origin/SHIM3-331_BR' into SHIM3-331
marknolan Jun 21, 2024
66493de
SHIM3-331 #time 1h working on bt unit set commands
marknolan Jun 21, 2024
8a20e17
SHIM3-331 #time 10m set RWC working and minor tidy
marknolan Jun 21, 2024
a0e0612
SHIM3-331 #time 10m working on bt unit test set infomem command
marknolan Jun 21, 2024
3a867eb
SHIM3-331 #time 5m minor code comment
marknolan Jun 21, 2024
3895461
SHIM3-331 #time 1d testing set cases to make it work
bhavanarallapalli Jun 24, 2024
bb9c46e
Merge branch 'SHIM3-331' of
bhavanarallapalli Jun 24, 2024
f13eb6a
SHIM3-331 #time 2h latest updates on BT unit test set infomem/calib
marknolan Jun 24, 2024
5380838
Merge branch 'SHIM3-331' of
marknolan Jun 24, 2024
ee6bb76
SHIM3-331 #time 1h bt unit test created for set ExG and sensors
marknolan Jun 24, 2024
b9d29af
SHIM3-331 #time 5m fix for bt unit test set exp id and shimmer name
marknolan Jun 24, 2024
3748447
SHIM3-331 #time 10m bt unit test bug fix for mag range read
marknolan Jun 24, 2024
c708eb6
SHIM3-331 #time 15m bug fix for bt unit tests get dir cmd
marknolan Jun 24, 2024
8d576e6
SHIM3-331 #time 10m refactoring
marknolan Jun 25, 2024
04a9ba5
SHIM3-331 #time 5m improved console print for byte comparison failure
marknolan Jun 25, 2024
f321e25
SHIM3-331 #time 5m fix for calib dump byte comparison
marknolan Jun 25, 2024
4ba68d3
SHIM3-331 #time 1h further bug fixes and robustness to bt unit tests
marknolan Jun 25, 2024
98f6271
SHIM3-331 #time 1d adding missing unit tests for cmds
bhavanarallapalli Jun 25, 2024
dbd6c1d
SHIM3-331 #time 30m correcting the numbering
bhavanarallapalli Jun 25, 2024
0654845
SHIM3-331 #time 1h work on set daughter card ID
marknolan Jun 25, 2024
ed7f3ef
Merge branch 'SHIM3-331' of
marknolan Jun 25, 2024
1af11b3
SHIM3-331 #time 5m formatting
marknolan Jun 25, 2024
1812472
SHIM3-331 #time 10m adding start/stop streaming cmds
bhavanarallapalli Jun 25, 2024
05065b0
SHIM3-331 #time 10m DAUGHTER_CARD_MEM unit tests working
marknolan Jun 25, 2024
94791e2
Merge branch 'SHIM3-331' of https://github.com/ShimmerResearch/shimme…
marknolan Jun 25, 2024
af2fd58
Merge branch 'SHIM3-331' of
marknolan Jun 25, 2024
1fdcc5d
SHIM3-331 #time 5m handling more cases on get dir unit test
marknolan Jun 25, 2024
7aa2a19
SHIM3-331 #time 5 implementing set sampling rate unit test
marknolan Jun 25, 2024
cf8b57b
SHIM3-331 #time 20m correcting the numbering of unit tests
bhavanarallapalli Jun 26, 2024
bf6e9e7
SHIM3-331 #time 10m revert test strings and minor bug fixes
marknolan Jun 26, 2024
680e85b
SHIM3-331 #time 5m adding last step to reset config calib in Shimmer
marknolan Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions LogAndStream/python_scripts/Bluetooth commands/SpeedTest/speedTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/usr/bin/python
import binascii
import serial
import struct
import sys
import time

from multiprocessing import Process

import speedTestPlot as plot
import speedTestBle as ble

from pc_ble_driver_py.observers import *
import logging

global ser

sleep_interval = 0.05
framesize = 4 # 32-bit counter value
ddata = b""

time_s_overall_start = 0
time_s_current_window_start = 0
num_bytes_total = 0
data_integrity_counter = 0


def wait_for_ack():
global ser
ddata = ""
ack = struct.pack('B', 0xff)
while ddata != ack:
ddata = ser.read(1)
if ddata != ack:
print("0x%02x" % int(ddata[0]))
print("ACK Received")
return


def bt_classic_parser(com_port, q, sample_index):
global ser, num_bytes_total, time_s_overall_start, time_s_current_window_start, ddata, data_integrity_counter

ser = serial.Serial(com_port, 1000000)
ser.flushInput()
logger.info("port opening, done.")

initialise_speed_test_vars()

ser.write(struct.pack('BB', 0xA4, 1))
wait_for_ack()

while 1:
time_s_current = time.time_ns() / 1000000000

buf_len = ser.inWaiting()
if buf_len > 0:
ddata = ddata + ser.read(buf_len)

process_new_data(q, time_s_current)

time.sleep(sleep_interval)


def initialise_speed_test_vars():
global num_bytes_total, time_s_overall_start, time_s_current_window_start, data_integrity_counter
time_s_overall_start = time.time_ns() / 1000000000
time_s_current_window_start = time_s_overall_start
num_bytes_total = 0
data_integrity_counter = 0


def process_new_data(q, time_s_current):
global num_bytes_total, time_s_overall_start, time_s_current_window_start, ddata, data_integrity_counter

counter_values = []
end_index = 0
data_integrity = []
data_integrity_issue_flag = False

if len(ddata) >= framesize:

num_counter_values = len(ddata) // framesize

fmt = '<' + ('I' * num_counter_values)
end_index = num_counter_values * framesize
num_bytes_total += end_index

counter_values = struct.unpack(fmt, ddata[0:end_index])

for sample in counter_values:
data_integrity_issue_flag = True if data_integrity_counter == sample else False
data_integrity_counter = sample + 1
data_integrity.append(data_integrity_issue_flag)

if data_integrity_counter == 2 ** (framesize * 8):
data_integrity_counter = 0

if len(ddata) > end_index:
ddata = ddata[end_index:]

data_rate_current = 0 if end_index == 0 else (end_index / 1024) / (time_s_current - time_s_current_window_start)
data_rate_overall = (num_bytes_total / 1024) / (time_s_current - time_s_overall_start)

plot.plot_data(q, time_s_current_window_start, time_s_current, counter_values, data_rate_current, data_rate_overall, data_integrity)

time_s_current_window_start = time_s_current

sys.stdout.write("\rData Rate: Current = %i KB/s, Overall = %i KB/s, Data integrity = %s" % (data_rate_current, data_rate_overall, "OK" if data_integrity_issue_flag else "Bad"))
sys.stdout.flush()


if __name__ == '__main__':
if len(sys.argv) < 2:
print("no device specified")
print("You need to specify the serial port of the device you wish to connect to")
print("example:")
print(" *.py Com12")
print("or")
print(" *.py /dev/rfcomm0")
else:
plot.setup_plots()

# ble.setup()

# COM15 = A615
# COM3 = D1E8
# COM24 = Shimmer3r 32FD
# COM7 = Shimmer3r 29FD

p = Process(target=bt_classic_parser, args=(sys.argv[1], plot.q, plot.sample_index))
p.start()

plot.start_thread()

# p.terminate()
# p.join()

print("All done")
Loading