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.

Features of BCA_Lib

The major features of this library are listed below.

The features of API are

Files

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

Definitions

About Communication

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

[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


Front page   New List of pages Search Recent changes   RSS of recent changes