diff --git a/.gitignore b/.gitignore index 16ba292..4a706ca 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ _build/* __pycache/ .vscode/c_cpp_properties.json .vscode/settings.json +.idea/ .devenv/ .direnv/ -data/ \ No newline at end of file +data/ diff --git a/.vscode/launch.json b/.vscode/launch.json index 5ff44ba..3dcf0f2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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}", diff --git a/BadgeFramework/audio_parser_V0.py b/BadgeFramework/audio_parser_V0.py index 1562611..a44d55c 100644 --- a/BadgeFramework/audio_parser_V0.py +++ b/BadgeFramework/audio_parser_V0.py @@ -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") diff --git a/BadgeFramework/badge.py b/BadgeFramework/badge.py index e953f14..33a702c 100644 --- a/BadgeFramework/badge.py +++ b/BadgeFramework/badge.py @@ -3,7 +3,7 @@ import logging import sys import struct -import Queue +import queue DEFAULT_SCAN_WINDOW = 250 DEFAULT_SCAN_INTERVAL = 1000 @@ -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 @@ -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) ) ) diff --git a/BadgeFramework/badge_gui.py b/BadgeFramework/badge_gui.py index 3e7912f..b9ca0a5 100644 --- a/BadgeFramework/badge_gui.py +++ b/BadgeFramework/badge_gui.py @@ -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 @@ -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) @@ -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): @@ -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()): @@ -311,7 +311,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='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()): @@ -319,7 +319,7 @@ def initUI(self): 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) @@ -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') @@ -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( "", @@ -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) @@ -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) diff --git a/BadgeFramework/badge_protocol.py b/BadgeFramework/badge_protocol.py index 3aabe20..66e65d9 100644 --- a/BadgeFramework/badge_protocol.py +++ b/BadgeFramework/badge_protocol.py @@ -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(' 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 diff --git a/BadgeFramework/hub_V1.py b/BadgeFramework/hub_V1.py index 39bbd9d..da36679 100644 --- a/BadgeFramework/hub_V1.py +++ b/BadgeFramework/hub_V1.py @@ -33,7 +33,7 @@ try: cur_connection = Connection(int(command),current_mac_addr) except Exception as error: - print (str(error)) + print((str(error))) sys.stdout.flush() continue print ("Connected to the badge. For available commands, please type help.") @@ -51,7 +51,7 @@ print (out) sys.stdout.flush() except Exception as error: - print (str(error)) + print((str(error))) print(" Command not found!") sys.stdout.flush() cur_connection.print_help() diff --git a/BadgeFramework/hub_connection_V1.py b/BadgeFramework/hub_connection_V1.py index f0f3625..74dd826 100644 --- a/BadgeFramework/hub_connection_V1.py +++ b/BadgeFramework/hub_connection_V1.py @@ -32,7 +32,7 @@ def handle_status_request(self): out = self.badge.get_status() return out except Exception as err: - print (str(err)) + print((str(err))) sys.stdout.flush() raise Exception("Could not get status for participant"+ str(self.badge_id)) @@ -90,7 +90,7 @@ def handle_restart_request(self): out = self.badge.restart() return out except Exception as err: - print (str(err)) + print((str(err))) print ("Please wait at least 10 seconds to connect back to the device.") print ("Don't forget to start the recording for the restarted badge.") #raise Exception("Could not restart for participant " + str(self.badge_id)) diff --git a/BadgeFramework/hub_utilities_V1.py b/BadgeFramework/hub_utilities_V1.py index bdc6755..e46c7df 100644 --- a/BadgeFramework/hub_utilities_V1.py +++ b/BadgeFramework/hub_utilities_V1.py @@ -33,7 +33,7 @@ def start_recording_all_devices(df): try: cur_connection=Connection(current_participant,current_mac) except Exception as error: - print(str(error) + ', sensors are not started.') + print((str(error) + ', sensors are not started.')) continue try: cur_connection.set_id_at_start() @@ -50,13 +50,13 @@ def stop_recording_all_devices(df): try: cur_connection=Connection(current_participant,current_mac) except Exception as error: - print(str(error) + ', sensors are not stopped.') + print((str(error) + ', sensors are not stopped.')) continue try: cur_connection.stop_recording_all_sensors() cur_connection.disconnect() except Exception as error: - print(str(error)) + print((str(error))) cur_connection.disconnect() def synchronise_and_check_all_devices(df): @@ -66,19 +66,19 @@ def synchronise_and_check_all_devices(df): try: cur_connection=Connection(current_participant,current_mac) except Exception as error: - print(str(error) + ', cannot synchronise.') + print((str(error) + ', cannot synchronise.')) sys.stdout.flush() continue try: out = cur_connection.handle_status_request() if out.imu_status == 0: - print ('IMU is not recording for participant ' + str(current_participant)) + print(('IMU is not recording for participant ' + str(current_participant))) if out.microphone_status == 0: - print ('Mic is not recording for participant ' + str(current_participant)) + print(('Mic is not recording for participant ' + str(current_participant))) if out.scan_status == 0: - print ('Scan is not recording for participant ' + str(current_participant)) + print(('Scan is not recording for participant ' + str(current_participant))) if out.clock_status == 0: - print ('Cant synch for participant ' + str(current_participant)) + print(('Cant synch for participant ' + str(current_participant))) sys.stdout.flush() cur_connection.disconnect() except Exception as error: diff --git a/BadgeFramework/imu_parser_V0.py b/BadgeFramework/imu_parser_V0.py index db7de64..a23f28f 100644 --- a/BadgeFramework/imu_parser_V0.py +++ b/BadgeFramework/imu_parser_V0.py @@ -52,14 +52,14 @@ def parse_scanner(self): data_bytes = byte[8 + i:16 + i] if (len(data_bytes)) == 8 and (len(ts_bytes) == 8): ts = struct.unpack('