From e432ce60065f9d073dca5d639a4fc179de566639 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Mon, 25 Nov 2013 18:05:58 +0000 Subject: [PATCH] Support mark/space parity settings. --- libserialport.h.in | 4 ++++ serialport.c | 30 +++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/libserialport.h.in b/libserialport.h.in index 6aa5f6f..649eb2c 100644 --- a/libserialport.h.in +++ b/libserialport.h.in @@ -144,6 +144,10 @@ enum sp_parity { SP_PARITY_ODD = 1, /** Even parity. */ SP_PARITY_EVEN = 2, + /** Mark parity. */ + SP_PARITY_MARK = 3, + /** Space parity. */ + SP_PARITY_SPACE = 4, }; /** RTS pin behaviour. */ diff --git a/serialport.c b/serialport.c index a0faf6a..05fb85c 100644 --- a/serialport.c +++ b/serialport.c @@ -1024,11 +1024,17 @@ static enum sp_return get_config(struct sp_port *port, struct port_data *data, case NOPARITY: config->parity = SP_PARITY_NONE; break; + case ODDPARITY: + config->parity = SP_PARITY_ODD; + break; case EVENPARITY: config->parity = SP_PARITY_EVEN; break; - case ODDPARITY: - config->parity = SP_PARITY_ODD; + case MARKPARITY: + config->parity = SP_PARITY_MARK; + break; + case SPACEPARITY: + config->parity = SP_PARITY_SPACE; break; default: config->parity = -1; @@ -1150,6 +1156,8 @@ static enum sp_return get_config(struct sp_port *port, struct port_data *data, config->parity = SP_PARITY_NONE; else if (!(data->term.c_cflag & PARENB) || (data->term.c_iflag & IGNPAR)) config->parity = -1; + else if (data->term.c_cflag & CMSPAR) + config->parity = (data->term.c_cflag & PARODD) ? SP_PARITY_MARK : SP_PARITY_SPACE; else config->parity = (data->term.c_cflag & PARODD) ? SP_PARITY_ODD : SP_PARITY_EVEN; @@ -1231,11 +1239,17 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data, case SP_PARITY_NONE: data->dcb.Parity = NOPARITY; break; + case SP_PARITY_ODD: + data->dcb.Parity = ODDPARITY; + break; case SP_PARITY_EVEN: data->dcb.Parity = EVENPARITY; break; - case SP_PARITY_ODD: - data->dcb.Parity = ODDPARITY; + case SP_PARITY_MARK: + data->dcb.Parity = MARKPARITY; + break; + case SP_PARITY_SPACE: + data->dcb.Parity = SPACEPARITY; break; default: RETURN_ERROR(SP_ERR_ARG, "Invalid parity setting"); @@ -1393,7 +1407,7 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data, if (config->parity >= 0) { data->term.c_iflag &= ~IGNPAR; - data->term.c_cflag &= ~(PARENB | PARODD); + data->term.c_cflag &= ~(PARENB | PARODD | CMSPAR); switch (config->parity) { case SP_PARITY_NONE: data->term.c_iflag |= IGNPAR; @@ -1404,6 +1418,12 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data, case SP_PARITY_ODD: data->term.c_cflag |= PARENB | PARODD; break; + case SP_PARITY_MARK: + data->term.c_cflag |= PARENB | PARODD | CMSPAR; + break; + case SP_PARITY_SPACE: + data->term.c_cflag |= PARENB | CMSPAR; + break; default: RETURN_ERROR(SP_ERR_ARG, "Invalid parity setting"); }