#include "VSensor.h" 
#include <signal.h> 
#include <direct.h> 
#pragma comment(lib, "VSensorSDK.lib")
using namespace std;
using namespace VSENSOR;
#define CAMERA_MAXSIZE  (2) //相机连接个数
int main()
{
    //获取相对路径
    char cwd[200];
    if (_getcwd(cwd, 200) == nullptr)
    {
        printf("get path failed\n");
    }
    //实例化设备
    VSensor lVSensor[CAMERA_MAXSIZE];
    //多相机
    for (int i = 0; i < CAMERA_MAXSIZE; ++i)
    {
        //获取设备列表
        VSensorCameraInfo cameraList[20];
        int num = 0;
        lVSensor[i].GetDeviceList(cameraList, &num);
        for (int j = 0; j < num; ++j)
        {
            printf("device num %d : list[%d] = %s\n", j, j, cameraList[j].CameraName);
        }
        //连接设备
        int status = lVSensor[i].DeviceConnect(i);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("connect device failed status = %d\n", status);
            system("pause");
        }
        //设备参数初始化，仅初次上电时需要进行此操作且该函数需要等待15s
        printf("waiting for parameter init...\n");
        status = lVSensor[i].DeviceParameterInit();
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("parameter init failed, status = %d\n", status);
            system("pause");
        }
        //设置为采集模式
        status = lVSensor[i].SetCaptureMode(emVSensorCaptureMode::MODE_CAPTURE);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("set capture mode failed, status = %d\n", status);
            system("pause");
        }
        //单次采集
        printf("start single capture...\n");
        VSensorResult* pResult = new VSensorResult;
        status = lVSensor[i].SingleRestruction(pResult, emVSensorCaptureOutputMode::OUTPUT_MODE_ALL);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("single restruction failed, status = %d\n", status);
            system("pause");
        }
        //保存无序点云为pcd格式
        string str(string(cwd) + "//test" + to_string(i + 1) + ".pcd");
        status = lVSensor[i].Save3DCloud(str, pResult, emVSensorPointType::POINT_TYPR_DISORDER);
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("save 3D points failed, status = %d\n", status);
            system("pause");
        }
        //反初始化设备
        status = lVSensor[i].DeviceUnInit();
        if (status != CAMERA_STATUS_SUCCESS)
        {
            printf("device release failed, status = %d\n", status);
            system("pause");
        }
        delete pResult;
    }
    printf("run success\n");
    system("pause");
    return 0;
}