#! /usr/bin/python
# -*- coding: utf-8 -*-
import os
import yaml
import camCheckData.check_rosbag_camera as camera
import lidarCheckData.check_lidar_imu as lidar
if __name__ == "__main__":

    print('程序开始')
    #Camera_Check
    Cam_optFile = os.getcwd() + "/camCheckData/cam_imu_check.yaml"
    with open(Cam_optFile) as f:
        opt = yaml.safe_load(f)

    featureNum = opt["feature_threshold"]
    bagPath = opt["bag_path"]
    reportPath = opt["report_path"] + "cam_imu_report.txt"
    error_list = camera.checkRosbag(bagPath, featureNum, reportPath)

    #Lidar_Check
    optFile = os.getcwd() + "/lidarCheckData/check_lidar_imu.yaml"
    with open(optFile) as f:
        opt = yaml.safe_load(f)

    threshLidarMsgsLossNum = opt["threshLidarMsgsLossNum"]
    threshImuMsgsLossNum   =opt["threshImuMsgsLossNum"]
    precision=opt["precision"]
    bagPath = opt["bag_path"]
    reportPath = opt["report_path"] + "lidar_report.txt"    
    BagFlag=lidar.checkRosbag(bagPath, reportPath,threshLidarMsgsLossNum,precision,threshImuMsgsLossNum)

    if len(error_list) == 0:
        print("Camera正常")
    if len(error_list) != 0:
        print("Camera异常")
    if BagFlag==True:
        print("Lidar正常")
    if BagFlag==False:
        print("Lidar异常")

    #total_report
    total_report_file= os.getcwd() + '/Total_report.txt'
    if os.path.exists(total_report_file):
        os.remove(total_report_file)
    with open(total_report_file, "a") as f:
        if len(error_list) == 0:
            f.write("Camera正常"+"\n")
        if len(error_list) != 0:
            f.write("Camera异常"+"\n")
        if BagFlag==True:
            f.write("Lidar正常"+"\n")
        if BagFlag==False:
            f.write("Lidar异常"+"\n")


