//
// Created by zx on 2023/10/7.
//
#include <iostream>
#include "log/log.h"
#include "vzense/device_tof3d.h"
#include "detect/detect_manager.h"
#include "proto/measure_manager.pb.h"
#include "protobuf/load_protobuf.hpp"
#include "communication/communication_manager.h"

int main(int argc, char * argv[]) {
    // 初始化日志系统
    ZX::InitGlog(PROJECT_NAME, ETC_PATH PROJECT_NAME "/LogInfo/");

    // 初始化相机处理程序
    tof3dManagerParams tof3d_etc;
    if (loadProtobufFile(ETC_PATH PROJECT_NAME "/tof3d_manager.json", tof3d_etc) == SUCCESS) {
        auto ret = DeviceTof3D::iter()->Init(tof3d_etc.vzense_tof3d_devices());
        if (ret != SUCCESS) {
            LOG(ERROR) << ret.to_string();
            return EXIT_FAILURE;
        }
    } else {
        LOG(WARNING) << "tof3dManager read param form " << ETC_PATH PROJECT_NAME "/tof3d_manager.json" << " error.";
        return EXIT_FAILURE;
    }

    // 初始化测量程序
    DetectManager::iter()->Init();

    // 通信
    CommunicationManager::iter()->Init(tof3d_etc.communication());

    // 加载看门狗 TODO：添加看门狗，监视线程
    LOG(INFO) << "---------- all init complate ----------";
    while (true) {
//        auto mat = DeviceTof3D::iter()->getDevicePointsMat(DeviceAzimuth::DEVICE_AZIMUTH_LF);
//        if (mat.empty()) {
//            LOG(INFO) << "get a empty mat";
//        } else {
//            cv::imshow("merge_mat", mat);
//        }
        usleep(100 * 1000);
    }

    return EXIT_SUCCESS;
}
