import multiprocessing
import random
import time
import datetime
import struct
import os import getFile # 76(28) + (2048 + 16) * 512 + 4 frame_flag_0 = 0x0000000000000001 # 8 byte
frame_flag_1 = 0x0000000000000002 # 8 byte
frame_flag_2 = 0x0000000000000003 # 8 byte
frame_flag_9 = 0x00000001 # 4 byte dir_name = 'Z:/'
file_out = 'Z:/312.dat' def producer(pipe):
print('start time: ' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
linestr = getFile.getFileList(dir_name, '_312_') for i in range(0, len(linestr)):
file_in = linestr[i]
f_in = open(file_in, 'rb')
f_in.seek(109)
while True:
buff = f_in.read(9)
buff = f_in.read(1792)
if buff:
pipe.send_bytes(buff)
else:
f_in.close()
break pipe.close() def consumer(pipe):
f_out = open(file_out, 'xb')
mm = 0
while True:
try: item = pipe.recv_bytes(1792)
if item:
if mm % 512 == 0: # 开始的首帧
f_out.write(struct.pack('>3Q', frame_flag_0, frame_flag_1, frame_flag_2))
f_out.write(struct.pack('>I', frame_flag_9))
f_out.write(item)
f_out.write(struct.pack('>I', 0x00000000) * 68) # 272 byte : 2048 - (896*2) + 16
mm = 0
elif mm % 512 == 511: # 结尾的结束帧
f_out.write(item)
f_out.write(struct.pack('>I', 0x00000000) * 68) # 272 byte
f_out.write(struct.pack('>I', 0x00000000)) # 4 byte 包尾
f_out.flush()
else:
f_out.write(item)
f_out.write(struct.pack('>I', 0x00000000) * 68) # 272 byte
mm += 1 except EOFError:
f_out.write(struct.pack('>I', 0x00000000) * 516 * (512 - mm)) # (2048 + 16)/4 = 516
f_out.write(struct.pack('>I', 0x00000000)) # 4 byte 包尾
f_out.close()
print('end time: ' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
break if __name__ == "__main__":
pipe = multiprocessing.Pipe()
process_producer = multiprocessing.Process(target = producer, args = (pipe[0],))
process_consumer = multiprocessing.Process(target = consumer, args = (pipe[1],))
process_producer.start()
process_consumer.start()
pipe[0].close()
process_producer.join()
process_consumer.join() print('OK')

最新文章

  1. Webform 文件上传、 C#加图片水印 、 图片验证码
  2. 关于e^PI>PI^e
  3. FZU 2216 The Longest Straight(最长直道)
  4. extjs 学习笔记(二)
  5. 学习使用Free RTOS ,移植最新的STM32 v3.5固件库
  6. on事件绑定阻止冒泡的问题
  7. 洛谷U4727 小L 的二叉树
  8. Spring 对缓存的抽象
  9. 图像处理------泛洪填充算法(Flood Fill Algorithm) 油漆桶功能
  10. [Sdoi2009]Elaxia的路线
  11. android 系统dialog的应用
  12. DOS:第二天
  13. Oracle 12C 密码文件问题 ORA-01017: invalid username/password; logon denied
  14. 02_计算机网络的OSI七层(应表会传网数物)
  15. TCP建立与断开连接、socket通讯模板
  16. C语言复习---找出报数最后一人
  17. pyqt5-顶层窗口特定操作-图标和标题和不透明度
  18. eclipse中创建DataBase Connections
  19. SYSAUX表空间如何清理
  20. 关于ubuntu下看视频中文字幕乱码的问题

热门文章

  1. 手机POS机
  2. 10.8 ss:查看网络状态
  3. Java必会之多线程
  4. CVPR2020:训练多视图三维点云配准
  5. 【NX二次开发】Block UI 双精度
  6. python学习笔记01-简单接触
  7. QueryTable的使用以及错误
  8. Lambda表达式和函数式接口
  9. docker入门详解
  10. Redis 面霸篇:高频问题横扫核心知识点