-
Notifications
You must be signed in to change notification settings - Fork 0
/
BBVA.C
287 lines (213 loc) · 6.1 KB
/
BBVA.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/****************************************************************************/
/* */
/* PROGRAMA : BBVA.c */
/* */
/* PROPOSITO: Puente de SDLC a Puerto Serial */
/* Escrito por Alvaro Medina de PERURIMPEX S.A. */
/****************************************************************************/
#include <windows.h>
#include "bbva.h"
#include "msa.h"
void GateWay(char wParam);
void Sleep(int Time);
char *IfFirst(char *pStr);
char *IfLast(char *pStr);
int y=0;
HANDLE hInst;
HDC hDC;
NPTTYINFO npTTYInfo ;
DCB dcb;
int err;
char szTemp[ TXQUEUE ] ;
HFILE hfTempFile;
char szBuf[TXQUEUE];
TIMERPROC lpfnMyTimerProc;
int nTimer, pTimer, lTrans;
int lFirst;
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if (!hPrevInstance)
if (!InitApplication(hInstance))
return (FALSE);
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
while (GetMessage(&msg, NULL, NULL, NULL)) {
TranslateMessage((LPMSG)&msg);
DispatchMessage((LPMSG)&msg);
}
return (msg.wParam);
}
BOOL InitApplication(HANDLE hInstance)
{
WNDCLASS wc;
wc.style = NULL;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( ICONO_BBVA ) );
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "SDLC";
wc.lpszClassName = "SDLCClass";
return (RegisterClass(&wc));
}
BOOL InitInstance(HANDLE hInstance, int nCmdShow)
{
HWND hWnd;
int i;
char tmp[100];
hInst = hInstance;
hWnd = CreateWindow(
"SDLCClass",
"Gateway from SDLC to Serial Port",
WS_SYSMENU | WS_MINIMIZEBOX,
200,
100,
290,
50,
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
return (FALSE);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
if ((i = MSAInit()) <= 0) {
wsprintf(tmp, "MOXA INIT error %d", i);
MessageBox(hWnd, tmp, NULL, MB_OK | MB_ICONHAND);
// return(FALSE);
}
if ((COMDEV( npTTYInfo ) = OpenComm( "COM5", RXQUEUE, TXQUEUE )) < 0)
{
MessageBox(hWnd,"Error:OpenComm","",MB_OK);
return ( FALSE ) ;
}
err = BuildCommDCB("COM5:19200,n,8,1", &dcb);
if (err < 0) {
MessageBox(hWnd, "Ok", "BuildCommDCB", MB_OK);
return 0;
}
err = SetCommState(&dcb);
if (err < 0) {
MessageBox(hWnd, "Ok", "SetCommState", MB_OK);
return 0;
}
strcpy(szBuf, "c:\\SDLC.TXT");
hfTempFile = _lcreat(szBuf, 0);
if (hfTempFile == HFILE_ERROR) {
MessageBox(hWnd, "Ok", "OpenFile", MB_OK);
return ( FALSE);
}
pTimer = 500;
lpfnMyTimerProc = (TIMERPROC) MakeProcInstance(MyTimerProc, hInstance);
SetTimer(hWnd, ID_MYTIMER, pTimer, lpfnMyTimerProc);
nTimer = 0;
lTrans = 0;
SendMessage( hWnd, WM_SYSCOMMAND, (WPARAM) SC_MINIMIZE, NULL ) ;
return (TRUE);
}
long FAR PASCAL MainWndProc(HWND hWnd, unsigned message,
WORD wParam, LONG lParam)
{
FARPROC lpProcAbout;
HMENU hMenu;
PAINTSTRUCT ps;
switch (message) {
case WM_COMMAND:
switch (wParam) {
default: /* Lets Windows process it */
return (DefWindowProc(hWnd, message, wParam, lParam));
}
break;
case WM_DESTROY:
PostQuitMessage(0);
MSAEnd();
CloseComm( COMDEV( npTTYInfo ) ) ;
_lclose(hfTempFile);
break;
default:
// GateWay(wParam, hWnd);
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (NULL);
}
void CALLBACK MyTimerProc(HWND hWnd, UINT msg, UINT idTimer, DWORD dwTime)
{
unsigned long t1;
int i,n=0, nFlg = 0, Index=0;
HDC hDC;
char *pStr;
if (nTimer > 0 )
if (nTimer > 10000)
{
nTimer = 0;
WriteComm(COMDEV( npTTYInfo ), (LPSTR) "FIN", 3);
}
else
{
nTimer += pTimer;
}
hDC = GetDC(hWnd);
memset( szTemp, 0, TXQUEUE) ;
if ((i = MSARead(szTemp, TXQUEUE)) > 0)
{
if ( i > 4 ) //(strcmp(Control, szTemp))
{
memset( szBuf, 0, TXQUEUE) ;
for(n=0;i>n;n++)
{
if (!szTemp[n]) szTemp[n]=' ';
//if (szTemp[n]== 12) { szTemp[n++]=0; nFlg = 1; break; }
}
/* Buscando el Inicio de la Transaccion*/
if (IfFirst(szTemp) != NULL)
{
lTrans = 1;
WriteComm(COMDEV( npTTYInfo ), (LPSTR) "INICIO", 6);
strcpy(szBuf, szTemp + 37);
strcpy(szTemp, szBuf);
nTimer = pTimer;
}
if ((pStr= IfLast(szTemp)) != NULL)
{
Index = pStr-szTemp;
szTemp[Index] = '\0';
strcpy(szBuf, szTemp + 5);
}
if ((IfFirst(szTemp) == NULL) && (IfLast(szTemp) == NULL))
strcpy(szBuf, szTemp + 5);
if (lTrans)
{
WriteComm(COMDEV( npTTYInfo ), (LPSTR) szBuf, strlen(szBuf));
// _lwrite(hfTempFile, (LPSTR) szBuf, strlen(szBuf) );
}
if (pStr=strchr(szTemp, 12) != NULL)
{
lTrans = 0;
//WriteComm(COMDEV( npTTYInfo ), (LPSTR) "FIN", 3);
}
//MessageBox(hWnd, szBuf ,"ok", MB_OK);
//sprintf(szBuf, "%s --> %d ==>%d,%d,%d ---->i=%d\n", szTemp, strlen(szTemp),szTemp[0], szTemp[1], szTemp[2],i);
//TextOut(hDC, 10, y, (LPSTR) szBuf, strlen(szBuf));
//TextOut(hDC, 10, y, (LPSTR) " ", 28);
//y+=15;
}
}
t1 = MSAIsUnderRun();
ReleaseDC(hWnd, hDC);
}
char *IfFirst(char *pStr)
{
pStr=strstr(pStr, "BBVA");
return pStr;
}
char *IfLast(char *pStr)
{
pStr=strchr(pStr, 12);
return pStr;
}