|
|
|
|
|
|
|
|
updatetimer.start(500000); |
|
|
updatetimer.start(500000); |
|
|
queue_Data_Transfer(rxpipe, rxpacket, 64, this); |
|
|
queue_Data_Transfer(rxpipe, rxpacket, 64, this); |
|
|
rxlen = 0; |
|
|
rxlen = 0; |
|
|
|
|
|
do_polling = false; |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
rxlen = 0; |
|
|
rxlen = 0; |
|
|
} else { |
|
|
} else { |
|
|
rxlen = len; // signal arrival of data to Task() |
|
|
rxlen = len; // signal arrival of data to Task() |
|
|
|
|
|
// TODO: should someday use EventResponder to call from yield() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (first_update) { |
|
|
if (first_update) { |
|
|
ResetSystem(); |
|
|
ResetSystem(); |
|
|
first_update = false; |
|
|
first_update = false; |
|
|
|
|
|
} else { |
|
|
|
|
|
do_polling = true; |
|
|
} |
|
|
} |
|
|
//println("ant update timer"); |
|
|
//println("ant update timer"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
rxlen = 0; |
|
|
rxlen = 0; |
|
|
NVIC_ENABLE_IRQ(IRQ_USBHS); |
|
|
NVIC_ENABLE_IRQ(IRQ_USBHS); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (do_polling) { |
|
|
|
|
|
do_polling = false; |
|
|
|
|
|
for (int i = 0; i < PROFILE_TOTAL; i++) { |
|
|
|
|
|
TDCONFIG *cfg = &ant.dcfg[i]; |
|
|
|
|
|
if (!(cfg->flags.profileValid)) continue; |
|
|
|
|
|
//printf("#### %i %i: %i %i %i ####", i, cfg->channel, |
|
|
|
|
|
// cfg->flags.channelStatus, cfg->flags.keyAccepted, |
|
|
|
|
|
// cfg->flags.chanIdOnce); |
|
|
|
|
|
if (cfg->flags.channelStatus) { |
|
|
|
|
|
RequestMessage(cfg->channel, MESG_CHANNEL_STATUS_ID); |
|
|
|
|
|
} else { |
|
|
|
|
|
AssignChannel(cfg->channel, cfg->channelType, cfg->networkNumber); |
|
|
|
|
|
RequestMessage(cfg->channel, MESG_CHANNEL_STATUS_ID); |
|
|
|
|
|
if (!cfg->flags.keyAccepted && !cfg->flags.chanIdOnce) { |
|
|
|
|
|
SetNetworkKey(cfg->networkNumber, getAntKey(ant.key)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum _akeys { |
|
|
enum _akeys { |
|
|
KEY_ANTSPORT, |
|
|
KEY_ANTSPORT, |
|
|
KEY_SUUNTO, |
|
|
KEY_SUUNTO, |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*int AntPlus::dispatchMessage(const uint8_t *stream, const int len) |
|
|
|
|
|
{ |
|
|
|
|
|
return ant.eventCb[EVENTI_MESSAGE].cbPtr(stream[STREAM_CHANNEL], |
|
|
|
|
|
stream[STREAM_MESSAGE], &stream[STREAM_DATA], |
|
|
|
|
|
(size_t)stream[STREAM_LENGTH], ant.eventCb[EVENTI_MESSAGE].uPtr); |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
uint8_t AntPlus::calcMsgChecksum(const uint8_t *buffer, const uint8_t len) |
|
|
uint8_t AntPlus::calcMsgChecksum(const uint8_t *buffer, const uint8_t len) |
|
|
{ |
|
|
{ |
|
|
uint8_t checksum = 0x00; |
|
|
uint8_t checksum = 0x00; |
|
|
|
|
|
|
|
|
message_event(stream[STREAM_CHANNEL], stream[STREAM_MESSAGE], |
|
|
message_event(stream[STREAM_CHANNEL], stream[STREAM_MESSAGE], |
|
|
&stream[STREAM_DATA], (size_t)stream[STREAM_LENGTH]); |
|
|
&stream[STREAM_DATA], (size_t)stream[STREAM_LENGTH]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int len = msgGetLength(stream); |
|
|
int len = msgGetLength(stream); |
|
|
stream += len; |
|
|
stream += len; |
|
|
tBytes -= len; |
|
|
tBytes -= len; |
|
|
|
|
|
|
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*int AntPlus::registerEventCallback(const int which, void *eventFunc, void *userPtr) |
|
|
|
|
|
{ |
|
|
|
|
|
if (which < EVENTI_TOTAL) { |
|
|
|
|
|
ant.eventCb[which].cbPtr = (int (*)(int, int, const uint8_t*, size_t, void*))eventFunc; |
|
|
|
|
|
ant.eventCb[which].uPtr = userPtr; |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
//printf("invalid callback id {%i}\n.", which); |
|
|
|
|
|
return 0; |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
/*int AntPlus::registerPayloadCallback(const int profile, void *eventFunc, void *userPtr) |
|
|
|
|
|
{ |
|
|
|
|
|
if (profile < PROFILE_TOTAL) { |
|
|
|
|
|
ant.payloadCb[profile].cbPtr = (void (*)(TDCONFIG*, const uint8_t*, size_t, void*))eventFunc; |
|
|
|
|
|
ant.payloadCb[profile].uPtr = userPtr; |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
//printf("invalid callback id {%i}\n.", profile); |
|
|
|
|
|
return 0; |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: replace this with multiple Arduino style OnXYZ callbacks |
|
|
// TODO: replace this with multiple Arduino style OnXYZ callbacks |
|
|
void AntPlus::setCallbackFunc(int (*func)(uint32_t msg, intptr_t *value1, uint32_t value2)) |
|
|
void AntPlus::setCallbackFunc(int (*func)(uint32_t msg, intptr_t *value1, uint32_t value2)) |
|
|
|
|
|
|
|
|
//printf(" $ chan event: chan:%i, msgId:0x%.2X, payload:%p, dataLen:%i, uPtr:%p", chan, eventId, payload, (int)dataLength, uPtr); |
|
|
//printf(" $ chan event: chan:%i, msgId:0x%.2X, payload:%p, dataLen:%i, uPtr:%p", chan, eventId, payload, (int)dataLength, uPtr); |
|
|
//dump_hexbytes(payload, dataLength); |
|
|
//dump_hexbytes(payload, dataLength); |
|
|
|
|
|
|
|
|
//TLIBANTPLUS *ant = (AntPlus::TLIBANTPLUS*)uPtr; |
|
|
|
|
|
TDCONFIG *cfg = &(ant.dcfg[chan]); |
|
|
TDCONFIG *cfg = &(ant.dcfg[chan]); |
|
|
|
|
|
|
|
|
switch (eventId){ |
|
|
switch (eventId){ |
|
|
|
|
|
|
|
|
//printf(" @ msg event cb: Chan:%i, Id:0x%.2X, payload:%p, len:%i, ptr:%p", channel, msgId, payload, (int)dataLength, uPtr); |
|
|
//printf(" @ msg event cb: Chan:%i, Id:0x%.2X, payload:%p, len:%i, ptr:%p", channel, msgId, payload, (int)dataLength, uPtr); |
|
|
//dump_hexbytes(payload, dataLength); |
|
|
//dump_hexbytes(payload, dataLength); |
|
|
|
|
|
|
|
|
//TLIBANTPLUS *ant = (TLIBANTPLUS*)uPtr; |
|
|
|
|
|
uint8_t chan = 0; |
|
|
uint8_t chan = 0; |
|
|
if (channel >= 0 && channel < PROFILE_TOTAL) chan = channel; |
|
|
if (channel >= 0 && channel < PROFILE_TOTAL) chan = channel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//int AntPlus::SetPayloadHandler(const int profile, void *eventFunc, void *userPtr) |
|
|
|
|
|
//{ |
|
|
|
|
|
//return registerPayloadCallback(profile, eventFunc, userPtr); |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
//int AntPlus::SetEventHandler(const int which, void *eventFunc, void *userPtr) |
|
|
|
|
|
//{ |
|
|
|
|
|
//return registerEventCallback(which, eventFunc, userPtr); |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
int AntPlus::ResetSystem() |
|
|
int AntPlus::ResetSystem() |
|
|
{ |
|
|
{ |
|
|
//println("libantplus_ResetSystem"); |
|
|
//println("libantplus_ResetSystem"); |
|
|
|
|
|
|
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//const uint8_t *libantplus_GetNetworkKey (const uint8_t keyIdx) |
|
|
|
|
|
//{ |
|
|
|
|
|
//return antplus_getAntKey(keyIdx); |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AntPlus::profileSetup_HRM(TDCONFIG *cfg, const uint32_t deviceId) |
|
|
void AntPlus::profileSetup_HRM(TDCONFIG *cfg, const uint32_t deviceId) |
|
|
|
|
|
|
|
|
int deviceId = 0; // TODO: user API to set this? |
|
|
int deviceId = 0; // TODO: user API to set this? |
|
|
profileSetup_HRM(&ant.dcfg[PROFILE_HRM], deviceId); |
|
|
profileSetup_HRM(&ant.dcfg[PROFILE_HRM], deviceId); |
|
|
profileSetup_SPDCAD(&ant.dcfg[PROFILE_SPDCAD], deviceId); |
|
|
profileSetup_SPDCAD(&ant.dcfg[PROFILE_SPDCAD], deviceId); |
|
|
profileSetup_POWER(&ant.dcfg[PROFILE_POWER], deviceId); |
|
|
|
|
|
profileSetup_STRIDE(&ant.dcfg[PROFILE_STRIDE], deviceId); |
|
|
|
|
|
profileSetup_SPEED(&ant.dcfg[PROFILE_SPEED], deviceId); |
|
|
|
|
|
profileSetup_CADENCE(&ant.dcfg[PROFILE_CADENCE], deviceId); |
|
|
|
|
|
|
|
|
//profileSetup_POWER(&ant.dcfg[PROFILE_POWER], deviceId); |
|
|
|
|
|
//profileSetup_STRIDE(&ant.dcfg[PROFILE_STRIDE], deviceId); |
|
|
|
|
|
//profileSetup_SPEED(&ant.dcfg[PROFILE_SPEED], deviceId); |
|
|
|
|
|
//profileSetup_CADENCE(&ant.dcfg[PROFILE_CADENCE], deviceId); |
|
|
|
|
|
|
|
|
//ant.eventCb[EVENTI_MESSAGE].cbPtr = &message_event; |
|
|
//ant.eventCb[EVENTI_MESSAGE].cbPtr = &message_event; |
|
|
//SetEventHandler(EVENTI_MESSAGE, (void*)message_event, (void*)ant); |
|
|
//SetEventHandler(EVENTI_MESSAGE, (void*)message_event, (void*)ant); |