[[ANT]]

* What is BCA_Lib? [#c8ccebc6]

>
“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>http://labs.beatcraft.com/en/index.php?ANT%2FBC-ANT-USB]] of BC::labs.

>
The class reference of BCA_lib is published on [[this page>http://labs.beatcraft.com/ja/BCA_Lib/html/index.html]].~ 
The class reference of BCA_lib is published on [[this page>http://labs.beatcraft.com/ja/BCA_Lib/html/index.html]].~

>
[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 [#r97f1b06]
>
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
- [[Callback I/F>http://labs.beatcraft.com/ja/BCA_Lib/html/_ant_callback_interface_8h.html]] (Interface)~
- [[C++ class I/F>http://labs.beatcraft.com/ja/BCA_Lib/html/class_ant_device.html]] (Interface)~
There are two types of I/Fs. You may use either one of two I/Fs.~

* Files [#g3b17237]
>
[Caution]~
To use this library, 5 files listed below and the driver for BC-ANT-USB are required.~

>
- [[AntCallbackInterface.h>http://labs.beatcraft.com/ja/BCA_Lib/html/_ant_callback_interface_8h_source.html]]: Callback interface header file.
- [[AntDevice.h>>http://labs.beatcraft.com/ja/BCA_Lib/html/_ant_device_8h_source.html]]: 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.
- &ref(BCA_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 [#g7223d38]
>
- 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 [#k869809c]
>
- 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 [#z55c3cda]
>
''[Transmitting side]''~
>>
|Channel Number| 0|
|Channel Type|0 (MASTER)|
|Shared Channel|0|
|Device Number|33|
|Device Type|1|
|Transmission Type|1|
|Frequency: 66 (2466MHz|Since 2466-2400 =66)|
|Channel Period|4Hz|

>
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 Number| 0|
|Channel Type| 0 (MASTER)|
|Shared Channel| 0|
|Device Number| 33|
|Device Type| 1|
|Transmission Type| 0 (Wildcard)|
|Frequency| 66 (2466MHz: Since 2466-2400 =66)|
|Channel Period| 4Hz|

>
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 [#saf1d856]
>
- Pairing is a way to establish a communication between two devices, specifically.~

>
''[Transmitting#1]''~
>>
|Channel Number| 0|
|Channel Type| 0 (MASTER)|
|Device Number| 1234|
|Frequency| 66 (2466MHz: Since 2466-2400 =66)|
|Channel Period| 4Hz|

>
''[Transmitting#2]''~
>>
|Channel Number| 0|
|Channel Type| 0 (MASTER)|
|Device Number| 5678|
|Frequency| 66 (2466MHz: Since 2466-2400 =66)|
|Channel Period| 4Hz|

>
''[Receiving]''~
>>
|Channel Number| 0|
|Channel Type|1 (SLAVE)|
|Device Number|0|
|Frequency| 66 (2466MHz: Since 2466-2400 =66)|
|Channel Period| 4Hz|

>
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()>http://labs.beatcraft.com/ja/BCA_Lib/html/_ant_callback_interface_8h.html#a0eaf75610fbbff7d3619dac50de70089]]) callback function is executed after the pairing process ([[BCA_StartPairing()>http://labs.beatcraft.com/ja/BCA_Lib/html/_ant_callback_interface_8h.html#a046465627184919fdf304a5445394a63]]) 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()>http://labs.beatcraft.com/ja/BCA_Lib/html/_ant_callback_interface_8h.html#acaf7b785223ac134556d28de451ecf8e]]).~

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

**Reference [#p90ce375]
>
- [[Function Reference (C++ I/F)>http://labs.beatcraft.com/ja/BCA_Lib/html/class_ant_device.html]]
- [[Function Reference (callback I/F)>http://labs.beatcraft.com/ja/BCA_Lib/html/_ant_callback_interface_8h.html]]

* Shared Channel [#w329e6d6]
** About Shared Channel [#jb87d670]

>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.~
&ref(diag1.jpg,,80%);~

>
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.~
&ref(diag2.jpg,,80%);~

>
An example of transmitting data~
&ref(diag3.jpg,,80%);~

>
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~
&ref(diag4.jpg,,80%);~

** Example of Configuration [#x3f5be0a]
>
''[Configuration of Node A]''~
>>
|Channel Number| 0|
|Channel Type|  BCA_CHANNEL_TYPE_MASTER|
|Shared Channel| BCA_CHANNEL_SHARED|
|Device Number| 33 (the serial number of node A)|
|Device Type| 3 (the device type of node A)|
|Transmission Type| 3 (2bytes of shared channel address)|
|Frequency| 66 (2466MHz: Since 2466-2400 =66)|
|Channel Period| 4Hz|

>
''[Configuration of Node B, C, and D]''~
>>
|Channel Number|0|
|Channel Type|  BCA_CHANNEL_TYPE_SLAVE|
|Shared Channel|BCA_CHANNEL_SHARED|
|Device Number| 33 (the serial number of node A)|
|Device Type| 3 (the device type of node A)|
|Transmission Type|3 (2bytes of shared channel address)|
|Frequency| 66 (2466MHz: Since 2466-2400 =66)|
|Channel Period| 4Hz|

>
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 [#b186a823]
>
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 [#i1b14c4d]
>
- &ref(SendCB.zip);: Sample code for sending
- &ref(RecvCB.zip);: Sample code for receiving
- &ref(PairingCB.zip);: Sample code for pairing (receiving only)

** Python Examples [#pafd1f9e]
>
- &ref(BCA_send.py);: Sample code for sending
- &ref(BCA_recv.py);: Sample code for receiving
- &ref(BCA_pairing.py);: Sample code for pairing (receiving only)

** Whole files, BCA_lib, and HTML document [#f0e5cda7]
>
- &ref(BCA_Lib.zip);~

* Revision History [#bbddba0e]
>
- 2013/02/01 This article is initially uploaded~

Front page   Edit Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   RSS of recent changes