Defines | Functions | Variables

mbus/mbus-protocol.c File Reference

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <mbus/mbus-protocol.h>

Defines

#define NITEMS(x)   (sizeof(x)/sizeof(x[0]))

Functions

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 ()
mbus_slave_datambus_slave_data_get (size_t i)
 Return a pointer to the slave_data register.
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.
u_char calc_checksum (mbus_frame *frame)
 Caclulate the checksum of the M-Bus frame. Internal.
int mbus_frame_calc_checksum (mbus_frame *frame)
 Caclulate the checksum of the M-Bus frame.
u_char calc_length (const mbus_frame *frame)
 Calculate the values of the lengths fields in 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_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_data_bcd_encode (u_char *bcd_data, size_t bcd_data_size, int value)
 Encode BCD data.
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)
int mbus_data_int_encode (u_char *int_data, size_t int_data_size, int value)
 Encode INTEGER data (into 'int_data_size' bytes).
void mbus_data_str_decode (u_char *dst, const u_char *src, size_t len)
 Decode string data.
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.
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.
u_char mbus_dif_datalength_lookup (u_char dif)
 Look up the data lenght from a VIF field in the data record.
const char * mbus_vif_unit_lookup (u_char vif)
 Look up the unit from a VIF field in the 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_data_record_decode (mbus_data_record *record)
 Return a string containing the data.
const char * mbus_data_record_unit (mbus_data_record *record)
 Return the unit description for a variable-length data record.
const char * mbus_data_record_value (mbus_data_record *record)
 Return the value for a variable-length data record.
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_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_internal_pack (mbus_frame *frame, mbus_frame_data *frame_data)
 pack the data stuctures into frame->data
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_variable_header_print (mbus_data_variable_header *header)
 Print M-bus frame info to stdout.
int mbus_data_variable_print (mbus_data_variable *data)
int mbus_data_fixed_print (mbus_data_fixed *data)
char * mbus_data_variable_header_xml (mbus_data_variable_header *header)
 Generate XML for the variable-length data header.
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.
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.
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.
char * mbus_frame_get_secondary_address (mbus_frame *frame)
int mbus_frame_select_secondary_pack (mbus_frame *frame, char *address)

Variables

static int parse_debug = 0
static char error_str [512]
static mbus_slave_data slave_data [MBUS_MAX_PRIMARY_SLAVES]

Define Documentation

#define NITEMS (   x  )     (sizeof(x)/sizeof(x[0]))

Function Documentation

u_char calc_checksum ( mbus_frame frame  ) 

Caclulate the checksum of the M-Bus frame. Internal.

u_char calc_length ( const mbus_frame frame  ) 

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

Internal.

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.

const char* mbus_data_record_decode ( mbus_data_record record  ) 

Return a string containing the data.

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.

const char* mbus_data_record_unit ( mbus_data_record record  ) 

Return the unit description for a variable-length data record.

const char* mbus_data_record_value ( mbus_data_record record  ) 

Return the value for a variable-length 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.

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


Variable Documentation

char error_str[512] [static]
int parse_debug = 0 [static]
mbus_slave_data slave_data[MBUS_MAX_PRIMARY_SLAVES] [static]
 All Data Structures Files Functions Variables Typedefs Defines