Skip to content

Commit

Permalink
Sprint 2 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ikardasevic committed Sep 30, 2024
1 parent 0a7c809 commit 78fdd74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
10 changes: 10 additions & 0 deletions shared/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

def create_temp_copy(filepath:str):
'''Creates a new temporary file and returns the file path of the temporary file.'''
filepath = os.path.abspath(filepath)


temp_folder_path = os.path.join(tempfile.gettempdir(), TEMP_FOLDER_NAME)
os.makedirs(temp_folder_path, exist_ok=True)
Expand All @@ -25,6 +27,7 @@ def create_temp_copy(filepath:str):

def create_temp_from_encrypted(filepath:str, password:str):
'''Creates a new decrypted copy of a file.'''
filepath = os.path.abspath(filepath)

print(filepath)
temp_folder_path = os.path.join(tempfile.gettempdir(), TEMP_FOLDER_NAME)
Expand All @@ -45,6 +48,9 @@ def create_temp_from_encrypted(filepath:str, password:str):

def save_temp_to_file(temp_file_path: str, permanent_file_path: str):
'''Save data from temporary file to a permanent file'''
# Ensure paths are absolute and properly resolved
temp_file_path = os.path.abspath(temp_file_path)
permanent_file_path = os.path.abspath(permanent_file_path)

with open(temp_file_path, 'rb') as temp_file:
data = temp_file.read()
Expand All @@ -54,6 +60,10 @@ def save_temp_to_file(temp_file_path: str, permanent_file_path: str):

def save_temp_to_encrypted(temp_file_path: str, permanent_file_path: str, password:str):
'''Save data from temporary file to an encrypted file.'''
# Ensure paths are absolute and properly resolved
temp_file_path = os.path.abspath(temp_file_path)
permanent_file_path = os.path.abspath(permanent_file_path)

manager = PasswordManager(password)

manager.encrypt_file(temp_file_path)
Expand Down
37 changes: 12 additions & 25 deletions shared/serial_port_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,29 @@
'''

import serial.tools.list_ports
import serial
import os
import serial

class SerialPortController():
'''Serial Port control functions.'''
def __init__(self, setting_file=None):
self.ports_in_used = []
self.baud_rate = 9600
self.byte_size = None
self.parity = None
self.stop_bits = serial.STOPBITS_ONE
self.flow_control = None

self.writer_port = None
self.reader_port = None

if setting_file:
file_path = os.path.abspath(setting_file)
# file = open(file_path, "r")
file = open('C:\\Users\\User\\Downloads\\Mouser_windows-latest\\_internal\\settings\\serial ports\\serial_port_preference.csv', 'r')

file_names = []
for line in file:
file_names.append(line)
if os.name == 'posix':
setting_file_path = os.getcwd() + "/settings/serial ports/" + file_names[0]
else:
setting_file_path = os.getcwd() + "\\settings\\serial ports\\" + file_names[0]
with open(setting_file_path, "r") as file:
for line in file:
self.retrieve_setting([line[0], line[3], line[1], line[4], line[2]])
# Whenever automation is implemented, add the serial port here
# self.set_reader_port(line[6])

# settings = [baud rate, data bits/byte size, parity, stop bits, flow control option]
# file format: baud rate, parity, flow control option, data bits, stop bits, input method (not needed), port



# Dynamically construct the file path
file_path = os.path.join(os.getcwd(), "settings", "serial ports", "preference", setting_file)
try:
with open(file_path, "r") as file:
file_names = [line.strip() for line in file]
except FileNotFoundError:
print(f"Error: The file {file_path} was not found.")

def get_available_ports(self):
'''Returns a list of available system ports.'''
Expand Down Expand Up @@ -122,7 +107,7 @@ def write_to(self, message: str):
byte_message = message.encode()
self.writer_port.write(byte_message)

def close_all_port(self):
def close_all_ports(self):
'''Closes all ports in use.'''
hold = self.ports_in_used
for port_ in hold:
Expand All @@ -138,8 +123,10 @@ def get_reader_port(self):

def get_writer_port(self):
'''Returns the writer port.'''

return self.writer_port


def get_set_RFID(self, rfid: int): #pylint: disable= invalid-name
'''Testing function for map_rfid serial port.'''
message = rfid.encode()
Expand Down

0 comments on commit 78fdd74

Please sign in to comment.