Python脚本
#!/usr/bin/env python3.6
# import os
# import shutil
import os,time
from multiprocessing import Process
dir = "/home/chahe/integrtion/data_test"
path_correction = "/home/chahe/Downloads/autorun/PA6430C5509530C554-correction.csv"
def get_output_filename(input):
vec = input.split("_")
num = vec[-1].split(".")
num = int(num[0])
if(num < 10):
num_str = "0" + str(num)
else:
num_str = str(num)
filename = vec[-2]+"_0" + num_str + ".pcap"
return filename
# prozess for RFL01
class MyProcess_RFL01(Process):
def __init__(self):
Process.__init__(self)
def run(self):
print("RFL01 --> Start >> pid={0},ppid={1}".format(os.getpid(),os.getppid()))
os.system('mkdir -p ./data/RFL01_Pcap')
os.system('mkdir -p ./data/RFL01_Merge')
print(dir)
# RFL01 MDF的路径
this_dir = dir + "/RFL01"
# 第一次MDF转PCAP的输出路径
output_dir_mdf_pcap = "./data/RFL01_Pcap"
# 第一次PCAP合并的输出路径
output_dir_pcap_merge = "./data/RFL01_Merge"
# 读取文件夹内的所有文件名
filelist=os.listdir(this_dir)
# 运行程序
print("==================Begin RFL01 MDF ---> PCAP=================")
for i in filelist:
print("------------------------start--------MDF ----> PCAP------------------")
input_file = this_dir + "/" + i
# input.append(input_file)
print("input:",input_file)
output_file = get_output_filename(i)
output_file = output_dir_mdf_pcap + "/" + output_file
# output.append(output_file)
print("output:",output_file)
os.system('./vigem-cca-converter -p {} -o {}'.format(input_file, output_file))
print("------------------------end------------------")
print("==================FINISH RFL01 MDF ---> PCAP=================")
print("==================Begin RFL01 PCAP MERGE=================")
os.system('./pcapAdd {}'.format(output_dir_mdf_pcap + " " + output_dir_pcap_merge))
print("==================FINISH RFL01 PCAP MERGE=================")
print("==================START LUNIMAR SDK=================")
merge_filename=os.listdir(output_dir_pcap_merge)
merge_file = output_dir_pcap_merge + "/" + merge_filename[0]
os.system('./luminar_sdk/./Luminar_sdk {}'.format(merge_file))
source = "./lum.bag"
outbag = "./data/bag"
os.system('mv {} -f {}'.format(source, outbag))
print("==================FINISH LUNIMAR SDK=================")
print("RFL01 --> Stop>>> pid={}".format(os.getpid()))
# prozess for RFL02
class MyProcess_RFL02(Process):
def __init__(self):
Process.__init__(self)
def run(self):
print("RFL02 --> Start >> pid={0},ppid={1}".format(os.getpid(),os.getppid()))
os.system('mkdir -p ./data/RFL02_Pcap')
os.system('mkdir -p ./data/RFL02_Merge')
print(dir)
# RFL02 MDF的路径
this_dir = dir + "/RFL02"
# 第一次MDF转PCAP的输出路径
output_dir_mdf_pcap = "./data/RFL02_Pcap"
# 第一次PCAP合并的输出路径
output_dir_pcap_merge = "./data/RFL02_Merge"
# 读取文件夹内的所有文件名
filelist=os.listdir(this_dir)
# 运行程序
print("==================Begin RFL02 MDF ---> PCAP=================")
for i in filelist:
print("------------------------start--------MDF ----> PCAP------------------")
input_file = this_dir + "/" + i
# input.append(input_file)
print("input:",input_file)
output_file = get_output_filename(i)
output_file = output_dir_mdf_pcap + "/" + output_file
# output.append(output_file)
print("output:",output_file)
os.system('./vigem-cca-converter -p {} -o {}'.format(input_file, output_file))
print("------------------------end------------------")
print("==================FINISH RFL02 MDF ---> PCAP=================")
# abspath = os.path.abspath(__file__)
# abspath_RFL02_Pcap = "./data/RFL02_Pcap"
# abspath_RFL02_Merge = "./data/RFL02_Merge"
os.system('./pcapAdd {}'.format(output_dir_mdf_pcap + " " + output_dir_pcap_merge))
print("==================Begin RFL02 PCAP MERGE=================")
print("==================START HESAI SDK=================")
merge_filename=os.listdir(output_dir_pcap_merge)
merge_file = output_dir_pcap_merge + "/" + merge_filename[0]
topic = "/hesai_RFL02"
outbag = "./data/bag"
os.system('./hesai_sdk/./PandarGeneralTest {}'.format(merge_file + " " + outbag + " " + path_correction + " " + topic))
print("==================FINISH HESAI SDK=================")
print("RFL02 --> Stop>>> pid={}".format(os.getpid()))
# prozess for RFL03
class MyProcess_RFL03(Process):
def __init__(self):
Process.__init__(self)
def run(self):
print("RFL03 --> Start >> pid={0},ppid={1}".format(os.getpid(),os.getppid()))
os.system('mkdir -p ./data/RFL03_Pcap')
os.system('mkdir -p ./data/RFL03_Merge')
print(dir)
# RFL03 MDF的路径
this_dir = dir + "/RFL03"
# 第一次MDF转PCAP的输出路径
output_dir_mdf_pcap = "./data/RFL03_Pcap"
# 第一次PCAP合并的输出路径
output_dir_pcap_merge = "./data/RFL03_Merge"
# 读取文件夹内的所有文件名
filelist=os.listdir(this_dir)
# 运行程序
print("==================Begin RFL03 MDF ---> PCAP=================")
for i in filelist:
print("------------------------start--------MDF ----> PCAP------------------")
input_file = this_dir + "/" + i
# input.append(input_file)
print("input:",input_file)
output_file = get_output_filename(i)
output_file = output_dir_mdf_pcap + "/" + output_file
# output.append(output_file)
print("output:",output_file)
os.system('./vigem-cca-converter -p {} -o {}'.format(input_file, output_file))
print("------------------------end------------------")
print("==================FINISH RFL03 MDF ---> PCAP=================")
# abspath = os.path.abspath(__file__)
os.system('./pcapAdd {}'.format(output_dir_mdf_pcap + " " + output_dir_pcap_merge))
print("==================Begin RFL03 PCAP MERGE=================")
print("==================START HESAI SDK=================")
merge_filename=os.listdir(output_dir_pcap_merge)
merge_file = output_dir_pcap_merge + "/" + merge_filename[0]
topic = "/hesai_RFL03"
outbag = "./data/bag"
os.system('./hesai_sdk/./PandarGeneralTest {}'.format(merge_file + " " + outbag + " " + path_correction + " " + topic))
print("==================FINISH HESAI SDK=================")
print("RFL03 --> Stop>>> pid={}".format(os.getpid()))
# prozess for VBS01
class MyProcess_VBS01(Process):
def __init__(self):
Process.__init__(self)
def run(self):
print("VBS01 --> Start >> pid={0},ppid={1}".format(os.getpid(),os.getppid()))
os.system('mkdir -p ./data/VBS01_Pcap')
os.system('mkdir -p ./data/VBS01_Merge')
print(dir)
# VBS01 MDF的路径
this_dir = dir + "/VBS01"
# 第一次MDF转PCAP的输出路径
output_dir_mdf_pcap = "./data/VBS01_Pcap"
# 第一次PCAP合并的输出路径
output_dir_pcap_merge = "./data/VBS01_Merge"
# 读取文件夹内的所有文件名
filelist=os.listdir(this_dir)
# 运行程序
print("==================Begin VBS01 MDF ---> PCAP=================")
for i in filelist:
print("------------------------start--------MDF ----> PCAP------------------")
input_file = this_dir + "/" + i
# input.append(input_file)
print("input:",input_file)
output_file = get_output_filename(i)
output_file = output_dir_mdf_pcap + "/" + output_file
# output.append(output_file)
print("output:",output_file)
os.system('./vigem-cca-converter -p {} -o {}'.format(input_file, output_file))
print("------------------------end------------------")
print("==================FINISH VBS01 MDF ---> PCAP=================")
# abspath = os.path.abspath(__file__)
os.system('./pcapAdd {}'.format(output_dir_mdf_pcap + " " + output_dir_pcap_merge))
print("==================Begin VBS01 PCAP MERGE=================")
print("==================START VBS SDK=================")
merge_filename=os.listdir(output_dir_pcap_merge)
merge_file = output_dir_pcap_merge + "/" + merge_filename[0]
outbag = "./data/bag"
os.system('./ego_interpreter/./ego_interpreter {}'.format(merge_file + " " + outbag))
print("==================FINISH VBS SDK=================")
print("VBS01 --> Stop>>> pid={}".format(os.getpid()))
def main():
print("主进程开始>>> pid={}".format(os.getpid()))
os.system("mkdir -p ./data/bag")
filelist=os.listdir(dir)
# num_datatypes = len(filelist)
# for i in filelist:
# if i == "RFL01":
# myp1 = MyProcess_RFL01()
# myp1.start()
# elif i == "RFL02":
# myp2 = MyProcess_RFL02()
# myp2.start()
# elif i == "RFL03":
# myp3 = MyProcess_RFL03()
# myp3.start()
# elif i == "VBS01":
# myp4 = MyProcess_VBS01()
# myp4.start()
# myp.join()
myp2 = MyProcess_RFL02()
myp2.start()
print("主进程终止")
if __name__ == '__main__':
main()
如果想输入什么命令,直接使用os.system(“cmd”).
前面还需要添加
#!/usr/bin/env python3.6
import os