Project

General

Profile

Feature #1162 » logic.cpp

yufeng wu, 01/05/2021 09:25 AM

 
1
// logic.cpp : Defines the entry point for the DLL application.
2
//
3

    
4
#include <windows.h>
5

    
6
#define LOGIC_API extern "C" __declspec(dllexport)
7

    
8
BOOL APIENTRY DllMain( HANDLE hModule, 
9
                       DWORD  ul_reason_for_call, 
10
                       LPVOID lpReserved
11
					 )
12
{
13
    switch (ul_reason_for_call)
14
	{
15
		case DLL_PROCESS_ATTACH:
16
		case DLL_THREAD_ATTACH:
17
		case DLL_THREAD_DETACH:
18
		case DLL_PROCESS_DETACH:
19
			break;
20
    }
21
    return TRUE;
22
}
23

    
24

    
25
LOGIC_API int Logic_state(int *pIn, int nums)
26
{
27
	if (nums == 2)
28
	{
29
		return pIn[0] != pIn[1] ? pIn[1] : 2;
30
	}
31
	else if (nums >= 3)
32
	{
33
		return pIn[0]+pIn[1]+pIn[2] == 1 ? (pIn[0] ? 0 : (pIn[1] ? 1 : 2)) : 3;
34
	}
35

    
36
	return -1;
37
}
38

    
39
LOGIC_API int Logic_fire(int *pIn, int nums)
40
{
41
	if (nums >= 3)
42
	{
43
		return pIn[0]+pIn[1]+pIn[2] == 0 ? 0 :
44
			(pIn[0]+pIn[1]+pIn[2] == 1 ? (pIn[0] ? 1 : (pIn[1] ? 2 : 3)) : 4);
45
	}
46

    
47
	return -1;
48
}
49

    
50
LOGIC_API int Logic_alarm(int *pIn, int nums)
51
{
52
	if (nums > 0)
53
	{
54
		for (int i=0; i < nums; i++)
55
		{
56
			if (pIn[i])
57
				return 1;
58
		}
59

    
60
		return 0;
61
	}
62

    
63
	return -1;
64
}
65

    
66
LOGIC_API int Logic_animation(int *pIn, int nums)
67
{
68
	if (nums == 2)
69
	{
70
		return pIn[0] != pIn[1] ? pIn[1] : 2;
71
	}
72
	else if (nums >= 3)
73
	{
74
		return pIn[0]+pIn[1]+pIn[2] == 1 ? (pIn[0] ? 0 : (pIn[1] ? 2 : 1)) : 3;
75
	}
76

    
77
	return -1;
78
}
79

    
80
LOGIC_API int Logic_stateN(int *pIn, int nums)//???ȼ????????????ߣ??????ȼ?״̬???????????ȼ?״̬20180709
81
{
82
	if (nums > 0)
83
	{
84
		for (int i=0; i < nums; i++)
85
		{
86
			if (pIn[nums-1-i])
87
				return nums-i;
88
		}
89

    
90
		return 0;
91
	}
92

    
93
	return -1;
94
}
95

    
96
LOGIC_API int Logic_state_PSCADA(int *pIn, int nums)//˫λ״̬+ͨѶ20180713
97
{
98
	if (nums >= 2)
99
		return pIn[1] == 0 ? pIn[0] : 2;
100
	else
101
		return pIn[0];
102
	return -1;
103
}
104

    
105
LOGIC_API int Logic_stateN2(int *pIn, int nums)//??Է????򣬷??????״̬???????
106
{
107
	int Flag=0;
108
	if (nums == 2)
109
	{
110
		return pIn[0] != pIn[1] ? pIn[1] : 4;
111
	}
112
	else if (nums > 2)
113
	{
114
		for (int i=2; i < nums; i++)
115
		{
116
			if (pIn[nums-i+1])
117
			{
118
				Flag=1;
119
				return nums-i+1;
120
			}
121
		}
122
		if (Flag==0)
123
		{
124
			return pIn[0] != pIn[1] ? pIn[1] : 4;
125
		}
126
		return 0;
127
	}
128

    
129
	return -1;
130
}
131

    
132
LOGIC_API int Logic_stateN3(int *pIn, int nums)//??Է????򣬷??????״̬???????
133
{
134
	int Flag=0;
135
	if (nums == 3)
136
	{
137
		return pIn[0]+pIn[1]+pIn[2] == 1 ? (pIn[0] ? 0 : (pIn[1] ? 1 : 1)) : 4;
138
	}
139
	else if (nums > 3)
140
	{
141
		for (int i=3; i < nums; i++)
142
		{
143
			if (pIn[nums-i+2])
144
			{
145
				Flag=1;
146
				return nums-i+1;
147
			}
148
		}
149
		if (Flag==0)
150
		{
151
			return pIn[0]+pIn[1]+pIn[2] == 1 ? (pIn[0] ? 0 : (pIn[1] ? 1 : 1)) : 4;
152
		}
153
		return 0;
154
	}
155

    
156
	return -1;
157
}
158
//SHL4 TVF off==1
159
LOGIC_API int Logic4_state(int *pIn, int nums)
160
{
161
	if (nums == 2)
162
	{
163
		return pIn[0] != pIn[1] ? pIn[1] : 2;
164
	}
165
	else if (nums >= 3)
166
	{
167
		if(pIn[1]+pIn[2]==0)	return pIn[0] ? 0 : 3;
168
		return pIn[1]+pIn[2] == 1 ? (pIn[1] ? 2 : 1) : 3;
169
	}
170

    
171
	return -1;
172
}
173
LOGIC_API int Logic4_animation(int *pIn, int nums)
174
{
175
	if (nums == 2)
176
	{
177
		return pIn[0] != pIn[1] ? pIn[1] : 2;
178
	}
179
	else if (nums >= 3)
180
	{
181
		if(pIn[1]+pIn[2]==0)	return pIn[0] ? 0 : 3;
182
		return pIn[1]+pIn[2] == 1 ? (pIn[1] ? 2 : 1) : 3;
183
	}
184

    
185
	return -1;
186
}
187
LOGIC_API int Logic4_stateN3(int *pIn, int nums)//??Է????򣬷??????״̬???????
188
{
189
	int Flag=0;
190
	if (nums == 3)
191
	{
192
		if(pIn[1]+pIn[2]==0)	return pIn[0] ? 0 : 4;
193
		return pIn[1]+pIn[2] == 1 ? (pIn[1] ? 1 : 1) : 4;
194
	}
195
	else if (nums > 3)
196
	{
197
		for (int i=3; i < nums; i++)
198
		{
199
			if (pIn[nums-i+2])
200
			{
201
				Flag=1;
202
				return nums-i+1;
203
			}
204
		}
205
		if (Flag==0)
206
		{
207
			if(pIn[1]+pIn[2]==0)	return pIn[0] ? 0 : 4;
208
			return pIn[1]+pIn[2] == 1 ? (pIn[1] ? 1 : 1) : 4;
209
		}
210
		return 0;
211
	}
212

    
213
	return -1;
214
}
215
LOGIC_API int Logic4_stateNis1(int *pIn, int nums)
216
{	int i=0,sum=0,index=0;
217
	if (nums == 2)
218
	{
219
		return pIn[0] != pIn[1] ? pIn[1] : 2;
220
	}
221
	else if (nums >= 3)
222
	{
223
		for (i=0; i < nums; i++)
224
		{
225
			sum+=pIn[i];
226
			if(pIn[i]>0)index=i;
227
		}
228
		if(sum!=1)
229
			return nums;
230
		else
231
		return index;
232
	}
233
	return -1;
234
}
(1-1/2)