Z-Wave Protocol Controller Reference
zwapi_connection.c File Reference
#include <assert.h>
#include <string.h>
#include "zwapi_connection.h"
#include "zwapi_serial.h"
#include "zwapi_timestamp.h"
#include "sl_log.h"
Include dependency graph for zwapi_connection.c:

Macros

#define SOF   0x01 /* Start Of Frame */
 
#define ACK   0x06 /* Acknowledge successfull frame reception */
 
#define NAK    0x15 /* Not Acknowledge successfull frame reception - please retransmit... */
 
#define CAN   0x18 /* Frame received (from host) was dropped - waiting for ACK */
 
#define STATE_SOF_HUNT   0
 
#define STATE_PARSE_FRAME   1
 
#define LOG_TAG   "zwapi_connection"
 

Functions

static const char * zwapi_frame_to_string (const uint8_t *buffer, uint16_t buffer_length)
 
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...
 

Variables

static uint8_t rx_buffer [FRAME_LENGTH_MAX]
 
static uint8_t rx_buffer_length
 
static uint8_t zwapi_connection_state
 
static zwapi_timestamp_t timeOutACK
 
static zwapi_timestamp_t timeOutRX
 
static bool ack_nak_needed = false
 

Macro Definition Documentation

◆ ACK

#define ACK   0x06 /* Acknowledge successfull frame reception */

◆ CAN

#define CAN   0x18 /* Frame received (from host) was dropped - waiting for ACK */

◆ LOG_TAG

#define LOG_TAG   "zwapi_connection"

◆ NAK

#define NAK    0x15 /* Not Acknowledge successfull frame reception - please retransmit... */

◆ SOF

#define SOF   0x01 /* Start Of Frame */

◆ STATE_PARSE_FRAME

#define STATE_PARSE_FRAME   1

◆ STATE_SOF_HUNT

#define STATE_SOF_HUNT   0

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:

◆ zwapi_frame_to_string()

static const char * zwapi_frame_to_string ( const uint8_t *  buffer,
uint16_t  buffer_length 
)
static
Here is the caller graph for this function:

Variable Documentation

◆ ack_nak_needed

bool ack_nak_needed = false
static

◆ rx_buffer

uint8_t rx_buffer[FRAME_LENGTH_MAX]
static

◆ rx_buffer_length

uint8_t rx_buffer_length
static

◆ timeOutACK

zwapi_timestamp_t timeOutACK
static

◆ timeOutRX

zwapi_timestamp_t timeOutRX
static

◆ zwapi_connection_state

uint8_t zwapi_connection_state
static