nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ANT-FS client device simulator

The ANT-FS client device simulator. More...

Macros

#define ANTFS_VERSION_MAJOR   1u
 
#define ANTFS_VERSION_MINOR   0
 
#define ANTFS_VERSION_ITERATION   0
 
#define ANTFS_VERSION_TYPE   'R'
 
#define ANTFS_VERSION_SPEC   '0.AK'
 
#define ANTFS_DIR_STRUCT_VERSION   1u
 
#define ANTFS_VERSION_DATE   20090522u
 
#define ANTFS_NETWORK_NUMBER   0
 
#define ANTFS_CHANNEL   0
 
#define ANTFS_LINK_FREQ   50u
 
#define ANTFS_PAIRING_TIMEOUT   120u
 
#define ANTFS_LINK_COMMAND_TIMEOUT   10u
 
#define ANTFS_TRANS_TYPE   5u
 
#define ANTFS_DEVICE_TYPE   1u
 
#define ANTFS_CHANNEL_TYPE   CHANNEL_TYPE_MASTER
 
#define ANTFS_BEACON_PERIOD_STATUS   BEACON_PERIOD_4_HZ
 
#define ANTFS_TRANSMIT_POWER   3u
 
#define ANTFS_AUTH_STRING_MAX   255u
 
#define ANTFS_PASSKEY_SIZE   16u
 
#define ANTFS_FRIENDLY_NAME_MAX   16u
 
#define ANTFS_REMOTE_FRIENDLY_NAME_MAX   16u
 
#define BEACON_PERIOD_SHIFT   0x00
 
#define BEACON_PERIOD_MASK   (0x07u << BEACON_PERIOD_SHIFT)
 
#define BEACON_PERIOD_0_5_HZ   (0x00 << BEACON_PERIOD_SHIFT)
 
#define BEACON_PERIOD_1_HZ   (0x01u << BEACON_PERIOD_SHIFT)
 
#define BEACON_PERIOD_2_HZ   (0x02u << BEACON_PERIOD_SHIFT)
 
#define BEACON_PERIOD_4_HZ   (0x03u << BEACON_PERIOD_SHIFT)
 
#define BEACON_PERIOD_8_HZ   (0x04u << BEACON_PERIOD_SHIFT)
 
#define PAIRING_AVAILABLE_FLAG_SHIFT   0x03u
 
#define PAIRING_AVAILABLE_FLAG_MASK   (0x01u << PAIRING_AVAILABLE_FLAG_SHIFT)
 
#define UPLOAD_ENABLED_FLAG_SHIFT   0x04u
 
#define UPLOAD_ENABLED_FLAG_MASK   (0x01u << UPLOAD_ENABLED_FLAG_SHIFT)
 
#define DATA_AVAILABLE_FLAG_SHIFT   0x05u
 
#define DATA_AVAILABLE_FLAG_MASK   (0x01u << DATA_AVAILABLE_FLAG_SHIFT)
 
#define ANTFS_PAIRING_BIT   0x00u
 
#define ANTFS_UPLOAD_BIT   0x00u
 
#define ANTFS_DEFAULT_BEACON   (ANTFS_BEACON_PERIOD_STATUS | ANTFS_UPLOAD_BIT | ANTFS_PAIRING_BIT | DATA_AVAILABLE_FLAG_MASK)
 
#define RESPONSE_MESSAGE_OK   0x00u
 
#define RESPONSE_MESSAGE_NOT_EXIST   0x01u
 
#define RESPONSE_MESSAGE_NOT_AVAILABLE   0x02u
 
#define RESPONSE_MESSAGE_NOT_READY   0x03u
 
#define RESPONSE_INVALID_OPERATION   0x04u
 
#define RESPONSE_INVALID_CRC   0x05u
 
#define RESPONSE_MESSAGE_NOT_ENOUGH_SPACE   0x03u
 
#define RESPONSE_MESSAGE_FAIL   0x01u
 
#define ANTFS_DIR_READ_MASK   0x80u
 
#define ANTFS_DIR_WRITE_MASK   0x40u
 
#define ANTFS_DIR_ERASE_MASK   0x20u
 
#define ANTFS_DIR_ARCHIVE_MASK   0x10u
 
#define ANTFS_DIR_APPEND_MASK   0x08u
 
#define ANTFS_MAX_FILE_SIZE   0xFFFFFFFFu
 
#define ANTFS_BURST_BLOCK_SIZE   20u
 
#define MAX_ULONG   0xFFFFFFFFu
 
#define APP_TIMER_PRESCALER   0
 
#define ANT_EVENT_MSG_BUFFER_MIN_SIZE   32u
 
#define ANTFS_CLIENT_SERIAL_NUMBER   0xABCDEF12u
 
#define ANTFS_CLIENT_DEV_TYPE   416u
 
#define ANTFS_CLIENT_MANUF_ID   2u
 
#define ANTFS_CLIENT_NAME   { "Ref Design" }
 
#define ANTFS_CLIENT_PASSKEY   {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10}
 
#define APP_TIMER_MAX_TIMERS   2u
 
#define APP_TIMER_OP_QUEUE_SIZE   4u
 
#define APP_GPIOTE_MAX_USERS   1u
 
#define BUTTON_DETECTION_DELAY   APP_TIMER_TICKS(50u, APP_TIMER_PRESCALER)
 

Enumerations

enum  antfs_state_t {
  ANTFS_STATE_OFF,
  ANTFS_STATE_INIT,
  ANTFS_STATE_LINK,
  ANTFS_STATE_AUTH,
  ANTFS_STATE_TRANS,
  ANTFS_STATE_OFF,
  ANTFS_STATE_INIT,
  ANTFS_STATE_LINK,
  ANTFS_STATE_AUTH,
  ANTFS_STATE_TRANS
}
 
enum  antfs_link_substate_t {
  ANTFS_LINK_SUBSTATE_NONE,
  ANTFS_LINK_SUBSTATE_NONE
}
 
enum  antfs_authenticate_substate_t {
  ANTFS_AUTH_SUBSTATE_NONE,
  ANTFS_AUTH_SUBSTATE_PAIR,
  ANTFS_AUTH_SUBSTATE_PASSKEY,
  ANTFS_AUTH_SUBSTATE_ACCEPT,
  ANTFS_AUTH_SUBSTATE_REJECT,
  ANTFS_AUTH_SUBSTATE_NONE,
  ANTFS_AUTH_SUBSTATE_PAIR,
  ANTFS_AUTH_SUBSTATE_PASSKEY,
  ANTFS_AUTH_SUBSTATE_ACCEPT,
  ANTFS_AUTH_SUBSTATE_REJECT
}
 
enum  antfs_transport_substate_t {
  ANTFS_TRANS_SUBSTATE_NONE,
  ANTFS_TRANS_SUBSTATE_VERIFY_CRC,
  ANTFS_TRANS_SUBSTATE_DOWNLOADING,
  ANTFS_TRANS_SUBSTATE_UPLOAD_WAIT_FOR_DATA,
  ANTFS_TRANS_SUBSTATE_UPLOADING,
  ANTFS_TRANS_SUBSTATE_UPLOAD_RESUME,
  ANTFS_TRANS_SUBSTATE_NONE,
  ANTFS_TRANS_SUBSTATE_VERIFY_CRC,
  ANTFS_TRANS_SUBSTATE_DOWNLOADING,
  ANTFS_TRANS_SUBSTATE_UPLOAD_WAIT_FOR_DATA,
  ANTFS_TRANS_SUBSTATE_UPLOADING,
  ANTFS_TRANS_SUBSTATE_UPLOAD_RESUME
}
 
enum  antfs_event_t {
  ANTFS_EVENT_PAIRING_REQUEST = 0xB0,
  ANTFS_EVENT_PAIRING_TIMEOUT = 0xB1,
  ANTFS_EVENT_OPEN_COMPLETE = 0xB2,
  ANTFS_EVENT_CLOSE_COMPLETE = 0xB4,
  ANTFS_EVENT_LINK = 0xB6,
  ANTFS_EVENT_AUTH = 0xB7,
  ANTFS_EVENT_TRANS = 0xB8,
  ANTFS_EVENT_DOWNLOAD_REQUEST = 0xB9,
  ANTFS_EVENT_DOWNLOAD_REQUEST_DATA = 0xBA,
  ANTFS_EVENT_DOWNLOAD_START = 0xBB,
  ANTFS_EVENT_DOWNLOAD_COMPLETE = 0xBC,
  ANTFS_EVENT_DOWNLOAD_FAIL = 0xBD,
  ANTFS_EVENT_UPLOAD_REQUEST = 0xBE,
  ANTFS_EVENT_UPLOAD_DATA = 0xBF,
  ANTFS_EVENT_UPLOAD_START = 0xC0,
  ANTFS_EVENT_UPLOAD_COMPLETE = 0xC1,
  ANTFS_EVENT_UPLOAD_FAIL = 0xC2,
  ANTFS_EVENT_ERASE_REQUEST = 0xC3,
  ANTFS_EVENT_PAIRING_REQUEST = 0xB0,
  ANTFS_EVENT_PAIRING_TIMEOUT = 0xB1,
  ANTFS_EVENT_OPEN_COMPLETE = 0xB2,
  ANTFS_EVENT_CLOSE_COMPLETE = 0xB4,
  ANTFS_EVENT_LINK = 0xB6,
  ANTFS_EVENT_AUTH = 0xB7,
  ANTFS_EVENT_TRANS = 0xB8,
  ANTFS_EVENT_DOWNLOAD_REQUEST = 0xB9,
  ANTFS_EVENT_DOWNLOAD_REQUEST_DATA = 0xBA,
  ANTFS_EVENT_DOWNLOAD_START = 0xBB,
  ANTFS_EVENT_DOWNLOAD_COMPLETE = 0xBC,
  ANTFS_EVENT_DOWNLOAD_FAIL = 0xBD,
  ANTFS_EVENT_UPLOAD_REQUEST = 0xBE,
  ANTFS_EVENT_UPLOAD_DATA = 0xBF,
  ANTFS_EVENT_UPLOAD_START = 0xC0,
  ANTFS_EVENT_UPLOAD_COMPLETE = 0xC1,
  ANTFS_EVENT_UPLOAD_FAIL = 0xC2,
  ANTFS_EVENT_ERASE_REQUEST = 0xC3
}
 
enum  leddriver_led_id_t {
  LED_ID_0,
  LED_ID_1,
  LED_ID_MAX,
  LED_ID_0,
  LED_ID_1,
  LED_ID_MAX
}
 
enum  pairing_state_t {
  PAIRING_OFF = 0,
  PAIRING_ACCEPT,
  PAIRING_DENY,
  PAIRING_OFF = 0,
  PAIRING_ACCEPT,
  PAIRING_DENY
}
 

Functions

void antfs_init (const antfs_params_t *const p_params)
 Function for setting initial ANT-FS configuration parameters. More...
 
const char * antfs_hostname_get (void)
 Function for getting host name if received. More...
 
bool antfs_pairing_resp_transmit (bool accept)
 Function for transmitting a response to a pairing request issued by ANT-FS host. More...
 
void antfs_download_req_resp_prepare (uint8_t response, const antfs_request_info_t *const p_request_info)
 Function for doing calculations prior downloading the data to the ANT-FS host. More...
 
uint32_t antfs_input_data_download (uint16_t index, uint32_t offset, uint32_t num_bytes, const uint8_t *const p_message)
 Function for downloading requested data. More...
 
bool antfs_upload_req_resp_transmit (uint8_t response, const antfs_request_info_t *const p_request_info)
 Function for transmitting upload request response to a upload request command by ANT-FS host. More...
 
bool antfs_upload_data_resp_transmit (bool data_upload_success)
 Function for transmitting upload data response to a upload data command by ANT-FS host. More...
 
void antfs_erase_req_resp_transmit (uint8_t response)
 Function for transmitting erase response to a erase request. More...
 
bool antfs_event_extract (antfs_event_return_t *const p_event)
 Function for extracting possible pending ANT-FS event. More...
 
void antfs_message_process (uint8_t *p_message)
 Function for processing ANT events and data received from the ANT-FS channel. More...
 
void antfs_channel_setup (void)
 Function for setting up the ANT-FS channel.
 
uint16_t crc_crc16_update (uint16_t current_crc, const volatile void *p_data, uint32_t size)
 Function for calculating CRC-16 in blocks. More...
 
void leddriver_init (void)
 Function for configuring all the GPIOs needed by the driver.
 
void leddriver_led_turn_on (leddriver_led_id_t led_id)
 Function for turning a single led on. More...
 
void leddriver_led_turn_off (leddriver_led_id_t led_id)
 Function for turning a single led off. More...
 
void leddriver_led_toggle (leddriver_led_id_t led_id)
 Function for toggling a single led. More...
 
bool mem_file_write (uint16_t index, uint32_t offset, const void *p_data, uint32_t size)
 Function for writing data to file system. More...
 
void mem_file_read (uint16_t index, uint32_t offset, void *p_data, uint32_t size)
 Function for reading data from file system. More...
 
bool mem_file_erase (uint16_t index)
 Function for erasing file from file system. More...
 
bool mem_file_info_get (uint16_t index, antfs_dir_struct_t *p_file_info)
 Function for retrieving file information from directory. More...
 
void softdevice_assert_callback (uint32_t pc, uint16_t line_num, const uint8_t *p_file_name)
 Function for handling softdevice asserts, does not return. More...
 
void app_error_handler (uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name)
 Function for handling an error. More...
 
void PROTOCOL_EVENT_IRQHandler (void)
 Function for handling protocol stack IRQ. More...
 
static __INLINE void pairing_user_feedback_handle (void)
 Function for processing user feedback for ANTFS pairing authentication request.
 
static __INLINE void event_pairing_request_handle (void)
 Function for processing ANTFS pairing request event.
 
static void event_download_request_handle (const antfs_event_return_t *p_event)
 Function for processing ANTFS download request event. More...
 
static void event_download_data_handle (const antfs_event_return_t *p_event)
 Function for processing ANTFS download data event. More...
 
static void event_upload_request_handle (const antfs_event_return_t *p_event)
 Function for processing ANTFS upload request data event. More...
 
static void event_upload_data_handle (const antfs_event_return_t *p_event)
 Function for processing ANTFS upload data event. More...
 
static __INLINE void event_upload_complete_handle (void)
 Function for processing ANTFS upload complete event.
 
static void event_erase_request_handle (const antfs_event_return_t *p_event)
 Function for processing ANTFS erase request event. More...
 
static void antfs_event_process (const antfs_event_return_t *p_event)
 Function for processing a single ANTFS event. More...
 
void button_event_handle (uint8_t pin_no)
 Function for handling button events. More...
 
static __INLINE void softdevice_setup (void)
 Function for configuring and setting up the softdevice.
 
int main (void)
 Function for application main entry, does not return.
 

Variables

static const uint8_t m_friendly_name [] = ANTFS_CLIENT_NAME
 
static const uint8_t m_pass_key [] = ANTFS_CLIENT_PASSKEY
 
static antfs_event_return_t m_antfs_event
 
static antfs_dir_struct_t m_temp_dir_structure
 
static antfs_request_info_t m_response_info
 
static uint16_t m_file_index
 
static uint32_t m_file_offset
 
static uint16_t m_current_crc
 
static bool m_upload_success
 
static volatile pairing_state_t m_pairing_state
 

Data Structures

union  antfs_beacon_status_byte1_t
 ANT-FS beacon status. More...
 
struct  antfs_event_return_t
 ANT-FS <-> application event communication object. More...
 
struct  antfs_params_t
 ANT-FS parameters. More...
 
struct  antfs_dir_header_t
 ANT-FS directory header. More...
 
struct  antfs_dir_struct_t
 ANT-FS directory entry. More...
 
struct  antfs_request_info_t
 ANT-FS download/upload request context. More...
 
union  ushort_union_t
 uint16_t type presentation as an union. More...
 
union  ulong_union_t
 uint32_t type presentation as an union. More...
 

Detailed Description

Note
The ANT-FS Network Key is available for ANT+ Adopters. Please refer to http://thisisant.com to become an ANT+ Adopter and access the key.

The ANT-FS client device simulator example illustrates the basic operations of an ANT-FS client.

This example supports all three methods of authentication defined in the ANT-FS specification: pairing, passkey and pass-thru. It also supports the simulation of downloading, uploading and erasing files. Other functionality that is not defined in the ANT-FS specification, such as file system implementation and data decoding/encoding are outside of scope of this implementation.

Note
This example does not implement the client undiscoverable mode as defined by the ANT-FS specification.

The general architecture of the ANT-FS client device simulator is illustrated in the picture below.

ant_fs_embedded_client_device_simulator_architecture.png
Architecture overview
ANT-FS specific configuration options

The following compile time configuration options are available to suite various ANT-FS implementations:

This example implements the pairing, pass key and pass-thru authentication methods, which can be enabled using compile switches. All three authentication methods are enabled by default. Upload functionality can also be enabled through a compile switch and it is by default turned on. The compile switches can be set on antfs.c and are listed below.

To establish communication, the host and client devices shall have corresponding configurations. The host device may wish to wildcard any of the fields in the Channel ID and Client Identifier by setting them to zero, but the network key and RF channel frequency shall be the same. The channel period of the client need not match the channel period of the host.

A simple user interface exists consisting of 2 keypad buttons, which are active during pairing authentication for user to accept or reject the authentication, and 2 LEDs which are active during reception of EVENT_TX and pairing authentication mode. LED0 been toggled for every EVENT_TX received from the and stack and LED1 turned on when in pairing authentication mode. The LEDs can be configured in the leddriver.c file.

General operation

The ANT-FS client device simulator executes automatically through each ANT-FS layer, as per the commands received from the ANT-FS host. User interaction is only required when using pairing authentication, to confirm or reject a pairing request.

Once a ANT-FS host detects a client with ANT channel and ANT-FS client parameters matching its search criteria, it will send a Link command to the client, specifying the Link RF channel frequency and channel period. The client will automatically switch to the new frequency and channel period, and indicate in its beacon that it has moved to the Authentication stage.

Authenticate

Once both the ANT-FS client and host are in the authentication layer the host can send a request to client device for pairing. The ANT-FS client example supports three methods of authentication: pairing, passkey and pass-thru. When using the passkey and pass-thru authentication methods, the client will automatically accept or reject the authentication as outlined by the ANT-FS specification. Intervention from the user is only required when using the pairing authentication method. If the client receives a pairing request from the host, it will turn on a LED to let the user know that a host device wishes to pair with it. The user can accept or reject the pairing request by pressing the one of the appropriate buttons. If no response from the user is received before the pairing timeout expires, the request will be rejected.

Download

A sample directory structure is implemented in this example, however, no actual files or file systems are present in the example. The client will send the directory to the host if it receives a request to download the directory (file index0). When the host requests a download for any other files, the client will check if the file exists in its directory, and if there is permission to download that file. If the file can be downloaded, the client will simulate a file by sending sequential data with size matching the requested file size; otherwise, it will reject the download.

Upload

When the host requests an upload, the client will check if the file index exists in its directory, if there is permission to write on that file, and if there is enough space to write the requested data. Once the client sends a response accepting the upload request, the host can start uploading data. The device simulator does not include actual files, so data is not written to memory; however, the client keeps track of the CRC of the received data to verify the integrity of the upload.

Erase

If the client receives a request to erase a file, it will check in its directory to see if the file exists and if there is permission to erase that file. As there are no actual files to delete in this example, if the file can be erased, the client will simply send a response to the host indicating the file was erased; otherwise, it will reject the request.

Development phase configuration options

The ANT-FS client device simulator will trace out ANT-FS protocol state information to UART when AN-FS protocol events occur. The UART peripheral can be configured in simple_uart.c file.

The following compile time configuration options are available to assist in the development phase of the ANT-FS client implementation:

Macro Definition Documentation

#define ANTFS_VERSION_MAJOR   1u

Version major number.

#define ANTFS_VERSION_MINOR   0

Version minor number.

#define ANTFS_VERSION_ITERATION   0

Version iteration.

#define ANTFS_VERSION_TYPE   'R'

Version type is release.

#define ANTFS_VERSION_SPEC   '0.AK'

Version of the ANT-FS Technology Specification.

#define ANTFS_DIR_STRUCT_VERSION   1u

Version of the directory file structure.

#define ANTFS_VERSION_DATE   20090522u

Version date.

#define ANTFS_NETWORK_NUMBER   0

ANT-FS Network Number.

#define ANTFS_CHANNEL   0

ANT Channel Number.

#define ANTFS_LINK_FREQ   50u

RF Frequency (+2400MHz).

#define ANTFS_PAIRING_TIMEOUT   120u

Pairing timeout (time the UI will wait for a response to the pairing request before switching to the link layer, in seconds).

#define ANTFS_LINK_COMMAND_TIMEOUT   10u

Command timeout (time the client will wait without receiving any commands before switching to the link layer, in seconds).

#define ANTFS_TRANS_TYPE   5u

ANT-FS Transmission Type.

#define ANTFS_DEVICE_TYPE   1u

ANT-FS Device Type.

#define ANTFS_CHANNEL_TYPE   CHANNEL_TYPE_MASTER

ANT-FS Client Channel Type.

#define ANTFS_BEACON_PERIOD_STATUS   BEACON_PERIOD_4_HZ

ANT-FS Beacon Message Period.

#define ANTFS_TRANSMIT_POWER   3u

ANT Transmit Power (0dBm).

#define ANTFS_AUTH_STRING_MAX   255u

Maximum size of authentication strings (passkey/friendly name).

#define ANTFS_PASSKEY_SIZE   16u

Passkey size.

#define ANTFS_FRIENDLY_NAME_MAX   16u

Maximum size of friendly name received from host.

#define ANTFS_REMOTE_FRIENDLY_NAME_MAX   16u

Maximum size of client's friendly name.

#define BEACON_PERIOD_SHIFT   0x00

Shift value for masking out beacon period.

#define BEACON_PERIOD_MASK   (0x07u << BEACON_PERIOD_SHIFT)

Beacon period bitmask.

#define BEACON_PERIOD_0_5_HZ   (0x00 << BEACON_PERIOD_SHIFT)

Value for 0,5Hz beacon period.

#define BEACON_PERIOD_1_HZ   (0x01u << BEACON_PERIOD_SHIFT)

Value for 1Hz beacon period.

#define BEACON_PERIOD_2_HZ   (0x02u << BEACON_PERIOD_SHIFT)

Value for 2Hz beacon period.

#define BEACON_PERIOD_4_HZ   (0x03u << BEACON_PERIOD_SHIFT)

Value for 4Hz beacon period.

#define BEACON_PERIOD_8_HZ   (0x04u << BEACON_PERIOD_SHIFT)

Value for 8Hz beacon period.

#define PAIRING_AVAILABLE_FLAG_SHIFT   0x03u

Shift value for masking out pairing enabled bit.

#define PAIRING_AVAILABLE_FLAG_MASK   (0x01u << PAIRING_AVAILABLE_FLAG_SHIFT)

Pairing enabled bitmask.

#define UPLOAD_ENABLED_FLAG_SHIFT   0x04u

Shift value for masking out upload enabled bit.

#define UPLOAD_ENABLED_FLAG_MASK   (0x01u << UPLOAD_ENABLED_FLAG_SHIFT)

Upload enabled bitmask.

#define DATA_AVAILABLE_FLAG_SHIFT   0x05u

Shift value for masking out data available bit.

#define DATA_AVAILABLE_FLAG_MASK   (0x01u << DATA_AVAILABLE_FLAG_SHIFT)

Data available bitmask.

#define ANTFS_PAIRING_BIT   0x00u

Build pairing disabled default beacon setting.

#define ANTFS_UPLOAD_BIT   0x00u

Build upload disabled default beacon setting.

Define the default beacon setting.

#define RESPONSE_MESSAGE_OK   0x00u

Download request ok.

#define RESPONSE_MESSAGE_NOT_EXIST   0x01u

File does not exist.

#define RESPONSE_MESSAGE_NOT_AVAILABLE   0x02u

File can not be read/written to (download/upload respectively).

#define RESPONSE_MESSAGE_NOT_READY   0x03u

Not ready to download.

#define RESPONSE_INVALID_OPERATION   0x04u

Request invalid.

#define RESPONSE_INVALID_CRC   0x05u

CRC incorrect.

#define RESPONSE_MESSAGE_NOT_ENOUGH_SPACE   0x03u

Not enough space to to complete write.

#define RESPONSE_MESSAGE_FAIL   0x01u

Data File Index does not exist / Erase failed.

#define ANTFS_DIR_READ_MASK   0x80u

Read (can download).

#define ANTFS_DIR_WRITE_MASK   0x40u

Write (can upload).

#define ANTFS_DIR_ERASE_MASK   0x20u

Erase (can erase).

#define ANTFS_DIR_ARCHIVE_MASK   0x10u

Archive (has been downloaded).

#define ANTFS_DIR_APPEND_MASK   0x08u

Append (can append to file only).

#define ANTFS_MAX_FILE_SIZE   0xFFFFFFFFu

Maximum file size, as specified by directory structure.

#define ANTFS_BURST_BLOCK_SIZE   20u

Size of each block of burst data that the client attempts to send when it processes a data request event.

#define MAX_ULONG   0xFFFFFFFFu

The Max value for the type.

#define APP_TIMER_PRESCALER   0

Value of the RTC1 PRESCALER register.

#define ANT_EVENT_MSG_BUFFER_MIN_SIZE   32u

Minimum size of ANT event message buffer.

#define ANTFS_CLIENT_SERIAL_NUMBER   0xABCDEF12u

Serial number of client device.

#define ANTFS_CLIENT_DEV_TYPE   416u

Beacon device type.

#define ANTFS_CLIENT_MANUF_ID   2u

Beacon manufacturer ID.

#define ANTFS_CLIENT_NAME   { "Ref Design" }

Client's friendly name.

#define ANTFS_CLIENT_PASSKEY   {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10}

Client passkey.

#define APP_TIMER_MAX_TIMERS   2u

Maximum number of simultaneously created timers.

#define APP_TIMER_OP_QUEUE_SIZE   4u

Size of timer operation queues.

#define APP_GPIOTE_MAX_USERS   1u

Maximum number of users of the GPIOTE handler.

#define BUTTON_DETECTION_DELAY   APP_TIMER_TICKS(50u, APP_TIMER_PRESCALER)

Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks).

Enumeration Type Documentation

Enumerator
ANTFS_STATE_OFF 

Off state.

ANTFS_STATE_INIT 

Init state.

ANTFS_STATE_LINK 

Link state.

ANTFS_STATE_AUTH 

Authenticate state.

ANTFS_STATE_TRANS 

Transport state.

ANTFS_STATE_OFF 

Off state.

ANTFS_STATE_INIT 

Init state.

ANTFS_STATE_LINK 

Link state.

ANTFS_STATE_AUTH 

Authenticate state.

ANTFS_STATE_TRANS 

Transport state.

Enumerator
ANTFS_LINK_SUBSTATE_NONE 

None state.

ANTFS_LINK_SUBSTATE_NONE 

None state.

Enumerator
ANTFS_AUTH_SUBSTATE_NONE 

None state.

ANTFS_AUTH_SUBSTATE_PAIR 

Pairing state.

ANTFS_AUTH_SUBSTATE_PASSKEY 

Passkey state.

ANTFS_AUTH_SUBSTATE_ACCEPT 

Authenticate accept state.

ANTFS_AUTH_SUBSTATE_REJECT 

Authenticate reject state.

ANTFS_AUTH_SUBSTATE_NONE 

None state.

ANTFS_AUTH_SUBSTATE_PAIR 

Pairing state.

ANTFS_AUTH_SUBSTATE_PASSKEY 

Passkey state.

ANTFS_AUTH_SUBSTATE_ACCEPT 

Authenticate accept state.

ANTFS_AUTH_SUBSTATE_REJECT 

Authenticate reject state.

Enumerator
ANTFS_TRANS_SUBSTATE_NONE 

None state.

ANTFS_TRANS_SUBSTATE_VERIFY_CRC 

Verify CRC state.

ANTFS_TRANS_SUBSTATE_DOWNLOADING 

Downloading state.

ANTFS_TRANS_SUBSTATE_UPLOAD_WAIT_FOR_DATA 

Wait for upload data request state.

ANTFS_TRANS_SUBSTATE_UPLOADING 

Ready / receiving upload data state.

ANTFS_TRANS_SUBSTATE_UPLOAD_RESUME 

RX failure upon receiving upload data state.

ANTFS_TRANS_SUBSTATE_NONE 

None state.

ANTFS_TRANS_SUBSTATE_VERIFY_CRC 

Verify CRC state.

ANTFS_TRANS_SUBSTATE_DOWNLOADING 

Downloading state.

ANTFS_TRANS_SUBSTATE_UPLOAD_WAIT_FOR_DATA 

Wait for upload data request state.

ANTFS_TRANS_SUBSTATE_UPLOADING 

Ready / receiving upload data state.

ANTFS_TRANS_SUBSTATE_UPLOAD_RESUME 

RX failure upon receiving upload data state.

Enumerator
ANTFS_EVENT_PAIRING_REQUEST 

Pairing request event.

ANTFS_EVENT_PAIRING_TIMEOUT 

Pairing timeout event.

ANTFS_EVENT_OPEN_COMPLETE 

Channel setup complete event.

ANTFS_EVENT_CLOSE_COMPLETE 

Channel closed event.

ANTFS_EVENT_LINK 

Enter link layer event.

ANTFS_EVENT_AUTH 

Enter authenticate layer event.

ANTFS_EVENT_TRANS 

Enter transport layer event.

ANTFS_EVENT_DOWNLOAD_REQUEST 

Download request event.

ANTFS_EVENT_DOWNLOAD_REQUEST_DATA 

Download request data event.

ANTFS_EVENT_DOWNLOAD_START 

Download started event.

ANTFS_EVENT_DOWNLOAD_COMPLETE 

Download completed event.

ANTFS_EVENT_DOWNLOAD_FAIL 

Download failed event.

ANTFS_EVENT_UPLOAD_REQUEST 

Upload request event.

ANTFS_EVENT_UPLOAD_DATA 

Upload data available for read event.

ANTFS_EVENT_UPLOAD_START 

Upload begin event.

ANTFS_EVENT_UPLOAD_COMPLETE 

Upload completed event.

ANTFS_EVENT_UPLOAD_FAIL 

Upload process failed event.

ANTFS_EVENT_ERASE_REQUEST 

Erase request event.

ANTFS_EVENT_PAIRING_REQUEST 

Pairing request event.

ANTFS_EVENT_PAIRING_TIMEOUT 

Pairing timeout event.

ANTFS_EVENT_OPEN_COMPLETE 

Channel setup complete event.

ANTFS_EVENT_CLOSE_COMPLETE 

Channel closed event.

ANTFS_EVENT_LINK 

Enter link layer event.

ANTFS_EVENT_AUTH 

Enter authenticate layer event.

ANTFS_EVENT_TRANS 

Enter transport layer event.

ANTFS_EVENT_DOWNLOAD_REQUEST 

Download request event.

ANTFS_EVENT_DOWNLOAD_REQUEST_DATA 

Download request data event.

ANTFS_EVENT_DOWNLOAD_START 

Download started event.

ANTFS_EVENT_DOWNLOAD_COMPLETE 

Download completed event.

ANTFS_EVENT_DOWNLOAD_FAIL 

Download failed event.

ANTFS_EVENT_UPLOAD_REQUEST 

Upload request event.

ANTFS_EVENT_UPLOAD_DATA 

Upload data available for read event.

ANTFS_EVENT_UPLOAD_START 

Upload begin event.

ANTFS_EVENT_UPLOAD_COMPLETE 

Upload completed event.

ANTFS_EVENT_UPLOAD_FAIL 

Upload process failed event.

ANTFS_EVENT_ERASE_REQUEST 

Erase request event.

Enumerator
LED_ID_0 

Led 0 ID.

LED_ID_1 

Led 1 ID.

LED_ID_0 

Led 0 ID.

LED_ID_1 

Led 1 ID.

Enumerator
PAIRING_OFF 

Pairing state not active.

PAIRING_ACCEPT 

Pairing accept.

PAIRING_DENY 

Pairing deny.

PAIRING_OFF 

Pairing state not active.

PAIRING_ACCEPT 

Pairing accept.

PAIRING_DENY 

Pairing deny.

Function Documentation

void antfs_init ( const antfs_params_t *const  p_params)
Parameters
[in]p_paramsThe initial ANT-FS configuration parameters.
const char* antfs_hostname_get ( void  )
Returns
Pointer to host name buffer if a host name was recieved, NULL otherwise.
bool antfs_pairing_resp_transmit ( bool  accept)
Parameters
[in]acceptThe pairing response, true if pairing accepted.
Return values
trueOperation success. Response to a pairing request was transmitted.
falseOperation failure. Not in pairing mode or pairing not supported by the implementation.
void antfs_download_req_resp_prepare ( uint8_t  response,
const antfs_request_info_t *const  p_request_info 
)

Function does the necessary pre processing calculations, which are required prior downloading the data, and also transmits the download request response right away in case of the download request was rejected or there is no data to send.

Parameters
[in]responseThe download request response code.
[in]p_request_infoANT-FS request info structure.
uint32_t antfs_input_data_download ( uint16_t  index,
uint32_t  offset,
uint32_t  num_bytes,
const uint8_t *const  p_message 
)
Parameters
[in]indexIndex of the current file downloaded.
[in]offsetOffset specified by client.
[in]num_bytesNumber of bytes requested to be transmitted from the buffer.
[in]p_messageData buffer to be transmitted.
Returns
Number of data bytes transmitted.
bool antfs_upload_req_resp_transmit ( uint8_t  response,
const antfs_request_info_t *const  p_request_info 
)
Parameters
[in]responseThe upload response code.
[in]p_request_infoANT-FS request info structure.
Return values
trueOperation success. Response to upload request command was transmitted.
falseOperation failure. Upload not supported by the implementation or not in correct state or application is sending a response for a different file than requested.
bool antfs_upload_data_resp_transmit ( bool  data_upload_success)
Parameters
[in]data_upload_successThe upload response code, true for success.
Return values
trueOperation success. Response to upload data command was transmitted.
falseOperation failure. Upload not supported by the implementation or not in correct state.
void antfs_erase_req_resp_transmit ( uint8_t  response)
Parameters
[in]responseThe erase response code.
bool antfs_event_extract ( antfs_event_return_t *const  p_event)
Parameters
[out]p_eventThe output event structure.
Return values
trueOperation success. Pending ANT-FS event available and it was copied to the output event structure.
falseOperation failure. No pending ANT-FS event available.
void antfs_message_process ( uint8_t *  p_message)
Parameters
[in]p_messageThe message buffer containing the message received from the ANT-FS channel.
uint16_t crc_crc16_update ( uint16_t  current_crc,
const volatile void *  p_data,
uint32_t  size 
)

Feed each consecutive data block into this function, along with the current value of current_crc as returned by the previous call of this function. The first call of this function should pass the initial value (usually 0) of the crc in current_crc.

Parameters
[in]current_crcThe current calculated CRC-16 value.
[in]p_dataThe input data block for computation.
[in]sizeThe size of the input data block in bytes.
Returns
The updated CRC-16 value, based on the input supplied.
void leddriver_led_turn_on ( leddriver_led_id_t  led_id)
Parameters
[in]led_idID of the led to be turned on.
void leddriver_led_turn_off ( leddriver_led_id_t  led_id)
Parameters
[in]led_idID of the led to be turned off.
void leddriver_led_toggle ( leddriver_led_id_t  led_id)
Parameters
[in]led_idID of the led to be toggled.
bool mem_file_write ( uint16_t  index,
uint32_t  offset,
const void *  p_data,
uint32_t  size 
)
Parameters
[in]indexThe file index.
[in]offsetThe write data offset.
[in]p_dataThe data to be written.
[in]sizeThe number of bytes to be written.
Return values
trueOperation success.
trueOperation failure.
void mem_file_read ( uint16_t  index,
uint32_t  offset,
void *  p_data,
uint32_t  size 
)
Parameters
[in]indexThe file index, 0 for directory.
[in]offsetThe read data offset.
[out]p_dataThe buffer where data is read.
[in]sizeThe number of bytes to read.
bool mem_file_erase ( uint16_t  index)
Parameters
[in]indexThe file index.
Return values
trueOperation success.
trueOperation failure.
bool mem_file_info_get ( uint16_t  index,
antfs_dir_struct_t p_file_info 
)
Parameters
[in]indexThe file index, which information to retrieve.
[out]p_file_infoThe container where information is read.
Return values
trueOperation success.
trueOperation failure.
void softdevice_assert_callback ( uint32_t  pc,
uint16_t  line_num,
const uint8_t *  p_file_name 
)

Traces out the user supplied parameters and busy loops.

Parameters
[in]pcValue of the program counter.
[in]line_numLine number where the assert occurred.
[in]p_file_namePointer to the file name.
void app_error_handler ( uint32_t  error_code,
uint32_t  line_num,
const uint8_t *  p_file_name 
)

Function for error handling, which is called when an error has occurred.

Parameters
[in]error_codeError code supplied to the handler.
[in]line_numLine number where the error occurred.
[in]p_file_namePointer to the file name.
void PROTOCOL_EVENT_IRQHandler ( void  )

Interrupt is generated by the ANT stack upon sending event to the application.

static void event_download_request_handle ( const antfs_event_return_t p_event)
static
Parameters
[in]p_eventThe event extracted from the queue to be processed.
static void event_download_data_handle ( const antfs_event_return_t p_event)
static
Parameters
[in]p_eventThe event extracted from the queue to be processed.
static void event_upload_request_handle ( const antfs_event_return_t p_event)
static
Parameters
[in]p_eventThe event extracted from the queue to be processed.
static void event_upload_data_handle ( const antfs_event_return_t p_event)
static
Parameters
[in]p_eventThe event extracted from the queue to be processed.
static void event_erase_request_handle ( const antfs_event_return_t p_event)
static
Parameters
[in]p_eventThe event extracted from the queue to be processed.
static void antfs_event_process ( const antfs_event_return_t p_event)
static
Parameters
[in]p_eventThe event extracted from the queue to be processed.
void button_event_handle ( uint8_t  pin_no)

Provides the user input regarding pairing request to the ANT-FS module.

Parameters
[in]pin_noThe pin number of the button pressed.

Variable Documentation

const uint8_t m_friendly_name[] = ANTFS_CLIENT_NAME
static

Client's friendly name.

const uint8_t m_pass_key[] = ANTFS_CLIENT_PASSKEY
static

Authentication string (passkey).

antfs_event_return_t m_antfs_event
static

ANTFS event queue element.

antfs_dir_struct_t m_temp_dir_structure
static

Current directory file structure.

antfs_request_info_t m_response_info
static

Parameters for response to a download and upload request.

uint16_t m_file_index
static

Index of the current file downloaded/uploaded.

uint32_t m_file_offset
static

Current offset.

uint16_t m_current_crc
static

Current CRC.

bool m_upload_success
static

Upload response.

volatile pairing_state_t m_pairing_state
static

Pairing state.