Radiocraft Wireless M-Bus extension module  1.00.00
Helper C functions

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

Functions

static void mbusDebug (const char *prefix, const char *format,...)
 Send a debug message to the device output in the format "<prefix>:<formated string>". 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 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_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 712 of file mod_mbus.c.

References mbus_config_mem_reg(), mbus_read_reg(), mbusConfigEnter(), mbusConfigExit(), and rssi_included.

Referenced by mbusCallSetFilter(), 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 678 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 622 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 653 of file mod_mbus.c.

References mbusConfigCmd().

Referenced by mbus_info().

◆ 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 571 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 589 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 304 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 408 of file mod_mbus.c.

References 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 764 of file mod_mbus.c.

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

◆ 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 467 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 a debug 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 244 of file mod_mbus.c.

Referenced by mbus_info(), mbus_read_reg(), mbusCallClose(), mbusCallInfo(), mbusCallOpen(), mbusCallReceive(), mbusCallRegisterSlave(), mbusCallSend(), mbusCallSetFilter(), mbusClose(), mbusConfigData(), mbusConfigEnter(), mbusConfigExit(), mbusConfigFactoryReset(), mbusConfigTransact(), mbusOpen(), mbusPower(), mbusReceive(), 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 269 of file mod_mbus.c.

References cfg_activated, and mbusDebug().

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