
#if defined(_WIN32)
#pragma comment(lib,"Kernel32.lib")
#endif

#include <iostream>
#include <Windows.h>
#include "gas_monitor.h"
#include "ysp_modbus_slave.h"
#include "database/database.h"
#include "common.h"

//同时只有进程运行
BOOL xProcess_unique()
{
    HANDLE hMutex = CreateMutex(nullptr, FALSE, "ysp_monitor");
    if (GetLastError() == ERROR_ALREADY_EXISTS) // 已经有了一个实例
    {
        printf("just one process run,exit");
        exit(0);
    }
    // 其他代码
    return TRUE;
}

int main(int argc, char** argv)
{
    char com_test[20] = { 0 };

    xProcess_unique();

    std::cout << "RUN YSP MONITOR APP!\n";

#if 1 //com_test 用来开发测试 发布时不起作用
    if (argc > 1) {
        memcpy(com_test, argv[1], strlen(argv[1]));
        std::cout << "uart test:" << argv[1] << std::endl;
    }
    else {
        memcpy(com_test, "COM4", strlen("COM4"));
        std::cout << "default uart test:" << com_test << std::endl;
    }
#endif


    //xGet_config_from_configFile 放在任务之前执行里面有读取延迟执行时间
    xGet_config_from_configFile();
    xDelay_run_process();
    xMutex_init();
    xModbus_task_init();//MODBUS thread
    xGas_alert_task_init(com_test);//GAS monitor thread

    while (1);
}
