├── .bettercodehub.yml ├── .circleci └── config.yml ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── COPYING ├── LICENSE ├── README.md ├── examples ├── Arduino │ ├── AntVersion │ │ └── AntVersion.ino │ ├── Callbacks │ │ └── Callbacks.ino │ ├── OpenChannel │ │ └── OpenChannel.ino │ ├── ProximitySearch │ │ └── ProximitySearch.ino │ ├── RSSIScan │ │ └── RSSIScan.ino │ ├── SearchList │ │ └── SearchList.ino │ ├── SoftwareSerialOpenChannel │ │ └── SoftwareSerialOpenChannel.ino │ └── TxCounter │ │ └── TxCounter.ino ├── Mbed │ └── AntVersion │ │ └── AntVersion.cpp └── NativeAnt │ └── NativeAnt.ino ├── img ├── library_layout.png └── object_layout.png ├── keywords.txt ├── library.json ├── library.properties ├── platformio.ini ├── src ├── ANT.h ├── ANT_defines.h ├── ANT_private_defines.h ├── BaseClasses │ ├── ANT_BaseAnt.cpp │ ├── ANT_BaseAnt.h │ ├── ANT_BaseAntWithCallbacks.cpp │ ├── ANT_BaseAntWithCallbacks.h │ ├── ANT_BaseFramework.h │ ├── ANT_BaseNativeAnt.cpp │ ├── ANT_BaseNativeAnt.h │ ├── ANT_BaseSerialAnt.cpp │ ├── ANT_BaseSerialAnt.h │ ├── ANT_BaseSpiAnt.cpp │ └── ANT_BaseSpiAnt.h ├── MainClasses │ ├── ANT_ArduinoNativeAnt.cpp │ ├── ANT_ArduinoNativeAnt.h │ ├── ANT_ArduinoNativeAntWithCallbacks.cpp │ ├── ANT_ArduinoNativeAntWithCallbacks.h │ ├── ANT_ArduinoSerialAnt.cpp │ ├── ANT_ArduinoSerialAnt.h │ ├── ANT_ArduinoSerialAntWithCallbacks.cpp │ ├── ANT_ArduinoSerialAntWithCallbacks.h │ ├── ANT_MbedSerialAnt.cpp │ ├── ANT_MbedSerialAnt.h │ ├── ANT_MbedSerialAntWithCallbacks.cpp │ ├── ANT_MbedSerialAntWithCallbacks.h │ ├── ANT_MbedSpiAnt.cpp │ ├── ANT_MbedSpiAnt.h │ ├── ANT_NativeAntWithCallbacks.cpp │ ├── ANT_NativeAntWithCallbacks.h │ └── FrameworkClasses │ │ └── ANT_ArduinoHandler.h ├── RX │ ├── ANT_AntResponse.cpp │ ├── ANT_AntResponse.h │ ├── ANT_AntRxDataResponse.cpp │ ├── ANT_AntRxDataResponse.h │ ├── ANT_messages.h │ ├── Data │ │ ├── ANT_AcknowledgedData.cpp │ │ ├── ANT_AcknowledgedData.h │ │ ├── ANT_AdvancedBurstData.cpp │ │ ├── ANT_AdvancedBurstData.h │ │ ├── ANT_BroadcastData.cpp │ │ ├── ANT_BroadcastData.h │ │ ├── ANT_BurstTransferData.cpp │ │ └── ANT_BurstTransferData.h │ └── Status │ │ ├── ANT_AdvancedBurstCapabilitiesConfiguration.cpp │ │ ├── ANT_AdvancedBurstCapabilitiesConfiguration.h │ │ ├── ANT_AntVersion.cpp │ │ ├── ANT_AntVersion.h │ │ ├── ANT_Capabilities.cpp │ │ ├── ANT_Capabilities.h │ │ ├── ANT_ChannelEventResponse.cpp │ │ ├── ANT_ChannelEventResponse.h │ │ ├── ANT_ChannelIdResponse.cpp │ │ ├── ANT_ChannelIdResponse.h │ │ ├── ANT_ChannelStatus.cpp │ │ ├── ANT_ChannelStatus.h │ │ ├── ANT_EncryptionModeParameters.cpp │ │ ├── ANT_EncryptionModeParameters.h │ │ ├── ANT_EventFilter.cpp │ │ ├── ANT_EventFilter.h │ │ ├── ANT_SelectiveDataUpdateMaskSetting.cpp │ │ ├── ANT_SelectiveDataUpdateMaskSetting.h │ │ ├── ANT_StartUpMessage.cpp │ │ └── ANT_StartUpMessage.h ├── TX │ ├── ANT_AntRequest.cpp │ ├── ANT_AntRequest.h │ ├── ANT_AntTxDataRequest.cpp │ ├── ANT_AntTxDataRequest.h │ ├── ANT_messages.h │ ├── Config │ │ ├── ANT_AddChannelIdToList.cpp │ │ ├── ANT_AddChannelIdToList.h │ │ ├── ANT_AddEncryptionIdToList.cpp │ │ ├── ANT_AddEncryptionIdToList.h │ │ ├── ANT_AssignChannel.cpp │ │ ├── ANT_AssignChannel.h │ │ ├── ANT_ChannelId.cpp │ │ ├── ANT_ChannelId.h │ │ ├── ANT_ChannelPeriod.cpp │ │ ├── ANT_ChannelPeriod.h │ │ ├── ANT_ChannelRfFrequency.cpp │ │ ├── ANT_ChannelRfFrequency.h │ │ ├── ANT_ChannelSearchPriority.cpp │ │ ├── ANT_ChannelSearchPriority.h │ │ ├── ANT_ChannelSearchSharing.cpp │ │ ├── ANT_ChannelSearchSharing.h │ │ ├── ANT_ConfigEncryptionIdList.cpp │ │ ├── ANT_ConfigEncryptionIdList.h │ │ ├── ANT_ConfigIdList.cpp │ │ ├── ANT_ConfigIdList.h │ │ ├── ANT_ConfigureAdvancedBurst.cpp │ │ ├── ANT_ConfigureAdvancedBurst.h │ │ ├── ANT_ConfigureEventFilter.cpp │ │ ├── ANT_ConfigureEventFilter.h │ │ ├── ANT_ConfigureSelectiveDataUpdates.cpp │ │ ├── ANT_ConfigureSelectiveDataUpdates.h │ │ ├── ANT_EnableExtRxMessages.cpp │ │ ├── ANT_EnableExtRxMessages.h │ │ ├── ANT_EnableSingleChannelEncryption.cpp │ │ ├── ANT_EnableSingleChannelEncryption.h │ │ ├── ANT_FrequencyAgility.cpp │ │ ├── ANT_FrequencyAgility.h │ │ ├── ANT_LibConfig.cpp │ │ ├── ANT_LibConfig.h │ │ ├── ANT_LowPrioritySearchTimeout.cpp │ │ ├── ANT_LowPrioritySearchTimeout.h │ │ ├── ANT_ProximitySearch.cpp │ │ ├── ANT_ProximitySearch.h │ │ ├── ANT_SearchTimeout.cpp │ │ ├── ANT_SearchTimeout.h │ │ ├── ANT_SearchWaveform.cpp │ │ ├── ANT_SearchWaveform.h │ │ ├── ANT_SerialNumberSetChannelId.cpp │ │ ├── ANT_SerialNumberSetChannelId.h │ │ ├── ANT_SetChannelTransmitPower.cpp │ │ ├── ANT_SetChannelTransmitPower.h │ │ ├── ANT_SetEncryptionInfo.cpp │ │ ├── ANT_SetEncryptionInfo.h │ │ ├── ANT_SetEncryptionKey.cpp │ │ ├── ANT_SetEncryptionKey.h │ │ ├── ANT_SetNetworkKey.cpp │ │ ├── ANT_SetNetworkKey.h │ │ ├── ANT_SetSelectiveDataUpdateMask.cpp │ │ ├── ANT_SetSelectiveDataUpdateMask.h │ │ ├── ANT_TransmitPower.cpp │ │ ├── ANT_TransmitPower.h │ │ ├── ANT_UnAssignChannel.cpp │ │ └── ANT_UnAssignChannel.h │ ├── Control │ │ ├── ANT_CloseChannel.cpp │ │ ├── ANT_CloseChannel.h │ │ ├── ANT_OpenChannel.cpp │ │ ├── ANT_OpenChannel.h │ │ ├── ANT_OpenRxScanMode.cpp │ │ ├── ANT_OpenRxScanMode.h │ │ ├── ANT_RequestMessage.cpp │ │ ├── ANT_RequestMessage.h │ │ ├── ANT_ResetSystem.cpp │ │ └── ANT_ResetSystem.h │ ├── Data │ │ ├── ANT_AcknowledgedDataMsg.cpp │ │ ├── ANT_AcknowledgedDataMsg.h │ │ ├── ANT_AdvancedBurstDataMsg.cpp │ │ ├── ANT_AdvancedBurstDataMsg.h │ │ ├── ANT_BroadcastDataMsg.cpp │ │ ├── ANT_BroadcastDataMsg.h │ │ ├── ANT_BurstTransferDataMsg.cpp │ │ └── ANT_BurstTransferDataMsg.h │ └── Test │ │ ├── ANT_CWInit.cpp │ │ ├── ANT_CWInit.h │ │ ├── ANT_CWTest.cpp │ │ └── ANT_CWTest.h └── Util │ ├── Testing.cpp │ └── Testing.h └── test ├── test_TX_AddChannelIdToList └── Test_AddChannelIdToList.cpp └── test_TX_AddEncryptionIdToList └── Test_AddEncryptionIdToList.cpp /.bettercodehub.yml: -------------------------------------------------------------------------------- 1 | component_depth: 2 2 | languages: 3 | - cpp 4 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Python CircleCI 2.0 configuration file 2 | # 3 | # Check https://circleci.com/docs/2.0/language-python/ for more details 4 | # 5 | version: 2 6 | jobs: 7 | build: 8 | docker: 9 | # specify the version you desire here 10 | # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` 11 | - image: circleci/python:3.8 12 | 13 | # Specify service dependencies here if necessary 14 | # CircleCI maintains a library of pre-built images 15 | # documented at https://circleci.com/docs/2.0/circleci-images/ 16 | # - image: circleci/postgres:9.4 17 | 18 | working_directory: ~/repo 19 | 20 | steps: 21 | - checkout 22 | 23 | - run: 24 | name: install dependencies 25 | command: | 26 | sudo pip install -U platformio 27 | 28 | # other common Python testing frameworks include pytest and nose 29 | # https://pytest.org 30 | # https://nose.readthedocs.io 31 | - run: 32 | name: run tests 33 | command: | 34 | pio test -e native 35 | 36 | - store_artifacts: 37 | path: test-reports 38 | destination: test-reports 39 | 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /notes.txt 2 | /deploy.sh 3 | .DS_Store 4 | .pioenvs 5 | .pio 6 | tags 7 | 8 | # ignore any soft device source for testing 9 | nrf_* 10 | ant_error.h 11 | ant_parameters.h 12 | ant_interface.h 13 | 14 | # ide files 15 | .tags* 16 | .ycm* 17 | .platformio* 18 | *.swp 19 | 20 | # ignore main file for testing 21 | src/main.cpp 22 | .pio/build/project.checksum 23 | .vscode/c_cpp_properties.json 24 | .vscode/extensions.json 25 | .vscode/launch.json 26 | /*.cpp 27 | /zephyr 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < http://docs.platformio.org/en/latest/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < http://docs.platformio.org/en/latest/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choice one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | language: python 23 | python: 24 | - "2.7" 25 | 26 | sudo: false 27 | cache: 28 | directories: 29 | - "~/.platformio" 30 | 31 | env: 32 | - PLATFORMIO_CI_SRC=examples/Arduino/AntVersion/AntVersion.ino 33 | - PLATFORMIO_CI_SRC=examples/Arduino/Callbacks/Callbacks.ino 34 | - PLATFORMIO_CI_SRC=examples/Arduino/OpenChannel/OpenChannel.ino 35 | - PLATFORMIO_CI_SRC=examples/Arduino/ProximitySearch/ProximitySearch.ino 36 | - PLATFORMIO_CI_SRC=examples/Arduino/RSSIScan/RSSIScan.ino 37 | - PLATFORMIO_CI_SRC=examples/Arduino/SearchList/SearchList.ino 38 | - PLATFORMIO_CI_SRC=examples/Arduino/SoftwareSerialOpenChannel/SoftwareSerialOpenChannel.ino 39 | - PLATFORMIO_CI_SRC=examples/Arduino/TxCounter/TxCounter.ino 40 | 41 | install: 42 | - pip install -U platformio 43 | 44 | script: 45 | - platformio ci --lib="." --board=teensy31 46 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at curtis@malainey.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /examples/Arduino/OpenChannel/OpenChannel.ino: -------------------------------------------------------------------------------- 1 | /*********************************** 2 | * Ant Open Channel Example 3 | * 4 | * Opens a channel with a preset 5 | * network key, period and frequncy. 6 | * All other fields are wildcarded. 7 | * Radio output is parsed and 8 | * transmitted to the serial monitor 9 | * 10 | * Author Curtis Malainey 11 | ************************************/ 12 | 13 | #include "ANT.h" 14 | #define BAUD_RATE 9600 15 | ArduinoSerialAnt ant; 16 | 17 | // Arbitrary key, if you want to connect to ANT+, you must get the key from thisisant.com 18 | const uint8_t NETWORK_KEY[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; 19 | 20 | void parseMessage(); 21 | void parseEventMessage(uint8_t code); 22 | 23 | void setup() 24 | { 25 | AssignChannel ac; 26 | ResetSystem rs; 27 | SetNetworkKey snk; 28 | ChannelId ci; 29 | ChannelPeriod cp; 30 | ChannelRfFrequency crf; 31 | OpenChannel oc; 32 | 33 | Serial1.begin(BAUD_RATE); 34 | ant.setSerial(Serial1); 35 | ant.send(rs); 36 | // Delay after resetting the radio to give the user time to connect on serial 37 | delay(10000); 38 | Serial.begin(BAUD_RATE); 39 | Serial.println("Running"); 40 | 41 | snk = SetNetworkKey(); 42 | snk.setNetwork(0); 43 | snk.setKey((uint8_t*)NETWORK_KEY); 44 | ant.send(snk); 45 | parseMessage(); 46 | 47 | ac = AssignChannel(); 48 | ac.setChannel(0); 49 | ac.setChannelType(CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE); //can't wildcard this 50 | ac.setChannelNetwork(0); 51 | ant.send(ac); 52 | parseMessage(); 53 | 54 | ci = ChannelId(); 55 | ci.setChannel(0); 56 | ci.setDeviceNumber(0); 57 | ci.setDeviceType(0); 58 | ci.setTransmissionType(0); 59 | ant.send(ci); 60 | parseMessage(); 61 | 62 | cp = ChannelPeriod(); 63 | cp.setChannel(0); 64 | cp.setPeriod(1234); //can't wildcard this 65 | ant.send(cp); 66 | parseMessage(); 67 | 68 | crf = ChannelRfFrequency(); 69 | crf.setChannel(0); 70 | crf.setRfFrequency(0); //can't wildcard this 71 | ant.send(crf); 72 | parseMessage(); 73 | 74 | oc = OpenChannel(); 75 | oc.setChannel(0); 76 | ant.send(oc); 77 | parseMessage(); 78 | } 79 | 80 | void loop() 81 | { 82 | parseMessage(); 83 | } 84 | 85 | void parseMessage() { 86 | ant.readPacket(); 87 | if (ant.getResponse().isAvailable()) { 88 | uint8_t msgId = ant.getResponse().getMsgId(); 89 | switch (msgId) { 90 | case CHANNEL_EVENT: 91 | { 92 | ChannelEventResponse cer = ChannelEventResponse(); 93 | ant.getResponse().getChannelEventResponseMsg(cer); 94 | Serial.println("Received Msg: ChannelEventResponse"); 95 | Serial.print("Channel: "); 96 | Serial.println(cer.getChannelNumber()); 97 | parseEventMessage(cer.getCode()); 98 | break; 99 | } 100 | 101 | case START_UP_MESSAGE: 102 | { 103 | StartUpMessage sum = StartUpMessage(); 104 | ant.getResponse().getStartUpMsg(sum); 105 | Serial.println("Received Msg: StartupMessage"); 106 | Serial.print("Message: "); 107 | Serial.println(sum.getMessage()); 108 | break; 109 | } 110 | 111 | case BROADCAST_DATA: 112 | { 113 | BroadcastData bd = BroadcastData(); 114 | ant.getResponse().getBroadcastDataMsg(bd); 115 | Serial.println("Received Msg: BroadcastData"); 116 | Serial.print("Channel: "); 117 | Serial.println(bd.getChannelNumber()); 118 | Serial.print("Data:["); 119 | Serial.print(bd.getData(0), HEX); 120 | for (uint8_t i = 1; i < 8; i++) 121 | { 122 | Serial.print(", "); 123 | Serial.print(bd.getData(i), HEX); 124 | } 125 | Serial.println("]"); 126 | break; 127 | } 128 | 129 | default: 130 | Serial.print("Unhandled Message: "); 131 | Serial.println(msgId, HEX); 132 | break; 133 | } 134 | } 135 | else if (ant.getResponse().isError()) 136 | { 137 | Serial.print("ANT MSG ERROR: "); 138 | Serial.println(ant.getResponse().getErrorCode()); 139 | } 140 | } 141 | 142 | void parseEventMessage(uint8_t code) { 143 | Serial.print("Code: "); 144 | switch (code) { 145 | case STATUS_RESPONSE_NO_ERROR: 146 | Serial.println("RESPONSE_NO_ERROR"); 147 | break; 148 | 149 | case STATUS_EVENT_RX_FAIL: 150 | Serial.println("EVENT_RX_FAIL"); 151 | break; 152 | 153 | case STATUS_EVENT_RX_SEARCH_TIMEOUT: 154 | Serial.println("EVENT_RX_SEARCH_TIMEOUT"); 155 | break; 156 | 157 | case STATUS_EVENT_CHANNEL_CLOSED: 158 | Serial.println("EVENT_CHANNEL_CLOSED"); 159 | break; 160 | 161 | default: 162 | Serial.println(code); 163 | break; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /examples/Arduino/RSSIScan/RSSIScan.ino: -------------------------------------------------------------------------------- 1 | /*********************************** 2 | * Ant RSSI Scan Example 3 | * 4 | * Opens a channel in rx scan mode 5 | * then reports all found devices 6 | * and their RSSI values 7 | * 8 | * Author Curtis Malainey 9 | ************************************/ 10 | 11 | #include "ANT.h" 12 | #define BAUD_RATE 9600 13 | ArduinoSerialAnt ant; 14 | 15 | const uint8_t NETWORK_KEY[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; 16 | 17 | void parseMessage(); 18 | void parseEventMessage(uint8_t code); 19 | 20 | void setup() 21 | { 22 | AssignChannel ac; 23 | ResetSystem rs; 24 | SetNetworkKey snk; 25 | ChannelId ci; 26 | ChannelRfFrequency crf; 27 | LibConfig lb; 28 | OpenRxScanMode osm; 29 | 30 | Serial1.begin(BAUD_RATE); 31 | ant.setSerial(Serial1); 32 | ant.send(rs); 33 | // Delay after resetting the radio to give the user time to connect on serial 34 | delay(10000); 35 | Serial.begin(9600); 36 | Serial.println("Running"); 37 | parseMessage(); 38 | 39 | snk.setNetwork(0); 40 | snk.setKey((uint8_t*)NETWORK_KEY); 41 | ant.send(snk); 42 | parseMessage(); 43 | 44 | ac.setChannel(OPEN_RX_SCAN_MODE_CHANNEL); 45 | ac.setChannelType(CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE); //can't wildcard this 46 | ac.setChannelNetwork(0); 47 | ant.send(ac); 48 | parseMessage(); 49 | 50 | ci.setChannel(OPEN_RX_SCAN_MODE_CHANNEL); 51 | ci.setDeviceNumber(0); 52 | ci.setDeviceType(0); 53 | ci.setTransmissionType(0); 54 | ant.send(ci); 55 | parseMessage(); 56 | 57 | lb.setConfig(LIB_CONFIG_RSSI | LIB_CONFIG_CHANNEL_ID); 58 | ant.send(lb); 59 | parseMessage(); 60 | 61 | crf.setChannel(OPEN_RX_SCAN_MODE_CHANNEL); 62 | crf.setRfFrequency(0); //can't wildcard this 63 | ant.send(crf); 64 | parseMessage(); 65 | 66 | ant.send(osm); 67 | parseMessage(); 68 | } 69 | 70 | void loop() 71 | { 72 | parseMessage(); 73 | } 74 | 75 | void parseMessage() { 76 | ant.readPacket(); 77 | if(ant.getResponse().isAvailable()) 78 | { 79 | uint8_t msgId = ant.getResponse().getMsgId(); 80 | switch (msgId) { 81 | case CHANNEL_EVENT: 82 | { 83 | ChannelEventResponse cer; 84 | ant.getResponse().getChannelEventResponseMsg(cer); 85 | Serial.println("Received Msg: ChannelEventResponse"); 86 | Serial.print("Channel: "); 87 | Serial.println(cer.getChannelNumber()); 88 | parseEventMessage(cer.getCode()); 89 | break; 90 | } 91 | 92 | case START_UP_MESSAGE: 93 | { 94 | StartUpMessage sum; 95 | ant.getResponse().getStartUpMsg(sum); 96 | Serial.println("Received Msg: StartupMessage"); 97 | Serial.print("Message: "); 98 | Serial.println(sum.getMessage()); 99 | break; 100 | } 101 | 102 | case BROADCAST_DATA: 103 | { 104 | BroadcastData bd; 105 | ant.getResponse().getBroadcastDataMsg(bd); 106 | if ((bd.getFlagByte() & LIB_CONFIG_RSSI) && (bd.getFlagByte() & LIB_CONFIG_CHANNEL_ID)) { 107 | Serial.print("Device Number: "); 108 | Serial.print(bd.getDeviceNumber()); 109 | Serial.print(", Device Type: "); 110 | Serial.print(bd.getDeviceType()); 111 | Serial.print(", RSSI: "); 112 | Serial.println(bd.getRSSIValue()); 113 | } 114 | break; 115 | } 116 | 117 | case ACKNOWLEDGED_DATA: 118 | { 119 | AcknowledgedData ad; 120 | ant.getResponse().getAcknowledgedDataMsg(ad); 121 | if ((ad.getFlagByte() & LIB_CONFIG_CHANNEL_ID) && (ad.getFlagByte() & LIB_CONFIG_RSSI)) { 122 | Serial.print("Device Number: "); 123 | Serial.print(ad.getDeviceNumber()); 124 | Serial.print(", Device Type: "); 125 | Serial.print(ad.getDeviceType()); 126 | Serial.print(", RSSI: "); 127 | Serial.println(ad.getRSSIValue()); 128 | } 129 | } 130 | 131 | default: 132 | Serial.print("Undefined Message: "); 133 | Serial.println(msgId, HEX); 134 | break; 135 | } 136 | } 137 | else if (ant.getResponse().isError()) 138 | { 139 | Serial.print("ANT MSG ERROR: "); 140 | Serial.println(ant.getResponse().getErrorCode()); 141 | } 142 | } 143 | 144 | void parseEventMessage(uint8_t code) 145 | { 146 | BroadcastDataMsg bm; 147 | Serial.print("Code: "); 148 | switch (code) 149 | { 150 | case STATUS_RESPONSE_NO_ERROR: 151 | Serial.println("RESPONSE_NO_ERROR"); 152 | break; 153 | 154 | case STATUS_EVENT_CHANNEL_CLOSED: 155 | Serial.println("EVENT_CHANNEL_CLOSED"); 156 | break; 157 | 158 | default: 159 | Serial.println(code); 160 | break; 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /examples/Arduino/SoftwareSerialOpenChannel/SoftwareSerialOpenChannel.ino: -------------------------------------------------------------------------------- 1 | /*********************************** 2 | * Ant Software Serial Open Channel Example 3 | * 4 | * Example same as open channel example 5 | * but instead uses a software based 6 | * serial port 7 | * 8 | * NOTE: This example is incomplete 9 | * 10 | * Author Curtis Malainey 11 | ************************************/ 12 | 13 | #include "ANT.h" 14 | #include "SoftwareSerial.h" 15 | #define BAUD_RATE 9600 16 | #define SOFT_RX_PIN 2 17 | #define SOFT_TX_PIN 3 18 | ArduinoSerialAnt ant; 19 | SoftwareSerial soft(SOFT_RX_PIN, SOFT_TX_PIN); 20 | 21 | // Arbitrary key, if you want to connect to ANT+, you must get the key from thisisant.com 22 | const uint8_t NETWORK_KEY[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; 23 | 24 | void parseMessage(); 25 | void parseEventMessage(uint8_t code); 26 | 27 | void setup() 28 | { 29 | AssignChannel ac; 30 | ResetSystem rs; 31 | SetNetworkKey snk; 32 | ChannelId ci; 33 | ChannelPeriod cp; 34 | ChannelRfFrequency crf; 35 | OpenChannel oc; 36 | 37 | soft.begin(BAUD_RATE); 38 | ant.setSerial(soft); 39 | ant.send(rs); 40 | // Delay after resetting the radio to give the user time to connect on serial 41 | delay(10000); 42 | Serial.begin(9600); 43 | Serial.println("Running"); 44 | 45 | snk = SetNetworkKey(); 46 | snk.setNetwork(0); 47 | snk.setKey((uint8_t*)NETWORK_KEY); 48 | ant.send(snk); 49 | parseMessage(); 50 | 51 | ac = AssignChannel(); 52 | ac.setChannel(0); 53 | ac.setChannelType(CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE); //can't wildcard this 54 | ac.setChannelNetwork(0); 55 | ant.send(ac); 56 | parseMessage(); 57 | 58 | ci = ChannelId(); 59 | ci.setChannel(0); 60 | ci.setDeviceNumber(0); 61 | ci.setDeviceType(0); 62 | ci.setTransmissionType(0); 63 | ant.send(ci); 64 | parseMessage(); 65 | 66 | cp = ChannelPeriod(); 67 | cp.setChannel(0); 68 | cp.setPeriod(1234); //can't wildcard this 69 | ant.send(cp); 70 | parseMessage(); 71 | 72 | crf = ChannelRfFrequency(); 73 | crf.setChannel(0); 74 | crf.setRfFrequency(0); //can't wildcard this 75 | ant.send(crf); 76 | parseMessage(); 77 | 78 | oc = OpenChannel(); 79 | oc.setChannel(0); 80 | ant.send(oc); 81 | parseMessage(); 82 | } 83 | 84 | void loop() 85 | { 86 | parseMessage(); 87 | } 88 | 89 | void parseMessage() { 90 | ant.readPacket(); 91 | if (ant.getResponse().isAvailable()) { 92 | uint8_t msgId = ant.getResponse().getMsgId(); 93 | switch (msgId) { 94 | case CHANNEL_EVENT: 95 | { 96 | ChannelEventResponse cer = ChannelEventResponse(); 97 | ant.getResponse().getChannelEventResponseMsg(cer); 98 | Serial.println("Received Msg: ChannelEventResponse"); 99 | Serial.print("Channel: "); 100 | Serial.println(cer.getChannelNumber()); 101 | parseEventMessage(cer.getCode()); 102 | break; 103 | } 104 | 105 | case START_UP_MESSAGE: 106 | { 107 | StartUpMessage sum = StartUpMessage(); 108 | ant.getResponse().getStartUpMsg(sum); 109 | Serial.println("Received Msg: StartupMessage"); 110 | Serial.print("Message: "); 111 | Serial.println(sum.getMessage()); 112 | break; 113 | } 114 | 115 | case BROADCAST_DATA: 116 | { 117 | BroadcastData bd = BroadcastData(); 118 | ant.getResponse().getBroadcastDataMsg(bd); 119 | Serial.println("Received Msg: BroadcastData"); 120 | Serial.print("Channel: "); 121 | Serial.println(bd.getChannelNumber()); 122 | Serial.print("Data:["); 123 | Serial.print(bd.getData(0), HEX); 124 | for (uint8_t i = 1; i < 8; i++) 125 | { 126 | Serial.print(", "); 127 | Serial.print(bd.getData(i), HEX); 128 | } 129 | Serial.println("]"); 130 | break; 131 | } 132 | 133 | default: 134 | Serial.print("Undefined Message: "); 135 | Serial.println(msgId, HEX); 136 | break; 137 | } 138 | } 139 | else if (ant.getResponse().isError()) 140 | { 141 | Serial.print("ANT MSG ERROR: "); 142 | Serial.println(ant.getResponse().getErrorCode()); 143 | } 144 | } 145 | 146 | void parseEventMessage(uint8_t code) { 147 | Serial.print("Code: "); 148 | switch (code) { 149 | case STATUS_RESPONSE_NO_ERROR: 150 | Serial.println("RESPONSE_NO_ERROR"); 151 | break; 152 | 153 | case STATUS_EVENT_RX_FAIL: 154 | Serial.println("EVENT_RX_FAIL"); 155 | break; 156 | 157 | case STATUS_EVENT_RX_SEARCH_TIMEOUT: 158 | Serial.println("EVENT_RX_SEARCH_TIMEOUT"); 159 | break; 160 | 161 | case STATUS_EVENT_CHANNEL_CLOSED: 162 | Serial.println("EVENT_CHANNEL_CLOSED"); 163 | break; 164 | 165 | default: 166 | Serial.println(code); 167 | break; 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /examples/Arduino/TxCounter/TxCounter.ino: -------------------------------------------------------------------------------- 1 | /*********************************** 2 | * Ant Tx Counter Example 3 | * 4 | * Opens a channel with the public 5 | * network key and transmits data 6 | * increments in value every second 7 | * 8 | * Author Curtis Malainey 9 | ************************************/ 10 | 11 | #include "ANT.h" 12 | #define BAUD_RATE 9600 13 | ArduinoSerialAnt ant; 14 | 15 | const uint8_t NETWORK_KEY[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; 16 | 17 | uint8_t buffer[] = {0, 0, 0, 0, 0, 0, 0, 0}; 18 | 19 | void parseMessage(); 20 | void parseEventMessage(uint8_t code); 21 | 22 | void setup() 23 | { 24 | AssignChannel ac; 25 | ResetSystem rs; 26 | SetNetworkKey snk; 27 | ChannelId ci; 28 | ChannelPeriod cp; 29 | ChannelRfFrequency crf; 30 | BroadcastDataMsg bm; 31 | OpenChannel oc; 32 | 33 | Serial1.begin(BAUD_RATE); 34 | ant.setSerial(Serial1); 35 | ant.send(rs); 36 | // Delay after resetting the radio to give the user time to connect on serial 37 | delay(10000); 38 | Serial.begin(9600); 39 | Serial.println("Running"); 40 | parseMessage(); 41 | 42 | snk = SetNetworkKey(); 43 | snk.setNetwork(0); 44 | snk.setKey((uint8_t*)NETWORK_KEY); 45 | ant.send(snk); 46 | parseMessage(); 47 | 48 | ac = AssignChannel(); 49 | ac.setChannel(0); 50 | ac.setChannelType(CHANNEL_TYPE_BIDIRECTIONAL_TRANSMIT); //can't wildcard this 51 | ac.setChannelNetwork(0); 52 | ant.send(ac); 53 | parseMessage(); 54 | 55 | ci = ChannelId(); 56 | ci.setChannel(0); 57 | ci.setDeviceNumber(0); 58 | ci.setDeviceType(0); 59 | ci.setTransmissionType(0); 60 | ant.send(ci); 61 | parseMessage(); 62 | 63 | cp = ChannelPeriod(); 64 | cp.setChannel(0); 65 | cp.setPeriod(1234); //can't wildcard this 66 | ant.send(cp); 67 | parseMessage(); 68 | 69 | crf = ChannelRfFrequency(); 70 | crf.setChannel(0); 71 | crf.setRfFrequency(0); //can't wildcard this 72 | ant.send(crf); 73 | parseMessage(); 74 | 75 | bm = BroadcastDataMsg(); 76 | bm.setDataBuffer(buffer); 77 | bm.setChannel(0); 78 | ant.send(bm); 79 | parseMessage(); 80 | 81 | oc = OpenChannel(); 82 | oc.setChannel(0); 83 | ant.send(oc); 84 | parseMessage(); 85 | } 86 | 87 | void loop() 88 | { 89 | parseMessage(); 90 | } 91 | 92 | void parseMessage() { 93 | ant.readPacket(); 94 | if(ant.getResponse().isAvailable()) 95 | { 96 | uint8_t msgId = ant.getResponse().getMsgId(); 97 | switch (msgId) { 98 | case CHANNEL_EVENT: 99 | { 100 | ChannelEventResponse cer = ChannelEventResponse(); 101 | ant.getResponse().getChannelEventResponseMsg(cer); 102 | Serial.println("Received Msg: ChannelEventResponse"); 103 | Serial.print("Channel: "); 104 | Serial.println(cer.getChannelNumber()); 105 | parseEventMessage(cer.getCode()); 106 | break; 107 | } 108 | 109 | case START_UP_MESSAGE: 110 | { 111 | StartUpMessage sum = StartUpMessage(); 112 | ant.getResponse().getStartUpMsg(sum); 113 | Serial.println("Received Msg: StartupMessage"); 114 | Serial.print("Message: "); 115 | Serial.println(sum.getMessage()); 116 | break; 117 | } 118 | 119 | default: 120 | Serial.print("Undefined Message: "); 121 | Serial.println(msgId, HEX); 122 | break; 123 | } 124 | } 125 | else if (ant.getResponse().isError()) 126 | { 127 | Serial.print("ANT MSG ERROR: "); 128 | Serial.println(ant.getResponse().getErrorCode()); 129 | } 130 | } 131 | 132 | void parseEventMessage(uint8_t code) 133 | { 134 | BroadcastDataMsg bm; 135 | Serial.print("Code: "); 136 | switch (code) 137 | { 138 | case STATUS_RESPONSE_NO_ERROR: 139 | Serial.println("RESPONSE_NO_ERROR"); 140 | break; 141 | 142 | case STATUS_EVENT_CHANNEL_CLOSED: 143 | Serial.println("EVENT_CHANNEL_CLOSED"); 144 | break; 145 | 146 | case STATUS_EVENT_TX: 147 | Serial.println("EVENT_TX"); 148 | buffer[0]++; 149 | bm = BroadcastDataMsg(); 150 | bm.setDataBuffer(buffer); 151 | bm.setChannel(0); 152 | ant.send(bm); 153 | break; 154 | 155 | default: 156 | Serial.println(code); 157 | break; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /img/library_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cujomalainey/ant-arduino/da24c50177ee84a817a32bfed6b91111f8c99022/img/library_layout.png -------------------------------------------------------------------------------- /img/object_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cujomalainey/ant-arduino/da24c50177ee84a817a32bfed6b91111f8c99022/img/object_layout.png -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | Ant KEYWORD1 2 | AntResponse KEYWORD1 3 | readPacket KEYWORD2 4 | readPacketUntilAvailable KEYWORD2 5 | begin KEYWORD2 6 | send KEYWORD2 7 | getResponse KEYWORD2 8 | setSerial KEYWORD2 9 | 10 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ANT", 3 | "keywords": "ant, protocol, radio, rf", 4 | "description": "Multi Protocol ANT radio support", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/cujomalainey/ant-arduino.git" 9 | }, 10 | "version": "2.0.3", 11 | "frameworks": "arduino, mbed", 12 | "platforms": "*", 13 | "headers": "ANT.h" 14 | } 15 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ANT-Arduino 2 | version=2.0.3 3 | author=Curtis Malainey 4 | maintainer=Curtis Malainey 5 | sentence=Library for communicating with various ANT radios from Dynastream Innovations. 6 | paragraph=Support for Serial or Softdevice based radios. Can be configured to work in the ANT+ ecosystem. 7 | category=Communication 8 | url=https://github.com/cujomalainey/ant-arduino 9 | architectures=* 10 | includes=ANT.h 11 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | # 2 | # Project Configuration File 3 | # 4 | # A detailed documentation with the EXAMPLES is located here: 5 | # http://docs.platformio.org/en/latest/projectconf.html 6 | # 7 | 8 | # A sign `#` at the beginning of the line indicates a comment 9 | # Comment lines are ignored. 10 | 11 | # Simple and base environment 12 | # [env:mybaseenv] 13 | # platform = %INSTALLED_PLATFORM_NAME_HERE% 14 | # framework = 15 | # board = 16 | # 17 | # Automatic targets - enable auto-uploading 18 | # targets = upload 19 | 20 | [env:teensy31-arduino] 21 | platform = teensy 22 | framework = arduino 23 | board = teensy31 24 | 25 | [env:teensy31-mbed] 26 | platform = teensy 27 | framework = mbed 28 | board = teensy31 29 | 30 | [env:native] 31 | platform = native 32 | test_build_src = true 33 | build_flags = -Wno-c++11-extensions -std=c++11 34 | 35 | [env:huzzah32] 36 | platform = espressif32 37 | framework = arduino 38 | board = featheresp32 39 | 40 | [env:nrf52_express] 41 | board = adafruit_feather_nrf52840_s340 42 | framework = arduino 43 | platform = https://github.com/cujomalainey/platform-nordicnrf52.git#develop 44 | ; upload_protocol = jlink 45 | 46 | [env:seeed_xiao] 47 | platform = https://github.com/maxgerhardt/platform-nordicnrf52 48 | board = xiaoblesense 49 | framework = arduino 50 | -------------------------------------------------------------------------------- /src/ANT.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 Curtis Malainey. All rights reserved. 3 | * 4 | * This file is part of Ant-Arduino. 5 | * 6 | * Ant-Arduino is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * Ant-Arduino is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with Ant-Arduino. If not, see . 18 | */ 19 | 20 | #ifndef ANT_h 21 | #define ANT_h 22 | 23 | /* Arbitrary Data Definitions */ 24 | #include 25 | 26 | /* Available Main Classes */ 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | // #include 34 | // #include 35 | // #include 36 | // #include 37 | 38 | /* Messages */ 39 | #include 40 | #include 41 | 42 | #endif // ANT_h 43 | -------------------------------------------------------------------------------- /src/ANT_private_defines.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Private definitions for the library 3 | * Users of the library do not need to use this and 4 | * the header is not available by default 5 | */ 6 | #ifndef ANT_PRIVATE_DEFINES_h 7 | #define ANT_PRIVATE_DEFINES_h 8 | 9 | #include 10 | 11 | #define ANT_START_BYTE 0xA4 12 | 13 | // start/length/msg/checksum bytes 14 | #define ANT_MSG_OVERHEAD_LENGTH 4 15 | // msg is always the third byte in packet 16 | #define ANT_MSG_ID_INDEX 3 17 | #define ANT_MSG_FRONT_OVERHEAD 3 18 | 19 | /** 20 | * Message Length Defines 21 | */ 22 | #define ACKNOWLEDGED_DATA_LENGTH 0x09 23 | #define ADD_CHANNEL_ID_TO_LIST_LENGTH 0x06 24 | #define ADD_ENCRYPTION_ID_TO_LIST_LENGTH 0x06 25 | #define ADVANCED_BURST_DATA_LENGTH 0x09 26 | #define ASSIGN_CHANNEL_LENGTH 0x03 27 | #define BROADCAST_DATA_LENGTH 0x09 28 | #define BURST_DATA_TRANSFER_LENGTH 0x09 29 | #define BURST_TRANSFER_DATA_LENGTH 0x09 30 | #define CHANNEL_ID_LENGTH 0x05 31 | #define CHANNEL_PERIOD_LENGTH 0x03 32 | #define CHANNEL_RF_FREQUENCY_LENGTH 0x02 33 | #define CHANNEL_SEARCH_PRIORITY_LENGTH 0x02 34 | #define CHANNEL_SEARCH_SHARING_LENGTH 0x02 35 | #define CLOSE_CHANNEL_LENGTH 0x01 36 | #define CONFIG_ENCRYPTION_ID_LIST_LENGTH 0x03 37 | #define CONFIG_ID_LIST_LENGTH 0x03 38 | #define CONFIGURE_ADVANCED_BURST_LENGTH 0x0C 39 | #define CONFIGURE_EVENT_FILTER_LENTGH 0x03 40 | #define CONFIGURE_SELECTIVE_DATA_UPDATES_LENGTH 0x02 41 | #define CW_INIT_LENGTH 0x01 42 | #define CW_TEST_LENGTH 0x03 43 | #define ENABLE_EXT_RX_MESSAGES_LENGTH 0x02 44 | #define ENABLE_SINGLE_CHANNEL_ENCRYPTION_LENGTH 0x04 45 | #define FREQUENCY_AGILITY_LENGTH 0x04 46 | #define LIB_CONFIG_LENGTH 0x02 47 | #define LOW_PRIORITY_SEARCH_TIMEOUT_LENGTH 0x02 48 | #define OPEN_CHANNEL_LENGTH 0x01 49 | #define OPEN_RX_SCAN_MODE_LENGTH 0x01 50 | #define PROXIMITY_SEARCH_LENGTH 0x02 51 | #define REQUEST_MESSAGE_LENGTH 0x02 52 | #define RESET_SYSTEM_LENGTH 0x01 53 | #define SEARCH_TIMEOUT_LENGTH 0x02 54 | #define SEARCH_WAVEFORM_LENGTH 0x03 55 | #define SERIAL_NUMBER_SET_CHANNEL_ID_LENGTH 0x03 56 | #define SET_CHANNEL_TRANSMIT_POWER_LENGTH 0x02 57 | #define SET_ENCRYPTION_INFO_LENGTH 0x01 58 | #define SET_ENCRYPTION_KEY_LENGTH 0x11 59 | #define SET_NETWORK_KEY_LENGTH 0x09 60 | #define TRANSMIT_POWER_LENGTH 0x02 61 | #define UNASSIGN_CHANNEL_LENGTH 0x01 62 | 63 | /** 64 | * Channel Status BitField Defines 65 | */ 66 | #define CHANNEL_STATUS_STATE_MASK 0x03 67 | #define CHANNEL_STATUS_NETWORK_NUMBER_SHIFT 0x02 68 | #define CHANNEL_STATUS_NETWORK_NUMBER_MASK 0x03 69 | #define CHANNEL_STATUS_CHANNEL_TYPE_SHIFT 0x04 70 | 71 | /** 72 | * Config ID List Defines 73 | */ 74 | #define CONFIG_ID_LIST_LIST_MAX_SIZE 0x04 75 | 76 | /** 77 | * Advanced burst defines 78 | */ 79 | #define ADVANCED_BURST_DATA_CHANNEL_MASK 0x1F 80 | #define ADVANCED_BURST_DATA_SEQUENCENUMBER_SHIFT 5 81 | 82 | /** 83 | * Configure Selective Data Updates defines 84 | */ 85 | #define CONFIGURE_SELECTIVE_DATA_UPDATES_SDU_DISABLE 0xFF 86 | #define CONFIGURE_SELECTIVE_DATA_UPDATES_SDU_NUMBER_MASK 0x1F 87 | #define CONFIGURE_SELECTIVE_DATA_UPDATES_FILTER_BIT_MASK 0x80 88 | 89 | /** 90 | * Extended Data definitions 91 | */ 92 | #define EXTENDEDDATA_FLAGBYTE_BYTE 9 93 | #define EXTENDEDDATA_DEVICENUMBER_LSB_BYTE 10 94 | #define EXTENDEDDATA_DEVICENUMBER_MSB_BYTE 11 95 | #define EXTENDEDDATA_DEVICENUMBER_MSB_SHIFT 8 96 | #define EXTENDEDDATA_DEVICETYPE_BYTE 12 97 | #define EXTENDEDDATA_TRANSMISSIONTYPE_BYTE 13 98 | #define EXTENDEDDATA_CHANNELID_SIZE 4 99 | #define EXTENDEDDATA_MEASUREMENTTYPE_BYTE 10 100 | #define EXTENDEDDATA_RSSIVALUE_BYTE 11 101 | #define EXTENDEDDATA_THRESHOLDCONFIGURATIONVALUE_BYTE 12 102 | #define EXTENDEDDATA_RSSIOUTPUT_SIZE 3 103 | #define EXTENDEDDATA_RXTIMESTAMP_LSB_BYTE 10 104 | #define EXTENDEDDATA_RXTIMESTAMP_MSB_BYTE 11 105 | #define EXTENDEDDATA_RXTIMESTAMP_MSB_SHIFT 8 106 | 107 | /** 108 | * Default data message length 109 | */ 110 | #define BROADCASTDATA_DEFAULT_MSG_LENGTH 9 111 | #define ACKNOWLEDGEDDATA_DEFAULT_MSG_LENGTH 9 112 | #define BURSTTRANSFERDATA_DEFAULT_MSG_LENGTH 9 113 | 114 | #endif // ANT_PRIVATE_DEFINES_h 115 | -------------------------------------------------------------------------------- /src/BaseClasses/ANT_BaseAnt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | BaseAnt::BaseAnt(): _response(AntResponse()) { 4 | _response.init(); 5 | } 6 | 7 | AntResponse& BaseAnt::getResponse() { 8 | return _response; 9 | } 10 | 11 | void BaseAnt::getResponse(AntResponse &response) { 12 | 13 | response.setLength(_response.getLength()); 14 | response.setMsgId(_response.getMsgId()); 15 | response.setFrameData(_response.getFrameData()); 16 | } 17 | 18 | // cppcheck-suppress unusedFunction 19 | void BaseAnt::readPacketUntilAvailable() { 20 | while (!(getResponse().isAvailable() || getResponse().isError())) { 21 | // read some more 22 | readPacket(); 23 | } 24 | } 25 | 26 | bool BaseAnt::readPacket(int timeout) { 27 | 28 | if (timeout < 0) { 29 | return false; 30 | } 31 | 32 | unsigned long start = getMs(); 33 | 34 | while (int((getMs() - start)) < timeout) { 35 | 36 | readPacket(); 37 | 38 | if (getResponse().isAvailable()) { 39 | return true; 40 | } else if (getResponse().isError()) { 41 | return false; 42 | } 43 | } 44 | 45 | // timed out 46 | return false; 47 | } 48 | 49 | uint8_t BaseAnt::bufferMessage(uint8_t *buf, AntRequest &request, uint8_t checksum) { 50 | uint8_t write_pos = 0; 51 | 52 | // write length 53 | checksum ^= request.getDataLength(); 54 | buf[write_pos++] = request.getDataLength(); 55 | 56 | // write msg id 57 | buf[write_pos++] = request.getMsgId(); 58 | checksum ^= request.getMsgId(); 59 | 60 | for (int i = 0; i < request.getDataLength(); i++) { 61 | buf[write_pos++] = request.getData(i); 62 | checksum ^= request.getData(i); 63 | } 64 | 65 | // write checksum 66 | buf[write_pos++] = checksum; 67 | 68 | return write_pos; 69 | } 70 | -------------------------------------------------------------------------------- /src/BaseClasses/ANT_BaseAnt.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_BASEANT_h 2 | #define ANT_BASEANT_h 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | class BaseAnt { 12 | public: 13 | BaseAnt(); 14 | /** 15 | * Checks to see if a packet is available 16 | * You may call ant.getResponse().isAvailable() after calling this method to determine if 17 | * a packet is ready, or ant.getResponse().isError() to determine if 18 | * a error occurred. 19 | *

20 | * This method will always return quickly with the native interface. 21 | * You will want to use this method if you are doing other timely stuff in your loop, where 22 | * a delay would cause problems. 23 | * NOTE: calling this method resets the current response, so make sure you first consume the 24 | * current response 25 | */ 26 | virtual void readPacket() = 0; 27 | /** 28 | * Waits a maximum of timeout milliseconds for a response packet before timing out; returns true if packet is read. 29 | * Returns false if timeout or error occurs. 30 | */ 31 | bool readPacket(int timeout); 32 | /** 33 | * Reads until a packet is received or an error occurs. 34 | * Caution: use this carefully since if you don't get a response, your Arduino code will hang on this 35 | * call forever!! often it's better to use a timeout: readPacket(int) 36 | */ 37 | void readPacketUntilAvailable(); 38 | void getResponse(AntResponse &response); 39 | /** 40 | * Returns a reference to the current response 41 | * Note: once readPacket is called again this response will be overwritten! 42 | */ 43 | AntResponse& getResponse(); 44 | /** 45 | * Sends a AntRequest (TX packet) 46 | */ 47 | virtual void send(AntRequest &request) = 0; 48 | protected: 49 | virtual uint32_t getMs() = 0; 50 | uint8_t bufferMessage(uint8_t *buf, AntRequest &msg, uint8_t checksum); 51 | private: 52 | AntResponse _response; 53 | }; 54 | 55 | #endif // ANT_BASEANT_h 56 | -------------------------------------------------------------------------------- /src/BaseClasses/ANT_BaseFramework.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_BASEFRAMEWORK_h 2 | #define ANT_BASEFRAMEWORK_h 3 | 4 | #if (defined(__MBED__) && !defined(ARDUINO)) 5 | #define IS_MBED 6 | #endif 7 | 8 | #ifdef UNIT_TEST 9 | #include 10 | #include "Util/Testing.h" 11 | #elif defined(ARDUINO) 12 | #include "Arduino.h" 13 | #elif IS_MBED 14 | #include "mbed.h" 15 | #endif 16 | 17 | #endif // ANT_BASEFRAMEWORK_h 18 | -------------------------------------------------------------------------------- /src/BaseClasses/ANT_BaseNativeAnt.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_BASENATIVEANT_h 2 | #define ANT_BASENATIVEANT_h 3 | 4 | #include 5 | 6 | #ifdef NATIVE_API_AVAILABLE 7 | 8 | /** 9 | * Primary interface for communicating with an Ant Radio via serial. 10 | * This class provides methods for sending and receiving packets with an Ant radio via the serial port. 11 | * The Ant radio must be configured with the network stack 12 | * in order to use this software. 13 | *

14 | * Since this code is designed to run on a microcontroller, with only one thread, you are responsible for reading the 15 | * data off the serial buffer in a timely manner. This involves a call to a variant of readPacket(...). 16 | * If your serial port is receiving data faster than you are reading, you can expect to lose packets. 17 | * Arduino only has a 128 byte serial buffer so it can overflow if many packets arrive 18 | * without a call to readPacket(...) 19 | *

20 | * In order to conserve resources, this class only supports storing one response packet in memory at a time. 21 | * This means that you must fully consume the packet prior to calling readPacket(...), because calling 22 | * readPacket(...) overwrites the previous response. 23 | *

24 | * This class creates an array of size MAX_FRAME_DATA_SIZE for storing the response packet. You may want 25 | * to adjust this value to conserve memory. 26 | * 27 | * \author Andrew Rapp 28 | * \edited by Curtis Malainey 29 | */ 30 | 31 | class BaseNativeAnt : virtual public BaseAnt { 32 | public: 33 | BaseNativeAnt(); 34 | /** 35 | * Will read as much data on the serial port as possible till either it has a packet, gets an error or runs out of data 36 | * You may call ant.getResponse().isAvailable() after calling this method to determine if 37 | * a packet is ready, or ant.getResponse().isError() to determine if 38 | * a error occurred. 39 | *

40 | * This method should return quickly as it only works with what is available 41 | * You will want to use this method if you are doing other timely stuff in your loop, where 42 | * a delay would cause problems. 43 | * NOTE: calling this method resets the current response, so make sure you first consume the 44 | * current response 45 | */ 46 | void readPacket() override; 47 | /** 48 | * Starts the serial connection on the specified serial port 49 | */ 50 | uint8_t begin(uint8_t total_chan, uint8_t encrypted_chan); 51 | /** 52 | * Sends a AntRequest (TX packet) out the serial port 53 | */ 54 | void send(AntRequest &request) override; 55 | private: 56 | void resetResponse(); 57 | uint32_t handleRequest(AntRequest &request); 58 | bool _backFillReady = false; 59 | bool _returnFillReady = false; 60 | // buffer for incoming RX packets. Backfill data structures for message reuse. 61 | ANT_MESSAGE _responseFrameData; 62 | // used for TX requests so TX won't overwrite RX state 63 | ANT_MESSAGE _backFillBuffer; 64 | // used to store response message 65 | ANT_MESSAGE _returnFillBuffer; 66 | // softdevice buffer 67 | uint8_t *_sd_buffer = NULL; 68 | }; 69 | 70 | #endif // NATIVE_API_AVAILABLE 71 | 72 | #endif // ANT_BASENATIVEANT_h 73 | -------------------------------------------------------------------------------- /src/BaseClasses/ANT_BaseSerialAnt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template 5 | BaseSerialAnt::BaseSerialAnt() : BaseAnt() { 6 | _pos = 0; 7 | _checksumTotal = 0; 8 | getResponse().setFrameData(_responseFrameData); 9 | 10 | } 11 | 12 | template 13 | void BaseSerialAnt::resetResponse() { 14 | _pos = 0; 15 | _checksumTotal = 0; 16 | getResponse().reset(); 17 | } 18 | 19 | template 20 | void BaseSerialAnt::begin(T &serial) { 21 | setSerial(serial); 22 | } 23 | 24 | template 25 | void BaseSerialAnt::readPacket() { 26 | // reset previous response 27 | if (getResponse().isAvailable() || getResponse().isError()) { 28 | // discard previous packet and start over 29 | resetResponse(); 30 | } 31 | 32 | while (available()) { 33 | 34 | b = read(); 35 | 36 | // checksum includes all bytes including the sync 37 | _checksumTotal ^= b; 38 | 39 | switch(_pos) { 40 | case 0: 41 | if (b == ANT_START_BYTE) { 42 | _pos++; 43 | } 44 | // TODO should we be reseting the checksum here if we fail to match the start byte? 45 | 46 | break; 47 | case 1: 48 | // length msb 49 | getResponse().setLength(b); 50 | _pos++; 51 | 52 | break; 53 | case 2: 54 | getResponse().setMsgId(b); 55 | _pos++; 56 | 57 | break; 58 | default: 59 | // starts at fourth byte 60 | 61 | if (_pos > ANT_MAX_MSG_DATA_SIZE) { 62 | // exceed max size. should never occur 63 | getResponse().setErrorCode(PACKET_EXCEEDS_BYTE_ARRAY_LENGTH); 64 | return; 65 | } 66 | 67 | // check if we're at the end of the packet 68 | if (_pos == (getResponse().getLength() + 3)) { 69 | // verify checksum 70 | // if the last byte is the checksum 71 | // then XOR it with itself should be 0 72 | 73 | if (_checksumTotal == 0) { 74 | getResponse().setChecksum(b); 75 | getResponse().setAvailable(true); 76 | 77 | getResponse().setErrorCode(NO_ERROR); 78 | } else { 79 | // checksum failed 80 | getResponse().setErrorCode(CHECKSUM_FAILURE); 81 | } 82 | 83 | // reset state vars 84 | _pos = 0; 85 | 86 | return; 87 | } else { 88 | // add to packet array, starting with the fourth byte of the msgId 89 | getResponse().getFrameData()[_pos - ANT_MSG_FRONT_OVERHEAD] = b; 90 | _pos++; 91 | } 92 | } 93 | } 94 | } 95 | 96 | template 97 | void BaseSerialAnt::send(AntRequest &request) { 98 | // checksum is XOR of all bytes 99 | uint8_t checksum = 0; 100 | uint8_t write_pos = 0; 101 | uint8_t buf[ANT_MAX_MSG_DATA_SIZE]; 102 | 103 | checksum ^= ANT_START_BYTE; 104 | buf[write_pos++] = ANT_START_BYTE; 105 | 106 | write_pos += bufferMessage(&buf[write_pos], request, checksum); 107 | 108 | write(buf, write_pos); 109 | } 110 | 111 | #if defined(ARDUINO) || defined(UNIT_TEST) 112 | template class BaseSerialAnt; 113 | #endif 114 | #ifdef IS_MBED 115 | template class BaseSerialAnt; 116 | #endif 117 | -------------------------------------------------------------------------------- /src/BaseClasses/ANT_BaseSerialAnt.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_BASESERIALANT_h 2 | #define ANT_BASESERIALANT_h 3 | 4 | #include 5 | 6 | /** 7 | * Primary interface for communicating with an Ant Radio via serial. 8 | * This class provides methods for sending and receiving packets with an Ant radio via the serial port. 9 | * The Ant radio must be configured with the network stack 10 | * in order to use this software. 11 | *

12 | * Since this code is designed to run on a microcontroller, with only one thread, you are responsible for reading the 13 | * data off the serial buffer in a timely manner. This involves a call to a variant of readPacket(...). 14 | * If your serial port is receiving data faster than you are reading, you can expect to lose packets. 15 | * Arduino only has a 128 byte serial buffer so it can overflow if many packets arrive 16 | * without a call to readPacket(...) 17 | *

18 | * In order to conserve resources, this class only supports storing one response packet in memory at a time. 19 | * This means that you must fully consume the packet prior to calling readPacket(...), because calling 20 | * readPacket(...) overwrites the previous response. 21 | *

22 | * This class creates an array of size MAX_FRAME_DATA_SIZE for storing the response packet. You may want 23 | * to adjust this value to conserve memory. 24 | * 25 | * \author Andrew Rapp 26 | * \edited by Curtis Malainey 27 | */ 28 | 29 | template 30 | class BaseSerialAnt : virtual public BaseAnt { 31 | public: 32 | BaseSerialAnt(); 33 | /** 34 | * Will read as much data on the serial port as possible till either it has a packet, gets an error or runs out of data 35 | * You may call ant.getResponse().isAvailable() after calling this method to determine if 36 | * a packet is ready, or ant.getResponse().isError() to determine if 37 | * a error occurred. 38 | *

39 | * This method should return quickly as it only works with what is available 40 | * You will want to use this method if you are doing other timely stuff in your loop, where 41 | * a delay would cause problems. 42 | * NOTE: calling this method resets the current response, so make sure you first consume the 43 | * current response 44 | */ 45 | void readPacket() override; 46 | /** 47 | * Starts the serial connection on the specified serial port 48 | */ 49 | void begin(T &serial); 50 | /** 51 | * Sends a AntRequest (TX packet) out the serial port 52 | */ 53 | void send(AntRequest &request) override; 54 | /** 55 | * Associates a serial device with the ANT driver 56 | */ 57 | virtual void setSerial(T &serial) = 0; 58 | protected: 59 | virtual uint8_t read() = 0; 60 | virtual uint8_t available() = 0; 61 | virtual void write(uint8_t* byte, uint8_t len) = 0; 62 | private: 63 | void resetResponse(); 64 | // current packet position for response. just a state variable for packet parsing and has no relevance for the response otherwise 65 | uint8_t _pos; 66 | // last byte read 67 | uint8_t b; 68 | uint8_t _checksumTotal; 69 | // buffer for incoming RX packets. holds only the msg specific frame data, starting after the msg id byte and prior to checksum 70 | uint8_t _responseFrameData[ANT_MAX_MSG_DATA_SIZE]; 71 | }; 72 | 73 | #endif // ANT_BASESERIALANT_h 74 | -------------------------------------------------------------------------------- /src/BaseClasses/ANT_BaseSpiAnt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | template 6 | BaseSpiAnt::BaseSpiAnt() : BaseAnt() { 7 | getResponse().setFrameData(_responseFrameData); 8 | 9 | } 10 | 11 | template 12 | void BaseSpiAnt::resetResponse() { 13 | _pos = 0; 14 | _checksumTotal = 0; 15 | getResponse().reset(); 16 | } 17 | 18 | template 19 | void BaseSpiAnt::begin(S &spi, I &hostEnable, O &hostMsgReady, O &hostSrdy) { 20 | setSpi(spi, hostEnable, hostMsgReady, hostSrdy); 21 | } 22 | 23 | template 24 | void BaseSpiAnt::readPacket() { 25 | // reset previous response 26 | if (getResponse().isAvailable() || getResponse().isError()) { 27 | // discard previous packet and start over 28 | resetResponse(); 29 | } 30 | 31 | while (available()) { 32 | 33 | b = read(); 34 | 35 | // checksum includes all bytes including the sync 36 | _checksumTotal ^= b; 37 | 38 | switch(_pos) { 39 | case 0: 40 | if (b == ANT_START_BYTE) { 41 | _pos++; 42 | } 43 | // TODO should we be reseting the checksum here if we fail to match the start byte? 44 | 45 | break; 46 | case 1: 47 | // length msb 48 | getResponse().setLength(b); 49 | _pos++; 50 | 51 | break; 52 | case 2: 53 | getResponse().setMsgId(b); 54 | _pos++; 55 | 56 | break; 57 | default: 58 | // starts at fourth byte 59 | 60 | if (_pos > ANT_MAX_MSG_DATA_SIZE) { 61 | // exceed max size. should never occur 62 | getResponse().setErrorCode(PACKET_EXCEEDS_BYTE_ARRAY_LENGTH); 63 | return; 64 | } 65 | 66 | // check if we're at the end of the packet 67 | if (_pos == (getResponse().getLength() + 3)) { 68 | // verify checksum 69 | // if the last byte is the checksum 70 | // then XOR it with itself should be 0 71 | 72 | if (_checksumTotal == 0) { 73 | getResponse().setChecksum(b); 74 | getResponse().setAvailable(true); 75 | 76 | getResponse().setErrorCode(NO_ERROR); 77 | } else { 78 | // checksum failed 79 | getResponse().setErrorCode(CHECKSUM_FAILURE); 80 | } 81 | 82 | // reset state vars 83 | _pos = 0; 84 | 85 | return; 86 | } else { 87 | // add to packet array, starting with the fourth byte of the msgId 88 | getResponse().getFrameData()[_pos - ANT_MSG_FRONT_OVERHEAD] = b; 89 | _pos++; 90 | } 91 | } 92 | } 93 | } 94 | 95 | // TODO remove 96 | #define SYNC_MASK 0xFE 97 | #define SYNC_BYTE 0xA4 98 | #define SYNC_READ_BIT 1 99 | #define SUCCESS 0 100 | template 101 | void BaseSpiAnt::send(AntRequest &request) { 102 | uint8_t sync, packetRead = 0; 103 | uint8_t write_pos = 0; 104 | uint8_t checksum = 0; 105 | uint8_t buf[ANT_MAX_MSG_DATA_SIZE]; 106 | 107 | setHostMsgReady(0); 108 | 109 | // block until radio acks 110 | while(available()) {} 111 | 112 | setHostSRdy(0); 113 | 114 | sync = read(); 115 | 116 | if ((sync & SYNC_MASK) != SYNC_BYTE) { 117 | setHostSRdy(1); 118 | } 119 | 120 | // ant synced as a write 121 | // read back and send write next 122 | if (!(sync & SYNC_READ_BIT)) { 123 | _pos = 1; 124 | // readPacket(); 125 | setHostMsgReady(1); 126 | packetRead = 1; 127 | 128 | // block until radio acks 129 | while(!available()) {} 130 | 131 | sync = read(); 132 | } 133 | 134 | // buffer initial byte 135 | // TODO does this need write bit set? 136 | checksum ^= ANT_START_BYTE; 137 | buf[write_pos++] = ANT_START_BYTE; 138 | 139 | write_pos += bufferMessage(&buf[write_pos], request, checksum); 140 | 141 | // TODO rewrite buffer write 142 | // data, offset for start byte sent by radio 143 | write(buf[0]); 144 | 145 | } 146 | 147 | template 148 | // cppcheck-suppress unusedFunction 149 | void BaseSpiAnt::resetRadio() { 150 | setHostMsgReady(1); 151 | setHostSRdy(1); 152 | setHostSRdy(0); 153 | // TODO wait 1 ms 154 | setHostMsgReady(0); 155 | setHostSRdy(1); 156 | } 157 | 158 | #ifdef IS_MBED 159 | template class BaseSpiAnt; 160 | #endif 161 | -------------------------------------------------------------------------------- /src/BaseClasses/ANT_BaseSpiAnt.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_BASESPIANT_h 2 | #define ANT_BASESPIANT_h 3 | 4 | #include 5 | 6 | /** 7 | * Primary interface for communicating with an Ant Radio via SPI. 8 | * This class provides methods for sending and receiving packets with an Ant radio via the serial port. 9 | * The Ant radio must be configured with the network stack 10 | * in order to use this software. 11 | *

12 | * Since this code is designed to run on a microcontroller, with only one thread, you are responsible for reading the 13 | * data off the serial buffer in a timely manner. This involves a call to a variant of readPacket(...). 14 | * If your serial port is receiving data faster than you are reading, you can expect to lose packets. 15 | * Arduino only has a 128 byte serial buffer so it can overflow if many packets arrive 16 | * without a call to readPacket(...) 17 | *

18 | * In order to conserve resources, this class only supports storing one response packet in memory at a time. 19 | * This means that you must fully consume the packet prior to calling readPacket(...), because calling 20 | * readPacket(...) overwrites the previous response. 21 | *

22 | * This class creates an array of size MAX_FRAME_DATA_SIZE for storing the response packet. You may want 23 | * to adjust this value to conserve memory. 24 | * 25 | * \author Andrew Rapp 26 | * \edited by Curtis Malainey 27 | */ 28 | 29 | template 30 | class BaseSpiAnt : virtual public BaseAnt { 31 | public: 32 | BaseSpiAnt(); 33 | /** 34 | * Will read as much data on the spi port as possible till either it has a packet, gets an error or runs out of data 35 | * You may call ant.getResponse().isAvailable() after calling this method to determine if 36 | * a packet is ready, or ant.getResponse().isError() to determine if 37 | * a error occurred. 38 | *

39 | * This method should return quickly as it only works with what is available 40 | * You will want to use this method if you are doing other timely stuff in your loop, where 41 | * a delay would cause problems. 42 | * NOTE: calling this method resets the current response, so make sure you first consume the 43 | * current response 44 | */ 45 | void readPacket() override; 46 | /** 47 | * Starts the serial connection on the specified serial port 48 | */ 49 | void begin(S &spi, I &hostEnable, O &hostMsgReady, O &hostSrdy); 50 | /** 51 | * Sends a AntRequest (TX packet) out the serial port 52 | */ 53 | void send(AntRequest &request) override; 54 | /** 55 | * Set communication device and pins 56 | */ 57 | virtual void setSpi(S &spi, I &hostEnable, O &hostMsgReady, O &hostSrdy) = 0; 58 | /** 59 | * Hardware reset radio using SPI wires without reset pin 60 | */ 61 | void resetRadio(); 62 | protected: 63 | virtual void setHostMsgReady(uint8_t value) = 0; 64 | virtual void setHostSRdy(uint8_t value) = 0; 65 | virtual uint8_t read() = 0; 66 | virtual uint8_t available() = 0; 67 | virtual void write(uint8_t byte) = 0; 68 | private: 69 | void resetResponse(); 70 | // current packet position for response. just a state variable for packet parsing and has no relevance for the response otherwise 71 | uint8_t _pos = 0; 72 | // last byte read 73 | uint8_t b; 74 | uint8_t _checksumTotal = 0; 75 | // buffer for incoming RX packets. holds only the msg specific frame data, starting after the msg id byte and prior to checksum 76 | uint8_t _responseFrameData[ANT_MAX_MSG_DATA_SIZE]; 77 | }; 78 | 79 | #endif // ANT_BASESPIANT_h 80 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_ArduinoNativeAnt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(ARDUINO) && defined(NATIVE_API_AVAILABLE) 4 | 5 | ArduinoNativeAnt::ArduinoNativeAnt() : BaseNativeAnt() {} 6 | 7 | uint32_t ArduinoNativeAnt::getMs() { 8 | return millis(); 9 | } 10 | 11 | #endif // defined(ARDUINO) && defined(NATIVE_API_AVAILABLE) 12 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_ArduinoNativeAnt.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ARDUINONATIVEANT_h 2 | #define ANT_ARDUINONATIVEANT_h 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #if defined(ARDUINO) && defined(NATIVE_API_AVAILABLE) 12 | 13 | /** 14 | * Native adapter interface for communicating with an Ant softdevice. 15 | * This class provides methods for sending and receiving packets with an Ant radio via the native api. 16 | * This class must run on an nRF device with an ANT enabled soft device. 17 | *

18 | * Since this code is designed to run on a microcontroller, you are responsible for reading the 19 | * data off the system buffer in a timely manner. This involves a call to a variant of readPacket(...). 20 | * If your system is receiving data faster than you are reading, you can expect to lose packets. 21 | *

22 | * In order to conserve resources, this class only supports storing one response packet in memory at a time. 23 | * This means that you must fully consume the packet prior to calling readPacket(...), because calling 24 | * readPacket(...) overwrites the previous response. 25 | *

26 | * This class creates an array of size MAX_SD_DATA_SIZE for storing the response packet. 27 | * Unlike the other classes, DO NOT MODIFY THIS VALUE. 28 | * 29 | * \author Curtis Malainey 30 | */ 31 | 32 | class ArduinoNativeAnt : public virtual BaseNativeAnt { 33 | public: 34 | ArduinoNativeAnt(); 35 | protected: 36 | uint32_t getMs() override; 37 | }; 38 | 39 | #endif // defined(ARDUINO) && defined(NATIVE_API_AVAILABLE) 40 | 41 | #endif // ANT_ARDUINONATIVEANT_h 42 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_ArduinoNativeAntWithCallbacks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(ARDUINO) && defined(NATIVE_API_AVAILABLE) 4 | 5 | ArduinoNativeAntWithCallbacks::ArduinoNativeAntWithCallbacks() : ArduinoNativeAnt(), BaseAntWithCallbacks() {} 6 | 7 | #endif // defined(ARDUINO) && defined(NATIVE_API_AVAILABLE) 8 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_ArduinoNativeAntWithCallbacks.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ARDUINONATIVEANTWITHCALLBACKS_h 2 | #define ANT_ARDUINONATIVEANTWITHCALLBACKS_h 3 | 4 | #include 5 | #include 6 | 7 | #if defined(ARDUINO) && defined(NATIVE_API_AVAILABLE) 8 | 9 | class ArduinoNativeAntWithCallbacks : public ArduinoNativeAnt, public BaseAntWithCallbacks { 10 | public: 11 | ArduinoNativeAntWithCallbacks(); 12 | }; 13 | 14 | #endif // defined(ARDUINO) && defined(NATIVE_API_AVAILABLE) 15 | 16 | #endif // ANT_ARDUINONATIVEANTWITHCALLBACKS_h 17 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_ArduinoSerialAnt.cpp: -------------------------------------------------------------------------------- 1 | #if defined(ARDUINO) || defined(UNIT_TEST) 2 | 3 | #include 4 | #include 5 | 6 | ArduinoSerialAnt::ArduinoSerialAnt() : BaseSerialAnt() { 7 | // Contributed by Paul Stoffregen for Teensy support 8 | #if defined(__AVR_ATmega32U4__) || defined(__MK20DX128__) 9 | setSerial(Serial1); 10 | #else 11 | setSerial(Serial); 12 | #endif 13 | } 14 | 15 | ArduinoSerialAnt::ArduinoSerialAnt(Stream &serial) : BaseSerialAnt(), _serial(&serial) {} 16 | 17 | void ArduinoSerialAnt::setSerial(Stream &serial) { 18 | _serial = &serial; 19 | } 20 | 21 | uint8_t ArduinoSerialAnt::available() { 22 | return _serial->available(); 23 | } 24 | 25 | uint8_t ArduinoSerialAnt::read() { 26 | return _serial->read(); 27 | } 28 | 29 | void ArduinoSerialAnt::write(uint8_t *data, uint8_t len) { 30 | _serial->write(data, len); 31 | } 32 | 33 | uint32_t ArduinoSerialAnt::getMs() { 34 | return millis(); 35 | } 36 | 37 | #endif // defined(ARDUINO) || defined(UNIT_TEST) 38 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_ArduinoSerialAnt.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ARDUINOSERIALANT_h 2 | #define ANT_ARDUINOSERIALANT_h 3 | 4 | #if defined(ARDUINO) || defined(UNIT_TEST) 5 | 6 | #include 7 | 8 | class ArduinoSerialAnt : virtual public BaseSerialAnt { 9 | public: 10 | ArduinoSerialAnt(); 11 | explicit ArduinoSerialAnt(Stream &serial); 12 | /** 13 | * Specify the serial port. Only relevant for Arduinos that support multiple serial ports (e.g. Mega) 14 | */ 15 | void setSerial(Stream &serial) override; 16 | protected: 17 | uint8_t available() override; 18 | uint8_t read() override; 19 | void write(uint8_t* data, uint8_t len) override; 20 | uint32_t getMs() override; 21 | Stream* _serial = NULL; 22 | }; 23 | 24 | #endif // defined(ARDUINO) || defined(UNIT_TEST) 25 | 26 | #endif // ANT_ARDUINOANT_h 27 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_ArduinoSerialAntWithCallbacks.cpp: -------------------------------------------------------------------------------- 1 | #if defined(ARDUINO) || defined(UNIT_TEST) 2 | 3 | #include 4 | 5 | ArduinoSerialAntWithCallbacks::ArduinoSerialAntWithCallbacks() : ArduinoSerialAnt(), BaseAntWithCallbacks() {} 6 | 7 | #endif // defined(ARDUINO) || defined(UNIT_TEST) 8 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_ArduinoSerialAntWithCallbacks.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ARDUINOSERIALANTWITHCALLBACKS_h 2 | #define ANT_ARDUINOSERIALANTWITHCALLBACKS_h 3 | 4 | #if defined(ARDUINO) || defined(UNIT_TEST) 5 | 6 | #include 7 | #include 8 | 9 | class ArduinoSerialAntWithCallbacks : public ArduinoSerialAnt, public BaseAntWithCallbacks { 10 | public: 11 | ArduinoSerialAntWithCallbacks(); 12 | }; 13 | 14 | #endif // defined(ARDUINO) || defined(UNIT_TEST) 15 | 16 | #endif // ANT_ARDUINOSERIALANTWITHCALLBACKS_h 17 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_MbedSerialAnt.cpp: -------------------------------------------------------------------------------- 1 | #ifdef IS_MBED 2 | 3 | #include 4 | #include 5 | 6 | MbedSerialAnt::MbedSerialAnt() : BaseSerialAnt() {} 7 | 8 | 9 | void MbedSerialAnt::setSerial(UARTSerial &serial) { 10 | _serial = &serial; 11 | } 12 | 13 | uint8_t MbedSerialAnt::available() { 14 | return _serial->readable(); 15 | } 16 | 17 | uint8_t MbedSerialAnt::read() { 18 | uint8_t buf; 19 | _serial->read(&buf, 1); 20 | return buf; 21 | } 22 | 23 | void MbedSerialAnt::write(uint8_t *buf, uint8_t len) { 24 | _serial->write(buf, len); 25 | } 26 | 27 | uint32_t MbedSerialAnt::getMs() { 28 | // TODO 29 | return 0; 30 | } 31 | 32 | 33 | #endif // IS_MBED 34 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_MbedSerialAnt.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_MBEDSERIALANT_h 2 | #define ANT_MBEDSERIALANT_h 3 | 4 | #include 5 | 6 | #ifdef IS_MBED 7 | 8 | #include 9 | 10 | class MbedSerialAnt : public BaseSerialAnt { 11 | public: 12 | MbedSerialAnt(); 13 | void setSerial(UARTSerial &serial) override; 14 | protected: 15 | uint8_t available() override; 16 | uint8_t read() override; 17 | void write(uint8_t *buf, uint8_t len) override; 18 | uint32_t getMs() override; 19 | UARTSerial* _serial; 20 | }; 21 | 22 | #endif // IS_MBED 23 | 24 | #endif // ANT_MBEDSERIALANT_h 25 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_MbedSerialAntWithCallbacks.cpp: -------------------------------------------------------------------------------- 1 | #if IS_MBED 2 | 3 | #include 4 | 5 | MbedSerialAntWithCallbacks::MbedSerialAntWithCallbacks() : MbedSerialAnt(), BaseAntWithCallbacks() {} 6 | 7 | #endif // IS_MBED 8 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_MbedSerialAntWithCallbacks.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_MBEDSERIALANTWITHCALLBACKS_h 2 | #define ANT_MBEDSERIALANTWITHCALLBACKS_h 3 | 4 | #include 5 | 6 | #ifdef IS_MBED 7 | 8 | #include 9 | #include 10 | 11 | class MbedSerialAntWithCallbacks : public MbedSerialAnt, public BaseAntWithCallbacks { 12 | public: 13 | MbedSerialAntWithCallbacks(); 14 | }; 15 | 16 | #endif // IS_MBED 17 | 18 | #endif // ANT_MBEDSERIALANTWITHCALLBACKS_h 19 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_MbedSpiAnt.cpp: -------------------------------------------------------------------------------- 1 | #ifdef IS_MBED 2 | 3 | #include 4 | #include 5 | 6 | MbedSpiAnt::MbedSpiAnt() : BaseSpiAnt() {} 7 | 8 | 9 | void MbedSpiAnt::setSpi(SPISlave &spi, DigitalIn &hostEnable, DigitalOut &hostMsgReady, DigitalOut &hostSrdy) { 10 | _spi = &spi; 11 | _hostEnable = &hostEnable; 12 | _hostMsgReady = &hostMsgReady; 13 | _hostSrdy = &hostSrdy; 14 | _hostMsgReady->write(1); 15 | _hostSrdy->write(1); 16 | } 17 | 18 | uint8_t MbedSpiAnt::available() { 19 | return _hostEnable->read(); 20 | } 21 | 22 | uint8_t MbedSpiAnt::read() { 23 | return _spi->read(); 24 | } 25 | 26 | void MbedSpiAnt::write(uint8_t val) { 27 | _spi->reply(val); 28 | } 29 | 30 | void MbedSpiAnt::setHostMsgReady(uint8_t value) { 31 | // _hostMsgReady->write(value); 32 | } 33 | 34 | void MbedSpiAnt::setHostSRdy(uint8_t value) { 35 | _hostSrdy->write(value); 36 | } 37 | 38 | uint32_t MbedSpiAnt::getMs() { 39 | // TODO 40 | return 0; 41 | } 42 | 43 | 44 | #endif // IS_MBED 45 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_MbedSpiAnt.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_MBEDSPIANT_h 2 | #define ANT_MBEDSPIANT_h 3 | 4 | #ifdef IS_MBED 5 | 6 | #include 7 | 8 | class MbedSpiAnt : public BaseSpiAnt { 9 | public: 10 | MbedSpiAnt(); 11 | void setSpi(SPISlave &spi, DigitalIn &hostEnable, DigitalOut &hostMsgReady, DigitalOut &hostSrdy) override; 12 | protected: 13 | void setHostMsgReady(uint8_t value) override; 14 | void setHostSRdy(uint8_t value) override; 15 | uint8_t available() override; 16 | uint8_t read() override; 17 | void write(uint8_t val) override; 18 | uint32_t getMs() override; 19 | private: 20 | SPISlave* _spi; 21 | DigitalOut* _hostMsgReady; 22 | DigitalOut* _hostSrdy; 23 | DigitalIn* _hostEnable; 24 | }; 25 | 26 | #endif // IS_MBED 27 | 28 | #endif // ANT_MBEDSPIANT_h 29 | -------------------------------------------------------------------------------- /src/MainClasses/ANT_NativeAntWithCallbacks.cpp: -------------------------------------------------------------------------------- 1 | #if NATIVE_API_AVAILABLE 2 | 3 | #endif // NATIVE_API_AVAILABLE -------------------------------------------------------------------------------- /src/MainClasses/ANT_NativeAntWithCallbacks.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_NATIVEANTWITHCALLBACKS_h 2 | #define ANT_NATIVEANTWITHCALLBACKS_h 3 | 4 | #include 5 | #include 6 | 7 | #ifdef NATIVE_API_AVAILABLE 8 | 9 | class NativeAntWithCallbacks : public NativeAnt, public BaseAntWithCallbacks 10 | { 11 | public: 12 | NativeAntWithCallbacks(); 13 | }; 14 | 15 | #endif 16 | 17 | #endif // ANT_NATIVEANTWITHCALLBACKS_h -------------------------------------------------------------------------------- /src/MainClasses/FrameworkClasses/ANT_ArduinoHandler.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cujomalainey/ant-arduino/da24c50177ee84a817a32bfed6b91111f8c99022/src/MainClasses/FrameworkClasses/ANT_ArduinoHandler.h -------------------------------------------------------------------------------- /src/RX/ANT_AntRxDataResponse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | AntRxDataResponse::AntRxDataResponse() : AntResponse() { 6 | 7 | } 8 | 9 | uint8_t AntRxDataResponse::getData(uint8_t index) { 10 | return getFrameData()[index]; 11 | } 12 | 13 | uint8_t* AntRxDataResponse::getData() { 14 | return getFrameData(); 15 | } 16 | 17 | // cppcheck-suppress unusedFunction 18 | uint8_t AntRxDataResponse::getDataOffset() { 19 | return ANT_MSG_FRONT_OVERHEAD; 20 | } 21 | 22 | // cppcheck-suppress unusedFunction 23 | uint16_t AntRxDataResponse::getDeviceNumber() { 24 | if (getFlagByte() & LIB_CONFIG_CHANNEL_ID) { 25 | return AntRxDataResponse::getData(EXTENDEDDATA_DEVICENUMBER_LSB_BYTE) | (AntRxDataResponse::getData(EXTENDEDDATA_DEVICENUMBER_MSB_BYTE) << EXTENDEDDATA_DEVICENUMBER_MSB_SHIFT); 26 | } else { 27 | return 0; 28 | } 29 | } 30 | 31 | // cppcheck-suppress unusedFunction 32 | uint8_t AntRxDataResponse::getDeviceType() { 33 | if (getFlagByte() & LIB_CONFIG_CHANNEL_ID) { 34 | return AntRxDataResponse::getData(EXTENDEDDATA_DEVICETYPE_BYTE); 35 | } else { 36 | return 0; 37 | } 38 | } 39 | 40 | // cppcheck-suppress unusedFunction 41 | uint8_t AntRxDataResponse::getTransmissionType() { 42 | if (getFlagByte() & LIB_CONFIG_CHANNEL_ID) { 43 | return AntRxDataResponse::getData(EXTENDEDDATA_TRANSMISSIONTYPE_BYTE); 44 | } else { 45 | return 0; 46 | } 47 | } 48 | 49 | // cppcheck-suppress unusedFunction 50 | uint8_t AntRxDataResponse::getMeasurementType() { 51 | if (getFlagByte() & LIB_CONFIG_RSSI) { 52 | uint8_t offset = 0; 53 | if (getFlagByte() & LIB_CONFIG_CHANNEL_ID) { 54 | offset += EXTENDEDDATA_CHANNELID_SIZE; 55 | } 56 | return AntRxDataResponse::getData(EXTENDEDDATA_MEASUREMENTTYPE_BYTE + offset); 57 | } else { 58 | return 0; 59 | } 60 | } 61 | 62 | // cppcheck-suppress unusedFunction 63 | int8_t AntRxDataResponse::getRSSIValue() { 64 | if (getFlagByte() & LIB_CONFIG_RSSI) { 65 | uint8_t offset = 0; 66 | if (getFlagByte() & LIB_CONFIG_CHANNEL_ID) { 67 | offset += EXTENDEDDATA_CHANNELID_SIZE; 68 | } 69 | return AntRxDataResponse::getData(EXTENDEDDATA_RSSIVALUE_BYTE + offset); 70 | } else { 71 | return 0; 72 | } 73 | } 74 | 75 | // cppcheck-suppress unusedFunction 76 | int8_t AntRxDataResponse::getThresholdConfigurationValue() { 77 | if (getFlagByte() & LIB_CONFIG_RSSI) { 78 | uint8_t offset = 0; 79 | if (getFlagByte() & LIB_CONFIG_CHANNEL_ID) { 80 | offset += EXTENDEDDATA_CHANNELID_SIZE; 81 | } 82 | return AntRxDataResponse::getData(EXTENDEDDATA_THRESHOLDCONFIGURATIONVALUE_BYTE + offset); 83 | } else { 84 | return 0; 85 | } 86 | } 87 | 88 | // cppcheck-suppress unusedFunction 89 | uint16_t AntRxDataResponse::getRxTimestamp() { 90 | if (getFlagByte() & LIB_CONFIG_RX_TIMESTAMP) { 91 | uint8_t offset = 0; 92 | if (getFlagByte() & LIB_CONFIG_CHANNEL_ID) { 93 | offset += EXTENDEDDATA_CHANNELID_SIZE; 94 | } 95 | if (getFlagByte() & LIB_CONFIG_RSSI) { 96 | offset += EXTENDEDDATA_RSSIOUTPUT_SIZE; 97 | } 98 | return AntRxDataResponse::getData(EXTENDEDDATA_RXTIMESTAMP_LSB_BYTE + offset) | (AntRxDataResponse::getData(EXTENDEDDATA_DEVICENUMBER_MSB_BYTE + offset) << EXTENDEDDATA_RXTIMESTAMP_MSB_SHIFT); 99 | } else { 100 | return 0; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/RX/ANT_AntRxDataResponse.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ANTRXDATARESPONSE_h 2 | #define ANT_ANTRXDATARESPONSE_h 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * Common functionality for Ant messages to get channel data 9 | */ 10 | class AntRxDataResponse : public AntResponse { 11 | public: 12 | AntRxDataResponse(); 13 | /** 14 | * Returns the specified index of the payload. The index may be 0 to getDataLength() - 1 15 | * This method is deprecated; use uint8_t* getData() 16 | */ 17 | virtual uint8_t getData(uint8_t index); 18 | /** 19 | * Returns the payload array. This may be accessed from index 0 to getDataLength() - 1 20 | */ 21 | virtual uint8_t* getData(); 22 | /** 23 | * Returns the length of the payload 24 | */ 25 | virtual uint8_t getDataLength() = 0; 26 | /** 27 | * Returns the position in the frame data where the data begins, 28 | * its the same for all messages 29 | */ 30 | uint8_t getDataOffset(); 31 | /** 32 | * Call this method to determine what extended fields are available 33 | * Use LIB_CONFIG defines to check bits if they are set 34 | */ 35 | virtual uint8_t getFlagByte() = 0; 36 | /** 37 | * Will return device number if getFlagByte() & LIB_CONFIG_CHANNEL_ID is true 38 | */ 39 | uint16_t getDeviceNumber(); 40 | /** 41 | * Will return device type if getFlagByte() & LIB_CONFIG_CHANNEL_ID is true 42 | */ 43 | uint8_t getDeviceType(); 44 | /** 45 | * Will return transmission type if getFlagByte() & LIB_CONFIG_CHANNEL_ID is true 46 | */ 47 | uint8_t getTransmissionType(); 48 | /** 49 | * Will return measurement type if getFlagByte() & LIB_CONFIG_RSSI is true 50 | */ 51 | uint8_t getMeasurementType(); 52 | /** 53 | * Will return rssi value if getFlagByte() & LIB_CONFIG_RSSI is true 54 | */ 55 | int8_t getRSSIValue(); 56 | /** 57 | * Will return threshoold configuration value if getFlagByte() & LIB_CONFIG_RSSI is true 58 | */ 59 | int8_t getThresholdConfigurationValue(); 60 | /** 61 | * Will return RX timestamp if getFlagByte() & LIB_CONFIG_RX_TIMESTAMP is true 62 | */ 63 | uint16_t getRxTimestamp(); 64 | }; 65 | #endif //ANT_ANTRXDATARESPONSE_h 66 | -------------------------------------------------------------------------------- /src/RX/ANT_messages.h: -------------------------------------------------------------------------------- 1 | /* Available RX Messages */ 2 | // RX 3 | // Data (RX) 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | // Status (RX) 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include -------------------------------------------------------------------------------- /src/RX/Data/ANT_AcknowledgedData.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | AcknowledgedData::AcknowledgedData() : AntRxDataResponse() { 6 | 7 | } 8 | 9 | // cppcheck-suppress unusedFunction 10 | uint8_t AcknowledgedData::getChannelNumber() { 11 | return AntRxDataResponse::getData(0); 12 | } 13 | 14 | uint8_t AcknowledgedData::getData(uint8_t index) { 15 | // skip channel byte 16 | return AntRxDataResponse::getData(index + 1); 17 | } 18 | 19 | uint8_t* AcknowledgedData::getData() { 20 | // skip channel byte 21 | return AntRxDataResponse::getData() + 1; 22 | } 23 | 24 | uint8_t AcknowledgedData::getDataLength() { 25 | return ACKNOWLEDGED_DATA_LENGTH; 26 | } 27 | 28 | uint8_t AcknowledgedData::getFlagByte() { 29 | if (getLength() > ACKNOWLEDGEDDATA_DEFAULT_MSG_LENGTH) { 30 | return AntRxDataResponse::getData(EXTENDEDDATA_FLAGBYTE_BYTE); 31 | } else { 32 | return 0x00; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RX/Data/ANT_AcknowledgedData.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ACKNOWLEDGEDDATA_h 2 | #define ANT_ACKNOWLEDGEDDATA_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a AcknowledgedData message 10 | */ 11 | class AcknowledgedData : public AntRxDataResponse { 12 | public: 13 | AcknowledgedData(); 14 | /** 15 | * Returns source channel 16 | */ 17 | uint8_t getChannelNumber(); 18 | /** 19 | * Returns sepcified byte of data from payload 20 | */ 21 | uint8_t getData(uint8_t index) override; 22 | uint8_t* getData() override; 23 | uint8_t getDataLength() override; 24 | uint8_t getFlagByte() override; 25 | 26 | static const uint8_t MSG_ID = ACKNOWLEDGED_DATA; 27 | }; 28 | 29 | #endif // ANT_ACKNOWLEDGEDDATA_h 30 | -------------------------------------------------------------------------------- /src/RX/Data/ANT_AdvancedBurstData.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | AdvancedBurstData::AdvancedBurstData() : AntRxDataResponse() { 6 | 7 | } 8 | 9 | uint8_t AdvancedBurstData::getChannelNumber() { 10 | return AntRxDataResponse::getData(0) & ADVANCED_BURST_DATA_CHANNEL_MASK; 11 | } 12 | 13 | // cppcheck-suppress unusedFunction 14 | uint8_t AdvancedBurstData::getSequenceNumber() { 15 | return (AntRxDataResponse::getData(0) & ~ADVANCED_BURST_DATA_CHANNEL_MASK) >> ADVANCED_BURST_DATA_SEQUENCENUMBER_SHIFT; 16 | } 17 | 18 | uint8_t AdvancedBurstData::getData(uint8_t index) { 19 | // skip channel byte 20 | return AntRxDataResponse::getData(index + 1); 21 | } 22 | 23 | uint8_t AdvancedBurstData::getFlagByte() { 24 | // hardcode disable flags since extended data not available in advanced burst data 25 | return 0x00; 26 | } 27 | 28 | // uint8_t* AcknowledgedData::getData() { 29 | // // TODO UNVERIFIED 30 | // // skip channel byte 31 | // return AntRxDataResponse::getData() + 1; 32 | // } 33 | 34 | uint8_t AdvancedBurstData::getDataLength() { 35 | // TODO this is actually variable 36 | return ADVANCED_BURST_DATA_LENGTH; 37 | } 38 | -------------------------------------------------------------------------------- /src/RX/Data/ANT_AdvancedBurstData.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ADVANCEDBURSTDDATA_h 2 | #define ANT_ADVANCEDBURSTDDATA_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a AdvancedBurstData message 10 | */ 11 | class AdvancedBurstData : public AntRxDataResponse { 12 | public: 13 | AdvancedBurstData(); 14 | /** 15 | * Returns source channel 16 | */ 17 | uint8_t getChannelNumber(); 18 | uint8_t getSequenceNumber(); 19 | /** 20 | * Returns sepcified byte of data from payload 21 | */ 22 | uint8_t getData(uint8_t index) override; 23 | uint8_t getDataLength() override; 24 | /** 25 | * AdvancedBurstData does not support extended data 26 | * therefore we lock it out with this method 27 | */ 28 | uint8_t getFlagByte() override; 29 | 30 | static const uint8_t MSG_ID = ADVANCED_BURST_DATA; 31 | }; 32 | 33 | #endif // ANT_ADVANCEDBURSTDDATA_h 34 | -------------------------------------------------------------------------------- /src/RX/Data/ANT_BroadcastData.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | BroadcastData::BroadcastData() : AntRxDataResponse() {} 6 | 7 | uint8_t BroadcastData::getChannelNumber() { 8 | return AntRxDataResponse::getData(0); 9 | } 10 | 11 | uint8_t BroadcastData::getData(uint8_t index) { 12 | // skip channel byte 13 | return AntRxDataResponse::getData(index + 1); 14 | } 15 | 16 | uint8_t* BroadcastData::getData() { 17 | // skip channel byte 18 | return AntRxDataResponse::getData() + 1; 19 | } 20 | 21 | uint8_t BroadcastData::getDataLength() { 22 | return BROADCAST_DATA_LENGTH; 23 | } 24 | 25 | uint8_t BroadcastData::getFlagByte() { 26 | if (getLength() > BROADCASTDATA_DEFAULT_MSG_LENGTH) { 27 | return AntRxDataResponse::getData(EXTENDEDDATA_FLAGBYTE_BYTE); 28 | } else { 29 | return 0x00; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/RX/Data/ANT_BroadcastData.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_BROADCASTDATA_h 2 | #define ANT_BROADCASTDATA_h 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * Represents a Ant Broadcast data message 9 | */ 10 | class BroadcastData : public AntRxDataResponse { 11 | public: 12 | BroadcastData(); 13 | /** 14 | * Returns source channel 15 | */ 16 | uint8_t getChannelNumber(); 17 | /** 18 | * Returns sepcified byte of data from payload 19 | */ 20 | uint8_t getData(uint8_t index) override; 21 | /** 22 | * Returns a pointer to the 8 byte payload 23 | */ 24 | uint8_t* getData() override; 25 | /** 26 | * Returns the size of the payload 27 | */ 28 | uint8_t getDataLength() override; 29 | /** 30 | * returns flag byte for extended data messages 31 | */ 32 | uint8_t getFlagByte() override; 33 | static const uint8_t MSG_ID = BROADCAST_DATA; 34 | }; 35 | 36 | #endif // ANT_BROADCASTDATA_h 37 | -------------------------------------------------------------------------------- /src/RX/Data/ANT_BurstTransferData.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | BurstTransferData::BurstTransferData() : AntRxDataResponse() { 6 | 7 | } 8 | 9 | uint8_t BurstTransferData::getChannelNumber() { 10 | return AntRxDataResponse::getData(0); 11 | } 12 | 13 | uint8_t BurstTransferData::getData(uint8_t index) { 14 | // skip channel byte 15 | return AntRxDataResponse::getData(index + 1); 16 | } 17 | 18 | uint8_t* BurstTransferData::getData() { 19 | // skip channel byte 20 | return AntRxDataResponse::getData() + 1; 21 | } 22 | 23 | // uint8_t BurstTransferData::getExtendedDataLength() { 24 | // // TODO not inplemented 25 | // return INVALID_REQUEST; 26 | // } 27 | 28 | // uint8_t BurstTransferData::getExtendedData(uint8_t index) { 29 | // // TODO not inplemented 30 | // return INVALID_REQUEST; 31 | // } 32 | 33 | uint8_t BurstTransferData::getDataLength() { 34 | return BURST_DATA_TRANSFER_LENGTH; 35 | } 36 | 37 | uint8_t BurstTransferData::getFlagByte() { 38 | if (getLength() > BURSTTRANSFERDATA_DEFAULT_MSG_LENGTH) { 39 | return AntRxDataResponse::getData(EXTENDEDDATA_FLAGBYTE_BYTE); 40 | } else { 41 | return 0x00; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/RX/Data/ANT_BurstTransferData.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_BURSTTRANSFERDATA_h 2 | #define ANT_BURSTTRANSFERDATA_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a BurstTransferData message 10 | */ 11 | class BurstTransferData : public AntRxDataResponse { 12 | public: 13 | BurstTransferData(); 14 | /** 15 | * Returns source channel 16 | */ 17 | uint8_t getChannelNumber(); 18 | uint8_t getSequenceNumber(); 19 | /** 20 | * Returns sepcified byte of data from payload 21 | */ 22 | uint8_t getData(uint8_t index) override; 23 | uint8_t* getData() override; 24 | uint8_t getDataLength() override; 25 | uint8_t getFlagByte() override; 26 | 27 | static const uint8_t MSG_ID = BURST_TRANSFER_DATA; 28 | }; 29 | 30 | #endif // ANT_BURSTTRANSFERDATA_h 31 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_AdvancedBurstCapabilitiesConfiguration.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | AdvancedBurstCapabilitiesConfiguration::AdvancedBurstCapabilitiesConfiguration() : AntResponse () { 4 | 5 | } 6 | 7 | // cppcheck-suppress unusedFunction 8 | uint8_t AdvancedBurstCapabilitiesConfiguration::getMsgType() { 9 | return getFrameData()[0]; 10 | } 11 | 12 | // cppcheck-suppress unusedFunction 13 | uint8_t AdvancedBurstCapabilitiesConfiguration::getSupportedMaxPacketLength() { 14 | return getFrameData()[1]; 15 | } 16 | 17 | // cppcheck-suppress unusedFunction 18 | uint32_t AdvancedBurstCapabilitiesConfiguration::getSupportedFeatures() { 19 | uint8_t* frame = getFrameData(); 20 | return ( frame[2] ) + ( frame[3] << BITS_IN_BYTE ) + ( frame[4] << BITS_IN_SHORT ); 21 | } 22 | 23 | uint8_t AdvancedBurstCapabilitiesConfiguration::enable() { 24 | return getFrameData()[1]; 25 | } 26 | 27 | // cppcheck-suppress unusedFunction 28 | uint8_t AdvancedBurstCapabilitiesConfiguration::getMaxPacketLength() { 29 | return getFrameData()[2]; 30 | } 31 | 32 | // cppcheck-suppress unusedFunction 33 | uint32_t AdvancedBurstCapabilitiesConfiguration::getRequiredFeatures() { 34 | uint32_t features = getFrameData()[3]; 35 | features |= getFrameData()[4] << BITS_IN_BYTE; 36 | features |= getFrameData()[5] << BITS_IN_SHORT; 37 | return features; 38 | } 39 | 40 | // cppcheck-suppress unusedFunction 41 | uint32_t AdvancedBurstCapabilitiesConfiguration::getOptionalFeatures() { 42 | uint32_t features = getFrameData()[6]; 43 | features |= getFrameData()[7] << BITS_IN_BYTE; 44 | features |= getFrameData()[8] << BITS_IN_SHORT; 45 | return features; 46 | } 47 | 48 | #ifdef NATIVE_API_AVAILABLE 49 | 50 | uint32_t AdvancedBurstCapabilitiesConfiguration::backFill(uint8_t subId, ANT_MESSAGE &buf) { 51 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 52 | buf.ANT_MESSAGE_ucSize = subId ? MESG_CONFIG_ADV_BURST_REQ_CONFIG_SIZE : MESG_CONFIG_ADV_BURST_REQ_CAPABILITIES_SIZE; 53 | // TODO verify sizes might need to be increased by 1 54 | buf.ANT_MESSAGE_aucMesgData[0] = subId; 55 | return sd_ant_adv_burst_config_get(subId, &buf.ANT_MESSAGE_aucMesgData[1]); 56 | } 57 | 58 | #endif // NATIVE_API_AVAILABLE 59 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_AdvancedBurstCapabilitiesConfiguration.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ADVANCEDBURSTCAPABILITIESCONFIGURATION_h 2 | #define ANT_ADVANCEDBURSTCAPABILITIESCONFIGURATION_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Advanced Burst Capabilities or Current Configuration message 10 | */ 11 | class AdvancedBurstCapabilitiesConfiguration : public AntResponse { 12 | public: 13 | AdvancedBurstCapabilitiesConfiguration(); 14 | /** 15 | * returns 0 for a capabilities message, 1 for a current configuration 16 | */ 17 | uint8_t getMsgType(); 18 | // Capabilities Methods 19 | uint8_t getSupportedMaxPacketLength(); 20 | uint32_t getSupportedFeatures(); 21 | 22 | // Current Configuration Methods 23 | 24 | /** 25 | * Defines whether advanced burst is enabled 26 | */ 27 | uint8_t enable(); 28 | uint8_t getMaxPacketLength(); 29 | uint32_t getRequiredFeatures(); 30 | uint32_t getOptionalFeatures(); 31 | 32 | // TODO Stall count, retry count 33 | 34 | #ifdef NATIVE_API_AVAILABLE 35 | 36 | static uint32_t backFill(uint8_t subId, ANT_MESSAGE &buf); 37 | 38 | #endif // NATIVE_API_AVAILABLE 39 | 40 | static const uint8_t MSG_ID = ADVANCED_BURST_CAPABILITES; 41 | }; 42 | 43 | #endif // ANT_ADVANCEDBURSTCAPABILITIESCONFIGURATION_h 44 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_AntVersion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | AntVersion::AntVersion() : AntResponse() {} 4 | 5 | // cppcheck-suppress unusedFunction 6 | uint8_t AntVersion::getVersionByte(uint8_t pos) { 7 | return getFrameData()[pos]; 8 | } 9 | 10 | #ifdef NATIVE_API_AVAILABLE 11 | 12 | uint32_t AntVersion::backFill(uint8_t subId, ANT_MESSAGE &buf) { 13 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 14 | buf.ANT_MESSAGE_ucSize = MESG_VERSION_SIZE; 15 | return sd_ant_version_get(buf.ANT_MESSAGE_aucMesgData); 16 | } 17 | 18 | #endif // NATIVE_API_AVAILABLE 19 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_AntVersion.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ANTVERSION_h 2 | #define ANT_ANTVERSION_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a ANT Version message 10 | */ 11 | class AntVersion : public AntResponse { 12 | public: 13 | AntVersion(); 14 | uint8_t getVersionByte(uint8_t pos); 15 | 16 | #ifdef NATIVE_API_AVAILABLE 17 | 18 | static uint32_t backFill(uint8_t subId, ANT_MESSAGE &buf); 19 | 20 | #endif // NATIVE_API_AVAILABLE 21 | 22 | static const uint8_t MSG_ID = ANT_VERSION; 23 | }; 24 | 25 | #endif // ANT_ANTVERSION_h 26 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_Capabilities.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | Capabilities::Capabilities() : AntResponse() {} 4 | 5 | // cppcheck-suppress unusedFunction 6 | uint8_t Capabilities::getMaxChannels() { 7 | return getFrameData()[0]; 8 | } 9 | 10 | // cppcheck-suppress unusedFunction 11 | uint8_t Capabilities::getMaxNetworks() { 12 | return getFrameData()[1]; 13 | } 14 | 15 | // cppcheck-suppress unusedFunction 16 | uint8_t Capabilities::getStandardOptions() { 17 | return getFrameData()[2]; 18 | } 19 | 20 | // cppcheck-suppress unusedFunction 21 | uint8_t Capabilities::getAdvancedOptions(uint8_t pos) { 22 | if ( pos == 0 ) 23 | { 24 | return getFrameData()[3]; 25 | } 26 | else if ( pos == 1 ) 27 | { 28 | return getFrameData()[4]; 29 | } 30 | else if ( pos == 2 ) 31 | { 32 | return getFrameData()[6]; 33 | } 34 | else 35 | { 36 | return getFrameData()[7]; 37 | } 38 | } 39 | 40 | // cppcheck-suppress unusedFunction 41 | uint8_t Capabilities::getMaxSensRcoreChannels() { 42 | return getFrameData()[5]; 43 | } 44 | 45 | #ifdef NATIVE_API_AVAILABLE 46 | 47 | uint32_t Capabilities::backFill(uint8_t subId, ANT_MESSAGE &buf) { 48 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 49 | buf.ANT_MESSAGE_ucSize = MESG_CAPABILITIES_SIZE; 50 | return sd_ant_capabilities_get(buf.ANT_MESSAGE_aucMesgData); 51 | } 52 | 53 | #endif // NATIVE_API_AVAILABLE 54 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_Capabilities.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CAPABILITIES_h 2 | #define ANT_CAPABILITIES_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Capabilities message 10 | */ 11 | class Capabilities : public AntResponse { 12 | public: 13 | Capabilities(); 14 | uint8_t getMaxChannels(); 15 | uint8_t getMaxNetworks(); 16 | uint8_t getStandardOptions(); 17 | uint8_t getAdvancedOptions(uint8_t pos); //note, this is 1 indexed to match the spec sheet 18 | uint8_t getMaxSensRcoreChannels(); 19 | 20 | #ifdef NATIVE_API_AVAILABLE 21 | 22 | static uint32_t backFill(uint8_t subId, ANT_MESSAGE &buf); 23 | 24 | #endif // NATIVE_API_AVAILABLE 25 | 26 | static const uint8_t MSG_ID = CAPABILITIES; 27 | }; 28 | 29 | #endif // ANT_CAPABILITIES_h 30 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_ChannelEventResponse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ChannelEventResponse::ChannelEventResponse() : AntResponse() { 4 | 5 | } 6 | 7 | uint8_t ChannelEventResponse::getChannelNumber() { 8 | return getFrameData()[0]; 9 | } 10 | 11 | uint8_t ChannelEventResponse::getResponseMsgId() { 12 | return getFrameData()[1]; 13 | } 14 | 15 | uint8_t ChannelEventResponse::getCode() { 16 | return getFrameData()[2]; 17 | } 18 | 19 | // cppcheck-suppress unusedFunction 20 | uint8_t ChannelEventResponse::getExtendedEventParameters() { 21 | if (getLength() > 3){ 22 | return getFrameData()[3]; 23 | } 24 | else { 25 | return INVALID_REQUEST; 26 | } 27 | } 28 | 29 | #ifdef NATIVE_API_AVAILABLE 30 | 31 | uint32_t ChannelEventResponse::backFill(uint8_t chan, uint8_t msgId, uint8_t retCode, ANT_MESSAGE& buf) { 32 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 33 | // TODO 34 | return 0; 35 | } 36 | 37 | #endif // NATIVE_API_AVAILABLE 38 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_ChannelEventResponse.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CHANNELEVENTRESPONSE_h 2 | #define ANT_CHANNELEVENTRESPONSE_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Channel Event or Channel Response Message 10 | */ 11 | class ChannelEventResponse : public AntResponse { 12 | public: 13 | ChannelEventResponse(); 14 | uint8_t getChannelNumber(); 15 | uint8_t getResponseMsgId(); 16 | uint8_t getCode(); 17 | uint8_t getExtendedEventParameters(); 18 | 19 | #ifdef NATIVE_API_AVAILABLE 20 | 21 | static uint32_t backFill(uint8_t chan, uint8_t msgId, uint8_t retCode, ANT_MESSAGE &buf); 22 | 23 | #endif // NATIVE_API_AVAILABLE 24 | 25 | static const uint8_t MSG_ID = CHANNEL_RESPONSE; 26 | }; 27 | 28 | #endif // ANT_CHANNELEVENTRESPONSE_h 29 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_ChannelIdResponse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ChannelIdResponse::ChannelIdResponse() : AntResponse() { 4 | 5 | } 6 | 7 | uint8_t ChannelIdResponse::getChannelNumber() { 8 | return getFrameData()[0]; 9 | } 10 | 11 | uint16_t ChannelIdResponse::getDeviceNumber() { 12 | uint16_t deviceNumber = getFrameData()[1]; 13 | deviceNumber |= getFrameData()[2] << BITS_IN_BYTE; 14 | return deviceNumber; 15 | } 16 | 17 | uint8_t ChannelIdResponse::getDeviceType() { 18 | return getFrameData()[3]; 19 | } 20 | 21 | uint8_t ChannelIdResponse::getTransmissionType() { 22 | return getFrameData()[4]; 23 | } 24 | 25 | #ifdef NATIVE_API_AVAILABLE 26 | 27 | uint32_t ChannelIdResponse::backFill(uint8_t subId, ANT_MESSAGE &buf) { 28 | uint16_t id; 29 | uint32_t ret; 30 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 31 | buf.ANT_MESSAGE_ucSize = MESG_CHANNEL_ID_SIZE; 32 | buf.ANT_MESSAGE_aucMesgData[0] = subId; 33 | ret = sd_ant_channel_id_get(subId, &id, &buf.ANT_MESSAGE_aucMesgData[3], &buf.ANT_MESSAGE_aucMesgData[4]); 34 | buf.ANT_MESSAGE_aucMesgData[1] = (uint8_t)id; 35 | buf.ANT_MESSAGE_aucMesgData[2] = (uint8_t)(id >> BITS_IN_BYTE); 36 | return ret; 37 | } 38 | 39 | #endif // NATIVE_API_AVAILABLE 40 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_ChannelIdResponse.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CHANNELIDRESPONSE_h 2 | #define ANT_CHANNELIDRESPONSE_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Channel Id Response Message 10 | */ 11 | class ChannelIdResponse : public AntResponse { 12 | public: 13 | ChannelIdResponse(); 14 | uint8_t getChannelNumber(); 15 | uint16_t getDeviceNumber(); 16 | uint8_t getDeviceType(); 17 | uint8_t getTransmissionType(); 18 | 19 | #ifdef NATIVE_API_AVAILABLE 20 | 21 | static uint32_t backFill(uint8_t subId, ANT_MESSAGE &buf); 22 | 23 | #endif // NATIVE_API_AVAILABLE 24 | 25 | static const uint8_t MSG_ID = CHANNEL_ID; 26 | }; 27 | 28 | #endif // ANT_CHANNELIDRESPONSE_h 29 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_ChannelStatus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | ChannelStatus::ChannelStatus() : AntResponse() { 6 | 7 | } 8 | 9 | uint8_t ChannelStatus::getChannelNumber() { 10 | return getFrameData()[0]; 11 | } 12 | 13 | // cppcheck-suppress unusedFunction 14 | uint8_t ChannelStatus::getChannelState() { 15 | return getFrameData()[1] & CHANNEL_STATUS_STATE_MASK; 16 | } 17 | 18 | // cppcheck-suppress unusedFunction 19 | uint8_t ChannelStatus::getNetworkNumber() { 20 | return ( getFrameData()[1] >> CHANNEL_STATUS_NETWORK_NUMBER_SHIFT ) & CHANNEL_STATUS_NETWORK_NUMBER_MASK; 21 | } 22 | 23 | // cppcheck-suppress unusedFunction 24 | uint8_t ChannelStatus::getChannelType() { 25 | return getFrameData()[1] >> CHANNEL_STATUS_CHANNEL_TYPE_SHIFT; 26 | } 27 | 28 | #ifdef NATIVE_API_AVAILABLE 29 | 30 | uint32_t ChannelStatus::backFill(uint8_t subId, ANT_MESSAGE &buf) { 31 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 32 | buf.ANT_MESSAGE_ucSize = MESG_CHANNEL_STATUS_SIZE; 33 | buf.ANT_MESSAGE_aucMesgData[0] = subId; 34 | return sd_ant_channel_status_get(subId, &buf.ANT_MESSAGE_aucMesgData[1]); 35 | } 36 | 37 | #endif // NATIVE_API_AVAILABLE 38 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_ChannelStatus.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CHANNELSTATUS_h 2 | #define ANT_CHANNELSTATUS_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Channel Status message 10 | */ 11 | class ChannelStatus : public AntResponse { 12 | public: 13 | ChannelStatus(); 14 | uint8_t getChannelNumber(); 15 | uint8_t getChannelState(); 16 | uint8_t getNetworkNumber(); 17 | uint8_t getChannelType(); 18 | 19 | #ifdef NATIVE_API_AVAILABLE 20 | 21 | static uint32_t backFill(uint8_t subId, ANT_MESSAGE &buf); 22 | 23 | #endif // NATIVE_API_AVAILABLE 24 | 25 | static const uint8_t MSG_ID = CHANNEL_STATUS; 26 | }; 27 | 28 | #endif // ANT_CHANNELSTATUS_h 29 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_EncryptionModeParameters.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | EncryptionModeParameters::EncryptionModeParameters() : AntResponse() { 4 | 5 | } 6 | 7 | // cppcheck-suppress unusedFunction 8 | uint8_t EncryptionModeParameters::getRequestedModeParameter() { 9 | return getFrameData()[0]; 10 | } 11 | 12 | // cppcheck-suppress unusedFunction 13 | uint8_t EncryptionModeParameters::getMaxSupportedEncryptionMode() { 14 | return getFrameData()[1]; 15 | } 16 | 17 | // cppcheck-suppress unusedFunction 18 | uint32_t EncryptionModeParameters::getUniqueIdentifier() { 19 | uint32_t identifier = getFrameData()[1]; 20 | identifier |= getFrameData()[2] << BITS_IN_BYTE; 21 | identifier |= getFrameData()[3] << BITS_IN_SHORT; 22 | identifier |= getFrameData()[4] << 24; 23 | return identifier; 24 | } 25 | 26 | // cppcheck-suppress unusedFunction 27 | char* EncryptionModeParameters::getUserInformationString() { 28 | return (char*)(getFrameData() + 1); // skip mode parameter 29 | } 30 | 31 | #ifdef NATIVE_API_AVAILABLE 32 | 33 | uint32_t EncryptionModeParameters::backFill(uint8_t subId, ANT_MESSAGE &buf) { 34 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 35 | switch (subId) { 36 | case ENCRYPTION_INFO_GET_SUPPORTED_MODE: 37 | buf.ANT_MESSAGE_ucSize = MESG_CONFIG_ENCRYPT_REQ_CAPABILITIES_SIZE; 38 | break; 39 | case ENCRYPTION_INFO_GET_CRYPTO_ID: 40 | buf.ANT_MESSAGE_ucSize = MESG_CONFIG_ENCRYPT_REQ_CONFIG_ID_SIZE; 41 | break; 42 | case ENCRYPTION_INFO_GET_CUSTOM_USER_DATA: 43 | buf.ANT_MESSAGE_ucSize = MESG_CONFIG_ENCRYPT_REQ_CONFIG_USER_DATA_SIZE; 44 | break; 45 | } 46 | buf.ANT_MESSAGE_aucMesgData[0] = subId; 47 | return sd_ant_crypto_info_get(subId, &buf.ANT_MESSAGE_aucMesgData[1]); 48 | } 49 | 50 | #endif // NATIVE_API_AVAILABLE 51 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_EncryptionModeParameters.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ENCRYPTIONMODEPARAMETERS_h 2 | #define ANT_ENCRYPTIONMODEPARAMETERS_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Channel Id Response Message 10 | */ 11 | class EncryptionModeParameters : public AntResponse { 12 | public: 13 | EncryptionModeParameters(); 14 | 15 | uint8_t getRequestedModeParameter(); 16 | /** 17 | * Only call if getRequestedModeParameter == 0 18 | */ 19 | uint8_t getMaxSupportedEncryptionMode(); 20 | /** 21 | * Only call if getRequestedModeParameter == 1 22 | */ 23 | uint32_t getUniqueIdentifier(); 24 | /** 25 | * Only call if getRequestedModeParameter == 2 26 | */ 27 | char* getUserInformationString(); 28 | 29 | #ifdef NATIVE_API_AVAILABLE 30 | 31 | static uint32_t backFill(uint8_t subId, ANT_MESSAGE &buf); 32 | 33 | #endif // NATIVE_API_AVAILABLE 34 | 35 | static const uint8_t MSG_ID = ENCRYPTION_MODE_PARAMETERS; 36 | }; 37 | 38 | #endif // ANT_ENCRYPTIONMODEPARAMETERS_h 39 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_EventFilter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | EventFilter::EventFilter() : AntResponse() { 4 | 5 | } 6 | 7 | uint8_t EventFilter::getChannelNumber() { 8 | return getFrameData()[0]; 9 | } 10 | 11 | // cppcheck-suppress unusedFunction 12 | uint16_t EventFilter::getEventFilter() { 13 | uint16_t filter = getFrameData()[1]; 14 | filter |= getFrameData()[2] << 8; 15 | return filter; 16 | } 17 | 18 | #ifdef NATIVE_API_AVAILABLE 19 | 20 | uint32_t EventFilter::backFill(uint8_t subId, ANT_MESSAGE &buf) { 21 | uint16_t filter; 22 | uint32_t ret; 23 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 24 | buf.ANT_MESSAGE_ucSize = MESG_EVENT_FILTER_CONFIG_REQ_SIZE; 25 | ret = sd_ant_event_filtering_get(&filter); 26 | buf.ANT_MESSAGE_aucMesgData[0] = (uint8_t)filter; 27 | buf.ANT_MESSAGE_aucMesgData[1] = (uint8_t)(filter >> BITS_IN_BYTE); 28 | return ret; 29 | } 30 | 31 | #endif // NATIVE_API_AVAILABLE 32 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_EventFilter.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_EVENTFILTER_h 2 | #define ANT_EVENTFILTER_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Event Filter Response Message 10 | */ 11 | class EventFilter : public AntResponse { 12 | public: 13 | EventFilter(); 14 | 15 | uint8_t getChannelNumber(); 16 | uint16_t getEventFilter(); 17 | 18 | #ifdef NATIVE_API_AVAILABLE 19 | 20 | static uint32_t backFill(uint8_t subId, ANT_MESSAGE &buf); 21 | 22 | #endif // NATIVE_API_AVAILABLE 23 | 24 | static const uint8_t MSG_ID = EVENT_FILTER; 25 | }; 26 | 27 | #endif // ANT_EVENTFILTER_h 28 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_SelectiveDataUpdateMaskSetting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | SelectiveDataUpdateMaskSetting::SelectiveDataUpdateMaskSetting() : AntResponse() { 4 | 5 | } 6 | 7 | // cppcheck-suppress unusedFunction 8 | uint8_t SelectiveDataUpdateMaskSetting::getSDUMaskNumber() { 9 | return getFrameData()[0]; 10 | } 11 | 12 | // cppcheck-suppress unusedFunction 13 | uint8_t* SelectiveDataUpdateMaskSetting::getSDUMask() { 14 | return getFrameData() + 1; 15 | } 16 | 17 | #ifdef NATIVE_API_AVAILABLE 18 | 19 | uint32_t SelectiveDataUpdateMaskSetting::backFill(uint8_t subId, ANT_MESSAGE &buf) { 20 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 21 | buf.ANT_MESSAGE_aucMesgData[0] = subId; 22 | buf.ANT_MESSAGE_ucSize = MESG_ANT_MAX_PAYLOAD_SIZE + MESG_CHANNEL_NUM_SIZE; 23 | return sd_ant_sdu_mask_get(subId, &buf.ANT_MESSAGE_aucMesgData[1]); 24 | } 25 | 26 | #endif // NATIVE_API_AVAILABLE 27 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_SelectiveDataUpdateMaskSetting.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_SELECTIVEDATAUPDATEMASKSETTING_h 2 | #define ANT_SELECTIVEDATAUPDATEMASKSETTING_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | class SelectiveDataUpdateMaskSetting : public AntResponse { 9 | public: 10 | SelectiveDataUpdateMaskSetting(); 11 | 12 | uint8_t getSDUMaskNumber(); 13 | /** 14 | * An array of length 8 15 | */ 16 | uint8_t* getSDUMask(); 17 | 18 | #ifdef NATIVE_API_AVAILABLE 19 | 20 | static uint32_t backFill(uint8_t subId, ANT_MESSAGE &buf); 21 | 22 | #endif // NATIVE_API_AVAILABLE 23 | 24 | static const uint8_t MSG_ID = SELECTIVE_DATA_UPDATE_MASK_SETTING; 25 | }; 26 | 27 | #endif // ANT_SELECTIVEDATAUPDATEMASKSETTING_h 28 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_StartUpMessage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | StartUpMessage::StartUpMessage() : AntResponse() { 4 | 5 | } 6 | 7 | // cppcheck-suppress unusedFunction 8 | uint8_t StartUpMessage::getMessage() { 9 | return getFrameData()[0]; 10 | } 11 | 12 | #ifdef NATIVE_API_AVAILABLE 13 | 14 | uint32_t StartUpMessage::backFill(uint8_t cause, ANT_MESSAGE &buf) { 15 | // TODO magic numbers 16 | buf.ANT_MESSAGE_ucSize = 1; 17 | buf.ANT_MESSAGE_ucMesgID = MSG_ID; 18 | buf.ANT_MESSAGE_ucSubID = cause; 19 | return NO_RESPONSE_MESSAGE; 20 | } 21 | 22 | #endif // NATIVE_API_AVAILABLE 23 | -------------------------------------------------------------------------------- /src/RX/Status/ANT_StartUpMessage.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_STARTUPMESSAGE_h 2 | #define ANT_STARTUPMESSAGE_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Startup message 10 | */ 11 | class StartUpMessage : public AntResponse { 12 | public: 13 | StartUpMessage(); 14 | uint8_t getMessage(); 15 | 16 | #ifdef NATIVE_API_AVAILABLE 17 | 18 | static uint32_t backFill(uint8_t cause, ANT_MESSAGE &buf); 19 | 20 | #endif // NATIVE_API_AVAILABLE 21 | 22 | static const uint8_t MSG_ID = START_UP_MESSAGE; 23 | }; 24 | 25 | #endif // ANT_STARTUPMESSAGE_h 26 | -------------------------------------------------------------------------------- /src/TX/ANT_AntRequest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | AntRequest::AntRequest(uint8_t msgId) { 4 | _msgId = msgId; 5 | } 6 | 7 | uint8_t AntRequest::getMsgId() { 8 | return _msgId; 9 | } -------------------------------------------------------------------------------- /src/TX/ANT_AntRequest.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ANTREQUEST_h 2 | #define ANT_ANTREQUEST_h 3 | #include 4 | #include 5 | #include 6 | 7 | /** 8 | * Super class of all Ant requests (TX packets) 9 | * It is recommended to reuse subclasses of the class to conserve memory 10 | */ 11 | class AntRequest { 12 | public: 13 | /** 14 | * Constructor 15 | */ 16 | AntRequest(uint8_t msgId); 17 | /** 18 | * Returns the Msg id 19 | */ 20 | uint8_t getMsgId(); 21 | /** 22 | * Starting after the frame id (pos = 0) and up to but not including the checksum 23 | * Note: Unlike Dynastream's definition of the frame data, this does not start with the MSG ID. 24 | * The reason for this is the MSG ID and Frame ID are common to all requests, whereas my definition of 25 | * frame data is only the MSG specific data. 26 | */ 27 | virtual uint8_t getData(uint8_t pos) = 0; 28 | /** 29 | * Returns the size of the msg frame (not including frame id or msg id or checksum). 30 | */ 31 | virtual uint8_t getDataLength() = 0; 32 | 33 | #ifdef NATIVE_API_AVAILABLE 34 | /** 35 | * Call to native API by NativeAnt when sent 36 | */ 37 | virtual uint32_t execute() = 0; 38 | #endif // NATIVE_API_AVAILABLE 39 | private: 40 | uint8_t _msgId; 41 | }; 42 | 43 | #endif //ANT_ANTREQUEST_h 44 | -------------------------------------------------------------------------------- /src/TX/ANT_AntTxDataRequest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | AntTxDataRequest::AntTxDataRequest(uint8_t msgId) : AntRequest(msgId) {} 4 | 5 | // cppcheck-suppress unusedFunction 6 | void AntTxDataRequest::setDataBuffer(uint8_t* dataPtr) { 7 | _data = dataPtr; 8 | } 9 | 10 | uint8_t* AntTxDataRequest::getDataBuffer() { 11 | return _data; 12 | } 13 | 14 | void AntTxDataRequest::setDataLength(uint8_t length) { 15 | _dataLength = length; 16 | } 17 | 18 | // cppcheck-suppress unusedFunction 19 | uint8_t AntTxDataRequest::getDataBufferLength() { 20 | return _dataLength; 21 | } 22 | -------------------------------------------------------------------------------- /src/TX/ANT_AntTxDataRequest.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ANTTXDATAREQUEST_h 2 | #define ANT_ANTTXDATAREQUEST_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Common functionality for Ant messages to set/send channel data 10 | */ 11 | class AntTxDataRequest : public AntRequest { 12 | public: 13 | explicit AntTxDataRequest(uint8_t msgId); 14 | /** 15 | * Returns a pointer to the buffer 16 | */ 17 | uint8_t* getDataBuffer(); 18 | /** 19 | * Returns the length of the payload 20 | */ 21 | uint8_t getDataBufferLength(); 22 | /** 23 | * Sets the data array 24 | */ 25 | void setDataBuffer(uint8_t* dataPtr); 26 | 27 | protected: 28 | void setDataLength(uint8_t length); 29 | 30 | private: 31 | uint8_t* _data = NULL; 32 | uint8_t _dataLength = 0; 33 | }; 34 | 35 | #endif // ANT_ANTTXDATAREQUEST_h 36 | -------------------------------------------------------------------------------- /src/TX/ANT_messages.h: -------------------------------------------------------------------------------- 1 | /* Available TX Messages */ 2 | // Config (TX) 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | // Control (TX) 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | // Data (TX) 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | // Test (TX) 47 | #include 48 | #include -------------------------------------------------------------------------------- /src/TX/Config/ANT_AddChannelIdToList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | AddChannelIdToList::AddChannelIdToList() : AntRequest(ADD_CHANNEL_ID_TO_LIST) { 7 | 8 | } 9 | 10 | AddChannelIdToList::AddChannelIdToList(uint8_t channel, uint16_t deviceNumber, uint8_t deviceType, uint8_t transmissionType, uint8_t listIndex) : AntRequest(ADD_CHANNEL_ID_TO_LIST) { 11 | setChannel(channel); 12 | setDeviceNumber(deviceNumber); 13 | setDeviceType(deviceType); 14 | setTransmissionType(transmissionType); 15 | setListIndex(listIndex); 16 | } 17 | 18 | void AddChannelIdToList::setChannel(uint8_t channel) { 19 | _channel = channel; 20 | } 21 | 22 | void AddChannelIdToList::setDeviceNumber(uint16_t deviceNumber) { 23 | _deviceNumber = deviceNumber; 24 | } 25 | 26 | void AddChannelIdToList::setDeviceType(uint8_t deviceType) { 27 | _deviceType = deviceType; 28 | } 29 | 30 | void AddChannelIdToList::setTransmissionType(uint8_t transmissionType) { 31 | _transmissionType = transmissionType; 32 | } 33 | 34 | void AddChannelIdToList::setListIndex(uint8_t listIndex) { 35 | _listIndex = listIndex; 36 | } 37 | 38 | // cppcheck-suppress unusedFunction 39 | uint8_t AddChannelIdToList::getChannel() { 40 | return _channel; 41 | } 42 | 43 | // cppcheck-suppress unusedFunction 44 | uint16_t AddChannelIdToList::getDeviceNumber() { 45 | return _deviceNumber; 46 | } 47 | 48 | // cppcheck-suppress unusedFunction 49 | uint8_t AddChannelIdToList::getDeviceType() { 50 | return _deviceType; 51 | } 52 | 53 | // cppcheck-suppress unusedFunction 54 | uint8_t AddChannelIdToList::getTransmissionType() { 55 | return _transmissionType; 56 | } 57 | 58 | // cppcheck-suppress unusedFunction 59 | uint8_t AddChannelIdToList::getListIndex() { 60 | return _listIndex; 61 | } 62 | 63 | uint8_t AddChannelIdToList::getData(uint8_t pos) { 64 | if (pos == 0) { 65 | return _channel; 66 | } else if (pos == 1) { 67 | return _deviceNumber & 0xFF; 68 | } else if (pos == 2) { 69 | return _deviceNumber >> 8; 70 | } else if (pos == 3) { 71 | return _deviceType & 0x7F; 72 | } else if (pos == 4) { 73 | return _transmissionType; 74 | } else { 75 | return _listIndex; 76 | } 77 | } 78 | 79 | uint8_t AddChannelIdToList::getDataLength() { 80 | return ADD_CHANNEL_ID_TO_LIST_LENGTH; 81 | } 82 | 83 | #ifdef NATIVE_API_AVAILABLE 84 | 85 | uint32_t AddChannelIdToList::execute() { 86 | uint8_t buf[4]; 87 | buf[0] = _deviceNumber; 88 | buf[1] = _deviceNumber << BITS_IN_BYTE; 89 | buf[2] = _deviceType; 90 | buf[3] = _transmissionType; 91 | return sd_ant_id_list_add(_channel, buf, _listIndex); 92 | } 93 | 94 | #endif // NATIVE_API_AVAILABLE 95 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_AddChannelIdToList.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ADDCHANNELIDTOLIST_h 2 | #define ANT_ADDCHANNELIDTOLIST_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents Add Channel Id To List message, it is used to add 8 | * a channel to a specified list 9 | */ 10 | class AddChannelIdToList : public AntRequest { 11 | public: 12 | AddChannelIdToList(); 13 | AddChannelIdToList(uint8_t channel, uint16_t deviceNumber, uint8_t deviceType, uint8_t transmissionType, uint8_t listIndex); 14 | void setChannel(uint8_t channel); 15 | void setDeviceNumber(uint16_t deviceNumber); 16 | void setDeviceType(uint8_t deviceType); 17 | void setTransmissionType(uint8_t transmissionType); 18 | void setListIndex(uint8_t listIndex); 19 | uint8_t getChannel(); 20 | uint16_t getDeviceNumber(); 21 | uint8_t getDeviceType(); 22 | uint8_t getTransmissionType(); 23 | uint8_t getListIndex(); 24 | uint8_t getData(uint8_t pos) override; 25 | uint8_t getDataLength() override; 26 | #ifdef NATIVE_API_AVAILABLE 27 | uint32_t execute() override; 28 | #endif // NATIVE_API_AVAILABLE 29 | private: 30 | uint8_t _channel = 0; 31 | uint16_t _deviceNumber = 0; 32 | uint8_t _deviceType = 0; 33 | uint8_t _transmissionType = 0; 34 | uint8_t _listIndex = 0; 35 | }; 36 | 37 | #endif // ANT_ADDCHANNELIDTOLIST_h 38 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_AddEncryptionIdToList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | AddEncryptionIdToList::AddEncryptionIdToList() : AntRequest(ADD_ENCRYPTION_ID_TO_LIST) { 6 | 7 | } 8 | 9 | AddEncryptionIdToList::AddEncryptionIdToList(uint8_t channel, uint32_t encryptionId, uint8_t listIndex) : AntRequest(ADD_ENCRYPTION_ID_TO_LIST) { 10 | setChannel(channel); 11 | setEncryptionId(encryptionId); 12 | setListIndex(listIndex); 13 | } 14 | 15 | void AddEncryptionIdToList::setChannel(uint8_t channel) { 16 | _channel = channel; 17 | } 18 | 19 | void AddEncryptionIdToList::setEncryptionId(uint32_t encryptionId) { 20 | _encryptionId = encryptionId; 21 | } 22 | 23 | void AddEncryptionIdToList::setListIndex(uint8_t listIndex) { 24 | _listIndex = listIndex; 25 | } 26 | 27 | uint8_t AddEncryptionIdToList::getChannel() { 28 | return _channel; 29 | } 30 | 31 | // cppcheck-suppress unusedFunction 32 | uint32_t AddEncryptionIdToList::getEncryptionId() { 33 | return _encryptionId; 34 | } 35 | 36 | uint8_t AddEncryptionIdToList::getListIndex() { 37 | return _listIndex; 38 | } 39 | 40 | uint8_t AddEncryptionIdToList::getData(uint8_t pos) { 41 | if (pos == 0) { 42 | return _channel; 43 | } else if (pos == 1) { 44 | return _encryptionId & 0xFF; 45 | } else if (pos == 2) { 46 | return (_encryptionId >> 8) & 0xFF; 47 | } else if (pos == 3) { 48 | return (_encryptionId >> 16) & 0xFF; 49 | } else if (pos == 4) { 50 | return _encryptionId >> 24; 51 | } else { 52 | return _listIndex; 53 | } 54 | } 55 | 56 | uint8_t AddEncryptionIdToList::getDataLength() { 57 | return ADD_ENCRYPTION_ID_TO_LIST_LENGTH; 58 | } 59 | 60 | #ifdef NATIVE_API_AVAILABLE 61 | 62 | uint32_t AddEncryptionIdToList::execute() { 63 | return sd_ant_id_list_add(_channel, (uint8_t*)&_encryptionId, _listIndex); 64 | } 65 | 66 | #endif // NATIVE_API_AVAILABLE 67 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_AddEncryptionIdToList.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ADDENCRYPTIONIDTOLIST_h 2 | #define ANT_ADDENCRYPTIONIDTOLIST_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a Add Encryption Id To List message, it is used to add 8 | * an encryption id to a list 9 | */ 10 | class AddEncryptionIdToList : public AntRequest { 11 | public: 12 | AddEncryptionIdToList(); 13 | AddEncryptionIdToList(uint8_t channel, uint32_t encryptionId, uint8_t listIndex); 14 | void setChannel(uint8_t channel); 15 | void setEncryptionId(uint32_t encryptionId); 16 | void setListIndex(uint8_t listIndex); 17 | uint8_t getChannel(); 18 | uint32_t getEncryptionId(); 19 | uint8_t getListIndex(); 20 | uint8_t getData(uint8_t pos) override; 21 | uint8_t getDataLength() override; 22 | #ifdef NATIVE_API_AVAILABLE 23 | uint32_t execute() override; 24 | #endif 25 | private: 26 | uint8_t _channel = 0; 27 | uint32_t _encryptionId = 0; 28 | uint8_t _listIndex = 0; 29 | }; 30 | 31 | #endif // ANT_ADDENCRYPTIONIDTOLIST_h 32 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_AssignChannel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | AssignChannel::AssignChannel() : AntRequest(ASSIGN_CHANNEL) { 7 | 8 | } 9 | 10 | AssignChannel::AssignChannel(uint8_t channel, uint8_t channelType, uint8_t network) : AntRequest(ASSIGN_CHANNEL) { 11 | setChannel(channel); 12 | setChannelType(channelType); 13 | setChannelNetwork(network); 14 | } 15 | 16 | void AssignChannel::setChannel(uint8_t channel) { 17 | _channel = channel; 18 | } 19 | 20 | void AssignChannel::setChannelType(uint8_t channelType) { 21 | _channelType = channelType; 22 | } 23 | 24 | void AssignChannel::setChannelNetwork(uint8_t network) { 25 | _network = network; 26 | } 27 | 28 | // cppcheck-suppress unusedFunction 29 | void AssignChannel::setExtendedAssignment(uint8_t extended) { 30 | _extended = extended; 31 | } 32 | 33 | uint8_t AssignChannel::getChannel() { 34 | return _channel; 35 | } 36 | 37 | uint8_t AssignChannel::getChannelType() { 38 | return _channelType; 39 | } 40 | 41 | // cppcheck-suppress unusedFunction 42 | uint8_t AssignChannel::getChannelNetwork() { 43 | return _network; 44 | } 45 | 46 | // cppcheck-suppress unusedFunction 47 | uint8_t AssignChannel::getExtendedAssignment() { 48 | return _extended; 49 | } 50 | 51 | uint8_t AssignChannel::getDataLength() { 52 | return _extended == 0 ? ASSIGN_CHANNEL_LENGTH : ASSIGN_CHANNEL_LENGTH + 1; 53 | } 54 | 55 | uint8_t AssignChannel::getData(uint8_t pos) { 56 | if (pos == 0) { 57 | return _channel; 58 | } else if (pos == 1) { 59 | return _channelType; 60 | } else if (pos == 2) { 61 | return _network; 62 | } else { 63 | return _extended; 64 | } 65 | } 66 | 67 | #ifdef NATIVE_API_AVAILABLE 68 | 69 | uint32_t AssignChannel::execute() { 70 | return sd_ant_channel_assign(_channel, _channelType, _network, _extended); 71 | } 72 | 73 | #endif // NATIVE_API_AVAILABLE 74 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_AssignChannel.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ASSIGNCHANNEL_h 2 | #define ANT_ASSIGNCHANNEL_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a assign channel packet, which is used to associate a channel 8 | * 9 | */ 10 | class AssignChannel : public AntRequest { 11 | public: 12 | AssignChannel(); 13 | AssignChannel(uint8_t channel, uint8_t channelType, uint8_t network); 14 | void setChannel(uint8_t channel); 15 | void setChannelType(uint8_t channelType); 16 | void setChannelNetwork(uint8_t network); 17 | void setExtendedAssignment(uint8_t extended); 18 | uint8_t getChannel(); 19 | uint8_t getChannelType(); 20 | uint8_t getChannelNetwork(); 21 | uint8_t getExtendedAssignment(); 22 | uint8_t getData(uint8_t pos) override; 23 | uint8_t getDataLength() override; 24 | #ifdef NATIVE_API_AVAILABLE 25 | uint32_t execute() override; 26 | #endif 27 | private: 28 | uint8_t _channel = 0; 29 | uint8_t _channelType = 0; 30 | uint8_t _network = 0; 31 | uint8_t _extended = 0; 32 | }; 33 | 34 | #endif // ANT_ASSIGNCHANNEL_h 35 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelId.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | ChannelId::ChannelId() : AntRequest(CHANNEL_ID) { 7 | 8 | } 9 | 10 | ChannelId::ChannelId(uint8_t channel, uint16_t deviceNumber, uint8_t deviceType) : AntRequest(CHANNEL_ID) { 11 | setChannel(channel); 12 | setDeviceNumber(deviceNumber); 13 | setDeviceType(deviceType); 14 | } 15 | 16 | ChannelId::ChannelId(uint8_t channel, uint16_t deviceNumber, uint8_t deviceType, bool paringBit, uint8_t transmissionType) : AntRequest(CHANNEL_ID) { 17 | setChannel(channel); 18 | setDeviceNumber(deviceNumber); 19 | setDeviceType(deviceType); 20 | setPairingBit(paringBit); 21 | setTransmissionType(transmissionType); 22 | } 23 | 24 | void ChannelId::setChannel(uint8_t channel) { 25 | _channel = channel; 26 | } 27 | 28 | void ChannelId::setDeviceNumber(uint16_t deviceNumber) { 29 | _deviceNumber = deviceNumber; 30 | } 31 | 32 | void ChannelId::setDeviceType(uint8_t deviceType) { 33 | _deviceType = deviceType; 34 | } 35 | 36 | void ChannelId::setTransmissionType(uint8_t transmissionType) { 37 | _transmissionType = transmissionType; 38 | } 39 | 40 | void ChannelId::setPairingBit(bool paringBit) { 41 | _pairingBit = paringBit; 42 | } 43 | 44 | uint8_t ChannelId::getChannel() { 45 | return _channel; 46 | } 47 | 48 | uint16_t ChannelId::getDeviceNumber() { 49 | return _deviceNumber; 50 | } 51 | 52 | uint8_t ChannelId::getDeviceType() { 53 | return _deviceType; 54 | } 55 | 56 | uint8_t ChannelId::getTransmissionType() { 57 | return _transmissionType; 58 | } 59 | 60 | // cppcheck-suppress unusedFunction 61 | bool ChannelId::getPairingBit() { 62 | return _pairingBit; 63 | } 64 | 65 | uint8_t ChannelId::getDataLength() { 66 | return CHANNEL_ID_LENGTH; 67 | } 68 | 69 | uint8_t ChannelId::getData(uint8_t pos) { 70 | if (pos == 0) { 71 | return _channel; 72 | } else if (pos == 1) { 73 | return (uint8_t)_deviceNumber; 74 | } else if (pos == 2) { 75 | return (uint8_t)(_deviceNumber >> BITS_IN_BYTE); 76 | } else if (pos == 3) { 77 | // TODO get rid of magic numbers 78 | return _pairingBit ? ( _deviceType | 0x80 ) : ( _deviceType & 0x7F ); 79 | } else { 80 | return _transmissionType; 81 | } 82 | } 83 | 84 | #ifdef NATIVE_API_AVAILABLE 85 | 86 | uint32_t ChannelId::execute() { 87 | return sd_ant_channel_id_set(_channel, _deviceNumber, _deviceType, _transmissionType); 88 | } 89 | 90 | #endif // NATIVE_API_AVAILABLE 91 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelId.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CHANNELID_h 2 | #define ANT_CHANNELID_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a channel id message, it is used to 8 | * configure a channel connection on the ANT radio 9 | */ 10 | class ChannelId : public AntRequest { 11 | public: 12 | ChannelId(); 13 | ChannelId(uint8_t channel, uint16_t deviceNumber, uint8_t deviceType); 14 | ChannelId(uint8_t channel, uint16_t deviceNumber, uint8_t deviceType, bool paringBit, uint8_t transmissionType); 15 | void setChannel(uint8_t channel); 16 | void setDeviceNumber(uint16_t deviceNumber); 17 | void setDeviceType(uint8_t deviceType); 18 | void setPairingBit(bool paringBit); 19 | void setTransmissionType(uint8_t transmissionType); 20 | uint8_t getChannel(); 21 | uint16_t getDeviceNumber(); 22 | uint8_t getDeviceType(); 23 | bool getPairingBit(); 24 | uint8_t getTransmissionType(); 25 | uint8_t getData(uint8_t pos) override; 26 | uint8_t getDataLength() override; 27 | #ifdef NATIVE_API_AVAILABLE 28 | uint32_t execute() override; 29 | #endif 30 | private: 31 | uint8_t _channel = 0; 32 | uint16_t _deviceNumber = 0; 33 | uint8_t _deviceType = 0; 34 | // TODO figure out default for pairing bit, assuming false 35 | bool _pairingBit = false; 36 | uint8_t _transmissionType = 0; 37 | }; 38 | 39 | #endif // ANT_CHANNELID_h 40 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelPeriod.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | ChannelPeriod::ChannelPeriod() : AntRequest(CHANNEL_PERIOD) { 7 | 8 | } 9 | 10 | ChannelPeriod::ChannelPeriod(uint8_t channel, uint16_t period) : AntRequest(CHANNEL_PERIOD) { 11 | setChannel(channel); 12 | setPeriod(period); 13 | } 14 | 15 | void ChannelPeriod::setChannel(uint8_t channel) { 16 | _channel = channel; 17 | } 18 | 19 | void ChannelPeriod::setPeriod(uint16_t period) { 20 | _period = period; 21 | } 22 | 23 | uint8_t ChannelPeriod::getChannel() { 24 | return _channel; 25 | } 26 | 27 | // cppcheck-suppress unusedFunction 28 | uint16_t ChannelPeriod::getPeriod() { 29 | return _period; 30 | } 31 | 32 | uint8_t ChannelPeriod::getDataLength() { 33 | return CHANNEL_PERIOD_LENGTH; 34 | } 35 | 36 | uint8_t ChannelPeriod::getData(uint8_t pos) { 37 | if (pos == 0) { 38 | return _channel; 39 | } else if (pos == 1) { 40 | return (uint8_t)_period; 41 | } else { 42 | return (uint8_t)(_period >> BITS_IN_BYTE); 43 | } 44 | } 45 | 46 | #ifdef NATIVE_API_AVAILABLE 47 | 48 | uint32_t ChannelPeriod::execute() { 49 | return sd_ant_channel_period_set(_channel, _period); 50 | } 51 | 52 | #endif // NATIVE_API_AVAILABLE 53 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelPeriod.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CHANNELPERIOD_h 2 | #define ANT_CHANNELPERIOD_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a channel period message, it is used to 8 | * configure a channel period on the ANT radio 9 | */ 10 | class ChannelPeriod : public AntRequest { 11 | public: 12 | ChannelPeriod(); 13 | ChannelPeriod(uint8_t channel, uint16_t period); 14 | void setChannel(uint8_t channel); 15 | void setPeriod(uint16_t period); 16 | uint8_t getChannel(); 17 | uint16_t getPeriod(); 18 | uint8_t getData(uint8_t pos) override; 19 | uint8_t getDataLength() override; 20 | #ifdef NATIVE_API_AVAILABLE 21 | uint32_t execute() override; 22 | #endif 23 | private: 24 | uint8_t _channel = 0; 25 | uint16_t _period = 0; 26 | }; 27 | 28 | #endif // ANT_CHANNELPERIOD_h 29 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelRfFrequency.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | ChannelRfFrequency::ChannelRfFrequency() : AntRequest(CHANNEL_RF_FREQUENCY) { 7 | 8 | } 9 | 10 | ChannelRfFrequency::ChannelRfFrequency(uint8_t channel, uint8_t frequency) : AntRequest(CHANNEL_RF_FREQUENCY) { 11 | setChannel(channel); 12 | setRfFrequency(frequency); 13 | } 14 | 15 | void ChannelRfFrequency::setChannel(uint8_t channel) { 16 | _channel = channel; 17 | } 18 | 19 | void ChannelRfFrequency::setRfFrequency(uint8_t frequency) { 20 | _frequency = frequency; 21 | } 22 | 23 | uint8_t ChannelRfFrequency::getChannel() { 24 | return _channel; 25 | } 26 | 27 | // cppcheck-suppress unusedFunction 28 | uint8_t ChannelRfFrequency::getRfFrequency() { 29 | return _frequency; 30 | } 31 | 32 | uint8_t ChannelRfFrequency::getDataLength() { 33 | return CHANNEL_RF_FREQUENCY_LENGTH; 34 | } 35 | 36 | uint8_t ChannelRfFrequency::getData(uint8_t pos) { 37 | if (pos == 0) { 38 | return _channel; 39 | } else { 40 | return _frequency; 41 | } 42 | } 43 | 44 | #ifdef NATIVE_API_AVAILABLE 45 | 46 | uint32_t ChannelRfFrequency::execute() { 47 | return sd_ant_channel_radio_freq_set(_channel, _frequency); 48 | } 49 | 50 | #endif // NATIVE_API_AVAILABLE 51 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelRfFrequency.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CHANNELRFFREQUENCY_h 2 | #define ANT_CHANNELRFFREQUENCY_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a channel rf frequency message, it is used to 8 | * configure a channel period on the ANT radio 9 | */ 10 | class ChannelRfFrequency : public AntRequest { 11 | public: 12 | ChannelRfFrequency(); 13 | ChannelRfFrequency(uint8_t channel, uint8_t frequency); 14 | void setChannel(uint8_t channel); 15 | void setRfFrequency(uint8_t frequency); 16 | uint8_t getChannel(); 17 | uint8_t getRfFrequency(); 18 | uint8_t getData(uint8_t pos) override; 19 | uint8_t getDataLength() override; 20 | #ifdef NATIVE_API_AVAILABLE 21 | uint32_t execute() override; 22 | #endif // NATIVE_API_AVAILABLE 23 | private: 24 | uint8_t _channel = 0; 25 | uint8_t _frequency = 0; 26 | }; 27 | 28 | #endif // ANT_CHANNELRFFREQUENCY_h 29 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelSearchPriority.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | ChannelSearchPriority::ChannelSearchPriority() : AntRequest(CHANNEL_SEARCH_PRIORITY) { 6 | 7 | } 8 | 9 | ChannelSearchPriority::ChannelSearchPriority(uint8_t channel, uint8_t priority) : AntRequest(CHANNEL_SEARCH_PRIORITY) { 10 | setChannel(channel); 11 | setPriority(priority); 12 | } 13 | 14 | void ChannelSearchPriority::setChannel(uint8_t channel) { 15 | _channel = channel; 16 | } 17 | 18 | void ChannelSearchPriority::setPriority(uint8_t priority) { 19 | _priority = priority; 20 | } 21 | 22 | uint8_t ChannelSearchPriority::getChannel() { 23 | return _channel; 24 | } 25 | 26 | // cppcheck-suppress unusedFunction 27 | uint8_t ChannelSearchPriority::getPriority() { 28 | return _priority; 29 | } 30 | 31 | uint8_t ChannelSearchPriority::getData(uint8_t pos) { 32 | if (pos == 0) { 33 | return _channel; 34 | } else { 35 | return _priority; 36 | } 37 | } 38 | 39 | uint8_t ChannelSearchPriority::getDataLength() { 40 | return CHANNEL_SEARCH_PRIORITY_LENGTH; 41 | } 42 | 43 | #ifdef NATIVE_API_AVAILABLE 44 | 45 | uint32_t ChannelSearchPriority::execute() { 46 | return sd_ant_search_channel_priority_set(_channel, _priority); 47 | } 48 | 49 | #endif // NATIVE_API_AVAILABLE 50 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelSearchPriority.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CHANNELSEARCHPRIORITY_h 2 | #define ANT_CHANNELSEARCHPRIORITY_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a channel search priority message, it is used to 8 | * configure a channels priority when searching for its device. 9 | * Higher priority channels will pre-empt lower priority channels 10 | */ 11 | class ChannelSearchPriority : public AntRequest { 12 | public: 13 | ChannelSearchPriority(); 14 | ChannelSearchPriority(uint8_t channel, uint8_t priority); 15 | void setChannel(uint8_t channel); 16 | void setPriority(uint8_t priority); 17 | uint8_t getChannel(); 18 | uint8_t getPriority(); 19 | uint8_t getData(uint8_t pos) override; 20 | uint8_t getDataLength() override; 21 | #ifdef NATIVE_API_AVAILABLE 22 | uint32_t execute() override; 23 | #endif // NATIVE_API_AVAILABLE 24 | private: 25 | uint8_t _channel = 0; 26 | uint8_t _priority = 0; 27 | }; 28 | 29 | #endif // ANT_CHANNELSEARCHPRIORITY_h 30 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelSearchSharing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | ChannelSearchSharing::ChannelSearchSharing() : AntRequest(CHANNEL_SEARCH_SHARING) { 6 | 7 | } 8 | 9 | ChannelSearchSharing::ChannelSearchSharing(uint8_t channel, uint8_t cycles) : AntRequest(CHANNEL_SEARCH_SHARING) { 10 | setChannel(channel); 11 | setSearchcycles(cycles); 12 | } 13 | 14 | void ChannelSearchSharing::setChannel(uint8_t channel) { 15 | _channel = channel; 16 | } 17 | 18 | void ChannelSearchSharing::setSearchcycles(uint8_t cycles) { 19 | _cycles = cycles; 20 | } 21 | 22 | uint8_t ChannelSearchSharing::getChannel() { 23 | return _channel; 24 | } 25 | 26 | // cppcheck-suppress unusedFunction 27 | uint8_t ChannelSearchSharing::getSearchCycles() { 28 | return _cycles; 29 | } 30 | 31 | uint8_t ChannelSearchSharing::getData(uint8_t pos) { 32 | if (pos == 0) { 33 | return _channel; 34 | } else { 35 | return _cycles; 36 | } 37 | } 38 | 39 | uint8_t ChannelSearchSharing::getDataLength() { 40 | return CHANNEL_SEARCH_SHARING_LENGTH; 41 | } 42 | 43 | #ifdef NATIVE_API_AVAILABLE 44 | 45 | uint32_t ChannelSearchSharing::execute() { 46 | return sd_ant_active_search_sharing_cycles_set(_channel, _cycles); 47 | } 48 | 49 | #endif // NATIVE_API_AVAILABLE 50 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ChannelSearchSharing.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CHANNELSEARCHSHARING_h 2 | #define ANT_CHANNELSEARCHSHARING_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a channel search sharing message, it is used to 8 | * configure a channels share cycles when searching for its device. 9 | * Only channels with the same search priority will share the 10 | * radio when searching 11 | */ 12 | class ChannelSearchSharing : public AntRequest { 13 | public: 14 | ChannelSearchSharing(); 15 | ChannelSearchSharing(uint8_t channel, uint8_t cycles); 16 | void setChannel(uint8_t channel); 17 | void setSearchcycles(uint8_t cycles); 18 | uint8_t getChannel(); 19 | uint8_t getSearchCycles(); 20 | uint8_t getData(uint8_t pos) override; 21 | uint8_t getDataLength() override; 22 | #ifdef NATIVE_API_AVAILABLE 23 | uint32_t execute() override; 24 | #endif // NATIVE_API_AVAILABLE 25 | private: 26 | uint8_t _channel = 0; 27 | uint8_t _cycles = 0; 28 | }; 29 | 30 | #endif // ANT_CHANNELSEARCHSHARING_h 31 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigEncryptionIdList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | ConfigEncryptionIdList::ConfigEncryptionIdList() : AntRequest(CONFIG_ENCRYPTION_ID_LIST) { 6 | 7 | } 8 | 9 | ConfigEncryptionIdList::ConfigEncryptionIdList(uint8_t channel, uint8_t size, uint8_t type) : AntRequest(CONFIG_ENCRYPTION_ID_LIST) { 10 | setChannel(channel); 11 | setListSize(size); 12 | setListType(type); 13 | } 14 | 15 | void ConfigEncryptionIdList::setChannel(uint8_t channel) { 16 | _channel = channel; 17 | } 18 | 19 | void ConfigEncryptionIdList::setListSize(uint8_t size) { 20 | _size = size <= CONFIG_ENCRYPTION_ID_LIST_MAX_LIST_SIZE ? size : CONFIG_ENCRYPTION_ID_LIST_MAX_LIST_SIZE; 21 | } 22 | 23 | void ConfigEncryptionIdList::setListType(uint8_t type) { 24 | _type = type; 25 | } 26 | 27 | uint8_t ConfigEncryptionIdList::getChannel() { 28 | return _channel; 29 | } 30 | 31 | // cppcheck-suppress unusedFunction 32 | uint8_t ConfigEncryptionIdList::getListSize() { 33 | return _size; 34 | } 35 | 36 | // cppcheck-suppress unusedFunction 37 | uint8_t ConfigEncryptionIdList::getListType() { 38 | return _type; 39 | } 40 | 41 | uint8_t ConfigEncryptionIdList::getData(uint8_t pos) { 42 | if (pos == 0) { 43 | return _channel; 44 | } else if (pos == 1) { 45 | return _size; 46 | } else { 47 | return _type; 48 | } 49 | } 50 | 51 | uint8_t ConfigEncryptionIdList::getDataLength() { 52 | return CONFIG_ENCRYPTION_ID_LIST_LENGTH; 53 | } 54 | 55 | #ifdef NATIVE_API_AVAILABLE 56 | 57 | uint32_t ConfigEncryptionIdList::execute() { 58 | // TODO 59 | return 0; 60 | } 61 | 62 | #endif // NATIVE_API_AVAILABLE 63 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigEncryptionIdList.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CONFIGENCRYPTIONIDLIST_h 2 | #define ANT_CONFIGENCRYPTIONIDLIST_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a Config Encryption Id List message, it is used to 8 | * configure a encryption ID list for a specific channel 9 | * IDs must be configured using AddEncryptionIdToList 10 | */ 11 | class ConfigEncryptionIdList : public AntRequest { 12 | public: 13 | ConfigEncryptionIdList(); 14 | ConfigEncryptionIdList(uint8_t channel, uint8_t size, uint8_t type); 15 | void setChannel(uint8_t channel); 16 | void setListSize(uint8_t size); // [0-4] 17 | void setListType(uint8_t type); 18 | uint8_t getChannel(); 19 | uint8_t getListSize(); 20 | uint8_t getListType(); 21 | uint8_t getData(uint8_t pos) override; 22 | uint8_t getDataLength() override; 23 | #ifdef NATIVE_API_AVAILABLE 24 | uint32_t execute() override; 25 | #endif // NATIVE_API_AVAILABLE 26 | private: 27 | uint8_t _channel = 0; 28 | uint8_t _size = 0; 29 | uint8_t _type = 0; 30 | }; 31 | 32 | #endif // ANT_CONFIGENCRYPTIONIDLIST_h 33 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigIdList.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | ConfigIdList::ConfigIdList() : AntRequest(CONFIG_ID_LIST) { 6 | 7 | } 8 | 9 | ConfigIdList::ConfigIdList(uint8_t channel, uint8_t size, uint8_t type) : AntRequest(CONFIG_ID_LIST) { 10 | setChannel(channel); 11 | setListSize(size); 12 | setExclusion(type); 13 | } 14 | 15 | void ConfigIdList::setChannel(uint8_t channel) { 16 | _channel = channel; 17 | } 18 | 19 | void ConfigIdList::setListSize(uint8_t size) { 20 | _size = size <= CONFIG_ID_LIST_LIST_MAX_SIZE ? size : CONFIG_ID_LIST_LIST_MAX_SIZE; 21 | } 22 | 23 | void ConfigIdList::setExclusion(uint8_t type) { 24 | _type = type; 25 | } 26 | 27 | uint8_t ConfigIdList::getChannel() { 28 | return _channel; 29 | } 30 | 31 | uint8_t ConfigIdList::getListSize() { 32 | return _size; 33 | } 34 | 35 | uint8_t ConfigIdList::getListType() { 36 | return _type; 37 | } 38 | 39 | uint8_t ConfigIdList::getData(uint8_t pos) { 40 | if (pos == 0) { 41 | return _channel; 42 | } else if (pos == 1) { 43 | return _size; 44 | } else { 45 | return _type; 46 | } 47 | } 48 | 49 | uint8_t ConfigIdList::getDataLength() { 50 | return CONFIG_ID_LIST_LENGTH; 51 | } 52 | 53 | #ifdef NATIVE_API_AVAILABLE 54 | 55 | uint32_t ConfigIdList::execute() { 56 | return sd_ant_id_list_config(_channel, _size, _type); 57 | } 58 | 59 | #endif // NATIVE_API_AVAILABLE 60 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigIdList.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CONFIGIDLIST_h 2 | #define ANT_CONFIGIDLIST_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a Config Id List message, it is used to 8 | * configure a ID list for a specific channel for 9 | * inclusion/exclusion purposes. This only works in slave mode. 10 | */ 11 | class ConfigIdList : public AntRequest { 12 | public: 13 | ConfigIdList(); 14 | ConfigIdList(uint8_t channel, uint8_t size, uint8_t type); 15 | void setChannel(uint8_t channel); 16 | void setListSize(uint8_t size); // [0-4] 17 | void setExclusion(uint8_t type); 18 | uint8_t getChannel(); 19 | uint8_t getListSize(); 20 | uint8_t getListType(); 21 | uint8_t getData(uint8_t pos) override; 22 | uint8_t getDataLength() override; 23 | #ifdef NATIVE_API_AVAILABLE 24 | uint32_t execute() override; 25 | #endif // NATIVE_API_AVAILABLE 26 | private: 27 | uint8_t _channel = 0; 28 | uint8_t _size = 0; 29 | uint8_t _type = 0; 30 | }; 31 | 32 | #endif // ANT_CONFIGIDLIST_h 33 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigureAdvancedBurst.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | ConfigureAdvancedBurst::ConfigureAdvancedBurst() : AntRequest(CONFIGURE_ADVANCED_BURST) { 6 | 7 | } 8 | 9 | ConfigureAdvancedBurst::ConfigureAdvancedBurst(uint8_t enable, uint8_t maxPacketLength) : AntRequest(CONFIGURE_ADVANCED_BURST) { 10 | setEnable(enable); 11 | setMaxPacketLength(maxPacketLength); 12 | } 13 | 14 | void ConfigureAdvancedBurst::setEnable(uint8_t enable) { 15 | _enable = enable; 16 | } 17 | 18 | void ConfigureAdvancedBurst::setMaxPacketLength(uint8_t maxPacketLength) { 19 | _maxPacketLength = maxPacketLength; 20 | } 21 | 22 | // cppcheck-suppress unusedFunction 23 | void ConfigureAdvancedBurst::setRequiredFeatures(uint32_t requiredFeatures) { 24 | _requiredFeatures = requiredFeatures; 25 | } 26 | 27 | // cppcheck-suppress unusedFunction 28 | void ConfigureAdvancedBurst::setOptionalFeatures(uint32_t optionalFeatures) { 29 | _optionalFeatures = optionalFeatures; 30 | } 31 | 32 | // cppcheck-suppress unusedFunction 33 | void ConfigureAdvancedBurst::setStallCount(uint16_t stallCount) { 34 | // TODO handle extentions 35 | _stallCount = stallCount; 36 | } 37 | 38 | // cppcheck-suppress unusedFunction 39 | void ConfigureAdvancedBurst::setRetryCount(uint8_t retryCount) { 40 | // TODO handle extentions 41 | _retryCount = retryCount; 42 | } 43 | 44 | // cppcheck-suppress unusedFunction 45 | uint8_t ConfigureAdvancedBurst::getEnable() { 46 | return _enable; 47 | } 48 | 49 | uint8_t ConfigureAdvancedBurst::getMaxPacketLength() { 50 | return _maxPacketLength; 51 | } 52 | 53 | uint32_t ConfigureAdvancedBurst::getRequiredFeatures() { 54 | return _requiredFeatures; 55 | } 56 | 57 | uint32_t ConfigureAdvancedBurst::getOptionalFeatures() { 58 | return _optionalFeatures; 59 | } 60 | 61 | // cppcheck-suppress unusedFunction 62 | uint16_t ConfigureAdvancedBurst::getStallCount() { 63 | return _stallCount; 64 | } 65 | 66 | // cppcheck-suppress unusedFunction 67 | uint8_t ConfigureAdvancedBurst::getRetryCount() { 68 | return _retryCount; 69 | } 70 | 71 | uint8_t ConfigureAdvancedBurst::getData(uint8_t pos) { 72 | if (pos == 0) { 73 | return 0; 74 | } else if (pos == 1) { 75 | return _enable; 76 | } else if (pos == 2) { 77 | return _maxPacketLength; 78 | } else if (pos == 3) { 79 | return _requiredFeatures & 0xFF; 80 | } else if (pos == 4) { 81 | return (_requiredFeatures >> 8) & 0xFF; 82 | } else if (pos == 5) { 83 | return (_requiredFeatures >> 16) & 0xFF; 84 | } else if (pos == 6) { 85 | return _optionalFeatures & 0xFF; 86 | } else if (pos == 7) { 87 | return (_optionalFeatures >> 8) & 0xFF; 88 | } else { 89 | return (_optionalFeatures >> 16) & 0xFF; 90 | } 91 | } 92 | 93 | uint8_t ConfigureAdvancedBurst::getDataLength() { 94 | return CONFIGURE_ADVANCED_BURST_LENGTH; 95 | } 96 | 97 | #ifdef NATIVE_API_AVAILABLE 98 | 99 | uint32_t ConfigureAdvancedBurst::execute() { 100 | // TODO arguments need to be packed into an array 101 | // return sd_ant_adv_burst_config_set(); 102 | return 0; 103 | } 104 | 105 | #endif // NATIVE_API_AVAILABLE 106 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigureAdvancedBurst.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CONFIGUREADVANCEDBURST_h 2 | #define ANT_CONFIGUREADVANCEDBURST_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a configure advanced burst packet 8 | * 9 | */ 10 | class ConfigureAdvancedBurst : public AntRequest { 11 | public: 12 | ConfigureAdvancedBurst(); 13 | ConfigureAdvancedBurst(uint8_t enable, uint8_t maxPacketLength); 14 | void setEnable(uint8_t enable); 15 | void setMaxPacketLength(uint8_t maxPacketLength); 16 | void setRequiredFeatures(uint32_t requiredFeatures); 17 | void setOptionalFeatures(uint32_t optionalFeatures); 18 | void setStallCount(uint16_t stallCount); 19 | void setRetryCount(uint8_t retryCount); 20 | uint8_t getEnable(); 21 | uint8_t getMaxPacketLength(); 22 | uint32_t getRequiredFeatures(); 23 | uint32_t getOptionalFeatures(); 24 | uint16_t getStallCount(); 25 | uint8_t getRetryCount(); 26 | uint8_t getData(uint8_t pos) override; 27 | uint8_t getDataLength() override; 28 | #ifdef NATIVE_API_AVAILABLE 29 | uint32_t execute() override; 30 | #endif 31 | private: 32 | uint8_t _enable = 0; 33 | uint8_t _maxPacketLength = 0; 34 | uint32_t _requiredFeatures = 0; 35 | uint32_t _optionalFeatures = 0; 36 | uint16_t _stallCount = 0; 37 | uint8_t _retryCount = 0; 38 | uint8_t _extended = 0; 39 | }; 40 | 41 | #endif // ANT_CONFIGUREADVANCEDBURST_h 42 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigureEventFilter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | ConfigureEventFilter::ConfigureEventFilter() : AntRequest(CONFIGURE_EVENT_FILTER) { 6 | 7 | } 8 | 9 | ConfigureEventFilter::ConfigureEventFilter(uint16_t eventFilter) : AntRequest(CONFIGURE_EVENT_FILTER) { 10 | setEventFilter(eventFilter); 11 | } 12 | 13 | void ConfigureEventFilter::setEventFilter(uint16_t eventFilter) { 14 | _eventFilter = eventFilter; 15 | } 16 | 17 | uint16_t ConfigureEventFilter::getEventFilter() { 18 | return _eventFilter; 19 | } 20 | 21 | uint8_t ConfigureEventFilter::getData(uint8_t pos) { 22 | if (pos == 0) { 23 | return 0; 24 | } else if (pos == 1) { 25 | return _eventFilter & 0xFF; 26 | } else { 27 | return _eventFilter >> 8; 28 | } 29 | } 30 | 31 | uint8_t ConfigureEventFilter::getDataLength() { 32 | return CONFIGURE_EVENT_FILTER_LENTGH; 33 | } 34 | 35 | #ifdef NATIVE_API_AVAILABLE 36 | 37 | uint32_t ConfigureEventFilter::execute() { 38 | return sd_ant_event_filtering_set(_eventFilter); 39 | } 40 | 41 | #endif // NATIVE_API_AVAILABLE 42 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigureEventFilter.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CONFIGUREEVENTFILTER_h 2 | #define ANT_CONFIGUREEVENTFILTER_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a configure event filter packet 8 | * 9 | */ 10 | class ConfigureEventFilter : public AntRequest { 11 | public: 12 | ConfigureEventFilter(); 13 | explicit ConfigureEventFilter(uint16_t eventFilter); 14 | void setEventFilter(uint16_t eventFilter); 15 | uint16_t getEventFilter(); 16 | uint8_t getData(uint8_t pos) override; 17 | uint8_t getDataLength() override; 18 | #ifdef NATIVE_API_AVAILABLE 19 | uint32_t execute() override; 20 | #endif // NATIVE_API_AVAILABLE 21 | private: 22 | uint16_t _eventFilter = 0; 23 | }; 24 | 25 | #endif // ANT_CONFIGUREEVENTFILTER_h 26 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigureSelectiveDataUpdates.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | ConfigureSelectiveDataUpdates::ConfigureSelectiveDataUpdates() : AntRequest(CONFIGURE_SELECTIVE_DATA_UPDATES) { 5 | 6 | } 7 | 8 | ConfigureSelectiveDataUpdates::ConfigureSelectiveDataUpdates(uint8_t channel) : AntRequest(CONFIGURE_SELECTIVE_DATA_UPDATES) { 9 | setChannelNumber(channel); 10 | } 11 | 12 | void ConfigureSelectiveDataUpdates::setChannelNumber(uint8_t channel) { 13 | _channel = channel; 14 | } 15 | 16 | // cppcheck-suppress unusedFunction 17 | void ConfigureSelectiveDataUpdates::setSDUMaskNumer(uint8_t maskNo) { 18 | _selectedData = (maskNo << 7) | (_selectedData & ~CONFIGURE_SELECTIVE_DATA_UPDATES_SDU_NUMBER_MASK); 19 | } 20 | 21 | // cppcheck-suppress unusedFunction 22 | void ConfigureSelectiveDataUpdates::setFilterAcknowledged(uint8_t filterBit) { 23 | _selectedData = (filterBit & CONFIGURE_SELECTIVE_DATA_UPDATES_FILTER_BIT_MASK) | (_selectedData & ~CONFIGURE_SELECTIVE_DATA_UPDATES_FILTER_BIT_MASK); 24 | } 25 | 26 | // cppcheck-suppress unusedFunction 27 | void ConfigureSelectiveDataUpdates::setDisableSDUOnChannel() { 28 | _selectedData = CONFIGURE_SELECTIVE_DATA_UPDATES_SDU_DISABLE; 29 | } 30 | 31 | uint8_t ConfigureSelectiveDataUpdates::getChannelNumber() { 32 | return _channel; 33 | } 34 | 35 | // cppcheck-suppress unusedFunction 36 | uint8_t ConfigureSelectiveDataUpdates::getSDUMaskNumer() { 37 | return _selectedData & CONFIGURE_SELECTIVE_DATA_UPDATES_SDU_NUMBER_MASK; 38 | } 39 | 40 | // cppcheck-suppress unusedFunction 41 | uint8_t ConfigureSelectiveDataUpdates::getFilterAcknowledged() { 42 | return _selectedData >> 7; 43 | } 44 | 45 | uint8_t ConfigureSelectiveDataUpdates::getData(uint8_t pos) { 46 | if (pos == 0) { 47 | return _channel; 48 | } else { 49 | return _selectedData; 50 | } 51 | } 52 | 53 | uint8_t ConfigureSelectiveDataUpdates::getDataLength() { 54 | return CONFIGURE_SELECTIVE_DATA_UPDATES_LENGTH; 55 | } 56 | 57 | #ifdef NATIVE_API_AVAILABLE 58 | 59 | uint32_t ConfigureSelectiveDataUpdates::execute() { 60 | // TODO 61 | return 0; 62 | } 63 | 64 | #endif // NATIVE_API_AVAILABLE 65 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ConfigureSelectiveDataUpdates.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CONFIGURESELECTIVEDATAUPDATES_h 2 | #define ANT_CONFIGURESELECTIVEDATAUPDATES_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a configure SDU packet 8 | * 9 | */ 10 | class ConfigureSelectiveDataUpdates : public AntRequest { 11 | public: 12 | ConfigureSelectiveDataUpdates(); 13 | explicit ConfigureSelectiveDataUpdates(uint8_t channel); 14 | void setChannelNumber(uint8_t channel); 15 | void setSDUMaskNumer(uint8_t maskNo); 16 | /** 17 | * 0 Filter broadcast only 18 | * 1 Filter broadcast and Acknowledged 19 | */ 20 | void setFilterAcknowledged(uint8_t filterBit); 21 | /** 22 | * Do not call any other setters after calling this function 23 | * 24 | * Use this function to disable the SDU mask on the specified channel 25 | */ 26 | void setDisableSDUOnChannel(); 27 | uint8_t getChannelNumber(); 28 | uint8_t getSDUMaskNumer(); 29 | uint8_t getFilterAcknowledged(); 30 | uint8_t getData(uint8_t pos) override; 31 | uint8_t getDataLength() override; 32 | #ifdef NATIVE_API_AVAILABLE 33 | uint32_t execute() override; 34 | #endif // NATIVE_API_AVAILABLE 35 | private: 36 | uint8_t _channel = 0; 37 | uint8_t _selectedData = 0; 38 | }; 39 | 40 | #endif // ANT_CONFIGURESELECTIVEDATAUPDATES_h 41 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_EnableExtRxMessages.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | EnableExtRxMessages::EnableExtRxMessages() : AntRequest(ENABLE_EXT_RX_MESSAGES) {} 6 | 7 | EnableExtRxMessages::EnableExtRxMessages(uint8_t enable) : AntRequest(ENABLE_EXT_RX_MESSAGES) { 8 | setEnable(enable); 9 | } 10 | 11 | void EnableExtRxMessages::setEnable(uint8_t enable) { 12 | _enable = enable; 13 | } 14 | 15 | uint8_t EnableExtRxMessages::getEnable() { 16 | return _enable; 17 | } 18 | 19 | uint8_t EnableExtRxMessages::getData(uint8_t pos) { 20 | if (pos == 0) { 21 | return 0; 22 | } else { 23 | return _enable; 24 | } 25 | } 26 | 27 | uint8_t EnableExtRxMessages::getDataLength() { 28 | return ENABLE_EXT_RX_MESSAGES_LENGTH; 29 | } 30 | 31 | 32 | #ifdef NATIVE_API_AVAILABLE 33 | 34 | uint32_t EnableExtRxMessages::execute() { 35 | if (_enable) 36 | return sd_ant_lib_config_set(LIB_CONFIG_CHANNEL_ID); 37 | else 38 | return sd_ant_lib_config_clear(LIB_CONFIG_CHANNEL_ID); 39 | } 40 | 41 | #endif // NATIVE_API_AVAILABLE 42 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_EnableExtRxMessages.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ENABLEEXTRXMESSAGES_h 2 | #define ANT_ENABLEEXTRXMESSAGES_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a enable Ext rx messages 8 | * 9 | * used to enable extended fields on data messages 10 | */ 11 | class EnableExtRxMessages : public AntRequest { 12 | public: 13 | EnableExtRxMessages(); 14 | explicit EnableExtRxMessages(uint8_t enable); 15 | void setEnable(uint8_t enable); 16 | uint8_t getEnable(); 17 | uint8_t getData(uint8_t pos) override; 18 | uint8_t getDataLength() override; 19 | #ifdef NATIVE_API_AVAILABLE 20 | uint32_t execute() override; 21 | #endif // NATIVE_API_AVAILABLE 22 | private: 23 | uint8_t _enable = 0; 24 | }; 25 | 26 | #endif // ANT_ENABLEEXTRXMESSAGES_h 27 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_EnableSingleChannelEncryption.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | EnableSingleChannelEncryption::EnableSingleChannelEncryption() : AntRequest(ENABLE_SINGLE_CHANNEL_ENCRYPTION) {} 6 | 7 | EnableSingleChannelEncryption::EnableSingleChannelEncryption(uint8_t channel) : AntRequest(ENABLE_SINGLE_CHANNEL_ENCRYPTION) { 8 | setChannel(channel); 9 | } 10 | 11 | void EnableSingleChannelEncryption::setChannel(uint8_t channel) { 12 | _channel = channel; 13 | } 14 | 15 | // cppcheck-suppress unusedFunction 16 | void EnableSingleChannelEncryption::setEncryptionMode(uint8_t encryptionMode) { 17 | _encryptionMode = encryptionMode; 18 | } 19 | 20 | // cppcheck-suppress unusedFunction 21 | void EnableSingleChannelEncryption::setVolatileKeyIndex(uint8_t index) { 22 | _volatileKeyIndex = index; 23 | } 24 | 25 | // cppcheck-suppress unusedFunction 26 | void EnableSingleChannelEncryption::setDecimationRate(uint8_t rate) { 27 | _decimationRate = rate; 28 | } 29 | 30 | uint8_t EnableSingleChannelEncryption::getChannel() { 31 | return _channel; 32 | } 33 | 34 | // cppcheck-suppress unusedFunction 35 | uint8_t EnableSingleChannelEncryption::getEncryptionMode() { 36 | return _encryptionMode; 37 | } 38 | 39 | // cppcheck-suppress unusedFunction 40 | uint8_t EnableSingleChannelEncryption::getVolatileKeyIndex() { 41 | return _volatileKeyIndex; 42 | } 43 | 44 | // cppcheck-suppress unusedFunction 45 | uint8_t EnableSingleChannelEncryption::getDecimationRate() { 46 | return _decimationRate; 47 | } 48 | 49 | uint8_t EnableSingleChannelEncryption::getData(uint8_t pos) { 50 | if (pos == 0) { 51 | return _channel; 52 | } else if (pos == 1) { 53 | return _encryptionMode; 54 | } else if (pos == 2) { 55 | return _volatileKeyIndex; 56 | } else { 57 | return _decimationRate; 58 | } 59 | } 60 | 61 | uint8_t EnableSingleChannelEncryption::getDataLength() { 62 | return ENABLE_SINGLE_CHANNEL_ENCRYPTION_LENGTH; 63 | } 64 | 65 | #ifdef NATIVE_API_AVAILABLE 66 | 67 | uint32_t EnableSingleChannelEncryption::execute() { 68 | return sd_ant_crypto_channel_enable(_channel, _encryptionMode, _volatileKeyIndex, _decimationRate); 69 | } 70 | 71 | #endif // NATIVE_API_AVAILABLE 72 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_EnableSingleChannelEncryption.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ENABLESINGLECHANNELENCRYPTION_h 2 | #define ANT_ENABLESINGLECHANNELENCRYPTION_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a enable single channel encryption 8 | * 9 | * used to enable encryption on a single channel 10 | */ 11 | class EnableSingleChannelEncryption : public AntRequest { 12 | public: 13 | EnableSingleChannelEncryption(); 14 | explicit EnableSingleChannelEncryption(uint8_t channel); 15 | void setChannel(uint8_t channel); 16 | void setEncryptionMode(uint8_t encryptionMode); 17 | void setVolatileKeyIndex(uint8_t index); 18 | void setDecimationRate(uint8_t rate); 19 | uint8_t getChannel(); 20 | uint8_t getEncryptionMode(); 21 | uint8_t getVolatileKeyIndex(); 22 | uint8_t getDecimationRate(); 23 | uint8_t getData(uint8_t pos) override; 24 | uint8_t getDataLength() override; 25 | #ifdef NATIVE_API_AVAILABLE 26 | uint32_t execute() override; 27 | #endif // NATIVE_API_AVAILABLE 28 | private: 29 | uint8_t _channel = 0; 30 | uint8_t _encryptionMode = 0; 31 | uint8_t _volatileKeyIndex = 0; 32 | uint8_t _decimationRate = 0; 33 | }; 34 | 35 | #endif // ANT_ENABLESINGLECHANNELENCRYPTION_h 36 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_FrequencyAgility.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | FrequencyAgility::FrequencyAgility() : AntRequest(FREQUENCY_AGILITY) {} 6 | 7 | FrequencyAgility::FrequencyAgility(uint8_t channel) : AntRequest(FREQUENCY_AGILITY) { 8 | setChannel(channel); 9 | } 10 | 11 | FrequencyAgility::FrequencyAgility(uint8_t channel, uint8_t freq1, uint8_t freq2, uint8_t freq3) : AntRequest(FREQUENCY_AGILITY) { 12 | setChannel(channel); 13 | setFrequency1(freq1); 14 | setFrequency2(freq2); 15 | setFrequency3(freq3); 16 | } 17 | 18 | void FrequencyAgility::setChannel(uint8_t channel) { 19 | _channel = channel; 20 | } 21 | 22 | // cppcheck-suppress unusedFunction 23 | void FrequencyAgility::setFrequency(uint8_t index, uint8_t freq) { 24 | if (index == 1) { 25 | setFrequency1(freq); 26 | } else if (index == 2) { 27 | setFrequency2(freq); 28 | } else { 29 | setFrequency3(freq); 30 | } 31 | } 32 | 33 | void FrequencyAgility::setFrequency1(uint8_t freq) { 34 | _freq1 = freq; 35 | } 36 | 37 | void FrequencyAgility::setFrequency2(uint8_t freq) { 38 | _freq2 = freq; 39 | } 40 | 41 | void FrequencyAgility::setFrequency3(uint8_t freq) { 42 | _freq3 = freq; 43 | } 44 | 45 | uint8_t FrequencyAgility::getChannel() { 46 | return _channel; 47 | } 48 | 49 | // cppcheck-suppress unusedFunction 50 | uint8_t FrequencyAgility::getFrequency(uint8_t index) { 51 | if (index == 1) { 52 | return getFrequency1(); 53 | } else if (index == 2) { 54 | return getFrequency2(); 55 | } else { 56 | return getFrequency3(); 57 | } 58 | } 59 | 60 | uint8_t FrequencyAgility::getFrequency1() { 61 | return _freq1; 62 | } 63 | 64 | uint8_t FrequencyAgility::getFrequency2() { 65 | return _freq2; 66 | } 67 | 68 | uint8_t FrequencyAgility::getFrequency3() { 69 | return _freq3; 70 | } 71 | 72 | uint8_t FrequencyAgility::getData(uint8_t pos) { 73 | if (pos == 0) { 74 | return _channel; 75 | } else if (pos == 1) { 76 | return _freq1; 77 | } else if (pos == 2) { 78 | return _freq2; 79 | } else { 80 | return _freq3; 81 | } 82 | } 83 | 84 | uint8_t FrequencyAgility::getDataLength() { 85 | return FREQUENCY_AGILITY_LENGTH; 86 | } 87 | 88 | #ifdef NATIVE_API_AVAILABLE 89 | 90 | uint32_t FrequencyAgility::execute() { 91 | return sd_ant_auto_freq_hop_table_set(_channel, _freq1, _freq2, _freq3); 92 | } 93 | 94 | #endif // NATIVE_API_AVAILABLE 95 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_FrequencyAgility.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_FREQUENCYAGILITY_h 2 | #define ANT_FREQUENCYAGILITY_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a configure event filter packet 8 | * 9 | */ 10 | class FrequencyAgility : public AntRequest { 11 | public: 12 | FrequencyAgility(); 13 | explicit FrequencyAgility(uint8_t channel); 14 | explicit FrequencyAgility(uint8_t channel, uint8_t freq1, uint8_t freq2, uint8_t freq3); 15 | void setChannel(uint8_t channel); 16 | void setFrequency(uint8_t index, uint8_t freq); 17 | void setFrequency1(uint8_t freq); 18 | void setFrequency2(uint8_t freq); 19 | void setFrequency3(uint8_t freq); 20 | uint8_t getChannel(); 21 | uint8_t getFrequency(uint8_t index); 22 | uint8_t getFrequency1(); 23 | uint8_t getFrequency2(); 24 | uint8_t getFrequency3(); 25 | uint8_t getData(uint8_t pos) override; 26 | uint8_t getDataLength() override; 27 | #ifdef NATIVE_API_AVAILABLE 28 | uint32_t execute() override; 29 | #endif // NATIVE_API_AVAILABLE 30 | private: 31 | uint8_t _channel = 0; 32 | uint8_t _freq1 = 0; 33 | uint8_t _freq2 = 0; 34 | uint8_t _freq3 = 0; 35 | }; 36 | 37 | #endif // ANT_FREQUENCYAGILITY_h 38 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_LibConfig.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | LibConfig::LibConfig() : AntRequest(LIB_CONFIG) {} 6 | 7 | LibConfig::LibConfig(uint8_t config) : AntRequest(LIB_CONFIG) { 8 | setConfig(config); 9 | } 10 | 11 | void LibConfig::setConfig(uint8_t config) { 12 | _config = config; 13 | } 14 | 15 | // cppcheck-suppress unusedFunction 16 | uint8_t LibConfig::getConfig() { 17 | return _config; 18 | } 19 | 20 | uint8_t LibConfig::getData(uint8_t pos) { 21 | if (pos == 0) { 22 | return 0; 23 | } else { 24 | return _config; 25 | } 26 | } 27 | 28 | uint8_t LibConfig::getDataLength() { 29 | return LIB_CONFIG_LENGTH; 30 | } 31 | 32 | #ifdef NATIVE_API_AVAILABLE 33 | 34 | uint32_t LibConfig::execute() { 35 | sd_ant_lib_config_clear(ANT_LIB_CONFIG_MASK_ALL); 36 | return sd_ant_lib_config_set(_config | ANT_LIB_CONFIG_RADIO_CONFIG_ALWAYS); 37 | } 38 | 39 | #endif // NATIVE_API_AVAILABLE 40 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_LibConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_LIBCONFIG_h 2 | #define ANT_LIBCONFIG_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a Lib Config message, it is used to 8 | * configure extended responses from the radio 9 | */ 10 | class LibConfig : public AntRequest { 11 | public: 12 | LibConfig(); 13 | explicit LibConfig(uint8_t config); 14 | void setConfig(uint8_t config); 15 | uint8_t getConfig(); 16 | uint8_t getData(uint8_t pos) override; 17 | uint8_t getDataLength() override; 18 | #ifdef NATIVE_API_AVAILABLE 19 | uint32_t execute() override; 20 | #endif // NATIVE_API_AVAILABLE 21 | private: 22 | uint8_t _config = 0; 23 | }; 24 | 25 | #endif // ANT_LIBCONFIG_h 26 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_LowPrioritySearchTimeout.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | LowPrioritySearchTimeout::LowPrioritySearchTimeout() : AntRequest(LOW_PRIORITY_SEARCH_TIMEOUT) {} 6 | 7 | LowPrioritySearchTimeout::LowPrioritySearchTimeout(uint8_t channel) : AntRequest(LOW_PRIORITY_SEARCH_TIMEOUT){ 8 | setChannel(channel); 9 | } 10 | 11 | LowPrioritySearchTimeout::LowPrioritySearchTimeout(uint8_t channel, uint8_t timeout) : AntRequest(LOW_PRIORITY_SEARCH_TIMEOUT){ 12 | setChannel(channel); 13 | setTimeout(timeout); 14 | } 15 | 16 | void LowPrioritySearchTimeout::setChannel(uint8_t channel) { 17 | _channel = channel; 18 | } 19 | 20 | void LowPrioritySearchTimeout::setTimeout(uint8_t timeout) { 21 | _timeout = timeout; 22 | } 23 | 24 | uint8_t LowPrioritySearchTimeout::getChannel() { 25 | return _channel; 26 | } 27 | 28 | // cppcheck-suppress unusedFunction 29 | uint8_t LowPrioritySearchTimeout::getTimeout() { 30 | return _timeout; 31 | } 32 | 33 | uint8_t LowPrioritySearchTimeout::getData(uint8_t pos) { 34 | if (pos == 0) { 35 | return _channel; 36 | } else { 37 | return _timeout; 38 | } 39 | } 40 | 41 | uint8_t LowPrioritySearchTimeout::getDataLength() { 42 | return LOW_PRIORITY_SEARCH_TIMEOUT_LENGTH; 43 | } 44 | 45 | #ifdef NATIVE_API_AVAILABLE 46 | 47 | uint32_t LowPrioritySearchTimeout::execute() { 48 | return sd_ant_channel_low_priority_rx_search_timeout_set(_channel, _timeout); 49 | } 50 | 51 | #endif // NATIVE_API_AVAILABLE 52 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_LowPrioritySearchTimeout.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_LOWPRIORITYSEARCHTIMEOUT_h 2 | #define ANT_LOWPRIORITYSEARCHTIMEOUT_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a Lib Config message, it is used to 8 | * configure extended responses from the radio 9 | */ 10 | class LowPrioritySearchTimeout : public AntRequest { 11 | public: 12 | LowPrioritySearchTimeout(); 13 | explicit LowPrioritySearchTimeout(uint8_t channel); 14 | explicit LowPrioritySearchTimeout(uint8_t channel, uint8_t timeout); 15 | void setChannel(uint8_t channel); 16 | void setTimeout(uint8_t timeout); 17 | uint8_t getChannel(); 18 | uint8_t getTimeout(); 19 | uint8_t getData(uint8_t pos) override; 20 | uint8_t getDataLength() override; 21 | #ifdef NATIVE_API_AVAILABLE 22 | uint32_t execute() override; 23 | #endif // NATIVE_API_AVAILABLE 24 | private: 25 | uint8_t _channel = 0; 26 | uint8_t _timeout = 0; 27 | }; 28 | 29 | #endif // ANT_LOWPRIORITYSEARCHTIMEOUT_h 30 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ProximitySearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | ProximitySearch::ProximitySearch() : AntRequest(PROXIMITY_SEARCH) {} 6 | 7 | ProximitySearch::ProximitySearch(uint8_t channel) : AntRequest(PROXIMITY_SEARCH) { 8 | setChannel(channel); 9 | } 10 | 11 | ProximitySearch::ProximitySearch(uint8_t channel, uint8_t searchThreshold) : AntRequest(PROXIMITY_SEARCH) { 12 | setChannel(channel); 13 | setSearchThreshold(searchThreshold); 14 | } 15 | 16 | void ProximitySearch::setChannel(uint8_t channel) { 17 | _channel = channel; 18 | } 19 | 20 | void ProximitySearch::setSearchThreshold(uint8_t searchThreshold) { 21 | _searchThreshold = searchThreshold; 22 | } 23 | 24 | uint8_t ProximitySearch::getChannel() { 25 | return _channel; 26 | } 27 | 28 | // cppcheck-suppress unusedFunction 29 | uint8_t ProximitySearch::getSearchThreshold() { 30 | return _searchThreshold; 31 | } 32 | 33 | uint8_t ProximitySearch::getData(uint8_t pos) { 34 | if (pos == 0) { 35 | return _channel; 36 | } else { 37 | return _searchThreshold; 38 | } 39 | } 40 | 41 | uint8_t ProximitySearch::getDataLength() { 42 | return PROXIMITY_SEARCH_LENGTH; 43 | } 44 | 45 | #ifdef NATIVE_API_AVAILABLE 46 | 47 | uint32_t ProximitySearch::execute() { 48 | return sd_ant_prox_search_set(_channel, _searchThreshold, 0); 49 | } 50 | 51 | #endif // NATIVE_API_AVAILABLE 52 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_ProximitySearch.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_PROXIMITYSEARCH_h 2 | #define ANT_PROXIMITYSEARCH_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a set proximity search packet 8 | * 9 | */ 10 | class ProximitySearch : public AntRequest { 11 | public: 12 | ProximitySearch(); 13 | explicit ProximitySearch(uint8_t channel); 14 | explicit ProximitySearch(uint8_t channel, uint8_t searchThreshold); 15 | void setChannel(uint8_t channel); 16 | void setSearchThreshold(uint8_t searchThreshold); 17 | uint8_t getChannel(); 18 | uint8_t getSearchThreshold(); 19 | uint8_t getData(uint8_t pos) override; 20 | uint8_t getDataLength() override; 21 | #ifdef NATIVE_API_AVAILABLE 22 | uint32_t execute() override; 23 | #endif // NATIVE_API_AVAILABLE 24 | private: 25 | uint8_t _channel = 0; 26 | uint8_t _searchThreshold = 0; 27 | }; 28 | 29 | #endif // ANT_PROXIMITYSEARCH_h 30 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SearchTimeout.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | SearchTimeout::SearchTimeout() : AntRequest(SEARCH_TIMEOUT) { 6 | 7 | } 8 | 9 | SearchTimeout::SearchTimeout(uint8_t channel, uint8_t timeout) : AntRequest(SEARCH_TIMEOUT) { 10 | setChannel(channel); 11 | setTimeout(timeout); 12 | } 13 | 14 | void SearchTimeout::setChannel(uint8_t channel) { 15 | _channel = channel; 16 | } 17 | 18 | void SearchTimeout::setTimeout(uint8_t timeout) { 19 | _timeout = timeout; 20 | } 21 | 22 | uint8_t SearchTimeout::getChannel() { 23 | return _channel; 24 | } 25 | 26 | uint8_t SearchTimeout::getTimeout() { 27 | return _timeout; 28 | } 29 | 30 | uint8_t SearchTimeout::getData(uint8_t pos) { 31 | if (pos == 0) { 32 | return _channel; 33 | } else { 34 | return _timeout; 35 | } 36 | } 37 | 38 | uint8_t SearchTimeout::getDataLength() { 39 | return SEARCH_TIMEOUT_LENGTH; 40 | } 41 | 42 | #ifdef NATIVE_API_AVAILABLE 43 | 44 | uint32_t SearchTimeout::execute() { 45 | return sd_ant_channel_search_timeout_set(_channel, _timeout); 46 | } 47 | 48 | #endif // NATIVE_API_AVAILABLE 49 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SearchTimeout.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_SEARCHTIMEOUT_h 2 | #define ANT_SEARCHTIMEOUT_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a search timeout message, it is used 8 | * to configure a channel timeout on the ANT radio 9 | */ 10 | class SearchTimeout : public AntRequest { 11 | public: 12 | SearchTimeout(); 13 | SearchTimeout(uint8_t channel, uint8_t timeout); 14 | void setChannel(uint8_t channel); 15 | void setTimeout(uint8_t timeout); 16 | uint8_t getChannel(); 17 | uint8_t getTimeout(); 18 | uint8_t getData(uint8_t pos) override; 19 | uint8_t getDataLength() override; 20 | #ifdef NATIVE_API_AVAILABLE 21 | uint32_t execute() override; 22 | #endif // NATIVE_API_AVAILABLE 23 | private: 24 | uint8_t _channel = 0; 25 | uint8_t _timeout = 0; 26 | }; 27 | 28 | #endif // ANT_SEARCHTIMEOUT_h 29 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SearchWaveform.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | SearchWaveform::SearchWaveform() : AntRequest(SEARCH_WAVEFORM) { 6 | 7 | } 8 | 9 | SearchWaveform::SearchWaveform(uint8_t channel, uint16_t waveform) : AntRequest(SEARCH_WAVEFORM) { 10 | setChannel(channel); 11 | setWaveform(waveform); 12 | } 13 | 14 | void SearchWaveform::setChannel(uint8_t channel) { 15 | _channel = channel; 16 | } 17 | 18 | void SearchWaveform::setWaveform(uint16_t waveform) { 19 | _waveform = waveform; 20 | } 21 | 22 | uint8_t SearchWaveform::getChannel() { 23 | return _channel; 24 | } 25 | 26 | // cppcheck-suppress unusedFunction 27 | uint16_t SearchWaveform::getWaveform() { 28 | return _waveform; 29 | } 30 | 31 | uint8_t SearchWaveform::getData(uint8_t pos) { 32 | if (pos == 0) { 33 | return _channel; 34 | } else if (pos == 1) { 35 | return _waveform & 0xFF; 36 | } else { 37 | return _waveform >> 8; 38 | } 39 | } 40 | 41 | uint8_t SearchWaveform::getDataLength() { 42 | return SEARCH_WAVEFORM_LENGTH; 43 | } 44 | 45 | #ifdef NATIVE_API_AVAILABLE 46 | 47 | uint32_t SearchWaveform::execute() { 48 | return sd_ant_search_waveform_set(_channel, _waveform); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SearchWaveform.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_SEARCHWAVEFORM_h 2 | #define ANT_SEARCHWAVEFORM_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a search waveform message, it is used to configure 8 | * the ...? 9 | */ 10 | class SearchWaveform : public AntRequest { 11 | public: 12 | SearchWaveform(); 13 | SearchWaveform(uint8_t channel, uint16_t waveform); 14 | void setChannel(uint8_t channel); 15 | void setWaveform(uint16_t waveform); 16 | uint8_t getChannel(); 17 | uint16_t getWaveform(); 18 | uint8_t getData(uint8_t pos) override; 19 | uint8_t getDataLength() override; 20 | #ifdef NATIVE_API_AVAILABLE 21 | uint32_t execute() override; 22 | #endif // NATIVE_API_AVAILABLE 23 | private: 24 | uint8_t _channel = 0; 25 | uint16_t _waveform = 0; 26 | }; 27 | 28 | #endif // ANT_SEARCHWAVEFORM_h 29 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SerialNumberSetChannelId.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | SerialNumberSetChannelId::SerialNumberSetChannelId() : AntRequest(SERIAL_NUMBER_SET_CHANNEL_ID) {} 6 | 7 | SerialNumberSetChannelId::SerialNumberSetChannelId(uint8_t channel) : AntRequest(SERIAL_NUMBER_SET_CHANNEL_ID) { 8 | setChannel(channel); 9 | } 10 | 11 | void SerialNumberSetChannelId::setChannel(uint8_t channel) { 12 | _channel = channel; 13 | } 14 | 15 | void SerialNumberSetChannelId::setDeviceType(uint8_t deviceType) { 16 | _deviceType = deviceType; 17 | } 18 | 19 | void SerialNumberSetChannelId::setPairingBit(bool paringBit) { 20 | _pairingBit = paringBit; 21 | } 22 | 23 | void SerialNumberSetChannelId::setTransmissionType(uint8_t transmissionType) { 24 | _transmissionType = transmissionType; 25 | } 26 | 27 | uint8_t SerialNumberSetChannelId::getChannel() { 28 | return _channel; 29 | } 30 | 31 | uint8_t SerialNumberSetChannelId::getDeviceType() { 32 | return _deviceType; 33 | } 34 | 35 | bool SerialNumberSetChannelId::getPairingBit() { 36 | return _pairingBit; 37 | } 38 | 39 | uint8_t SerialNumberSetChannelId::getTransmissionType() { 40 | return _transmissionType; 41 | } 42 | 43 | uint8_t SerialNumberSetChannelId::getData(uint8_t pos) { 44 | if (pos == 0) { 45 | return _channel; 46 | } else if (pos == 1) { 47 | return _deviceType; 48 | } else { 49 | return _transmissionType; 50 | } 51 | } 52 | 53 | uint8_t SerialNumberSetChannelId::getDataLength() { 54 | return SERIAL_NUMBER_SET_CHANNEL_ID_LENGTH; 55 | } 56 | 57 | #ifdef NATIVE_API_AVAILABLE 58 | 59 | uint32_t SerialNumberSetChannelId::execute() { 60 | // TODO 61 | return 0; 62 | } 63 | 64 | #endif // NATIVE_API_AVAILABLE 65 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SerialNumberSetChannelId.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_SERIALNUMBERSETCHANNELID_h 2 | #define ANT_SERIALNUMBERSETCHANNELID_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a serial number set channel id message 8 | * 9 | * used to configure a radio to use a devices serial number 10 | */ 11 | class SerialNumberSetChannelId : public AntRequest { 12 | public: 13 | SerialNumberSetChannelId(); 14 | explicit SerialNumberSetChannelId(uint8_t channel); 15 | void setChannel(uint8_t channel); 16 | void setDeviceType(uint8_t deviceType); 17 | void setPairingBit(bool paringBit); 18 | void setTransmissionType(uint8_t transmissionType); 19 | uint8_t getChannel(); 20 | uint8_t getDeviceType(); 21 | bool getPairingBit(); 22 | uint8_t getTransmissionType(); 23 | uint8_t getData(uint8_t pos) override; 24 | uint8_t getDataLength() override; 25 | #ifdef NATIVE_API_AVAILABLE 26 | uint32_t execute() override; 27 | #endif // NATIVE_API_AVAILABLE 28 | private: 29 | uint8_t _channel = 0; 30 | uint8_t _deviceType = 0; 31 | // TODO figure out default for pairing bit, assuming false 32 | bool _pairingBit = false; 33 | uint8_t _transmissionType = 0; 34 | }; 35 | 36 | #endif // ANT_SERIALNUMBERSETCHANNELID_h 37 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetChannelTransmitPower.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | SetChannelTransmitPower::SetChannelTransmitPower() : AntRequest(SET_CHANNEL_TRANSMIT_POWER) { 6 | 7 | } 8 | 9 | SetChannelTransmitPower::SetChannelTransmitPower(uint8_t channel) : AntRequest(SET_CHANNEL_TRANSMIT_POWER) { 10 | setChannel(channel); 11 | } 12 | 13 | SetChannelTransmitPower::SetChannelTransmitPower(uint8_t channel, uint8_t transmitPower) : AntRequest(SET_CHANNEL_TRANSMIT_POWER) { 14 | setChannel(channel); 15 | setTransmitPower(transmitPower); 16 | } 17 | 18 | void SetChannelTransmitPower::setChannel(uint8_t channel) { 19 | _channel = channel; 20 | } 21 | 22 | void SetChannelTransmitPower::setTransmitPower(uint8_t transmitPower) { 23 | _transmitPower = transmitPower; 24 | } 25 | 26 | uint8_t SetChannelTransmitPower::getChannel() { 27 | return _channel; 28 | } 29 | 30 | // cppcheck-suppress unusedFunction 31 | uint16_t SetChannelTransmitPower::getTransmitPower() { 32 | return _transmitPower; 33 | } 34 | 35 | uint8_t SetChannelTransmitPower::getData(uint8_t pos) { 36 | if (pos == 0) { 37 | return _channel; 38 | } else { 39 | return _transmitPower; 40 | } 41 | } 42 | 43 | uint8_t SetChannelTransmitPower::getDataLength() { 44 | return SET_CHANNEL_TRANSMIT_POWER_LENGTH; 45 | } 46 | 47 | 48 | #ifdef NATIVE_API_AVAILABLE 49 | 50 | uint32_t SetChannelTransmitPower::execute() { 51 | return sd_ant_channel_radio_tx_power_set(_channel, _transmitPower, 0); 52 | } 53 | 54 | #endif // NATIVE_API_AVAILABLE 55 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetChannelTransmitPower.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_SETCHANNELTRANSMITPOWER_h 2 | #define ANT_SETCHANNELTRANSMITPOWER_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a set channel transmit power message 8 | * 9 | * configures the Tx power of the specified channel 10 | */ 11 | class SetChannelTransmitPower : public AntRequest { 12 | public: 13 | SetChannelTransmitPower(); 14 | explicit SetChannelTransmitPower(uint8_t channel); 15 | explicit SetChannelTransmitPower(uint8_t channel, uint8_t transmitPower); 16 | void setChannel(uint8_t channel); 17 | void setTransmitPower(uint8_t transmitPower); 18 | uint8_t getChannel(); 19 | uint16_t getTransmitPower(); 20 | uint8_t getData(uint8_t pos) override; 21 | uint8_t getDataLength() override; 22 | #ifdef NATIVE_API_AVAILABLE 23 | uint32_t execute() override; 24 | #endif // NATIVE_API_AVAILABLE 25 | private: 26 | uint8_t _channel = 0; 27 | uint16_t _transmitPower = 0; 28 | }; 29 | 30 | #endif // ANT_SETCHANNELTRANSMITPOWER_h 31 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetEncryptionInfo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | 7 | SetEncryptionInfo::SetEncryptionInfo() : AntRequest(SET_ENCRYPTION_INFO) { 8 | } 9 | 10 | SetEncryptionInfo::SetEncryptionInfo(uint8_t param, uint8_t* data) : AntRequest(SET_ENCRYPTION_INFO), _setParameter(param) { 11 | memcpy(_dataString, data, getDataStringSize()); 12 | } 13 | 14 | void SetEncryptionInfo::setParameter(uint8_t param) { 15 | _setParameter = param; 16 | } 17 | 18 | void SetEncryptionInfo::setDataString(uint8_t* data) { 19 | memcpy(_dataString, data, getDataStringSize()); 20 | } 21 | 22 | void SetEncryptionInfo::setDataStringByte(uint8_t byte, uint8_t pos) { 23 | _dataString[pos] = byte; 24 | } 25 | 26 | // cppcheck-suppress unusedFunction 27 | uint8_t SetEncryptionInfo::getParameter() { 28 | return _setParameter; 29 | } 30 | 31 | void SetEncryptionInfo::getDataString(uint8_t* arr) { 32 | memcpy(arr, _dataString, getDataStringSize()); 33 | } 34 | 35 | uint8_t SetEncryptionInfo::getDataStringByte(uint8_t pos) { 36 | return _dataString[pos]; 37 | } 38 | 39 | uint8_t SetEncryptionInfo::getData(uint8_t pos) { 40 | if (pos == 0) { 41 | return _setParameter; 42 | } else { 43 | return _dataString[pos - 1]; 44 | } 45 | } 46 | 47 | uint8_t SetEncryptionInfo::getDataLength() { 48 | return SET_ENCRYPTION_INFO_LENGTH + getDataStringSize(); 49 | } 50 | 51 | #ifdef NATIVE_API_AVAILABLE 52 | 53 | uint32_t SetEncryptionInfo::execute() { 54 | return sd_ant_crypto_info_set(_setParameter, _dataString); 55 | } 56 | 57 | #endif // NATIVE_API_AVAILABLE 58 | 59 | uint8_t SetEncryptionInfo::getDataStringSize() { 60 | switch (_setParameter) { 61 | case SET_ENCRYPTION_INFO_SET_PARAMETER_ENCRYPTION_ID: 62 | return SET_ENCRYPTION_INFO_DATA_STRING_ENCRYPTION_ID_SIZE; 63 | case SET_ENCRYPTION_INFO_SET_PARAMETER_USER_INFORMATION_STRING: 64 | return SET_ENCRYPTION_INFO_DATA_STRING_USER_INFORMATION_STRING_SIZE; 65 | case SET_ENCRYPTION_INFO_SET_PARAMETER_RANDOM_NUMBER_SEED: 66 | return SET_ENCRYPTION_INFO_DATA_STRING_RANDOM_NUMBER_SEED_SIZE; 67 | default: 68 | return 0; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetEncryptionInfo.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_SETENCRYPTIONINFO_h 2 | #define ANT_SETENCRYPTIONINFO_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a set encryption info message 8 | * 9 | * it is used to configure the ...? 10 | */ 11 | class SetEncryptionInfo : public AntRequest { 12 | public: 13 | SetEncryptionInfo(); 14 | SetEncryptionInfo(uint8_t param, uint8_t* data); 15 | void setParameter(uint8_t param); 16 | void setDataString(uint8_t* data); 17 | void setDataStringByte(uint8_t byte, uint8_t pos); 18 | uint8_t getParameter(); 19 | void getDataString(uint8_t* arr); 20 | uint8_t getDataStringByte(uint8_t pos); 21 | uint8_t getData(uint8_t pos) override; 22 | uint8_t getDataLength() override; 23 | #ifdef NATIVE_API_AVAILABLE 24 | uint32_t execute() override; 25 | #endif // NATIVE_API_AVAILABLE 26 | private: 27 | uint8_t getDataStringSize(); 28 | uint8_t _setParameter = 0; 29 | uint8_t _dataString[SET_ENCRYPTION_INFO_DATA_STRING_USER_INFORMATION_STRING_SIZE] = {0}; 30 | // USER_INFORMATION_STRING is the largest among the possible configurations, can be used for other modes 31 | }; 32 | 33 | #endif // ANT_SETENCRYPTIONINFO_h 34 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetEncryptionKey.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | SetEncryptionKey::SetEncryptionKey() : AntRequest(SET_ENCRYPTION_KEY) { 7 | } 8 | 9 | SetEncryptionKey::SetEncryptionKey(uint8_t index, uint8_t* key) : AntRequest(SET_ENCRYPTION_KEY), _volatileKeyIndex(index) { 10 | memcpy(_encryptionKey, key, ENCRYPTION_KEY_SIZE); 11 | } 12 | 13 | void SetEncryptionKey::setVolatileKeyIndex(uint8_t index) { 14 | _volatileKeyIndex = index; 15 | } 16 | 17 | void SetEncryptionKey::setEncryptionKey(uint8_t* key) { 18 | memcpy(_encryptionKey, key, ENCRYPTION_KEY_SIZE); 19 | } 20 | 21 | void SetEncryptionKey::setEncryptionKeyByte(uint8_t byte, uint8_t pos) { 22 | if (pos < ENCRYPTION_KEY_SIZE) { 23 | _encryptionKey[pos] = byte; 24 | } 25 | } 26 | 27 | uint8_t SetEncryptionKey::getVolatileKeyIndex() { 28 | return _volatileKeyIndex; 29 | } 30 | 31 | uint8_t SetEncryptionKey::getEncryptionKeyByte(uint8_t pos) { 32 | return _encryptionKey[pos]; 33 | } 34 | 35 | void SetEncryptionKey::getEncryptionKey(uint8_t* arr) { 36 | memcpy(arr, _encryptionKey, ENCRYPTION_KEY_SIZE); 37 | } 38 | 39 | uint8_t SetEncryptionKey::getData(uint8_t pos) { 40 | if (pos == 0) { 41 | return _volatileKeyIndex; 42 | } else { 43 | return _encryptionKey[pos - 1]; 44 | } 45 | } 46 | 47 | uint8_t SetEncryptionKey::getDataLength() { 48 | return SET_ENCRYPTION_KEY_LENGTH; 49 | } 50 | 51 | #ifdef NATIVE_API_AVAILABLE 52 | 53 | uint32_t SetEncryptionKey::execute() { 54 | return sd_ant_crypto_key_set(_volatileKeyIndex, _encryptionKey); 55 | } 56 | 57 | #endif // NATIVE_API_AVAILABLE 58 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetEncryptionKey.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_SETENCRYPTIONKEY_h 2 | #define ANT_SETENCRYPTIONKEY_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a set encryption key packet 8 | * 9 | */ 10 | class SetEncryptionKey : public AntRequest { 11 | public: 12 | SetEncryptionKey(); 13 | SetEncryptionKey(uint8_t index, uint8_t* key); 14 | void setVolatileKeyIndex(uint8_t index); 15 | void setEncryptionKey(uint8_t* key); 16 | void setEncryptionKeyByte(uint8_t byte, uint8_t pos); 17 | uint8_t getVolatileKeyIndex(); 18 | uint8_t getEncryptionKeyByte(uint8_t pos); 19 | void getEncryptionKey(uint8_t* arr); 20 | uint8_t getData(uint8_t pos) override; 21 | uint8_t getDataLength() override; 22 | #ifdef NATIVE_API_AVAILABLE 23 | uint32_t execute() override; 24 | #endif // NATIVE_API_AVAILABLE 25 | private: 26 | uint8_t _volatileKeyIndex = 0; 27 | uint8_t _encryptionKey[ENCRYPTION_KEY_SIZE] = {0}; 28 | }; 29 | 30 | #endif // ANT_SETENCRYPTIONKEY_h 31 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetNetworkKey.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | 7 | SetNetworkKey::SetNetworkKey() : AntRequest(SET_NETWORK_KEY) { 8 | memset(_key, 0, NETWORK_KEY_SIZE); 9 | } 10 | 11 | SetNetworkKey::SetNetworkKey(uint8_t network, uint8_t* key) : AntRequest(SET_NETWORK_KEY) { 12 | setNetwork(network); 13 | setKey(key); 14 | } 15 | 16 | void SetNetworkKey::setNetwork(uint8_t network) { 17 | _network = network; 18 | } 19 | 20 | void SetNetworkKey::setKey(uint8_t* key) { 21 | memcpy(_key, key, NETWORK_KEY_SIZE); 22 | } 23 | 24 | void SetNetworkKey::setKeyByte(uint8_t byte, uint8_t pos) { 25 | _key[pos] = byte; 26 | } 27 | 28 | // cppcheck-suppress unusedFunction 29 | uint8_t SetNetworkKey::getNetwork() { 30 | return _network; 31 | } 32 | 33 | void SetNetworkKey::getKey(uint8_t* arr) { 34 | memcpy(arr, _key, NETWORK_KEY_SIZE); 35 | } 36 | 37 | uint8_t SetNetworkKey::getKeyByte(uint8_t pos) { 38 | return _key[pos]; 39 | } 40 | 41 | uint8_t SetNetworkKey::getDataLength() { 42 | return SET_NETWORK_KEY_LENGTH; 43 | } 44 | 45 | uint8_t SetNetworkKey::getData(uint8_t pos) { 46 | if (pos == 0) { 47 | return _network; 48 | } else { 49 | return _key[pos - 1]; 50 | } 51 | } 52 | 53 | #ifdef NATIVE_API_AVAILABLE 54 | 55 | uint32_t SetNetworkKey::execute() { 56 | return sd_ant_network_address_set(_network, _key); 57 | } 58 | 59 | #endif // NATIVE_API_AVAILABLE 60 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetNetworkKey.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_SETNETWORKKEY_h 2 | #define ANT_SETNETWORKKEY_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a set network key message, it is used to configure 10 | * a network key on the ANT radio 11 | */ 12 | class SetNetworkKey : public AntRequest { 13 | public: 14 | SetNetworkKey(); 15 | SetNetworkKey(uint8_t network, uint8_t* key); 16 | void setNetwork(uint8_t network); 17 | void setKey(uint8_t* key); 18 | void setKeyByte(uint8_t byte, uint8_t pos); 19 | uint8_t getNetwork(); 20 | void getKey(uint8_t* arr); 21 | uint8_t getKeyByte(uint8_t pos); 22 | uint8_t getData(uint8_t pos) override; 23 | uint8_t getDataLength() override; 24 | #ifdef NATIVE_API_AVAILABLE 25 | uint32_t execute() override; 26 | #endif 27 | private: 28 | uint8_t _network = 0; 29 | uint8_t _key[NETWORK_KEY_SIZE] = {0}; 30 | }; 31 | 32 | #endif // ANT_SETNETWORKKEY_h 33 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetSelectiveDataUpdateMask.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | // TODO -------------------------------------------------------------------------------- /src/TX/Config/ANT_SetSelectiveDataUpdateMask.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_SETSELECTIVEDATAUPDATEMASK_h 2 | #define ANT_SETSELECTIVEDATAUPDATEMASK_h 3 | 4 | // TODO 5 | 6 | #endif // ANT_SETSELECTIVEDATAUPDATEMASK_h -------------------------------------------------------------------------------- /src/TX/Config/ANT_TransmitPower.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | TransmitPower::TransmitPower() : AntRequest(TRANSMIT_POWER) {} 7 | 8 | TransmitPower::TransmitPower(uint8_t power) : AntRequest(TRANSMIT_POWER) { 9 | setTxPower(power); 10 | } 11 | 12 | void TransmitPower::setTxPower(uint8_t power) { 13 | _power = power; 14 | } 15 | 16 | // cppcheck-suppress unusedFunction 17 | uint8_t TransmitPower::getTxPower() { 18 | return _power; 19 | } 20 | 21 | uint8_t TransmitPower::getData(uint8_t pos) { 22 | if (pos == 0) { 23 | return 0; 24 | } else { 25 | return _power; 26 | } 27 | } 28 | 29 | uint8_t TransmitPower::getDataLength() { 30 | return TRANSMIT_POWER_LENGTH; 31 | } 32 | 33 | #ifdef NATIVE_API_AVAILABLE 34 | 35 | uint32_t TransmitPower::execute() { 36 | // TODO ant_processor sets all channels to the same value 37 | // return sd_ant_channel_radio_tx_power_set(); 38 | return 0; 39 | } 40 | 41 | #endif // NATIVE_API_AVAILABLE 42 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_TransmitPower.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_TRANSMITPOWER_h 2 | #define ANT_TRANSMITPOWER_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a transmit power message, it is used to configure 8 | * the radios transmission characteristics 9 | */ 10 | class TransmitPower : public AntRequest { 11 | public: 12 | TransmitPower(); 13 | explicit TransmitPower(uint8_t power); 14 | void setTxPower(uint8_t power); 15 | uint8_t getTxPower(); 16 | uint8_t getData(uint8_t pos) override; 17 | uint8_t getDataLength() override; 18 | #ifdef NATIVE_API_AVAILABLE 19 | uint32_t execute() override; 20 | #endif // NATIVE_API_AVAILABLE 21 | private: 22 | uint8_t _power = 0; 23 | }; 24 | 25 | #endif // ANT_TRANSMITPOWER_h 26 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_UnAssignChannel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | UnAssignChannel::UnAssignChannel() : AntRequest(UNASSIGN_CHANNEL) {} 7 | 8 | UnAssignChannel::UnAssignChannel(uint8_t channel) : AntRequest(UNASSIGN_CHANNEL) { 9 | setChannel(channel); 10 | } 11 | 12 | void UnAssignChannel::setChannel(uint8_t channel) { 13 | _channel = channel; 14 | } 15 | 16 | uint8_t UnAssignChannel::getChannel() { 17 | return _channel; 18 | } 19 | 20 | uint8_t UnAssignChannel::getDataLength() { 21 | return UNASSIGN_CHANNEL_LENGTH; 22 | } 23 | 24 | uint8_t UnAssignChannel::getData(uint8_t pos) { 25 | return _channel; 26 | } 27 | 28 | #ifdef NATIVE_API_AVAILABLE 29 | 30 | uint32_t UnAssignChannel::execute() { 31 | return sd_ant_channel_unassign(_channel); 32 | } 33 | 34 | #endif // NATIVE_API_AVAILABLE 35 | -------------------------------------------------------------------------------- /src/TX/Config/ANT_UnAssignChannel.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_UNASSIGNCHANNEL_h 2 | #define ANT_UNASSIGNCHANNEL_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a unassign channel packet, which is used to disociate a channel 10 | * 11 | */ 12 | class UnAssignChannel : public AntRequest { 13 | public: 14 | UnAssignChannel(); 15 | explicit UnAssignChannel(uint8_t channel); 16 | void setChannel(uint8_t channel); 17 | uint8_t getChannel(); 18 | uint8_t getData(uint8_t pos) override; 19 | uint8_t getDataLength() override; 20 | #ifdef NATIVE_API_AVAILABLE 21 | uint32_t execute() override; 22 | #endif 23 | private: 24 | uint8_t _channel = 0; 25 | }; 26 | 27 | #endif // ANT_UNASSIGNCHANNEL_h 28 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_CloseChannel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | CloseChannel::CloseChannel() : AntRequest(CLOSE_CHANNEL) { 7 | 8 | } 9 | 10 | CloseChannel::CloseChannel(uint8_t channel) : AntRequest(CLOSE_CHANNEL) { 11 | setChannel(channel); 12 | } 13 | 14 | void CloseChannel::setChannel(uint8_t channel) { 15 | _channel = channel; 16 | } 17 | 18 | uint8_t CloseChannel::getChannel() { 19 | return _channel; 20 | } 21 | 22 | uint8_t CloseChannel::getDataLength() { 23 | return CLOSE_CHANNEL_LENGTH; 24 | } 25 | 26 | uint8_t CloseChannel::getData(uint8_t pos) { 27 | return _channel; 28 | } 29 | 30 | #ifdef NATIVE_API_AVAILABLE 31 | 32 | uint32_t CloseChannel::execute() { 33 | return sd_ant_channel_close(_channel); 34 | } 35 | 36 | #endif // NATIVE_API_AVAILABLE 37 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_CloseChannel.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CLOSECHANNEL_h 2 | #define ANT_CLOSECHANNEL_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a close channel message, it is used to close a open channel the ANT radio 8 | */ 9 | class CloseChannel : public AntRequest { 10 | public: 11 | CloseChannel(); 12 | explicit CloseChannel(uint8_t channel); 13 | void setChannel(uint8_t channel); 14 | uint8_t getChannel(); 15 | uint8_t getData(uint8_t pos) override; 16 | uint8_t getDataLength() override; 17 | #ifdef NATIVE_API_AVAILABLE 18 | uint32_t execute() override; 19 | #endif 20 | private: 21 | uint8_t _channel = 0; 22 | }; 23 | 24 | #endif // ANT_CLOSECHANNEL_h 25 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_OpenChannel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | OpenChannel::OpenChannel() : AntRequest(OPEN_CHANNEL) {} 7 | 8 | OpenChannel::OpenChannel(uint8_t channel) : AntRequest(OPEN_CHANNEL) { 9 | setChannel(channel); 10 | } 11 | 12 | void OpenChannel::setChannel(uint8_t channel) { 13 | _channel = channel; 14 | } 15 | 16 | uint8_t OpenChannel::getChannel() { 17 | return _channel; 18 | } 19 | 20 | uint8_t OpenChannel::getDataLength() { 21 | return OPEN_CHANNEL_LENGTH; 22 | } 23 | 24 | uint8_t OpenChannel::getData(uint8_t pos) { 25 | return _channel; 26 | } 27 | 28 | #ifdef NATIVE_API_AVAILABLE 29 | 30 | uint32_t OpenChannel::execute() { 31 | return sd_ant_channel_open(_channel); 32 | } 33 | 34 | #endif // NATIVE_API_AVAILABLE 35 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_OpenChannel.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_OPENCHANNEL_h 2 | #define ANT_OPENCHANNEL_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a open channel message, it is used to open a configured channel the ANT radio 8 | */ 9 | class OpenChannel : public AntRequest { 10 | public: 11 | OpenChannel(); 12 | explicit OpenChannel(uint8_t channel); 13 | void setChannel(uint8_t channel); 14 | uint8_t getChannel(); 15 | uint8_t getData(uint8_t pos) override; 16 | uint8_t getDataLength() override; 17 | #ifdef NATIVE_API_AVAILABLE 18 | uint32_t execute() override; 19 | #endif 20 | private: 21 | uint8_t _channel = 0; 22 | }; 23 | 24 | #endif // ANT_OPENCHANNEL_h 25 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_OpenRxScanMode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | OpenRxScanMode::OpenRxScanMode() : AntRequest(OPEN_RX_SCAN_MODE) { 7 | 8 | } 9 | 10 | OpenRxScanMode::OpenRxScanMode(uint8_t synchronousOnly) : AntRequest(OPEN_RX_SCAN_MODE) { 11 | setSynchronousChannelPacketsOnly(synchronousOnly); 12 | } 13 | 14 | void OpenRxScanMode::setSynchronousChannelPacketsOnly(uint8_t synchronousOnly) { 15 | _extendLength = 1; 16 | _synchronousChannelPacketsOnly = synchronousOnly; 17 | } 18 | 19 | // cppcheck-suppress unusedFunction 20 | uint8_t OpenRxScanMode::getSynchronousChannelPacketsOnly() { 21 | return _synchronousChannelPacketsOnly; 22 | } 23 | 24 | uint8_t OpenRxScanMode::getData(uint8_t pos) { 25 | if (pos == 0) { 26 | return 0; 27 | } else { 28 | return _synchronousChannelPacketsOnly ? 1 : 0; 29 | } 30 | } 31 | 32 | uint8_t OpenRxScanMode::getDataLength() { 33 | return OPEN_RX_SCAN_MODE_LENGTH + _extendLength; 34 | } 35 | 36 | #ifdef NATIVE_API_AVAILABLE 37 | 38 | uint32_t OpenRxScanMode::execute() { 39 | return sd_ant_rx_scan_mode_start(_synchronousChannelPacketsOnly); 40 | } 41 | 42 | #endif // NATIVE_API_AVAILABLE 43 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_OpenRxScanMode.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_OPENRXSCANMODE_h 2 | #define ANT_OPENRXSCANMODE_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a Open Rx Scan Mode message, it is used to put the ANT radio into open rx scan mode 8 | */ 9 | class OpenRxScanMode : public AntRequest { 10 | public: 11 | OpenRxScanMode(); 12 | explicit OpenRxScanMode(uint8_t synchronousOnly); 13 | void setSynchronousChannelPacketsOnly(uint8_t synchronousOnly); 14 | uint8_t getSynchronousChannelPacketsOnly(); 15 | uint8_t getData(uint8_t pos) override; 16 | uint8_t getDataLength() override; 17 | #ifdef NATIVE_API_AVAILABLE 18 | uint32_t execute() override; 19 | #endif // NATIVE_API_AVAILABLE 20 | private: 21 | uint8_t _extendLength = 0; 22 | uint8_t _synchronousChannelPacketsOnly = 0; 23 | }; 24 | 25 | #endif // ANT_OPENRXSCANMODE_h 26 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_RequestMessage.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | /* Extended message format not currently supported */ 7 | RequestMessage::RequestMessage() : AntRequest(REQUEST_MESSAGE) {} 8 | 9 | RequestMessage::RequestMessage(uint8_t msgId) : AntRequest(REQUEST_MESSAGE) { 10 | setRequestedMessage(msgId); 11 | } 12 | 13 | RequestMessage::RequestMessage(uint8_t msgId, uint8_t subId) : AntRequest(REQUEST_MESSAGE) { 14 | setRequestedMessage(msgId); 15 | setSubId(subId); 16 | } 17 | 18 | void RequestMessage::setRequestedMessage(uint8_t msgId) { 19 | _msgId = msgId; 20 | } 21 | 22 | // cppcheck-suppress unusedFunction 23 | uint8_t RequestMessage::getRequestedMessage() { 24 | return _msgId; 25 | } 26 | 27 | void RequestMessage::setSubId(uint8_t subId) { 28 | _subId = subId; 29 | } 30 | 31 | // cppcheck-suppress unusedFunction 32 | uint8_t RequestMessage::getSubId() { 33 | return _subId; 34 | } 35 | 36 | uint8_t RequestMessage::getData(uint8_t pos) { 37 | if (pos == 0) { 38 | return _subId; 39 | } 40 | else if (pos == 1) { 41 | return _msgId; 42 | } 43 | else { 44 | return INVALID_REQUEST; 45 | } 46 | } 47 | 48 | uint8_t RequestMessage::getDataLength() { 49 | return REQUEST_MESSAGE_LENGTH; 50 | } 51 | 52 | #ifdef NATIVE_API_AVAILABLE 53 | 54 | uint32_t RequestMessage::execute() { 55 | return 0; 56 | } 57 | 58 | #endif // NATIVE_API_AVAILABLE 59 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_RequestMessage.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_REQUESTMESSAGE_h 2 | #define ANT_REQUESTMESSAGE_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a request message, it is used to request a message from the ANT radio 8 | */ 9 | class RequestMessage : public AntRequest { 10 | public: 11 | RequestMessage(); 12 | explicit RequestMessage(uint8_t msgId); 13 | explicit RequestMessage(uint8_t msgId, uint8_t subId); 14 | void setRequestedMessage(uint8_t msgId); 15 | void setSubId(uint8_t subId); 16 | uint8_t getRequestedMessage(); 17 | uint8_t getSubId(); 18 | uint8_t getData(uint8_t pos) override; 19 | uint8_t getDataLength() override; 20 | #ifdef NATIVE_API_AVAILABLE 21 | uint32_t execute() override; 22 | #endif 23 | private: 24 | uint8_t _msgId = 0; 25 | uint8_t _subId = 0; 26 | }; 27 | 28 | #endif // ANT_REQUESTMESSAGE_h 29 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_ResetSystem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | ResetSystem::ResetSystem() : AntRequest(RESET_SYSTEM) { 7 | 8 | } 9 | 10 | uint8_t ResetSystem::getDataLength() { 11 | return RESET_SYSTEM_LENGTH; 12 | } 13 | 14 | uint8_t ResetSystem::getData(uint8_t pos) { 15 | return 0; 16 | } 17 | 18 | #ifdef NATIVE_API_AVAILABLE 19 | 20 | uint32_t ResetSystem::execute() { 21 | return sd_ant_stack_reset(); 22 | } 23 | 24 | #endif // NATIVE_API_AVAILABLE 25 | -------------------------------------------------------------------------------- /src/TX/Control/ANT_ResetSystem.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_RESETSYSTEM_h 2 | #define ANT_RESETSYSTEM_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a reset system message, it is used to reset the ANT radio 8 | */ 9 | class ResetSystem : public AntRequest { 10 | public: 11 | ResetSystem(); 12 | uint8_t getData(uint8_t pos) override; 13 | uint8_t getDataLength() override; 14 | #ifdef NATIVE_API_AVAILABLE 15 | uint32_t execute() override; 16 | #endif 17 | }; 18 | 19 | #endif // ANT_RESETSYSTEM_h 20 | -------------------------------------------------------------------------------- /src/TX/Data/ANT_AcknowledgedDataMsg.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | /* Extended message format not currently supported */ 7 | AcknowledgedDataMsg::AcknowledgedDataMsg() : AntTxDataRequest(ACKNOWLEDGED_DATA) { 8 | setDataLength(MESSAGE_SIZE); 9 | } 10 | 11 | AcknowledgedDataMsg::AcknowledgedDataMsg(uint8_t channel) : AntTxDataRequest(ACKNOWLEDGED_DATA) { 12 | setDataLength(MESSAGE_SIZE); 13 | setChannel(channel); 14 | } 15 | 16 | void AcknowledgedDataMsg::setChannel(uint8_t channel) { 17 | _channel = channel; 18 | } 19 | 20 | uint8_t AcknowledgedDataMsg::getChannel() { 21 | return _channel; 22 | } 23 | 24 | uint8_t AcknowledgedDataMsg::getDataLength() { 25 | return ACKNOWLEDGED_DATA_LENGTH; 26 | } 27 | 28 | uint8_t AcknowledgedDataMsg::getData(uint8_t pos) { 29 | if (pos == 0) { 30 | return _channel; 31 | } 32 | else { 33 | return getDataBuffer()[pos - 1]; 34 | } 35 | } 36 | 37 | #ifdef NATIVE_API_AVAILABLE 38 | 39 | uint32_t AcknowledgedDataMsg::execute() { 40 | return sd_ant_acknowledge_message_tx(_channel, 8, getDataBuffer()); 41 | } 42 | 43 | #endif // NATIVE_API_AVAILABLE 44 | -------------------------------------------------------------------------------- /src/TX/Data/ANT_AcknowledgedDataMsg.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ACKNOWLEDGEDMSG_h 2 | #define ANT_ACKNOWLEDGEDMSG_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Acknowledged Tx message, it is used to send a message from the ANT radio 10 | */ 11 | class AcknowledgedDataMsg : public AntTxDataRequest { 12 | public: 13 | AcknowledgedDataMsg(); 14 | explicit AcknowledgedDataMsg(uint8_t channel); 15 | void setChannel(uint8_t channel); 16 | uint8_t getChannel(); 17 | uint8_t getData(uint8_t pos) override; 18 | uint8_t getDataLength() override; 19 | #ifdef NATIVE_API_AVAILABLE 20 | uint32_t execute() override; 21 | #endif 22 | private: 23 | uint8_t _channel = 0; 24 | }; 25 | 26 | #endif // ANT_ACKNOWLEDGEDMSG_h 27 | -------------------------------------------------------------------------------- /src/TX/Data/ANT_AdvancedBurstDataMsg.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | AdvancedBurstDataMsg::AdvancedBurstDataMsg() : AntTxDataRequest(ADVANCED_BURST_DATA) { 6 | 7 | } 8 | 9 | AdvancedBurstDataMsg::AdvancedBurstDataMsg(uint8_t channel, uint8_t length) : AntTxDataRequest(ADVANCED_BURST_DATA) { 10 | setChannelNumber(channel); 11 | setDataLength(length); 12 | } 13 | 14 | void AdvancedBurstDataMsg::setChannelNumber(uint8_t channel) { 15 | // TODO fix this to handle sequence 16 | _channel = channel; 17 | } 18 | 19 | uint8_t AdvancedBurstDataMsg::getChannelNumber() { 20 | return _channel; 21 | } 22 | 23 | uint8_t AdvancedBurstDataMsg::getData(uint8_t pos) { 24 | // TODO 25 | return 0; 26 | } 27 | 28 | void AdvancedBurstDataMsg::setDataLength(uint8_t length) { 29 | AntTxDataRequest::setDataLength(length); 30 | } 31 | 32 | uint8_t AdvancedBurstDataMsg::getDataLength() { 33 | // TODO 34 | return 0; 35 | } 36 | 37 | #ifdef NATIVE_API_AVAILABLE 38 | 39 | uint32_t AdvancedBurstDataMsg::execute() { 40 | // TODO 41 | return 0; 42 | } 43 | 44 | #endif // NATIVE_API_AVAILABLE 45 | -------------------------------------------------------------------------------- /src/TX/Data/ANT_AdvancedBurstDataMsg.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_ADVANCEDBURSTDATAMSG_h 2 | #define ANT_ADVANCEDBURSTDATAMSG_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a Advanced Burst Data Tx message, it is used to send a message from the ANT radio 8 | */ 9 | class AdvancedBurstDataMsg : public AntTxDataRequest { 10 | public: 11 | AdvancedBurstDataMsg(); 12 | AdvancedBurstDataMsg(uint8_t channel, uint8_t length); 13 | void setChannelNumber(uint8_t channel); 14 | void setSequenceNumber(uint8_t seqNo); 15 | uint8_t getChannelNumber(); 16 | uint8_t getSequenceNumber(); 17 | uint8_t getData(uint8_t pos) override; 18 | void setDataLength(uint8_t length); 19 | uint8_t getDataLength() override; 20 | #ifdef NATIVE_API_AVAILABLE 21 | uint32_t execute() override; 22 | #endif // NATIVE_API_AVAILABLE 23 | private: 24 | uint8_t _channel = 0; 25 | }; 26 | 27 | #endif // ANT_ADVANCEDBURSTDATAMSG_h 28 | -------------------------------------------------------------------------------- /src/TX/Data/ANT_BroadcastDataMsg.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | /* Extended message format not currently supported */ 7 | BroadcastDataMsg::BroadcastDataMsg() : AntTxDataRequest(BROADCAST_DATA) { 8 | setDataLength(MESSAGE_SIZE); 9 | } 10 | 11 | BroadcastDataMsg::BroadcastDataMsg(uint8_t channel) : AntTxDataRequest(BROADCAST_DATA) { 12 | setDataLength(MESSAGE_SIZE); 13 | setChannel(channel); 14 | } 15 | 16 | void BroadcastDataMsg::setChannel(uint8_t channel) { 17 | _channel = channel; 18 | } 19 | 20 | uint8_t BroadcastDataMsg::getChannel() { 21 | return _channel; 22 | } 23 | 24 | uint8_t BroadcastDataMsg::getDataLength() { 25 | return BROADCAST_DATA_LENGTH; 26 | } 27 | 28 | uint8_t BroadcastDataMsg::getData(uint8_t pos) { 29 | if (pos == 0) { 30 | return _channel; 31 | } 32 | else { 33 | return getDataBuffer()[pos - 1]; 34 | } 35 | } 36 | 37 | #ifdef NATIVE_API_AVAILABLE 38 | 39 | uint32_t BroadcastDataMsg::execute() { 40 | return sd_ant_broadcast_message_tx(_channel, 8, getDataBuffer()); 41 | } 42 | 43 | #endif // NATIVE_API_AVAILABLE 44 | -------------------------------------------------------------------------------- /src/TX/Data/ANT_BroadcastDataMsg.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_BROADCASTMSG_h 2 | #define ANT_BROADCASTMSG_h 3 | 4 | #include 5 | 6 | #include 7 | 8 | /** 9 | * Represents a Broadcast Tx message, it is used to send a message from the ANT radio 10 | */ 11 | class BroadcastDataMsg : public AntTxDataRequest { 12 | public: 13 | BroadcastDataMsg(); 14 | explicit BroadcastDataMsg(uint8_t channel); 15 | void setChannel(uint8_t channel); 16 | uint8_t getChannel(); 17 | uint8_t getData(uint8_t pos) override; 18 | uint8_t getDataLength() override; 19 | #ifdef NATIVE_API_AVAILABLE 20 | uint32_t execute() override; 21 | #endif 22 | private: 23 | uint8_t _channel = 0; 24 | }; 25 | 26 | #endif // ANT_BROADCASTMSG_h 27 | -------------------------------------------------------------------------------- /src/TX/Data/ANT_BurstTransferDataMsg.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | BurstTransferDataMsg::BurstTransferDataMsg() : AntTxDataRequest(BURST_TRANSFER_DATA) { 6 | 7 | } 8 | 9 | BurstTransferDataMsg::BurstTransferDataMsg(uint8_t channel) : AntTxDataRequest(BURST_TRANSFER_DATA) { 10 | setChannelNumber(channel); 11 | } 12 | 13 | void BurstTransferDataMsg::setChannelNumber(uint8_t channel) { 14 | // TODO handle sequence number bits 15 | _channel = channel; 16 | } 17 | 18 | uint8_t BurstTransferDataMsg::getSequenceNumber() { 19 | return _channel; 20 | } 21 | 22 | uint8_t BurstTransferDataMsg::getData(uint8_t pos) { 23 | // TODO 24 | return 0; 25 | } 26 | 27 | uint8_t BurstTransferDataMsg::getDataLength() { 28 | // TODO 29 | return 0; 30 | } 31 | 32 | void BurstTransferDataMsg::setDataLength(uint8_t length) { 33 | AntTxDataRequest::setDataLength(length); 34 | } 35 | 36 | #ifdef NATIVE_API_AVAILABLE 37 | 38 | uint32_t BurstTransferDataMsg::execute() { 39 | // TODO 40 | return 0; 41 | } 42 | 43 | #endif // NATIVE_API_AVAILABLE 44 | -------------------------------------------------------------------------------- /src/TX/Data/ANT_BurstTransferDataMsg.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_BURSTTRANSFERDATAMSG_h 2 | #define ANT_BURSTTRANSFERDATAMSG_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a Burst Transfer Data Tx message, it is used to send a message from the ANT radio 8 | */ 9 | class BurstTransferDataMsg : public AntTxDataRequest { 10 | public: 11 | BurstTransferDataMsg(); 12 | explicit BurstTransferDataMsg(uint8_t channel); 13 | void setChannelNumber(uint8_t channel); 14 | /** 15 | * Sets the sequence number for the message (upper 3 bits of first byte) 16 | * 17 | * Make sure your read up on seqno in the ant docs before you use this 18 | */ 19 | void setSequenceNumber(uint8_t seqNo); 20 | uint8_t getChannelSequence(); 21 | uint8_t getSequenceNumber(); 22 | uint8_t getData(uint8_t pos) override; 23 | uint8_t getDataLength() override; 24 | void setDataLength(uint8_t length); 25 | #ifdef NATIVE_API_AVAILABLE 26 | uint32_t execute() override; 27 | #endif // NATIVE_API_AVAILABLE 28 | private: 29 | uint8_t _channel = 0; 30 | }; 31 | 32 | #endif // ANT_BURSTTRANSFERDATAMSG_h 33 | -------------------------------------------------------------------------------- /src/TX/Test/ANT_CWInit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | CWInit::CWInit() : AntRequest(CW_INIT) {} 6 | 7 | uint8_t CWInit::getData(uint8_t pos) { 8 | return 0; 9 | } 10 | 11 | uint8_t CWInit::getDataLength() { 12 | return CW_INIT_LENGTH; 13 | } 14 | 15 | #ifdef NATIVE_API_AVAILABLE 16 | 17 | uint32_t CWInit::execute() { 18 | return sd_ant_cw_test_mode_init(); 19 | } 20 | 21 | #endif // NATIVE_API_AVAILABLE 22 | -------------------------------------------------------------------------------- /src/TX/Test/ANT_CWInit.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CWINIT_h 2 | #define ANT_CWINIT_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a cw init packet 8 | * 9 | */ 10 | class CWInit : public AntRequest { 11 | public: 12 | CWInit(); 13 | uint8_t getData(uint8_t pos) override; 14 | uint8_t getDataLength() override; 15 | #ifdef NATIVE_API_AVAILABLE 16 | uint32_t execute() override; 17 | #endif // NATIVE_API_AVAILABLE 18 | }; 19 | 20 | #endif // ANT_CWINIT_h 21 | -------------------------------------------------------------------------------- /src/TX/Test/ANT_CWTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | CWTest::CWTest() : AntRequest(CW_TEST) {} 6 | 7 | CWTest::CWTest(uint8_t power, uint8_t frequency) : AntRequest(CW_TEST), _transmitPower(power), _channelRfFrequency(frequency) { 8 | } 9 | 10 | void CWTest::setTransmitPower(uint8_t power) { 11 | _transmitPower = power; 12 | } 13 | 14 | // cppcheck-suppress unusedFunction 15 | void CWTest::setChannelRfFrequency(uint8_t frequency) { 16 | _channelRfFrequency = frequency; 17 | } 18 | 19 | uint8_t CWTest::getTransmitPower() { 20 | return _transmitPower; 21 | } 22 | 23 | // cppcheck-suppress unusedFunction 24 | uint8_t CWTest::getChannelRfFrequency() { 25 | return _channelRfFrequency; 26 | } 27 | 28 | uint8_t CWTest::getData(uint8_t pos) { 29 | if (pos == 0) { 30 | return 0; 31 | } else if (pos == 1) { 32 | return _transmitPower; 33 | } else { 34 | return _channelRfFrequency; 35 | } 36 | } 37 | 38 | uint8_t CWTest::getDataLength() { 39 | return CW_TEST_LENGTH; 40 | } 41 | 42 | #ifdef NATIVE_API_AVAILABLE 43 | 44 | uint32_t CWTest::execute() { 45 | return sd_ant_cw_test_mode(_channelRfFrequency, _transmitPower, 0, 0); 46 | } 47 | 48 | #endif // NATIVE_API_AVAILABLE 49 | -------------------------------------------------------------------------------- /src/TX/Test/ANT_CWTest.h: -------------------------------------------------------------------------------- 1 | #ifndef ANT_CWTEST_h 2 | #define ANT_CWTEST_h 3 | 4 | #include 5 | 6 | /** 7 | * Represents a cw test packet 8 | * 9 | */ 10 | class CWTest : public AntRequest { 11 | public: 12 | CWTest(); 13 | CWTest(uint8_t power, uint8_t frequency); 14 | void setTransmitPower(uint8_t power); 15 | void setChannelRfFrequency(uint8_t frequency); 16 | uint8_t getTransmitPower(); 17 | uint8_t getChannelRfFrequency(); 18 | uint8_t getData(uint8_t pos) override; 19 | uint8_t getDataLength() override; 20 | #ifdef NATIVE_API_AVAILABLE 21 | uint32_t execute() override; 22 | #endif // NATIVE_API_AVAILABLE 23 | private: 24 | uint8_t _transmitPower = 0; 25 | uint8_t _channelRfFrequency = 0; 26 | }; 27 | 28 | #endif // ANT_CWTEST_h 29 | -------------------------------------------------------------------------------- /src/Util/Testing.cpp: -------------------------------------------------------------------------------- 1 | #ifdef UNIT_TEST 2 | 3 | #include "Util/Testing.h" 4 | #include 5 | #include "unity.h" 6 | 7 | Stream Serial = Stream(NULL, NULL); 8 | 9 | unsigned long millis() { 10 | struct timeval time; 11 | gettimeofday(&time, NULL); 12 | return time.tv_usec/1000; 13 | } 14 | 15 | Stream::Stream(const uint8_t* inBuffer, const uint8_t* outBuffer) { 16 | _inBuffer = inBuffer; 17 | _outBuffer = outBuffer; 18 | } 19 | 20 | uint8_t Stream::available() { 21 | return sizeof(_inBuffer) - _read; 22 | } 23 | 24 | uint8_t Stream::read() { 25 | return _inBuffer[_read++]; 26 | } 27 | 28 | void Stream::write(uint8_t data) { 29 | if (_wrote < sizeof(_outBuffer)) { 30 | TEST_ASSERT_EQUAL(data, _outBuffer[_wrote++]); 31 | } 32 | } 33 | 34 | void Stream::write(uint8_t *data, uint8_t len) { 35 | for (int i = 0; i < len; i++) { 36 | write(data[i]); 37 | } 38 | } 39 | 40 | #endif // UNIT_TEST 41 | -------------------------------------------------------------------------------- /src/Util/Testing.h: -------------------------------------------------------------------------------- 1 | #ifdef UNIT_TEST 2 | #ifndef ANT_TESTING_h 3 | #define ANT_TESTING_h 4 | #include 5 | #include 6 | 7 | unsigned long millis(); 8 | 9 | class Stream { 10 | public: 11 | Stream(const uint8_t* inBuffer, const uint8_t* outBuffer); 12 | uint8_t available(); 13 | uint8_t read(); 14 | void write(uint8_t data); 15 | void write(uint8_t *data, uint8_t len); 16 | private: 17 | const uint8_t* _inBuffer; 18 | const uint8_t* _outBuffer; 19 | uint8_t _read = 0; 20 | uint8_t _wrote = 0; 21 | }; 22 | 23 | extern Stream Serial; 24 | #endif // ANT_TESTING_h 25 | #endif // UNIT_TEST 26 | -------------------------------------------------------------------------------- /test/test_TX_AddChannelIdToList/Test_AddChannelIdToList.cpp: -------------------------------------------------------------------------------- 1 | #include "unity.h" 2 | #include "ANT.h" 3 | #include "Util/Testing.h" 4 | 5 | #ifdef UNIT_TEST 6 | 7 | const uint8_t expectedOut[] = {0xA4, 6, 0x59, 2, 0x44, 0x33, 120, 34, 2, 214}; 8 | Stream mock_stream = Stream(NULL, expectedOut); 9 | ArduinoSerialAntWithCallbacks ant; 10 | AddChannelIdToList msg; 11 | 12 | void test_constructors(void) { 13 | msg = AddChannelIdToList(2, 3344, 120, 34, 2); 14 | TEST_ASSERT_EQUAL_UINT8(2, msg.getChannel()); 15 | TEST_ASSERT_EQUAL_UINT16(3344, msg.getDeviceNumber()); 16 | TEST_ASSERT_EQUAL_UINT8(120, msg.getDeviceType()); 17 | TEST_ASSERT_EQUAL_UINT8(34, msg.getTransmissionType()); 18 | TEST_ASSERT_EQUAL_UINT8(2, msg.getListIndex()); 19 | } 20 | 21 | void test_setChannel(void) { 22 | msg.setChannel(3); 23 | TEST_ASSERT_EQUAL_UINT8(3, msg.getChannel()); 24 | } 25 | 26 | void test_setDeviceNumber(void) { 27 | msg.setDeviceNumber(0x4455); 28 | TEST_ASSERT_EQUAL_UINT16(0x4455, msg.getDeviceNumber()); 29 | } 30 | 31 | void test_setDeviceType(void) { 32 | msg.setDeviceType(100); 33 | TEST_ASSERT_EQUAL_UINT8(100, msg.getDeviceType()); 34 | } 35 | 36 | void test_setTransmisionType(void) { 37 | msg.setTransmissionType(12); 38 | TEST_ASSERT_EQUAL_UINT8(12, msg.getTransmissionType()); 39 | } 40 | 41 | void test_setListIndex(void) { 42 | msg.setListIndex(4); 43 | TEST_ASSERT_EQUAL_UINT8(4, msg.getListIndex()); 44 | } 45 | 46 | void test_getDataLength(void) { 47 | TEST_ASSERT_EQUAL_UINT8(6, msg.getDataLength()); 48 | } 49 | 50 | void test_serialize(void) { 51 | // Asserts are in mock stream 52 | ant.begin(mock_stream); 53 | msg = AddChannelIdToList(2, 0x3344, 120, 34, 2); 54 | ant.send(msg); 55 | } 56 | 57 | int main(int argc, char **argv) { 58 | UNITY_BEGIN(); 59 | RUN_TEST(test_constructors); 60 | RUN_TEST(test_setChannel); 61 | RUN_TEST(test_setDeviceNumber); 62 | RUN_TEST(test_setDeviceType); 63 | RUN_TEST(test_setTransmisionType); 64 | RUN_TEST(test_setListIndex); 65 | RUN_TEST(test_getDataLength); 66 | RUN_TEST(test_serialize); 67 | UNITY_END(); 68 | 69 | return 0; 70 | } 71 | 72 | #endif // UNIT_TEST 73 | -------------------------------------------------------------------------------- /test/test_TX_AddEncryptionIdToList/Test_AddEncryptionIdToList.cpp: -------------------------------------------------------------------------------- 1 | #include "unity.h" 2 | #include "ANT.h" 3 | #include "Util/Testing.h" 4 | 5 | #ifdef UNIT_TEST 6 | 7 | const uint8_t expectedOut[] = {0xA4, 6, 0x59, 1, 0x78, 0x56, 0x34, 0x12, 3, 241}; 8 | Stream mock_stream = Stream(NULL, expectedOut); 9 | ArduinoSerialAntWithCallbacks ant; 10 | AddEncryptionIdToList msg; 11 | 12 | void test_constructors(void) { 13 | msg = AddEncryptionIdToList(1, 0x12345678, 3); 14 | TEST_ASSERT_EQUAL_UINT8(1, msg.getChannel()); 15 | TEST_ASSERT_EQUAL_UINT32(0x12345678, msg.getEncryptionId()); 16 | TEST_ASSERT_EQUAL_UINT8(3, msg.getListIndex()); 17 | } 18 | 19 | void test_setChannel(void) { 20 | msg.setChannel(3); 21 | TEST_ASSERT_EQUAL_UINT8(3, msg.getChannel()); 22 | } 23 | 24 | void test_setEncryptionId(void) { 25 | msg.setEncryptionId(0x11223344); 26 | TEST_ASSERT_EQUAL_UINT16(0x11223344, msg.getEncryptionId()); 27 | } 28 | 29 | void test_setListIndex(void) { 30 | msg.setListIndex(3); 31 | TEST_ASSERT_EQUAL_UINT8(3, msg.getListIndex()); 32 | } 33 | 34 | void test_getDataLength(void) { 35 | TEST_ASSERT_EQUAL_UINT8(6, msg.getDataLength()); 36 | } 37 | 38 | void test_serialize(void) { 39 | // Asserts are in mock stream 40 | ant.begin(mock_stream); 41 | msg = AddEncryptionIdToList(1, 0x12345678, 3); 42 | ant.send(msg); 43 | } 44 | 45 | int main(int argc, char **argv) { 46 | UNITY_BEGIN(); 47 | RUN_TEST(test_constructors); 48 | RUN_TEST(test_setEncryptionId); 49 | RUN_TEST(test_setListIndex); 50 | RUN_TEST(test_getDataLength); 51 | RUN_TEST(test_serialize); 52 | UNITY_END(); 53 | 54 | return 0; 55 | } 56 | 57 | #endif // UNIT_TEST 58 | --------------------------------------------------------------------------------