Remove trailing whitespace
Signed-off-by: Stefan Wahren <info@lategoodbye.de>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
||||
// Copyright (C) 2011, Robert Johansson and contributors, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
@ -13,9 +13,9 @@
|
||||
|
||||
/**
|
||||
* @file mbus-protocol-aux.h
|
||||
*
|
||||
*
|
||||
* @brief Auxiliary functions to the Freescada libmbus library
|
||||
*
|
||||
*
|
||||
* The idea is to simplify the basic task of querying MBus slaves and
|
||||
* the data processing.
|
||||
* Typical use might be (in oversimplified "pseudocode"):
|
||||
@ -160,26 +160,26 @@ extern void (*_mbus_found_event)(mbus_handle * handle, mbus_frame *frame);
|
||||
void mbus_register_scan_progress(void (*event)(mbus_handle * handle, const char *mask));
|
||||
void mbus_register_found_event(void (*event)(mbus_handle * handle, mbus_frame *frame));
|
||||
|
||||
/**
|
||||
/**
|
||||
* Allocate and initialize M-Bus serial context.
|
||||
*
|
||||
*
|
||||
* @param device Serial device (like /dev/ttyUSB0 or /dev/ttyS0)
|
||||
*
|
||||
*
|
||||
* @return Initialized "unified" handler when successful, NULL otherwise;
|
||||
*/
|
||||
mbus_handle * mbus_context_serial(const char *device);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Allocate and initialize M-Bus TCP context.
|
||||
*
|
||||
*
|
||||
* @param host Gateway host
|
||||
* @param port Gateway port
|
||||
*
|
||||
*
|
||||
* @return Initialized "unified" handler when successful, NULL otherwise;
|
||||
*/
|
||||
mbus_handle * mbus_context_tcp(const char *host, uint16_t port);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Deallocate memory used by M-Bus context.
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
@ -198,9 +198,9 @@ int mbus_connect(mbus_handle * handle);
|
||||
|
||||
/**
|
||||
* Disconnects the "unified" handle.
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_disconnect(mbus_handle * handle);
|
||||
@ -216,17 +216,17 @@ int mbus_disconnect(mbus_handle * handle);
|
||||
*/
|
||||
int mbus_context_set_option(mbus_handle * handle, mbus_context_option option, long value);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Receives a frame using "unified" handle
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param frame Received frame
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_recv_frame(mbus_handle * handle, mbus_frame *frame);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Used for handling collisions. Blocks as long as receiving frames or corrupted data.
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
@ -237,232 +237,232 @@ int mbus_purge_frames(mbus_handle * handle);
|
||||
|
||||
/**
|
||||
* Sends frame using "unified" handle
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param frame Frame to send
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_frame(mbus_handle * handle, mbus_frame *frame);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sends secondary address selection frame using "unified" handle
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param secondary_addr_str Secondary address
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_select_frame(mbus_handle * handle, const char *secondary_addr_str);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sends application reset to given slave using "unified" handle
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address (0-255)
|
||||
* @param subcode Subcode (0-255) or no subcode (-1)
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_application_reset_frame(mbus_handle * handle, int address, int subcode);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sends switch baudrate frame using "unified" handle
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address (0-255)
|
||||
* @param baudrate Baudrate (300,600,1200,2400,4800,9600,19200,38400)
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_switch_baudrate_frame(mbus_handle * handle, int address, long baudrate);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sends request frame (REQ_UD2) to given slave using "unified" handle
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address (0-255)
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_request_frame(mbus_handle * handle, int address);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sends a request and read replies until no more records available
|
||||
* or limit is reached.
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address (0-255)
|
||||
* @param reply pointer to an mbus frame for the reply
|
||||
* @param max_frames limit of frames to readout (0 = no limit)
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, int max_frames);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sends ping frame to given slave using "unified" handle
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address (0-255)
|
||||
* @param purge_response Response flag (=0 don't receive response, >0 purge response)
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_send_ping_frame(mbus_handle *handle, int address, char purge_response);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Select slave by secondary address using "unified" handle
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param mask Address/mask to select
|
||||
*
|
||||
*
|
||||
* @return See MBUS_PROBE_* constants
|
||||
*/
|
||||
int mbus_select_secondary_address(mbus_handle * handle, const char *mask);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Probe/address slave by secondary address using "unified" handle
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param mask Address/mask to probe
|
||||
* @param matching_addr Matched address (the buffer has tobe at least 16 bytes)
|
||||
*
|
||||
*
|
||||
* @return See MBUS_PROBE_* constants
|
||||
*/
|
||||
int mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *matching_addr);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Read data from given slave using "unified" handle and address types
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param address Address of the slave
|
||||
* @param reply Reply from the slave
|
||||
*
|
||||
*
|
||||
* @return Zero when successful.
|
||||
*/
|
||||
int mbus_read_slave(mbus_handle *handle, mbus_address *address, mbus_frame *reply);
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Allocate new data record. Use #mbus_record_free when finished.
|
||||
*
|
||||
*
|
||||
* @return pointer to the new record, NULL when failed
|
||||
*/
|
||||
mbus_record * mbus_record_new();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Destructor for mbus_record
|
||||
*
|
||||
*
|
||||
* @param rec record to be freed
|
||||
*/
|
||||
void mbus_record_free(mbus_record *rec);
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create/parse single counter from the fixed data structure
|
||||
*
|
||||
*
|
||||
* @param statusByte status byte
|
||||
* @param medium_unit_byte medium/unit byte
|
||||
* @param data pointer to the data counter (4 bytes)
|
||||
*
|
||||
*
|
||||
* @return Newly allocated record if succesful, NULL otherwise. Later on need to use #mbus_record_free
|
||||
*/
|
||||
mbus_record *mbus_parse_fixed_record(char statusByte, char medium_unit_byte, unsigned char *data);
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create/parse single counter from the variable data structure record
|
||||
*
|
||||
*
|
||||
* @param record record data to be parsed
|
||||
*
|
||||
*
|
||||
* @return Newly allocated record if succesful, NULL otherwise. Later on need to use #mbus_record_free
|
||||
*/
|
||||
mbus_record * mbus_parse_variable_record(mbus_data_record *record);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get normalized counter value for a fixed counter
|
||||
*
|
||||
* Get "normalized" value and unit of the counter
|
||||
*
|
||||
*
|
||||
* @param medium_unit_byte medium/unit byte of the fixed counter
|
||||
* @param medium_value raw counter value
|
||||
* @param unit_out units of the counter - use free when done
|
||||
* @param value_out resulting counter value
|
||||
* @param quantity_out parsed quantity, when done use "free"
|
||||
*
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_data_fixed_normalize(int medium_unit_byte, long medium_value, char **unit_out, double *value_out, char **quantity_out);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Decode value of a variable data structure
|
||||
*
|
||||
*
|
||||
* @param record record to be decoded
|
||||
* @param value_out_real numerical counter value output (when numerical)
|
||||
* @param value_out_str string counter value output (when string, NULL otherwise), when finished use "free *value_out_str"
|
||||
* @param value_out_str_size string counter value size
|
||||
*
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_data_variable_value_decode(mbus_record *record, double *value_out_real, char **value_out_str, int *value_out_str_size);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Decode units and normalize value using VIF/VIFE (used internally by mbus_vib_unit_normalize)
|
||||
*
|
||||
*
|
||||
* @param vif VIF (including standard extensions)
|
||||
* @param value already parsed "raw" numerical value
|
||||
* @param unit_out parsed unit, when done use "free"
|
||||
* @param value_out normalized value
|
||||
* @param quantity_out parsed quantity, when done use "free"
|
||||
*
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_vif_unit_normalize(int vif, double value, char **unit_out, double *value_out, char **quantity_out);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Decode units and normalize value from VIB
|
||||
*
|
||||
*
|
||||
* @param vib mbus value information block of the variable record
|
||||
* @param value already parsed "raw" numerical value
|
||||
* @param unit_out parsed unit, when done use "free"
|
||||
* @param value_out normalized value
|
||||
* @param quantity_out parsed quantity, when done use "free"
|
||||
*
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_vib_unit_normalize(mbus_value_information_block *vib, double value, char **unit_out, double *value_out, char ** quantity_out);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Generate XML for normalized variable-length data
|
||||
*
|
||||
*
|
||||
* @param data variable-length data
|
||||
*
|
||||
*
|
||||
* @return string with XML
|
||||
*/
|
||||
char * mbus_data_variable_xml_normalized(mbus_data_variable *data);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Return a string containing an XML representation of the normalized M-BUS frame data.
|
||||
*
|
||||
*
|
||||
* @param data M-Bus frame data
|
||||
*
|
||||
*
|
||||
* @return string with XML
|
||||
*/
|
||||
char * mbus_frame_data_xml_normalized(mbus_frame_data *data);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Iterate over secondary addresses, send a probe package to all addresses matching
|
||||
* the given addresses mask.
|
||||
*
|
||||
*
|
||||
* @param handle Initialized handle
|
||||
* @param pos current address
|
||||
* @param addr_mask address mask to
|
||||
*
|
||||
* @param addr_mask address mask to
|
||||
*
|
||||
* @return zero when OK
|
||||
*/
|
||||
int mbus_scan_2nd_address_range(mbus_handle * handle, int pos, char *addr_mask);
|
||||
|
1222
mbus/mbus-protocol.c
1222
mbus/mbus-protocol.c
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
||||
// Copyright (C) 2010-2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
/**
|
||||
* @file mbus-protocol.h
|
||||
*
|
||||
*
|
||||
* @brief Functions and data structures for M-Bus protocol parsing.
|
||||
*
|
||||
*/
|
||||
@ -82,13 +82,13 @@ typedef struct _mbus_frame {
|
||||
// variable data field
|
||||
unsigned char checksum;
|
||||
unsigned char stop;
|
||||
|
||||
unsigned char data[252];
|
||||
|
||||
unsigned char data[252];
|
||||
size_t data_size;
|
||||
|
||||
|
||||
int type;
|
||||
time_t timestamp;
|
||||
|
||||
|
||||
//mbus_frame_data frame_data;
|
||||
|
||||
void *next; // pointer to next mbus_frame for multi-telegram replies
|
||||
@ -99,7 +99,7 @@ typedef struct _mbus_slave_data {
|
||||
|
||||
int state_fcb;
|
||||
int state_acd;
|
||||
|
||||
|
||||
} mbus_slave_data;
|
||||
|
||||
#define NITEMS(x) (sizeof(x)/sizeof(x[0]))
|
||||
@ -134,7 +134,7 @@ typedef struct _mbus_slave_data {
|
||||
|
||||
|
||||
typedef struct _mbus_data_information_block {
|
||||
|
||||
|
||||
unsigned char dif;
|
||||
unsigned char dife[10];
|
||||
size_t ndife;
|
||||
@ -142,7 +142,7 @@ typedef struct _mbus_data_information_block {
|
||||
} mbus_data_information_block;
|
||||
|
||||
typedef struct _mbus_value_information_block {
|
||||
|
||||
|
||||
unsigned char vif;
|
||||
unsigned char vife[10];
|
||||
size_t nvife;
|
||||
@ -152,18 +152,18 @@ typedef struct _mbus_value_information_block {
|
||||
} mbus_value_information_block;
|
||||
|
||||
typedef struct _mbus_data_record_header {
|
||||
|
||||
|
||||
mbus_data_information_block dib;
|
||||
mbus_value_information_block vib;
|
||||
mbus_value_information_block vib;
|
||||
|
||||
} mbus_data_record_header;
|
||||
|
||||
typedef struct _mbus_data_record {
|
||||
|
||||
|
||||
mbus_data_record_header drh;
|
||||
|
||||
unsigned char data[234];
|
||||
size_t data_len;
|
||||
size_t data_len;
|
||||
|
||||
time_t timestamp;
|
||||
|
||||
@ -171,25 +171,25 @@ typedef struct _mbus_data_record {
|
||||
|
||||
} mbus_data_record;
|
||||
|
||||
//
|
||||
//
|
||||
// HEADER FOR VARIABLE LENGTH DATA FORMAT
|
||||
//
|
||||
//
|
||||
typedef struct _mbus_data_variable_header {
|
||||
|
||||
|
||||
//Ident.Nr. Manufr. Version Medium Access No. Status Signature
|
||||
//4 Byte 2 Byte 1 Byte 1 Byte 1 Byte 1 Byte 2 Byte
|
||||
|
||||
|
||||
// ex
|
||||
// 88 63 80 09 82 4D 02 04 15 00 00 00
|
||||
|
||||
|
||||
unsigned char id_bcd[4]; // 88 63 80 09
|
||||
unsigned char manufacturer[2]; // 82 4D
|
||||
unsigned char manufacturer[2]; // 82 4D
|
||||
unsigned char version; // 02
|
||||
unsigned char medium; // 04
|
||||
unsigned char access_no; // 15
|
||||
unsigned char status; // 00
|
||||
unsigned char signature[2]; // 00 00
|
||||
|
||||
|
||||
} mbus_data_variable_header;
|
||||
|
||||
#define MBUS_DATA_VARIABLE_HEADER_LENGTH 12
|
||||
@ -198,22 +198,22 @@ typedef struct _mbus_data_variable_header {
|
||||
// VARIABLE LENGTH DATA FORMAT
|
||||
//
|
||||
typedef struct _mbus_data_variable {
|
||||
|
||||
|
||||
mbus_data_variable_header header;
|
||||
|
||||
mbus_data_record *record;
|
||||
|
||||
mbus_data_record *record;
|
||||
size_t nrecords;
|
||||
|
||||
|
||||
unsigned char *data;
|
||||
size_t data_len;
|
||||
|
||||
|
||||
unsigned char more_records_follow;
|
||||
|
||||
|
||||
// are these needed/used?
|
||||
unsigned char mdh;
|
||||
unsigned char *mfg_data;
|
||||
size_t mfg_data_len;
|
||||
|
||||
size_t mfg_data_len;
|
||||
|
||||
} mbus_data_variable;
|
||||
|
||||
//
|
||||
@ -262,22 +262,22 @@ typedef struct _mbus_frame_data {
|
||||
|
||||
} mbus_frame_data;
|
||||
|
||||
//
|
||||
//
|
||||
// HEADER FOR SECONDARY ADDRESSING
|
||||
//
|
||||
//
|
||||
typedef struct _mbus_data_secondary_address {
|
||||
|
||||
//Ident.Nr. Manufr. Version Medium
|
||||
//4 Byte 2 Byte 1 Byte 1 Byte
|
||||
|
||||
|
||||
//Ident.Nr. Manufr. Version Medium
|
||||
//4 Byte 2 Byte 1 Byte 1 Byte
|
||||
|
||||
// ex
|
||||
// 14 49 10 01 10 57 01 06
|
||||
|
||||
|
||||
unsigned char id_bcd[4]; // 14 49 10 01
|
||||
unsigned char manufacturer[2]; // 10 57
|
||||
unsigned char version; // 01
|
||||
unsigned char medium; // 06
|
||||
|
||||
|
||||
} mbus_data_secondary_address;
|
||||
|
||||
|
||||
@ -309,7 +309,7 @@ typedef struct _mbus_data_secondary_address {
|
||||
|
||||
#define MBUS_FRAME_FIXED_SIZE_ACK 1
|
||||
#define MBUS_FRAME_FIXED_SIZE_SHORT 5
|
||||
#define MBUS_FRAME_FIXED_SIZE_CONTROL 6
|
||||
#define MBUS_FRAME_FIXED_SIZE_CONTROL 6
|
||||
#define MBUS_FRAME_FIXED_SIZE_LONG 6
|
||||
|
||||
//
|
||||
@ -463,7 +463,7 @@ typedef struct _mbus_data_secondary_address {
|
||||
|
||||
//
|
||||
// VARIABLE DATA FLAGS
|
||||
//
|
||||
//
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_OTHER 0x00
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_OIL 0x01
|
||||
#define MBUS_VARIABLE_DATA_MEDIUM_ELECTRICITY 0x02
|
||||
@ -554,7 +554,7 @@ int mbus_data_fixed_parse (mbus_frame *frame, mbus_data_fixed *data);
|
||||
int mbus_data_variable_parse(mbus_frame *frame, mbus_data_variable *data);
|
||||
|
||||
int mbus_frame_data_parse (mbus_frame *frame, mbus_frame_data *data);
|
||||
|
||||
|
||||
int mbus_frame_pack(mbus_frame *frame, unsigned char *data, size_t data_size);
|
||||
|
||||
int mbus_frame_verify(mbus_frame *frame);
|
||||
@ -615,7 +615,7 @@ void mbus_hex_dump(const char *label, const char *buff, size_t len);
|
||||
int mbus_data_manufacturer_encode(unsigned char *m_data, unsigned char *m_code);
|
||||
const char *mbus_decode_manufacturer(unsigned char byte1, unsigned char byte2);
|
||||
const char *mbus_data_product_name(mbus_data_variable_header *header);
|
||||
|
||||
|
||||
int mbus_data_bcd_encode(unsigned char *bcd_data, size_t bcd_data_size, int value);
|
||||
int mbus_data_int_encode(unsigned char *int_data, size_t int_data_size, int value);
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright (C) 2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
@ -105,7 +105,7 @@ mbus_serial_set_baudrate(mbus_handle *handle, long baudrate)
|
||||
return -1;
|
||||
|
||||
serial_data = (mbus_serial_data *) handle->auxdata;
|
||||
|
||||
|
||||
if (serial_data == NULL)
|
||||
return -1;
|
||||
|
||||
@ -201,12 +201,12 @@ mbus_serial_data_free(mbus_handle *handle)
|
||||
if (handle)
|
||||
{
|
||||
serial_data = (mbus_serial_data *) handle->auxdata;
|
||||
|
||||
|
||||
if (serial_data == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
free(serial_data->device);
|
||||
free(serial_data);
|
||||
handle->auxdata = NULL;
|
||||
@ -226,7 +226,7 @@ mbus_serial_send_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Make sure serial connection is open
|
||||
if (isatty(handle->fd) == 0)
|
||||
{
|
||||
@ -238,7 +238,7 @@ mbus_serial_send_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
fprintf(stderr, "%s: mbus_frame_pack failed\n", __PRETTY_FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#ifdef MBUS_SERIAL_DEBUG
|
||||
// if debug, dump in HEX form to stdout what we write to the serial port
|
||||
printf("%s: Dumping M-Bus frame [%d bytes]: ", __PRETTY_FUNCTION__, len);
|
||||
@ -254,16 +254,16 @@ mbus_serial_send_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
{
|
||||
//
|
||||
// call the send event function, if the callback function is registered
|
||||
//
|
||||
//
|
||||
if (_mbus_send_event)
|
||||
_mbus_send_event(MBUS_HANDLE_TYPE_SERIAL, buff, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
fprintf(stderr, "%s: Failed to write frame to socket (ret = %d: %s)\n", __PRETTY_FUNCTION__, ret, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// wait until complete frame has been transmitted
|
||||
//
|
||||
@ -281,13 +281,13 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
char buff[PACKET_BUFF_SIZE];
|
||||
int remaining, timeouts;
|
||||
ssize_t len, nread;
|
||||
|
||||
|
||||
if (handle == NULL || frame == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: Invalid parameter.\n", __PRETTY_FUNCTION__);
|
||||
return MBUS_RECV_RESULT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
// Make sure serial connection is open
|
||||
if (isatty(handle->fd) == 0)
|
||||
{
|
||||
@ -310,7 +310,7 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
// avoid out of bounds access
|
||||
return MBUS_RECV_RESULT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
//printf("%s: Attempt to read %d bytes [len = %d]\n", __PRETTY_FUNCTION__, remaining, len);
|
||||
|
||||
if ((nread = read(handle->fd, &buff[len], remaining)) == -1)
|
||||
@ -321,11 +321,11 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
}
|
||||
|
||||
// printf("%s: Got %d byte [remaining %d, len %d]\n", __PRETTY_FUNCTION__, nread, remaining, len);
|
||||
|
||||
|
||||
if (nread == 0)
|
||||
{
|
||||
timeouts++;
|
||||
|
||||
|
||||
if (timeouts >= 3)
|
||||
{
|
||||
// abort to avoid endless loop
|
||||
@ -333,7 +333,7 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (len > (SSIZE_MAX-nread))
|
||||
{
|
||||
// avoid overflow
|
||||
@ -349,13 +349,13 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
// No data received
|
||||
return MBUS_RECV_RESULT_TIMEOUT;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// call the receive event function, if the callback function is registered
|
||||
//
|
||||
//
|
||||
if (_mbus_recv_event)
|
||||
_mbus_recv_event(MBUS_HANDLE_TYPE_SERIAL, buff, len);
|
||||
|
||||
|
||||
if (remaining != 0)
|
||||
{
|
||||
// Would be OK when e.g. scanning the bus, otherwise it is a failure.
|
||||
@ -368,7 +368,7 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
fprintf(stderr, "%s: M-Bus layer failed to parse data.\n", __PRETTY_FUNCTION__);
|
||||
return MBUS_RECV_RESULT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
return MBUS_RECV_RESULT_OK;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright (C) 2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
/**
|
||||
* @file mbus-serial.h
|
||||
*
|
||||
*
|
||||
* @brief Functions and data structures for sending M-Bus data via RS232.
|
||||
*
|
||||
*/
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright (C) 2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
@ -104,12 +104,12 @@ mbus_tcp_data_free(mbus_handle *handle)
|
||||
if (handle)
|
||||
{
|
||||
tcp_data = (mbus_tcp_data *) handle->auxdata;
|
||||
|
||||
|
||||
if (tcp_data == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
free(tcp_data->host);
|
||||
free(tcp_data);
|
||||
handle->auxdata = NULL;
|
||||
@ -158,12 +158,12 @@ mbus_tcp_send_frame(mbus_handle *handle, mbus_frame *frame)
|
||||
{
|
||||
//
|
||||
// call the send event function, if the callback function is registered
|
||||
//
|
||||
//
|
||||
if (_mbus_send_event)
|
||||
_mbus_send_event(MBUS_HANDLE_TYPE_TCP, buff, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
snprintf(error_str, sizeof(error_str), "%s: Failed to write frame to socket (ret = %d)\n", __PRETTY_FUNCTION__, ret);
|
||||
mbus_error_str_set(error_str);
|
||||
return -1;
|
||||
@ -224,7 +224,7 @@ retry:
|
||||
// avoid overflow
|
||||
return MBUS_RECV_RESULT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
len += nread;
|
||||
}
|
||||
} while ((remaining = mbus_parse(frame, buff, len)) > 0);
|
||||
@ -244,7 +244,7 @@ retry:
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// The the timeout in seconds that will be used as the amount of time the
|
||||
/// The the timeout in seconds that will be used as the amount of time the
|
||||
/// a read operation will wait before giving up. Note: This configuration has
|
||||
/// to be made before calling mbus_tcp_connect.
|
||||
//------------------------------------------------------------------------------
|
||||
@ -256,7 +256,7 @@ mbus_tcp_set_timeout_set(double seconds)
|
||||
mbus_error_str_set("Invalid timeout (must be positive).");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
tcp_timeout_sec = (int)seconds;
|
||||
tcp_timeout_usec = (seconds - tcp_timeout_sec) * 1000000;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright (C) 2011, Robert Johansson, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
/**
|
||||
* @file mbus-tcp.h
|
||||
*
|
||||
*
|
||||
* @brief Functions and data structures for sending M-Bus data via TCP.
|
||||
*
|
||||
*/
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright (C) 2010, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Copyright (C) 2010, Raditex AB
|
||||
// All rights reserved.
|
||||
//
|
||||
// rSCADA
|
||||
// rSCADA
|
||||
// http://www.rSCADA.se
|
||||
// info@rscada.se
|
||||
//
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
/**
|
||||
* @file mbus.h
|
||||
*
|
||||
*
|
||||
* @brief Main include file for the Freescada libmbus library.
|
||||
*
|
||||
* Include this file to access the libmbus API:
|
||||
@ -20,7 +20,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*! \mainpage libmbus
|
||||
/*! \mainpage libmbus
|
||||
*
|
||||
* These pages contain automatically generated documentation for the libmbus
|
||||
* API. For examples on how to use the libmbus library, see the applications
|
||||
|
Reference in New Issue
Block a user