Z-Wave Protocol Controller Reference
transport_service.c File Reference
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "transport_service.h"
#include "zwave_tx.h"
#include "ctimer.h"
#include "transport_service_command_class_def.h"
#include "zwave_controller_crc16.h"
#include "sl_log.h"
Include dependency graph for transport_service.c:

Classes

struct  transition_t
 
struct  cb
 
struct  sending_cntrl_blk
 
struct  rx_timer_expired_data
 
struct  receiving_cntrl_blk
 

Macros

#define LOG_TAG   "transport_service"
 
#define PAYLOAD_SIZE_MAX   (200)
 
#define FIRST_HDR_LEN   4 /* Cmd class, cmd, size, seqno */
 
#define SUBSEQ_HDR_LEN   5 /* Cmd class, cmd, size, seqno + offset 1, offset 2*/
 
#define FRAGMENT_FC_TIMEOUT   1000 /*ms*/
 
#define FRAGMENT_RX_TIMEOUT   800 /*ms*/
 
#define RESET_TIME   5000 /* ms */
 
#define log_debug(f, ...)   sl_log_debug(LOG_TAG, f, ##__VA_ARGS__)
 
#define log_error(f, ...)   sl_log_debug(LOG_TAG, f, ##__VA_ARGS__)
 
#define FIRST_FRAG_NONPAYLOAD_LENGTH    (sizeof(ZW_COMMAND_FIRST_FRAGMENT_1BYTE_FRAME) - 1)
 
#define SUBSEQ_FRAG_NONPAYLOAD_LENGTH    (sizeof(ZW_COMMAND_SUBSEQUENT_FRAGMENT_1BYTE_FRAME) - 1)
 

Typedefs

typedef enum TRANSPORT2_STATES TRANSPORT2_ST_T
 
typedef enum TRANSPORT2_EVENTS TRANSPORT2_EV_T
 
typedef struct cb control_block_t
 
typedef struct sending_cntrl_blk sending_cntrl_blk_t
 
typedef struct receiving_cntrl_blk receiving_cntrl_blk_t
 

Enumerations

enum  TRANSPORT2_STATES {
  ST_IDLE , ST_RECEIVING , ST_SEND_FRAG_COMPLETE , ST_SEND_FRAG_REQ ,
  ST_SEND_FRAG_WAIT , ST_FIND_MISS_FRAG , ST_SEND_FRAG , ST_SEND_LAST_FRAG ,
  ST_WAIT_ACK
}
 
enum  TRANSPORT2_EVENTS {
  EV_START_RECV , EV_RECV_NEW_FRAG , EV_NO_SESSION_ID , EV_SEND_FRAG_COMPLETE ,
  EV_NO_SEND_FRAG_COMPLETE , EV_SUCCESS , EV_SUCCESS2 , EV_SUCCESS3 ,
  EV_FRAG_RX_TIMER , EV_MISSING_FRAG , EV_MISSING_FRAG_BCAST , EV_SCAST_DIFF_NODE ,
  EV_BCAST_DIFF_NODE , EV_DIFF_SESSION , EV_SUBSEQ_DIFF_SESSION , EV_FRAG_REQ_COMPL_WAIT_DIFF_SESSION ,
  EV_FRAG_REQ_COMPL_WAIT_DIFF_NODE , EV_RECV_FRAG_REQ , EV_RECV_LAST_FRAG , EV_RECV_FRAG_COMPLETE ,
  EV_TIE_BREAK , EV_DUPL_FRAME , EV_FRAG_REQ_OR_COMPL , EV_START_SEND ,
  EV_SEND_NEW_FRAG , EV_SEND_NXT_MISS_FRAG , EV_SENT_MISS_FRAG , EV_RECV_FRAG_WAIT ,
  EV_SEND_LAST_FRAG , EV_SEND_LAST_MISS_FRAG , EV_FRAG_COMPL_TIMER , EV_FRAG_COMPL_TIMER2 ,
  EV_FRAG_COMPL_TIMER_REQ , EV_FAILURE_LAST_FRAG2 , EV_RECV_FRAG_COMPL , EV_REPLY_FRAG_REQ_DONE ,
  EV_FAIL
}
 

Functions

static void reply_frag_req ()
 
static uint8_t send_frag_wait_cmd ()
 
static void send_subseq_frag (void *nthing)
 
void fc_timer_expired (void *nthing)
 
static void send_first_frag ()
 
static uint8_t get_next_missing_offset ()
 
static void rx_timer_expired (void *ss)
 
static void send_last_frag (void)
 
void transport_service_init (ts_node_id_t node_id, const upper_layer_command_handler_t command_handler, const send_data_t send_data)
 Initialize the Transport Service. More...
 
uint8_t find_transition (TRANSPORT2_ST_T cstate, TRANSPORT2_EV_T event)
 
void t2_sm_post_event (TRANSPORT2_EV_T ev)
 
static uint8_t recv_or_send ()
 
uint8_t is_transport_service_receiving ()
 
uint8_t is_transport_service_sending ()
 
void transport_service_senddata_cb (uint8_t status, void *user)
 
static uint8_t discard_all_received_fragments (void)
 
static void reset_transport_service (void *user)
 
static uint8_t mark_frag_received (const uint16_t offset, const uint8_t size)
 
static uint8_t send_frag_complete_cmd ()
 
static uint8_t send_frag_req_cmd ()
 
static void find_missing ()
 
static void add_crc (uint8_t *buf, uint16_t len)
 
static void temp_callback_last_frag (uint8_t status, void *user)
 
void temp_callback_reply_frag_req (unsigned char status, void *user)
 
static void wait_restart_from_first (void *nthing)
 
static bool receive (void)
 
static bool transport_service_command_handler (ts_node_id_t source, ts_node_id_t dest, receive_type rx_type, const uint8_t *frame_data, uint8_t frame_length)
 
bool transport_service_on_frame_received (ts_node_id_t source, ts_node_id_t dest, receive_type rx_type, const uint8_t *frame_data, uint8_t frame_length)
 Transport service RX function. More...
 
transport_service_send_data_return_code_t transport_service_send_data (ts_node_id_t source, ts_node_id_t dest, const uint8_t *payload, uint16_t payload_len, uint16_t max_frame_len, const on_transport_service_send_data_complete_t c)
 Sending a long frame with Transport service. More...
 

Variables

static on_transport_service_send_data_complete_t on_send_complete_cb = 0
 
static send_data_t lower_layer_send_data = 0
 
static upper_layer_command_handler_t upper_layer_command_handler
 
static uint16_t my_node_id
 
static uint16_t max_fragment_size = 0
 
static uint16_t offset_to_request = 0
 
static uint8_t flag_tie_broken = 0
 
static uint8_t flag_initialize_once = 1
 
uint8_t t2_txBuf [PAYLOAD_SIZE_MAX+sizeof(ZW_COMMAND_SUBSEQUENT_FRAGMENT_1BYTE_FRAME) - 1]
 
ZW_COMMAND_FIRST_FRAGMENT_1BYTE_FRAMEfirst_frag = (ZW_COMMAND_FIRST_FRAGMENT_1BYTE_FRAME *)t2_txBuf
 
ZW_COMMAND_SUBSEQUENT_FRAGMENT_1BYTE_FRAMEsubseq_frag = (ZW_COMMAND_SUBSEQUENT_FRAGMENT_1BYTE_FRAME *)t2_txBuf
 
static const transition_t trans []
 
TRANSPORT2_ST_T current_state = ST_IDLE
 
sending_cntrl_blk_t scb
 
receiving_cntrl_blk_t rcb
 

Macro Definition Documentation

◆ FIRST_FRAG_NONPAYLOAD_LENGTH

#define FIRST_FRAG_NONPAYLOAD_LENGTH    (sizeof(ZW_COMMAND_FIRST_FRAGMENT_1BYTE_FRAME) - 1)

◆ FIRST_HDR_LEN

#define FIRST_HDR_LEN   4 /* Cmd class, cmd, size, seqno */

◆ FRAGMENT_FC_TIMEOUT

#define FRAGMENT_FC_TIMEOUT   1000 /*ms*/

◆ FRAGMENT_RX_TIMEOUT

#define FRAGMENT_RX_TIMEOUT   800 /*ms*/

◆ log_debug

#define log_debug (   f,
  ... 
)    sl_log_debug(LOG_TAG, f, ##__VA_ARGS__)

◆ log_error

#define log_error (   f,
  ... 
)    sl_log_debug(LOG_TAG, f, ##__VA_ARGS__)

◆ LOG_TAG

#define LOG_TAG   "transport_service"

◆ PAYLOAD_SIZE_MAX

#define PAYLOAD_SIZE_MAX   (200)

◆ RESET_TIME

#define RESET_TIME   5000 /* ms */

◆ SUBSEQ_FRAG_NONPAYLOAD_LENGTH

#define SUBSEQ_FRAG_NONPAYLOAD_LENGTH    (sizeof(ZW_COMMAND_SUBSEQUENT_FRAGMENT_1BYTE_FRAME) - 1)

◆ SUBSEQ_HDR_LEN

#define SUBSEQ_HDR_LEN   5 /* Cmd class, cmd, size, seqno + offset 1, offset 2*/

Typedef Documentation

◆ control_block_t

typedef struct cb control_block_t

◆ receiving_cntrl_blk_t

◆ sending_cntrl_blk_t

◆ TRANSPORT2_EV_T

◆ TRANSPORT2_ST_T

Enumeration Type Documentation

◆ TRANSPORT2_EVENTS

Enumerator
EV_START_RECV 
EV_RECV_NEW_FRAG 
EV_NO_SESSION_ID 
EV_SEND_FRAG_COMPLETE 
EV_NO_SEND_FRAG_COMPLETE 
EV_SUCCESS 
EV_SUCCESS2 
EV_SUCCESS3 
EV_FRAG_RX_TIMER 
EV_MISSING_FRAG 
EV_MISSING_FRAG_BCAST 
EV_SCAST_DIFF_NODE 
EV_BCAST_DIFF_NODE 
EV_DIFF_SESSION 
EV_SUBSEQ_DIFF_SESSION 
EV_FRAG_REQ_COMPL_WAIT_DIFF_SESSION 
EV_FRAG_REQ_COMPL_WAIT_DIFF_NODE 
EV_RECV_FRAG_REQ 
EV_RECV_LAST_FRAG 
EV_RECV_FRAG_COMPLETE 
EV_TIE_BREAK 
EV_DUPL_FRAME 
EV_FRAG_REQ_OR_COMPL 
EV_START_SEND 
EV_SEND_NEW_FRAG 
EV_SEND_NXT_MISS_FRAG 
EV_SENT_MISS_FRAG 
EV_RECV_FRAG_WAIT 
EV_SEND_LAST_FRAG 
EV_SEND_LAST_MISS_FRAG 
EV_FRAG_COMPL_TIMER 
EV_FRAG_COMPL_TIMER2 
EV_FRAG_COMPL_TIMER_REQ 
EV_FAILURE_LAST_FRAG2 
EV_RECV_FRAG_COMPL 
EV_REPLY_FRAG_REQ_DONE 
EV_FAIL 

◆ TRANSPORT2_STATES

Enumerator
ST_IDLE 
ST_RECEIVING 
ST_SEND_FRAG_COMPLETE 
ST_SEND_FRAG_REQ 
ST_SEND_FRAG_WAIT 
ST_FIND_MISS_FRAG 
ST_SEND_FRAG 
ST_SEND_LAST_FRAG 
ST_WAIT_ACK 

Function Documentation

◆ add_crc()

static void add_crc ( uint8_t *  buf,
uint16_t  len 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ discard_all_received_fragments()

static uint8_t discard_all_received_fragments ( void  )
static
Here is the caller graph for this function:

◆ fc_timer_expired()

void fc_timer_expired ( void *  nthing)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_missing()

static void find_missing ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_transition()

uint8_t find_transition ( TRANSPORT2_ST_T  cstate,
TRANSPORT2_EV_T  event 
)
Here is the caller graph for this function:

◆ get_next_missing_offset()

static uint8_t get_next_missing_offset ( )
static
Here is the caller graph for this function:

◆ is_transport_service_receiving()

uint8_t is_transport_service_receiving ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_transport_service_sending()

uint8_t is_transport_service_sending ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mark_frag_received()

static uint8_t mark_frag_received ( const uint16_t  offset,
const uint8_t  size 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ receive()

static bool receive ( void  )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recv_or_send()

static uint8_t recv_or_send ( )
static
Here is the caller graph for this function:

◆ reply_frag_req()

static void reply_frag_req ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_transport_service()

static void reset_transport_service ( void *  user)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rx_timer_expired()

static void rx_timer_expired ( void *  ss)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_first_frag()

static void send_first_frag ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_frag_complete_cmd()

static uint8_t send_frag_complete_cmd ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_frag_req_cmd()

static uint8_t send_frag_req_cmd ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_frag_wait_cmd()

static uint8_t send_frag_wait_cmd ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_last_frag()

static void send_last_frag ( void  )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_subseq_frag()

static void send_subseq_frag ( void *  nthing)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ t2_sm_post_event()

void t2_sm_post_event ( TRANSPORT2_EV_T  ev)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ temp_callback_last_frag()

static void temp_callback_last_frag ( uint8_t  status,
void *  user 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ temp_callback_reply_frag_req()

void temp_callback_reply_frag_req ( unsigned char  status,
void *  user 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transport_service_command_handler()

static bool transport_service_command_handler ( ts_node_id_t  source,
ts_node_id_t  dest,
receive_type  rx_type,
const uint8_t *  frame_data,
uint8_t  frame_length 
)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transport_service_senddata_cb()

void transport_service_senddata_cb ( uint8_t  status,
void *  user 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_restart_from_first()

static void wait_restart_from_first ( void *  nthing)
static
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ current_state

TRANSPORT2_ST_T current_state = ST_IDLE

◆ first_frag

◆ flag_initialize_once

uint8_t flag_initialize_once = 1
static

◆ flag_tie_broken

uint8_t flag_tie_broken = 0
static

◆ lower_layer_send_data

send_data_t lower_layer_send_data = 0
static

◆ max_fragment_size

uint16_t max_fragment_size = 0
static

◆ my_node_id

uint16_t my_node_id
static

◆ offset_to_request

uint16_t offset_to_request = 0
static

◆ on_send_complete_cb

on_transport_service_send_data_complete_t on_send_complete_cb = 0
static

◆ rcb

◆ scb

◆ subseq_frag

◆ t2_txBuf

◆ trans

const transition_t trans[]
static

◆ upper_layer_command_handler

upper_layer_command_handler_t upper_layer_command_handler
static