forked from GoldenCheetah/GoldenCheetah
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANTChannel.h
185 lines (157 loc) · 5.83 KB
/
ANTChannel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright (c) 2009 Mark Rages
* Copyright (c) 2011 Mark Liversedge ([email protected])
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef gc_ANTChannel_h
#define gc_ANTChannel_h
#include "ANT.h"
#include "ANTMessage.h"
#include <QObject>
#define CHANNEL_TYPE_QUICK_SEARCH 0x10 // or'ed with current channel type
/* after fast search, wait for slow search. Otherwise, starting slow
search might postpone the fast search on another channel. */
#define CHANNEL_TYPE_WAITING 0x20
#define CHANNEL_TYPE_PAIR 0x40 // to do an Ant pair
#define MESSAGE_RECEIVED -1
// note: this struct is from quarqd_dist/quarqd/src/generated-headers.h
class ANTChannelInitialisation {
public:
ANTChannelInitialisation() {
initialise();
}
void initialise() {
first_time_crank_torque=
first_time_crank_SRM=
first_time_wheel_torque=
first_time_standard_power=
first_time_torque_support=
first_time_calibration_pass=
first_time_calibration_fail=
first_time_heart_rate=
first_time_speed=
first_time_cadence=
first_time_speed_cadence=
first_time_manufacturer=
first_time_product=
first_time_battery_voltage= true;
}
bool first_time_crank_torque;
bool first_time_crank_SRM;
bool first_time_wheel_torque;
bool first_time_standard_power;
bool first_time_torque_support;
bool first_time_calibration_pass;
bool first_time_calibration_fail;
bool first_time_heart_rate;
bool first_time_speed;
bool first_time_cadence;
bool first_time_speed_cadence;
bool first_time_manufacturer;
bool first_time_product;
bool first_time_battery_voltage;
};
class ANTChannel : public QObject {
private:
Q_OBJECT
ANT *parent;
ANTMessage lastMessage, lastStdPwrMessage;
int dualNullCount, nullCount, stdNullCount;
double last_message_timestamp;
double blanking_timestamp;
int blanked;
char id[10]; // short identifier
bool channel_assigned;
ANTChannelInitialisation mi;
int messages_received; // for signal strength metric
int messages_dropped;
unsigned char rx_burst_data[RX_BURST_DATA_LEN];
int rx_burst_data_index;
unsigned char rx_burst_next_sequence;
void (*rx_burst_disposition)(struct ant_channel *);
void (*tx_ack_disposition)(struct ant_channel *);
// what we got
int manufacturer_id;
int product_id;
int product_version;
public:
enum channeltype {
CHANNEL_TYPE_UNUSED,
CHANNEL_TYPE_HR,
CHANNEL_TYPE_POWER,
CHANNEL_TYPE_SPEED,
CHANNEL_TYPE_CADENCE,
CHANNEL_TYPE_SandC,
CHANNEL_TYPE_QUARQ,
CHANNEL_TYPE_FAST_QUARQ,
CHANNEL_TYPE_FAST_QUARQ_NEW,
CHANNEL_TYPE_GUARD
};
typedef enum channeltype ChannelType;
// Channel Information - to save tedious set/getters made public
int number; // Channel number within Ant chip
int state;
int channel_type;
int device_number;
int channel_type_flags;
int device_id;
bool is_cinqo; // bool
bool is_old_cinqo; // bool, set for cinqo needing separate control channel
bool is_alt; // is alternative channel for power
int search_type;
int srm_offset;
ANTChannel *control_channel;
ANTChannel(int number, ANT *parent);
// What kind of channel
const char *getDescription();
int interpretDescription(char *description);
// channel open/close
void init();
void open(int device_number, int channel_type);
void close();
// handle inbound data
void receiveMessage(unsigned char *message);
void channelEvent(unsigned char *message);
void burstInit();
void burstData(unsigned char *message);
void broadcastEvent(unsigned char *message);
void ackEvent(unsigned char *message);
void channelId(unsigned char *message);
void setChannelID(int device, int id, int txtype);
void setId();
void requestCalibrate();
void attemptTransition(int message_code);
void setTimeout(int seconds);
// telemetry for this channel
double channelValue() { return value; }
double channelValue2() { return value2; }
double value,value2; // used during config, rather than rtData
// search
int isSearching();
// Cinqo support
void sendCinqoError();
void sendCinqoSuccess();
void checkCinqo();
void setAlt(bool value) { is_alt = value; }
signals:
void channelInfo(int number, int device_number, int device_id); // we got a channel info message
void dropInfo(int number, int dropped, int received); // we dropped a packet
void lostInfo(int number); // we lost a connection
void staleInfo(int number); // the connection is stale
void searchTimeout(int number); // search timed out
void searchComplete(int number); // search completed successfully
};
#endif