forked from maccasoft/lora3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombase.h
324 lines (283 loc) · 8.29 KB
/
combase.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// LoraBBS Version 2.99 Free Edition
// Copyright (C) 1987-98 Marco Maccaferri
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef _COMBASE_H
#define _COMBASE_H
#if defined(__OS2__)
#include <types.h>
#include <netinet\in.h>
#include <sys\socket.h>
#include <netdb.h>
#include <sys\ioctl.h>
#elif defined(__NT__)
#elif defined(__LINUX__)
#include <errno.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#else
extern "C" {
#include <sys\types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <pctcp/types.h>
#include <pctcp/rwconf.h>
#include <pctcp/pctcp.h>
#include <pctcp/syscalls.h>
};
#endif
#if defined(__DOS__) || (defined(__BORLANDC__) && !defined(__OS2__))
#if defined(__386__)
#define DOS4G
#endif
#include "commlib.h"
#include "ibmkeys.h"
#endif
#include "cxl.h"
#if defined(__LINUX__)
#include <signal.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <linux/kd.h> /* RAW mode stuff, etc. */
#include <linux/keyboard.h> /* mainly for NR_KEYS */
#include <linux/vt.h> /* for VT stuff - nah, really? :) */
#endif
#define RSIZE 2048
#define TSIZE 512
class DLL_EXPORT TCom
{
public:
TCom () {};
virtual ~TCom () {};
USHORT EndRun;
USHORT RxBytes, TxBytes;
virtual USHORT BytesReady () = 0;
virtual VOID BufferByte (UCHAR byte) = 0;
virtual VOID BufferBytes (UCHAR *bytes, USHORT len) = 0;
virtual USHORT Carrier () = 0;
virtual VOID ClearOutbound () = 0;
virtual VOID ClearInbound () = 0;
virtual UCHAR ReadByte () = 0;
virtual USHORT ReadBytes (UCHAR *bytes, USHORT len) = 0;
virtual VOID SendByte (UCHAR byte) = 0;
virtual VOID SendBytes (UCHAR *bytes, USHORT len) = 0;
virtual VOID UnbufferBytes () = 0;
virtual VOID SetName (PSZ name) = 0;
virtual VOID SetCity (PSZ name) = 0;
virtual VOID SetLevel (PSZ level) = 0;
virtual VOID SetTimeLeft (ULONG seconds) = 0;
virtual VOID SetTime (ULONG seconds) = 0;
protected:
UCHAR RxBuffer[RSIZE], TxBuffer[TSIZE];
UCHAR *NextByte;
};
#define DTR 1
#define RTS 2
#define CTS 16
#define DSR 32
#define RI 64
#define DCD 128
#define DATA_READY 0x0100
#define TX_SHIFT_EMPTY 0x4000
class DLL_EXPORT TSerial : public TCom
{
public:
TSerial ();
~TSerial ();
#if defined(__OS2__) || defined(__NT__) || defined(__LINUX__)
CHAR Device[32];
#elif defined(__DOS__)
USHORT Com;
#endif
ULONG Speed;
USHORT DataBits, StopBits;
CHAR Parity;
#if defined(__OS2__)
HFILE hFile;
#elif defined(__NT__)
HANDLE hFile;
#elif defined(__LINUX__)
int hFile;
struct termios tty;
#endif
USHORT BytesReady ();
VOID BufferByte (UCHAR byte);
VOID BufferBytes (UCHAR *bytes, USHORT len);
USHORT Carrier ();
VOID ClearOutbound ();
VOID ClearInbound ();
USHORT Initialize ();
UCHAR ReadByte ();
USHORT ReadBytes (UCHAR *bytes, USHORT len);
VOID SendByte (UCHAR byte);
VOID SendBytes (UCHAR *bytes, USHORT len);
VOID SetDTR (USHORT fStatus);
VOID SetRTS (USHORT fStatus);
VOID SetParameters (ULONG ulSpeed, USHORT nData, UCHAR nParity, USHORT nStop);
VOID UnbufferBytes ();
VOID SetName (PSZ name);
VOID SetCity (PSZ name);
VOID SetLevel (PSZ level);
VOID SetTimeLeft (ULONG seconds);
VOID SetTime (ULONG seconds);
private:
#if defined(__DOS__)
PORT *hPort;
#elif defined(__LINUX__)
struct termios new_termio;
struct termios old_termio;
#endif
};
class DLL_EXPORT TScreen : public TCom
{
public:
TScreen ();
~TScreen ();
USHORT BytesReady ();
VOID BufferByte (UCHAR byte);
VOID BufferBytes (UCHAR *bytes, USHORT len);
USHORT Carrier ();
VOID ClearOutbound ();
VOID ClearInbound ();
USHORT Initialize ();
UCHAR ReadByte ();
USHORT ReadBytes (UCHAR *bytes, USHORT len);
VOID SendByte (UCHAR byte);
VOID SendBytes (UCHAR *bytes, USHORT len);
VOID UnbufferBytes ();
VOID SetName (PSZ name);
VOID SetCity (PSZ name);
VOID SetLevel (PSZ level);
VOID SetTimeLeft (ULONG seconds);
VOID SetTime (ULONG seconds);
private:
CXLWIN wh;
USHORT Running;
USHORT RxPosition, Counter;
USHORT Attr, Count, Params[10];
CHAR Prec, Ansi;
};
class DLL_EXPORT TTcpip : public TCom
{
public:
TTcpip ();
~TTcpip ();
CHAR ClientIP[16];
CHAR ClientName[128];
CHAR HostIP[16];
ULONG HostID;
USHORT BytesReady ();
VOID BufferByte (UCHAR byte);
VOID BufferBytes (UCHAR *bytes, USHORT len);
USHORT Carrier ();
VOID ClearOutbound ();
VOID ClearInbound ();
VOID ClosePort ();
USHORT ConnectServer (PSZ pszServerName, USHORT usPort);
USHORT Initialize (USHORT usPort, USHORT usSocket = 0, USHORT usProtocol = IPPROTO_TCP);
UCHAR ReadByte ();
USHORT ReadBytes (UCHAR *bytes, USHORT len);
VOID SendByte (UCHAR byte);
VOID SendBytes (UCHAR *bytes, USHORT len);
VOID UnbufferBytes ();
USHORT WaitClient ();
USHORT GetPacket (PVOID lpBuffer, USHORT usSize);
USHORT PeekPacket (PVOID lpBuffer, USHORT usSize);
USHORT SendPacket (PVOID lpBuffer, USHORT usSize);
VOID SetName (PSZ name);
VOID SetCity (PSZ name);
VOID SetLevel (PSZ level);
VOID SetTimeLeft (ULONG seconds);
VOID SetTime (ULONG seconds);
private:
int Sock, Accepted;
int LSock;
USHORT fCarrierDown;
USHORT RxPosition;
struct sockaddr_in udp_client;
#if defined(__OS2__)
friend VOID WaitThread (PVOID Args);
#endif
};
class DLL_EXPORT TStdio : public TCom
{
public:
TStdio ();
~TStdio ();
USHORT BytesReady ();
VOID BufferByte (UCHAR byte);
VOID BufferBytes (UCHAR *bytes, USHORT len);
USHORT Carrier ();
VOID ClearOutbound ();
VOID ClearInbound ();
USHORT Initialize ();
UCHAR ReadByte ();
USHORT ReadBytes (UCHAR *bytes, USHORT len);
VOID SendByte (UCHAR byte);
VOID SendBytes (UCHAR *bytes, USHORT len);
VOID UnbufferBytes ();
VOID SetName (PSZ name);
VOID SetCity (PSZ name);
VOID SetLevel (PSZ level);
VOID SetTimeLeft (ULONG seconds);
VOID SetTime (ULONG seconds);
private:
USHORT RxPosition;
#if defined(__LINUX__)
int tty_fd;
struct termios new_termio, old_termio;
#endif
};
#if defined(__OS2__) || defined(__NT__)
class DLL_EXPORT TPipe : public TCom
{
public:
TPipe ();
~TPipe ();
CHAR Name[64], City[64], Level[64];
ULONG TimeLeft, Time;
USHORT BytesReady ();
VOID BufferByte (UCHAR byte);
VOID BufferBytes (UCHAR *bytes, USHORT len);
USHORT Carrier ();
VOID ClearOutbound ();
VOID ClearInbound ();
USHORT Initialize (PSZ pszPipeName, PSZ pszCtlName, USHORT usInstances);
USHORT ConnectServer (PSZ pszPipeName, PSZ pszCtlName);
UCHAR ReadByte ();
USHORT ReadBytes (UCHAR *bytes, USHORT len);
VOID SendByte (UCHAR byte);
VOID SendBytes (UCHAR *bytes, USHORT len);
VOID UnbufferBytes ();
USHORT WaitClient ();
VOID SetName (PSZ name);
VOID SetCity (PSZ name);
VOID SetLevel (PSZ level);
VOID SetTimeLeft (ULONG seconds);
VOID SetTime (ULONG seconds);
private:
USHORT CtlConnect, PipeConnect;
#if defined(__OS2__)
HFILE hFile, hFileCtl;
#elif defined(__NT__)
HANDLE hFile, hFileCtl;
#endif
};
#endif
#endif