#pragma once

#define Hahan_IMPORT __declspec(dllimport)
#define Hahan_API __stdcall

#ifdef _WIN64
	#pragma comment(lib, "./SL04_x64/SL04.lib")
#else
	#pragma comment(lib, "./SL04_x32/SL04.lib")
#endif 


#ifdef __cplusplus
extern "C" {
#endif


//----------------------------- 中文说明 ---------------------------------------------------------------
// 使用方法：
// 在你的程序中，只需要包含这个头文件，然后调用下面2个函数中的任何一个就可以。
//
// bool DMXSendBox(long PORT, unsigned char* buf); 只对1个盒子发数据有效，这个函数可以兼容旧盒子HD512二次开发
// 的程序，你原先开发的HD512程序可以不用改，直接把这个SL04.dll改一个名称为HD512DLL.dll就可以直接使用原HD512程序。
// PORT = 0，1，2，3 对应盒子的4个输出口
// buf 为保存512通道DMX数据的数组，比如：dmxdate[512]
// 这个函数不需要填写盒子的IP地址，网络数据采用广播发送，如果你电脑有内置网卡或者安装过虚拟机的虚拟网卡，需要注意
// 这个广播包有可能会被拦截，最终无法发到盒子里面

// bool DMXSendUniverse(char *ip, unsigned char universe, unsigned char* buf); 这个函数可以发N多个盒子
// 如果你的灯光网络里面接了我们N多个盒子，可以调用这个函数
// ip 为要发到哪个盒子的ip地址，比如 “2.0.0.44”
// universe 为盒子的域的输出端口，取值范围为：0-255，最大为255
// buf 为保存512通道DMX数据的数组，比如：dmxdate[512]
//-----------------------------------------------------------------------------------------------------

//----------------------------- English Instructions --------------------------------------------------
// How to Use:
// In your program, you only need to include this header file and call any of the following 2 functions.
//
// bool DMXSendBox(long PORT, unsigned char* buf); It is only for one box to send data, and this function 
// can be compatible with the secondary development of the old box HD512, You don't need to change the HD512
// program you originally developed, just change the name of this SL04.dll to HD512DLL.dll you can directly 
// use the original HD512 program.
// PORT = 0,1,2,3 corresponds to the 4 outputs of the SL04 box
// buf is an array that holds 512 channels of DMX data, e.g. dmxdate[512]
// This function does not need to fill in the IP address of the box, the network data is sent by broadcasting, 
// if your computer has a built-in network card or virtual network card, you need to pay attention to whether the
// built-in network card and virtual network card will intercept the broadcast packet

// bool DMXSendUniverse(char *ip, unsigned char universe, unsigned char* buf); This function can send multiple boxes
// If your lighting network is connected to our more than one box, you can call this function
// IP is the IP address of the SL04 box to which you want to send it, for example, "2.0.0.44"
// universe is the Universe number of the SL04 box output, the value range is 0-255, and the maximum value is 255
// buf is an array that holds 512 channels of DMX data, e.g. dmxdate[512]
//-----------------------------------------------------------------------------------------------------

Hahan_IMPORT bool Hahan_API DMXSendBox(long PORT, unsigned char* buf);
Hahan_IMPORT bool Hahan_API DMXSendUniverse(char *ip, unsigned char universe, unsigned char* buf); 


#ifdef __cplusplus
}
#endif


//========================For example=====================================
/*
//example 1, link one SL04 box, Box IP=2.0.0.22, work 4 universe output
//call bool DMXSendBox(long PORT, unsigned char* buf);

#include <windows.h>
#include "SL04.h"		//only include our header file

unsigned char U0_DMXData[512], U1_DMXData[512], U2_DMXData[512], U3_DMXData[512]; //save 4 PORT dmx data, each is 512 channels

for(int i=0; i<512; i++)
{
	U0_DMXData[ i ] = 255;	//all to 255, light on
	U1_DMXData[ i ] = 255;	//all to 255, light on
	U2_DMXData[ i ] = 255;	//all to 255, light on
	U3_DMXData[ i ] = 255;	//all to 255, light on
}

//Way1: send broadcast packet
DMXSendBox(0,U0_DMXData); //Send 512 byte(channels) DMX data to PORT0 
DMXSendBox(1,U1_DMXData); //Send 512 byte(channels) DMX data to PORT1
DMXSendBox(2,U2_DMXData); //Send 512 byte(channels) DMX data to PORT2 
DMXSendBox(3,U3_DMXData); //Send 512 byte(channels) DMX data to PORT3


//Way2: send unicast packet
DMXSendUniverse("2.0.0.22", 0, U0_DMXData); //Send 512 byte(channels) DMX data to PORT0
DMXSendUniverse("2.0.0.22", 1, U1_DMXData); //Send 512 byte(channels) DMX data to PORT1
DMXSendUniverse("2.0.0.22", 2, U2_DMXData); //Send 512 byte(channels) DMX data to PORT2
DMXSendUniverse("2.0.0.22", 3, U3_DMXData); //Send 512 byte(channels) DMX data to PORT3

//-------------------------------------------------------------

//examlpe 2, link 2 SL04 box, work 8 universe output
//box0 ip=2.0.0.44 / universe=0,1,2,3
//box1 ip=2.0.0.45 / universe=4,5,6,7

unsigned char box0_DMXData[2048]; //save box1 2048 channels data
unsigned char box1_DMXData[2048]; //save box2 2048 channels data

for(int i=0; i<2048; i++)
{
	box0_DMXData[ i ] = 255;	//all to 255, light on
	box1_DMXData[ i ] = 255;	//all to 255, light on
}

for(int i=0; i<4; i++)
{
	DMXSendUniverse("2.0.0.44", i, &box0_DMXData[ i*512 ]); //send to box0 each universe 0,1,2,3
	DMXSendUniverse("2.0.0.45", i+4, &box1_DMXData[ i*512 ]); //send to box1 each universe 4,5,6,7
}

*/