/*
	Copyright (C) MOXA Inc. All rights reserved.

	This software is distributed under the terms of the
	MOXA License.  See the file COPYING-MOXA for details.
*/
#pragma once
#include <iostream>
#include <string>
//#include <format>
//
//#include <memory>
//#include <stdexcept>
using namespace std;

#define IPMI_CMD_RAW L"raw"
#define IPMI_CMD_LED L"0x3E 0xC0 0x06 0xF7"
#define IPMI_LED_GET L"0"
#define IPMI_LED_SET L"1"
#define IPMI_LED_SET_STATUS_ON 0
#define IPMI_LED_SET_STATUS_OFF 1
#define IPMI_LED_SET_STATUS_BLINK 2

#define RETURN_BUF_SIZE 512


#ifdef __cplusplus    // If used by C++ code, 
extern "C" {          // we need to export the C interface
#endif

	wstring ipmi_path = L"\".\\PlugInTool\\IPMICLI\\spv_ipmi.exe\"";
	HANDLE m_hChildStd_OUT_Rd_T = NULL;
	HANDLE m_hChildStd_OUT_Wr_T = NULL;

	enum led_mode {
		LED_status_OFF = 0,
		LED_status_ON = 1,
		LED_status_BLINK = 2
	};

	enum LED_STATUS
	{
		LED_ON = 1,
		LED_OFF = 0,
		LIB_INITIALIZE_FAIL = -1,
		PORT_OUTOF_INDEX = -2,
		SET_STATUS_ERR = -3
	};

	HMODULE GetCurrentModule();
	HANDLE mxled_open();
	void mxled_close(HANDLE fd);
	int mxgpio_get_data(HANDLE fd, int port);
	int mxgpio_set_data(HANDLE fd, int port, int data);

	int InitMXLED(void);
	int GetLedCount();
	int GetLedData(int port);
	int SetLedData(int port, int status);
	void SetLedBlink(const WORD &wPortAddr, int led_bit);

	//void RunIpmiSystem(string extProgram, string arguments);
	//int RunIpmiTest(string extProgram, string arguments, int waitTime, string& res);
	int RunIpmi(wstring extProgram, wstring arguments, int waitTime, string& res);

#ifdef __cplusplus    // If used by C++ code, 
}
#endif