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

Classes

struct  list_elem
 

Macros

#define LOG_TAG   "zwapi_session"
 
#define TIMEOUT_TIME   1600
 
#define MAX_RX_QUEUE_LENGTH   30
 
#define MAX_TRANSMISSION_RETRIES   20
 
#define MAX_RX_FRAMES_WAITING_FOR_RESPONSE   3
 
#define MAX_TX_TIMEOUTS   3
 

Typedefs

typedef struct list_elem zwapi_session_list_elem_t
 

Functions

static int zwapi_session_get_rx_queue_length (void)
 
static void zwapi_session_enqueue_frame (void)
 
static zwapi_connection_status_t zwapi_session_wait_for_response (void)
 
int zwapi_session_init (const char *serial_port)
 Initialize a zwapi_session with the Z-Wave module. More...
 
void zwapi_session_shutdown ()
 Close the zwapi_session with the Z-Wave module. More...
 
int zwapi_session_restart ()
 Closes and re-initializes the zwapi_session to the Z-Wave module. More...
 
bool zwapi_session_dequeue_frame (uint8_t **frame_ptr, uint8_t *frame_len)
 Get the next frame from the zwapi_session receive queue. More...
 
void zwapi_session_enqueue_rx_frames ()
 Loads the received frames from the serial device into the zwapi_session receive queue. More...
 
sl_status_t zwapi_session_send_frame (uint8_t command, const uint8_t *payload_buffer, uint8_t payload_buffer_length)
 Send data frame to Z-Wave chip via serial port and wait for ACK. More...
 
sl_status_t zwapi_session_send_frame_with_response (uint8_t command, const uint8_t *payload_buffer, uint8_t payload_buffer_length, uint8_t *response_buf, uint8_t *response_len)
 Send data frame to Z-Wave chip via serial API, wait for ACK and a RES frame. More...
 
sl_status_t zwapi_session_send_frame_no_ack (uint8_t command, const uint8_t *payload_buffer, uint8_t payload_buffer_length)
 Send data frame to Z-Wave chip via serial API without waiting for ACK. More...
 
void zwapi_session_flush_queue (void)
 Flush the zwapi_session receive queue. More...
 

Variables

static zwapi_session_list_elem_tzwapi_session_rx_queue
 

Macro Definition Documentation

◆ LOG_TAG

#define LOG_TAG   "zwapi_session"

◆ MAX_RX_FRAMES_WAITING_FOR_RESPONSE

#define MAX_RX_FRAMES_WAITING_FOR_RESPONSE   3

◆ MAX_RX_QUEUE_LENGTH

#define MAX_RX_QUEUE_LENGTH   30

◆ MAX_TRANSMISSION_RETRIES

#define MAX_TRANSMISSION_RETRIES   20

◆ MAX_TX_TIMEOUTS

#define MAX_TX_TIMEOUTS   3

◆ TIMEOUT_TIME

#define TIMEOUT_TIME   1600

Typedef Documentation

◆ zwapi_session_list_elem_t

Function Documentation

◆ zwapi_session_dequeue_frame()

bool zwapi_session_dequeue_frame ( uint8_t **  frame_ptr,
uint8_t *  frame_len 
)

Get the next frame from the zwapi_session receive queue.

Parameters
frame_ptrPointer to frame data. This is set to NULL if no frame was available Must be deallocated with free() after use.
frame_lenlength of frame. This is set to 0 if no frame was available
Returns
true the receive queue still contains more frames
false the receive queue is now empty.

aka DequeueFrame

Here is the caller graph for this function:

◆ zwapi_session_enqueue_frame()

static void zwapi_session_enqueue_frame ( void  )
static

Enqueue a new element in the zwapi_session_rx_queue from the zwapi_connection buffer. Only REQUEST type frames will be enqueued, others will be ignored TODO: Get rid of malloc

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

◆ zwapi_session_enqueue_rx_frames()

void zwapi_session_enqueue_rx_frames ( void  )

Loads the received frames from the serial device into the zwapi_session receive queue.

aka DrainRX

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

◆ zwapi_session_flush_queue()

void zwapi_session_flush_queue ( void  )

Flush the zwapi_session receive queue.

aka SerialFlushQueue

Here is the caller graph for this function:

◆ zwapi_session_get_rx_queue_length()

static int zwapi_session_get_rx_queue_length ( void  )
static

Give the number of outstanding packets in zwapi_session_rx_queue

Here is the caller graph for this function:

◆ zwapi_session_init()

int zwapi_session_init ( const char *  serial_port)

Initialize a zwapi_session with 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zwapi_session_restart()

int zwapi_session_restart ( )

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

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

If no access to hard reset is available, it is recommended to issue a FUNC_ID_SERIAL_API_SOFT_RESET command to the Z-Wave module after restarting a session, and subsequently wait 1500ms before resuming operations.

Here is the call graph for this function:

◆ zwapi_session_send_frame()

sl_status_t zwapi_session_send_frame ( uint8_t  command,
const uint8_t *  payload_buffer,
uint8_t  payload_buffer_length 
)

Send data frame to Z-Wave chip via serial port and wait for ACK.

Parameters
commandZ-Wave Serial API Command (zwapi_func_ids.h)
payload_bufferByte array with serial API command parameters
payload_buffer_lengthLength in bytes of parameter array It may take up to RX_ACK_TIMEOUT_DEFAULT ms to receive a ACK from the Z-Wave module
Returns
SL_STATUS_OK if the frame sent and Ack'ed by the module. SL_STATUS_FAIL otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zwapi_session_send_frame_no_ack()

sl_status_t zwapi_session_send_frame_no_ack ( uint8_t  command,
const uint8_t *  payload_buffer,
uint8_t  payload_buffer_length 
)

Send data frame to Z-Wave chip via serial API without waiting for ACK.

Parameters
commandZ-Wave Serial API Command (zwapi_func_ids.h)
payload_bufferByte array with serial API command parameters
payload_buffer_lengthLength in bytes of parameter array
Returns
SL_STATUS_OK if the frame has been sent.

Does not wait for any ACK. Can be used e.g. if the Z-Wave module is expected to restart

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

◆ zwapi_session_send_frame_with_response()

sl_status_t zwapi_session_send_frame_with_response ( uint8_t  command,
const uint8_t *  payload_buffer,
uint8_t  payload_buffer_length,
uint8_t *  response_buf,
uint8_t *  response_len 
)

Send data frame to Z-Wave chip via serial API, wait for ACK and a RES frame.

Parameters
commandZ-Wave Serial API Command (zwapi_func_ids.h)
payload_bufferByte array with serial API command parameters
payload_buffer_lengthLength in bytes of parameter array
response_bufoutput Buffer to hold response (buffer MUST be large enough to hold SERIAL_BUFFER_SIZE bytes).
response_lenouput Length of response copied to response_buf. It may take up to RX_ACK_TIMEOUT_DEFAULT ms to receive a ACK It may take up to RX_BYTE_TIMEOUT_DEFAULT ms to receive a RES frame
Returns
SL_STATUS_OK if the frame sent and Ack'ed by the module and the corresponding Response frame was received. SL_STATUS_FAIL otherwise

aka SendFrameWithResponse

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

◆ zwapi_session_shutdown()

void zwapi_session_shutdown ( )

Close the zwapi_session with the Z-Wave module.

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

◆ zwapi_session_wait_for_response()

static zwapi_connection_status_t zwapi_session_wait_for_response ( void  )
static

Wait for a acknowledgement (ACK, NAK, CAN) or possibly another SOF (REQ/RES) frame from the Z-Wave serial device.

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

Variable Documentation

◆ zwapi_session_rx_queue

zwapi_session_list_elem_t* zwapi_session_rx_queue
static