diff --git a/dummy_receiver.py b/dummy_receiver.py index 0ca3bdc..2975b9b 100644 --- a/dummy_receiver.py +++ b/dummy_receiver.py @@ -18,7 +18,6 @@ IPC_CREAT = 0o1000 terminate = False - class TDriveData(ctypes.Structure): _fields_ = [ ("caDriveIndex", ctypes.c_char * STR_BUFFER_SIZE), @@ -29,6 +28,7 @@ class TDriveData(ctypes.Structure): ("caDriveShredDuration", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveCapacity", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveState", ctypes.c_char * STR_BUFFER_SIZE), + ("caDriveConnectionType", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveModelFamily", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveModelName", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveSerialnumber", ctypes.c_char * STR_BUFFER_SIZE), @@ -75,6 +75,7 @@ def create_drive_objects(drive_info): smart_error_count=int(drive_info["driveErrors"]), shred_timestamp=int(drive_info["driveShredTimestamp"]), shred_duration=int(drive_info["driveShredDuration"]), + connection_type=drive_info["driveConnectionType"], ) rehdd_info = layouter.ReHddInfo( @@ -88,8 +89,8 @@ def create_drive_objects(drive_info): def worker(queue_id, test_mode=False): try: while not terminate: + time.sleep(3) if test_mode: - time.sleep(3) drive_info = { "driveIndex": "42", "driveHours": 44, @@ -99,6 +100,7 @@ def worker(queue_id, test_mode=False): "driveShredDuration": 0, "driveCapacity": 42, "driveState": "shredded", + "driveConnectionType": "sata", "driveModelFamily": "modelFamily", "driveModelName": "modelName", "driveSerialnumber": "serial", @@ -145,6 +147,7 @@ def worker(queue_id, test_mode=False): ), "driveCapacity": int(d.caDriveCapacity.decode().strip("\x00")), "driveState": d.caDriveState.decode().strip("\x00"), + "driveConnectionType": d.caDriveConnectionType.decode().strip("\x00"), "driveModelFamily": d.caDriveModelFamily.decode().strip("\x00"), "driveModelName": d.caDriveModelName.decode().strip("\x00"), "driveSerialnumber": d.caDriveSerialnumber.decode().strip("\x00"), diff --git a/dummy_sender/main.cpp b/dummy_sender/main.cpp index ea63cb1..5cff79d 100644 --- a/dummy_sender/main.cpp +++ b/dummy_sender/main.cpp @@ -43,23 +43,7 @@ int main(void) sprintf(msgQueueData.driveData.caDriveErrors, "%i", 1); sprintf(msgQueueData.driveData.caDriveShredTimestamp, "%li", 71718LU); sprintf(msgQueueData.driveData.caDriveShredDuration, "%li", 81718LU); - /* - switch (drive->connectionType) - { - case Drive::USB: - strcpy(msgQueueData.driveData.caDriveConnectionType, "usb"); - break; - case Drive::SATA: - strcpy(msgQueueData.driveData.caDriveConnectionType, "sata"); - break; - case Drive::NVME: - strcpy(msgQueueData.driveData.caDriveConnectionType, "nvme"); - break; - case Drive::UNKNOWN: - default: - strcpy(msgQueueData.driveData.caDriveConnectionType, "na"); - } - */ + strcpy(msgQueueData.driveData.caDriveConnectionType, "sata"); sprintf(msgQueueData.driveData.caDriveReHddVersion, REHDD_VERSION); std::cout << "Sending message to queue..." << std::endl; diff --git a/dummy_sender/main.h b/dummy_sender/main.h index 2ed16cd..35445cf 100644 --- a/dummy_sender/main.h +++ b/dummy_sender/main.h @@ -28,7 +28,7 @@ typedef struct char caDriveShredDuration[STR_BUFFER_SIZE]; char caDriveCapacity[STR_BUFFER_SIZE]; char caDriveState[STR_BUFFER_SIZE]; - // char caDriveConnectionType[STR_BUFFER_SIZE]; + char caDriveConnectionType[STR_BUFFER_SIZE]; char caDriveModelFamily[STR_BUFFER_SIZE]; char caDriveModelName[STR_BUFFER_SIZE]; char caDriveSerialnumber[STR_BUFFER_SIZE]; diff --git a/layouter.py b/layouter.py index 57aeace..a8d0583 100644 --- a/layouter.py +++ b/layouter.py @@ -34,6 +34,7 @@ logging.basicConfig( class DriveData: drive_index: int drive_state: str + drive_connection_type: str modelfamily: str modelname: str capacity: int @@ -48,6 +49,7 @@ class DriveData: @dataclasses.dataclass class DriveDataJson: state: str + contype: str fam: str name: str cap: int @@ -61,6 +63,7 @@ class DriveDataJson: @dataclasses.dataclass class DriveDataPrintable: + connectiontype: str modelfamily: str modelname: str capacity: str @@ -132,6 +135,7 @@ def cut_string(max_length, data, direction="end"): def format_to_printable(drive): return DriveDataPrintable( + drive.drive_connection_type, cut_string(20, re.sub(r"[^a-zA-Z0-9. ]", "", drive.modelfamily), "end"), cut_string(20, re.sub(r"[^a-zA-Z0-9. ]", "", drive.modelname), "end"), cut_string(20, human_readable_capacity(drive.capacity), "end"), @@ -149,17 +153,19 @@ def format_to_printable(drive): cut_string(30, str(datetime.timedelta(seconds=drive.shred_duration)), "end"), ) - def draw_text(drawable, printable_data, font_regular, font_bold, font_bold_bigger): """Draws formatted text with Cycles and Errors on one row.""" - + y_start = 4 line_height = 26 label_x = TEXT_X_OFFSET value_offset = 115 right_field_spacing = 200 # Horizontal gap between Cycles and Errors x_capacity = 520 y_capacity = 142 - y_start = 4 + x_connection_type = 600 + y_connection_type = y_start + y_spacing_connection_type = 25 + # Serial Number drawable.text((label_x, y_start), "Serial:", fill=0, font=font_bold) @@ -246,6 +252,49 @@ def draw_text(drawable, printable_data, font_regular, font_bold, font_bold_bigge font=font_bold_bigger, ) + if (printable_data.connectiontype == "sata"): + drawable.text( + (x_connection_type, y_connection_type), + "⬤ SATA", + fill=0, + font=font_regular, + ) + + drawable.text( + (x_connection_type, y_connection_type+y_spacing_connection_type), + "◯ NVME", + fill=0, + font=font_regular, + ) + elif (printable_data.connectiontype == "nvme"): + drawable.text( + (x_connection_type, y_connection_type), + "◯ SATA", + fill=0, + font=font_regular, + ) + + drawable.text( + (x_connection_type, y_connection_type+y_spacing_connection_type), + "⬤ NVME", + fill=0, + font=font_regular, + ) + else: + drawable.text( + (x_connection_type, y_connection_type), + "◯ SATA", + fill=0, + font=font_regular, + ) + + drawable.text( + (x_connection_type, y_connection_type+y_spacing_connection_type), + "◯ NVME", + fill=0, + font=font_regular, + ) + def draw_qr_code(image, data): """ @@ -270,7 +319,6 @@ def draw_qr_code(image, data): region = (5, 5, 5 + QR_CODE_SIZE, 5 + QR_CODE_SIZE) image.paste(qr_img, box=region) - def draw_outline(drawable, margin, width, output_width, output_height): """ Draws a rectangular outline on the drawable canvas. @@ -299,13 +347,13 @@ def draw_outline(drawable, margin, width, output_width, output_height): for line in lines: drawable.line(line, fill=0, width=width) - def generate_image(drive, rehdd_info, output_file): """Generates an image containing drive data and a QR code.""" try: drive_json = DriveDataJson( state=drive.drive_state, + contype=drive.drive_connection_type, fam=drive.modelfamily, name=drive.modelname, cap=drive.capacity, @@ -346,6 +394,7 @@ def main(): temp_drive = DriveData( drive_index=0, + drive_connection_type="sata", drive_state="shredded", modelfamily='Toshiba 2.5" HDD MK..65GSSX', modelname="TOSHIBA MK3265GSDX", diff --git a/output.png b/output.png index 7f9d9dc..58a30f1 100644 Binary files a/output.png and b/output.png differ diff --git a/reHDDPrinter.py b/reHDDPrinter.py index 0d6fa13..8e31a87 100644 --- a/reHDDPrinter.py +++ b/reHDDPrinter.py @@ -43,6 +43,7 @@ class TDriveData(ctypes.Structure): ("caDriveShredDuration", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveCapacity", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveState", ctypes.c_char * STR_BUFFER_SIZE), + ("caDriveConnectionType", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveModelFamily", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveModelName", ctypes.c_char * STR_BUFFER_SIZE), ("caDriveSerialnumber", ctypes.c_char * STR_BUFFER_SIZE), @@ -106,6 +107,7 @@ def create_drive_objects(drive_info): smart_error_count=int(drive_info["driveErrors"]), shred_timestamp=int(drive_info["driveShredTimestamp"]), shred_duration=int(drive_info["driveShredDuration"]), + drive_connection_type=drive_info["driveConnectionType"], ) rehdd_info = layouter.ReHddInfo( @@ -130,9 +132,11 @@ def worker(queue_id, test_mode=False): "driveShredDuration": 0, "driveCapacity": 42, "driveState": "shredded", + "driveConnectionType": "sata", "driveModelFamily": "modelFamily", "driveModelName": "modelName", "driveSerialnumber": "serial", + "driveConnectionType": "sata", "driveReHddVersion": "V1.1.2", } else: @@ -163,9 +167,15 @@ def worker(queue_id, test_mode=False): ), "driveCapacity": int(d.caDriveCapacity.decode().strip("\x00")), "driveState": d.caDriveState.decode().strip("\x00"), + "driveConnectionType": d.caDriveConnectionType.decode().strip( + "\x00" + ), "driveModelFamily": d.caDriveModelFamily.decode().strip("\x00"), "driveModelName": d.caDriveModelName.decode().strip("\x00"), "driveSerialnumber": d.caDriveSerialnumber.decode().strip("\x00"), + "driveConnectionType": d.caDriveConnectionType.decode().strip( + "\x00" + ), "driveReHddVersion": d.caDriveReHddVersion.decode().strip("\x00"), }