Z-Wave Protocol Controller Reference
zwapi_connection.h File Reference

API to connect and send frames to the Z-Wave module using the serial port. More...

#include "zwapi_internal.h"
Include dependency graph for zwapi_connection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RX_ACK_TIMEOUT_DEFAULT   1500
 
#define RX_BYTE_TIMEOUT_DEFAULT   1500
 

Enumerations

enum  zwapi_connection_status_t {
  ZWAPI_CONNECTION_STATUS_IDLE , ZWAPI_CONNECTION_STATUS_FRAME_RECEIVED , ZWAPI_CONNECTION_STATUS_FRAME_SENT , ZWAPI_CONNECTION_STATUS_CHECKSUM_ERROR ,
  ZWAPI_CONNECTION_STATUS_RX_TIMEOUT , ZWAPI_CONNECTION_STATUS_TX_TIMEOUT , ZWAPI_CONNECTION_STATUS_TX_NAK , ZWAPI_CONNECTION_STATUS_TX_CAN
}
 State of the connection to the Z-Wave module. More...
 

Functions

int zwapi_connection_init (const char *serial_port)
 Initialize the zwapi_connection to the Z-Wave module. More...
 
void zwapi_connection_shutdown ()
 Close the zwapi_connection to the Z-Wave module. More...
 
int zwapi_connection_restart ()
 Closes and re-initializes the zwapi_connection to the Z-Wave module. More...
 
void zwapi_connection_tx (uint8_t cmd, uint8_t type, const uint8_t *Buf, uint8_t len, bool ack_needed)
 Transmit a frame via serial port by adding SOF, Len, Type, cmd and Checksum. More...
 
zwapi_connection_status_t zwapi_connection_refresh ()
 Parses serial data sent from the Z-Wave module to the serial port. Should be frequently called by main loop. More...
 
int zwapi_connection_get_last_rx_frame (uint8_t *user_buffer, int user_buffer_length)
 Provides the data of the serial buffer for the last received frame. More...
 
const char * zwapi_connection_status_to_string (zwapi_connection_status_t t)
 make the zwapi_connection_status types human readable. More...
 

Detailed Description

API to connect and send frames to the Z-Wave module using the serial port.

Macro Definition Documentation

◆ RX_ACK_TIMEOUT_DEFAULT

#define RX_ACK_TIMEOUT_DEFAULT   1500

◆ RX_BYTE_TIMEOUT_DEFAULT

#define RX_BYTE_TIMEOUT_DEFAULT   1500

Enumeration Type Documentation

◆ zwapi_connection_status_t

State of the connection to the Z-Wave module.

Enumerator
ZWAPI_CONNECTION_STATUS_IDLE 

Nothing has happened (no tx, no rx)

ZWAPI_CONNECTION_STATUS_FRAME_RECEIVED 

A valid frame has been received.

ZWAPI_CONNECTION_STATUS_FRAME_SENT 

A frame was sent successfully and ACKed by the other end.

ZWAPI_CONNECTION_STATUS_CHECKSUM_ERROR 

A frame has an incorrect Checksum.

ZWAPI_CONNECTION_STATUS_RX_TIMEOUT 

Rx timeout has happened.

ZWAPI_CONNECTION_STATUS_TX_TIMEOUT 

Tx timeout (waiting for ACK) has happened.

ZWAPI_CONNECTION_STATUS_TX_NAK 

A frame was sent and the other end issued a NAK.

ZWAPI_CONNECTION_STATUS_TX_CAN 

A frame was sent and the other end issued a CAN, i.e. a collision occurred.

Function Documentation

◆ zwapi_connection_get_last_rx_frame()

int zwapi_connection_get_last_rx_frame ( uint8_t *  user_buffer,
int  user_buffer_length 
)

Provides the data of the serial buffer for the last received frame.

Parameters
user_buffera pointer to the user buffer in which the frame is to be copied
user_buffer_lengthThe length of the user buffer
Returns
The length of the data copied in the user buffer.
Here is the caller graph for this function:

◆ zwapi_connection_init()

int zwapi_connection_init ( const char *  serial_port)

Initialize the zwapi_connection to the Z-Wave module.

Parameters
serial_portString representing the serial device path
Returns
integer file descriptor for the serial device. the value will be greater than 0 if successful.

aka ConInit

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zwapi_connection_refresh()

zwapi_connection_status_t zwapi_connection_refresh ( )

Parses serial data sent from the Z-Wave module to the serial port. Should be frequently called by main loop.

Returns
The current connection state. Refer to zwapi_connection_status_t values

aka ConUpdate

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zwapi_connection_restart()

int zwapi_connection_restart ( )

Closes and re-initializes the zwapi_connection to the Z-Wave module.

Returns
integer file descriptor for the serial device. the value will be greater than 0 if successful.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zwapi_connection_shutdown()

void zwapi_connection_shutdown ( )

Close the zwapi_connection to the Z-Wave module.

aka ConDestroy

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zwapi_connection_status_to_string()

const char * zwapi_connection_status_to_string ( zwapi_connection_status_t  t)

make the zwapi_connection_status types human readable.

Returns
A string representation of a zwapi_connection_status_t value

aka ConTypeToStr

Here is the caller graph for this function:

◆ zwapi_connection_tx()

void zwapi_connection_tx ( uint8_t  cmd,
uint8_t  type,
const uint8_t *  Buf,
uint8_t  len,
bool  ack_needed 
)

Transmit a frame via serial port by adding SOF, Len, Type, cmd and Checksum.

Parameters
cmdThe command to be executed by the Z-Wave module, using FUNC_ID defines
typeThe type of frame, either Request 0x00 or Response 0x01
BufA pointer to the command payload buffer
lenThe length of the data contained in the payload buffer
ack_neededtrue if we expect an Ack back for this frame.

A frame on the serial line consist of: SOF-Len-Type-Cmd-DATA-Chksum, where:

  • SOF is Start of frame byte
  • Len is length of bytes between and including Len to last DATA byte
  • Type is Response or Request
  • Cmd Serial application command describing what DATA is
  • DATA as it says
  • Chksum is a XOR checksum taken on all BYTEs from Len to last DATA byte

aka ConTxFrame

Here is the call graph for this function:
Here is the caller graph for this function: