Skip to content

Commit f32e5fc

Browse files
committed
Implement ChannelIdResponse callback
Used to identify when a wildcard channel has be identified
1 parent 03a8f5a commit f32e5fc

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/BaseClasses/ANTPLUS_BaseProfile.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ void BaseProfile::closeChannel() {
7070
_router->send(cc);
7171
}
7272

73-
void BaseProfile::onChannelEventResponse(ChannelEventResponse& msg)
74-
{
73+
void BaseProfile::onChannelEventResponse(ChannelEventResponse& msg) {
7574
uint8_t event = msg.getCode();
7675
// TODO maybe define an explicit state enum?
7776
switch (event) {
@@ -83,4 +82,10 @@ void BaseProfile::onChannelEventResponse(ChannelEventResponse& msg)
8382
break;
8483
}
8584
_onChannelEvent.call(msg);
85+
}
86+
87+
void BaseProfile::onChannelIdResponse(ChannelIdResponse& msg) {
88+
setDeviceNumber(msg.getDeviceNumber());
89+
setTransmissionType(msg.getTransmissionType());
90+
_onChannelIdResponse.call(msg);
8691
}

src/BaseClasses/ANTPLUS_BaseProfile.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class BaseProfile {
2424
* Callback when an event on this channel occurs
2525
*/
2626
void onChannelEvent(void (*func)(ChannelEventResponse&, uintptr_t), uintptr_t data = 0) { _onChannelEvent.set(func, data); }
27-
// TODO on channel config change callback (used for when wildcarding to identify when actual information has been found)
27+
/**
28+
* Notifies handler of channel config found after searching
29+
*/
30+
void onChannelIdResponse(void (*func)(ChannelIdResponse&,uintptr_t), uintptr_t data = 0) { _onChannelIdResponse.set(func, data); }
2831
/**
2932
* Set the channel deviceNumber, wildcard for searching is 0
3033
*/
@@ -66,6 +69,7 @@ class BaseProfile {
6669
virtual void onBroadcastData(BroadcastData& msg) { _onDataPage.call(msg); }
6770
virtual void onBurstTransferData(BurstTransferData& msg) { _onDataPage.call(msg); }
6871
virtual void onChannelEventResponse(ChannelEventResponse& msg);
72+
virtual void onChannelIdResponse(ChannelIdResponse& msg);
6973
void setRouter(AntPlusRouter* router);
7074
void setChannelNumber(uint8_t channel);
7175
// TODO this should probably have the whole message passed in so
@@ -87,6 +91,7 @@ class BaseProfile {
8791
Callback<AntRxDataResponse&> _onDataPage;
8892
Callback<AntRxDataResponse&> _onOtherDataPage;
8993
Callback<ChannelEventResponse&> _onChannelEvent;
94+
Callback<ChannelIdResponse&> _onChannelIdResponse;
9095
uint8_t _channel;
9196
uint8_t _channelType = 0;
9297
uint16_t _channelPeriod = 0;

src/BaseClasses/ANTPLUS_BaseSlaveProfile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class BaseSlaveProfile : public BaseProfile {
99
BaseSlaveProfile(uint16_t deviceNumber);
1010
BaseSlaveProfile(uint16_t deviceNumber, uint8_t transmissionType);
1111

12+
// TODO add a search method
13+
1214
private:
1315
};
1416

src/MainClasses/ANTPLUS_AntPlusRouter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ void AntPlusRouter::onChannelEventResponse(ChannelEventResponse& msg) {
151151
}
152152

153153
void AntPlusRouter::onChannelIdResponse(ChannelIdResponse& msg) {
154-
// TODO
154+
uint8_t channel = msg.getChannelNumber();
155+
if (_profiles[channel]) {
156+
_profiles[channel]->onChannelIdResponse(msg);
157+
}
155158
}
156159

157160
void AntPlusRouter::onChannelStatus(ChannelStatus& msg) {

0 commit comments

Comments
 (0)