libexplain  1.4.D001
libexplain/buffer/serial_rs485.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - a library of system-call-specific strerror replacements
00003  * Copyright (C) 2011, 2013 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU Lesser General Public License as
00007  * published by the Free Software Foundation; either version 3 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include <libexplain/ac/linux/serial.h>
00020 
00021 #include <libexplain/buffer/int32_t.h>
00022 #include <libexplain/buffer/pointer.h>
00023 #include <libexplain/buffer/serial_rs485.h>
00024 #include <libexplain/is_efault.h>
00025 #include <libexplain/parse_bits.h>
00026 
00027 
00028 #ifdef HAVE_STRUCT_SERIAL_RS485
00029 
00030 static void
00031 explain_buffer_serial_rs485_flags(explain_string_buffer_t *sb, uint32_t value)
00032 {
00033     static const explain_parse_bits_table_t table[] =
00034     {
00035 #ifdef SER_RS485_ENABLED
00036         { "SER_RS485_ENABLED", SER_RS485_ENABLED },
00037 #endif
00038 #ifdef SER_RS485_RTS_ON_SEND
00039         { "SER_RS485_RTS_ON_SEND", SER_RS485_RTS_ON_SEND },
00040 #endif
00041 #ifdef SER_RS485_RTS_AFTER_SEND
00042         { "SER_RS485_RTS_AFTER_SEND", SER_RS485_RTS_AFTER_SEND },
00043 #endif
00044 #ifdef SER_RS485_RTS_BEFORE_SEND
00045         { "SER_RS485_RTS_BEFORE_SEND", SER_RS485_RTS_BEFORE_SEND },
00046 #endif
00047     };
00048 
00049     explain_parse_bits_print(sb, value, table, SIZEOF(table));
00050 }
00051 
00052 
00053 void
00054 explain_buffer_serial_rs485(explain_string_buffer_t *sb,
00055     const struct serial_rs485 *data)
00056 {
00057     if (explain_is_efault_pointer(data, sizeof(*data)))
00058     {
00059         explain_buffer_pointer(sb, data);
00060         return;
00061     }
00062 
00063     explain_string_buffer_puts(sb, "{ flags = ");
00064     explain_buffer_serial_rs485_flags(sb, data->flags);
00065     if (data->delay_rts_before_send)
00066     {
00067         explain_string_buffer_puts(sb, ", delay_rts_before_send = ");
00068         explain_buffer_uint32_t(sb, data->delay_rts_before_send);
00069     }
00070 #ifdef HAVE_STRUCT_SERIAL_RS485_delay_rts_after_send
00071     if (data->delay_rts_after_send)
00072     {
00073         explain_string_buffer_puts(sb, ", delay_rts_after_send = ");
00074         explain_buffer_uint32_t(sb, data->delay_rts_after_send);
00075     }
00076 #endif
00077     if (!explain_uint32_array_all_zero(data->padding, SIZEOF(data->padding)))
00078     {
00079         explain_string_buffer_puts(sb, ", padding = ");
00080         explain_buffer_uint32_array(sb, data->padding, SIZEOF(data->padding));
00081     }
00082     explain_string_buffer_puts(sb, " }");
00083 }
00084 
00085 #else
00086 
00087 void
00088 explain_buffer_serial_rs485(explain_string_buffer_t *sb,
00089     const struct serial_rs485 *data)
00090 {
00091     explain_buffer_pointer(sb, data);
00092 }
00093 
00094 #endif
00095 /* vim: set ts=8 sw=4 et : */