Radiocraft Wireless M-Bus extension module  2.18
Implementation C functions

These functions are called directly from the Modcall C functions. More...

Functions

static int mbusBufferReceive (tdef_mbus_frame *rframe, tdef_mbus_slave_address *address, int32 timeout)
 Get element from buffer with timeout. More...
 
static int mbusClose (void)
 Closes the communication interface. More...
 
static int mbusOpen (int8 mode, int8 rssi)
 Opens the connection to the M-Bus module. More...
 
static int mbusSend (int16 c, int8 *data, int8 size)
 Send an M-BUS packet. More...
 
static int mbus_register_slave (int idx, int16 manufacturer, int32 id, int8 version, int8 type, uint8 *key)
 Registers/installs a slave device on the M-Bus module. More...
 
static int mbus_info (void)
 Print some information about the RF module to the device output. More...
 
static int mbusStartReader (uint16 buf_size, int8 overwrite)
 Start the receive thread. More...
 
static int mbusStopReader (void)
 Stop the receive thread and clean up. More...
 
static int mbusGetBufferLevel (void)
 Get the actual level of how full the buffer is in promille. More...
 

Detailed Description

These functions are called directly from the Modcall C functions.

Function Documentation

◆ mbus_info()

static int mbus_info ( void  )
static

Print some information about the RF module to the device output.

Returns
-1 Communication error.
0 Success.

Definition at line 1850 of file mod_mbus.c.

References mbus_read_regs(), mbusConfigCmd(), mbusConfigEnter(), mbusConfigExit(), mbusDebug(), mbusPrintInfo(), MUTEX_LOCK, MUTEX_UNLOCK, and rw_lock.

Referenced by mbusCallInfo().

◆ mbus_register_slave()

static int mbus_register_slave ( int  idx,
int16  manufacturer,
int32  id,
int8  version,
int8  type,
uint8 *  key 
)
static

Registers/installs a slave device on the M-Bus module.

This is necessary when filtering or when using encryption.

Parameters
[in]idxThe index of the slave to register. 0-63.
[in]manufacturerThe ID of the manufacturer. Part of the device address.
[in]idThe device identification number/serial number. Part of the device address.
[in]versionThe device version. Part of the device address.
[in]typeThe device type. Part of the device address.
[in]keyThe 16 byte (128 bit) encryption key. Can be set to NULL if encryption is not used.
Returns
-2 Invalid idx
-1 communication error
0 Slave was registered

Definition at line 1775 of file mod_mbus.c.

References MAX_SLAVE_REGISTERS, mbus_slave_register, mbusConfigCmd(), mbusConfigEnter(), mbusConfigExit(), mbusConfigTransact(), mbusDebug(), MUTEX_LOCK, MUTEX_UNLOCK, and rw_lock.

Referenced by mbusCallRegisterSlave().

◆ mbusBufferReceive()

static int mbusBufferReceive ( tdef_mbus_frame rframe,
tdef_mbus_slave_address address,
int32  timeout 
)
static

Get element from buffer with timeout.

Parameters
[in]rframePointer to frame structure to return data to.
[in]addressM-Bus slave address to lookup data for.
[in]timeoutTimeout in milliseconds. If timeout is -1, wait until data is received.
Returns
1 data ready
0 no data available
-1 failed to access system interface
-2 interface is not open

Definition at line 1454 of file mod_mbus.c.

References mbus_frame::control, mbus_frame::data, flist_search_remove(), mbus_frame::id, mbus_frame::length, mbus_frame::linsec, lock, mbus_frame::manufacture, MUTEX_LOCK, MUTEX_UNLOCK, read_sem, mbus_frame::rssi, run_thread, TH_SEM_RESET, mbus_frame::type, and mbus_frame::version.

Referenced by mbusCallFilterReceive(), and mbusCallReceive().

◆ mbusClose()

static int mbusClose ( void  )
static

Closes the communication interface.

Returns
0 success
-1 failed to close interface

Definition at line 1512 of file mod_mbus.c.

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

Referenced by mbusCallClose(), mbusCallFilterEnable(), mbusCallInfo(), mbusCallRegisterSlave(), mbusCallSend(), and moduleNotify().

◆ mbusGetBufferLevel()

static int mbusGetBufferLevel ( void  )
static

Get the actual level of how full the buffer is in promille.

Returns
buffer level in promille [0..1000]

Definition at line 2043 of file mod_mbus.c.

References mbus_frame_list::counter, mbus_frame_list::frames_max, and mbus_flist.

Referenced by mbusCallGetBufferLevel().

◆ mbusOpen()

static int mbusOpen ( int8  mode,
int8  rssi 
)
static

Opens the connection to the M-Bus module.

This must be called before the rest of the functions will work.

Parameters
[in]modeThe M-Bus mode to use.
  • 0 = S2
  • 1 = T1 (default)
  • 2 = T2
  • 3 = S1
  • 4 = R
  • 10 = T1+C
  • 11 = T2+C
[in]rssiSet to true to include the signal strength (RSSI) for each valid packet. It can be read from mbusReceive() and is available in the mbusFrame struct block (mbus_frame).
Returns
0 success
-1 failed to open interface

Definition at line 1558 of file mod_mbus.c.

References fd, mbus_config(), mbusConfigEnter(), mbusConfigExit(), mbusDebug(), mbusPower(), MUTEX_LOCK, MUTEX_UNLOCK, and rw_lock.

Referenced by mbusCallFilterEnable(), mbusCallInfo(), mbusCallOpen(), mbusCallRegisterSlave(), and mbusCallSend().

◆ mbusSend()

static int mbusSend ( int16  c,
int8 *  data,
int8  size 
)
static

Send an M-BUS packet.

This will send a M-BUS message, if c is not -1 then the control field will be changed before sending. If no length is supplied then only the header frame will be send.

Parameters
[in]cNew value for the Control field if not -1.
[in]dataData to send, may be null if only header is to be send.
[in]sizeSize of data to send, if 0 the only header will be send
Returns
-1 communication error
0 success

Definition at line 1670 of file mod_mbus.c.

References fd, mbusConfigCmd(), mbusConfigEnter(), mbusConfigExit(), mbusDebug(), MUTEX_LOCK, MUTEX_UNLOCK, and rw_lock.

Referenced by mbusCallSend().

◆ mbusStartReader()

static int mbusStartReader ( uint16  buf_size,
int8  overwrite 
)
static

Start the receive thread.

Parameters
[in]buf_sizeAmount of elements the buffer will accept
[in]overwriteIf 1 (true), use overwrite policy, if 0 (false), discard newly received frame.
Returns
0 Thread started successfully
-1 Failed to start thread
-1 Invalid input

Definition at line 1997 of file mod_mbus.c.

References mbus_frame_list::counter, mbus_frame_list::discarded, mbus_frame_list::flist_head, mbus_frame_list::flist_tail, mbus_frame_list::frames_max, mbus_flist, mbus_th_reader(), mbus_frame_list::overwrite, read_sem, reader, and run_thread.

Referenced by mbusCallOpen().

◆ mbusStopReader()

static int mbusStopReader ( void  )
static

Stop the receive thread and clean up.

Returns
0 Success.
!=0 Clean-up error, the list was erroneous

Definition at line 2026 of file mod_mbus.c.

References flist_clear(), read_sem, and run_thread.

Referenced by mbusCallClose(), and moduleNotify().