diff --git a/README.md b/README.md index 1871519..f59812a 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,37 @@ # reHDDPrinter # -Generate label and print them via brother_ql to +- Generate label and print them via brother QL-570. +- Receive data from [reHDD](https://git.mosad.xyz/localhorst/reHDD) via IPC message queue. -## Printer usage ## +# Install # + +`pip install qrcode sysv-ipc pycstruct` + +``` +cd /root/ +git clone https://git.mosad.xyz/localhorst/reHDDPrinter.git +cd reHDDPrinter +chmod +x reHDDPrinter.py +cp reHDDPrinter.service /lib/systemd/system/reHDDPrinter.service +systemctl daemon-reload +systemctl enable /lib/systemd/system/reHDDPrinter.service +``` + +## Test printer manually ## ``` export BROTHER_QL_PRINTER=file:///dev/usb/lp0 export BROTHER_QL_MODEL=QL-570 ``` - - `brother_ql print -l 62 Untitled.png` ## Printer/Paper Info ## +- Brother QL-570 +- Paper With: 62mm or 696px -Brother QL-570 - -Paper With: 62mm or 696px - - -## Install ## see https://github.com/pklaus/brother_ql -pip install qrcode diff --git a/output.png b/output.png index 1dda8ff..6efa03a 100644 Binary files a/output.png and b/output.png differ diff --git a/reHDDPrinter.py b/reHDDPrinter.py index c901f39..7a9c099 100644 --- a/reHDDPrinter.py +++ b/reHDDPrinter.py @@ -6,29 +6,58 @@ Date of last modification: 2022/11/23 """ +import sysv_ipc +import pycstruct import layouter +str_buffer_size = 64 #keep this synchronous to reHDD +msg_queue_key = 0x1B11193C0 #keep this synchronous to reHDD + +def get_struct_format(): + #keep this synchronous to struct in reHDD + driveData = pycstruct.StructDef() + driveData.add('utf-8', 'driveIndex', length=str_buffer_size) + driveData.add('utf-8', 'driveHours', length=str_buffer_size) + driveData.add('utf-8', 'driveCycles', length=str_buffer_size) + driveData.add('utf-8', 'driveErrors', length=str_buffer_size) + driveData.add('utf-8', 'driveShredTimestamp', length=str_buffer_size) + driveData.add('utf-8', 'driveShredDuration', length=str_buffer_size) + driveData.add('utf-8', 'driveCapacity', length=str_buffer_size) + driveData.add('utf-8', 'driveState', length=str_buffer_size) + driveData.add('utf-8', 'driveModelFamiliy', length=str_buffer_size) + driveData.add('utf-8', 'driveModelName', length=str_buffer_size) + driveData.add('utf-8', 'driveSerialnumber', length=str_buffer_size) + driveData.add('utf-8', 'driveReHddVersion', length=str_buffer_size) + return driveData def main(): + try: + mq = sysv_ipc.MessageQueue(msg_queue_key, sysv_ipc.IPC_CREAT) - rehdd_info = layouter.ReHddInfo("https://git.mosad.xyz/localhorst/reHDD", "bV0.2.2") # read this from rehdd process + while True: + message, mtype = mq.receive() + driveData = get_struct_format().deserialize(message) + + rehdd_info = layouter.ReHddInfo("https://git.mosad.xyz/localhorst/reHDD", driveData['driveReHddVersion']) - temp_drive = layouter.DriveData( - drive_index=0,\ - drive_state="shredded",\ - modelfamiliy="Toshiba 2.5\\ HDD MK..65GSSX",\ - modelname="TOSHIBA MK3265GSDX",\ - capacity=343597383680,\ - serialnumber="YG6742U56UDRL123",\ - power_on_hours=7074,\ - power_cycle=4792,\ - smart_error_count=1,\ - shred_timestamp=1647937421,\ - shred_duration=81718) + drive = layouter.DriveData( + drive_index=int(driveData['driveIndex']),\ + drive_state=str(driveData['driveState']),\ + modelfamiliy=str(driveData['driveModelFamiliy']),\ + modelname=str(driveData['driveModelName']),\ + capacity=int(driveData['driveCapacity']),\ + serialnumber=str(driveData['driveSerialnumber']),\ + power_on_hours=int(driveData['driveHours']),\ + power_cycle=int(driveData['driveCycles']),\ + smart_error_count=int(driveData['driveErrors']),\ + shred_timestamp=int(driveData['driveShredTimestamp']),\ + shred_duration=int(driveData['driveShredDuration'])) - layouter.generate_image(temp_drive, rehdd_info, "output.png") + layouter.generate_image(drive, rehdd_info, "output.png") + + except sysv_ipc.ExistentialError: + print("ERROR: message queue creation failed") - if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/reHDDPrinter.service b/reHDDPrinter.service new file mode 100644 index 0000000..8c0c040 --- /dev/null +++ b/reHDDPrinter.service @@ -0,0 +1,16 @@ +[Unit] +Description=reHDDPrinter +After=syslog.target + +[Service] +Type=simple +User=root +Group=root +Restart=on-failure +RestartSec=5s +ExecStart=/usr/bin/python3 /root/reHDDPrinter/reHDDPrinter.py + +[Install] +WantedBy=multi-user.target + +