Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cujomalainey committed Oct 1, 2017
2 parents d49b125 + e77f291 commit 4f38e68
Show file tree
Hide file tree
Showing 60 changed files with 1,115 additions and 395 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Arduino library for communicating with ANT radios, with support for nrf51 device

## Roadmap

* v1.5 callback system implemented (partially implemented in current release)
* v1.0 callback system implemented (partially implemented in current release)
* v1.1 unit test done on all messages, serial driver and callback system
* ~~v1.6 SPI support~~ (Arduino has no support for being a SPI slave, maybe mbed)
* v2.0 compile switch to handle running natively on an nRF52 dev board

Expand Down
34 changes: 28 additions & 6 deletions examples/Callbacks/Callbacks.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void handleBroadcastMessage(BroadcastData& bd, uintptr_t data);
void handleAntError(uint8_t code, uintptr_t data);
void handleStartUpMessage(StartUpMessage& sum, uintptr_t data);
void handleChannelEventResponse(ChannelEventResponse& cer, uintptr_t data);
bool itsAlive(StartUpMessage& sm, uintptr_t data);

void setup()
{
Expand All @@ -29,6 +30,7 @@ void setup()
ChannelPeriod cp;
ChannelRfFrequency crf;
OpenChannel oc;
StartUpMessage sm;

Serial1.begin(BAUD_RATE);
ant.onBroadcastData(handleBroadcastMessage);
Expand All @@ -37,24 +39,39 @@ void setup()
ant.onChannelEventResponse(handleChannelEventResponse);
ant.onOtherResponse(handleMessageWithNoCallback);
ant.begin(Serial1);
ant.send(rs);
// Delay after resetting the radio to give the user time to connect on serial
delay(10000);

Serial.begin(9600);
delay(10000);
// Delay to give the user time to connect on serial

Serial.println("Running");

ant.send(rs);
ant.waitFor(sm, 2000, itsAlive); // wait 2s for device to start

snk = SetNetworkKey();
snk.setNetwork(0);
snk.setKey((uint8_t*)NETWORK_KEY);
ant.send(snk);
ant.loop();
if(ant.waitForStatus(snk.getMsgId(), 1000)) {
Serial.println("No Response for setting network key");
} else {
ChannelEventResponse cer = ChannelEventResponse();
ant.getResponse().getChannelEventResponseMsg(cer);
handleChannelEventResponse(cer, 0);
}

ac = AssignChannel();
ac.setChannel(0);
ac.setChannelType(CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE); //can't wildcard this
ac.setChannelNetwork(0);
ant.send(ac);
ant.loop();
if (ant.sendAndWait(ac, 2000)) {
Serial.println("No Response for assigning channel");
} else {
ChannelEventResponse cer = ChannelEventResponse();
ant.getResponse().getChannelEventResponseMsg(cer);
handleChannelEventResponse(cer, 0);
}

ci = ChannelId();
ci.setChannel(0);
Expand Down Expand Up @@ -145,3 +162,8 @@ void handleChannelEventResponse(ChannelEventResponse& cer, uintptr_t data) {
break;
}
}

bool itsAlive(StartUpMessage& sm, uintptr_t data) {
Serial.println("Radio Reset!");
return true;
}
2 changes: 1 addition & 1 deletion examples/OpenChannel/OpenChannel.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void setup()
ant.send(rs);
// Delay after resetting the radio to give the user time to connect on serial
delay(10000);
Serial.begin(9600);
Serial.begin(BAUD_RATE);
Serial.println("Running");

snk = SetNetworkKey();
Expand Down
2 changes: 2 additions & 0 deletions src/ANT_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
#define CHECKSUM_FAILURE 1
#define PACKET_EXCEEDS_BYTE_ARRAY_LENGTH 2
#define UNEXPECTED_START_BYTE 3
#define ANT_WAIT_TIMEOUT 255

/**
* Framework Defines
Expand All @@ -246,6 +247,7 @@
#define MESSAGE_SIZE 0x08
#define INVALID_REQUEST 0xFF
#define BITS_IN_BYTE 0x08
#define BITS_IN_SHORT 0x10

/**
* SoftDevice API available, build native ant
Expand Down
74 changes: 50 additions & 24 deletions src/ANT_private_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,43 @@
/**
* Message Length Defines
*/
#define ACKNOWLEDGED_DATA_LENGTH 0x09
#define ADVANCED_BURST_DATA_LENGTH 0x09
#define ASSIGN_CHANNEL_LENGTH 0x03
#define BROADCAST_DATA_LENGTH 0x09
#define BURST_DATA_TRANSFER_LENGTH 0x09
#define BURST_TRANSFER_DATA_LENGTH 0x09
#define CHANNEL_ID_LENGTH 0x05
#define CHANNEL_PERIOD_LENGTH 0x03
#define CHANNEL_RF_FREQUENCY_LENGTH 0x02
#define CHANNEL_SEARCH_SHARING_LENGTH 0x02
#define CLOSE_CHANNEL_LENGTH 0x01
#define CONFIG_ENCRYPTION_ID_LIST_LENGTH 0x03
#define CONFIG_ID_LIST_LENGTH 0x03
#define CW_INIT_LENGTH 0x01
#define LIB_CONFIG_LENGTH 0x02
#define OPEN_CHANNEL_LENGTH 0x01
#define OPEN_RX_SCAN_MODE_LENGTH 0x01
#define REQUEST_MESSAGE_LENGTH 0x02
#define RESET_SYSTEM_LENGTH 0x01
#define SEARCH_TIMEOUT_LENGTH 0x02
#define SEARCH_WAVEFORM_LENGTH 0x03
#define SET_NETWORK_KEY_LENGTH 0x09
#define TRANSMIT_POWER_LENGTH 0x02
#define UNASSIGN_CHANNEL_LENGTH 0x01
#define ACKNOWLEDGED_DATA_LENGTH 0x09
#define ADD_CHANNEL_ID_TO_LIST_LENGTH 0x06
#define ADD_ENCRYPTION_ID_TO_LIST_LENGTH 0x06
#define ADVANCED_BURST_DATA_LENGTH 0x09
#define ASSIGN_CHANNEL_LENGTH 0x03
#define BROADCAST_DATA_LENGTH 0x09
#define BURST_DATA_TRANSFER_LENGTH 0x09
#define BURST_TRANSFER_DATA_LENGTH 0x09
#define CHANNEL_ID_LENGTH 0x05
#define CHANNEL_PERIOD_LENGTH 0x03
#define CHANNEL_RF_FREQUENCY_LENGTH 0x02
#define CHANNEL_SEARCH_PRIORITY_LENGTH 0x02
#define CHANNEL_SEARCH_SHARING_LENGTH 0x02
#define CLOSE_CHANNEL_LENGTH 0x01
#define CONFIG_ENCRYPTION_ID_LIST_LENGTH 0x03
#define CONFIG_ID_LIST_LENGTH 0x03
#define CONFIGURE_ADVANCED_BURST_LENGTH 0x0C
#define CONFIGURE_EVENT_FILTER_LENTGH 0x03
#define CONFIGURE_SELECTIVE_DATA_UPDATES_LENGTH 0x02
#define CW_INIT_LENGTH 0x01
#define ENABLE_EXT_RX_MESSAGES_LENGTH 0x02
#define ENABLE_SINGLE_CHANNEL_ENCRYPTION_LENGTH 0x04
#define FREQUENCY_AGILITY_LENGTH 0x04
#define LIB_CONFIG_LENGTH 0x02
#define LOW_PRIORITY_SEARCH_TIMEOUT_LENGTH 0x02
#define OPEN_CHANNEL_LENGTH 0x01
#define OPEN_RX_SCAN_MODE_LENGTH 0x01
#define PROXIMITY_SEARCH_LENGTH 0x02
#define REQUEST_MESSAGE_LENGTH 0x02
#define RESET_SYSTEM_LENGTH 0x01
#define SEARCH_TIMEOUT_LENGTH 0x02
#define SEARCH_WAVEFORM_LENGTH 0x03
#define SERIAL_NUMBER_SET_CHANNEL_ID_LENGTH 0x03
#define SET_CHANNEL_TRANSMIT_POWER_LENGTH 0x02
#define SET_NETWORK_KEY_LENGTH 0x09
#define TRANSMIT_POWER_LENGTH 0x02
#define UNASSIGN_CHANNEL_LENGTH 0x01

/**
* Channel Status BitField Defines
Expand All @@ -52,4 +65,17 @@
*/
#define CONFIG_ID_LIST_LIST_MAX_SIZE 0x04

/**
* Advanced burst defines
*/
#define ADVANCED_BURST_DATA_CHANNEL_MASK 0x1F
#define ADVANCED_BURST_DATA_SEQUENCENUMBER_SHIFT 5

/**
* Configure Selective Data Updates defines
*/
#define CONFIGURE_SELECTIVE_DATA_UPDATES_SDU_DISABLE 0xFF
#define CONFIGURE_SELECTIVE_DATA_UPDATES_SDU_NUMBER_MASK 0x1F
#define CONFIGURE_SELECTIVE_DATA_UPDATES_FILTER_BIT_MASK 0x80

#endif // ANT_PRIVATE_DEFINES_h
Loading

0 comments on commit 4f38e68

Please sign in to comment.