Radiocraft Wireless M-Bus extension module
2.18
|
Go to the documentation of this file.
21 #include <semaphore.h>
30 #define MBUS_DATA_LENGTH 0xF6
31 #define MAX_SLAVE_REGISTERS 64
33 #define MUTEX_LOCK(m) pthread_mutex_lock(&m)
34 #define MUTEX_UNLOCK(m) pthread_mutex_unlock(&m)
35 #define TH_SEM_RESET(s) while (sem_trywait(&s) == 0)
349 mbusDebug(
const char* prefix,
const char *format, ...)
355 strcpy(buffer, prefix);
357 va_start(valist, format);
358 vsprintf(&buffer[strlen(buffer)], format, valist);
364 mbusDebug(
const char* prefix __attribute__((unused)),
const char *format __attribute__((unused)), ...)
382 strcpy(buffer, prefix);
384 va_start(valist, format);
385 vsprintf(&buffer[strlen(buffer)], format, valist);
426 if (vplSetIOSignal(RF_OFF, !power) != 0)
428 mbusDebug(__func__,
"ERR (%d): Failed to set signal", __LINE__);
434 vplSetIOSignal(RF_CFG, 0);
437 vplSetIOSignal(RF_CFG, 1);
467 mbusDebug(__func__,
"ERR (%d): Already in config mode", __LINE__);
471 if (vplSetIOSignal(RF_CFG, 0) != 0)
473 mbusDebug(__func__,
"ERR (%d): Failed to set signal", __LINE__);
477 for (
int try = 0;
try < 3; ++
try)
480 if (tcflush(
fd, TCIOFLUSH))
482 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
489 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
493 if (vplSetIOSignal(RF_CFG, 1) != 0)
495 mbusDebug(__func__,
"ERR (%d): Failed to set signal", __LINE__);
501 rc = write(
fd, &cmd, 1);
504 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
509 mbusDebug(__func__,
"ERR (%d): failed to send exit command",
520 while (rc == 0 && tries < 3)
522 rc = read(
fd, &reply, 1);
525 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
531 if (vplSetIOSignal(RF_CFG, 0) != 0)
533 mbusDebug(__func__,
"ERR (%d): Failed to set signal", __LINE__);
536 if ((rc == 1) && reply ==
'>')
543 return (reply ==
'>') ? 0 : 1;
563 mbusDebug(__func__,
"ERR (%d): config not active", __LINE__);
568 int rc = write(
fd, &cmd, 1);
571 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
576 mbusDebug(__func__,
"ERR (%d): failed to send exit command", __LINE__);
584 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
588 if (tcflush(
fd, TCIOFLUSH))
590 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
621 rc = write(
fd, &cmd, 1);
624 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
629 mbusDebug(__func__,
"ERR (%d): failed to send 0x%02X", __LINE__, cmd);
633 if (data && d_size > 0)
635 rc = write(
fd, data, d_size);
638 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
643 mbusDebug(__func__,
"ERR (%d): failed to send 0x%02X", __LINE__, cmd);
651 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
658 int remaining = r_size;
659 for (
int try = 0;
try < 5;
try++)
661 int rc = read(
fd, &reply[r_size - remaining], remaining);
664 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
675 "ERR (%d): unexpected reply to 0x%02X (missing %d of %d)",
676 __LINE__, (cmd & 0xFF), remaining, r_size);
683 for (
int try = 0;
try < 5;
try++)
685 rc = read(
fd, &cfm, 1);
688 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
691 if ((rc == 1) && cfm ==
'>')
698 mbusDebug(__func__,
"ERR (%d): no reply to 0x%02X, 0x%x(%c)", __LINE__,
744 int rc = write(
fd, &cmd, 1);
747 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
752 mbusDebug(__func__,
"ERR (%d): failed to send 0x%02X", __LINE__, cmd);
759 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
782 memset(reply, 0x00, size);
783 for (
int i = 0; i < size; ++i)
789 sprintf(&buf[i * 3],
"%02X ", reply[i]);
792 mbusDebug(__func__,
"%s = '%s'", name, buf);
809 memset(buffer, 0x00, size);
810 for (
int i = 0; i < size; ++i)
869 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
904 if (only_installed >= 0)
947 int remaining =
sizeof(*start);
975 while (pos < remaining && tries < 3)
977 rlen = read(
fd, (&start->
length) + 1 + pos, remaining - pos);
988 if (pos != remaining)
990 tcflush(
fd, TCIFLUSH);
994 if (pos != remaining)
996 tcflush(
fd, TCIFLUSH);
1001 data_size = start->
length -
sizeof(*start) + 1;
1005 tcflush(
fd, TCIFLUSH);
1018 while (pos < data_size && tries < 3)
1020 rlen = read(
fd, &data[pos], data_size - pos);
1030 if (pos != data_size)
1032 tcflush(
fd, TCIFLUSH);
1041 rlen = read(
fd, &buf, 1);
1055 start->
length = (uint8) data_size;
1084 linsec = vplClockGet();
1109 static int __attribute__( (unused))
1118 mbusDebug(__func__,
"ERR (%d): Already in config mode", __LINE__);
1124 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
1127 if (vplSetIOSignal(RF_CFG, 0) != 0)
1129 mbusDebug(__func__,
"ERR (%d): Failed to set signal", __LINE__);
1132 for (
int try = 0;
try < 3; ++
try)
1135 if (tcflush(
fd, TCIOFLUSH))
1138 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1146 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1150 if (vplSetIOSignal(RF_CFG, 1) != 0)
1152 mbusDebug(__func__,
"ERR (%d): Failed to set signal", __LINE__);
1158 rc = write(
fd, &cmd, 1);
1162 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1168 mbusDebug(__func__,
"ERR (%d): failed to send exit command",
1180 while (rc == 0 && tries < 3)
1182 rc = read(
fd, &reply, 1);
1186 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1193 if ((rc == 1) && reply ==
'>')
1200 if (vplSetIOSignal(RF_CFG, 0) != 0)
1202 mbusDebug(__func__,
"ERR (%d): Failed to set signal", __LINE__);
1212 if (vplSetIOSignal(RF_CFG, 0) != 0)
1214 mbusDebug(__func__,
"ERR (%d): Failed to set signal", __LINE__);
1251 mbusDebug(__func__,
"ERR (%d): list corruption! Counter was %d", __LINE__, fl->
counter);
1282 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
1290 if (address->
type == 0xff)
1361 mbusDebug(__func__,
"ERR (%d): list corruption! Element next pointer should be NULL. Counter was %d", __LINE__, fl->
counter);
1413 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
1462 if (clock_gettime(CLOCK_REALTIME, &ts) == -1)
return -1;
1464 ts.tv_sec += timeout/1000;
1465 ts.tv_nsec +=(timeout%1000)*1000000;
1481 rc2 = sem_timedwait(&
read_sem, &ts);
1486 }
while ( !e && errno != ETIMEDOUT && timeout && rc2 >= 0 );
1490 rframe->
control = (int8) e->frame.control;
1491 write16b(&rframe->
manufacture, e->frame.manufacture);
1492 write32b(&rframe->
id, e->frame.id);
1493 rframe->
version = (int8) e->frame.version;
1494 rframe->
type = e->frame.type;
1495 write16b(&rframe->
rssi, e->frame.rssi);
1496 write32b(&rframe->
linsec, e->frame.linsec);
1497 write16b(&rframe->
length, e->frame.length);
1498 memcpy(&rframe->
data, e->frame.data, e->frame.length);
1516 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
1522 tcflush(
fd, TCIOFLUSH);
1528 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1560 char port_path[200];
1565 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
1570 mbusDebug(__func__,
"ERR: Communication interface already opened:");
1574 if (vplFsMapFile(port_path, 200,
"dev:ser3"))
1577 mbusDebug(__func__,
"ERR: Failed to open port:");
1581 fd = open(port_path, O_RDWR | O_NOCTTY | O_SYNC);
1585 mbusDebug(__func__,
"ERR: Failed to open '%s': %s", port_path,
1590 memset(&tty, 0,
sizeof tty);
1591 if (tcgetattr(
fd, &tty) != 0)
1594 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1599 cfsetospeed(&tty, B19200);
1600 cfsetispeed(&tty, B19200);
1602 tty.c_cflag |= (CLOCAL | CREAD);
1603 tty.c_cflag &= ~CSIZE;
1605 tty.c_cflag &= ~PARENB;
1606 tty.c_cflag &= ~CSTOPB;
1607 tty.c_cflag &= ~CRTSCTS;
1610 tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL
1612 tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
1613 tty.c_oflag &= ~OPOST;
1616 tty.c_cc[VMIN] = (cc_t) 0;
1617 tty.c_cc[VTIME] = (cc_t) 10;
1619 if (tcsetattr(
fd, TCSANOW, &tty) != 0)
1621 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1631 for (i = 0; i < 5; ++i)
1643 mbusDebug(__func__,
"ERR (%d): failed to reset module", __LINE__);
1675 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
1710 send = write(
fd, &cmd, 1);
1714 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1720 mbusDebug(__func__,
"(%d): Failed to write send request", __LINE__);
1727 send = write(
fd, &size, 1);
1731 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1737 mbusDebug(__func__,
"(%d): Failed to write data length", __LINE__);
1740 send = write(
fd, data, size);
1744 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
1750 mbusDebug(__func__,
"(%d): Failed to write data (%d of %d)", __LINE__,
1786 memcpy(&addr[0], &
id, 4);
1787 memcpy(&addr[4], &manufacturer, 2);
1788 memcpy(&addr[6], &version, 1);
1789 memcpy(&addr[7], &type, 1);
1796 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
1858 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
1892 mbusPrintInfo(__func__,
"Temperature = %d C", (reply[0] - 128));
1921 mbusPrintInfo(__func__,
"DATA_INTERFACE = 0x%02X", reply[0]);
1956 for (i = 0; i < 8; i++)
1958 sprintf(&serial[i * 3],
"%02X ", reply[i]);
1960 serial[8 * 3 - 1] = 0;
2002 if ( !(buf_size > 0 && buf_size <= 1000) )
2067 static int32 MODDECL
2074 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
2080 if (rc == 0 && rc2 == -2)
return -2;
2094 static int32 MODDECL
2096 void* pBase __attribute__((unused)))
2100 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
2106 if (rc == 0)
return rc2? -2 : 0;
2107 return rc2? -3 : -1;
2122 static int32 MODDECL
2131 idx = pdata->
idx - 1;
2136 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
2159 static int32 MODDECL
2168 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
2172 write32b(&address.
id, pdata->
id);
2189 static int32 MODDECL
2196 mbusDebug(__func__,
"ERR (%d): missing data", __LINE__);
2202 mbusDebug(__func__,
"ERR (%d): illegal data length %d", __LINE__,
2209 mbusDebug(__func__,
"ERR (%d): illegal control value %d", __LINE__,
2215 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
2220 if (rc && (pdata->
control >= 0) )
2222 mbusDebug(__func__,
"error (%d) - resetting interface", rc);
2273 static int32 MODDECL
2275 void* pBase __attribute__((unused)))
2279 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
2286 mbusDebug(__func__,
"error (%d) - resetting interface", rc);
2301 static int32 MODDECL
2308 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
2315 mbusDebug(__func__,
"error (%d) - resetting interface", rc);
2330 static int32 MODDECL
2337 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
2346 mbusDebug(__func__,
"error (%d) - resetting interface", rc);
2364 static int32 MODDECL
2366 void* pBase __attribute__( (unused)))
2370 mbusDebug(__func__,
"ERR (%d): failed to get lock", __LINE__);
2399 pthread_mutexattr_t lock_attr;
2400 pthread_mutexattr_t list_lock_attr;
2401 pthread_mutexattr_t rw_lock_attr;
2403 vplFunctionEntry ftable[] =
2420 rc = pthread_mutexattr_init(&lock_attr);
2423 mbusDebug(__func__,
"ERR (%d): %d", __LINE__, rc);
2426 rc = pthread_mutexattr_settype(&lock_attr, PTHREAD_MUTEX_RECURSIVE);
2429 mbusDebug(__func__,
"ERR (%d): %d", __LINE__, rc);
2432 rc = pthread_mutex_init(&
lock, &lock_attr);
2435 mbusDebug(__func__,
"ERR (%d): %d", __LINE__, rc);
2439 rc = pthread_mutexattr_init(&list_lock_attr);
2442 mbusDebug(__func__,
"ERR (%d): %d", __LINE__, rc);
2445 rc = pthread_mutexattr_settype(&list_lock_attr, PTHREAD_MUTEX_RECURSIVE);
2448 mbusDebug(__func__,
"ERR (%d): %d", __LINE__, rc);
2451 rc = pthread_mutex_init(&
lock, &list_lock_attr);
2454 mbusDebug(__func__,
"ERR (%d): %d", __LINE__, rc);
2458 rc = pthread_mutexattr_init(&rw_lock_attr);
2461 mbusDebug(__func__,
"ERR (%d): %d", __LINE__, rc);
2464 rc = pthread_mutexattr_settype(&rw_lock_attr, PTHREAD_MUTEX_RECURSIVE);
2467 mbusDebug(__func__,
"ERR (%d): %d", __LINE__, rc);
2470 rc = pthread_mutex_init(&
lock, &rw_lock_attr);
2473 mbusDebug(__func__,
"ERR (%d): %d", __LINE__, rc);
2478 rc = vplInstallFunctions(
"mod_mbus", ftable);
2482 mbusDebug(__func__,
"failed to install 'mod_mbus' functions err %d", rc);
2486 if (vplSetIOSignal(RF_CFG, 0) != 0)
2488 mbusDebug(__func__,
"ERR (%d): %s", __LINE__, strerror(errno));
2528 case EVENT_SHUTDOWN:
2533 case EVENT_POWERFAIL:
2544 case EVENT_POWERSAVE:
2556 mbusDebug(__func__,
"Unknown event %d", event);
static tdef_mbus_frame_list_elem * flist_remove_first_element(void)
Take out the oldest element in the buffer list and return a pointer to it.
int16 manufacturer
M-Field : Manufacture ID, e.g. 0x0646 (ARF)
static int flist_clear(void)
Clear the internal buffer list.
int16 manufacturer
Manufacturer ID. Part of the address of the slave.
static int mbusGetBufferLevel(void)
Get the actual level of how full the buffer is in promille.
tdef_mbus_frame frame
Received frame.
static int mbusSend(int16 c, int8 *data, int8 size)
Send an M-BUS packet.
static tdef_mbus_frame_list_elem * flist_search_remove(tdef_mbus_slave_address *address)
Search for and remove element from the buffer list, based on a given slave address,...
FUNCTION mbusReceive Defines the data structure of the VPL function mbusReceive.
int16 length
The length of the additional data in the frame.
static pthread_mutex_t lock
thread synchronization lock
static int mbusClose(void)
Closes the communication interface.
static int cfg_activated
Flag to monitor if we have received the reply showing the we are in config mode.
static int32 MODDECL mbusCallGetBufferLevel(HANDLE *pCPU, void *pBase)
Get the actual level of how full the buffer is in promille.
static int32 MODDECL mbusCallRegisterSlave(HANDLE *pCPU, void *pBase)
Register a slave device.
static int32 MODDECL mbusCallInfo(HANDLE *pCPU, void *pBase)
Perform a series of tests to validate communication.
int16 error
error value from call, set by VPL
FUNCTION mbusSetFilter Defines the data structure of the VPL function mbusSetFilter.
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.
int8 rssi
Set to true to include the signal strength (RSSI) for each valid packet.
uint16 frames_max
Maximum amount of elements the list will accept.
static int mbusBufferReceive(tdef_mbus_frame *rframe, tdef_mbus_slave_address *address, int32 timeout)
Get element from buffer with timeout.
static int run_thread
thread running state
STRUCT_BLOCK mbusFrame Defines the data structure of the VPL STRUCT_BLOCK mbusFrame.
int16 error
error value from call, set by VPL
uint16 discarded
Counter that tells how many entries were discarded, also in the case of overwriting.
struct mbus_frame_list_elem * next
Pointer to the later received frames.
int moduleInit(void)
This function is called by the firmware when 'extModuleLoad' is called.
static pthread_mutex_t list_lock
list synchronization lock
uint8 version
Version number. Part of the address of the slave.
static int mbus_config_mem_reg(uint8 reg, uint8 val)
Change the value of a register in the M-Bus module.
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 outpu...
uint32 linsec
Timestamp. Time of receiving frame in linsec. See clockGet VPL function block.
int8 only_installed
Set to true to only receive packets from installed slaves.
uint8 version
A-Field[5]:Device version part of address field.
static int cfg_active
Flag to monitor if we are in config mode.
int16 rssi
The signal strength (RSSI), if enabled in mbusOpen().
int8 overwrite
Boolean value to decide on policy when buffer is full. On True we overwrite by removing oldest frame ...
void moduleNotify(int event, int parm)
This function is called by the firmware to notify the module about an event.
static int rssi_included
Flag to keep track of whether the RSSI is included in each packet.
uint8 type
Device Type. Part of the address of the slave.
FUNCTION mbusRegisterSlave Defines the data structure of the VPL function mbusRegisterSlave.
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 buf...
int16 error
error value from call, set by VPL
#define MAX_SLAVE_REGISTERS
uint8 version
Version number. Part of the address of the slave.
uint8 type
Device Type. Part of the device address.
static int mbus_config(int8 mode, int8 rssi, int8 only_installed)
Configure a number of common settings.
int16 manufacturer
Manufacturer ID. Part of the address of the slave.
static int fd
serial port handle
The first block of data when a new MBUS message is received.
static int mbusStopReader(void)
Stop the receive thread and clean up.
static int mbusStartReader(uint16 buf_size, int8 overwrite)
Start the receive thread.
int16 idx
id of filter to receive from.
static tdef_mbus_slave_address mbus_slave_register[MAX_SLAVE_REGISTERS]
The stored addresses of registered slaves.
tdef_mbus_frame_list_elem * flist_tail
Pointer to the tail of the list, where the oldest frames are kept.
int16 retval
return value from call, set by VPL
FUNCTION mbusFilterReceive Defines the data structure of the VPL function mbusFilterReceive.
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.
uint8 type
Device Type. Part of the address of the slave.
int16 manufacture
Manufacture ID. Part of the device address.
tdef_mbus_frame * frame
The provided struct is filled with the values of a received M-Bus frame.
static tdef_mbus_frame_list mbus_flist
The frame list buffer.
int8 data[MBUS_DATA_LENGTH]
The additional data received from the M-Bus module. Only the first [length] bytes are valid.
int16 retval
return value from call, set by VPL
uint16 counter
Counter that tells how many elements has been inserted in the buffer list.
static int32 MODDECL mbusCallFilterEnable(HANDLE *pCPU, void *pBase)
Set mode.
uint8 type
Device Type. Part of the address of the slave.
static int mbusOpen(int8 mode, int8 rssi)
Opens the connection to the M-Bus module.
int16 manufacturer
Manufacturer ID. Part of the address of the slave.
static int32 MODDECL mbusCallFilterReceive(HANDLE *pCPU, void *pBase)
Check if any MBUS packets has been received for a given filter.
FUNCTION mbusSend Defines the data structure of the VPL function mbusSend.
int16 retval
return value from call, set by VPL
static int32 MODDECL mbusCallSend(HANDLE *pCPU, void *pBase)
Send a MBUS message.
FUNCTION mbusOpen Defines the data structure of the VPL function mbusOpen.
static int mbusConfigCmd(uint8 cmd, uint8 *reply, int size)
Send a single command/argument.
uint8 control
C-field : Control byte used to identify packet type.
struct mbus_frame_list_elem * prev
Pointer to the previous received frames.
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...
int16 error
error value from call, set by VPL
int16 retval
return value from call, set by VPL
int16 control
Value of the control field to use when sending.
uint8 version
Version number. Part of the address of the slave.
uint32 id
Identification number/serial number. Part of the address of the slave.
static int mbusConfigExit(void)
Exit configuration mode.
static int32 MODDECL mbusCallReceive(HANDLE *pCPU, void *pBase)
Check if any MBUS packets has been received.
static void mbus_th_reader(void *arg)
Thread function to recieve data and add to frame buffer list.
uint32 id
Identification number/serial number. Part of the address of the slave.
static int mbusConfigFactoryReset(void)
This function performs a factory reset of the RF module.
int16 retval
return value from call, set by VPL
int16 error
error value from call, set by VPL
uint8 length
L-field : Length of full frame not including length or any start/stop bytes.
The doubly-connected frame buffer list keeping received frames.
int16 length
Length of the data to send.
static pthread_t reader
thread configuration
static int32 MODDECL mbusCallClose(HANDLE *pCPU, void *pBase)
Close communication interface to the module.
static int mbusPower(uint8 power)
Control power to module.
static pthread_mutex_t rw_lock
device read/write lock
int16 idx
The index of the slave to register. 1-64.
int16 retval
return value from call, set by VPL
int8 mode
The M-Bus mode to use.
int8 control
Control field.
static sem_t read_sem
semaphore to await data with timeout
static int32 MODDECL mbusCallOpen(HANDLE *pCPU, void *pBase)
Open communication interface to the module.
static int mbus_receive(tdef_mbus_start_frame *start, int8 *data, int16 *rssi)
Receive a new frame from the M-Bus module.
static int mbusConfigEnter(void)
Entering configuration mode.
static int mbusConfigData(uint8 cmd)
Send configuration data.
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.
The buffer list structure, specifying overwrite policy, buffer size and counters.
uint8 type
A-Field[6]:Device type part of address field.
int32 timeout
Time to wait for data if buffer is empty in milliseconds. If timeout is -1, wait until data is receiv...
uint8 * key
Encryption key, 16 bytes. Can be set to NULL when encryption is not used.
uint32 id
A-Field[4]:ID/Serial number part of address field.
#define MBUS_DATA_LENGTH
Maximum size of a MBUS message not including header information.
uint32 id
Identification number/serial number. Part of the device address.
int8 overwrite
If 1 (true), use overwrite policy, if 0 (false), discard newly received frame.
int16 error
error value from call, set by VPL
tdef_mbus_frame * frame
The provided struct is filled with the values of a received M-Bus frame.
static void mbusPrintInfo(const char *prefix, const char *format,...)
Send mbus info message to the device output in the format "<prefix>:<formated string>".
int16 max_frames
Amount of elements the buffer will accept. Maximum value 1000.
tdef_mbus_frame_list_elem * flist_head
Pointer to the head of the list, where the latest frames received are kept.
static void flist_append(tdef_mbus_frame_list_elem *e)
Add element containing received frame data to list.
uint32 id
Identification number/serial number. Part of the address of the slave.
static int mbus_info(void)
Print some information about the RF module to the device output.
uint8 version
Version number. Part of the device address.