Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _build/*
__pycache/
.vscode/c_cpp_properties.json
.vscode/settings.json
.idea/
.devenv/
.direnv/
data/
data/
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python test.py",
"cwd": "${workspaceFolder}/BadgeFramework",
"request": "launch",
"type": "debugpy",
"program": "${workspaceFolder}/BadgeFramework/test.py",
"console": "integratedTerminal",
"args": ["de:94:80:39:25:be"]
},
{
"name": "Debug",
"cwd": "${workspaceFolder}",
Expand Down
2 changes: 1 addition & 1 deletion BadgeFramework/audio_parser_V0.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def main(fn):
if (path_raw_input.is_file() and path_raw_input.suffix == "" and
("MICLO" in path_raw_input.stem or "MICHI" in path_raw_input.stem)):

print("Raw input file " + str(path_raw_input))
print(("Raw input file " + str(path_raw_input)))

path_wav_output = path_raw_input.parent / (path_raw_input.stem + ".wav")

Expand Down
20 changes: 10 additions & 10 deletions BadgeFramework/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import sys
import struct
import Queue
import queue
Copy link
Contributor

@Era-Dorta Era-Dorta May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about importing it like this? Does that makes more sense and make the code leaner?

Suggested change
import queue
from queue import Queue

If so, can you do the same for the other files?


DEFAULT_SCAN_WINDOW = 250
DEFAULT_SCAN_INTERVAL = 1000
Expand Down Expand Up @@ -46,14 +46,14 @@ def timestamps_to_time(timestamp_seconds, timestamp_miliseconds):
class OpenBadge(object):
def __init__(self, connection):
self.connection = connection
self.status_response_queue = Queue.Queue()
self.start_microphone_response_queue = Queue.Queue()
self.start_scan_response_queue = Queue.Queue()
self.start_imu_response_queue = Queue.Queue()
self.free_sdc_space_response_queue = Queue.Queue()
self.sdc_errase_all_response_queue = Queue.Queue()
self.get_imu_data_response_queue = Queue.Queue()
self.get_fw_version_response_queue = Queue.Queue()
self.status_response_queue = queue.Queue()
self.start_microphone_response_queue = queue.Queue()
self.start_scan_response_queue = queue.Queue()
self.start_imu_response_queue = queue.Queue()
self.free_sdc_space_response_queue = queue.Queue()
self.sdc_errase_all_response_queue = queue.Queue()
self.get_imu_data_response_queue = queue.Queue()
self.get_fw_version_response_queue = queue.Queue()


# Helper function to send a BadgeMessage `command_message` to a device, expecting a response
Expand Down Expand Up @@ -88,7 +88,7 @@ def send_request(self, request_message):

logger.debug(
"Sending: {}, Raw: {}".format(
request_message, serialized_request.encode("hex")
request_message, str(serialized_request)
)
)

Expand Down
36 changes: 18 additions & 18 deletions BadgeFramework/badge_gui.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Tkinter as tk
import ttk
from Tkinter import Label, Button, Canvas
import tkFont
import tkinter as tk
import tkinter.ttk
from tkinter import Label, Button, Canvas
import tkinter.font
import random
import time
import csv
from badge_interface import *
from .badge_interface import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure

Expand Down Expand Up @@ -43,9 +43,9 @@ def initUI(self):
# Device info
self.badgeId = Label(self, text="Badge ID: {}".format(self.name))
self.badgeId.grid(row=0, column=0, padx=10, pady=5)
self.midge = Label(self, text=self.address, font=tkFont.Font(size=12))
self.midge = Label(self, text=self.address, font=tkinter.font.Font(size=12))
self.midge.grid(row=1, column=0, padx=10, pady=5)
self.midge = Label(self, text="FW: {}".format(self.badge.get_fw_version().version), font=tkFont.Font(size=12))
self.midge = Label(self, text="FW: {}".format(self.badge.get_fw_version().version), font=tk.font.Font(size=12))
self.midge.grid(row=2, column=0, padx=10, pady=5)
self.battery = Label(self, text='Battery: {}%'.format(self.badge_status.battery_level), relief="solid")
self.battery.grid(row=3, column=0, padx=10, pady=5)
Expand Down Expand Up @@ -222,7 +222,7 @@ def __init__(self, parent, imu_status):
def initUI(self):
info = ["acc_fsr (g): 16", "gyr_fsr (dps): 2000", "datarate: 50"]

title = tk.Label(self.top_frame, text='IMU Data', font=tkFont.Font(size=10, weight="bold"))
title = tk.Label(self.top_frame, text='IMU Data', font=tkinter.font.Font(size=10, weight="bold"))
title.grid(row=0, column=0, columnspan=2, sticky='w')
# Create information header
for i, text in enumerate(info):
Expand Down Expand Up @@ -278,7 +278,7 @@ def initUI(self):
top_frame.grid(row=0, column=0, sticky='nsew')
table.grid(row=1, column=0, sticky='nsew')

title = tk.Label(top_frame, text='Microphones Data', font=tkFont.Font(size=10, weight="bold"))
title = tk.Label(top_frame, text='Microphones Data', font=tkinter.font.Font(size=10, weight="bold"))
title.grid(row=0, column=0, columnspan=2, sticky='w')
# Loop over the dictionary and create labels
for i, (key, value) in enumerate(self.info.items()):
Expand Down Expand Up @@ -311,15 +311,15 @@ def initUI(self):
top_frame.grid(row=0, column=0, sticky='nsew')
table.grid(row=1, column=0, sticky='nsew')

title = tk.Label(top_frame, text='Scanner Data', font=tkFont.Font(size=10, weight="bold"))
title = tk.Label(top_frame, text='Scanner Data', font=tkinter.font.Font(size=10, weight="bold"))
title.grid(row=0, column=0, columnspan=2, sticky='w')
# Loop over the dictionary and create labels
for i, (key, value) in enumerate(self.info.items()):
label_text = "{}: {}".format(key, value)
label = tk.Label(top_frame, text=label_text)
label.grid(row=i+1, column=0, columnspan=2, sticky='w')

table_title = tk.Label(table, text='RSSI', font=tkFont.Font( weight="bold"), relief=tk.RIDGE, width=45)
table_title = tk.Label(table, text='RSSI', font=tkinter.font.Font( weight="bold"), relief=tk.RIDGE, width=45)
table_title.grid(row=0, column=0, sticky="nsew")
for i, e in enumerate(self.data):
label = tk.Label(table, text=str(e), relief=tk.RIDGE, width=45)
Expand Down Expand Up @@ -381,11 +381,11 @@ def initUI(self):
right_down.grid(row=1, column=1, sticky='nsew')

# header
self.badgeId = Label(left_top, text="Badge Id: {}".format(self.name), font=tkFont.Font(size=10, ))
self.badgeId = Label(left_top, text="Badge Id: {}".format(self.name), font=tkinter.font.Font(size=10, ))
self.badgeId.grid(row=0, column=0, columnspan=2, sticky='w')
self.midge = Label(left_top, text="Battery: {}%".format(self.status.battery_level), font=tkFont.Font(size=10))
self.midge = Label(left_top, text="Battery: {}%".format(self.status.battery_level), font=tkinter.font.Font(size=10))
self.midge.grid(row=1, column=0, columnspan=2, sticky='w')
self.battery = Label(left_top, text="Available memory: {}MB".format(self.free_space), font=tkFont.Font(size=10))
self.battery = Label(left_top, text="Available memory: {}MB".format(self.free_space), font=tkinter.font.Font(size=10))
self.battery.grid(row=2, column=0, columnspan=2, sticky='w')
self.reset_battery = Button(left_top, text='Erase', command=self.badge.sdc_errase_all)
self.reset_battery.grid(row=2, column=1, columnspan=2, sticky='w')
Expand Down Expand Up @@ -480,8 +480,8 @@ def __init__(self):
self.geometry("1100x700")

self.canvas = tk.Canvas(self)
self.scrollbar = ttk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.container_frame = ttk.Frame(self.canvas)
self.scrollbar = tkinter.ttk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.container_frame = tkinter.ttk.Frame(self.canvas)

self.container_frame.bind(
"<Configure>",
Expand All @@ -504,7 +504,7 @@ def __init__(self):
separator = tk.Frame(self.canvas, height=2, bg="black")
separator.pack(side=tk.TOP, fill=tk.X, pady=5)

self.all_label = Label(self.all_badges_buttons_frame, text="All badges:", font=tkFont.Font(size=12))
self.all_label = Label(self.all_badges_buttons_frame, text="All badges:", font=tk.font.Font(size=12))
self.all_label.pack(side="left", padx=(15, 0))

self.start_all_button = Button(self.all_badges_buttons_frame, text="Start", command=self.start_all_midges)
Expand All @@ -513,7 +513,7 @@ def __init__(self):
self.stop_all_button = Button(self.all_badges_buttons_frame, text="Stop", command=self.stop_all_midges)
self.stop_all_button.pack(side="left", padx=10)

self.all_sensors_label = Label(self.all_badges_buttons_frame, text="Sensors:", font=tkFont.Font(size=12))
self.all_sensors_label = Label(self.all_badges_buttons_frame, text="Sensors:", font=tk.font.Font(size=12))
self.all_sensors_label.pack(side="left", padx=(15, 0))

self.imu_checkbox_var = tk.IntVar(value=1)
Expand Down
66 changes: 33 additions & 33 deletions BadgeFramework/badge_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,29 +978,29 @@ def decode_internal(self, istream):
def decode_clock_status(self, istream):
#print("decode_clock_status:", istream.buf)
#print("decode_clock_status:", istream.read(1))
self.clock_status= struct.unpack('<B', istream.buf[3])[0]
self.clock_status= struct.unpack('<B', istream.buf[3:4])[0]

def decode_microphone_status(self, istream):
#print("decode_microphone_status: ", i)
self.microphone_status= struct.unpack('<B', istream.buf[4])[0]
self.microphone_status= struct.unpack('<B', istream.buf[4:5])[0]

def decode_scan_status(self, istream):
#print("decode_scan_status: ", i)
self.scan_status= struct.unpack('<B', istream.buf[5])[0]
self.scan_status= struct.unpack('<B', istream.buf[5:6])[0]

def decode_imu_status(self, istream):
#print("decode_imu_status: ", i)
self.imu_status= struct.unpack('<B', istream.buf[6])[0]
self.imu_status= struct.unpack('<B', istream.buf[6:7])[0]

def decode_battery_level(self, istream):
#print("decode_battery_level: ", i)
self.battery_level= struct.unpack('<B', istream.buf[7])[0]
self.battery_level= struct.unpack('<B', istream.buf[7:8])[0]

def decode_pdm_data(self, istream):
self.pdm_data= (struct.unpack('<b', istream.buf[13])[0] << 16) + (struct.unpack('<B', (istream.buf[12]))[0]<< 8)+ struct.unpack('<B', (istream.buf[11]))[0]
self.pdm_data= (struct.unpack('<b', istream.buf[13:14])[0] << 16) + (struct.unpack('<B', (istream.buf[12:13]))[0]<< 8)+ struct.unpack('<B', (istream.buf[11:12]))[0]

def decode_scan_data(self, istream):
self.scan_data= (struct.unpack('<b', istream.buf[10])[0] << 8) + struct.unpack('<B', (istream.buf[9]))[0]
self.scan_data= (struct.unpack('<b', istream.buf[10:11])[0] << 8) + struct.unpack('<B', (istream.buf[9:10]))[0]

def decode_timestamp(self, istream):
self.timestamp = Timestamp()
Expand Down Expand Up @@ -1078,16 +1078,16 @@ def decode_timestamp(self, istream):
self.timestamp.decode_internal(istream)

def decode_mode(self, istream):
self.mode= struct.unpack('<b', istream.buf[3])[0]
self.mode= struct.unpack('<b', istream.buf[3:4])[0]

def decode_gain_l(self, istream):
self.gain_l= struct.unpack('<b', istream.buf[4])[0]
self.gain_l= struct.unpack('<b', istream.buf[4:5])[0]

def decode_gain_r(self, istream):
self.gain_r= struct.unpack('<b', istream.buf[5])[0]
self.gain_r= struct.unpack('<b', istream.buf[5:6])[0]

def decode_switch_pos(self, istream):
self.switch_pos= struct.unpack('<b', istream.buf[6])[0]
self.switch_pos= struct.unpack('<b', istream.buf[6:7])[0]

def decode_pdm_freq(self, istream):
self.pdm_freq= struct.unpack('<H', istream.buf[7:9])[0]
Expand Down Expand Up @@ -1146,10 +1146,10 @@ def decode_timestamp(self, istream):
self.timestamp.decode_internal(istream)

def decode_window(self, istream):
self.window= (struct.unpack('<B', istream.buf[4])[0] << 8) + struct.unpack('<B', (istream.buf[3]))[0]
self.window= (struct.unpack('<B', istream.buf[4:5])[0] << 8) + struct.unpack('<B', (istream.buf[3:4]))[0]

def decode_interval(self, istream):
self.interval= (struct.unpack('<B', istream.buf[6])[0] << 8) + struct.unpack('<B', (istream.buf[5]))[0]
self.interval= (struct.unpack('<B', istream.buf[6:7])[0] << 8) + struct.unpack('<B', (istream.buf[5:6]))[0]


class StartImuResponse:
Expand Down Expand Up @@ -1214,17 +1214,17 @@ def decode_timestamp(self, istream):
self.timestamp.decode_internal(istream)

def decode_self_test_done(self, istream):
self.self_test_done= struct.unpack('<B', istream.buf[3])[0]
self.self_test_done= struct.unpack('<B', istream.buf[3:4])[0]

def decode_acc_fsr(self, istream):
self.gyr_fsr = (struct.unpack('<B', istream.buf[8])[0] << 32) + (struct.unpack('<B', istream.buf[7])[0] << 16) + (struct.unpack('<B', istream.buf[6])[0] << 8) + (struct.unpack('<B', (istream.buf[5]))[0])
self.gyr_fsr = (struct.unpack('<B', istream.buf[8:9])[0] << 32) + (struct.unpack('<B', istream.buf[7:8])[0] << 16) + (struct.unpack('<B', istream.buf[6:7])[0] << 8) + (struct.unpack('<B', (istream.buf[5:6]))[0])

def decode_gyr_fsr(self, istream):
self.acc_fsr = (struct.unpack('<B', istream.buf[12])[0] << 32) + (struct.unpack('<B', istream.buf[11])[0] << 16) + (struct.unpack('<B', istream.buf[10])[0] << 8) + (struct.unpack('<B', (istream.buf[9]))[0])
self.acc_fsr = (struct.unpack('<B', istream.buf[12:13])[0] << 32) + (struct.unpack('<B', istream.buf[11:12])[0] << 16) + (struct.unpack('<B', istream.buf[10:11])[0] << 8) + (struct.unpack('<B', (istream.buf[9:10]))[0])

def decode_datarate(self, istream):
#print("datarate:", istream.buf)
self.datarate = struct.unpack('<B', istream.buf[13])[0]
self.datarate = struct.unpack('<B', istream.buf[13:14])[0]


class FreeSDCSpaceResponse:
Expand Down Expand Up @@ -1276,11 +1276,11 @@ def decode_internal(self, istream):
pass

def decode_total_space(self, istream):
print(" total space",istream.buf)
self.total_space= (struct.unpack('<b', istream.buf[6])[0] << 32) + (struct.unpack('<b', istream.buf[5])[0] << 16) + (struct.unpack('<b', istream.buf[4])[0] << 8) + (struct.unpack('<b', (istream.buf[3]))[0])
print((" total space",istream.buf))
self.total_space= (struct.unpack('<b', istream.buf[6:7])[0] << 32) + (struct.unpack('<b', istream.buf[5:6])[0] << 16) + (struct.unpack('<b', istream.buf[4:5])[0] << 8) + (struct.unpack('<b', (istream.buf[3:4]))[0])

def decode_free_space(self, istream):
self.free_space= (struct.unpack('<b', istream.buf[10])[0] << 32) + (struct.unpack('<b', istream.buf[9])[0] << 16) + (struct.unpack('<b', istream.buf[8])[0] << 8) + (struct.unpack('<b', (istream.buf[7]))[0])
self.free_space= (struct.unpack('<b', istream.buf[10:11])[0] << 32) + (struct.unpack('<b', istream.buf[9:10])[0] << 16) + (struct.unpack('<b', istream.buf[8:9])[0] << 8) + (struct.unpack('<b', (istream.buf[7:8]))[0])

def decode_timestamp(self, istream):
self.timestamp = Timestamp()
Expand Down Expand Up @@ -1329,7 +1329,7 @@ def decode_internal(self, istream):
pass

def decode_done_errase(self, istream):
self.done_errase= struct.unpack('<B', istream.buf[3])[0]
self.done_errase= struct.unpack('<B', istream.buf[3:4])[0]

def decode_timestamp(self, istream):
self.timestamp = Timestamp()
Expand Down Expand Up @@ -1448,40 +1448,40 @@ def decode_internal(self, istream):
pass

def decode_gyr_x(self, istream):
self.gyr_x= float((struct.unpack('<b', istream.buf[4])[0] << 8) + struct.unpack('<B', (istream.buf[3]))[0])/float(10000)
self.gyr_x= float((struct.unpack('<b', istream.buf[4:5])[0] << 8) + struct.unpack('<B', (istream.buf[3:4]))[0])/float(10000)

def decode_gyr_y(self, istream):
self.gyr_y= float((struct.unpack('<b', istream.buf[6])[0] << 8) + struct.unpack('<B', (istream.buf[5]))[0])/float(10000)
self.gyr_y= float((struct.unpack('<b', istream.buf[6:7])[0] << 8) + struct.unpack('<B', (istream.buf[5:6]))[0])/float(10000)

def decode_gyr_z(self, istream):
self.gyr_z= float((struct.unpack('<b', istream.buf[8])[0] << 8) + struct.unpack('<B', (istream.buf[7]))[0])/float(10000)
self.gyr_z= float((struct.unpack('<b', istream.buf[8:9])[0] << 8) + struct.unpack('<B', (istream.buf[7:8]))[0])/float(10000)

def decode_mag_x(self, istream):
self.mag_x= float((struct.unpack('<b', istream.buf[10])[0] << 8) + struct.unpack('<B', (istream.buf[9]))[0])/float(10000)
self.mag_x= float((struct.unpack('<b', istream.buf[10:11])[0] << 8) + struct.unpack('<B', (istream.buf[9:10]))[0])/float(10000)

def decode_mag_y(self, istream):
self.mag_y= float((struct.unpack('<b', istream.buf[12])[0] << 8) + struct.unpack('<B', (istream.buf[11]))[0])/float(10000)
self.mag_y= float((struct.unpack('<b', istream.buf[12:13])[0] << 8) + struct.unpack('<B', (istream.buf[11:12]))[0])/float(10000)

def decode_mag_z(self, istream):
self.mag_z= float((struct.unpack('<b', istream.buf[14])[0] << 8) + struct.unpack('<B', (istream.buf[13]))[0])/float(10000)
self.mag_z= float((struct.unpack('<b', istream.buf[14:15])[0] << 8) + struct.unpack('<B', (istream.buf[13:14]))[0])/float(10000)

def decode_acc_x(self, istream):
self.acc_x= float((struct.unpack('<b', istream.buf[16])[0] << 8) + struct.unpack('<B', (istream.buf[15]))[0])/float(10000)
self.acc_x= float((struct.unpack('<b', istream.buf[16:17])[0] << 8) + struct.unpack('<B', (istream.buf[15:16]))[0])/float(10000)

def decode_acc_y(self, istream):
self.acc_y= float((struct.unpack('<b', istream.buf[18])[0] << 8) + struct.unpack('<B', (istream.buf[17]))[0])/float(10000)
self.acc_y= float((struct.unpack('<b', istream.buf[18:19])[0] << 8) + struct.unpack('<B', (istream.buf[17:18]))[0])/float(10000)

def decode_acc_z(self, istream):
self.acc_z= float((struct.unpack('<b', istream.buf[20])[0] << 8) + struct.unpack('<B', (istream.buf[19]))[0])/float(10000)
self.acc_z= float((struct.unpack('<b', istream.buf[20:21])[0] << 8) + struct.unpack('<B', (istream.buf[19:20]))[0])/float(10000)

def decode_rot_x(self, istream):
self.rot_x= float((struct.unpack('<b', istream.buf[22])[0] << 8) + struct.unpack('<B', (istream.buf[21]))[0])/float(10000)
self.rot_x= float((struct.unpack('<b', istream.buf[22:23])[0] << 8) + struct.unpack('<B', (istream.buf[21:22]))[0])/float(10000)

def decode_rot_y(self, istream):
self.rot_y= float((struct.unpack('<b', istream.buf[24])[0] << 8) + struct.unpack('<B', (istream.buf[23]))[0])/float(10000)
self.rot_y= float((struct.unpack('<b', istream.buf[24:25])[0] << 8) + struct.unpack('<B', (istream.buf[23:24]))[0])/float(10000)

def decode_rot_z(self, istream):
self.rot_z= float((struct.unpack('<b', istream.buf[26])[0] << 8) + struct.unpack('<B', (istream.buf[25]))[0])/float(10000)
self.rot_z= float((struct.unpack('<b', istream.buf[26:27])[0] << 8) + struct.unpack('<B', (istream.buf[25:26]))[0])/float(10000)

def decode_timestamp(self, istream):
self.timestamp = Timestamp()
Expand Down
12 changes: 6 additions & 6 deletions BadgeFramework/ble_badge_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from bluepy.btle import UUID, Peripheral, DefaultDelegate, AssignedNumbers ,Scanner
from bluepy.btle import BTLEException
import struct
import Queue
import queue

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,7 +74,7 @@ def __init__(self, ble_device):


# Contains the bytes recieved from the device. Held here until an entire message is recieved.
self.rx_queue = Queue.Queue()
self.rx_queue = queue.Queue()


BadgeConnection.__init__(self)
Expand All @@ -93,10 +93,10 @@ def get_connection_to_badge(cls, device_addr, timeout_seconds=10.0):
# primitives to send data to other threads.

def received(self,data):
logger.debug("Recieved {}".format(data.encode("hex")))
logger.debug("Recieved {}".format(str(data)))

for b in data:
self.rx_queue.put(b)
for i in range(len(data)):
self.rx_queue.put(data[i:i+1])


# Implements BadgeConnection's connect() spec.
Expand Down Expand Up @@ -153,7 +153,7 @@ def await_data(self, data_len):
if rx_bytes_expected > 0:
while True:
while(not self.rx_queue.empty()):
rx_message += self.rx_queue.get()
rx_message += str(self.rx_queue.get())
if(len(rx_message) == rx_bytes_expected):
return rx_message

Expand Down
Loading