receive data via IPC msg queue
This commit is contained in:
parent
977baf27db
commit
4c3e40a658
30
README.md
30
README.md
|
@ -1,29 +1,37 @@
|
||||||
# reHDDPrinter #
|
# 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_PRINTER=file:///dev/usb/lp0
|
||||||
export BROTHER_QL_MODEL=QL-570
|
export BROTHER_QL_MODEL=QL-570
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
`brother_ql print -l 62 Untitled.png`
|
`brother_ql print -l 62 Untitled.png`
|
||||||
|
|
||||||
## Printer/Paper Info ##
|
## 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
|
see https://github.com/pklaus/brother_ql
|
||||||
|
|
||||||
pip install qrcode
|
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
output.png
BIN
output.png
Binary file not shown.
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.6 KiB |
|
@ -6,29 +6,58 @@
|
||||||
Date of last modification: 2022/11/23
|
Date of last modification: 2022/11/23
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import sysv_ipc
|
||||||
|
import pycstruct
|
||||||
import layouter
|
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():
|
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 = layouter.DriveData(
|
||||||
drive_index=0,\
|
drive_index=int(driveData['driveIndex']),\
|
||||||
drive_state="shredded",\
|
drive_state=str(driveData['driveState']),\
|
||||||
modelfamiliy="Toshiba 2.5\\ HDD MK..65GSSX",\
|
modelfamiliy=str(driveData['driveModelFamiliy']),\
|
||||||
modelname="TOSHIBA MK3265GSDX",\
|
modelname=str(driveData['driveModelName']),\
|
||||||
capacity=343597383680,\
|
capacity=int(driveData['driveCapacity']),\
|
||||||
serialnumber="YG6742U56UDRL123",\
|
serialnumber=str(driveData['driveSerialnumber']),\
|
||||||
power_on_hours=7074,\
|
power_on_hours=int(driveData['driveHours']),\
|
||||||
power_cycle=4792,\
|
power_cycle=int(driveData['driveCycles']),\
|
||||||
smart_error_count=1,\
|
smart_error_count=int(driveData['driveErrors']),\
|
||||||
shred_timestamp=1647937421,\
|
shred_timestamp=int(driveData['driveShredTimestamp']),\
|
||||||
shred_duration=81718)
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue