Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
072b3e39
Commit
072b3e39
authored
17 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Add *nix comio implementation.
parent
8619b77d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/comio/comio.h
+25
-0
25 additions, 0 deletions
src/comio/comio.h
src/comio/comio_nix.c
+197
-0
197 additions, 0 deletions
src/comio/comio_nix.c
with
222 additions
and
0 deletions
src/comio/comio.h
+
25
−
0
View file @
072b3e39
...
...
@@ -54,9 +54,34 @@
#define COM_RING MS_RING_ON
#define COM_DCD MS_RLSD_ON
#else
#include
<termios.h>
#define COM_HANDLE int
#define COM_HANDLE_INVALID -1
#define COM_ERROR_VALUE errno
/* Stuff we apparently don't care about... */
*
*
TIOCM_LE
Line
Enable
.
*
TIOCM_DTR
Data
Terminal
Ready
.
*
TIOCM_RTS
Request
To
Send
.
*
TIOCM_ST
Secondary
Transmit
.
*
TIOCM_SR
Secondary
Receive
.
*/
#define COM_CTS TIOCM_CTS
/* Clear To Send. */
#ifdef TIOCM_CAR
#define COM_DCD TIOCM_CAR
/* Carrier Detect. */
#else
#define COM_DCD TIOCM_CD
/* Carrier Detect (synonym). */
#endif
#ifdef TIOCM_RNG
#define COM_RING TIOCM_RNG
/* Ring Indication. */
#else
#define COM_RING TIOCM_RI
/* Ring Indication (synonym). */
#endif
#define COM_DSR TIOCM_DSR
/* Data Set Ready. */
#endif
/**************/
...
...
This diff is collapsed.
Click to expand it.
src/comio/comio_nix.c
0 → 100644
+
197
−
0
View file @
072b3e39
/* comio_nix.c */
/* Synchronet Serial Communications I/O Library Functions for *nix */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* See the GNU Lesser General Public License for more details: lgpl.txt or *
* http://www.fsf.org/copyleft/lesser.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include
<sys/file.h>
#include
"comio.h"
#include
"genwrap.h"
char
*
comVersion
(
char
*
str
,
size_t
len
)
{
char
revision
[
16
];
sscanf
(
"$Revision$"
,
"%*s %s"
,
revision
);
safe_snprintf
(
str
,
len
,
"Synchronet Communications I/O Library for "
PLATFORM_DESC
" v%s"
,
revision
);
return
str
;
}
COM_HANDLE
comOpen
(
const
char
*
device
)
{
COM_HANDLE
handle
;
struct
termios
t
;
if
((
handle
=
open
(
device
,
O_NONBLOCK
|
O_RDWR
)
==
INVALID_HANDLE_VALUE
)
return
COM_HANDLE_INVALID
;
if
(
tcgetattr
(
handle
,
&
t
)
==-
1
)
{
close
(
device
);
return
COM_HANDLE_INVALID
;
}
t
.
c_iflag
=
(
IGNBRK
/* ignore BREAK condition */
|
IGNPAR
/* ignore (discard) parity errors */
);
t
.
c_oflag
=
0
;
/* No output processing */
t
.
c_cflag
=
(
CS8
/* 8 bits */
|
CREAD
/* enable receiver */
/*
Fun snippet from the FreeBSD manpage:
If CREAD is set, the receiver is enabled. Otherwise, no character is
received. Not all hardware supports this bit. In fact, this flag is
pretty silly and if it were not part of the termios specification it
would be omitted.
*/
|
HUPCL
/* hang up on last close */
|
CLOCAL
/* ignore modem status lines */
/* The next two are pretty much never used */
#ifdef CCTX_OFLOW
|
CCTS_OFLOW
/* CTS flow control of output */
#endif
#ifdef CRTSCTS
|
CRTSCTS
/* same as CCTS_OFLOW */
#endif
#ifdef CRTS_IFLOW
|
CRTS_IFLOW
/* RTS flow control of input */
#endif
);
t
.
c_lflag
=
0
;
/* No local modes */
if
(
tcsetattr
(
handle
,
TCSANOW
,
&
t
)
==-
1
)
{
close
(
device
);
return
COM_HANDLE_INVALID
;
}
return
handle
;
}
BOOL
comClose
(
COM_HANDLE
handle
)
{
return
(
!
close
(
handle
));
}
long
comGetBaudRate
(
COM_HANDLE
handle
)
{
struct
termios
t
;
speed_t
in
;
speed_t
out
;
if
(
tcgetattr
(
handle
,
&
t
))
return
COM_ERROR
;
/*
* We actually have TWO speeds available...
* return the biggest one
*/
in
=
cfgetispeed
(
&
t
);
out
=
cfgetospeed
(
&
t
);
return
((
long
)(
in
>
out
?
in
:
out
));
}
BOOL
comSetBaudRate
(
COM_HANDLE
handle
,
unsigned
long
rate
)
{
struct
termios
t
;
if
(
tcgetattr
(
handle
,
&
t
))
return
FALSE
;
cfsetispeed
(
&
t
);
cfsetospeed
(
&
t
);
if
(
tcsetattr
(
handle
,
TCSANOW
,
&
t
)
==-
1
)
return
FALSE
;
return
TRUE
;
}
int
comGetModemStatus
(
COM_HANDLE
handle
)
{
int
status
;
if
(
ioctl
(
handle
,
TIOCMGET
,
&
status
)
==-
1
)
return
COM_ERROR
;
return
status
;
}
BOOL
comRaiseDTR
(
COM_HANDLE
handle
)
{
return
(
ioctl
(
handle
,
TIOCSDTR
)
==
0
);
}
BOOL
comLowerDTR
(
COM_HANDLE
handle
)
{
return
(
ioctl
(
handle
,
TIOCCDTR
)
==
0
);
}
BOOL
comWriteByte
(
COM_HANDLE
handle
,
BYTE
ch
)
{
return
(
write
(
handle
,
&
ch
,
1
)
==
1
);
}
int
comWriteBuf
(
COM_HANDLE
handle
,
const
BYTE
*
buf
,
size_t
buflen
)
{
return
write
(
handle
,
&
buf
,
buflen
);
}
/*
* TODO: This seem kinda dangerous for short writes...
*/
int
comWriteString
(
COM_HANDLE
handle
,
const
char
*
str
)
{
return
comWriteBuf
(
handle
,
str
,
strlen
(
str
));
}
BOOL
comReadByte
(
COM_HANDLE
handle
,
BYTE
*
ch
)
{
return
(
read
(
handle
,
ch
,
1
)
==
1
);
}
BOOL
comPurgeInput
(
COM_HANDLE
handle
)
{
int
what
=
FREAD
;
return
(
ioctl
(
handle
,
TIOCFLUSH
,
&
what
)
==
0
);
}
BOOL
comPurgeOutput
(
COM_HANDLE
handle
)
{
int
what
=
FWRITE
;
return
(
ioctl
(
handle
,
TIOCFLUSH
,
&
what
)
==
0
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment