Atmel Software Framework

thirdparty/wireless/avr2102_rf4control/apps/zrc/terminal_tgt/main.c File Reference
#include <ctype.h>
#include "conf_board.h"
#include <asf.h>
#include "app_config.h"
#include "led.h"
#include "delay.h"
#include "vendor_data.h"
#include "pb_pairing.h"
#include "common_sw_timer.h"
#include "sio2host.h"

Macros

#define LED_DATA   (LED0)
 
#define LED_NWK_SETUP   (LED0)
 
#define LED_START   (LED0)
 
#define MAX_PAIRED_DEVICES   NWKC_MAX_PAIRING_TABLE_ENTRIES
 

Typedefs

typedef enum node_status_tag node_status_t
 

Enumerations

enum  node_status_tag {
  IDLE = 0,
  RESETTING,
  POWER_SAVE,
  STARTING,
  ZID_CONNECTING,
  ALL_IN_ONE_START,
  WARM_STARTING,
  IDLE = 0,
  RESETTING,
  POWER_SAVE,
  STARTING,
  ZID_CONNECTING,
  ALL_IN_ONE_START,
  WARM_STARTING,
  IDLE,
  WARM_START,
  COLD_START,
  TRANSMITTING,
  SELECT_TARGET_OPTIONS,
  TARGET_PAIRING,
  TARGET_CHANGING,
  BUTTON_RELEASE_WAITING,
  TARGET_PAIRING_WAIT,
  IDLE = 0,
  RESETTING,
  POWER_SAVE,
  STARTING,
  PUSH_BUTTON_PAIRING,
  CMD_DISCOVERING,
  ALL_IN_ONE_START,
  WARM_STARTING,
  PRINTING_PAIRING_TABLE,
  UNPAIRING,
  CH_AGILITY_EXECUTION,
  BASE_CHANNEL_CHANGE,
  GETTING_CH_AG_NIBS,
  COLD_START_RESET,
  PC_RUNNING,
  IDLE,
  TRANSMITTING,
  IDLE = 0,
  RESETTING,
  POWER_SAVE,
  STARTING,
  ZID_CONNECTING,
  ALL_IN_ONE_START,
  WARM_STARTING,
  PRINTING_PAIRING_TABLE,
  UNPAIRING,
  IDLE,
  WARM_START,
  COLD_START,
  CONFIGURING_ATTRIBUTES,
  CONNECTING,
  TRANSMITTING
}
 

Functions

static void app_alert (void)
 
static void app_task (void)
 Application task. More...
 
 FLASH_DECLARE (uint16_t VendorIdentifier)
 
 FLASH_DECLARE (uint8_t vendor_string[7])
 
 FLASH_DECLARE (uint8_t app_user_string[15])
 
 FLASH_DECLARE (uint8_t supported_cec_cmds[32])
 
static char * get_status_text (nwk_enum_t status)
 This function is used to print the status in text on the hyperterminal. More...
 
static void handle_input (uint8_t input_char)
 Handle keyboard input. More...
 
static void led_handling (void *callback_parameter)
 LED handling including timer control . More...
 
int main (void)
 Main function of the Terminal Target application. More...
 
static void nlme_get_confirm (nwk_enum_t Status, nib_attribute_t NIBAttribute, uint8_t NIBAttributeIndex, void *NIBAttributeValue)
 Notify the application of the status of its request for the value of a NIB attribute. More...
 
static void nlme_reset_confirm (nwk_enum_t Status)
 Notify the application of the status of its request to reset the NWK layer. More...
 
static void nlme_rx_enable_confirm (nwk_enum_t Status)
 Notify the application of the status of its request to enable or disable the receiver. More...
 
static void nlme_set_confirm (nwk_enum_t Status, nib_attribute_t NIBAttribute, uint8_t NIBAttributeIndex)
 Notify the application of the status of its request to to change the value of a NIB attribute. More...
 
static void nlme_start_confirm (nwk_enum_t Status)
 Notify the application of the status of its request to start a network. More...
 
static void nlme_unpair_confirm (uint8_t Status, uint8_t PairingRef)
 Notify the application for the previous unpair request. More...
 
static void nlme_unpair_indication (uint8_t PairingRef)
 Notify the application of the removal of link by another device. More...
 
static void nwk_ch_agility_confirm (nwk_enum_t Status, bool ChannelChanged, uint8_t LogicalChannel)
 Confirms the previous channel agility request, i.e. More...
 
static void nwk_ch_agility_indication (uint8_t LogicalChannel)
 Prints the new channel after channel agility took place. More...
 
bool pbp_allow_pairing (nwk_enum_t Status, uint64_t SrcIEEEAddr, uint16_t OrgVendorId, uint8_t OrgVendorString[7], uint8_t OrgUserString[15], uint8_t KeyExTransferCount)
 This function decides whether push button pairing request should be allowed. More...
 
static void pbp_rec_pair_confirm (nwk_enum_t Status, uint8_t PairingRef)
 Prints the status of push button pairing and if status is success, then send the cmd discovery to controller. More...
 
static void print_app_header (void)
 Print the head lines of the application to the terminal program. More...
 
static void print_ch_change_submenu (void)
 Prints the sub menu for the base channel change. More...
 
static void print_main_menu (void)
 Print main menu to terminal program. More...
 
static void print_node_status (void)
 Print the node status to the terminal program. More...
 
static void print_pairing_table (bool start_from_scratch, uint8_t *table_entry, uint8_t index)
 Print the pairing table to the terminal program. More...
 
static void print_sub_mode_ch_ag_setup (void)
 Prints the sub menu for the channel agility. More...
 
static void print_unpair_submenu (void)
 Print the unpairing submenu to the terminal program. More...
 
static void print_vendor_data_submenu (vendor_cmd_id_t Vcmd)
 This function is used to print the vendor data submenu on the hyperterminal. More...
 
void vendor_data_confirm (nwk_enum_t Status, uint8_t PairingRef, profile_id_t ProfileId, uint8_t Handle)
 Post processing of the vendor data confirm. More...
 
static void vendor_data_ind (uint8_t PairingRef, uint16_t VendorId, uint8_t nsduLength, uint8_t *nsdu, uint8_t RxLinkQuality, uint8_t RxFlags)
 Post processing of the vendor data response. More...
 
static void zrc_cmd_disc_confirm (nwk_enum_t Status, uint8_t PairingRef, uint8_t *SupportedCmd)
 The command discovery confirm for the previous command discovery request. More...
 
static void zrc_cmd_disc_indication (uint8_t PairingRef)
 The command discovery indication callback indicates that a command discovery request command was receiced. More...
 
static void zrc_cmd_indication (uint8_t PairingRef, uint8_t nsduLength, uint8_t *nsdu, uint8_t RxLinkQuality, uint8_t RxFlags)
 Handles the rc command indications at terminal target. More...
 

Variables

static bool ch_ag_enabled = false
 
static bool duplicate_pair_entry = false
 
static uint8_t led_timer
 
static node_status_t node_status
 
static uint8_t number_of_paired_dev = 0
 
static nwk_indication_callback_t nwk_ind
 
static uint8_t nwk_Private_ChAgEdThreshold
 
static uint32_t nwk_Private_ChAgScanInterval
 
static uint8_t nwk_ScanDuration
 
static node_status_t previous_node_status
 
static zrc_indication_callback_t zrc_ind
 

#define LED_DATA   (LED0)
#define LED_NWK_SETUP   (LED0)
#define LED_START   (LED0)

Referenced by main().

#define MAX_PAIRED_DEVICES   NWKC_MAX_PAIRING_TABLE_ENTRIES

Referenced by nlme_get_confirm().

Enumerator
IDLE 
RESETTING 
POWER_SAVE 
STARTING 
ZID_CONNECTING 
ALL_IN_ONE_START 
WARM_STARTING 
IDLE 
RESETTING 
POWER_SAVE 
STARTING 
ZID_CONNECTING 
ALL_IN_ONE_START 
WARM_STARTING 
IDLE 
WARM_START 
COLD_START 
TRANSMITTING 
SELECT_TARGET_OPTIONS 
TARGET_PAIRING 
TARGET_CHANGING 
BUTTON_RELEASE_WAITING 
TARGET_PAIRING_WAIT 
IDLE 
RESETTING 
POWER_SAVE 
STARTING 
PUSH_BUTTON_PAIRING 
CMD_DISCOVERING 
ALL_IN_ONE_START 
WARM_STARTING 
PRINTING_PAIRING_TABLE 
UNPAIRING 
CH_AGILITY_EXECUTION 
BASE_CHANNEL_CHANGE 
GETTING_CH_AG_NIBS 
COLD_START_RESET 
PC_RUNNING 
IDLE 
TRANSMITTING 
IDLE 
RESETTING 
POWER_SAVE 
STARTING 
ZID_CONNECTING 
ALL_IN_ONE_START 
WARM_STARTING 
PRINTING_PAIRING_TABLE 
UNPAIRING 
IDLE 
WARM_START 
COLD_START 
CONFIGURING_ATTRIBUTES 
CONNECTING 
TRANSMITTING 

static void app_alert ( void  )
static

References delay_us.

static void app_task ( void  )
static

Application task.

References handle_input(), nwk_stack_idle(), and sio2host_getchar_nowait().

Referenced by main().

FLASH_DECLARE ( uint16_t  VendorIdentifier)
FLASH_DECLARE ( uint8_t  vendor_string[7])
FLASH_DECLARE ( uint8_t  app_user_string[15])
FLASH_DECLARE ( uint8_t  supported_cec_cmds[32])
static void led_handling ( void *  callback_parameter)
static
static void nlme_get_confirm ( nwk_enum_t  Status,
nib_attribute_t  NIBAttribute,
uint8_t  NIBAttributeIndex,
void *  NIBAttributeValue 
)
static

Notify the application of the status of its request for the value of a NIB attribute.

Parameters
Statusnwk status
NIBAttributeNIBAttribute
NIBAttributeIndexNIBAttributeIndex
NIBAttributeValueValue of the NIB attribute.

References pairing_table_tag::DestinationLogicalChannel, FUNC_PTR, IDLE, MAX_PAIRED_DEVICES, nlme_get_request(), node_status, number_of_paired_dev, nwk_Private_ChAgEdThreshold, nwk_Private_ChAgScanInterval, nwk_ScanDuration, NWK_SUCCESS, nwkBaseChannel, nwkPairingTable, nwkPrivateChAgEdThreshold, nwkPrivateChAgScanInterval, nwkScanDuration, previous_node_status, print_pairing_table(), print_sub_mode_ch_ag_setup(), and WARM_STARTING.

Referenced by handle_input(), print_node_status(), and print_pairing_table().

static void nlme_reset_confirm ( nwk_enum_t  Status)
static

Notify the application of the status of its request to reset the NWK layer.

Parameters
Statusnwk status

References ALL_IN_ONE_START, FUNC_PTR, get_status_text(), IDLE, nlme_rx_enable_confirm(), nlme_rx_enable_request(), nlme_start_confirm(), nlme_start_request(), node_status, number_of_paired_dev, NWK_SUCCESS, RESETTING, RX_DURATION_INFINITY, and WARM_STARTING.

Referenced by handle_input().

static void nlme_rx_enable_confirm ( nwk_enum_t  Status)
static

Notify the application of the status of its request to enable or disable the receiver.

Parameters
Statusnwk status
static void nlme_set_confirm ( nwk_enum_t  Status,
nib_attribute_t  NIBAttribute,
uint8_t  NIBAttributeIndex 
)
static

Notify the application of the status of its request to to change the value of a NIB attribute.

Parameters
Statusnwk status
NIBAttributeNIBAttribute
NIBAttributeIndexNIBAttributeIndex

References get_status_text(), IDLE, node_status, NWK_SUCCESS, and nwkBaseChannel.

Referenced by print_ch_change_submenu(), and print_sub_mode_ch_ag_setup().

static void nlme_start_confirm ( nwk_enum_t  Status)
static

Notify the application of the status of its request to start a network.

The NLME-START.confirm primitive allows the NLME to notify the application of the status of its request to start a network.

Parameters
Statusnwk status

References ALL_IN_ONE_START, APP_CAPABILITIES, DEVICE_TYPE_LIST_SIZE, FUNC_PTR, get_status_text(), IDLE, led_handling(), LED_NWK_SETUP, led_timer, node_status, pbp_rec_pair_confirm(), pbp_rec_pair_request(), PROFILE_ID_LIST_SIZE, STARTING, SUPPORTED_DEV_TYPE_0, SUPPORTED_PROFILE_ID_0, SW_TIMEOUT_RELATIVE, and sw_timer_start().

Referenced by handle_input(), and nlme_reset_confirm().

static void nlme_unpair_confirm ( uint8_t  Status,
uint8_t  PairingRef 
)
static

Notify the application for the previous unpair request.

The NLME-UNPAIR.confirm primitive allows the NLME to notify the application of the status of its request to remove a pair with another device.

Parameters
Statusnwk status
PairingRefPairing Ref for which entry is removed from pairing table.

References get_status_text(), IDLE, node_status, number_of_paired_dev, NWK_NO_PAIRING, and UNPAIRING.

Referenced by print_unpair_submenu().

static void nlme_unpair_indication ( uint8_t  PairingRef)
static

Notify the application of the removal of link by another device.

The NLME-UNPAIR.indication primitive allows the NLME to notify the application of the removal of a pairing link by another device.

Parameters
PairingRefPairing Ref for which entry is removed from pairing table.

References number_of_paired_dev.

Referenced by main().

static void nwk_ch_agility_confirm ( nwk_enum_t  Status,
bool  ChannelChanged,
uint8_t  LogicalChannel 
)
static

Confirms the previous channel agility request, i.e.

nwk_ch_agility_req()

Parameters
Statusnwk status
ChannelChangedwhether channel is changed.
LogicalChannelchanged logical channel.

References ch_ag_enabled, get_status_text(), IDLE, and node_status.

Referenced by handle_input().

static void nwk_ch_agility_indication ( uint8_t  LogicalChannel)
static

Prints the new channel after channel agility took place.

Parameters
LogicalChannelchanged logical channel.
static void pbp_rec_pair_confirm ( nwk_enum_t  Status,
uint8_t  PairingRef 
)
static

Prints the status of push button pairing and if status is success, then send the cmd discovery to controller.

Parameters
Statusnwk status
PairingRefPairing Ref of the new entry.

References CMD_DISCOVERING, duplicate_pair_entry, FUNC_PTR, get_status_text(), IDLE, node_status, number_of_paired_dev, NWK_SUCCESS, zrc_cmd_disc_confirm(), and zrc_cmd_disc_request().

Referenced by handle_input(), and nlme_start_confirm().

static void print_app_header ( void  )
static

Print the head lines of the application to the terminal program.

References BOARD_NAME.

Referenced by print_main_menu().

static void print_ch_change_submenu ( void  )
static

Prints the sub menu for the base channel change.

References BASE_CHANNEL_CHANGE, FUNC_PTR, nlme_set_confirm(), nlme_set_request(), node_status, nwkBaseChannel, and sio2host_getchar().

Referenced by handle_input().

static void print_main_menu ( void  )
static

Print main menu to terminal program.

References print_app_header(), and print_node_status().

Referenced by handle_input().

static void print_node_status ( void  )
static
static void print_pairing_table ( bool  start_from_scratch,
uint8_t *  table_entry,
uint8_t  index 
)
static
static void print_unpair_submenu ( void  )
static

Print the unpairing submenu to the terminal program.

References FUNC_PTR, IDLE, nlme_unpair_confirm(), nlme_unpair_request(), node_status, and sio2host_getchar().

Referenced by handle_input().

static void print_vendor_data_submenu ( vendor_cmd_id_t  Vcmd)
static

This function is used to print the vendor data submenu on the hyperterminal.

Parameters
VcmdVendor command id to be requested.

References IDLE, node_status, NWKC_VENDOR_IDENTIFIER, PROFILE_ID_ZRC, sio2host_getchar(), TXO_ACK_REQ, TXO_CH_NOT_SPEC, TXO_DST_ADDR_IEEE, TXO_MULTI_CH, TXO_SEC_REQ, TXO_UNICAST, TXO_VEND_SPEC, and vendor_data_request().

Referenced by handle_input().

void vendor_data_confirm ( nwk_enum_t  Status,
uint8_t  PairingRef,
profile_id_t  ProfileId,
uint8_t  Handle 
)

Post processing of the vendor data confirm.

Parameters
statusnwk status (constants defined by nwk layer)
PairingRefPairing reference
HandleNetwork Layer retries

References EOT, get_next_tx_buffer(), RF4CONTROL_PID, RF4CONTROL_PID_LEN, and VENDOR_DATA_CONFIRM.

static void vendor_data_ind ( uint8_t  PairingRef,
uint16_t  VendorId,
uint8_t  nsduLength,
uint8_t *  nsdu,
uint8_t  RxLinkQuality,
uint8_t  RxFlags 
)
static

Post processing of the vendor data response.

Parameters
PairingRefPairing reference
VendorIdVendor ID.
nsduLengthLength of the payload.
nsduActual payload
RxLinkQualityLink quality of received packet.
RxFlagsRx Flags.
static void zrc_cmd_disc_confirm ( nwk_enum_t  Status,
uint8_t  PairingRef,
uint8_t *  SupportedCmd 
)
static

The command discovery confirm for the previous command discovery request.

   request command was receiced.
Parameters
Statusnwk status
PairingRefPairing Ref for destination.
SupportedCmdSupported commands by destination node.

References get_status_text(), IDLE, and node_status.

Referenced by pbp_rec_pair_confirm().

static void zrc_cmd_disc_indication ( uint8_t  PairingRef)
static

The command discovery indication callback indicates that a command discovery request command was receiced.

Parameters
PairingRefPairing Ref for the source.

References PGM_READ_BLOCK, and zrc_cmd_disc_response().

Referenced by main().

static void zrc_cmd_indication ( uint8_t  PairingRef,
uint8_t  nsduLength,
uint8_t *  nsdu,
uint8_t  RxLinkQuality,
uint8_t  RxFlags 
)
static

Handles the rc command indications at terminal target.

Parameters
PairingRefPairing reference
nsduLengthLength of the payload.
nsduActual payload
RxLinkQualityLink quality of received packet.
RxFlagsRx Flags.

References zrc_cmd_frm_tag::fcf, FUNC_PTR, IDLE, LED_DATA, led_handling(), led_timer, nlme_rx_enable_confirm(), nlme_rx_enable_request(), node_status, POWER_SAVE, zrc_cmd_frm_tag::rc_cmd, RX_DURATION_INFINITY, SW_TIMEOUT_RELATIVE, sw_timer_start(), USER_CONTROL_PRESSED, USER_CONTROL_RELEASED, USER_CONTROL_REPEATED, and zrc_print_rc_cmd_text().

Referenced by main().

bool ch_ag_enabled = false
static
bool duplicate_pair_entry = false
static
uint8_t led_timer
static
nwk_indication_callback_t nwk_ind
static
uint8_t nwk_Private_ChAgEdThreshold
static
uint32_t nwk_Private_ChAgScanInterval
static
uint8_t nwk_ScanDuration
static
node_status_t previous_node_status
static

Referenced by handle_input(), and nlme_get_confirm().

zrc_indication_callback_t zrc_ind
static