-
Notifications
You must be signed in to change notification settings - Fork 11
/
MTTTY.H
248 lines (211 loc) · 5.77 KB
/
MTTTY.H
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
/*-----------------------------------------------------------------------------
This is a part of the Microsoft Source Code Samples.
Copyright (C) 1995 Microsoft Corporation.
All rights reserved.
This source code is only intended as a supplement to
Microsoft Development Tools and/or WinHelp documentation.
See these sources for detailed information regarding the
Microsoft samples programs.
MODULE: MTTTY.h
PURPOSE: Contains global definitions and variables
-----------------------------------------------------------------------------*/
//
// File: MTTTY.h
//
#include <TCHAR.H>
#include "strsafe.h"
#include "resource.h"
#include "ttyinfo.h"
//
// GLOBAL DEFINES
//
#define TTY_BUFFER_SIZE MAXROWS * MAXCOLS
#define MAX_STATUS_BUFFER 20000
#define MAX_WRITE_BUFFER 1024
#define MAX_READ_BUFFER 2048
#define READ_TIMEOUT 500
#define STATUS_CHECK_TIMEOUT 500
#define WRITE_CHECK_TIMEOUT 500
#define PURGE_FLAGS PURGE_TXABORT | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_RXCLEAR
#define EVENTFLAGS_DEFAULT EV_BREAK | EV_CTS | EV_DSR | EV_ERR | EV_RING | EV_RLSD
#define FLAGCHAR_DEFAULT '\n'
//
// Write request types
//
#define WRITE_CHAR 0x01
#define WRITE_FILE 0x02
#define WRITE_FILESTART 0x03
#define WRITE_FILEEND 0x04
#define WRITE_ABORT 0x05
#define WRITE_BLOCK 0x06
//
// Read states
//
#define RECEIVE_TTY 0x01
#define RECEIVE_CAPTURED 0x02
//
// window coords
//
#define MAXXWINDOW 750
#define MAXYWINDOW 530
#define STARTXWINDOW 80
#define STARTYWINDOW 70
#define SETTINGSFACTOR 6
#define STATUSFACTOR 5
//
// window timer ids
//
#define TIMERID 1
//
// GLOBAL VARIABLES
//
#ifdef CAN_USE_GETVERSIONINFOEX
OSVERSIONINFO gOSV;
#endif
HINSTANCE ghInst;
HACCEL ghAccel;
HWND ghwndMain;
HWND ghWndToolbarDlg;
HWND ghWndStatusDlg;
HWND ghWndTTY;
HWND ghWndHidden;
//
// COMMTIMEOUTS is init'd in Init.c
//
extern COMMTIMEOUTS gTimeoutsDefault;
//
// Window placement variables
//
WORD gwBaseY;
LONG gcyMinimumWindowHeight;
//
// Flags controlling thread actions
//
HANDLE ghThreadExitEvent;
BOOL gfAbortTransfer;
//
// File transfer variables
//
DWORD gdwFileTransferLeft;
DWORD gdwReceiveState;
HANDLE ghFileCapture;
//
// Status updating
//
CRITICAL_SECTION gStatusCritical;
HANDLE ghStatusMessageEvent;
HANDLE ghStatusMessageHeap;
HFONT ghFontStatus;
int gnStatusIndex;
typedef struct STATUS_MESSAGE
{
struct STATUS_MESSAGE * lpNext; // pointer to next node
TCHAR chMessageStart; // variable length string start here
} STATUS_MESSAGE;
struct STATUS_MESSAGE * glpStatusMessageHead;
struct STATUS_MESSAGE * glpStatusMessageTail;
//
// Port name
//
TCHAR gszPort[10];
//
// Writer heap variables
//
CRITICAL_SECTION gcsWriterHeap;
CRITICAL_SECTION gcsDataHeap;
HANDLE ghWriterHeap;
HANDLE ghWriterEvent;
HANDLE ghTransferCompleteEvent;
//
// Write request data structure; look in Writer.c for more info
//
struct WRITEREQUEST;
struct WRITEREQUEST *gpWriterHead;
struct WRITEREQUEST *gpWriterTail;
typedef struct WRITEREQUEST
{
DWORD dwWriteType; // TCHAR, file start, file abort, file packet
DWORD dwSize; // size of buffer
TCHAR ch; // ch to send
TCHAR * lpBuf; // address of buffer to send
HANDLE hHeap; // heap containing buffer
HWND hWndProgress; // status bar window handle
struct WRITEREQUEST *pNext; // next node in the list
struct WRITEREQUEST *pPrev; // prev node in the list
} WRITEREQUEST, *PWRITEREQUEST;
//
// Prototypes of functions called between source files
//
//
// Error functions
//
void ErrorReporter( TCHAR * szMessage );
void ErrorHandler( TCHAR * szMessage );
void ErrorInComm( TCHAR * szMessage );
//
// Initialization/deinitialization/settings functions
//
HANDLE SetupCommPort( void );
void ChangeConnection( HWND, BOOL );
BOOL BreakDownCommPort( void );
BOOL UpdateConnection( void );
void GlobalInitialize( void );
void DestroyTTYInfo( void );
void GlobalCleanup( void );
void UpdateTTYInfo( void );
BOOL DisconnectOK( void );
BOOL InitTTYInfo( void );
void InitNewFont( LOGFONT, COLORREF );
//
// TTY functions
//
void OpenSettingsToolbar( HWND );
void OpenStatusToolbar( HWND );
BOOL CmdAbout( HWND );
//
// TTY functions
//
BOOL MoveTTYCursor( HWND );
BOOL KillTTYFocus( HWND );
BOOL SetTTYFocus( HWND );
BOOL SizeTTY( HWND, WORD, WORD );
//
// Thread procedures
//
DWORD WINAPI ReaderAndStatusProc( LPVOID );
DWORD WINAPI WriterProc( LPVOID );
//
// File transfer functions
//
void CALLBACK TransferRepeatDo( UINT, UINT, DWORD, DWORD, DWORD );
void TransferRepeatCreate( LPCTSTR, DWORD );
void TransferRepeatDestroy( void );
void TransferFileTextStart( LPCTSTR );
void TransferFileTextEnd( void );
// void TransferFileText( LPCTSTR );
void ReceiveFileText( LPCTSTR );
DWORD GetAFrequency( void );
//
// Buffer manipulation functions
//
void OutputABufferToWindow( HWND, char *, DWORD );
void OutputABuffer( HWND, char *, DWORD );
BOOL ClearTTYContents( void );
//
// Status functions
//
HFONT CreateStatusEditFont( void );
void ReportStatusEvent( DWORD );
void CheckModemStatus( BOOL );
void ReportCommError( void );
void ReportComStat( COMSTAT );
void StatusMessage( void );
void UpdateStatus( TCHAR * );
void CheckComStat( BOOL );
//
// Writer heap functions
//
BOOL WriterAddNewNode( DWORD, DWORD, TCHAR, TCHAR *, HANDLE, HWND );
BOOL WriterAddExistingNode( PWRITEREQUEST, DWORD, DWORD, TCHAR, TCHAR *, HANDLE, HWND );
BOOL WriterAddNewNodeTimeout( DWORD, DWORD, TCHAR, TCHAR *, HANDLE, HWND, DWORD );
BOOL WriterAddFirstNodeTimeout( DWORD, DWORD, TCHAR, TCHAR *, HANDLE, HWND, DWORD );