/*
	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>
using namespace std;

#define IPMI_CMD_RAW L"raw"
#define IPMI_CMD_RELAY L"0x3E 0xC0 0x06 0xF8"
#define IPMI_RELAY_GET L"0"
#define IPMI_RELAY_SET L"1"
#define IPMI_RELAY_SET_STATUS_LOW 0
#define IPMI_RELAY_SET_STATUS_HIGH 1

#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 RELAY_STATUS
	{
		RELAY_ON = 1,
		RELAY_OFF = 0,
		LIB_INITIALIZE_FAIL = -1,
		PORT_OUTOF_INDEX = -2,
		SET_STATUS_ERR = -3
	};

	HMODULE GetCurrentModule();
	HANDLE mxrelay_open();
	void mxrelay_close(HANDLE fd);
	int mxrelay_get_output_signal(HANDLE fd, int port_no);
	int mxrelay_set_output_signal_high(HANDLE fd, int port);
	int mxrelay_set_output_signal_low(HANDLE fd, int port);
	
	int InitMXRELAY(void);
	int GetRelayData(int port);
	int SetRelayData(int port, int status);

	int RunIpmi(wstring extProgram, wstring arguments, int waitTime, string& res);

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