receive data via IPC msg queue
This commit is contained in:
@ -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()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user