Data Structures | Defines | Typedefs | Functions | Variables

mbus/mbus-protocol-aux.c File Reference

#include "mbus-protocol-aux.h"
#include <stdio.h>
#include <string.h>

Data Structures

struct  _mbus_variable_vif

Defines

#define MBUS_ERROR(...)   fprintf (stderr, __VA_ARGS__)
#define MBUS_DEBUG(...)

Typedefs

typedef struct _mbus_variable_vif mbus_variable_vif

Functions

int mbus_fixed_normalize (int medium_unit, long medium_value, char **unit_out, double *value_out, char **quantity_out)
int mbus_variable_value_decode (mbus_data_record *record, double *value_out_real, char **value_out_str, int *value_out_str_size)
int mbus_vif_unit_normalize (int vif, double value, char **unit_out, double *value_out, char **quantity_out)
 Decode units and normalize value using VIF/VIFE (used internally by mbus_vib_unit_normalize).
int mbus_vib_unit_normalize (mbus_value_information_block *vib, double value, char **unit_out, double *value_out, char **quantity_out)
 Decode units and normalize value from VIB.
mbus_recordmbus_record_new ()
 Allocate new data record.
void mbus_record_free (mbus_record *rec)
 Destructor for mbus_record.
mbus_recordmbus_parse_fixed_record (char status_byte, char medium_unit, u_char *data)
 Create/parse single counter from the fixed data structure.
mbus_recordmbus_parse_variable_record (mbus_data_record *data)
 Create/parse single counter from the variable data structure record.
mbus_handlembus_connect_serial (const char *device)
 Connects to serial gateway and initializes MBus handle.
mbus_handlembus_connect_tcp (const char *host, int port)
 Connects to TCP gateway and initializes MBus handle.
int mbus_disconnect (mbus_handle *handle)
 Disconnects the "unified" handle.
int mbus_recv_frame (mbus_handle *handle, mbus_frame *frame)
 Receives a frame using "unified" handle.
int mbus_send_frame (mbus_handle *handle, mbus_frame *frame)
 Sends frame using "unified" handle.
int mbus_send_select_frame (mbus_handle *handle, const char *secondary_addr_str)
 Sends secodary address selection frame using "unified" handle.
int mbus_send_request_frame (mbus_handle *handle, int address)
int mbus_send_ping_frame (mbus_handle *handle, int address)
int mbus_probe_secondary_address (mbus_handle *handle, const char *mask, char *matching_addr)
 Probe/address slave by secondary address using "unified" handle.
int mbus_read_slave (mbus_handle *handle, mbus_address *address, mbus_frame *reply)
 Read data from given slave using "unified" handle and address types.
int mbus_scan_2nd_address_range (mbus_handle *handle, int pos, char *addr_mask)
 Iterate over secondary addresses, send a probe package to all addresses matching the given addresses mask.

Variables

mbus_variable_vif vif_table []
mbus_variable_vif fixed_table []

Define Documentation

#define MBUS_DEBUG (   ...  ) 
#define MBUS_ERROR (   ...  )     fprintf (stderr, __VA_ARGS__)

Typedef Documentation


Function Documentation

mbus_handle* mbus_connect_serial ( const char *  device  ) 

Connects to serial gateway and initializes MBus handle.

Parameters:
device Serial device (like /dev/ttyUSB0 or /dev/ttyS0)
Returns:
Initialized "unified" handler when successful, NULL otherwise;
mbus_handle* mbus_connect_tcp ( const char *  host,
int  port 
)

Connects to TCP gateway and initializes MBus handle.

Parameters:
host Gateway host
port Gateway port
Returns:
Initialized "unified" handler when successful, NULL otherwise;
int mbus_disconnect ( mbus_handle handle  ) 

Disconnects the "unified" handle.

Parameters:
handle Initialized handle
Returns:
Zero when successful.
int mbus_fixed_normalize ( int  medium_unit,
long  medium_value,
char **  unit_out,
double *  value_out,
char **  quantity_out 
)
mbus_record* mbus_parse_fixed_record ( char  statusByte,
char  medium_unit_byte,
u_char *  data 
)

Create/parse single counter from the fixed data structure.

Parameters:
statusByte status byte
medium_unit_byte medium/unit byte
data pointer to the data counter (4 bytes)
Returns:
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  ) 

Create/parse single counter from the variable data structure record.

Parameters:
data record data to be parsed
Returns:
Newly allocated record if succesful, NULL otherwise. Later on need to use mbus_record_free

< raw value

< normalized value

int mbus_probe_secondary_address ( mbus_handle handle,
const char *  mask,
char *  matching_addr 
)

Probe/address slave by secondary address using "unified" handle.

Parameters:
handle Initialized handle
mask Address/mask to probe
matching_addr Matched address (the buffer has tobe at least 16 bytes)
Returns:
See MBUS_PROBE_* constants
int mbus_read_slave ( mbus_handle handle,
mbus_address address,
mbus_frame reply 
)

Read data from given slave using "unified" handle and address types.

Parameters:
handle Initialized handle
address Address of the slave
reply Reply from the slave
Returns:
Zero when successful.
void mbus_record_free ( mbus_record rec  ) 

Destructor for mbus_record.

Parameters:
rec record to be freed
mbus_record* mbus_record_new (  ) 

Allocate new data record.

Use mbus_record_free when finished.

Returns:
pointer to the new record, NULL when failed
int mbus_recv_frame ( mbus_handle handle,
mbus_frame frame 
)

Receives a frame using "unified" handle.

Parameters:
handle Initialized handle
frame Received frame
Returns:
Zero when successful.
int mbus_scan_2nd_address_range ( mbus_handle handle,
int  pos,
char *  addr_mask 
)

Iterate over secondary addresses, send a probe package to all addresses matching the given addresses mask.

Parameters:
pos current address
addr_mask address mask to
Returns:
zero when OK
int mbus_send_frame ( mbus_handle handle,
mbus_frame frame 
)

Sends frame using "unified" handle.

Parameters:
handle Initialized handle
frame Frame to send
Returns:
Zero when successful.
int mbus_send_ping_frame ( mbus_handle handle,
int  address 
)
int mbus_send_request_frame ( mbus_handle handle,
int  address 
)
int mbus_send_select_frame ( mbus_handle handle,
const char *  secondary_addr_str 
)

Sends secodary address selection frame using "unified" handle.

Parameters:
handle Initialized handle
secondary_addr_str Secondary address
Returns:
Zero when successful.
int mbus_variable_value_decode ( mbus_data_record record,
double *  value_out_real,
char **  value_out_str,
int *  value_out_str_size 
)
int mbus_vib_unit_normalize ( mbus_value_information_block vib,
double  value,
char **  unit_out,
double *  value_out,
char **  quantity_out 
)

Decode units and normalize value from VIB.

Parameters:
vib mbus value information block of the variable record
value already parsed "raw" numerical value
unit_out parsed unit, when done use "free"
value_out normalized value
quantity_out parsed quantity, when done use "free"
Returns:
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 using VIF/VIFE (used internally by mbus_vib_unit_normalize).

Parameters:
vif VIF (including standard extensions)
value already parsed "raw" numerical value
unit_out parsed unit, when done use "free"
value_out normalized value
quantity_out parsed quantity, when done use "free"
Returns:
zero when OK

Variable Documentation

 All Data Structures Files Functions Variables Typedefs Defines