#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_record * | mbus_record_new () |
Allocate new data record. | |
void | mbus_record_free (mbus_record *rec) |
Destructor for mbus_record. | |
mbus_record * | mbus_parse_fixed_record (char status_byte, char medium_unit, u_char *data) |
Create/parse single counter from the fixed data structure. | |
mbus_record * | mbus_parse_variable_record (mbus_data_record *data) |
Create/parse single counter from the variable data structure record. | |
mbus_handle * | mbus_connect_serial (const char *device) |
Connects to serial gateway and initializes MBus handle. | |
mbus_handle * | mbus_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 MBUS_DEBUG | ( | ... | ) |
#define MBUS_ERROR | ( | ... | ) | fprintf (stderr, __VA_ARGS__) |
typedef struct _mbus_variable_vif mbus_variable_vif |
mbus_handle* mbus_connect_serial | ( | const char * | device | ) |
Connects to serial gateway and initializes MBus handle.
device | Serial device (like /dev/ttyUSB0 or /dev/ttyS0) |
mbus_handle* mbus_connect_tcp | ( | const char * | host, | |
int | port | |||
) |
Connects to TCP gateway and initializes MBus handle.
host | Gateway host | |
port | Gateway port |
int mbus_disconnect | ( | mbus_handle * | handle | ) |
Disconnects the "unified" handle.
handle | Initialized handle |
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.
statusByte | status byte | |
medium_unit_byte | medium/unit byte | |
data | pointer to the data counter (4 bytes) |
mbus_record* mbus_parse_variable_record | ( | mbus_data_record * | record | ) |
Create/parse single counter from the variable data structure record.
data | record data to be parsed |
< 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.
handle | Initialized handle | |
mask | Address/mask to probe | |
matching_addr | Matched address (the buffer has tobe at least 16 bytes) |
int mbus_read_slave | ( | mbus_handle * | handle, | |
mbus_address * | address, | |||
mbus_frame * | reply | |||
) |
Read data from given slave using "unified" handle and address types.
handle | Initialized handle | |
address | Address of the slave | |
reply | Reply from the slave |
void mbus_record_free | ( | mbus_record * | rec | ) |
Destructor for mbus_record.
rec | record to be freed |
mbus_record* mbus_record_new | ( | ) |
Allocate new data record.
Use mbus_record_free when finished.
int mbus_recv_frame | ( | mbus_handle * | handle, | |
mbus_frame * | frame | |||
) |
Receives a frame using "unified" handle.
handle | Initialized handle | |
frame | Received frame |
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.
pos | current address | |
addr_mask | address mask to |
int mbus_send_frame | ( | mbus_handle * | handle, | |
mbus_frame * | frame | |||
) |
Sends frame using "unified" handle.
handle | Initialized handle | |
frame | Frame to send |
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.
handle | Initialized handle | |
secondary_addr_str | Secondary address |
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.
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" |
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).
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" |