From 9b94df16b9cb155256b482afca878554b5e49ab5 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Tue, 11 Dec 2012 20:22:26 +0100 Subject: [PATCH] - add new type for context options - add new function mbus_context_set_option to set context specific options like retransmission or echo cancelation --- mbus/mbus-protocol-aux.c | 32 ++++++++++++++++++++++++++++++++ mbus/mbus-protocol-aux.h | 30 ++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c index 3708d1e..0d2645e 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -1485,6 +1485,38 @@ mbus_disconnect(mbus_handle * handle) return handle->close(handle); } +int +mbus_context_set_option(mbus_handle * handle, mbus_context_option option, long value) +{ + if (handle == NULL) + { + MBUS_ERROR("%s: Invalid M-Bus handle to set option.\n", __PRETTY_FUNCTION__); + return -1; + } + + switch (option) + { + case MBUS_OPTION_MAX_RETRY: + if ((value >= 0) && (value <= 9)) + { + handle->max_retry = value; + return 0; + } + break; + case MBUS_OPTION_PURGE_FIRST_FRAME: + if ((value == MBUS_FRAME_PURGE_NONE) || + (value == MBUS_FRAME_PURGE_M2S) || + (value == MBUS_FRAME_PURGE_S2M)) + { + handle->purge_first_frame = value; + return 0; + } + break; + } + + return -1; // unable to set option +} + int mbus_recv_frame(mbus_handle * handle, mbus_frame *frame) { diff --git a/mbus/mbus-protocol-aux.h b/mbus/mbus-protocol-aux.h index 40d9fd4..b9dc6bf 100755 --- a/mbus/mbus-protocol-aux.h +++ b/mbus/mbus-protocol-aux.h @@ -24,6 +24,8 @@ * or * mbus_handle = mbus_context_tcp(host, port); * + * mbus_context_set_option(mbus_handle,option,value); // optional + * * mbus_connect(mbus_handle); * * ... @@ -136,6 +138,15 @@ typedef struct _mbus_record { char *quantity; /**< Quantity type (e.g. Energy) */ } mbus_record; +/** + * MBus handle option type + */ +enum _mbus_context_option { + MBUS_OPTION_MAX_RETRY, + MBUS_OPTION_PURGE_FIRST_FRAME +}; + +typedef enum _mbus_context_option mbus_context_option; /** * Event callback functions @@ -194,6 +205,17 @@ int mbus_connect(mbus_handle * handle); */ int mbus_disconnect(mbus_handle * handle); +/** + * Set option of a M-Bus context. + * + * @param handle Initialized handle + * @param option option to set + * @param value value to set + * + * @return Zero when successful. + */ +int mbus_context_set_option(mbus_handle * handle, mbus_context_option option, long value); + /** * Receives a frame using "unified" handle * @@ -436,10 +458,10 @@ int mbus_scan_2nd_address_range(mbus_handle * handle, int pos, char *addr_mask); /** * Convert a buffer with hex values into a buffer with binary values. * - * @param src_buff source buffer with hex values - * @param src_len byte count of source buffer - * @param dest_buff destination buffer with binary values - * @param dest_len byte count of destination buffer + * @param dst destination buffer with binary values + * @param dst_len byte count of destination buffer + * @param src source buffer with hex values + * @param src_len byte count of source buffer * * @return byte count of successful converted values */