Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>2006-02-28 11:25:00 +0300
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>2006-02-28 11:25:00 +0300
commit87f82f506d15ed750b04695583a0f5b571ec0a93 (patch)
treebf36d48f9cfce8c10bd946cd52318d0c72c306a9 /support
parent5295cd8a570b7ca0f8ae6468cd444434f6be2696 (diff)
2006-02-28 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* serial.h: New file with serial port constants. * serial.c: Use the constants in serial.h instead of magic numbers. svn path=/trunk/mono/; revision=57383
Diffstat (limited to 'support')
-rw-r--r--support/ChangeLog5
-rw-r--r--support/serial.c58
-rw-r--r--support/serial.h31
3 files changed, 67 insertions, 27 deletions
diff --git a/support/ChangeLog b/support/ChangeLog
index d26822f695d..6423a9952a8 100644
--- a/support/ChangeLog
+++ b/support/ChangeLog
@@ -1,3 +1,8 @@
+2006-02-28 Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+ * serial.h: New file with serial port constants.
+ * serial.c: Use the constants in serial.h instead of magic numbers.
+
2006-01-03 Jonathan Pryor <jonpryor@vt.edu>
* sys-time.c: lutimes(2) only exists on some BSDs. There's a configure
diff --git a/support/serial.c b/support/serial.c
index 8ae46b8a6bf..e73e6f65591 100644
--- a/support/serial.c
+++ b/support/serial.c
@@ -13,6 +13,8 @@
#include <glib.h>
+#include "serial.h"
+
int
open_serial (char* devfile)
{
@@ -89,7 +91,7 @@ discard_buffer (int fd, gboolean input)
}
gboolean
-set_attributes (int fd, int baud_rate, int parity, int dataBits, int stopBits, int handshake)
+set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake)
{
struct termios newtio;
@@ -121,22 +123,22 @@ set_attributes (int fd, int baud_rate, int parity, int dataBits, int stopBits, i
}
switch (parity) {
- case 0: /* Even */
- newtio.c_iflag &= ~IGNPAR;
- newtio.c_cflag |= PARENB;
- break;
- case 1: /* Mark */
- /* XXX unhandled */
- break;
- case 2: /* None */
+ case NoneParity: /* None */
newtio.c_iflag |= IGNPAR;
newtio.c_cflag &= ~(PARENB | PARODD);
break;
- case 3: /* Odd */
+ case Odd: /* Odd */
newtio.c_iflag &= ~IGNPAR;
newtio.c_cflag |= PARENB | PARODD;
break;
- case 4: /* Space */
+ case Even: /* Even */
+ newtio.c_iflag &= ~IGNPAR;
+ newtio.c_cflag |= PARENB;
+ break;
+ case Mark: /* Mark */
+ /* XXX unhandled */
+ break;
+ case Space: /* Space */
/* XXX unhandled */
break;
}
@@ -154,15 +156,18 @@ set_attributes (int fd, int baud_rate, int parity, int dataBits, int stopBits, i
newtio.c_cflag &= ~CSTOPB;
switch (stopBits) {
- case 0: /* One */
- /* do nothing, the default is one stop bit */
+ case NoneStopBits:
+ /* Unhandled */
break;
- case 1: /* OnePointFive */
- /* XXX unhandled */
+ case One: /* One */
+ /* do nothing, the default is one stop bit */
break;
- case 2: /* Two */
+ case Two: /* Two */
newtio.c_cflag |= CSTOPB;
break;
+ case OnePointFive: /* OnePointFive */
+ /* XXX unhandled */
+ break;
}
newtio.c_iflag &= ~IXOFF;
@@ -171,29 +176,28 @@ set_attributes (int fd, int baud_rate, int parity, int dataBits, int stopBits, i
newtio.c_cflag &= ~CRTSCTS;
#endif /* def CRTSCTS */
switch (handshake) {
- case 0: /* None */
+ case NoneHandshake: /* None */
/* do nothing */
break;
- case 1: /* RequestToSend (RTS) */
+ case XOnXOff: /* XOnXOff */
+ newtio.c_iflag |= IXOFF;
+ // newtio.c_oflag |= IXON;
+ break;
+ case RequestToSend: /* RequestToSend (RTS) */
#ifdef CRTSCTS
newtio.c_cflag |= CRTSCTS;
#endif /* def CRTSCTS */
break;
- case 2: /* RequestToSendXOnXOff (RTS + XON/XOFF) */
+ case RequestToSendXOnXOff: /* RequestToSendXOnXOff (RTS + XON/XOFF) */
#ifdef CRTSCTS
newtio.c_cflag |= CRTSCTS;
#endif /* def CRTSCTS */
/* fall through */
- case 3: /* XOnXOff */
- newtio.c_iflag |= IXOFF;
- // newtio.c_oflag |= IXON;
- break;
}
- cfsetospeed (&newtio, baud_rate);
- cfsetispeed (&newtio, baud_rate);
-
- tcsetattr(fd,TCSADRAIN,&newtio);
+ if (cfsetospeed (&newtio, baud_rate) < 0 || cfsetispeed (&newtio, baud_rate) < 0 ||
+ tcsetattr (fd, TCSADRAIN, &newtio) < 0)
+ return FALSE;
return TRUE;
}
diff --git a/support/serial.h b/support/serial.h
new file mode 100644
index 00000000000..8c3221ebab1
--- /dev/null
+++ b/support/serial.h
@@ -0,0 +1,31 @@
+
+#ifndef __SERIAL_H
+#define __SERIAL_H
+
+/* This is a copy of System.IO.Ports.Handshake */
+typedef enum {
+ NoneHandshake = 0,
+ XOnXOff = 1,
+ RequestToSend = 2,
+ RequestToSendXOnXOff = 3
+} MonoHandshake;
+
+/* This is a copy of System.IO.Ports.Parity */
+typedef enum {
+ NoneParity = 0,
+ Odd = 1,
+ Even = 2,
+ Mark = 3,
+ Space = 4
+} MonoParity;
+
+/* This is a copy of System.IO.Ports.StopBits */
+typedef enum {
+ NoneStopBits = 0,
+ One = 1,
+ Two = 2,
+ OnePointFive = 3
+} MonoStopBits;
+
+#endif
+