Radiocraft Wireless M-Bus extension module  2.18
Helper C functions

These functions are called from different C functions and contain common functionality. More...

Modules

 List helper functions
 These functions are used to manipulate the internal buffer.
 

Functions

static void mbusDebug (const char *prefix, const char *format,...)
 Send mbus debug message to the device output in the format "<prefix>:<formated string>" This function is by default empty, but is active when compiling with DEBUG defined. More...
 
static void mbusPrintInfo (const char *prefix, const char *format,...)
 Send mbus info message to the device output in the format "<prefix>:<formated string>". More...
 
static int8 mbus_address_compare (tdef_mbus_slave_address *a, tdef_mbus_frame *f)
 Compare the address in a received frame to a given address. More...
 
static int mbusPower (uint8 power)
 Control power to module. More...
 
static int mbusConfigEnter (void)
 Entering configuration mode. More...
 
static int mbusConfigExit (void)
 Exit configuration mode. More...
 
static int mbusConfigTransact (uint8 cmd, uint8 *data, int d_size, uint8 *reply, int r_size)
 Send a single configuration command with additional data and receive the reply. More...
 
static int mbusConfigCmd (uint8 cmd, uint8 *reply, int size)
 Send a single command/argument. More...
 
static int mbusConfigData (uint8 cmd)
 Send configuration data. More...
 
static int mbus_read_reg (int8 reg, int size, const char *name)
 Reads the value of one or more registers in the M-Bus module and prints the value to the device output as hexadecimal values. More...
 
static int mbus_read_regs (int8 reg, uint8 *buffer, int size)
 Reads the value of one or more registers in the M-Bus module and stores the value in the provided buffer. More...
 
static int mbus_config_mem_reg (uint8 reg, uint8 val)
 Change the value of a register in the M-Bus module. More...
 
static int mbus_config (int8 mode, int8 rssi, int8 only_installed)
 Configure a number of common settings. More...
 
static int mbus_receive (tdef_mbus_start_frame *start, int8 *data, int16 *rssi)
 Receive a new frame from the M-Bus module. More...
 
static void mbus_th_reader (void *arg)
 Thread function to recieve data and add to frame buffer list. More...
 
static int mbusConfigFactoryReset (void)
 This function performs a factory reset of the RF module. More...
 

Detailed Description

These functions are called from different C functions and contain common functionality.

Function Documentation

◆ mbus_address_compare()

static int8 mbus_address_compare ( tdef_mbus_slave_address a,
tdef_mbus_frame f 
)
static

Compare the address in a received frame to a given address.

Parameters
[in]aPointer to the given address in the compare
[in]fPointer to an address field in a frame
Returns
-1 Invalid slave address
0 No match
1 Matched found.

Definition at line 399 of file mod_mbus.c.

References mbus_frame::id, mbus_slave_address::id, mbus_frame::manufacture, mbus_slave_address::manufacturer, mbus_frame::type, mbus_slave_address::type, mbus_frame::version, and mbus_slave_address::version.

Referenced by flist_search_remove().

◆ mbus_config()

static int mbus_config ( int8  mode,
int8  rssi,
int8  only_installed 
)
static

Configure a number of common settings.

Parameters
[in]modeSet the M-Bus mode( see mbusOpen() for values). Set to -1 to not change it.
[in]rssiSet true to include RSSI in each packet. Set to -1 to not change it.
[in]only_installedSet true to only receive packets from installed/registered slaves. Set to -1 to not change it.
Returns
-1 communication error
0 success

Definition at line 864 of file mod_mbus.c.

References mbus_config_mem_reg(), mbus_read_reg(), mbusConfigEnter(), mbusConfigExit(), mbusDebug(), MUTEX_LOCK, MUTEX_UNLOCK, rssi_included, and rw_lock.

Referenced by mbusCallFilterEnable(), and mbusOpen().

◆ mbus_config_mem_reg()

static int mbus_config_mem_reg ( uint8  reg,
uint8  val 
)
static

Change the value of a register in the M-Bus module.

It check to make sure that it does not already have the value, to avoid unneeded writing to the flash.

Parameters
[in]regThe register to change
[in]valThe new value
Returns
-1 communication error
0 success, the register has the wanted value.

Definition at line 830 of file mod_mbus.c.

References mbusConfigCmd(), and mbusConfigData().

Referenced by mbus_config().

◆ mbus_read_reg()

static int mbus_read_reg ( int8  reg,
int  size,
const char *  name 
)
static

Reads the value of one or more registers in the M-Bus module and prints the value to the device output as hexadecimal values.

Parameters
[in]regThe index of the first register to read
[in]sizeThe number of sequential registers to read.
[in]nameThe name of the register to show in the output.
Returns
-1 communication error
0 success

Definition at line 774 of file mod_mbus.c.

References mbusConfigCmd(), and mbusDebug().

Referenced by mbus_config().

◆ mbus_read_regs()

static int mbus_read_regs ( int8  reg,
uint8 *  buffer,
int  size 
)
static

Reads the value of one or more registers in the M-Bus module and stores the value in the provided buffer.

Parameters
[in]regThe index of the first register to read
[in]bufferThe bufer to place the data in.
[in]sizeThe number of sequential registers to read.
Returns
-1 communication error
0 success

Definition at line 805 of file mod_mbus.c.

References mbusConfigCmd().

Referenced by mbus_info().

◆ mbus_receive()

static int mbus_receive ( tdef_mbus_start_frame start,
int8 *  data,
int16 *  rssi 
)
static

Receive a new frame from the M-Bus module.

Parameters
[in]startThe frame to store the information from the header in.
[in]dataBuffer to store the received data in.
[out]rssiIf not NULL and if the RSSI is included in the packet, this is set to the RSSI of the packet.
Returns
-1 communication error
0 no data
1 data received

Definition at line 944 of file mod_mbus.c.

References fd, mbus_start_frame::length, MBUS_DATA_LENGTH, MUTEX_LOCK, MUTEX_UNLOCK, rssi_included, and rw_lock.

Referenced by mbus_th_reader().

◆ mbus_th_reader()

static void mbus_th_reader ( void *  arg)
static

◆ mbusConfigCmd()

static int mbusConfigCmd ( uint8  cmd,
uint8 *  reply,
int  size 
)
static

Send a single command/argument.

Will send the supplied configuration command/argument, and return any expected reply.

The module must first have been set in configuration mode using mbusConfigEnter().

Parameters
[in]cmdThe command or value to send.
[in]replyReference to where reply is stored.
[in]sizeSize of expected reply, '0' of no reply is expected.
Returns
-1 communication error
0 success
1 missing confirm

Definition at line 723 of file mod_mbus.c.

References mbusConfigTransact().

Referenced by mbus_config_mem_reg(), mbus_info(), mbus_read_reg(), mbus_read_regs(), mbus_register_slave(), and mbusSend().

◆ mbusConfigData()

static int mbusConfigData ( uint8  cmd)
static

Send configuration data.

Sends the supplied data and does not expect confirmation.

The module must first have been set in configuration mode using mbusConfigEnter().

Parameters
[in]cmdThe command or value to send.
Returns
-1 communication error
0 success

Definition at line 741 of file mod_mbus.c.

References fd, and mbusDebug().

Referenced by mbus_config_mem_reg().

◆ mbusConfigEnter()

static int mbusConfigEnter ( void  )
static

Entering configuration mode.

Request entering configuration mode by sending '0x00', and wait for confirmation. Any data received but not read and data written but not transmitted will be flushed, to ensure synchronization.

To exit configuration mode mbusConfigExit() must be called.

Returns
-1 communication error
0 success
1 missing confirm

Definition at line 459 of file mod_mbus.c.

References cfg_activated, cfg_active, fd, and mbusDebug().

Referenced by mbus_config(), mbus_info(), mbus_register_slave(), mbusOpen(), and mbusSend().

◆ mbusConfigExit()

static int mbusConfigExit ( void  )
static

Exit configuration mode.

Request exit configuration mode by sending 'X', notice that the actual exit can't be confirmed, and success is always assumed.

To enter configuration mode, mbusConfigEnter() must be called.

Returns
-1 communication error
0 success

Definition at line 558 of file mod_mbus.c.

References cfg_activated, cfg_active, fd, and mbusDebug().

Referenced by mbus_config(), mbus_info(), mbus_register_slave(), mbusConfigFactoryReset(), mbusOpen(), and mbusSend().

◆ mbusConfigFactoryReset()

static int mbusConfigFactoryReset ( void  )
static

This function performs a factory reset of the RF module.

This includes erasing the serial number, so care should be taken when using it.

Returns
-1 communication error
0 success

Definition at line 1110 of file mod_mbus.c.

References cfg_activated, cfg_active, fd, mbusConfigExit(), mbusConfigTransact(), mbusDebug(), MUTEX_LOCK, MUTEX_UNLOCK, and rw_lock.

◆ mbusConfigTransact()

static int mbusConfigTransact ( uint8  cmd,
uint8 *  data,
int  d_size,
uint8 *  reply,
int  r_size 
)
static

Send a single configuration command with additional data and receive the reply.

Will send the supplied configuration command/argument and the additional data, and return any expected reply.

The module must first have been set in configuration mode using mbusConfigEnter().

Parameters
[in]cmdThe command or value to send.
[in]dataAdditional data to send.
[in]d_sizeThe length of the additional data to send
[in]replyReference to where reply is stored.
[in]r_sizeSize of expected reply, '0' of no reply is expected.
Returns
-1 communication error
0 success
1 missing confirm

Definition at line 617 of file mod_mbus.c.

References fd, and mbusDebug().

Referenced by mbus_register_slave(), mbusConfigCmd(), and mbusConfigFactoryReset().

◆ mbusDebug()

static void mbusDebug ( const char *  prefix,
const char *  format,
  ... 
)
static

Send mbus debug message to the device output in the format "<prefix>:<formated string>" This function is by default empty, but is active when compiling with DEBUG defined.

Parameters
[in]prefixprefix to message
[in]formatthe format and arguments
See also
sprintf

Definition at line 364 of file mod_mbus.c.

Referenced by flist_append(), flist_clear(), flist_remove_first_element(), flist_search_remove(), mbus_config(), mbus_info(), mbus_read_reg(), mbus_register_slave(), mbusCallClose(), mbusCallFilterEnable(), mbusCallFilterReceive(), mbusCallGetBufferLevel(), mbusCallInfo(), mbusCallOpen(), mbusCallReceive(), mbusCallRegisterSlave(), mbusCallSend(), mbusClose(), mbusConfigData(), mbusConfigEnter(), mbusConfigExit(), mbusConfigFactoryReset(), mbusConfigTransact(), mbusOpen(), mbusPower(), mbusSend(), moduleInit(), and moduleNotify().

◆ mbusPower()

static int mbusPower ( uint8  power)
static

Control power to module.

Power the module on or off.

Parameters
[in]powerIf 0 then off else on.
Returns
-1 Failed to set power.
0 Success.

Definition at line 424 of file mod_mbus.c.

References cfg_activated, and mbusDebug().

Referenced by mbusClose(), mbusOpen(), and moduleInit().

◆ mbusPrintInfo()

static void mbusPrintInfo ( const char *  prefix,
const char *  format,
  ... 
)
static

Send mbus info message to the device output in the format "<prefix>:<formated string>".

Parameters
[in]prefixprefix to message
[in]formatthe format and arguments
See also
sprintf

Definition at line 376 of file mod_mbus.c.

Referenced by mbus_info().