updated analysis software

This commit is contained in:
ggw
2026-05-11 12:50:35 -07:00
parent 74debab835
commit 19e646286f
3 changed files with 72 additions and 42 deletions
+7 -3
View File
@@ -12,11 +12,15 @@ async def scan():
async def connect(device): async def connect(device):
async with BleakClient(device) as client: async with BleakClient(device) as client:
value = b'6' await client.write_gatt_char(TX_UUID, b'4', response=True)
await client.write_gatt_char(TX_UUID, value, response=True) await client.write_gatt_char(TX_UUID, b'6', response=True)
await client.stop_notify(RX_UUID) await client.stop_notify(RX_UUID)
await client.start_notify(RX_UUID, cb) await client.start_notify(RX_UUID, cb)
await asyncio.sleep(10000) await asyncio.sleep(60)
#await client.write_gatt_char(TX_UUID, b'2', response=True)
#await client.write_gatt_char(TX_UUID, b'S', response=True)
await client.stop_notify(RX_UUID)
#await asyncio.sleep(5)
RX_UUID = "00000001-8E22-4541-9D4C-21EDAE82ED19" RX_UUID = "00000001-8E22-4541-9D4C-21EDAE82ED19"
TX_UUID = "00000000-8E22-4541-9D4C-21EDAE82ED19" TX_UUID = "00000000-8E22-4541-9D4C-21EDAE82ED19"
+49 -39
View File
@@ -72,8 +72,9 @@ def process_ppg(d, t):
accs = [] accs = []
gyros = [] gyros = []
imu_sparse = 0
def process_imu(d, t): def process_imu(d, t):
global accs, gyros global accs, gyros, imu_sparse
for e in t['elements']: for e in t['elements']:
block = d[e['offset']:e['offset'] + e['size']] block = d[e['offset']:e['offset'] + e['size']]
element_size = int(len(block) / e['n_elements']) element_size = int(len(block) / e['n_elements'])
@@ -91,58 +92,67 @@ def process_imu(d, t):
else: else:
pass pass
#assert False #assert False
if len(gyros) > 400:
gyros = gyros[-400:] imu_sparse += 1
if len(accs) > 400: if imu_sparse % 5 == 4:
accs = accs[-400:] if len(gyros) > 1600:
fig, axs = plt.subplots(2) gyros = gyros[-1600:]
g = np.array(gyros) accs = accs[-1600:]
a = np.array(accs) fig, axs = plt.subplots(2)
axs[0].set_ylabel("dps") g = np.array(gyros)
axs[0].plot(g[:,0]) a = np.array(accs)
axs[0].plot(g[:,1]) #np.save("gyros.npy", g)
axs[0].plot(g[:,2]) #np.save("accs.npy", a)
axs[1].set_ylabel("g") a -= np.mean(a, axis = 0).reshape(1,3)
axs[1].plot(a[:,0]) axs[0].set_ylabel("dps")
axs[1].plot(a[:,1]) axs[0].plot(g[:,0])
axs[1].plot(a[:,2]) axs[0].plot(g[:,1])
plt.savefig("acc_gyro.png") axs[0].plot(g[:,2])
plt.close() axs[1].set_ylabel("g")
axs[1].plot(a[:,0])
axs[1].plot(a[:,1])
axs[1].plot(a[:,2])
plt.savefig("acc_gyro.png")
plt.close()
ecgs = [] ecgs = []
t1s = [] t1s = []
t2s = [] t2s = []
strains = [] strains = []
adc_sparse = 0
def process_adc(d, t): def process_adc(d, t):
global ecgs, t1s, t2s, strains global ecgs, t1s, t2s, strains, adc_sparse
for e in t['elements']: for e in t['elements']:
block = d[e['offset']:e['offset'] + e['size']] block = d[e['offset']:e['offset'] + e['size']]
element_size = int(len(block) / e['n_elements']) element_size = int(len(block) / e['n_elements'])
if e['name'] == b'ekg_readings_cnts[50]': if e['name'] == b'ekg_readings_cnts[50]':
ecgs = ecgs + [(2.4 / (1<<24)) * int.from_bytes(block[4 * i : 4 * i + 4], byteorder = 'little', signed = True) for i in range(50)] ecgs = ecgs + [(2.4 / (1<<24)) * int.from_bytes(block[4 * i : 4 * i + 4], byteorder = 'little', signed = True) for i in range(50)]
if len(ecgs) > 200: adc_sparse += 1
ecgs = ecgs[-2048:] if adc_sparse % 10 == 9:
t1s = t1s[-205:] if len(ecgs) > 200:
t2s = t2s[-205:] ecgs = ecgs[-2048:]
strains = strains[-205:] t1s = t1s[-205:]
fig, axs = plt.subplots(4) t2s = t2s[-205:]
axs[0].set_title("ECG") strains = strains[-205:]
axs[1].set_title("Strain") fig, axs = plt.subplots(1)
axs[2].set_title("oT") axs.set_title("ECG")
axs[3].set_title("iT") #axs[1].set_title("Strain")
axs[0].plot(ecgs) #axs[2].set_title("oT")
axs[1].plot(strains) #axs[3].set_title("iT")
axs[2].plot(t1s) axs.plot(ecgs)
axs[3].plot(t2s) #axs[1].plot(strains)
plt.savefig("adcs.png") #axs[2].plot(t1s)
plt.close() #axs[3].plot(t2s)
fig.tight_layout()
plt.savefig("adcs.png")
plt.close()
if e['name'] == b'str_readings_cnts[5]': if e['name'] == b'str_readings_cnts[5]':
strains = strains + [(2.4 / (1<<24)) * int.from_bytes(block[4 * i : 4 * i + 4], byteorder = 'little', signed = True) for i in range(5)] strains = strains + [int.from_bytes(block[4 * i : 4 * i + 4], byteorder = 'little', signed = True) for i in range(5)]
if e['name'] == b'oT_readings_cnts[5]': if e['name'] == b'oT_readings_cnts[5]':
t1s = t1s + [(2.4 / (1<<24)) * int.from_bytes(block[4 * i : 4 * i + 4], byteorder = 'little', signed = True) for i in range(5)] t1s = t1s + [int.from_bytes(block[4 * i : 4 * i + 4], byteorder = 'little', signed = True) for i in range(5)]
if e['name'] == b'iT_readings_cnts[5]': if e['name'] == b'iT_readings_cnts[5]':
t2s = t2s + [(2.4 / (1<<24)) * int.from_bytes(block[4 * i : 4 * i + 4], byteorder = 'little', signed = True) for i in range(5)] t2s = t2s + [int.from_bytes(block[4 * i : 4 * i + 4], byteorder = 'little', signed = True) for i in range(5)]
def read_and_process(types, cons, size): def read_and_process(types, cons, size):
index = 0 index = 0
+16
View File
@@ -0,0 +1,16 @@
from packet_parser_helpers import *
import time
log = open('first_real.LOG','rb').read()
types = get_type_list(packet_definitions)
index = 493
while index < len(log):
size = int.from_bytes(log[index:index + 4], byteorder = 'little', signed = False)
print("INDEX: " + str(index) + " SIZE: " + str(size) + " FILESIZE: " + str(len(log)))
cons = log[index + 4 : index + 4 + size]
read_and_process(types, cons, size)
#time.sleep(0.1)
index += 4 + size