| 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 |
#ifndef _WIN32S_H_ |
| 59 |
#define _WIN32S_H_ |
| 60 |
#include <windows.h> |
| 61 |
#include <sys/types.h> |
| 62 |
#include <io.h> |
| 63 |
#ifdef TRACE |
| 64 |
#define ENTER(x) report("entering "x" \n"); |
| 65 |
#define LEAVE(x) report("leaving "x" \n"); |
| 66 |
#else |
| 67 |
#define ENTER(x) |
| 68 |
#define LEAVE(x) |
| 69 |
#endif |
| 70 |
#define YACK() \ |
| 71 |
{ \ |
| 72 |
char *allocTextBuf, message[80]; \ |
| 73 |
unsigned long nChars; \ |
| 74 |
unsigned int errorCode = GetLastError(); \ |
| 75 |
nChars = FormatMessage ( \ |
| 76 |
FORMAT_MESSAGE_ALLOCATE_BUFFER | \ |
| 77 |
FORMAT_MESSAGE_FROM_SYSTEM, \ |
| 78 |
NULL, \ |
| 79 |
errorCode, \ |
| 80 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \ |
| 81 |
(LPSTR)&allocTextBuf, \ |
| 82 |
16, \ |
| 83 |
NULL ); \ |
| 84 |
sprintf( message, "Error 0x%x at %s(%d): %s\n", errorCode, __FILE__, __LINE__, allocTextBuf); \ |
| 85 |
report_error( message ); \ |
| 86 |
LocalFree(allocTextBuf); \ |
| 87 |
Sleep(1); \ |
| 88 |
} |
| 89 |
|
| 90 |
typedef unsigned char cc_t; |
| 91 |
typedef unsigned int speed_t; |
| 92 |
typedef unsigned int tcflag_t; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
struct timespec |
| 99 |
{ |
| 100 |
time_t tv_sec; |
| 101 |
long tv_nsec; |
| 102 |
}; |
| 103 |
|
| 104 |
#define NCCS 32 |
| 105 |
struct termios |
| 106 |
{ |
| 107 |
tcflag_t c_iflag; |
| 108 |
tcflag_t c_oflag; |
| 109 |
tcflag_t c_cflag; |
| 110 |
tcflag_t c_lflag; |
| 111 |
cc_t c_cc[NCCS]; |
| 112 |
cc_t c_line; |
| 113 |
speed_t c_ispeed; |
| 114 |
speed_t c_ospeed; |
| 115 |
}; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
struct serial_struct { |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
int custom_divisor; |
| 128 |
int baud_base; |
| 129 |
|
| 130 |
unsigned short close_delay, closing_wait, iomem_reg_shift; |
| 131 |
int type, line, irq, flags, xmit_fifo_size, hub6; |
| 132 |
unsigned int port, port_high; |
| 133 |
char io_type; |
| 134 |
unsigned char *iomem_base; |
| 135 |
}; |
| 136 |
struct serial_icounter_struct { |
| 137 |
int cts; |
| 138 |
int dsr; |
| 139 |
int rng; |
| 140 |
int dcd; |
| 141 |
int rx; |
| 142 |
int tx; |
| 143 |
int frame; |
| 144 |
int overrun; |
| 145 |
int parity; |
| 146 |
int brk; |
| 147 |
int buf_overrun; |
| 148 |
int reserved[9]; |
| 149 |
}; |
| 150 |
|
| 151 |
int serial_test( char * ); |
| 152 |
int serial_open(const char *File, int flags, ... ); |
| 153 |
int serial_close(int fd); |
| 154 |
int serial_read(int fd, void *b, int size); |
| 155 |
int serial_write(int fd, char *Str, int length); |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
#ifndef __LCC__ |
| 160 |
int serial_select(int, struct fd_set *, struct fd_set *, struct fd_set *, struct timeval *); |
| 161 |
#define select serial_select |
| 162 |
#endif |
| 163 |
|
| 164 |
#define OPEN serial_open |
| 165 |
#define CLOSE serial_close |
| 166 |
#define READ serial_read |
| 167 |
#define WRITE serial_write |
| 168 |
|
| 169 |
void termios_interrupt_event_loop( int , int ); |
| 170 |
void termios_setflags( int , int[] ); |
| 171 |
struct termios_list *find_port( int ); |
| 172 |
|
| 173 |
int fcntl(int fd, int command, ...); |
| 174 |
const char *get_dos_port(const char *); |
| 175 |
void set_errno(int); |
| 176 |
char *sterror(int); |
| 177 |
int B_to_CBR(int); |
| 178 |
int CBR_to_B(int); |
| 179 |
int termios_to_bytesize(int); |
| 180 |
int bytesize_to_termios(int); |
| 181 |
int tcgetattr(int Fd, struct termios *s_termios); |
| 182 |
int tcsetattr(int Fd, int when, struct termios *); |
| 183 |
int serial_close(int ); |
| 184 |
speed_t cfgetospeed(struct termios *s_termios); |
| 185 |
speed_t cfgetispeed(struct termios *s_termios); |
| 186 |
int cfsetspeed(struct termios *, speed_t speed); |
| 187 |
int cfsetospeed(struct termios *, speed_t speed); |
| 188 |
int cfsetispeed ( struct termios *, speed_t speed); |
| 189 |
int tcflush ( int , int ); |
| 190 |
int tcgetpgrp ( int ); |
| 191 |
int tcsetpgrp ( int , int ); |
| 192 |
int tcdrain ( int ); |
| 193 |
int tcflow ( int , int ); |
| 194 |
int tcsendbreak ( int , int ); |
| 195 |
int ioctl(int fd, int request, ... ); |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
void cfmakeraw(struct termios *s_termios); |
| 200 |
int termiosGetParityErrorChar( int ); |
| 201 |
void termiosSetParityError( int, char ); |
| 202 |
|
| 203 |
#define O_NOCTTY 0400 |
| 204 |
#define O_NONBLOCK 00004 |
| 205 |
#define O_NDELAY O_NONBLOCK |
| 206 |
#define O_SYNC 040000 |
| 207 |
#define O_FSYNC O_SYNC |
| 208 |
#define O_ASYNC 020000 |
| 209 |
|
| 210 |
#define F_DUPFD 0 |
| 211 |
#define F_GETFD 1 |
| 212 |
#define F_SETFD 2 |
| 213 |
#define F_GETFL 3 |
| 214 |
#define F_SETFL 4 |
| 215 |
#define F_GETLK 7 |
| 216 |
#define F_SETLK 8 |
| 217 |
#define F_SETLKW 9 |
| 218 |
|
| 219 |
#define F_SETOWN 5 |
| 220 |
#define F_GETOWN 6 |
| 221 |
|
| 222 |
|
| 223 |
#define FD_CLOEXEC 1 |
| 224 |
|
| 225 |
|
| 226 |
#define F_RDLCK 1 |
| 227 |
#define F_WRLCK 2 |
| 228 |
#define F_UNLCK 8 |
| 229 |
|
| 230 |
|
| 231 |
#define F_EXLCK 16 |
| 232 |
#define F_SHLCK 32 |
| 233 |
|
| 234 |
|
| 235 |
#define LOCK_SH 1 |
| 236 |
#define LOCK_EX 2 |
| 237 |
#define LOCK_NB 4 |
| 238 |
|
| 239 |
#define LOCK_UN 8 |
| 240 |
|
| 241 |
|
| 242 |
#define VINTR 0 |
| 243 |
#define VQUIT 1 |
| 244 |
#define VERASE 2 |
| 245 |
#define VKILL 3 |
| 246 |
#define VEOF 4 |
| 247 |
#define VTIME 5 |
| 248 |
#define VMIN 6 |
| 249 |
#define VSWTC 7 |
| 250 |
#define VSTART 8 |
| 251 |
#define VSTOP 9 |
| 252 |
#define VSUSP 10 |
| 253 |
#define VEOL 11 |
| 254 |
#define VREPRINT 12 |
| 255 |
#define VDISCARD 13 |
| 256 |
#define VWERASE 14 |
| 257 |
#define VLNEXT 15 |
| 258 |
#define VEOL2 16 |
| 259 |
|
| 260 |
|
| 261 |
#define IGNBRK 0000001 |
| 262 |
#define BRKINT 0000002 |
| 263 |
#define IGNPAR 0000004 |
| 264 |
#define PARMRK 0000010 |
| 265 |
#define INPCK 0000020 |
| 266 |
#define ISTRIP 0000040 |
| 267 |
#define INLCR 0000100 |
| 268 |
#define IGNCR 0000200 |
| 269 |
#define ICRNL 0000400 |
| 270 |
#define IXON 0002000 |
| 271 |
#define IXANY 0004000 |
| 272 |
#define IXOFF 0010000 |
| 273 |
#define IMAXBEL 0020000 |
| 274 |
#define CRTS_IFLOW 0040000 |
| 275 |
#define CCTS_OFLOW 0100000 |
| 276 |
#define CIGNORE 0400000 |
| 277 |
#define CRTSCTS 020000000000 |
| 278 |
#define HARDWARE_FLOW_CONTROL CRTSCTS |
| 279 |
#define CRTSXOFF 010000000000 |
| 280 |
|
| 281 |
#define OPOST 0000001 |
| 282 |
#define ONLCR 0000002 |
| 283 |
#define OLCUC 0000004 |
| 284 |
|
| 285 |
#define OCRNL 0000010 |
| 286 |
#define ONOCR 0000020 |
| 287 |
#define ONLRET 0000040 |
| 288 |
|
| 289 |
#define OFILL 00000100 |
| 290 |
#define OFDEL 00000200 |
| 291 |
#define NLDLY 00001400 |
| 292 |
#define NL0 00000000 |
| 293 |
#define NL1 00000400 |
| 294 |
#define NL2 00001000 |
| 295 |
#define NL3 00001400 |
| 296 |
#define TABDLY 00006000 |
| 297 |
#define TAB0 00000000 |
| 298 |
#define TAB1 00002000 |
| 299 |
#define TAB2 00004000 |
| 300 |
#define TAB3 00006000 |
| 301 |
#define CRDLY 00030000 |
| 302 |
#define CR0 00000000 |
| 303 |
#define CR1 00010000 |
| 304 |
#define CR2 00020000 |
| 305 |
#define CR3 00030000 |
| 306 |
#define FFDLY 00040000 |
| 307 |
#define FF0 00000000 |
| 308 |
#define FF1 00040000 |
| 309 |
#define BSDLY 00100000 |
| 310 |
#define BS0 00000000 |
| 311 |
#define BS1 00100000 |
| 312 |
#define VTDLY 00200000 |
| 313 |
#define VT0 00000000 |
| 314 |
#define VT1 00200000 |
| 315 |
#define XTABS 01000000 |
| 316 |
|
| 317 |
|
| 318 |
#define CBAUD 0030017 |
| 319 |
#define B0 0000000 |
| 320 |
#define B50 0000001 |
| 321 |
#define B75 0000002 |
| 322 |
#define B110 0000003 |
| 323 |
#define B134 0000004 |
| 324 |
#define B150 0000005 |
| 325 |
#define B200 0000006 |
| 326 |
#define B300 0000007 |
| 327 |
#define B600 0000010 |
| 328 |
#define B1200 0000011 |
| 329 |
#define B1800 0000012 |
| 330 |
#define B2400 0000013 |
| 331 |
#define B4800 0000014 |
| 332 |
#define B9600 0000015 |
| 333 |
#define B19200 0000016 |
| 334 |
#define B38400 0000017 |
| 335 |
#define B57600 0010001 |
| 336 |
#define B115200 0010002 |
| 337 |
#define B230400 0010003 |
| 338 |
#define B460800 0010004 |
| 339 |
#define B500000 0010005 |
| 340 |
#define B576000 0010006 |
| 341 |
#define B921600 0010007 |
| 342 |
#define B1000000 0010010 |
| 343 |
#define B1152000 0010011 |
| 344 |
#define B1500000 0010012 |
| 345 |
#define B2000000 0010013 |
| 346 |
#define B2500000 0010014 |
| 347 |
#define B3000000 0010015 |
| 348 |
#define B3500000 0010016 |
| 349 |
#define B4000000 0010017 |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
#define B14400 0020001 |
| 358 |
#define B28800 0020002 |
| 359 |
#define B128000 0020003 |
| 360 |
#define B256000 0020004 |
| 361 |
|
| 362 |
#define EXTA B19200 |
| 363 |
#define EXTB B38400 |
| 364 |
#define CSIZE 0000060 |
| 365 |
#define CS5 0000000 |
| 366 |
#define CS6 0000020 |
| 367 |
#define CS7 0000040 |
| 368 |
#define CS8 0000060 |
| 369 |
#define CSTOPB 0000100 |
| 370 |
#define CREAD 0000200 |
| 371 |
#define PARENB 0000400 |
| 372 |
#define PARODD 0001000 |
| 373 |
#define HUPCL 0002000 |
| 374 |
#define CLOCAL 0004000 |
| 375 |
# define CBAUDEX 0010000 |
| 376 |
# define CIBAUD 002003600000 |
| 377 |
# define CRTSCTS 020000000000 |
| 378 |
|
| 379 |
|
| 380 |
#define ISIG 0000001 |
| 381 |
#define ICANON 0000002 |
| 382 |
#define XCASE 0000004 |
| 383 |
#define ECHO 0000010 |
| 384 |
#define ECHOE 0000020 |
| 385 |
#define ECHOK 0000040 |
| 386 |
#define ECHONL 0000100 |
| 387 |
#define NOFLSH 0000200 |
| 388 |
#define TOSTOP 0000400 |
| 389 |
#define ECHOCTL 0001000 |
| 390 |
#define ECHOPRT 0002000 |
| 391 |
#define ECHOKE 0004000 |
| 392 |
#define FLUSHO 0010000 |
| 393 |
#define PENDIN 0040000 |
| 394 |
#define IEXTEN 0100000 |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
#define CBR_28800 28800 |
| 399 |
#define CBR_128000 128000 |
| 400 |
#define CBR_230400 230400 |
| 401 |
#define CBR_256000 256000 |
| 402 |
#define CBR_460800 460800 |
| 403 |
#define CBR_500000 500000 |
| 404 |
#define CBR_576000 576000 |
| 405 |
#define CBR_921600 921600 |
| 406 |
#define CBR_1000000 1000000 |
| 407 |
#define CBR_1152000 1152000 |
| 408 |
#define CBR_1500000 1500000 |
| 409 |
#define CBR_2000000 2000000 |
| 410 |
#define CBR_2500000 2500000 |
| 411 |
#define CBR_3000000 3000000 |
| 412 |
#define CBR_3500000 3500000 |
| 413 |
#define CBR_4000000 4000000 |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
#define TCOOFF 0 |
| 418 |
#define TCOON 1 |
| 419 |
#define TCIOFF 2 |
| 420 |
#define TCION 3 |
| 421 |
|
| 422 |
|
| 423 |
#define TCIFLUSH 0 |
| 424 |
#define TCOFLUSH 1 |
| 425 |
#define TCIOFLUSH 2 |
| 426 |
|
| 427 |
|
| 428 |
#define TCSANOW 0 |
| 429 |
#define TCSADRAIN 1 |
| 430 |
#define TCSAFLUSH 2 |
| 431 |
|
| 432 |
|
| 433 |
#define TIOCSERGETLSR 0x5459 |
| 434 |
|
| 435 |
#endif |
| 436 |
|
| 437 |
|
| 438 |
#define TCSBRK 0x5409 |
| 439 |
#define TIOCOUTQ 0x5411 |
| 440 |
#define TIOCMGET 0x5415 |
| 441 |
#define TIOCMBIS 0x5416 |
| 442 |
#define TIOCMBIC 0x5417 |
| 443 |
#define TIOCMSET 0x5418 |
| 444 |
#define TIOCGSOFTCAR 0x5419 |
| 445 |
#define TIOCSSOFTCAR 0x541a |
| 446 |
#define TIOCSER_TEMP 0x01 |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
#define TCSBRKP 0x5425 |
| 455 |
#define TIOCSERCONFIG 0x5453 |
| 456 |
#define TIOCSERGWILD 0x5454 |
| 457 |
#define TIOCSERSWILD 0x5455 |
| 458 |
#define TIOCSERGSTRUCT 0x5458 |
| 459 |
#define TIOCSERGETMULTI 0x545a |
| 460 |
#define TIOCSERSETMULTI 0x545b |
| 461 |
#define TIOCMIWAIT 0x545c |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
#define TIOCGICOUNT 0x545d |
| 468 |
|
| 469 |
|
| 470 |
#define ENOIOCTLCMD 515 |
| 471 |
#define EBADFD 77 |
| 472 |
|
| 473 |
#define TIOCM_LE 0x001 |
| 474 |
#define TIOCM_DTR 0x002 |
| 475 |
#define TIOCM_RTS 0x004 |
| 476 |
#define TIOCM_ST 0x008 |
| 477 |
#define TIOCM_SR 0x010 |
| 478 |
#define TIOCM_CTS 0x020 |
| 479 |
#define TIOCM_CAR 0x040 |
| 480 |
#define TIOCM_RNG 0x080 |
| 481 |
#define TIOCM_DSR 0x100 |
| 482 |
#define TIOCM_CD TIOCM_CAR |
| 483 |
#define TIOCM_RI TIOCM_RNG |
| 484 |
|
| 485 |
|
| 486 |
#define CMSPAR 010000000000 |