BCA_Lib

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Pages
AntInterface.h
1 #ifndef __BCA_ANTINTERFACE_H__
2 #define __BCA_ANTINTERFACE_H__
3
4 #include "Device.h"
5
6 #define ANT_NETWORK_KEY {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}
7 #define ANT_NETWORK_NUM 0 // 0: 1:ANT FS 2:ANT Plus
8
10 // Assign Channel Parameters
12 #define PARAMETER_RX_NOT_TX ((unsigned char)0x00)
13 #define PARAMETER_TX_NOT_RX ((unsigned char)0x10)
14 #define PARAMETER_SHARED_RX_CHANNEL ((unsigned char)0x20)
15 #define PARAMETER_SHARED_TX_CHANNEL ((unsigned char)0x30)
16 #define PARAMETER_RX_ONLY ((unsigned char)0x40)
17 #define PARAMETER_TX_ONLY ((unsigned char)0x50)
18
19 #define MESG_TX_SYNC ((unsigned char)0xA4)
20 #define MESG_RX_SYNC ((unsigned char)0xA5)
21 #define MESG_SYNC_SIZE ((unsigned char)1)
22 #define MESG_SIZE_SIZE ((unsigned char)1)
23 #define MESG_ID_SIZE ((unsigned char)1)
24 #define MESG_CHANNEL_NUM_SIZE ((unsigned char)1)
25 #define MESG_EXT_MESG_BF_SIZE ((unsigned char)1) // NOTE: this could increase in the future
26 #define MESG_CHECKSUM_SIZE ((unsigned char)1)
27 #define MESG_DATA_SIZE ((unsigned char)9)
28
29 // The largest serial message is an ANT data message with all of the extended fields
30 #define MESG_ANT_MAX_PAYLOAD_SIZE ANT_STANDARD_DATA_PAYLOAD_SIZE
31
32 #define MESG_MAX_EXT_DATA_SIZE (ANT_EXT_MESG_DEVICE_ID_FIELD_SIZE + 4 + 2) // ANT device ID (4 bytes) + (4 bytes) + (2 bytes)
33
34 #define MESG_MAX_DATA_SIZE (MESG_ANT_MAX_PAYLOAD_SIZE + MESG_EXT_MESG_BF_SIZE + MESG_MAX_EXT_DATA_SIZE) // ANT data payload (8 bytes) + extended bitfield (1 byte) + extended data (10 bytes)
35 #define MESG_MAX_SIZE_VALUE (MESG_MAX_DATA_SIZE + MESG_CHANNEL_NUM_SIZE) // this is the maximum value that the serial message size value is allowed to be
36 #define MESG_BUFFER_SIZE (MESG_SIZE_SIZE + MESG_ID_SIZE + MESG_CHANNEL_NUM_SIZE + MESG_MAX_DATA_SIZE + MESG_CHECKSUM_SIZE)
37 #define MESG_FRAMED_SIZE (MESG_ID_SIZE + MESG_CHANNEL_NUM_SIZE + MESG_MAX_DATA_SIZE)
38 #define MESG_HEADER_SIZE (MESG_SYNC_SIZE + MESG_SIZE_SIZE + MESG_ID_SIZE)
39 #define MESG_FRAME_SIZE (MESG_HEADER_SIZE + MESG_CHECKSUM_SIZE)
40 #define MESG_MAX_SIZE (MESG_MAX_DATA_SIZE + MESG_FRAME_SIZE)
41
42 #define MESG_SIZE_OFFSET (MESG_SYNC_SIZE)
43 #define MESG_ID_OFFSET (MESG_SYNC_SIZE + MESG_SIZE_SIZE)
44 #define MESG_DATA_OFFSET (MESG_HEADER_SIZE)
45 #define MESG_RECOMMENDED_BUFFER_SIZE ((unsigned char) 64) // This is the recommended size for serial message buffers if there are no RAM restrictions on the system
46
48 // Message ID's
50 #define MESG_INVALID_ID ((unsigned char)0x00)
51 #define MESG_EVENT_ID ((unsigned char)0x01)
52
53 #define MESG_VERSION_ID ((unsigned char)0x3E)
54 #define MESG_RESPONSE_EVENT_ID ((unsigned char)0x40)
55
56 #define MESG_UNASSIGN_CHANNEL_ID ((unsigned char)0x41)
57 #define MESG_ASSIGN_CHANNEL_ID ((unsigned char)0x42)
58 #define MESG_CHANNEL_MESG_PERIOD_ID ((unsigned char)0x43)
59 #define MESG_CHANNEL_SEARCH_TIMEOUT_ID ((unsigned char)0x44)
60 #define MESG_CHANNEL_RADIO_FREQ_ID ((unsigned char)0x45)
61 #define MESG_NETWORK_KEY_ID ((unsigned char)0x46)
62 #define MESG_RADIO_TX_POWER_ID ((unsigned char)0x47)
63 #define MESG_RADIO_CW_MODE_ID ((unsigned char)0x48)
64 #define MESG_SYSTEM_RESET_ID ((unsigned char)0x4A)
65 #define MESG_OPEN_CHANNEL_ID ((unsigned char)0x4B)
66 #define MESG_CLOSE_CHANNEL_ID ((unsigned char)0x4C)
67 #define MESG_REQUEST_ID ((unsigned char)0x4D)
68
69 #define MESG_BROADCAST_DATA_ID ((unsigned char)0x4E)
70 #define MESG_ACKNOWLEDGED_DATA_ID ((unsigned char)0x4F)
71 #define MESG_BURST_DATA_ID ((unsigned char)0x50)
72
73 #define MESG_CHANNEL_ID_ID ((unsigned char)0x51)
74 #define MESG_CHANNEL_STATUS_ID ((unsigned char)0x52)
75 #define MESG_RADIO_CW_INIT_ID ((unsigned char)0x53)
76 #define MESG_CAPABILITIES_ID ((unsigned char)0x54)
77
78 #define MESG_STACKLIMIT_ID ((unsigned char)0x55)
79
80 #define MESG_SCRIPT_DATA_ID ((unsigned char)0x56)
81 #define MESG_SCRIPT_CMD_ID ((unsigned char)0x57)
82
83 #define MESG_ID_LIST_ADD_ID ((unsigned char)0x59)
84 #define MESG_ID_LIST_CONFIG_ID ((unsigned char)0x5A)
85 #define MESG_OPEN_RX_SCAN_ID ((unsigned char)0x5B)
86
87 #define MESG_CHANNEL_RADIO_TX_POWER_ID ((unsigned char)0x60)
88 #define MESG_GET_SERIAL_NUM_ID ((unsigned char)0x61)
89 #define MESG_GET_TEMP_CAL_ID ((unsigned char)0x62)
90 #define MESG_SET_LP_SEARCH_TIMEOUT_ID ((unsigned char)0x63)
91 #define MESG_SET_TX_SEARCH_ON_NEXT_ID ((unsigned char)0x64)
92 #define MESG_SERIAL_NUM_SET_CHANNEL_ID_ID ((unsigned char)0x65)
93 #define MESG_RX_EXT_MESGS_ENABLE_ID ((unsigned char)0x66)
94 #define MESG_RADIO_CONFIG_ALWAYS_ID ((unsigned char)0x67)
95 #define MESG_ENABLE_LED_FLASH_ID ((unsigned char)0x68)
96 #define MESG_XTAL_ENABLE_ID ((unsigned char)0x6D)
97 #define MESG_STARTUP_MESG_ID ((unsigned char)0x6F)
98 #define MESG_AUTO_FREQ_CONFIG_ID ((unsigned char)0x70)
99 #define MESG_PROX_SEARCH_CONFIG_ID ((unsigned char)0x71)
100
101 #define FLG_DEVICE_INFO ((unsigned char)0x80)
102 #define FLG_RSSI ((unsigned char)0x40)
103
104 /*
105 #define EVENT_RX_BROADCAST ((unsigned char)0x9A) // returned when module receives broadcast data
106 #define EVENT_RX_ACKNOWLEDGED ((unsigned char)0x9B) // returned when module receives acknowledged data
107 #define EVENT_RX_BURST_PACKET ((unsigned char)0x9C) // returned when module receives burst data
108
109 #define EVENT_RX_EXT_BROADCAST ((unsigned char)0x9D) // returned when module receives broadcast data
110 #define EVENT_RX_EXT_ACKNOWLEDGED ((unsigned char)0x9E) // returned when module receives acknowledged data
111 #define EVENT_RX_EXT_BURST_PACKET ((unsigned char)0x9F) // returned when module receives burst data
112
113 #define EVENT_RX_FLAG_BROADCAST ((unsigned char)0xA3) // returned when module receives broadcast data with flag attached
114 #define EVENT_RX_FLAG_ACKNOWLEDGED ((unsigned char)0xA4) // returned when module receives acknowledged data with flag attached
115 #define EVENT_RX_FLAG_BURST_PACKET ((unsigned char)0xA5) // returned when module receives burst data with flag attached
116 */
117 #define ANT_STANDARD_DATA_PAYLOAD_SIZE ((unsigned char)8)
118 #define ANT_EXT_MESG_DEVICE_ID_FIELD_SIZE ((unsigned char)4)
119
120 class AntInterface
121 {
122 public:
123 AntInterface(Device* dev);
124 virtual ~AntInterface(void);
125
126 int ANT_Init();
127 int ANT_Close();
128
129 // config messages
130 int ANT_UnAssginChannel(unsigned char channel_number);
131 int ANT_AssginChannel( unsigned char channel_number,
132 unsigned char channel_type,
133 unsigned char network_number);
134 int ANT_SetChannelId(unsigned char channel_number,
135 unsigned short device_number,
136 unsigned char device_type_id,
137 unsigned char trans_type);
138 int ANT_SetChannelPeriod(unsigned char channel_number,
139 unsigned short messaging_period);
140 int ANT_SetChannelSearchTimeout(unsigned char channel_number,
141 unsigned char search_timeout);
142 int ANT_SetChannelRFFreq(unsigned char channel_number, unsigned char rf_freqency);
143 int ANT_SetNetworkKey(unsigned char network_number, unsigned char key[8]);
144 int ANT_SetTransmitPower(unsigned char tx_power);
145 int ANT_AddChannelID(unsigned char channel_number,
146 unsigned short device_number,
147 unsigned char device_type_id,
148 unsigned char trans_type,
149 unsigned char list_index);
150 int ANT_ConfigList(unsigned char channel_number,
151 unsigned char list_size,
152 unsigned char exclude);
153 int ANT_SetChannelTxPower(unsigned char channel_number,
154 unsigned char tx_power);
155
156 int ANT_SetLowPriorityChannelSearchTimeout(unsigned char channel_number,
157 unsigned char search_timeout);
158
159 int ANT_SetSerialNumChannelID(unsigned char channel_number,
160 unsigned char device_type_id,
161 unsigned char trans_type);
162
163 int ANT_RxExtMessageEnable(bool enable);
164 int ANT_EnableLED(bool enable);
165 // control messages
166 int ANT_ResetSystem();
167 int ANT_OpenChannel(unsigned char channel_number);
168 int ANT_CloseChannel(unsigned char channel_number);
169 int ANT_OpenRxScanMode();
170 int ANT_RequestMessage(unsigned char channel_number, unsigned char message_id);
171 // send
172 int ANT_SendBroadcastData(unsigned char channel_number, unsigned char* data, unsigned char length);
173 int ANT_SendAcknowledgeData(unsigned char channel_number, unsigned char* data, unsigned char length);
174 int ANT_SendBurstTransferPacket(unsigned char channel_number, unsigned char* data, unsigned char length);
175
176 int ANT_LibConfig(unsigned char config);
177
178 int ANT_Nap(int msec);
179
180 private:
181 bool deviceCheck();
182 bool channelCheck(unsigned char channel);
183 void setShortData(unsigned char* dst, unsigned short* src);
184
185 Device* _dev;
186
187 #define DATA_SIZE 16
188 unsigned char _data[DATA_SIZE];
189
190
191 };
192
193 #endif // __BCA_ANTINTERFACE_H__