Data Structures | Defines | Typedefs | Functions

mbus/mbus-protocol.h File Reference

Functions and data structures for M-Bus protocol parsing. More...

#include <stdlib.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  _mbus_frame
struct  _mbus_slave_data
struct  _mbus_data_information_block
struct  _mbus_value_information_block
struct  _mbus_data_record_header
struct  _mbus_data_record
struct  _mbus_data_variable_header
struct  _mbus_data_variable
struct  _mbus_data_fixed
struct  _mbus_frame_data
struct  _mbus_data_secondary_address

Defines

#define NITEMS(x)   (sizeof(x)/sizeof(x[0]))
#define MBUS_DIB_DIF_EXTENSION_BIT   0x80
#define MBUS_DIB_VIF_EXTENSION_BIT   0x80
#define MBUS_DATA_TYPE_FIXED   1
#define MBUS_DATA_TYPE_VARIABLE   2
#define MBUS_FRAME_TYPE_ANY   0x00
#define MBUS_FRAME_TYPE_ACK   0x01
#define MBUS_FRAME_TYPE_SHORT   0x02
#define MBUS_FRAME_TYPE_CONTROL   0x03
#define MBUS_FRAME_TYPE_LONG   0x04
#define MBUS_FRAME_ACK_BASE_SIZE   1
#define MBUS_FRAME_SHORT_BASE_SIZE   5
#define MBUS_FRAME_CONTROL_BASE_SIZE   9
#define MBUS_FRAME_LONG_BASE_SIZE   9
#define MBUS_FRAME_BASE_SIZE_ACK   1
#define MBUS_FRAME_BASE_SIZE_SHORT   5
#define MBUS_FRAME_BASE_SIZE_CONTROL   9
#define MBUS_FRAME_BASE_SIZE_LONG   9
#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_LONG   6
#define MBUS_FRAME_ACK_START   0xE5
#define MBUS_FRAME_SHORT_START   0x10
#define MBUS_FRAME_CONTROL_START   0x68
#define MBUS_FRAME_LONG_START   0x68
#define MBUS_FRAME_STOP   0x16
#define MBUS_MAX_PRIMARY_SLAVES   256
#define MBUS_CONTROL_FIELD_DIRECTION   0x07
#define MBUS_CONTROL_FIELD_FCB   0x06
#define MBUS_CONTROL_FIELD_ACD   0x06
#define MBUS_CONTROL_FIELD_FCV   0x05
#define MBUS_CONTROL_FIELD_DFC   0x05
#define MBUS_CONTROL_FIELD_F3   0x04
#define MBUS_CONTROL_FIELD_F2   0x03
#define MBUS_CONTROL_FIELD_F1   0x02
#define MBUS_CONTROL_FIELD_F0   0x01
#define MBUS_CONTROL_MASK_SND_NKE   0x40
#define MBUS_CONTROL_MASK_SND_UD   0x53
#define MBUS_CONTROL_MASK_REQ_UD2   0x5B
#define MBUS_CONTROL_MASK_REQ_UD1   0x5A
#define MBUS_CONTROL_MASK_RSP_UD   0x08
#define MBUS_CONTROL_MASK_FCB   0x20
#define MBUS_CONTROL_MASK_FCV   0x10
#define MBUS_CONTROL_MASK_ACD   0x20
#define MBUS_CONTROL_MASK_DFC   0x10
#define MBUS_CONTROL_MASK_DIR   0x40
#define MBUS_CONTROL_MASK_DIR_M2S   0x40
#define MBUS_CONTROL_MASK_DIR_S2M   0x00
#define MBUS_ADDRESS_BROADCAST_REPLY   0xFE
#define MBUS_ADDRESS_BROADCAST_NOREPLY   0xFF
#define MBUS_ADDRESS_NETWORK_LAYER   0xFD
#define MBUS_CONTROL_INFO_DATA_SEND   0x51
#define MBUS_CONTROL_INFO_DATA_SEND_MSB   0x55
#define MBUS_CONTROL_INFO_SELECT_SLAVE   0x52
#define MBUS_CONTROL_INFO_SELECT_SLAVE_MSB   0x56
#define MBUS_CONTROL_INFO_APPLICATION_RESET   0x50
#define MBUS_CONTROL_INFO_SYNC_ACTION   0x54
#define MBUS_CONTROL_INFO_SET_BAUDRATE_300   0xB8
#define MBUS_CONTROL_INFO_SET_BAUDRATE_600   0xB9
#define MBUS_CONTROL_INFO_SET_BAUDRATE_1200   0xBA
#define MBUS_CONTROL_INFO_SET_BAUDRATE_2400   0xBB
#define MBUS_CONTROL_INFO_SET_BAUDRATE_4800   0xBC
#define MBUS_CONTROL_INFO_SET_BAUDRATE_9600   0xBD
#define MBUS_CONTROL_INFO_SET_BAUDRATE_19200   0xBE
#define MBUS_CONTROL_INFO_SET_BAUDRATE_38400   0xBF
#define MBUS_CONTROL_INFO_REQUEST_RAM_READ   0xB1
#define MBUS_CONTROL_INFO_SEND_USER_DATA   0xB2
#define MBUS_CONTROL_INFO_INIT_TEST_CALIB   0xB3
#define MBUS_CONTROL_INFO_EEPROM_READ   0xB4
#define MBUS_CONTROL_INFO_SW_TEST_START   0xB6
#define MBUS_CONTROL_INFO_RESP_FIXED   0x73
#define MBUS_CONTROL_INFO_RESP_FIXED_MSB   0x77
#define MBUS_CONTROL_INFO_RESP_VARIABLE   0x72
#define MBUS_CONTROL_INFO_RESP_VARIABLE_MSB   0x73
#define MBUS_DATA_FIXED_STATUS_FORMAT_MASK   0x80
#define MBUS_DATA_FIXED_STATUS_FORMAT_BCD   0x00
#define MBUS_DATA_FIXED_STATUS_FORMAT_INT   0x80
#define MBUS_DATA_FIXED_STATUS_DATE_MASK   0x40
#define MBUS_DATA_FIXED_STATUS_DATE_STORED   0x40
#define MBUS_DATA_FIXED_STATUS_DATE_CURRENT   0x00
#define MBUS_DATA_RECORD_DIF_MASK_INST   0x00
#define MBUS_DATA_RECORD_DIF_MASK_MIN   0x10
#define MBUS_DATA_RECORD_DIF_MASK_TYPE_INT32   0x04
#define MBUS_DATA_RECORD_DIF_MASK_STORAGE_NO   0x40
#define MBUS_DATA_RECORD_DIF_MASK_EXTENTION   0x80
#define MBUS_VARIABLE_DATA_MEDIUM_OTHER   0x00
#define MBUS_VARIABLE_DATA_MEDIUM_OIL   0x01
#define MBUS_VARIABLE_DATA_MEDIUM_ELECTRICITY   0x02
#define MBUS_VARIABLE_DATA_MEDIUM_GAS   0x03
#define MBUS_VARIABLE_DATA_MEDIUM_HEAT   0x04
#define MBUS_VARIABLE_DATA_MEDIUM_STEAM   0x05
#define MBUS_VARIABLE_DATA_MEDIUM_HOT_WATER   0x06
#define MBUS_VARIABLE_DATA_MEDIUM_WATER   0x07
#define MBUS_VARIABLE_DATA_MEDIUM_HEAT_COST   0x08
#define MBUS_VARIABLE_DATA_MEDIUM_COMPR_AIR   0x09
#define MBUS_VARIABLE_DATA_MEDIUM_COOL_OUT   0x0A
#define MBUS_VARIABLE_DATA_MEDIUM_COOL_IN   0x0B
#define MBUS_VARIABLE_DATA_MEDIUM_BUS   0x0E
#define MBUS_VARIABLE_DATA_MEDIUM_COLD_WATER   0x16
#define MBUS_VARIABLE_DATA_MEDIUM_DUAL_WATER   0x17
#define MBUS_VARIABLE_DATA_MEDIUM_PRESSURE   0x18
#define MBUS_VARIABLE_DATA_MEDIUM_ADC   0x19

Typedefs

typedef struct _mbus_frame mbus_frame
typedef struct _mbus_slave_data mbus_slave_data
typedef struct
_mbus_data_information_block 
mbus_data_information_block
typedef struct
_mbus_value_information_block 
mbus_value_information_block
typedef struct
_mbus_data_record_header 
mbus_data_record_header
typedef struct _mbus_data_record mbus_data_record
typedef struct
_mbus_data_variable_header 
mbus_data_variable_header
typedef struct _mbus_data_variable mbus_data_variable
typedef struct _mbus_data_fixed mbus_data_fixed
typedef struct _mbus_frame_data mbus_frame_data
typedef struct
_mbus_data_secondary_address 
mbus_data_secondary_address

Functions

mbus_data_recordmbus_data_record_new ()
 Allocate and initialize a new variable data record.
void mbus_data_record_free (mbus_data_record *record)
 free up memory associated with a data record and all the subsequent records in its list (apply recursively)
void mbus_data_record_append (mbus_data_variable *data, mbus_data_record *record)
 Return a string containing an XML representation of the M-BUS frame.
mbus_framembus_frame_new (int frame_type)
 Allocate an M-bus frame data structure and initialize it according to which frame type is requested.
int mbus_frame_free (mbus_frame *frame)
 Free the memory resources allocated for the M-Bus frame data structure.
mbus_frame_datambus_frame_data_new ()
 Allocate and initialize a new frame data structure.
void mbus_frame_data_free (mbus_frame_data *data)
 Free up data associated with a frame data structure.
int mbus_frame_calc_checksum (mbus_frame *frame)
 Caclulate the checksum of the M-Bus frame.
int mbus_frame_calc_length (mbus_frame *frame)
 Calculate the values of the lengths fields in the M-Bus frame.
int mbus_parse (mbus_frame *frame, u_char *data, size_t data_size)
 PARSE M-BUS frame data structures from binary data.
int mbus_data_fixed_parse (mbus_frame *frame, mbus_data_fixed *data)
 Parse the fixed-length data of a M-Bus frame.
int mbus_data_variable_parse (mbus_frame *frame, mbus_data_variable *data)
 Parse the variable-length data of a M-Bus frame.
int mbus_frame_data_parse (mbus_frame *frame, mbus_frame_data *data)
 Check the stype of the frame data (fixed or variable) and dispatch to the corresponding parser function.
int mbus_frame_pack (mbus_frame *frame, u_char *data, size_t data_size)
 Pack the M-bus frame into a binary string representation that can be sent on the bus.
int mbus_frame_verify (mbus_frame *frame)
 Verify that parsed frame is a valid M-bus frame.
int mbus_frame_internal_pack (mbus_frame *frame, mbus_frame_data *frame_data)
 pack the data stuctures into frame->data
const char * mbus_data_record_function (mbus_data_record *record)
 Return a string containing the function description.
const char * mbus_data_fixed_function (int status)
 For fixed-length frames, return a string describing the type of value (stored or actual).
int mbus_frame_type (mbus_frame *frame)
 Return the M-Bus frame type.
mbus_slave_datambus_slave_data_get (size_t i)
 Return a pointer to the slave_data register.
char * mbus_data_xml (mbus_frame_data *data)
char * mbus_data_variable_xml (mbus_data_variable *data)
 Generate XML for variable-length data.
char * mbus_data_fixed_xml (mbus_data_fixed *data)
 Generate XML representation of fixed-length frame.
char * mbus_frame_data_xml (mbus_frame_data *data)
 Return a string containing an XML representation of the M-BUS frame.
char * mbus_data_variable_header_xml (mbus_data_variable_header *header)
 Generate XML for the variable-length data header.
int mbus_frame_print (mbus_frame *frame)
 Dump frame in HEX on standard output.
int mbus_frame_data_print (mbus_frame_data *data)
 Print the data part of a frame.
int mbus_data_fixed_print (mbus_data_fixed *data)
int mbus_data_variable_header_print (mbus_data_variable_header *header)
 Print M-bus frame info to stdout.
int mbus_data_variable_print (mbus_data_variable *data)
char * mbus_error_str ()
 Return a string that contains an the latest error message.
void mbus_error_str_set (char *message)
void mbus_error_reset ()
int mbus_data_manufacturer_encode (u_char *m_data, u_char *m_code)
 Generate manufacturer code from 2-byte encoded data.
const char * mbus_decode_manufacturer (u_char byte1, u_char byte2)
 Generate manufacturer code from 2-byte encoded data.
int mbus_data_bcd_encode (u_char *bcd_data, size_t bcd_data_size, int value)
 Encode BCD data.
int mbus_data_int_encode (u_char *int_data, size_t int_data_size, int value)
 Encode INTEGER data (into 'int_data_size' bytes).
long mbus_data_bcd_decode (u_char *bcd_data, size_t bcd_data_size)
 Decode BCD data.
int mbus_data_int_decode (u_char *int_data, size_t int_data_size)
 Decode INTEGER data.
long mbus_data_long_decode (u_char *int_data, size_t int_data_size)
void mbus_data_str_decode (u_char *dst, const u_char *src, size_t len)
 Decode string data.
const char * mbus_data_fixed_medium (mbus_data_fixed *data)
 For fixed-length frames, get a string describing the medium.
const char * mbus_data_fixed_unit (int medium_unit_byte)
 For fixed-length frames, get a string describing the unit of the data.
const char * mbus_data_variable_medium_lookup (u_char medium)
 For variable-length frames, returns a string describing the medium.
const char * mbus_unit_prefix (int exp)
 Lookup the unit description from a VIF field in a data record.
const char * mbus_vib_unit_lookup (mbus_value_information_block *vib)
 Lookup the unit from the VIB (VIF or VIFE).
const char * mbus_vif_unit_lookup (u_char vif)
 Look up the unit from a VIF field in the data record.
u_char mbus_dif_datalength_lookup (u_char dif)
 Look up the data lenght from a VIF field in the data record.
char * mbus_frame_get_secondary_address (mbus_frame *frame)
int mbus_frame_select_secondary_pack (mbus_frame *frame, char *address)

Detailed Description

Functions and data structures for M-Bus protocol parsing.


Define Documentation

#define MBUS_ADDRESS_BROADCAST_NOREPLY   0xFF
#define MBUS_ADDRESS_BROADCAST_REPLY   0xFE
#define MBUS_ADDRESS_NETWORK_LAYER   0xFD
#define MBUS_CONTROL_FIELD_ACD   0x06
#define MBUS_CONTROL_FIELD_DFC   0x05
#define MBUS_CONTROL_FIELD_DIRECTION   0x07
#define MBUS_CONTROL_FIELD_F0   0x01
#define MBUS_CONTROL_FIELD_F1   0x02
#define MBUS_CONTROL_FIELD_F2   0x03
#define MBUS_CONTROL_FIELD_F3   0x04
#define MBUS_CONTROL_FIELD_FCB   0x06
#define MBUS_CONTROL_FIELD_FCV   0x05
#define MBUS_CONTROL_INFO_APPLICATION_RESET   0x50
#define MBUS_CONTROL_INFO_DATA_SEND   0x51
#define MBUS_CONTROL_INFO_DATA_SEND_MSB   0x55
#define MBUS_CONTROL_INFO_EEPROM_READ   0xB4
#define MBUS_CONTROL_INFO_INIT_TEST_CALIB   0xB3
#define MBUS_CONTROL_INFO_REQUEST_RAM_READ   0xB1
#define MBUS_CONTROL_INFO_RESP_FIXED   0x73
#define MBUS_CONTROL_INFO_RESP_FIXED_MSB   0x77
#define MBUS_CONTROL_INFO_RESP_VARIABLE   0x72
#define MBUS_CONTROL_INFO_RESP_VARIABLE_MSB   0x73
#define MBUS_CONTROL_INFO_SELECT_SLAVE   0x52
#define MBUS_CONTROL_INFO_SELECT_SLAVE_MSB   0x56
#define MBUS_CONTROL_INFO_SEND_USER_DATA   0xB2
#define MBUS_CONTROL_INFO_SET_BAUDRATE_1200   0xBA
#define MBUS_CONTROL_INFO_SET_BAUDRATE_19200   0xBE
#define MBUS_CONTROL_INFO_SET_BAUDRATE_2400   0xBB
#define MBUS_CONTROL_INFO_SET_BAUDRATE_300   0xB8
#define MBUS_CONTROL_INFO_SET_BAUDRATE_38400   0xBF
#define MBUS_CONTROL_INFO_SET_BAUDRATE_4800   0xBC
#define MBUS_CONTROL_INFO_SET_BAUDRATE_600   0xB9
#define MBUS_CONTROL_INFO_SET_BAUDRATE_9600   0xBD
#define MBUS_CONTROL_INFO_SW_TEST_START   0xB6
#define MBUS_CONTROL_INFO_SYNC_ACTION   0x54
#define MBUS_CONTROL_MASK_ACD   0x20
#define MBUS_CONTROL_MASK_DFC   0x10
#define MBUS_CONTROL_MASK_DIR   0x40
#define MBUS_CONTROL_MASK_DIR_M2S   0x40
#define MBUS_CONTROL_MASK_DIR_S2M   0x00
#define MBUS_CONTROL_MASK_FCB   0x20
#define MBUS_CONTROL_MASK_FCV   0x10
#define MBUS_CONTROL_MASK_REQ_UD1   0x5A
#define MBUS_CONTROL_MASK_REQ_UD2   0x5B
#define MBUS_CONTROL_MASK_RSP_UD   0x08
#define MBUS_CONTROL_MASK_SND_NKE   0x40
#define MBUS_CONTROL_MASK_SND_UD   0x53
#define MBUS_DATA_FIXED_STATUS_DATE_CURRENT   0x00
#define MBUS_DATA_FIXED_STATUS_DATE_MASK   0x40
#define MBUS_DATA_FIXED_STATUS_DATE_STORED   0x40
#define MBUS_DATA_FIXED_STATUS_FORMAT_BCD   0x00
#define MBUS_DATA_FIXED_STATUS_FORMAT_INT   0x80
#define MBUS_DATA_FIXED_STATUS_FORMAT_MASK   0x80
#define MBUS_DATA_RECORD_DIF_MASK_EXTENTION   0x80
#define MBUS_DATA_RECORD_DIF_MASK_INST   0x00
#define MBUS_DATA_RECORD_DIF_MASK_MIN   0x10
#define MBUS_DATA_RECORD_DIF_MASK_STORAGE_NO   0x40
#define MBUS_DATA_RECORD_DIF_MASK_TYPE_INT32   0x04
#define MBUS_DATA_TYPE_FIXED   1
#define MBUS_DATA_TYPE_VARIABLE   2
#define MBUS_DIB_DIF_EXTENSION_BIT   0x80
#define MBUS_DIB_VIF_EXTENSION_BIT   0x80
#define MBUS_FRAME_ACK_BASE_SIZE   1
#define MBUS_FRAME_ACK_START   0xE5
#define MBUS_FRAME_BASE_SIZE_ACK   1
#define MBUS_FRAME_BASE_SIZE_CONTROL   9
#define MBUS_FRAME_BASE_SIZE_LONG   9
#define MBUS_FRAME_BASE_SIZE_SHORT   5
#define MBUS_FRAME_CONTROL_BASE_SIZE   9
#define MBUS_FRAME_CONTROL_START   0x68
#define MBUS_FRAME_FIXED_SIZE_ACK   1
#define MBUS_FRAME_FIXED_SIZE_CONTROL   6
#define MBUS_FRAME_FIXED_SIZE_LONG   6
#define MBUS_FRAME_FIXED_SIZE_SHORT   5
#define MBUS_FRAME_LONG_BASE_SIZE   9
#define MBUS_FRAME_LONG_START   0x68
#define MBUS_FRAME_SHORT_BASE_SIZE   5
#define MBUS_FRAME_SHORT_START   0x10
#define MBUS_FRAME_STOP   0x16
#define MBUS_FRAME_TYPE_ACK   0x01
#define MBUS_FRAME_TYPE_ANY   0x00
#define MBUS_FRAME_TYPE_CONTROL   0x03
#define MBUS_FRAME_TYPE_LONG   0x04
#define MBUS_FRAME_TYPE_SHORT   0x02
#define MBUS_MAX_PRIMARY_SLAVES   256
#define MBUS_VARIABLE_DATA_MEDIUM_ADC   0x19
#define MBUS_VARIABLE_DATA_MEDIUM_BUS   0x0E
#define MBUS_VARIABLE_DATA_MEDIUM_COLD_WATER   0x16
#define MBUS_VARIABLE_DATA_MEDIUM_COMPR_AIR   0x09
#define MBUS_VARIABLE_DATA_MEDIUM_COOL_IN   0x0B
#define MBUS_VARIABLE_DATA_MEDIUM_COOL_OUT   0x0A
#define MBUS_VARIABLE_DATA_MEDIUM_DUAL_WATER   0x17
#define MBUS_VARIABLE_DATA_MEDIUM_ELECTRICITY   0x02
#define MBUS_VARIABLE_DATA_MEDIUM_GAS   0x03
#define MBUS_VARIABLE_DATA_MEDIUM_HEAT   0x04
#define MBUS_VARIABLE_DATA_MEDIUM_HEAT_COST   0x08
#define MBUS_VARIABLE_DATA_MEDIUM_HOT_WATER   0x06
#define MBUS_VARIABLE_DATA_MEDIUM_OIL   0x01
#define MBUS_VARIABLE_DATA_MEDIUM_OTHER   0x00
#define MBUS_VARIABLE_DATA_MEDIUM_PRESSURE   0x18
#define MBUS_VARIABLE_DATA_MEDIUM_STEAM   0x05
#define MBUS_VARIABLE_DATA_MEDIUM_WATER   0x07
#define NITEMS (   x  )     (sizeof(x)/sizeof(x[0]))

Typedef Documentation

typedef struct _mbus_frame mbus_frame

Function Documentation

long mbus_data_bcd_decode ( u_char *  bcd_data,
size_t  bcd_data_size 
)

Decode BCD data.

int mbus_data_bcd_encode ( u_char *  bcd_data,
size_t  bcd_data_size,
int  value 
)

Encode BCD data.

const char* mbus_data_fixed_function ( int  status  ) 

For fixed-length frames, return a string describing the type of value (stored or actual).

const char* mbus_data_fixed_medium ( mbus_data_fixed data  ) 

For fixed-length frames, get a string describing the medium.

int mbus_data_fixed_parse ( mbus_frame frame,
mbus_data_fixed data 
)

Parse the fixed-length data of a M-Bus frame.

int mbus_data_fixed_print ( mbus_data_fixed data  ) 
const char* mbus_data_fixed_unit ( int  medium_unit_byte  ) 

For fixed-length frames, get a string describing the unit of the data.

char* mbus_data_fixed_xml ( mbus_data_fixed data  ) 

Generate XML representation of fixed-length frame.

int mbus_data_int_decode ( u_char *  int_data,
size_t  int_data_size 
)

Decode INTEGER data.

int mbus_data_int_encode ( u_char *  int_data,
size_t  int_data_size,
int  value 
)

Encode INTEGER data (into 'int_data_size' bytes).

long mbus_data_long_decode ( u_char *  int_data,
size_t  int_data_size 
)
int mbus_data_manufacturer_encode ( u_char *  m_data,
u_char *  m_code 
)

Generate manufacturer code from 2-byte encoded data.

void mbus_data_record_append ( mbus_data_variable data,
mbus_data_record record 
)

Return a string containing an XML representation of the M-BUS frame.

void mbus_data_record_free ( mbus_data_record record  ) 

free up memory associated with a data record and all the subsequent records in its list (apply recursively)

const char* mbus_data_record_function ( mbus_data_record record  ) 

Return a string containing the function description.

mbus_data_record* mbus_data_record_new (  ) 

Allocate and initialize a new variable data record.

void mbus_data_str_decode ( u_char *  dst,
const u_char *  src,
size_t  len 
)

Decode string data.

int mbus_data_variable_header_print ( mbus_data_variable_header header  ) 

Print M-bus frame info to stdout.

char* mbus_data_variable_header_xml ( mbus_data_variable_header header  ) 

Generate XML for the variable-length data header.

const char* mbus_data_variable_medium_lookup ( u_char  medium  ) 

For variable-length frames, returns a string describing the medium.

int mbus_data_variable_parse ( mbus_frame frame,
mbus_data_variable data 
)

Parse the variable-length data of a M-Bus frame.

int mbus_data_variable_print ( mbus_data_variable data  ) 
char* mbus_data_variable_xml ( mbus_data_variable data  ) 

Generate XML for variable-length data.

char* mbus_data_xml ( mbus_frame_data data  ) 
const char* mbus_decode_manufacturer ( u_char  byte1,
u_char  byte2 
)

Generate manufacturer code from 2-byte encoded data.

u_char mbus_dif_datalength_lookup ( u_char  dif  ) 

Look up the data lenght from a VIF field in the data record.

See the table on page 41 the M-BUS specification.

void mbus_error_reset (  ) 
char* mbus_error_str (  ) 

Return a string that contains an the latest error message.

void mbus_error_str_set ( char *  message  ) 
int mbus_frame_calc_checksum ( mbus_frame frame  ) 

Caclulate the checksum of the M-Bus frame.

The checksum algorithm is the arithmetic sum of the frame content, without using carry. Which content that is included in the checksum calculation depends on the frame type.

int mbus_frame_calc_length ( mbus_frame frame  ) 

Calculate the values of the lengths fields in the M-Bus frame.

void mbus_frame_data_free ( mbus_frame_data data  ) 

Free up data associated with a frame data structure.

mbus_frame_data* mbus_frame_data_new (  ) 

Allocate and initialize a new frame data structure.

int mbus_frame_data_parse ( mbus_frame frame,
mbus_frame_data data 
)

Check the stype of the frame data (fixed or variable) and dispatch to the corresponding parser function.

int mbus_frame_data_print ( mbus_frame_data data  ) 

Print the data part of a frame.

char* mbus_frame_data_xml ( mbus_frame_data data  ) 

Return a string containing an XML representation of the M-BUS frame.

int mbus_frame_free ( mbus_frame frame  ) 

Free the memory resources allocated for the M-Bus frame data structure.

char* mbus_frame_get_secondary_address ( mbus_frame frame  ) 
int mbus_frame_internal_pack ( mbus_frame frame,
mbus_frame_data frame_data 
)

pack the data stuctures into frame->data

mbus_frame* mbus_frame_new ( int  frame_type  ) 

Allocate an M-bus frame data structure and initialize it according to which frame type is requested.

int mbus_frame_pack ( mbus_frame frame,
u_char *  data,
size_t  data_size 
)

Pack the M-bus frame into a binary string representation that can be sent on the bus.

The binary packet format is different for the different types of M-bus frames.

int mbus_frame_print ( mbus_frame frame  ) 

Dump frame in HEX on standard output.

int mbus_frame_select_secondary_pack ( mbus_frame frame,
char *  address 
)
int mbus_frame_type ( mbus_frame frame  ) 

Return the M-Bus frame type.

int mbus_frame_verify ( mbus_frame frame  ) 

Verify that parsed frame is a valid M-bus frame.

int mbus_parse ( mbus_frame frame,
u_char *  data,
size_t  data_size 
)

PARSE M-BUS frame data structures from binary data.

mbus_slave_data* mbus_slave_data_get ( size_t  i  ) 

Return a pointer to the slave_data register.

This register can be used for storing current slave status.

const char* mbus_unit_prefix ( int  exp  ) 

Lookup the unit description from a VIF field in a data record.

const char* mbus_vib_unit_lookup ( mbus_value_information_block vib  ) 

Lookup the unit from the VIB (VIF or VIFE).

const char* mbus_vif_unit_lookup ( u_char  vif  ) 

Look up the unit from a VIF field in the data record.

See section 8.4.3 Codes for Value Information Field (VIF) in the M-BUS spec

 All Data Structures Files Functions Variables Typedefs Defines