ANT

What is BCA_Lib?

“BCA_Lib” is a library, which uses with BC-ANT-USB. This library makes the configuration of ANT communication simple. For more information of ANT protocol, please look at ANT's community page, “thisisant.com.” The details of BC-ANT-USB is listed on ANT/BC-ANT-USB of BC::labs.

The class reference of BCA_lib is published on this page.

[Caution!]
BCA_Lib is created for ANT devices such as BC-ANT-USB, and it can NOT be used with any ANT+ devices.

Features of BCA_Lib

The major features of this library are listed below.

  • Open/close ANT devices
  • Receive data/events
  • Transmit data
  • Pairing process
  • The size of transmitting and receiving data is 8byte

The features of API are

Files

[Caution]
To use this library, 5 files listed below and the driver for BC-ANT-USB are required.

  • AntCallbackInterface.h: Callback interface header file.
  • AntDevice.h>: C++ class interface header file.
  • BCA_Lib.dll: The whole library
  • BCA_Lib.lib: Import library
  • bc_abstract.dll: A support library developed by BeatCraft, Inc.
  • fileBCA_Lib.zip: The details of BCA_Lib (written in HTML format), BC-ANT-USB driver, and sample programs. The details of contents are listed below
    • bin: this contains bc_abstract.dll, BCA_Lib.dll, and BCA_Lib.lib. The details are shown above.
    • driver: BC-ANT-USB driver
    • html: A HTML formatted document, which explains the details of BCA_Lib. (To read this document, please click index.html)
    • include: ANTCallbackInterface.h, AntDecice.h, and BCA_Lib.h
    • python_sample: Python sample programs, which handle transmitting, receiving, and pairing (receiving side only)
    • sample: C++ sample programs, which manage transmitting, receiving, and pairing (receiving side only)

Definitions

  • Chanel Type:
    Specify the transmitter (sender) as MASTER and receiver as SLAVE
  • Channel Number:
    8 channels of ANT communications are available at an ANT device
  • Share Channel:
    It defines whether Shared Cannel is applied or not.
    The details of Shared Channel are explained in the later section.
  • Device Number:
    This is a value, which is unique to a specific device. (It can be the serial number of a device). The cause of wildcard, which specifies this number as 0, cannot be applicable to a MASTER (transmitting, or sending) device.
  • Device Type:
    This value defines device type. Select a number form 1 to 127. 0 can be used as wildcard. However, wildcard cannot apply to a MASTER (transmitter or sender) device.
  • Transmission Type:
    This defines characteristics of communication of a device. Specify a number from 1 to 255. Wildcard, 0, can be used for only SLAVE (receiver) devices.
  • Frequency:
    2.4GHz band is used.
    API defined a frequency own formula.~ Please input the number, which is determined by subtracting 2400 from the selected Mega frequency (MHz). i.e. 2466MHz is the selected frequency, the input number is 66 since 66 = 2466-2600.
  • Channel Period
    The intervals between sending or receiving data is 0.5Hz ~ 32768Hz

About Communication

  • The values of Channel ID (device number, device type, and trans mission type) and frequency must be identical between transmitting and receiving devices as they establish ANT communication. (In some case, receiving devices may select wildcard.)
  • If wildcard is selected, the receiving channel receives only the data from the transmitting device that the channel has been established and pared with first.

Example of Configuration

[Transmitting side]

Channel Number0
Channel Type0 (MASTER)
Shared Channel0
Device Number33
Device Type1
Transmission Type1
Frequency: 66 (2466MHzSince 2466-2400 =66)
Channel Period4Hz

Example code (transmitting data): this uses the callback interface.

main() {
    //  Opening an ANT device
    dev = BCA_OpenDevice(0);
    //  Initializing the ANT device
    res = BCA_Init(dev);
    //  Registering the transmitting callback function
    BCA_RegisterSendFunc(dev, SendFunc, NULL);
    //  Opening a channel
    res = BCA_OpenChannel(dev,                          //      device context
                      0,                                //      channel no(0)
                      BCA_CHANNEL_TYPE_MASTER,          //      channel type(Master)
                      BCA_CHANNEL_NOSHARED,             //      shared channel
                      33,                               //      device no
                      1,                                //      device type
                      1,                                //      trans typs
                      66,                               //      freq 2466Hz = 2400 + 66
                      4);                               //      hz
    // 
    //  Transmitting...
    // 
    //  Closing the channel
    BCA_CloseChannel(dev, 0); 
    //  Closing the device
    BCA_CloseDevice(dev);
}
/////////////////////////////////////////////////////////////////
//      Transmitting Callback Function
/////////////////////////////////////////////////////////////////
void SendFunc(void* cookie, int channel, void* cookie)
{
        static unsigned char val = 0;
        unsigned char dat[8];
        memset(dat, val,8);
        val++;
        //      Processing transmission
        //      Data is fixed at 8bytes.
        BCA_SendData(dev, channel, dat, 8);
}

[Receiving side]

Channel Number0
Channel Type0 (MASTER)
Shared Channel0
Device Number33
Device Type1
Transmission Type0 (Wildcard)
Frequency66 (2466MHz: Since 2466-2400 =66)
Channel Period4Hz

Example code (receiving data)

main() {
    //  Opening an ANT device
    dev = BCA_OpenDevice();
    //  Initializing the ANT device
    res = BCA_Init(dev);
    //  Registering the receiving callback function
    BCA_RegisterReceiveFunc(dev,ReceiveFunc, NULL);
    //  Opening a channel
    res = BCA_OpenChannel(dev,
                          0,                                    //      channel
                          BCA_CHANNEL_TYPE_SLAVE,               //      slave
                          BCA_CHANNEL_NOSHARED,                 //      shared channel
                          0,                                    //      device no
                          0,                                    //      device type
                          0,                                    //      tarans type
                          66,                                   //      freq
                          4);                                   //      Hz
    //
    //  Receiving...
    //
    //  Closing the channel
    BCA_CloseChannel(dev, 0); 
    //  Closing the device
    BCA_CloseDevice(dev);
}
/////////////////////////////////////////////////////////////////
//      Receiving Callback Function
/////////////////////////////////////////////////////////////////
void ReceiveFunc(void* cookie, int channel, unsigned char evnt, void* data, unsigned int length, void* cookie)
{
        unsigned char* dat = (unsigned char*)data;
        printf("DATA[%x][%d][%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x]\n",
                        evnt,
                        channel,
                        dat[0],
                        dat[1],
                        dat[2],
                        dat[3],
                        dat[4],
                        dat[5],
                        dat[6],
                        dat[7]);
}

About Pairing

  • Pairing is a way to establish a communication between two devices, specifically.

[Transmitting#1]

Channel Number0
Channel Type0 (MASTER)
Device Number1234
Frequency66 (2466MHz: Since 2466-2400 =66)
Channel Period4Hz

[Transmitting#2]

Channel Number0
Channel Type0 (MASTER)
Device Number5678
Frequency66 (2466MHz: Since 2466-2400 =66)
Channel Period4Hz

[Receiving]

Channel Number0
Channel Type1 (SLAVE)
Device Number0
Frequency66 (2466MHz: Since 2466-2400 =66)
Channel Period4Hz

Example Code

main() {
    //  Opening an ANT device
    dev = BCA_OpenDevice(0);
    //  Initializing the ANT device
    res = BCA_Init(dev);
    //  Registering the pairing callback function
    BCA_RegisterPairingFunc(dev,PairingFunc, NULL);
    //  Registering the receiving callback function
    BCA_RegisterReceiveFunc(dev,ReceiveFunc, NULL);
    //  Starting the pairing process
    res = BCA_StartPairing(dev,
                           66, // freq
                           4,  // Hz
                           10);// Duration of search time of pairing (Sec.)
    //
    //  Process...
    //
    //  Closing the channel
    BCA_CloseChannel(dev, 0); 
    //  Closing the device 
    BCA_CloseDevice(dev);
}
/////////////////////////////////////////////////////////////////
//      Pairing Callback Function;
/////////////////////////////////////////////////////////////////
void PairingFunc(void* cookie, int* device, unsigned char count, void* cookie)
{
    if (count <= 0) {
        //  There are no devices
        return;
    }
    int device_no = 0;
    int device_type = 0;
    int trans_type = 0;
    int res = 0;
    //  Connecting the first device to find
    //  Obtaining the information of the device
    res = BCA_GetPairingDeviceInfo(dev, 0, &device_no, &device_type, &trans_type);
    //  Opening the channel
    res = BCA_OpenChannel(dev,
                          0,                            //  channel no
                          BCA_CHANNEL_TYPE_SLAVE,       //  SLAVE
                          BCA_CHANNEL_NOSHARED,         //  no shared
                          device_no,                    //  device no
                          device_type,                  //  device type
                          trans_type,                   //  trans type
                          66,                           //  2466MHz
                          4);                           //  4Hz
}

The registered (BCA_RegisterPairingFunc()) callback function is executed after the pairing process (BCA_StartPairing()) has been executed and the selected duration of time has passed. The channel information, such as Device ID, of a newly found device is handed over to the function.
As the device, which you like to connect, is selected from the application of UI, the channel is opened (BCA_OpenChannel()).

The device search is performed by all 8 channels, so 8 devices would be found at most.

Reference

Shared Channel

About Shared Channel

The common connection types of ANT network are 1-to-1 or broadcast connection.

Excluding broadcast, as a master connects to multiple slaves, the master needs to connect to each slave, independently.
diag1.jpg

Shard Channel is a way that a single master connects to multiple slaves in one channel.
In Shared Channel, specific shared addresses are configured to all slaves. To add a shared address to a slave, the address consumes 2 bytes, and the total amount of data, which can be sent in one transmission, is reduced to 6 bytes.
diag2.jpg

An example of transmitting data
diag3.jpg

To send data, which includes a specific shared address from a mater, a node, which corresponds to a specific shared address that each slave has sent to the master, receives the data.
As the nodes start receiving the data, the nodes send back data, whose first 2bytes include own shared addresses, in broadcast.

Notify shared addresses on a shared channel
diag4.jpg

Example of Configuration

[Configuration of Node A]

Channel Number0
Channel TypeBCA_CHANNEL_TYPE_MASTER
Shared ChannelBCA_CHANNEL_SHARED
Device Number33 (the serial number of node A)
Device Type3 (the device type of node A)
Transmission Type3 (2bytes of shared channel address)
Frequency66 (2466MHz: Since 2466-2400 =66)
Channel Period4Hz

[Configuration of Node B, C, and D]

Channel Number0
Channel TypeBCA_CHANNEL_TYPE_SLAVE
Shared ChannelBCA_CHANNEL_SHARED
Device Number33 (the serial number of node A)
Device Type3 (the device type of node A)
Transmission Type3 (2bytes of shared channel address)
Frequency66 (2466MHz: Since 2466-2400 =66)
Channel Period4Hz

As the slaves (node B, C, and D) has completed opening own channels, they add own shared addresses to the first 2bytes of the data and send back the data in broadcast. Since now on, slaves reply as sending back the data which includes shared addresses at its first 2 bytes. Otherwise, the information of the configured shared address is void.

Sample Code

There are sets of sample code for transmitting, receiving, and pairing (receiving only). One is for C++, and the other is for Python.

C++ Samples

Python Examples

Whole files, BCA_lib, and HTML document

Revision History

  • 2013/02/01 This article is initially uploaded

Attach file: fileBCA_Lib.zip 1382 download [Information] fileBCA_pairing.py 1461 download [Information] fileBCA_recv.py 1405 download [Information] fileBCA_send.py 1397 download [Information] fileRecvCB.zip 1268 download [Information] filePairingCB.zip 1274 download [Information] fileSendCB.zip 1326 download [Information] filediag4.jpg 1659 download [Information] filediag3.jpg 1704 download [Information] filediag2.jpg 1675 download [Information] filediag1.jpg 1678 download [Information]

Front page   Edit Freeze Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   RSS of recent changes
Last-modified: 2013-03-01 (Fri) 10:40:46 (4075d)