Radiocraft Wireless M-Bus extension module  1.00.00
mod_mbus.c File Reference

Wireless M-Bus communication example module. More...

#include <module.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <pthread.h>

Go to the source code of this file.

Data Structures

struct  mbus_open
 FUNCTION mbusOpen
Defines the data structure of the VPL function mbusOpen. More...
 
struct  mbus_frame
 STRUCT_BLOCK mbusFrame
Defines the data structure of the VPL STRUCT_BLOCK mbusFrame. More...
 
struct  mbus_send
 FUNCTION mbusSend
Defines the data structure of the VPL function mbusSend. More...
 
struct  mbus_receive
 FUNCTION mbusReceive
Defines the data structure of the VPL function mbusReceive. More...
 
struct  mbus_reg_slave
 FUNCTION mbusRegisterSlave
Defines the data structure of the VPL function mbusRegisterSlave. More...
 
struct  mbus_set_filter
 FUNCTION mbusSetFilter
Defines the data structure of the VPL function mbusSetFilter. More...
 
struct  mbus_start_frame
 The first block of data when a new MBUS message is received. More...
 

Macros

#define MBUS_DATA_LENGTH   0xF6
 Maximum size of a MBUS message not including header information. More...
 

Typedefs

typedef struct mbus_open tdef_mbus_open
 Typedef for mbus_open. More...
 
typedef struct mbus_frame tdef_mbus_frame
 Typedef for mbus_frame. More...
 
typedef struct mbus_send tdef_mbus_send
 Typedef for mbus_send. More...
 
typedef struct mbus_receive tdef_mbus_receive
 Typedef for mbus_receive. More...
 
typedef struct mbus_reg_slave tdef_mbus_reg_slave
 Typedef for mbus_reg_slave. More...
 
typedef struct mbus_set_filter tdef_mbus_set_filter
 Typedef for mbus_set_filter. More...
 
typedef struct mbus_start_frame tdef_mbus_start_frame
 Typedef for mbus_start_frame. 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...
 
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 mbusReceive (tdef_mbus_start_frame *start, int8 *data, int16 *rssi)
 Receive a new frame from the M-Bus module. 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 int32 MODDECL mbusCallOpen (HANDLE *pCPU, void *pBase)
 Open communication interface to the module. More...
 
static int32 MODDECL mbusCallClose (HANDLE *pCPU, void *pBase)
 Close communication interface to the module. More...
 
static int32 MODDECL mbusCallReceive (HANDLE *pCPU, void *pBase)
 Check if any MBUS packets has been received. More...
 
static int32 MODDECL mbusCallSend (HANDLE *pCPU, void *pBase)
 Send a MBUS message. More...
 
static int32 MODDECL mbusCallInfo (HANDLE *pCPU, void *pBase)
 Perform a series of tests to validate communication. More...
 
static int32 MODDECL mbusCallSetFilter (HANDLE *pCPU, void *pBase)
 Set mode. More...
 
static int32 MODDECL mbusCallRegisterSlave (HANDLE *pCPU, void *pBase)
 Register a slave device. More...
 
int moduleInit (void)
 This function is called by the firmware when 'extModuleLoad' is called. More...
 
void moduleNotify (int event, int parm)
 This function is called by the firmware to notify the module about an event. More...
 

Variables

static int fd = -1
 serial port handle More...
 
static int cfg_active = 0
 Flag to monitor if we are in config mode. More...
 
static int cfg_activated = 0
 Flag to monitor if we have received the reply showing the we are in config mode. More...
 
static int rssi_included = 0
 Flag to keep track of whether the RSSI is included in each packet. More...
 
static pthread_mutex_t lock
 thread synchronization lock More...
 

Detailed Description

Wireless M-Bus communication example module.

This shows the framework necessary for communicating with the Radiocraft Wireless M-Bus RC1180-MBUS3 module.

Definition in file mod_mbus.c.

Macro Definition Documentation

◆ MBUS_DATA_LENGTH

#define MBUS_DATA_LENGTH   0xF6

Maximum size of a MBUS message not including header information.

Definition at line 28 of file mod_mbus.c.

Referenced by mbusCallSend(), and mbusReceive().

Typedef Documentation

◆ tdef_mbus_start_frame

Typedef for mbus_start_frame.

Definition at line 204 of file mod_mbus.c.

Variable Documentation

◆ cfg_activated

int cfg_activated = 0
static

Flag to monitor if we have received the reply showing the we are in config mode.

Definition at line 218 of file mod_mbus.c.

Referenced by mbusConfigEnter(), mbusConfigFactoryReset(), and mbusPower().

◆ cfg_active

int cfg_active = 0
static

Flag to monitor if we are in config mode.

Definition at line 216 of file mod_mbus.c.

Referenced by mbusConfigEnter(), mbusConfigExit(), and mbusConfigFactoryReset().

◆ fd

int fd = -1
static

◆ lock

pthread_mutex_t lock
static

◆ rssi_included

int rssi_included = 0
static

Flag to keep track of whether the RSSI is included in each packet.

Definition at line 220 of file mod_mbus.c.

Referenced by mbus_config(), and mbusReceive().