[
  {
    "path": ".gitattributes",
    "content": "# Auto detect text files and perform LF normalization\n* text=auto\n\n# Custom for Visual Studio\n*.cs     diff=csharp\n\n# Standard to msysgit\n*.doc\t diff=astextplain\n*.DOC\t diff=astextplain\n*.docx diff=astextplain\n*.DOCX diff=astextplain\n*.dot  diff=astextplain\n*.DOT  diff=astextplain\n*.pdf  diff=astextplain\n*.PDF\t diff=astextplain\n*.rtf\t diff=astextplain\n*.RTF\t diff=astextplain\n"
  },
  {
    "path": ".gitignore",
    "content": "\n*.o\n\n#################\n## Eclipse\n#################\n\n*.pydevproject\n.project\n.metadata\nbin/\ntmp/\n*.tmp\n*.bak\n*.swp\n*~.nib\nlocal.properties\n.classpath\n.settings/\n.loadpath\n\n# External tool builders\n.externalToolBuilders/\n\n# Locally stored \"Eclipse launch configurations\"\n*.launch\n\n# CDT-specific\n.cproject\n\n# PDT-specific\n.buildpath\n\n\n#################\n## Visual Studio\n#################\n\n## Ignore Visual Studio temporary files, build results, and\n## files generated by popular Visual Studio add-ons.\n\n# User-specific files\n*.suo\n*.user\n*.sln.docstates\n\n# Build results\n\n[Dd]ebug/\n[Rr]elease/\nx64/\nbuild/\n[Bb]in/\n[Oo]bj/\n\n# MSTest test Results\n[Tt]est[Rr]esult*/\n[Bb]uild[Ll]og.*\n\n*_i.c\n*_p.c\n*.ilk\n*.meta\n*.obj\n*.pch\n*.pdb\n*.pgc\n*.pgd\n*.rsp\n*.sbr\n*.tlb\n*.tli\n*.tlh\n*.tmp\n*.tmp_proj\n*.log\n*.vspscc\n*.vssscc\n.builds\n*.pidb\n*.log\n*.scc\n\n# Visual C++ cache files\nipch/\n*.aps\n*.ncb\n*.opensdf\n*.sdf\n*.cachefile\n\n# Visual Studio profiler\n*.psess\n*.vsp\n*.vspx\n\n# Guidance Automation Toolkit\n*.gpState\n\n# ReSharper is a .NET coding add-in\n_ReSharper*/\n*.[Rr]e[Ss]harper\n\n# TeamCity is a build add-in\n_TeamCity*\n\n# DotCover is a Code Coverage Tool\n*.dotCover\n\n# NCrunch\n*.ncrunch*\n.*crunch*.local.xml\n\n# Installshield output folder\n[Ee]xpress/\n\n# DocProject is a documentation generator add-in\nDocProject/buildhelp/\nDocProject/Help/*.HxT\nDocProject/Help/*.HxC\nDocProject/Help/*.hhc\nDocProject/Help/*.hhk\nDocProject/Help/*.hhp\nDocProject/Help/Html2\nDocProject/Help/html\n\n# Click-Once directory\npublish/\n\n# Publish Web Output\n*.Publish.xml\n*.pubxml\n*.publishproj\n\n# NuGet Packages Directory\n## TODO: If you have NuGet Package Restore enabled, uncomment the next line\n#packages/\n\n# Windows Azure Build Output\ncsx\n*.build.csdef\n\n# Windows Store app package directory\nAppPackages/\n\n# Others\nsql/\n*.Cache\nClientBin/\n[Ss]tyle[Cc]op.*\n~$*\n*~\n*.dbmdl\n*.[Pp]ublish.xml\n*.pfx\n*.publishsettings\n\n# RIA/Silverlight projects\nGenerated_Code/\n\n# Backup & report files from converting an old project file to a newer\n# Visual Studio version. Backup files are not needed, because we have git ;-)\n_UpgradeReport_Files/\nBackup*/\nUpgradeLog*.XML\nUpgradeLog*.htm\n\n# SQL Server files\nApp_Data/*.mdf\nApp_Data/*.ldf\n\n#############\n## Windows detritus\n#############\n\n# Windows image file caches\nThumbs.db\nehthumbs.db\n\n# Folder config file\nDesktop.ini\n\n# Recycle Bin used on file shares\n$RECYCLE.BIN/\n\n# Mac crap\n.DS_Store\n\n\n#############\n## Python\n#############\n\n*.py[cod]\n\n# Packages\n*.egg\n*.egg-info\ndist/\nbuild/\neggs/\nparts/\nvar/\nsdist/\ndevelop-eggs/\n.installed.cfg\n\n# Installer logs\npip-log.txt\n\n# Unit test / coverage reports\n.coverage\n.tox\n\n#Translations\n*.mo\n\n#Mr Developer\n.mr.developer.cfg\n"
  },
  {
    "path": "LICENSE",
    "content": "This software is Copyright (C) 2008 Mike McCauley. Use is subject to license\nconditions. The main licensing options available are GPL V2 or Commercial:\n\nOpen Source Licensing GPL V2\n\nThis is the appropriate option if you want to share the source code of your\napplication with everyone you distribute it to, and you also want to give them\nthe right to share who uses it. If you wish to use this software under Open\nSource Licensing, you must contribute all your source code to the open source\ncommunity in accordance with the GPL Version 2 when your application is\ndistributed. See http://www.gnu.org/copyleft/gpl.html\n\nCommercial Licensing\n\nThis is the appropriate option if you are creating proprietary applications\nand you are not prepared to distribute and share the source code of your\napplication. Contact info@open.com.au for details.\n"
  },
  {
    "path": "MANIFEST",
    "content": "RadioHead/LICENSE\nRadioHead/MANIFEST\nRadioHead/project.cfg\nRadioHead/RadioHead.h\nRadioHead/RH_ASK.cpp\nRadioHead/RH_ASK.h\nRadioHead/RHCRC.cpp\nRadioHead/RHCRC.h\nRadioHead/RHDatagram.cpp\nRadioHead/RHDatagram.h\nRadioHead/RHGenericDriver.cpp\nRadioHead/RHGenericDriver.h\nRadioHead/RHGenericSPI.cpp\nRadioHead/RHGenericSPI.h\nRadioHead/RHHardwareSPI.cpp\nRadioHead/RHHardwareSPI.h\nRadioHead/RHMesh.cpp\nRadioHead/RHMesh.h\nRadioHead/RHReliableDatagram.cpp\nRadioHead/RHReliableDatagram.h\nRadioHead/RH_CC110.cpp\nRadioHead/RH_CC110.h\nRadioHead/RH_NRF24.cpp\nRadioHead/RH_NRF24.h\nRadioHead/RH_NRF51.cpp\nRadioHead/RH_NRF51.h\nRadioHead/RH_NRF905.cpp\nRadioHead/RH_NRF905.h\nRadioHead/RH_RF22.cpp\nRadioHead/RH_RF22.h\nRadioHead/RH_RF24.cpp\nRadioHead/RH_RF24.h\nRadioHead/radio_config_Si4460.h\nRadioHead/RH_RF69.cpp\nRadioHead/RH_RF69.h\nRadioHead/RH_MRF89.cpp\nRadioHead/RH_MRF89.h\nRadioHead/RH_RF95.cpp\nRadioHead/RH_RF95.h\nRadioHead/RH_TCP.cpp\nRadioHead/RH_TCP.h\nRadioHead/RHRouter.cpp\nRadioHead/RHRouter.h\nRadioHead/RH_Serial.cpp\nRadioHead/RH_Serial.h\nRadioHead/RHSoftwareSPI.cpp\nRadioHead/RHSoftwareSPI.h\nRadioHead/RHSPIDriver.cpp\nRadioHead/RHSPIDriver.h\nRadioHead/RHTcpProtocol.h\nRadioHead/RHNRFSPIDriver.cpp\nRadioHead/RHNRFSPIDriver.h\nRadioHead/RHutil\nRadioHead/RHutil/atomic.h\nRadioHead/RHutil/simulator.h\nRadioHead/RHutil/HardwareSerial.h\nRadioHead/RHutil/HardwareSerial.cpp\nRadioHead/RHutil/RasPi.cpp\nRadioHead/RHutil/RasPi.h\nRadioHead/examples/ask/ask_reliable_datagram_client/ask_reliable_datagram_client.pde\nRadioHead/examples/ask/ask_reliable_datagram_server/ask_reliable_datagram_server.pde\nRadioHead/examples/ask/ask_transmitter/ask_transmitter.pde\nRadioHead/examples/ask/ask_receiver/ask_receiver.pde\nRadioHead/examples/cc110/cc110_client/cc110_client.pde\nRadioHead/examples/cc110/cc110_server/cc110_server.pde\nRadioHead/examples/rf95/rf95_client/rf95_client.pde\nRadioHead/examples/rf95/rf95_reliable_datagram_client/rf95_reliable_datagram_client.pde\nRadioHead/examples/rf95/rf95_reliable_datagram_server/rf95_reliable_datagram_server.pde\nRadioHead/examples/rf95/rf95_server/rf95_server.pde\nRadioHead/examples/rf22/rf22_client/rf22_client.pde\nRadioHead/examples/rf22/rf22_mesh_client/rf22_mesh_client.pde\nRadioHead/examples/rf22/rf22_mesh_server1/rf22_mesh_server1.pde\nRadioHead/examples/rf22/rf22_mesh_server2/rf22_mesh_server2.pde\nRadioHead/examples/rf22/rf22_mesh_server3/rf22_mesh_server3.pde\nRadioHead/examples/rf22/rf22_reliable_datagram_client/rf22_reliable_datagram_client.pde\nRadioHead/examples/rf22/rf22_reliable_datagram_server/rf22_reliable_datagram_server.pde\nRadioHead/examples/rf22/rf22_router_client/rf22_router_client.pde\nRadioHead/examples/rf22/rf22_router_server1/rf22_router_server1.pde\nRadioHead/examples/rf22/rf22_router_server2/rf22_router_server2.pde\nRadioHead/examples/rf22/rf22_router_server3/rf22_router_server3.pde\nRadioHead/examples/rf22/rf22_router_test/rf22_router_test.pde\nRadioHead/examples/rf22/rf22_server/rf22_server.pde\nRadioHead/examples/rf24/rf24_client/rf24_client.pde\nRadioHead/examples/rf24/rf24_reliable_datagram_client/rf24_reliable_datagram_client.pde\nRadioHead/examples/rf24/rf24_reliable_datagram_server/rf24_reliable_datagram_server.pde\nRadioHead/examples/rf24/rf24_server/rf24_server.pde\nRadioHead/examples/rf69/rf69_client/rf69_client.pde\nRadioHead/examples/rf69/rf69_reliable_datagram_client/rf69_reliable_datagram_client.pde\nRadioHead/examples/rf69/rf69_reliable_datagram_server/rf69_reliable_datagram_server.pde\nRadioHead/examples/rf69/rf69_server/rf69_server.pde\nRadioHead/examples/mrf89/mrf89_client/mrf89_client.pde\nRadioHead/examples/mrf89/mrf89_server/mrf89_server.pde\nRadioHead/examples/nrf24/nrf24_client/nrf24_client.pde\nRadioHead/examples/nrf24/nrf24_reliable_datagram_client/nrf24_reliable_datagram_client.pde\nRadioHead/examples/nrf24/nrf24_reliable_datagram_server/nrf24_reliable_datagram_server.pde\nRadioHead/examples/nrf24/nrf24_server/nrf24_server.pde\nRadioHead/examples/nrf51/nrf51_client/nrf51_client.pde\nRadioHead/examples/nrf51/nrf51_reliable_datagram_client/nrf51_reliable_datagram_client.pde\nRadioHead/examples/nrf51/nrf51_reliable_datagram_server/nrf51_reliable_datagram_server.pde\nRadioHead/examples/nrf51/nrf51_server/nrf51_server.pde\nRadioHead/examples/nrf51/nrf51_audio_tx/nrf51_audio_tx.pde\nRadioHead/examples/nrf51/nrf51_audio_tx/nrf51_audio.pdf\nRadioHead/examples/nrf51/nrf51_audio_rx/nrf51_audio_rx.pde\nRadioHead/examples/nrf905/nrf905_client/nrf905_client.pde\nRadioHead/examples/nrf905/nrf905_reliable_datagram_client/nrf905_reliable_datagram_client.pde\nRadioHead/examples/nrf905/nrf905_reliable_datagram_server/nrf905_reliable_datagram_server.pde\nRadioHead/examples/nrf905/nrf905_server/nrf905_server.pde\nRadioHead/examples/serial/serial_reliable_datagram_client/serial_reliable_datagram_client.pde\nRadioHead/examples/serial/serial_reliable_datagram_server/serial_reliable_datagram_server.pde\nRadioHead/examples/simulator/simulator_reliable_datagram_client/simulator_reliable_datagram_client.pde\nRadioHead/examples/simulator/simulator_reliable_datagram_server/simulator_reliable_datagram_server.pde\nRadioHead/examples/raspi/RasPiRH.cpp\nRadioHead/examples/raspi/Makefile\nRadioHead/tools/etherSimulator.pl\nRadioHead/tools/chain.conf\nRadioHead/tools/simMain.cpp\nRadioHead/tools/simBuild\nRadioHead/doc\nRadioHead/STM32ArduinoCompat/HardwareSerial.cpp\nRadioHead/STM32ArduinoCompat/HardwareSerial.h\nRadioHead/STM32ArduinoCompat/HardwareSPI.cpp\nRadioHead/STM32ArduinoCompat/HardwareSPI.h\nRadioHead/STM32ArduinoCompat/wirish.cpp\nRadioHead/STM32ArduinoCompat/wirish.h\nRadioHead/STM32ArduinoCompat/README\n"
  },
  {
    "path": "README.md",
    "content": "RadioHead Packet Radio library for embedded microprocessors\n===========================================================\n\n###Version 1.67\n\nThis is a fork of the original RadioHead Packet Radio library for embedded microprocessors. It provides a complete object-oriented library for sending and receiving packetized messages via a variety of common data radios and other transports on a range of embedded microprocessors.\n\n**Please read the full documentation and licensing from the original author [site][3]**\n\n### features added with this fork\n=================================\n\n**Compatible with boards**    \n\n[LoRasPI][10], [Raspberry PI Lora Gateway][12], [Dragino Lora GPS HAT][13]\n\n<img src=\"https://raw.githubusercontent.com/hallard/LoRasPI/master/images/LoRasPI-on-Pi.jpg\" height=\"25%\" width=\"25%\" alt=\"LoRasPI\">&nbsp;\n<img src=\"https://raw.githubusercontent.com/hallard/RPI-Lora-Gateway/master/images/RPI-Lora-Gateway-mounted.jpg\" height=\"25%\" width=\"25%\" alt=\"Raspberry PI Lora Gateway/Node\">&nbsp;\n<img src=\"http://wiki.dragino.com/images/d/d6/Lora_GPS_HAT.png\" height=\"25%\" width=\"25%\" alt=\"Raspberry PI Lora Gateway/Node\">   \n\n- Added moteino modem setting on RF69 to be compatible with lowpowerlab RF69 configuration library\n- Added possibility to work with no IRQ connected for RF69 and RF95\n  - for example to get one more GPIO free \n  - on Raspberry Pi, we do not have `attachInterrupt()` like with bcm2835 library\n- Added samples for multiples Raspberry Pi boards with RF69 and RF95 modules such as \n  - [LoRasPI][10], simple RFM9x or RFM69HCW shield\n  - [iC880A or Linklabs Raspberry PI shield][11] with RFM9x or RFM69HCW onboard \n  - [Raspberry PI Lora Gateway][12] with multiple RFM9x or RFM69HCW shield\n  - [Dragino Lora shield][13]\n  - Sample code are in [rf95][21], [rf69][20], [nrf24][22] and [multi_server][23], note that old sample NRF24 sample has been moved to nrf24 folder for consistency.\n- Added 2 samples test tools (for Raspberry PI) do detect RF69 and RF95 modules and check IRQ rising edge\n  - [spi_scan][9] sample code, scan and try to detect connected modules\n  - [irq_test][8] sample code, check a rising edge on a GPIO\n\nSample code for Raspberry PI is located under [RadioHead/examples/raspi][7] folder.\n\n### Installation on Raspberry PI\n================================\n\nClone repository\n```shell\ngit clone https://github.com/hallard/RadioHead\n```\n\nTo avoid system hangs/instability starting with kernel 4.14, disable all GPIO kernel interrupts by adding this line to your `/boot/config.txt`:\n```\ndtoverlay=gpio-no-irq\n```\nThis works around an issue with the design of the bcm2835 library and how it handles rising/falling edge detection events, but has some downsides as well.  For more information, see [this issue][30] and [this discussion][31].\n\n**Connection and pins definition**\n\nBoards pins (Chip Select, IRQ line, Reset and LED) definition are set in the new [RadioHead/examples/raspi/RasPiBoards.h][24] file. In your code, you need to define board used and then, include the file definition like this\n```cpp\n// LoRasPi board \n#define BOARD_LORASPI\n\n// Now we include RasPi_Boards.h so this will expose defined \n// constants with CS/IRQ/RESET/on board LED pins definition\n#include \"../RasPiBoards.h\"\n\n// Your code start here\n#ifdef RF_RST_PIN\n// Blah blah do reset line\n#endif\n\n```\n\nThen in your code you'll have exposed RF_CS_PIN, RF_IRQ_PIN, RF_RST_PIN and RF_LED_PIN and you'll be able to do some `#ifdef RF_LED_LIN` for example. See [rf95_client][25] sample code.\n\nSo you have 3 options to define the pins you want \n\n- The board you have is already defined so just need to define it your source code (as explained above)\n- You can add your board into [RasPiBoards.h][24] and then define it your source code as above\n- You can manually define pins in your code and remove the board definition and `#include \"../RasPiBoards.h\"`\n\nTo go further with examples :\n\ngo to example folder here spi_scan\n```shell\ncd RadioHead/examples/raspi/spi_scan\n```\nBuild executable\n```shell\nroot@pi03(rw):~/RadioHead/examples/raspi/spi_scan# make\ng++ -DRASPBERRY_PI -DBCM2835_NO_DELAY_COMPATIBILITY -c -I../../.. spi_scan.c\ng++ spi_scan.o -lbcm2835  -o spi_scan\nroot@pi03(rw):~/RadioHead/examples/raspi/spi_scan\n```\nAnd run \n```shell\nroot@pi03(rw):~/RadioHead/examples/raspi/spi_scan# ./spi_scan\nChecking register(0x42) with CS=GPIO06 => Nothing!\nChecking register(0x10) with CS=GPIO06 => Nothing!\nChecking register(0x42) with CS=GPIO08 => SX1276 RF95/96 (V=0x12)\nChecking register(0x10) with CS=GPIO08 => Nothing!\nChecking register(0x42) with CS=GPIO07 => Nothing!\nChecking register(0x10) with CS=GPIO07 => Nothing!\nChecking register(0x42) with CS=GPIO26 => Nothing!\nChecking register(0x10) with CS=GPIO26 => Nothing!\n```\nAnd voila! with [LoRasPi][10] board RFM95 dedected on SPI with GPIO8 (CE0)\n\n\nIf I'm doing same test with [PI Lora Gateway][12] with 2 RFM95 (one 433MHz and one 868MHz) and one RFMHW69 433MHz on board like this    \n\n<img src=\"https://raw.githubusercontent.com/hallard/RPI-Lora-Gateway/master/images/RPI-Lora-Gateway-mounted.jpg\" height=\"40%\" width=\"40%\" alt=\"Raspberry PI Lora Gateway/Node\">   \n\nHere are the results when trying to detect the onboard modules:\n\n```shell\nroot@pi01(rw):~/RadioHead/examples/raspi/spi_scan# ./spi_scan\nChecking register(0x42) with CS=GPIO06 => Nothing!\nChecking register(0x10) with CS=GPIO06 => Nothing!\nChecking register(0x42) with CS=GPIO08 => SX1276 RF95/96 (V=0x12)\nChecking register(0x10) with CS=GPIO08 => Nothing!\nChecking register(0x42) with CS=GPIO07 => SX1276 RF95/96 (V=0x12)\nChecking register(0x10) with CS=GPIO07 => Nothing!\nChecking register(0x42) with CS=GPIO26 => Unknown (V=0x01)\nChecking register(0x10) with CS=GPIO26 => SX1231 RFM69 (V=0x24)\n```\n\nVoila! 3 modules are seen, now let's try listenning packets with PI Lora [Gateway][12].\n\nMy setup has another Raspberry Pi with RFM95 868MHZ [LoRasPI][10] shield running [`rf95_client`][25] sample and some [ULPnode][6] prototypes always running with on board RFM69 configured as Group ID 69 on 433MHz. I don't have a Lora 433MHz sender running so we won't receive anything on this one.\n\nHere the results starting from scratch\n\n**Client side**    \n\n<img src=\"https://raw.githubusercontent.com/hallard/RadioHead/master/examples/raspi/pictures/rf95_client.png\" alt=\"RF95 client\">    \n\n**multi server side**    \n\n<img src=\"https://raw.githubusercontent.com/hallard/RadioHead/master/examples/raspi/pictures/multi_server.png\" alt=\"RF95 client\">   \n\nIt works! \n\n### Difference with original Author repo\n========================================\n\nDue to easier maintenance to keep in sync with original author lib, I've got 2 repo:    \n\n- My master one (this one) https://github.com/hallard/RadioHead that is the one you need if you want to use my projects or lib added features.\n-  The one above has been forked to https://github.com/ch2i/RadioHead where I put the original version released by the author.\n\nLike this, I can do Pull Request from [ch2i][4] to [hallard][1] to add new features added by the author to my version. This mean that this [one][4] is just a github copy version of the latest original done by Mike, I don't do any change on this one. I know it's not the best way, but I didn't found a better solution for now, if you have better idea, just let me know.\n\n[1]: https://github.com/hallard/RadioHead \n[2]: https://hallard.me\n[3]: http://www.airspayce.com/mikem/arduino/RadioHead/\n[4]: http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.67.zip\n[5]: https://github.com/ch2i/RadioHead \n[6]: http://hallard.me/category/ulpnode/ \n[7]: https://github.com/hallard/RadioHead/tree/master/examples/raspi\n[8]: https://github.com/hallard/RadioHead/tree/master/examples/raspi/irq_test\n[9]: https://github.com/hallard/RadioHead/tree/master/examples/raspi/spi_scan\n\n[10]: https://github.com/hallard/LoRasPI\n[11]: https://github.com/ch2i/iC880A-Raspberry-PI\n[12]: https://github.com/hallard/RPI-Lora-Gateway\n[13]: https://github.com/dragino/Lora\n\n[20]: https://github.com/hallard/RadioHead/tree/master/examples/raspi/rf69\n[21]: https://github.com/hallard/RadioHead/tree/master/examples/raspi/rf95\n[22]: https://github.com/hallard/RadioHead/tree/master/examples/raspi/nrf24\n[23]: https://github.com/hallard/RadioHead/tree/master/examples/raspi/multi_server\n[24]: https://github.com/hallard/RadioHead/tree/master/examples/raspi/RasPiBoards.h\n[25]: https://github.com/hallard/RadioHead/tree/master/examples/raspi/rf95/rf95_client.cpp\n\n[30]: https://github.com/raspberrypi/linux/issues/2550\n[31]: https://groups.google.com/forum/#!topic/bcm2835/Y3D1mmp6vew\n"
  },
  {
    "path": "RHCRC.cpp",
    "content": "/* Copyright (c) 2002, 2003, 2004  Marek Michalkiewicz\n   Copyright (c) 2005, 2007 Joerg Wunsch\n   All rights reserved.\n\n   Redistribution and use in source and binary forms, with or without\n   modification, are permitted provided that the following conditions are met:\n\n   * Redistributions of source code must retain the above copyright\n     notice, this list of conditions and the following disclaimer.\n\n   * Redistributions in binary form must reproduce the above copyright\n     notice, this list of conditions and the following disclaimer in\n     the documentation and/or other materials provided with the\n     distribution.\n\n   * Neither the name of the copyright holders nor the names of\n     contributors may be used to endorse or promote products derived\n     from this software without specific prior written permission.\n\n  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\n  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n  POSSIBILITY OF SUCH DAMAGE. */\n\n//\tPort to Energia / MPS430 by Yannick DEVOS XV4Y - (c) 2013\n//\thttp://xv4y.radioclub.asia/\n//\t\n\n// Adapted to RadioHead use by Mike McCauley 2014\n// This is to prevent name collisions with other similar library functions\n// and to provide a consistent API amonng all processors\n//\n\n/* $Id: RHCRC.cpp,v 1.1 2014/06/24 02:40:12 mikem Exp $ */\n\n#include <RHCRC.h>\n\n#define lo8(x) ((x)&0xff) \n#define hi8(x) ((x)>>8)\n\nuint16_t RHcrc16_update(uint16_t crc, uint8_t a)\n{\n    int i;\n\n    crc ^= a;\n    for (i = 0; i < 8; ++i)\n    {\n\tif (crc & 1)\n\t    crc = (crc >> 1) ^ 0xA001;\n\telse\n\t    crc = (crc >> 1);\n    }\n    return crc;\n}\n\nuint16_t RHcrc_xmodem_update (uint16_t crc, uint8_t data)\n{\n    int i;\n    \n    crc = crc ^ ((uint16_t)data << 8);\n    for (i=0; i<8; i++)\n    {\n\tif (crc & 0x8000)\n\t    crc = (crc << 1) ^ 0x1021;\n\telse\n\t    crc <<= 1;\n    }\n    \n    return crc;\n}\n\nuint16_t RHcrc_ccitt_update (uint16_t crc, uint8_t data)\n{\n    data ^= lo8 (crc);\n    data ^= data << 4;\n    \n    return ((((uint16_t)data << 8) | hi8 (crc)) ^ (uint8_t)(data >> 4) \n\t    ^ ((uint16_t)data << 3));\n}\n\nuint8_t RHcrc_ibutton_update(uint8_t crc, uint8_t data)\n{\n    uint8_t i;\n    \n    crc = crc ^ data;\n    for (i = 0; i < 8; i++)\n    {\n\tif (crc & 0x01)\n\t    crc = (crc >> 1) ^ 0x8C;\n\telse\n\t    crc >>= 1;\n    }\n    \n    return crc;\n}\n\n\n"
  },
  {
    "path": "RHCRC.h",
    "content": "// RHCRC.h\n//\n// Definitions for RadioHead compatible CRC outines.\n//\n// These routines originally derived from Arduino source code. See RHCRC.cpp\n// for copyright information\n// $Id: RHCRC.h,v 1.1 2014/06/24 02:40:12 mikem Exp $\n\n#ifndef RHCRC_h\n#define RHCRC_h\n\n#include <RadioHead.h>\n\nextern uint16_t RHcrc16_update(uint16_t crc, uint8_t a);\nextern uint16_t RHcrc_xmodem_update (uint16_t crc, uint8_t data);\nextern uint16_t RHcrc_ccitt_update (uint16_t crc, uint8_t data);\nextern uint8_t  RHcrc_ibutton_update(uint8_t crc, uint8_t data);\n\n#endif\n"
  },
  {
    "path": "RHDatagram.cpp",
    "content": "// RHDatagram.cpp\n//\n// Copyright (C) 2011 Mike McCauley\n// $Id: RHDatagram.cpp,v 1.6 2014/05/23 02:20:17 mikem Exp $\n\n#include <RHDatagram.h>\n\nRHDatagram::RHDatagram(RHGenericDriver& driver, uint8_t thisAddress) \n    :\n    _driver(driver),\n    _thisAddress(thisAddress)\n{\n}\n\n////////////////////////////////////////////////////////////////////\n// Public methods\nbool RHDatagram::init()\n{\n    bool ret = _driver.init();\n    if (ret)\n\tsetThisAddress(_thisAddress);\n    return ret;\n}\n\nvoid RHDatagram::setThisAddress(uint8_t thisAddress)\n{\n    _driver.setThisAddress(thisAddress);\n    // Use this address in the transmitted FROM header\n    setHeaderFrom(thisAddress);\n    _thisAddress = thisAddress;\n}\n\nbool RHDatagram::sendto(uint8_t* buf, uint8_t len, uint8_t address)\n{\n    setHeaderTo(address);\n    return _driver.send(buf, len);\n}\n\nbool RHDatagram::recvfrom(uint8_t* buf, uint8_t* len, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags)\n{\n    if (_driver.recv(buf, len))\n    {\n\tif (from)  *from =  headerFrom();\n\tif (to)    *to =    headerTo();\n\tif (id)    *id =    headerId();\n\tif (flags) *flags = headerFlags();\n\treturn true;\n    }\n    return false;\n}\n\nbool RHDatagram::available()\n{\n    return _driver.available();\n}\n\nvoid RHDatagram::waitAvailable()\n{\n    _driver.waitAvailable();\n}\n\nbool RHDatagram::waitPacketSent()\n{\n    return _driver.waitPacketSent();\n}\n\nbool RHDatagram::waitPacketSent(uint16_t timeout)\n{\n    return _driver.waitPacketSent(timeout);\n}\n\nbool RHDatagram::waitAvailableTimeout(uint16_t timeout)\n{\n    return _driver.waitAvailableTimeout(timeout);\n}\n\nuint8_t RHDatagram::thisAddress()\n{\n    return _thisAddress;\n}\n\nvoid RHDatagram::setHeaderTo(uint8_t to)\n{\n    _driver.setHeaderTo(to);\n}\n\nvoid RHDatagram::setHeaderFrom(uint8_t from)\n{\n    _driver.setHeaderFrom(from);\n}\n\nvoid RHDatagram::setHeaderId(uint8_t id)\n{\n    _driver.setHeaderId(id);\n}\n\nvoid RHDatagram::setHeaderFlags(uint8_t set, uint8_t clear)\n{\n    _driver.setHeaderFlags(set, clear);\n}\n\nuint8_t RHDatagram::headerTo()\n{\n    return _driver.headerTo();\n}\n\nuint8_t RHDatagram::headerFrom()\n{\n    return _driver.headerFrom();\n}\n\nuint8_t RHDatagram::headerId()\n{\n    return _driver.headerId();\n}\n\nuint8_t RHDatagram::headerFlags()\n{\n    return _driver.headerFlags();\n}\n\n\n\n"
  },
  {
    "path": "RHDatagram.h",
    "content": "// RHDatagram.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// $Id: RHDatagram.h,v 1.14 2015/08/12 23:18:51 mikem Exp $\n\n#ifndef RHDatagram_h\n#define RHDatagram_h\n\n#include <RHGenericDriver.h>\n\n// This is the maximum possible message size for radios supported by RadioHead.\n// Not all radios support this length, and many are much smaller\n#define RH_MAX_MESSAGE_LEN 255\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHDatagram RHDatagram.h <RHDatagram.h>\n/// \\brief Manager class for addressed, unreliable messages\n///\n/// Every RHDatagram node has an 8 bit address (defaults to 0).\n/// Addresses (DEST and SRC) are 8 bit integers with an address of RH_BROADCAST_ADDRESS (0xff) \n/// reserved for broadcast.\n///\n/// \\par Media Access Strategy\n///\n/// RHDatagram and the underlying drivers always transmit as soon as sendto() is called.\n///\n/// \\par Message Lengths\n///\n/// Not all Radio drivers supported by RadioHead can handle the same message lengths. Some radios can handle\n/// up to 255 octets, and some as few as 28. If you attempt to send a message that is too long for \n/// the underlying driver, sendTo() will return false and will not transmit the message. \n/// It is the programmers responsibility to make\n/// sure that messages passed to sendto() do not exceed the capability of the radio. You can use the \n/// *_MAX_MESSAGE_LENGTH definitions or driver->maxMessageLength() to help.\n///\n/// \\par Headers\n///\n/// Each message sent and received by a RadioHead driver includes 4 headers:<br>\n/// \\b TO The node address that the message is being sent to (broadcast RH_BROADCAST_ADDRESS (255) is permitted)<br>\n/// \\b FROM The node address of the sending node<br>\n/// \\b ID A message ID, distinct (over short time scales) for each message sent by a particilar node<br>\n/// \\b FLAGS A bitmask of flags. The most significant 4 bits are reserved for use by RadioHead. The least\n/// significant 4 bits are reserved for applications.<br>\n///\nclass RHDatagram\n{\npublic:\n    /// Constructor. \n    /// \\param[in] driver The RadioHead driver to use to transport messages.\n    /// \\param[in] thisAddress The address to assign to this node. Defaults to 0\n    RHDatagram(RHGenericDriver& driver, uint8_t thisAddress = 0);\n\n    /// Initialise this instance and the \n    /// driver connected to it.\n    bool init();\n\n    /// Sets the address of this node. Defaults to 0. \n    /// This will be used to set the FROM address of all messages sent by this node.\n    /// In a conventional multinode system, all nodes will have a unique address \n    /// (which you could store in EEPROM).\n    /// \\param[in] thisAddress The address of this node\n    void setThisAddress(uint8_t thisAddress);\n\n    /// Sends a message to the node(s) with the given address\n    /// RH_BROADCAST_ADDRESS is a valid address which will cause the message\n    /// to be accepted by all RHDatagram nodes within range.\n    /// \\param[in] buf Pointer to the binary message to send\n    /// \\param[in] len Number of octets to send (> 0)\n    /// \\param[in] address The address to send the message to.\n    /// \\return true if the message not too loing fot eh driver, and the message was transmitted.\n    bool sendto(uint8_t* buf, uint8_t len, uint8_t address);\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available for this node, copy it to buf and return true\n    /// The SRC address is placed in *from if present and not NULL.\n    /// The DEST address is placed in *to if present and not NULL.\n    /// If a message is copied, *len is set to the length.\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\param[in] from If present and not NULL, the referenced uint8_t will be set to the FROM address\n    /// \\param[in] to If present and not NULL, the referenced uint8_t will be set to the TO address\n    /// \\param[in] id If present and not NULL, the referenced uint8_t will be set to the ID\n    /// \\param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS\n    /// (not just those addressed to this node).\n    /// \\return true if a valid message was copied to buf\n    bool recvfrom(uint8_t* buf, uint8_t* len, uint8_t* from = NULL, uint8_t* to = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);\n\n    /// Tests whether a new message is available\n    /// from the Driver.\n    /// On most drivers, this will also put the Driver into RHModeRx mode until\n    /// a message is actually received bythe transport, when it will be returned to RHModeIdle.\n    /// This can be called multiple times in a timeout loop.\n    /// \\return true if a new, complete, error-free uncollected message is available to be retreived by recv()\n    bool            available();\n\n    /// Starts the Driver receiver and blocks until a valid received \n    /// message is available.\n    void            waitAvailable();\n\n    /// Blocks until the transmitter \n    /// is no longer transmitting.\n    bool            waitPacketSent();\n\n    /// Blocks until the transmitter is no longer transmitting.\n    /// or until the timeout occuers, whichever happens first\n    /// \\param[in] timeout Maximum time to wait in milliseconds.\n    /// \\return true if the radio completed transmission within the timeout period. False if it timed out.\n    bool            waitPacketSent(uint16_t timeout);\n\n    /// Starts the Driver receiver and blocks until a received message is available or a timeout\n    /// \\param[in] timeout Maximum time to wait in milliseconds.\n    /// \\return true if a message is available\n    bool            waitAvailableTimeout(uint16_t timeout);\n\n    /// Sets the TO header to be sent in all subsequent messages\n    /// \\param[in] to The new TO header value\n    void           setHeaderTo(uint8_t to);\n\n    /// Sets the FROM header to be sent in all subsequent messages\n    /// \\param[in] from The new FROM header value\n    void           setHeaderFrom(uint8_t from);\n\n    /// Sets the ID header to be sent in all subsequent messages\n    /// \\param[in] id The new ID header value\n    void           setHeaderId(uint8_t id);\n\n    /// Sets and clears bits in the FLAGS header to be sent in all subsequent messages\n    /// \\param[in] set bitmask of bits to be set\n    /// \\param[in] clear bitmask of flags to clear\n    void           setHeaderFlags(uint8_t set, uint8_t clear = RH_FLAGS_NONE);\n\n    /// Returns the TO header of the last received message\n    /// \\return The TO header of the most recently received message.\n    uint8_t        headerTo();\n\n    /// Returns the FROM header of the last received message\n    /// \\return The FROM header of the most recently received message.\n    uint8_t        headerFrom();\n\n    /// Returns the ID header of the last received message\n    /// \\return The ID header of the most recently received message.\n    uint8_t        headerId();\n\n    /// Returns the FLAGS header of the last received message\n    /// \\return The FLAGS header of the most recently received message.\n    uint8_t        headerFlags();\n\n    /// Returns the address of this node.\n    /// \\return The address of this node\n    uint8_t         thisAddress();\n\nprotected:\n    /// The Driver we are to use\n    RHGenericDriver&        _driver;\n\n    /// The address of this node\n    uint8_t         _thisAddress;\n};\n\n#endif\n"
  },
  {
    "path": "RHGenericDriver.cpp",
    "content": "// RHGenericDriver.cpp\n//\n// Copyright (C) 2014 Mike McCauley\n// $Id: RHGenericDriver.cpp,v 1.20 2017/01/12 23:58:00 mikem Exp $\n\n#include <RHGenericDriver.h>\n\nRHGenericDriver::RHGenericDriver()\n    :\n    _mode(RHModeInitialising),\n    _thisAddress(RH_BROADCAST_ADDRESS),\n    _txHeaderTo(RH_BROADCAST_ADDRESS),\n    _txHeaderFrom(RH_BROADCAST_ADDRESS),\n    _txHeaderId(0),\n    _txHeaderFlags(0),\n    _rxBad(0),\n    _rxGood(0),\n    _txGood(0),\n    _cad_timeout(0)\n{\n}\n\nbool RHGenericDriver::init()\n{\n    return true;\n}\n\n// Blocks until a valid message is received\nvoid RHGenericDriver::waitAvailable()\n{\n    while (!available())\n\tYIELD;\n}\n\n// Blocks until a valid message is received or timeout expires\n// Return true if there is a message available\n// Works correctly even on millis() rollover\nbool RHGenericDriver::waitAvailableTimeout(uint16_t timeout)\n{\n    unsigned long starttime = millis();\n    while ((millis() - starttime) < timeout)\n    {\n        if (available())\n\t{\n           return true;\n\t}\n\tYIELD;\n    }\n    return false;\n}\n\nbool RHGenericDriver::waitPacketSent()\n{\n    while (_mode == RHModeTx)\n\tYIELD; // Wait for any previous transmit to finish\n    return true;\n}\n\nbool RHGenericDriver::waitPacketSent(uint16_t timeout)\n{\n    unsigned long starttime = millis();\n    while ((millis() - starttime) < timeout)\n    {\n        if (_mode != RHModeTx) // Any previous transmit finished?\n           return true;\n\tYIELD;\n    }\n    return false;\n}\n\n// Wait until no channel activity detected or timeout\nbool RHGenericDriver::waitCAD()\n{\n    if (!_cad_timeout)\n\treturn true;\n\n    // Wait for any channel activity to finish or timeout\n    // Sophisticated DCF function...\n    // DCF : BackoffTime = random() x aSlotTime\n    // 100 - 1000 ms\n    // 10 sec timeout\n    unsigned long t = millis();\n    while (isChannelActive())\n    {\n         if (millis() - t > _cad_timeout) \n\t     return false;\n         delay(random(1, 10) * 100); // Should these values be configurable? Macros?\n    }\n\n    return true;\n}\n\n// subclasses are expected to override if CAD is available for that radio\nbool RHGenericDriver::isChannelActive()\n{\n    return false;\n}\n\nvoid RHGenericDriver::setPromiscuous(bool promiscuous)\n{\n    _promiscuous = promiscuous;\n}\n\nvoid RHGenericDriver::setThisAddress(uint8_t address)\n{\n    _thisAddress = address;\n}\n\nvoid RHGenericDriver::setHeaderTo(uint8_t to)\n{\n    _txHeaderTo = to;\n}\n\nvoid RHGenericDriver::setHeaderFrom(uint8_t from)\n{\n    _txHeaderFrom = from;\n}\n\nvoid RHGenericDriver::setHeaderId(uint8_t id)\n{\n    _txHeaderId = id;\n}\n\nvoid RHGenericDriver::setHeaderFlags(uint8_t set, uint8_t clear)\n{\n    _txHeaderFlags &= ~clear;\n    _txHeaderFlags |= set;\n}\n\nuint8_t RHGenericDriver::headerTo()\n{\n    return _rxHeaderTo;\n}\n\nuint8_t RHGenericDriver::headerFrom()\n{\n    return _rxHeaderFrom;\n}\n\nuint8_t RHGenericDriver::headerId()\n{\n    return _rxHeaderId;\n}\n\nuint8_t RHGenericDriver::headerFlags()\n{\n    return _rxHeaderFlags;\n}\n\nint8_t RHGenericDriver::lastRssi()\n{\n    return _lastRssi;\n}\n\nRHGenericDriver::RHMode  RHGenericDriver::mode()\n{\n    return _mode;\n}\n\nvoid  RHGenericDriver::setMode(RHMode mode)\n{\n    _mode = mode;\n}\n\nbool  RHGenericDriver::sleep()\n{\n    return false;\n}\n\n// Diagnostic help\nvoid RHGenericDriver::printBuffer(const char* prompt, const uint8_t* buf, uint8_t len)\n{\n    uint8_t i;\n\n#ifdef RH_HAVE_SERIAL\n    Serial.println(prompt);\n    for (i = 0; i < len; i++)\n    {\n\tif (i % 16 == 15)\n\t    Serial.println(buf[i], HEX);\n\telse\n\t{\n\t    Serial.print(buf[i], HEX);\n\t    Serial.print(' ');\n\t}\n    }\n    Serial.println(\"\");\n#endif\n}\n\nuint16_t RHGenericDriver::rxBad()\n{\n    return _rxBad;\n}\n\nuint16_t RHGenericDriver::rxGood()\n{\n    return _rxGood;\n}\n\nuint16_t RHGenericDriver::txGood()\n{\n    return _txGood;\n}\n\nvoid RHGenericDriver::setCADTimeout(unsigned long cad_timeout)\n{\n    _cad_timeout = cad_timeout;\n}\n\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(RH_PLATFORM_ATTINY)\n// Tinycore does not have __cxa_pure_virtual, so without this we\n// get linking complaints from the default code generated for pure virtual functions\nextern \"C\" void __cxa_pure_virtual()\n{\n    while (1);\n}\n#endif\n"
  },
  {
    "path": "RHGenericDriver.h",
    "content": "// RHGenericDriver.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2014 Mike McCauley\n// $Id: RHGenericDriver.h,v 1.18 2017/01/12 23:58:00 mikem Exp $\n\n#ifndef RHGenericDriver_h\n#define RHGenericDriver_h\n\n#include <RadioHead.h>\n\n// Defines bits of the FLAGS header reserved for use by the RadioHead library and \n// the flags available for use by applications\n#define RH_FLAGS_RESERVED                 0xf0\n#define RH_FLAGS_APPLICATION_SPECIFIC     0x0f\n#define RH_FLAGS_NONE                     0\n\n// Default timeout for waitCAD() in ms\n#define RH_CAD_DEFAULT_TIMEOUT            10000\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHGenericDriver RHGenericDriver.h <RHGenericDriver.h>\n/// \\brief Abstract base class for a RadioHead driver.\n///\n/// This class defines the functions that must be provided by any RadioHead driver.\n/// Different types of driver will implement all the abstract functions, and will perhaps override \n/// other functions in this subclass, or perhaps add new functions specifically required by that driver.\n/// Do not directly instantiate this class: it is only to be subclassed by driver classes.\n///\n/// Subclasses are expected to implement a half-duplex, unreliable, error checked, unaddressed packet transport.\n/// They are expected to carry a message payload with an appropriate maximum length for the transport hardware\n/// and to also carry unaltered 4 message headers: TO, FROM, ID, FLAGS\n///\n/// \\par Headers\n///\n/// Each message sent and received by a RadioHead driver includes 4 headers:\n/// -TO The node address that the message is being sent to (broadcast RH_BROADCAST_ADDRESS (255) is permitted)\n/// -FROM The node address of the sending node\n/// -ID A message ID, distinct (over short time scales) for each message sent by a particilar node\n/// -FLAGS A bitmask of flags. The most significant 4 bits are reserved for use by RadioHead. The least\n/// significant 4 bits are reserved for applications.\nclass RHGenericDriver\n{\npublic:\n    /// \\brief Defines different operating modes for the transport hardware\n    ///\n    /// These are the different values that can be adopted by the _mode variable and \n    /// returned by the mode() member function,\n    typedef enum\n    {\n\tRHModeInitialising = 0, ///< Transport is initialising. Initial default value until init() is called..\n\tRHModeSleep,            ///< Transport hardware is in low power sleep mode (if supported)\n\tRHModeIdle,             ///< Transport is idle.\n\tRHModeTx,               ///< Transport is in the process of transmitting a message.\n\tRHModeRx,               ///< Transport is in the process of receiving a message.\n\tRHModeCad               ///< Transport is in the process of detecting channel activity (if supported)\n    } RHMode;\n\n    /// Constructor\n    RHGenericDriver();\n\n    /// Initialise the Driver transport hardware and software.\n    /// Make sure the Driver is properly configured before calling init().\n    /// \\return true if initialisation succeeded.\n    virtual bool init();\n\n    /// Tests whether a new message is available\n    /// from the Driver. \n    /// On most drivers, if there is an uncollected received message, and there is no message\n    /// currently bing transmitted, this will also put the Driver into RHModeRx mode until\n    /// a message is actually received by the transport, when it will be returned to RHModeIdle.\n    /// This can be called multiple times in a timeout loop.\n    /// \\return true if a new, complete, error-free uncollected message is available to be retreived by recv().\n    virtual bool available() = 0;\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    virtual bool recv(uint8_t* buf, uint8_t* len) = 0;\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then optionally waits for Channel Activity Detection (CAD) \n    /// to show the channnel is clear (if the radio supports CAD) by calling waitCAD().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is NOT permitted. If the message is too long for the underlying radio technology, send() will\n    /// return false and will not send the message.\n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send (> 0)\n    /// specify the maximum time in ms to wait. If 0 (the default) do not wait for CAD before transmitting.\n    /// \\return true if the message length was valid and it was correctly queued for transmit. Return false\n    /// if CAD was requested and the CAD timeout timed out before clear channel was detected.\n    virtual bool send(const uint8_t* data, uint8_t len) = 0;\n\n    /// Returns the maximum message length \n    /// available in this Driver.\n    /// \\return The maximum legal message length\n    virtual uint8_t maxMessageLength() = 0;\n\n    /// Starts the receiver and blocks until a valid received \n    /// message is available.\n    virtual void            waitAvailable();\n\n    /// Blocks until the transmitter \n    /// is no longer transmitting.\n    virtual bool            waitPacketSent();\n\n    /// Blocks until the transmitter is no longer transmitting.\n    /// or until the timeout occuers, whichever happens first\n    /// \\param[in] timeout Maximum time to wait in milliseconds.\n    /// \\return true if the radio completed transmission within the timeout period. False if it timed out.\n    virtual bool            waitPacketSent(uint16_t timeout);\n\n    /// Starts the receiver and blocks until a received message is available or a timeout\n    /// \\param[in] timeout Maximum time to wait in milliseconds.\n    /// \\return true if a message is available\n    virtual bool            waitAvailableTimeout(uint16_t timeout);\n\n    // Bent G Christensen (bentor@gmail.com), 08/15/2016\n    /// Channel Activity Detection (CAD).\n    /// Blocks until channel activity is finished or CAD timeout occurs.\n    /// Uses the radio's CAD function (if supported) to detect channel activity.\n    /// Implements random delays of 100 to 1000ms while activity is detected and until timeout.\n    /// Caution: the random() function is not seeded. If you want non-deterministic behaviour, consider\n    /// using something like randomSeed(analogRead(A0)); in your sketch.\n    /// Permits the implementation of listen-before-talk mechanism (Collision Avoidance).\n    /// Calls the isChannelActive() member function for the radio (if supported) \n    /// to determine if the channel is active. If the radio does not support isChannelActive(),\n    /// always returns true immediately\n    /// \\return true if the radio-specific CAD (as returned by isChannelActive())\n    /// shows the channel is clear within the timeout period (or the timeout period is 0), else returns false.\n    virtual bool            waitCAD();\n\n    /// Sets the Channel Activity Detection timeout in milliseconds to be used by waitCAD().\n    /// The default is 0, which means do not wait for CAD detection.\n    /// CAD detection depends on support for isChannelActive() by your particular radio.\n    void setCADTimeout(unsigned long cad_timeout);\n\n    /// Determine if the currently selected radio channel is active.\n    /// This is expected to be subclassed by specific radios to implement their Channel Activity Detection\n    /// if supported. If the radio does not support CAD, returns true immediately. If a RadioHead radio \n    /// supports isChannelActive() it will be documented in the radio specific documentation.\n    /// This is called automatically by waitCAD().\n    /// \\return true if the radio-specific CAD (as returned by override of isChannelActive()) shows the\n    /// current radio channel as active, else false. If there is no radio-specific CAD, returns false.\n    virtual bool            isChannelActive();\n\n    /// Sets the address of this node. Defaults to 0xFF. Subclasses or the user may want to change this.\n    /// This will be used to test the adddress in incoming messages. In non-promiscuous mode,\n    /// only messages with a TO header the same as thisAddress or the broadcast addess (0xFF) will be accepted.\n    /// In promiscuous mode, all messages will be accepted regardless of the TO header.\n    /// In a conventional multinode system, all nodes will have a unique address \n    /// (which you could store in EEPROM).\n    /// You would normally set the header FROM address to be the same as thisAddress (though you dont have to, \n    /// allowing the possibilty of address spoofing).\n    /// \\param[in] thisAddress The address of this node.\n    virtual void setThisAddress(uint8_t thisAddress);\n\n    /// Sets the TO header to be sent in all subsequent messages\n    /// \\param[in] to The new TO header value\n    virtual void           setHeaderTo(uint8_t to);\n\n    /// Sets the FROM header to be sent in all subsequent messages\n    /// \\param[in] from The new FROM header value\n    virtual void           setHeaderFrom(uint8_t from);\n\n    /// Sets the ID header to be sent in all subsequent messages\n    /// \\param[in] id The new ID header value\n    virtual void           setHeaderId(uint8_t id);\n\n    /// Sets and clears bits in the FLAGS header to be sent in all subsequent messages\n    /// First it clears he FLAGS according to the clear argument, then sets the flags according to the \n    /// set argument. The default for clear always clears the application specific flags.\n    /// \\param[in] set bitmask of bits to be set. Flags are cleared with the clear mask before being set.\n    /// \\param[in] clear bitmask of flags to clear. Defaults to RH_FLAGS_APPLICATION_SPECIFIC\n    ///            which clears the application specific flags, resulting in new application specific flags\n    ///            identical to the set.\n    virtual void           setHeaderFlags(uint8_t set, uint8_t clear = RH_FLAGS_APPLICATION_SPECIFIC);\n\n    /// Tells the receiver to accept messages with any TO address, not just messages\n    /// addressed to thisAddress or the broadcast address\n    /// \\param[in] promiscuous true if you wish to receive messages with any TO address\n    virtual void           setPromiscuous(bool promiscuous);\n\n    /// Returns the TO header of the last received message\n    /// \\return The TO header\n    virtual uint8_t        headerTo();\n\n    /// Returns the FROM header of the last received message\n    /// \\return The FROM header\n    virtual uint8_t        headerFrom();\n\n    /// Returns the ID header of the last received message\n    /// \\return The ID header\n    virtual uint8_t        headerId();\n\n    /// Returns the FLAGS header of the last received message\n    /// \\return The FLAGS header\n    virtual uint8_t        headerFlags();\n\n    /// Returns the most recent RSSI (Receiver Signal Strength Indicator).\n    /// Usually it is the RSSI of the last received message, which is measured when the preamble is received.\n    /// If you called readRssi() more recently, it will return that more recent value.\n    /// \\return The most recent RSSI measurement in dBm.\n    int8_t        lastRssi();\n\n    /// Returns the operating mode of the library.\n    /// \\return the current mode, one of RF69_MODE_*\n    RHMode          mode();\n\n    /// Sets the operating mode of the transport.\n    void            setMode(RHMode mode);\n\n    /// Sets the transport hardware into low-power sleep mode\n    /// (if supported). May be overridden by specific drivers to initialte sleep mode.\n    /// If successful, the transport will stay in sleep mode until woken by \n    /// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc)\n    /// \\return true if sleep mode is supported by transport hardware and the RadioHead driver, and if sleep mode\n    ///         was successfully entered. If sleep mode is not suported, return false.\n    virtual bool    sleep();\n\n    /// Prints a data buffer in HEX.\n    /// For diagnostic use\n    /// \\param[in] prompt string to preface the print\n    /// \\param[in] buf Location of the buffer to print\n    /// \\param[in] len Length of the buffer in octets.\n    static void    printBuffer(const char* prompt, const uint8_t* buf, uint8_t len);\n\n    /// Returns the count of the number of bad received packets (ie packets with bad lengths, checksum etc)\n    /// which were rejected and not delivered to the application.\n    /// Caution: not all drivers can correctly report this count. Some underlying hardware only report\n    /// good packets.\n    /// \\return The number of bad packets received.\n    uint16_t       rxBad();\n\n    /// Returns the count of the number of \n    /// good received packets\n    /// \\return The number of good packets received.\n    uint16_t       rxGood();\n\n    /// Returns the count of the number of \n    /// packets successfully transmitted (though not necessarily received by the destination)\n    /// \\return The number of packets successfully transmitted\n    uint16_t       txGood();\n\nprotected:\n\n    /// The current transport operating mode\n    volatile RHMode     _mode;\n\n    /// This node id\n    uint8_t             _thisAddress;\n    \n    /// Whether the transport is in promiscuous mode\n    bool                _promiscuous;\n\n    /// TO header in the last received mesasge\n    volatile uint8_t    _rxHeaderTo;\n\n    /// FROM header in the last received mesasge\n    volatile uint8_t    _rxHeaderFrom;\n\n    /// ID header in the last received mesasge\n    volatile uint8_t    _rxHeaderId;\n\n    /// FLAGS header in the last received mesasge\n    volatile uint8_t    _rxHeaderFlags;\n\n    /// TO header to send in all messages\n    uint8_t             _txHeaderTo;\n\n    /// FROM header to send in all messages\n    uint8_t             _txHeaderFrom;\n\n    /// ID header to send in all messages\n    uint8_t             _txHeaderId;\n\n    /// FLAGS header to send in all messages\n    uint8_t             _txHeaderFlags;\n\n    /// The value of the last received RSSI value, in some transport specific units\n    volatile int8_t     _lastRssi;\n\n    /// Count of the number of bad messages (eg bad checksum etc) received\n    volatile uint16_t   _rxBad;\n\n    /// Count of the number of successfully transmitted messaged\n    volatile uint16_t   _rxGood;\n\n    /// Count of the number of bad messages (correct checksum etc) received\n    volatile uint16_t   _txGood;\n\n    /// Channel activity detected\n    volatile bool       _cad;\n    unsigned int        _cad_timeout;\n    \nprivate:\n\n};\n\n\n#endif \n"
  },
  {
    "path": "RHGenericSPI.cpp",
    "content": "// RHGenericSPI.cpp\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// Contributed by Joanna Rutkowska\n// $Id: RHGenericSPI.cpp,v 1.2 2014/04/12 05:26:05 mikem Exp $\n\n#include <RHGenericSPI.h>\n\nRHGenericSPI::RHGenericSPI(Frequency frequency, BitOrder bitOrder, DataMode dataMode)\n    :\n    _frequency(frequency),\n    _bitOrder(bitOrder),\n    _dataMode(dataMode)\n{\n}\n\nvoid RHGenericSPI::setBitOrder(BitOrder bitOrder)\n{\n    _bitOrder = bitOrder;\n}\n\nvoid RHGenericSPI::setDataMode(DataMode dataMode)\n{\n    _dataMode = dataMode; \n}\n\nvoid RHGenericSPI::setFrequency(Frequency frequency)\n{\n    _frequency = frequency;\n}\n\n"
  },
  {
    "path": "RHGenericSPI.h",
    "content": "// RHGenericSPI.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// Contributed by Joanna Rutkowska\n// $Id: RHGenericSPI.h,v 1.7 2014/04/14 08:37:11 mikem Exp $\n\n#ifndef RHGenericSPI_h\n#define RHGenericSPI_h\n\n#include <RadioHead.h>\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHGenericSPI RHGenericSPI.h <RHGenericSPI.h>\n/// \\brief Base class for SPI interfaces\n///\n/// This generic abstract class is used to encapsulate hardware or software SPI interfaces for \n/// a variety of platforms.\n/// The intention is so that driver classes can be configured to use hardware or software SPI\n/// without changing the main code.\n///\n/// You must provide a subclass of this class to driver constructors that require SPI.\n/// A concrete subclass that encapsualates the standard Arduino hardware SPI and a bit-banged\n/// software implementation is included.\n///\n/// Do not directly use this class: it must be subclassed and the following abstract functions at least \n/// must be implmented:\n/// - begin()\n/// - end() \n/// - transfer()\nclass RHGenericSPI \n{\npublic:\n\n    /// \\brief Defines constants for different SPI modes\n    ///\n    /// Defines constants for different SPI modes\n    /// that can be passed to the constructor or setMode()\n    /// We need to define these in a device and platform independent way, because the\n    /// SPI implementation is different on each platform.\n    typedef enum\n    {\n\tDataMode0 = 0, ///< SPI Mode 0: CPOL = 0, CPHA = 0\n\tDataMode1,     ///< SPI Mode 1: CPOL = 0, CPHA = 1\n\tDataMode2,     ///< SPI Mode 2: CPOL = 1, CPHA = 0\n\tDataMode3,     ///< SPI Mode 3: CPOL = 1, CPHA = 1\n    } DataMode;\n\n    /// \\brief Defines constants for different SPI bus frequencies\n    ///\n    /// Defines constants for different SPI bus frequencies\n    /// that can be passed to setFrequency().\n    /// The frequency you get may not be exactly the one according to the name.\n    /// We need to define these in a device and platform independent way, because the\n    /// SPI implementation is different on each platform.\n    typedef enum\n    {\n\tFrequency1MHz = 0,  ///< SPI bus frequency close to 1MHz\n\tFrequency2MHz,      ///< SPI bus frequency close to 2MHz\n\tFrequency4MHz,      ///< SPI bus frequency close to 4MHz\n\tFrequency8MHz,      ///< SPI bus frequency close to 8MHz\n\tFrequency16MHz      ///< SPI bus frequency close to 16MHz\n    } Frequency;\n\n    /// \\brief Defines constants for different SPI endianness\n    ///\n    /// Defines constants for different SPI endianness\n    /// that can be passed to setBitOrder()\n    /// We need to define these in a device and platform independent way, because the\n    /// SPI implementation is different on each platform.\n    typedef enum\n    {\n\tBitOrderMSBFirst = 0,  ///< SPI MSB first\n\tBitOrderLSBFirst,      ///< SPI LSB first\n    } BitOrder;\n\n    /// Constructor\n    /// Creates an instance of an abstract SPI interface.\n    /// Do not use this contructor directly: you must instead use on of the concrete subclasses provided \n    /// such as RHHardwareSPI or RHSoftwareSPI\n    /// \\param[in] frequency One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency\n    /// is mapped to the closest available bus frequency on the platform.\n    /// \\param[in] bitOrder Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or \n    /// RHGenericSPI::BitOrderLSBFirst.\n    /// \\param[in] dataMode Selects the SPI bus data mode. One of RHGenericSPI::DataMode\n    RHGenericSPI(Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);\n\n    /// Transfer a single octet to and from the SPI interface\n    /// \\param[in] data The octet to send\n    /// \\return The octet read from SPI while the data octet was sent\n    virtual uint8_t transfer(uint8_t data) = 0;\n\n    /// SPI Configuration methods\n    /// Enable SPI interrupts (if supported)\n    /// This can be used in an SPI slave to indicate when an SPI message has been received\n    virtual void attachInterrupt() {};\n\n    /// Disable SPI interrupts (if supported)\n    /// This can be used to diable the SPI interrupt in slaves where that is supported.\n    virtual void detachInterrupt() {};\n\n    /// Initialise the SPI library.\n    /// Call this after configuring and before using the SPI library\n    virtual void begin() = 0;\n\n    /// Disables the SPI bus (leaving pin modes unchanged). \n    /// Call this after you have finished using the SPI interface\n    virtual void end() = 0;\n\n    /// Sets the bit order the SPI interface will use\n    /// Sets the order of the bits shifted out of and into the SPI bus, either \n    /// LSBFIRST (least-significant bit first) or MSBFIRST (most-significant bit first). \n    /// \\param[in] bitOrder Bit order to be used: one of RHGenericSPI::BitOrder\n    virtual void setBitOrder(BitOrder bitOrder);\n\n    /// Sets the SPI data mode: that is, clock polarity and phase. \n    /// See the Wikipedia article on SPI for details. \n    /// \\param[in] dataMode The mode to use: one of RHGenericSPI::DataMode\n    virtual void setDataMode(DataMode dataMode);\n\n    /// Sets the SPI clock divider relative to the system clock. \n    /// On AVR based boards, the dividers available are 2, 4, 8, 16, 32, 64 or 128. \n    /// The default setting is SPI_CLOCK_DIV4, which sets the SPI clock to one-quarter \n    /// the frequency of the system clock (4 Mhz for the boards at 16 MHz). \n    /// \\param[in] frequency The data rate to use: one of RHGenericSPI::Frequency\n    virtual void setFrequency(Frequency frequency);\n\nprotected:\n    /// The configure SPI Bus frequency, one of RHGenericSPI::Frequency\n    Frequency    _frequency; // Bus frequency, one of RHGenericSPI::Frequency\n\n    /// Bit order, one of RHGenericSPI::BitOrder\n    BitOrder     _bitOrder;  \n\n    /// SPI bus mode, one of RHGenericSPI::DataMode\n    DataMode     _dataMode;  \n};\n#endif\n"
  },
  {
    "path": "RHHardwareSPI.cpp",
    "content": "// RHHardwareSPI.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// Contributed by Joanna Rutkowska\n// $Id: RHHardwareSPI.cpp,v 1.16 2016/07/07 00:02:53 mikem Exp $\n\n#include <RHHardwareSPI.h>\n\n// Declare a single default instance of the hardware SPI interface class\nRHHardwareSPI hardware_spi;\n\n#ifdef RH_HAVE_HARDWARE_SPI\n\n#if (RH_PLATFORM == RH_PLATFORM_STM32) // Maple etc\n// Declare an SPI interface to use\nHardwareSPI SPI(1);\n#elif (RH_PLATFORM == RH_PLATFORM_STM32STD) // STM32F4 Discovery\n// Declare an SPI interface to use\nHardwareSPI SPI(1);\n#endif\n\n// Arduino Due has default SPI pins on central SPI headers, and not on 10, 11, 12, 13\n// as per other Arduinos\n// http://21stdigitalhome.blogspot.com.au/2013/02/arduino-due-hardware-spi.html\n#if defined (__arm__) && !defined(CORE_TEENSY) && !defined(SPI_CLOCK_DIV16)\n // Arduino Due in 1.5.5 has no definitions for SPI dividers\n // SPI clock divider is based on MCK of 84MHz  \n #define SPI_CLOCK_DIV16 (VARIANT_MCK/84000000) // 1MHz\n #define SPI_CLOCK_DIV8  (VARIANT_MCK/42000000) // 2MHz\n #define SPI_CLOCK_DIV4  (VARIANT_MCK/21000000) // 4MHz\n #define SPI_CLOCK_DIV2  (VARIANT_MCK/10500000) // 8MHz\n #define SPI_CLOCK_DIV1  (VARIANT_MCK/5250000)  // 16MHz\n#endif\n\nRHHardwareSPI::RHHardwareSPI(Frequency frequency, BitOrder bitOrder, DataMode dataMode)\n    :\n    RHGenericSPI(frequency, bitOrder, dataMode)\n{\n}\n\nuint8_t RHHardwareSPI::transfer(uint8_t data) \n{\n    return SPI.transfer(data);\n}\n\nvoid RHHardwareSPI::attachInterrupt() \n{\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO)\n    SPI.attachInterrupt();\n#endif\n}\n\nvoid RHHardwareSPI::detachInterrupt() \n{\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO)\n    SPI.detachInterrupt();\n#endif\n}\n    \nvoid RHHardwareSPI::begin() \n{\n    // Sigh: there are no common symbols for some of these SPI options across all platforms\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) || (RH_PLATFORM == RH_PLATFORM_UNO32) || (RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE)\n    uint8_t dataMode;\n    if (_dataMode == DataMode0)\n\tdataMode = SPI_MODE0;\n    else if (_dataMode == DataMode1)\n\tdataMode = SPI_MODE1;\n    else if (_dataMode == DataMode2)\n\tdataMode = SPI_MODE2;\n    else if (_dataMode == DataMode3)\n\tdataMode = SPI_MODE3;\n    else\n\tdataMode = SPI_MODE0;\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(__arm__) && defined(CORE_TEENSY)\n    // Temporary work-around due to problem where avr_emulation.h does not work properly for the setDataMode() cal\n    SPCR &= ~SPI_MODE_MASK;\n#else\n #if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && defined(ARDUINO_ARCH_SAMD)\n    // Zero requires begin() before anything else :-)\n    SPI.begin();\n #endif\n\n    SPI.setDataMode(dataMode);\n#endif\n\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && (defined(ARDUINO_SAM_DUE) || defined(ARDUINO_ARCH_SAMD))\n    // Arduino Due in 1.5.5 has its own BitOrder :-(\n    // So too does Arduino Zero\n    ::BitOrder bitOrder;\n#else\n    uint8_t bitOrder;\n#endif\n    if (_bitOrder == BitOrderLSBFirst)\n\tbitOrder = LSBFIRST;\n    else\n\tbitOrder = MSBFIRST;\n    SPI.setBitOrder(bitOrder);\n    uint8_t divider;\n    switch (_frequency)\n    {\n\tcase Frequency1MHz:\n\tdefault:\n#if F_CPU == 8000000\n\t    divider = SPI_CLOCK_DIV8;\n#else\n\t    divider = SPI_CLOCK_DIV16;\n#endif\n\t    break;\n\n\tcase Frequency2MHz:\n#if F_CPU == 8000000\n\t    divider = SPI_CLOCK_DIV4;\n#else\n\t    divider = SPI_CLOCK_DIV8;\n#endif\n\t    break;\n\n\tcase Frequency4MHz:\n#if F_CPU == 8000000\n\t    divider = SPI_CLOCK_DIV2;\n#else\n\t    divider = SPI_CLOCK_DIV4;\n#endif\n\t    break;\n\n\tcase Frequency8MHz:\n\t    divider = SPI_CLOCK_DIV2; // 4MHz on an 8MHz Arduino\n\t    break;\n\n\tcase Frequency16MHz:\n\t    divider = SPI_CLOCK_DIV2; // Not really 16MHz, only 8MHz. 4MHz on an 8MHz Arduino\n\t    break;\n\n    }\n\n    SPI.setClockDivider(divider);\n    SPI.begin();\n    // Teensy requires it to be set _after_ begin()\n    SPI.setClockDivider(divider);\n\n#elif (RH_PLATFORM == RH_PLATFORM_STM32) // Maple etc\n    spi_mode dataMode;\n    // Hmmm, if we do this as a switch, GCC on maple gets v confused!\n    if (_dataMode == DataMode0)\n\tdataMode = SPI_MODE_0;\n    else if (_dataMode == DataMode1)\n\tdataMode = SPI_MODE_1;\n    else if (_dataMode == DataMode2)\n\tdataMode = SPI_MODE_2;\n    else if (_dataMode == DataMode3)\n\tdataMode = SPI_MODE_3;\n    else\n\tdataMode = SPI_MODE_0;\n\n    uint32 bitOrder;\n    if (_bitOrder == BitOrderLSBFirst)\n\tbitOrder = LSBFIRST;\n    else\n\tbitOrder = MSBFIRST;\n\n    SPIFrequency frequency; // Yes, I know these are not exact equivalents.\n    switch (_frequency)\n    {\n\tcase Frequency1MHz:\n\tdefault:\n\t    frequency = SPI_1_125MHZ;\n\t    break;\n\n\tcase Frequency2MHz:\n\t    frequency = SPI_2_25MHZ;\n\t    break;\n\n\tcase Frequency4MHz:\n\t    frequency = SPI_4_5MHZ;\n\t    break;\n\n\tcase Frequency8MHz:\n\t    frequency = SPI_9MHZ;\n\t    break;\n\n\tcase Frequency16MHz:\n\t    frequency = SPI_18MHZ;\n\t    break;\n\n    }\n    SPI.begin(frequency, bitOrder, dataMode);\n\n#elif (RH_PLATFORM == RH_PLATFORM_STM32STD) // STM32F4 discovery\n    uint8_t dataMode;\n    if (_dataMode == DataMode0)\n\tdataMode = SPI_MODE0;\n    else if (_dataMode == DataMode1)\n\tdataMode = SPI_MODE1;\n    else if (_dataMode == DataMode2)\n\tdataMode = SPI_MODE2;\n    else if (_dataMode == DataMode3)\n\tdataMode = SPI_MODE3;\n    else\n\tdataMode = SPI_MODE0;\n\n    uint32_t bitOrder;\n    if (_bitOrder == BitOrderLSBFirst)\n\tbitOrder = LSBFIRST;\n    else\n\tbitOrder = MSBFIRST;\n\n    SPIFrequency frequency; // Yes, I know these are not exact equivalents.\n    switch (_frequency)\n    {\n\tcase Frequency1MHz:\n\tdefault:\n\t    frequency = SPI_1_3125MHZ;\n\t    break;\n\n\tcase Frequency2MHz:\n\t    frequency = SPI_2_625MHZ;\n\t    break;\n\n\tcase Frequency4MHz:\n\t    frequency = SPI_5_25MHZ;\n\t    break;\n\n\tcase Frequency8MHz:\n\t    frequency = SPI_10_5MHZ;\n\t    break;\n\n\tcase Frequency16MHz:\n\t    frequency = SPI_21_0MHZ;\n\t    break;\n\n    }\n    SPI.begin(frequency, bitOrder, dataMode);\n\n#elif (RH_PLATFORM == RH_PLATFORM_STM32F2) // Photon\n    Serial.println(\"HERE\");\n    uint8_t dataMode;\n    if (_dataMode == DataMode0)\n\tdataMode = SPI_MODE0;\n    else if (_dataMode == DataMode1)\n\tdataMode = SPI_MODE1;\n    else if (_dataMode == DataMode2)\n\tdataMode = SPI_MODE2;\n    else if (_dataMode == DataMode3)\n\tdataMode = SPI_MODE3;\n    else\n\tdataMode = SPI_MODE0;\n    SPI.setDataMode(dataMode);\n    if (_bitOrder == BitOrderLSBFirst)\n\tSPI.setBitOrder(LSBFIRST);\n    else\n\tSPI.setBitOrder(MSBFIRST);\n\n    switch (_frequency)\n    {\n\tcase Frequency1MHz:\n\tdefault:\n\t    SPI.setClockSpeed(1, MHZ);\n\t    break;\n\n\tcase Frequency2MHz:\n\t    SPI.setClockSpeed(2, MHZ);\n\t    break;\n\n\tcase Frequency4MHz:\n\t    SPI.setClockSpeed(4, MHZ);\n\t    break;\n\n\tcase Frequency8MHz:\n\t    SPI.setClockSpeed(8, MHZ);\n\t    break;\n\n\tcase Frequency16MHz:\n\t    SPI.setClockSpeed(16, MHZ);\n\t    break;\n    }\n\n//      SPI.setClockDivider(SPI_CLOCK_DIV4);  // 72MHz / 4MHz = 18MHz\n//      SPI.setClockSpeed(1, MHZ);\n      SPI.begin();\n\n#elif (RH_PLATFORM == RH_PLATFORM_ESP8266)\n     // Requires SPI driver for ESP8266 from https://github.com/esp8266/Arduino/tree/master/libraries/SPI\n     // Which ppears to be in Arduino Board Manager ESP8266 Community version 2.1.0\n     // Contributed by David Skinner\n     // begin comes first \n     SPI.begin();\n\n     // datamode\n     switch ( _dataMode )\n     { \n\t case DataMode1:\n\t     SPI.setDataMode ( SPI_MODE1 );\n\t     break;\n\t case DataMode2:\n\t     SPI.setDataMode ( SPI_MODE2 );\n\t     break;\n\t case DataMode3:\n\t     SPI.setDataMode ( SPI_MODE3 );\n\t     break;\n\t case DataMode0:\n\t default:\n\t     SPI.setDataMode ( SPI_MODE0 );\n\t     break;\n     }\n\n     // bitorder\n     SPI.setBitOrder(_bitOrder == BitOrderLSBFirst ? LSBFIRST : MSBFIRST);\n\n     // frequency (this sets the divider)\n     switch (_frequency)\n     {\n\t case Frequency1MHz:\n\t default:\n\t     SPI.setFrequency(1000000);\n\t     break;\n\t case Frequency2MHz:\n\t     SPI.setFrequency(2000000);\n\t     break;\n\t case Frequency4MHz:\n\t     SPI.setFrequency(4000000);\n\t     break;\n\t case Frequency8MHz:\n\t     SPI.setFrequency(8000000);\n\t     break;\n\t case Frequency16MHz:\n\t     SPI.setFrequency(16000000);\n\t     break;\n     }\n\n#elif (RH_PLATFORM == RH_PLATFORM_RASPI) // Raspberry PI\n  uint8_t dataMode;\n  if (_dataMode == DataMode0)\n    dataMode = BCM2835_SPI_MODE0;\n  else if (_dataMode == DataMode1)\n    dataMode = BCM2835_SPI_MODE1;\n  else if (_dataMode == DataMode2)\n    dataMode = BCM2835_SPI_MODE2;\n  else if (_dataMode == DataMode3)\n    dataMode = BCM2835_SPI_MODE3;\n\n  uint8_t bitOrder;\n  if (_bitOrder == BitOrderLSBFirst)\n    bitOrder = BCM2835_SPI_BIT_ORDER_LSBFIRST;\n  else\n    bitOrder = BCM2835_SPI_BIT_ORDER_MSBFIRST;\n\n  uint32_t divider;\n  switch (_frequency)\n  {\n    case Frequency1MHz:\n    default:\n      divider = BCM2835_SPI_CLOCK_DIVIDER_256;\n      break;\n    case Frequency2MHz:\n      divider = BCM2835_SPI_CLOCK_DIVIDER_128;\n      break;\n    case Frequency4MHz:\n      divider = BCM2835_SPI_CLOCK_DIVIDER_64;\n      break;\n    case Frequency8MHz:\n      divider = BCM2835_SPI_CLOCK_DIVIDER_32;\n      break;\n    case Frequency16MHz:\n      divider = BCM2835_SPI_CLOCK_DIVIDER_16;\n      break;\n  }\n  SPI.begin(divider, bitOrder, dataMode);\n#else\n #warning RHHardwareSPI does not support this platform yet. Consider adding it and contributing a patch.\n#endif\n}\n\nvoid RHHardwareSPI::end() \n{\n    return SPI.end();\n}\n\n#endif\n\n"
  },
  {
    "path": "RHHardwareSPI.h",
    "content": "// RHHardwareSPI.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// Contributed by Joanna Rutkowska\n// $Id: RHHardwareSPI.h,v 1.10 2017/01/12 23:58:00 mikem Exp $\n\n#ifndef RHHardwareSPI_h\n#define RHHardwareSPI_h\n\n#include <RHGenericSPI.h>\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHHardwareSPI RHHardwareSPI.h <RHHardwareSPI.h>\n/// \\brief Encapsulate a hardware SPI bus interface\n///\n/// This concrete subclass of GenericSPIClass encapsulates the standard Arduino hardware and other\n/// hardware SPI interfaces.\nclass RHHardwareSPI : public RHGenericSPI\n{\n#ifdef RH_HAVE_HARDWARE_SPI\npublic:\n    /// Constructor\n    /// Creates an instance of a hardware SPI interface, using whatever SPI hardware is available on\n    /// your processor platform. On Arduino and Uno32, uses SPI. On Maple, uses HardwareSPI.\n    /// \\param[in] frequency One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency\n    /// is mapped to the closest available bus frequency on the platform.\n    /// \\param[in] bitOrder Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or \n    /// RHGenericSPI::BitOrderLSBFirst.\n    /// \\param[in] dataMode Selects the SPI bus data mode. One of RHGenericSPI::DataMode\n    RHHardwareSPI(Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);\n\n    /// Transfer a single octet to and from the SPI interface\n    /// \\param[in] data The octet to send\n    /// \\return The octet read from SPI while the data octet was sent\n    uint8_t transfer(uint8_t data);\n\n    // SPI Configuration methods\n    /// Enable SPI interrupts\n    /// This can be used in an SPI slave to indicate when an SPI message has been received\n    /// It will cause the SPI_STC_vect interrupt vectr to be executed\n    void attachInterrupt();\n\n    /// Disable SPI interrupts\n    /// This can be used to diable the SPI interrupt in slaves where that is supported.\n    void detachInterrupt();\n    \n    /// Initialise the SPI library\n    /// Call this after configuring the SPI interface and before using it to transfer data.\n    /// Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high. \n    void begin();\n\n    /// Disables the SPI bus (leaving pin modes unchanged). \n    /// Call this after you have finished using the SPI interface.\n    void end();\n#else\n    // not supported on ATTiny etc\n    uint8_t transfer(uint8_t /*data*/) {return 0;}\n    void begin(){}\n    void end(){}\n\n#endif\n};\n\n// Built in default instance\nextern RHHardwareSPI hardware_spi;\n\n#endif\n"
  },
  {
    "path": "RHMesh.cpp",
    "content": "// RHMesh.cpp\n//\n// Define addressed datagram\n// \n// Part of the Arduino RH library for operating with HopeRF RH compatible transceivers \n// (see http://www.hoperf.com)\n// RHDatagram will be received only by the addressed node or all nodes within range if the \n// to address is RH_BROADCAST_ADDRESS\n//\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// $Id: RHMesh.cpp,v 1.9 2015/08/13 02:45:47 mikem Exp $\n\n#include <RHMesh.h>\n\nuint8_t RHMesh::_tmpMessage[RH_ROUTER_MAX_MESSAGE_LEN];\n\n////////////////////////////////////////////////////////////////////\n// Constructors\nRHMesh::RHMesh(RHGenericDriver& driver, uint8_t thisAddress) \n    : RHRouter(driver, thisAddress)\n{\n}\n\n////////////////////////////////////////////////////////////////////\n// Public methods\n\n////////////////////////////////////////////////////////////////////\n// Discovers a route to the destination (if necessary), sends and \n// waits for delivery to the next hop (but not for delivery to the final destination)\nuint8_t RHMesh::sendtoWait(uint8_t* buf, uint8_t len, uint8_t address, uint8_t flags)\n{\n    if (len > RH_MESH_MAX_MESSAGE_LEN)\n\treturn RH_ROUTER_ERROR_INVALID_LENGTH;\n\n    if (address != RH_BROADCAST_ADDRESS)\n    {\n\tRoutingTableEntry* route = getRouteTo(address);\n\tif (!route && !doArp(address))\n\t    return RH_ROUTER_ERROR_NO_ROUTE;\n    }\n\n    // Now have a route. Contruct an application layer message and send it via that route\n    MeshApplicationMessage* a = (MeshApplicationMessage*)&_tmpMessage;\n    a->header.msgType = RH_MESH_MESSAGE_TYPE_APPLICATION;\n    memcpy(a->data, buf, len);\n    return RHRouter::sendtoWait(_tmpMessage, sizeof(RHMesh::MeshMessageHeader) + len, address, flags);\n}\n\n////////////////////////////////////////////////////////////////////\nbool RHMesh::doArp(uint8_t address)\n{\n    // Need to discover a route\n    // Broadcast a route discovery message with nothing in it\n    MeshRouteDiscoveryMessage* p = (MeshRouteDiscoveryMessage*)&_tmpMessage;\n    p->header.msgType = RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST;\n    p->destlen = 1; \n    p->dest = address; // Who we are looking for\n    uint8_t error = RHRouter::sendtoWait((uint8_t*)p, sizeof(RHMesh::MeshMessageHeader) + 2, RH_BROADCAST_ADDRESS);\n    if (error !=  RH_ROUTER_ERROR_NONE)\n\treturn false;\n    \n    // Wait for a reply, which will be unicast back to us\n    // It will contain the complete route to the destination\n    uint8_t messageLen = sizeof(_tmpMessage);\n    // FIXME: timeout should be configurable\n    unsigned long starttime = millis();\n    int32_t timeLeft;\n    while ((timeLeft = RH_MESH_ARP_TIMEOUT - (millis() - starttime)) > 0)\n    {\n\tif (waitAvailableTimeout(timeLeft))\n\t{\n\t    if (RHRouter::recvfromAck(_tmpMessage, &messageLen))\n\t    {\n\t\tif (   messageLen > 1\n\t\t       && p->header.msgType == RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE)\n\t\t{\n\t\t    // Got a reply, now add the next hop to the dest to the routing table\n\t\t    // The first hop taken is the first octet\n\t\t    addRouteTo(address, headerFrom());\n\t\t    return true;\n\t\t}\n\t    }\n\t}\n\tYIELD;\n    }\n    return false;\n}\n\n////////////////////////////////////////////////////////////////////\n// Called by RHRouter::recvfromAck whenever a message goes past\nvoid RHMesh::peekAtMessage(RoutedMessage* message, uint8_t messageLen)\n{\n    MeshMessageHeader* m = (MeshMessageHeader*)message->data;\n    if (   messageLen > 1 \n\t&& m->msgType == RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE)\n    {\n\t// This is a unicast RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE messages \n\t// being routed back to the originator here. Want to scrape some routing data out of the response\n\t// We can find the routes to all the nodes between here and the responding node\n\tMeshRouteDiscoveryMessage* d = (MeshRouteDiscoveryMessage*)message->data;\n\taddRouteTo(d->dest, headerFrom());\n\tuint8_t numRoutes = messageLen - sizeof(RoutedMessageHeader) - sizeof(MeshMessageHeader) - 2;\n\tuint8_t i;\n\t// Find us in the list of nodes that were traversed to get to the responding node\n\tfor (i = 0; i < numRoutes; i++)\n\t    if (d->route[i] == _thisAddress)\n\t\tbreak;\n\ti++;\n\twhile (i++ < numRoutes)\n\t    addRouteTo(d->route[i], headerFrom());\n    }\n    else if (   messageLen > 1 \n\t     && m->msgType == RH_MESH_MESSAGE_TYPE_ROUTE_FAILURE)\n    {\n\tMeshRouteFailureMessage* d = (MeshRouteFailureMessage*)message->data;\n\tdeleteRouteTo(d->dest);\n    }\n}\n\n////////////////////////////////////////////////////////////////////\n// This is called when a message is to be delivered to the next hop\nuint8_t RHMesh::route(RoutedMessage* message, uint8_t messageLen)\n{\n    uint8_t from = headerFrom(); // Might get clobbered during call to superclass route()\n    uint8_t ret = RHRouter::route(message, messageLen);\n    if (   ret == RH_ROUTER_ERROR_NO_ROUTE\n\t|| ret == RH_ROUTER_ERROR_UNABLE_TO_DELIVER)\n    {\n\t// Cant deliver to the next hop. Delete the route\n\tdeleteRouteTo(message->header.dest);\n\tif (message->header.source != _thisAddress)\n\t{\n\t    // This is being proxied, so tell the originator about it\n\t    MeshRouteFailureMessage* p = (MeshRouteFailureMessage*)&_tmpMessage;\n\t    p->header.msgType = RH_MESH_MESSAGE_TYPE_ROUTE_FAILURE;\n\t    p->dest = message->header.dest; // Who you were trying to deliver to\n\t    // Make sure there is a route back towards whoever sent the original message\n\t    addRouteTo(message->header.source, from);\n\t    ret = RHRouter::sendtoWait((uint8_t*)p, sizeof(RHMesh::MeshMessageHeader) + 1, message->header.source);\n\t}\n    }\n    return ret;\n}\n\n////////////////////////////////////////////////////////////////////\n// Subclasses may want to override\nbool RHMesh::isPhysicalAddress(uint8_t* address, uint8_t addresslen)\n{\n    // Can only handle physical addresses 1 octet long, which is the physical node address\n    return addresslen == 1 && address[0] == _thisAddress;\n}\n\n////////////////////////////////////////////////////////////////////\nbool RHMesh::recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* source, uint8_t* dest, uint8_t* id, uint8_t* flags)\n{     \n    uint8_t tmpMessageLen = sizeof(_tmpMessage);\n    uint8_t _source;\n    uint8_t _dest;\n    uint8_t _id;\n    uint8_t _flags;\n    if (RHRouter::recvfromAck(_tmpMessage, &tmpMessageLen, &_source, &_dest, &_id, &_flags))\n    {\n\tMeshMessageHeader* p = (MeshMessageHeader*)&_tmpMessage;\n\n\tif (   tmpMessageLen >= 1 \n\t    && p->msgType == RH_MESH_MESSAGE_TYPE_APPLICATION)\n\t{\n\t    MeshApplicationMessage* a = (MeshApplicationMessage*)p;\n\t    // Handle application layer messages, presumably for our caller\n\t    if (source) *source = _source;\n\t    if (dest)   *dest   = _dest;\n\t    if (id)     *id     = _id;\n\t    if (flags)  *flags  = _flags;\n\t    uint8_t msgLen = tmpMessageLen - sizeof(MeshMessageHeader);\n\t    if (*len > msgLen)\n\t\t*len = msgLen;\n\t    memcpy(buf, a->data, *len);\n\t    \n\t    return true;\n\t}\n\telse if (   _dest == RH_BROADCAST_ADDRESS \n\t\t && tmpMessageLen > 1 \n\t\t && p->msgType == RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST)\n\t{\n\t    MeshRouteDiscoveryMessage* d = (MeshRouteDiscoveryMessage*)p;\n\t    // Handle Route discovery requests\n\t    // Message is an array of node addresses the route request has already passed through\n\t    // If it originally came from us, ignore it\n\t    if (_source == _thisAddress)\n\t\treturn false;\n\t    \n\t    uint8_t numRoutes = tmpMessageLen - sizeof(MeshMessageHeader) - 2;\n\t    uint8_t i;\n\t    // Are we already mentioned?\n\t    for (i = 0; i < numRoutes; i++)\n\t\tif (d->route[i] == _thisAddress)\n\t\t    return false; // Already been through us. Discard\n\t    \n\t    // Hasnt been past us yet, record routes back to the earlier nodes\n\t    addRouteTo(_source, headerFrom()); // The originator\n\t    for (i = 0; i < numRoutes; i++)\n\t\taddRouteTo(d->route[i], headerFrom());\n\t    if (isPhysicalAddress(&d->dest, d->destlen))\n\t    {\n\t\t// This route discovery is for us. Unicast the whole route back to the originator\n\t\t// as a RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE\n\t\t// We are certain to have a route there, because we just got it\n\t\td->header.msgType = RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE;\n\t\tRHRouter::sendtoWait((uint8_t*)d, tmpMessageLen, _source);\n\t    }\n\t    else if (i < _max_hops)\n\t    {\n\t\t// Its for someone else, rebroadcast it, after adding ourselves to the list\n\t\td->route[numRoutes] = _thisAddress;\n\t\ttmpMessageLen++;\n\t\t// Have to impersonate the source\n\t\t// REVISIT: if this fails what can we do?\n\t\tRHRouter::sendtoFromSourceWait(_tmpMessage, tmpMessageLen, RH_BROADCAST_ADDRESS, _source);\n\t    }\n\t}\n    }\n    return false;\n}\n\n////////////////////////////////////////////////////////////////////\nbool RHMesh::recvfromAckTimeout(uint8_t* buf, uint8_t* len, uint16_t timeout, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags)\n{  \n    unsigned long starttime = millis();\n    int32_t timeLeft;\n    while ((timeLeft = timeout - (millis() - starttime)) > 0)\n    {\n\tif (waitAvailableTimeout(timeLeft))\n\t{\n\t    if (recvfromAck(buf, len, from, to, id, flags))\n\t\treturn true;\n\t    YIELD;\n\t}\n    }\n    return false;\n}\n\n\n\n"
  },
  {
    "path": "RHMesh.h",
    "content": "// RHMesh.h\n//\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// $Id: RHMesh.h,v 1.15 2015/08/13 02:45:47 mikem Exp $\n\n#ifndef RHMesh_h\n#define RHMesh_h\n\n#include <RHRouter.h>\n\n// Types of RHMesh message, used to set msgType in the RHMeshHeader\n#define RH_MESH_MESSAGE_TYPE_APPLICATION                    0\n#define RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST        1\n#define RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE       2\n#define RH_MESH_MESSAGE_TYPE_ROUTE_FAILURE                  3\n\n// Timeout for address resolution in milliecs\n#define RH_MESH_ARP_TIMEOUT 4000\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHMesh RHMesh.h <RHMesh.h>\n/// \\brief RHRouter subclass for sending addressed, optionally acknowledged datagrams\n/// multi-hop routed across a network, with automatic route discovery\n///\n/// Manager class that extends RHRouter to add automatic route discovery within a mesh of adjacent nodes, \n/// and route signalling.\n///\n/// Unlike RHRouter, RHMesh can be used in networks where the network topology is fluid, or unknown, \n/// or if nodes can mode around or go in or out of service. When a node wants to send a \n/// message to another node, it will automatically discover a route to the destination node and use it. \n/// If the route becomes unavailable, a new route will be discovered.\n///\n/// \\par Route Discovery\n///\n/// When a RHMesh mesh node is initialised, it doe not know any routes to any other nodes \n/// (see RHRouter for details on route and the routing table).\n/// When you attempt to send a message with sendtoWait, will first check to see if there is a route to the \n/// destinastion node in the routing tabl;e. If not, it wil initialite 'Route Discovery'.\n/// When a node needs to discover a route to another node, it broadcasts MeshRouteDiscoveryMessage \n/// with a message type of RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST. \n/// Any node that receives such a request checks to see if it is a request for a route to itself\n/// (in which case it makes a unicast reply to the originating node with a \n/// MeshRouteDiscoveryMessage \n/// with a message type of RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE) \n/// otherwise it rebroadcasts the request, after adding itself to the list of nodes visited so \n/// far by the request.\n///\n/// If a node receives a RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST that already has itself \n/// listed in the visited nodes, it knows it has already seen and rebroadcast this request, \n/// and threfore ignores it. This prevents broadcast storms.\n/// When a node receives a RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST it can use the list of \n/// nodes aready visited to deduce routes back towards the originating (requesting node). \n/// This also means that when the destination node of the request is reached, it (and all \n/// the previous nodes the request visited) will have a route back to the originating node. \n/// This means the unicast RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE \n/// reply will be routed successfully back to the original route requester.\n///\n/// The RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE sent back by the destination node contains \n/// the full list of nodes that were visited on the way to the destination.\n/// Therefore, intermediate nodes that route the reply back towards the originating node can use the \n/// node list in the reply to deduce routes to all the nodes between it and the destination node.\n///\n/// Therefore, RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST and \n/// RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE together ensure the original requester and all \n/// the intermediate nodes know how to route to the source and destination nodes and every node along the path.\n///\n/// Note that there is a race condition here that can effect routing on multipath routes. For example, \n/// if the route to the destination can traverse several paths, last reply from the destination \n/// will be the one used.\n///\n/// \\par Route Failure\n///\n/// RHRouter (and therefore RHMesh) use reliable hop-to-hop delivery of messages using \n/// hop-to-hop acknowledgements, but not end-to-end acknowledgements. When sendtoWait() returns, \n/// you know that the message has been delivered to the next hop, but not if it is (or even if it can be) \n/// delivered to the destination node. If during the course of hop-to-hop routing of a message, \n/// one of the intermediate RHMesh nodes finds it cannot deliver to the next hop \n/// (say due to a lost route or no acknwledgement from the next hop), it replies to the \n/// originator with a unicast MeshRouteFailureMessage RH_MESH_MESSAGE_TYPE_ROUTE_FAILURE message. \n/// Intermediate nodes (on the way beack to the originator)\n/// and the originating node use this message to delete the route to the destination \n/// node of the original message. This means that if a route to a destination becomes unusable \n/// (either because an intermediate node is off the air, or has moved out of range) a new route \n/// will be established the next time a message is to be sent.\n///\n/// \\par Message Format\n///\n/// RHMesh uses a number of message formats layered on top of RHRouter:\n/// - MeshApplicationMessage (message type RH_MESH_MESSAGE_TYPE_APPLICATION). \n///   Carries an application layer message for the caller of RHMesh\n/// - MeshRouteDiscoveryMessage (message types RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST \n///   and RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_RESPONSE). Carries Route Discovery messages \n///   (broadcast) and replies (unicast).\n/// - MeshRouteFailureMessage (message type RH_MESH_MESSAGE_TYPE_ROUTE_FAILURE) Informs nodes of \n///   route failures.\n///\n/// Part of the Arduino RH library for operating with HopeRF RH compatible transceivers \n/// (see http://www.hoperf.com)\n///\n/// \\par Memory\n///\n/// RHMesh programs require significant amount of SRAM, often approaching 2kbytes, \n/// which is beyond or at the limits of some Arduinos and other processors. Programs \n/// with additional software besides basic RHMesh programs may well require even more. If you have insufficient\n/// SRAM for your program, it may result in failure to run, or wierd crashes and other hard to trace behaviour.\n/// In this event you should consider a processor with more SRAM, such as the MotienoMEGA with 16k\n/// (https://lowpowerlab.com/shop/moteinomega) or others.\n///\n/// \\par Performance\n/// This class (in the interests of simple implemtenation and low memory use) does not have\n/// message queueing. This means that only one message at a time can be handled. Message transmission \n/// failures can have a severe impact on network performance.\n/// If you need high performance mesh networking under all conditions consider XBee or similar.\nclass RHMesh : public RHRouter\n{\npublic:\n\n    /// The maximum length permitted for the application payload data in a RHMesh message\n    #define RH_MESH_MAX_MESSAGE_LEN (RH_ROUTER_MAX_MESSAGE_LEN - sizeof(RHMesh::MeshMessageHeader))\n\n    /// Structure of the basic RHMesh header.\n    typedef struct\n    {\n\tuint8_t             msgType;  ///< Type of RHMesh message, one of RH_MESH_MESSAGE_TYPE_*\n    } MeshMessageHeader;\n\n    /// Signals an application layer message for the caller of RHMesh\n    typedef struct\n    {\n\tMeshMessageHeader   header; ///< msgType = RH_MESH_MESSAGE_TYPE_APPLICATION \n\tuint8_t             data[RH_MESH_MAX_MESSAGE_LEN]; ///< Application layer payload data\n    } MeshApplicationMessage;\n\n    /// Signals a route discovery request or reply (At present only supports physical dest addresses of length 1 octet)\n    typedef struct\n    {\n\tMeshMessageHeader   header;  ///< msgType = RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_*\n\tuint8_t             destlen; ///< Reserved. Must be 1.g\n\tuint8_t             dest;    ///< The address of the destination node whose route is being sought\n\tuint8_t             route[RH_MESH_MAX_MESSAGE_LEN - 1]; ///< List of node addresses visited so far. Length is implcit\n    } MeshRouteDiscoveryMessage;\n\n    /// Signals a route failure\n    typedef struct\n    {\n\tMeshMessageHeader   header; ///< msgType = RH_MESH_MESSAGE_TYPE_ROUTE_FAILURE\n\tuint8_t             dest; ///< The address of the destination towards which the route failed\n    } MeshRouteFailureMessage;\n\n    /// Constructor. \n    /// \\param[in] driver The RadioHead driver to use to transport messages.\n    /// \\param[in] thisAddress The address to assign to this node. Defaults to 0\n    RHMesh(RHGenericDriver& driver, uint8_t thisAddress = 0);\n\n    /// Sends a message to the destination node. Initialises the RHRouter message header \n    /// (the SOURCE address is set to the address of this node, HOPS to 0) and calls \n    /// route() which looks up in the routing table the next hop to deliver to.\n    /// If no route is known, initiates route discovery and waits for a reply.\n    /// Then sends the message to the next hop\n    /// Then waits for an acknowledgement from the next hop \n    /// (but not from the destination node (if that is different).\n    /// \\param [in] buf The application message data\n    /// \\param [in] len Number of octets in the application message data. 0 is permitted\n    /// \\param [in] dest The destination node address. If the address is RH_BROADCAST_ADDRESS (255)\n    /// the message will be broadcast to all the nearby nodes, but not routed or relayed.\n    /// \\param [in] flags Optional flags for use by subclasses or application layer, \n    ///             delivered end-to-end to the dest address. The receiver can recover the flags with recvFromAck().\n    /// \\return The result code:\n    ///         - RH_ROUTER_ERROR_NONE Message was routed and delivered to the next hop \n    ///           (not necessarily to the final dest address)\n    ///         - RH_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table\n    ///         - RH_ROUTER_ERROR_UNABLE_TO_DELIVER Not able to deliver to the next hop \n    ///           (usually because it dod not acknowledge due to being off the air or out of range\n    uint8_t sendtoWait(uint8_t* buf, uint8_t len, uint8_t dest, uint8_t flags = 0);\n\n    /// Starts the receiver if it is not running already, processes and possibly routes any received messages\n    /// addressed to other nodes\n    /// and delivers any messages addressed to this node.\n    /// If there is a valid application layer message available for this node (or RH_BROADCAST_ADDRESS), \n    /// send an acknowledgement to the last hop\n    /// address (blocking until this is complete), then copy the application message payload data\n    /// to buf and return true\n    /// else return false. \n    /// If a message is copied, *len is set to the length..\n    /// If from is not NULL, the originator SOURCE address is placed in *source.\n    /// If to is not NULL, the DEST address is placed in *dest. This might be this nodes address or \n    /// RH_BROADCAST_ADDRESS. \n    /// This is the preferred function for getting messages addressed to this node.\n    /// If the message is not a broadcast, acknowledge to the sender before returning.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Available space in buf. Set to the actual number of octets copied.\n    /// \\param[in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address\n    /// \\param[in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address\n    /// \\param[in] id If present and not NULL, the referenced uint8_t will be set to the ID\n    /// \\param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS\n    /// (not just those addressed to this node).\n    /// \\return true if a valid message was received for this node and copied to buf\n    bool recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* source = NULL, uint8_t* dest = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);\n\n    /// Starts the receiver if it is not running already.\n    /// Similar to recvfromAck(), this will block until either a valid application layer \n    /// message available for this node\n    /// or the timeout expires. \n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Available space in buf. Set to the actual number of octets copied.\n    /// \\param[in] timeout Maximum time to wait in milliseconds\n    /// \\param[in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address\n    /// \\param[in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address\n    /// \\param[in] id If present and not NULL, the referenced uint8_t will be set to the ID\n    /// \\param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS\n    /// (not just those addressed to this node).\n    /// \\return true if a valid message was copied to buf\n    bool recvfromAckTimeout(uint8_t* buf, uint8_t* len,  uint16_t timeout, uint8_t* source = NULL, uint8_t* dest = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);\n\nprotected:\n\n    /// Internal function that inspects messages being received and adjusts the routing table if necessary.\n    /// Called by recvfromAck() immediately after it gets the message from RHReliableDatagram\n    /// \\param [in] message Pointer to the RHRouter message that was received.\n    /// \\param [in] messageLen Length of message in octets\n    virtual void peekAtMessage(RoutedMessage* message, uint8_t messageLen);\n\n    /// Internal function that inspects messages being received and adjusts the routing table if necessary.\n    /// This is virtual, which lets subclasses override or intercept the route() function.\n    /// Called by sendtoWait after the message header has been filled in.\n    /// \\param [in] message Pointer to the RHRouter message to be sent.\n    /// \\param [in] messageLen Length of message in octets\n    virtual uint8_t route(RoutedMessage* message, uint8_t messageLen);\n\n    /// Try to resolve a route for the given address. Blocks while discovering the route\n    /// which may take up to 4000 msec.\n    /// Virtual so subclasses can override.\n    /// \\param [in] address The physical address to resolve\n    /// \\return true if the address was resolved and added to the local routing table\n    virtual bool doArp(uint8_t address);\n\n    /// Tests if the given address of length addresslen is indentical to the\n    /// physical address of this node.\n    /// RHMesh always implements physical addresses as the 1 octet address of the node\n    /// given by _thisAddress\n    /// Called by recvfromAck() to test whether a RH_MESH_MESSAGE_TYPE_ROUTE_DISCOVERY_REQUEST\n    /// is for this node.\n    /// Subclasses may want to override to implement more complicated or longer physical addresses\n    /// \\param [in] address Address of the pyysical addres being tested\n    /// \\param [in] addresslen Lengthof the address in bytes\n    /// \\return true if the physical address of this node is identical to address\n    virtual bool isPhysicalAddress(uint8_t* address, uint8_t addresslen);\n\nprivate:\n    /// Temporary message buffer\n    static uint8_t _tmpMessage[RH_ROUTER_MAX_MESSAGE_LEN];\n\n};\n\n/// @example rf22_mesh_client.pde\n/// @example rf22_mesh_server1.pde\n/// @example rf22_mesh_server2.pde\n/// @example rf22_mesh_server3.pde\n\n#endif\n\n"
  },
  {
    "path": "RHNRFSPIDriver.cpp",
    "content": "// RHNRFSPIDriver.cpp\n//\n// Copyright (C) 2014 Mike McCauley\n// $Id: RHNRFSPIDriver.cpp,v 1.3 2015/12/16 04:55:33 mikem Exp $\n\n#include <RHNRFSPIDriver.h>\n\nRHNRFSPIDriver::RHNRFSPIDriver(uint8_t slaveSelectPin, RHGenericSPI& spi)\n    : \n    _spi(spi),\n    _slaveSelectPin(slaveSelectPin)\n{\n}\n\nbool RHNRFSPIDriver::init()\n{\n    // start the SPI library with the default speeds etc:\n    // On Arduino Due this defaults to SPI1 on the central group of 6 SPI pins\n    _spi.begin();\n\n    // Initialise the slave select pin\n    // On Maple, this must be _after_ spi.begin\n    pinMode(_slaveSelectPin, OUTPUT);\n    digitalWrite(_slaveSelectPin, HIGH);\n\n    delay(100);\n    return true;\n}\n\n// Low level commands for interfacing with the device\nuint8_t RHNRFSPIDriver::spiCommand(uint8_t command)\n{\n    uint8_t status;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    status = _spi.transfer(command);\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return status;\n}\n\nuint8_t RHNRFSPIDriver::spiRead(uint8_t reg)\n{\n    uint8_t val;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    _spi.transfer(reg); // Send the address, discard the status\n    val = _spi.transfer(0); // The written value is ignored, reg value is read\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return val;\n}\n\nuint8_t RHNRFSPIDriver::spiWrite(uint8_t reg, uint8_t val)\n{\n    uint8_t status = 0;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    status = _spi.transfer(reg); // Send the address\n    _spi.transfer(val); // New value follows\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(__arm__) && defined(CORE_TEENSY)\n    // Sigh: some devices, such as MRF89XA dont work properly on Teensy 3.1:\n    // At 1MHz, the clock returns low _after_ slave select goes high, which prevents SPI\n    // write working. This delay gixes time for the clock to return low.\ndelayMicroseconds(5);\n#endif\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return status;\n}\n\nuint8_t RHNRFSPIDriver::spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len)\n{\n    uint8_t status = 0;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    status = _spi.transfer(reg); // Send the start address\n    while (len--)\n\t*dest++ = _spi.transfer(0);\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return status;\n}\n\nuint8_t RHNRFSPIDriver::spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len)\n{\n    uint8_t status = 0;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    status = _spi.transfer(reg); // Send the start address\n    while (len--)\n\t_spi.transfer(*src++);\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return status;\n}\n\nvoid RHNRFSPIDriver::setSlaveSelectPin(uint8_t slaveSelectPin)\n{\n    _slaveSelectPin = slaveSelectPin;\n}\n\n\n"
  },
  {
    "path": "RHNRFSPIDriver.h",
    "content": "// RHNRFSPIDriver.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2014 Mike McCauley\n// $Id: RHNRFSPIDriver.h,v 1.3 2015/12/16 04:55:33 mikem Exp $\n\n#ifndef RHNRFSPIDriver_h\n#define RHNRFSPIDriver_h\n\n#include <RHGenericDriver.h>\n#include <RHHardwareSPI.h>\n\nclass RHGenericSPI;\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHNRFSPIDriver RHNRFSPIDriver.h <RHNRFSPIDriver.h>\n/// \\brief Base class for a RadioHead driver that use the SPI bus\n/// to communicate with its transport hardware.\n///\n/// This class can be subclassed by Drivers that require to use the SPI bus.\n/// It can be configured to use either the RHHardwareSPI class (if there is one available on the platform)\n/// of the bitbanged RHSoftwareSPI class. The dfault behaviour is to use a pre-instantiated built-in RHHardwareSPI\n/// interface.\n/// \n/// SPI bus access is protected by ATOMIC_BLOCK_START and ATOMIC_BLOCK_END, which will ensure interrupts \n/// are disabled during access.\n/// \n/// The read and write routines use SPI conventions as used by Nordic NRF radios and otehr devices, \n/// but these can be overriden \n/// in subclasses if necessary.\n///\n/// Application developers are not expected to instantiate this class directly: \n/// it is for the use of Driver developers.\nclass RHNRFSPIDriver : public RHGenericDriver\n{\npublic:\n    /// Constructor\n    /// \\param[in] slaveSelectPin The controller pin to use to select the desired SPI device. This pin will be driven LOW\n    /// during SPI communications with the SPI device that uis iused by this Driver.\n    /// \\param[in] spi Reference to the SPI interface to use. The default is to use a default built-in Hardware interface.\n    RHNRFSPIDriver(uint8_t slaveSelectPin = SS, RHGenericSPI& spi = hardware_spi);\n\n    /// Initialise the Driver transport hardware and software.\n    /// Make sure the Driver is properly configured before calling init().\n    /// \\return true if initialisation succeeded.\n    bool init();\n\n    /// Sends a single command to the device\n    /// \\param[in] command The command code to send to the device.\n    /// \\return Some devices return a status byte during the first data transfer. This byte is returned.\n    ///  it may or may not be meaningfule depending on the the type of device being accessed.\n    uint8_t spiCommand(uint8_t command);\n\n    /// Reads a single register from the SPI device\n    /// \\param[in] reg Register number\n    /// \\return The value of the register\n    uint8_t        spiRead(uint8_t reg);\n\n    /// Writes a single byte to the SPI device\n    /// \\param[in] reg Register number\n    /// \\param[in] val The value to write\n    /// \\return Some devices return a status byte during the first data transfer. This byte is returned.\n    ///  it may or may not be meaningfule depending on the the type of device being accessed.\n    uint8_t           spiWrite(uint8_t reg, uint8_t val);\n\n    /// Reads a number of consecutive registers from the SPI device using burst read mode\n    /// \\param[in] reg Register number of the first register\n    /// \\param[in] dest Array to write the register values to. Must be at least len bytes\n    /// \\param[in] len Number of bytes to read\n    /// \\return Some devices return a status byte during the first data transfer. This byte is returned.\n    ///  it may or may not be meaningfule depending on the the type of device being accessed.\n    uint8_t           spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);\n\n    /// Write a number of consecutive registers using burst write mode\n    /// \\param[in] reg Register number of the first register\n    /// \\param[in] src Array of new register values to write. Must be at least len bytes\n    /// \\param[in] len Number of bytes to write\n    /// \\return Some devices return a status byte during the first data transfer. This byte is returned.\n    ///  it may or may not be meaningfule depending on the the type of device being accessed.\n    uint8_t           spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len);\n\n    /// Set or change the pin to be used for SPI slave select.\n    /// This can be called at any time to change the\n    /// pin that will be used for slave select in subsquent SPI operations.\n    /// \\param[in] slaveSelectPin The pin to use\n    void setSlaveSelectPin(uint8_t slaveSelectPin);\n\nprotected:\n    /// Reference to the RHGenericSPI instance to use to trasnfer data with teh SPI device\n    RHGenericSPI&       _spi;\n\n    /// The pin number of the Slave Select pin that is used to select the desired device.\n    uint8_t             _slaveSelectPin;\n};\n\n#endif\n"
  },
  {
    "path": "RHReliableDatagram.cpp",
    "content": "// RHReliableDatagram.cpp\n//\n// Define addressed datagram\n// \n// Part of the Arduino RH library for operating with HopeRF RH compatible transceivers \n// (see http://www.hoperf.com)\n// RHDatagram will be received only by the addressed node or all nodes within range if the \n// to address is RH_BROADCAST_ADDRESS\n//\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// $Id: RHReliableDatagram.cpp,v 1.16 2017/01/12 23:58:00 mikem Exp $\n\n#include <RHReliableDatagram.h>\n\n////////////////////////////////////////////////////////////////////\n// Constructors\nRHReliableDatagram::RHReliableDatagram(RHGenericDriver& driver, uint8_t thisAddress) \n    : RHDatagram(driver, thisAddress)\n{\n    _retransmissions = 0;\n    _lastSequenceNumber = 0;\n    _timeout = RH_DEFAULT_TIMEOUT;\n    _retries = RH_DEFAULT_RETRIES;\n    memset(_seenIds, 0, sizeof(_seenIds));\n}\n\n////////////////////////////////////////////////////////////////////\n// Public methods\nvoid RHReliableDatagram::setTimeout(uint16_t timeout)\n{\n    _timeout = timeout;\n}\n\n////////////////////////////////////////////////////////////////////\nvoid RHReliableDatagram::setRetries(uint8_t retries)\n{\n    _retries = retries;\n}\n\n////////////////////////////////////////////////////////////////////\nuint8_t RHReliableDatagram::retries()\n{\n    return _retries;\n}\n\n////////////////////////////////////////////////////////////////////\nbool RHReliableDatagram::sendtoWait(uint8_t* buf, uint8_t len, uint8_t address)\n{\n    // Assemble the message\n    uint8_t thisSequenceNumber = ++_lastSequenceNumber;\n    uint8_t retries = 0;\n    while (retries++ <= _retries)\n    {\n\tsetHeaderId(thisSequenceNumber);\n\tsetHeaderFlags(RH_FLAGS_NONE, RH_FLAGS_ACK); // Clear the ACK flag\n\tsendto(buf, len, address);\n\twaitPacketSent();\n\n\t// Never wait for ACKS to broadcasts:\n\tif (address == RH_BROADCAST_ADDRESS)\n\t    return true;\n\n\tif (retries > 1)\n\t    _retransmissions++;\n\tunsigned long thisSendTime = millis(); // Timeout does not include original transmit time\n\n\t// Compute a new timeout, random between _timeout and _timeout*2\n\t// This is to prevent collisions on every retransmit\n\t// if 2 nodes try to transmit at the same time\n#if (RH_PLATFORM == RH_PLATFORM_RASPI) // use standard library random(), bugs in random(min, max)\n\tuint16_t timeout = _timeout + (_timeout * (random() & 0xFF) / 256);\n#else\n\tuint16_t timeout = _timeout + (_timeout * random(0, 256) / 256);\n#endif\n\tint32_t timeLeft;\n        while ((timeLeft = timeout - (millis() - thisSendTime)) > 0)\n\t{\n\t    if (waitAvailableTimeout(timeLeft))\n\t    {\n\t\tuint8_t from, to, id, flags;\n\t\tif (recvfrom(0, 0, &from, &to, &id, &flags)) // Discards the message\n\t\t{\n\t\t    // Now have a message: is it our ACK?\n\t\t    if (   from == address \n\t\t\t   && to == _thisAddress \n\t\t\t   && (flags & RH_FLAGS_ACK) \n\t\t\t   && (id == thisSequenceNumber))\n\t\t    {\n\t\t\t// Its the ACK we are waiting for\n\t\t\treturn true;\n\t\t    }\n\t\t    else if (   !(flags & RH_FLAGS_ACK)\n\t\t\t\t&& (id == _seenIds[from]))\n\t\t    {\n\t\t\t// This is a request we have already received. ACK it again\n\t\t\tacknowledge(id, from);\n\t\t    }\n\t\t    // Else discard it\n\t\t}\n\t    }\n\t    // Not the one we are waiting for, maybe keep waiting until timeout exhausted\n\t    YIELD;\n\t}\n\t// Timeout exhausted, maybe retry\n\tYIELD;\n    }\n    // Retries exhausted\n    return false;\n}\n\n////////////////////////////////////////////////////////////////////\nbool RHReliableDatagram::recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags)\n{  \n    uint8_t _from;\n    uint8_t _to;\n    uint8_t _id;\n    uint8_t _flags;\n    // Get the message before its clobbered by the ACK (shared rx and tx buffer in some drivers\n    if (available() && recvfrom(buf, len, &_from, &_to, &_id, &_flags))\n    {\n\t// Never ACK an ACK\n\tif (!(_flags & RH_FLAGS_ACK))\n\t{\n\t    // Its a normal message for this node, not an ACK\n\t    if (_to != RH_BROADCAST_ADDRESS)\n\t    {\n\t\t// Its not a broadcast, so ACK it\n\t\t// Acknowledge message with ACK set in flags and ID set to received ID\n\t\tacknowledge(_id, _from);\n\t    }\n\t    // If we have not seen this message before, then we are interested in it\n\t    if (_id != _seenIds[_from])\n\t    {\n\t\tif (from)  *from =  _from;\n\t\tif (to)    *to =    _to;\n\t\tif (id)    *id =    _id;\n\t\tif (flags) *flags = _flags;\n\t\t_seenIds[_from] = _id;\n\t\treturn true;\n\t    }\n\t    // Else just re-ack it and wait for a new one\n\t}\n    }\n    // No message for us available\n    return false;\n}\n\nbool RHReliableDatagram::recvfromAckTimeout(uint8_t* buf, uint8_t* len, uint16_t timeout, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags)\n{\n    unsigned long starttime = millis();\n    int32_t timeLeft;\n    while ((timeLeft = timeout - (millis() - starttime)) > 0)\n    {\n\tif (waitAvailableTimeout(timeLeft))\n\t{\n\t    if (recvfromAck(buf, len, from, to, id, flags))\n\t\treturn true;\n\t}\n\tYIELD;\n    }\n    return false;\n}\n\nuint32_t RHReliableDatagram::retransmissions()\n{\n    return _retransmissions;\n}\n\nvoid RHReliableDatagram::resetRetransmissions()\n{\n    _retransmissions = 0;\n}\n \nvoid RHReliableDatagram::acknowledge(uint8_t id, uint8_t from)\n{\n    setHeaderId(id);\n    setHeaderFlags(RH_FLAGS_ACK);\n    // We would prefer to send a zero length ACK,\n    // but if an RH_RF22 receives a 0 length message with a CRC error, it will never receive\n    // a 0 length message again, until its reset, which makes everything hang :-(\n    // So we send an ACK of 1 octet\n    // REVISIT: should we send the RSSI for the information of the sender?\n    uint8_t ack = '!';\n    sendto(&ack, sizeof(ack), from); \n    waitPacketSent();\n}\n\n"
  },
  {
    "path": "RHReliableDatagram.h",
    "content": "// RHReliableDatagram.h\n//\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// $Id: RHReliableDatagram.h,v 1.17 2016/04/04 01:40:12 mikem Exp $\n\n#ifndef RHReliableDatagram_h\n#define RHReliableDatagram_h\n\n#include <RHDatagram.h>\n\n// The acknowledgement bit in the FLAGS\n// The top 4 bits of the flags are reserved for RadioHead. The lower 4 bits are reserved\n// for application layer use.\n#define RH_FLAGS_ACK 0x80\n\n/// the default retry timeout in milliseconds\n#define RH_DEFAULT_TIMEOUT 200\n\n/// The default number of retries\n#define RH_DEFAULT_RETRIES 3\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHReliableDatagram RHReliableDatagram.h <RHReliableDatagram.h>\n/// \\brief RHDatagram subclass for sending addressed, acknowledged, retransmitted datagrams.\n///\n/// Manager class that extends RHDatagram to define addressed, reliable datagrams with acknowledgement and retransmission.\n/// Based on RHDatagram, adds flags and sequence numbers. RHReliableDatagram is reliable in the sense\n/// that messages are acknowledged by the recipient, and unacknowledged messages are retransmitted until acknowledged or the\n/// retries are exhausted.\n/// When addressed messages are sent (by sendtoWait()), it will wait for an ack, and retransmit\n/// after timeout until an ack is received or retries are exhausted.\n/// When addressed messages are collected by the application (by recvfromAck()), \n/// an acknowledgement is automatically sent to the sender.\n///\n/// You can use RHReliableDatagram to send broadcast messages, with a TO address of RH_BROADCAST_ADDRESS,\n/// however broadcasts are not acknowledged or retransmitted and are therefore NOT actually reliable.\n///\n/// The retransmit timeout is randomly varied between timeout and timeout*2 to prevent collisions on all\n/// retries when 2 nodes happen to start sending at the same time .\n///\n/// Each new message sent by sendtoWait() has its ID incremented.\n///\n/// An ack consists of a message with:\n/// - TO set to the from address of the original message\n/// - FROM set to this node address\n/// - ID set to the ID of the original message\n/// - FLAGS with the RH_FLAGS_ACK bit set\n/// - 1 octet of payload containing ASCII '!' (since some drivers cannot handle 0 length payloads)\n///\n/// \\par Media Access Strategy\n///\n/// RHReliableDatagram and the underlying drivers always transmit as soon as\n/// sendtoWait() is called.  RHReliableDatagram waits for an acknowledgement,\n/// and if one is not received after a timeout period the message is\n/// transmitted again.  If no acknowledgement is received after several\n/// retries, the transmissions is deemed to have failed.\n/// No contention for media is detected.\n/// This will be recognised as \"pure ALOHA\". \n/// The addition of Clear Channel Assessment (CCA) is desirable and planned.\n///\n/// There is no message queuing or threading in RHReliableDatagram. \n/// sendtoWait() waits until an acknowledgement is received, retransmitting\n/// up to (by default) 3 retries time with a default 200ms timeout. \n/// During this transmit-acknowledge phase, any received message (other than the expected\n/// acknowledgement) will be ignored. Your sketch will be unresponsive to new messages \n/// until an acknowledgement is received or the retries are exhausted. \n/// Central server-type sketches should be very cautious about their\n/// retransmit strategy and configuration lest they hang for a long time\n/// trying to reply to clients that are unreachable.\n///\n/// Caution: if you have a radio network with a mixture of slow and fast\n/// processors and ReliableDatagrams, you may be affected by race conditions\n/// where the fast processor acknowledges a message before the sender is ready\n/// to process the acknowledgement. Best practice is to use the same processors (and\n/// radios) throughout your network.\n///\nclass RHReliableDatagram : public RHDatagram\n{\npublic:\n    /// Constructor. \n    /// \\param[in] driver The RadioHead driver to use to transport messages.\n    /// \\param[in] thisAddress The address to assign to this node. Defaults to 0\n    RHReliableDatagram(RHGenericDriver& driver, uint8_t thisAddress = 0);\n\n    /// Sets the minimum retransmit timeout. If sendtoWait is waiting for an ack \n    /// longer than this time (in milliseconds), \n    /// it will retransmit the message. Defaults to 200ms. The timeout is measured from the end of\n    /// transmission of the message. It must be at least longer than the the transmit \n    /// time of the acknowledgement (preamble+6 octets) plus the latency/poll time of the receiver. \n    /// For fast modulation schemes you can considerably shorten this time.\n    /// Caution: if you are using slow packet rates and long packets \n    /// you may need to change the timeout for reliable operations.\n    /// The actual timeout is randomly varied between timeout and timeout*2.\n    /// \\param[in] timeout The new timeout period in milliseconds\n    void setTimeout(uint16_t timeout);\n\n    /// Sets the maximum number of retries. Defaults to 3 at construction time. \n    /// If set to 0, each message will only ever be sent once.\n    /// sendtoWait will give up and return false if there is no ack received after all transmissions time out\n    /// and the retries count is exhausted.\n    /// param[in] retries The maximum number a retries.\n    void setRetries(uint8_t retries);\n\n    /// Returns the currently configured maximum retries count.\n    /// Can be changed with setRetries().\n    /// \\return The currently configured maximum number of retries.\n    uint8_t retries();\n\n    /// Send the message (with retries) and waits for an ack. Returns true if an acknowledgement is received.\n    /// Synchronous: any message other than the desired ACK received while waiting is discarded.\n    /// Blocks until an ACK is received or all retries are exhausted (ie up to retries*timeout milliseconds).\n    /// If the destination address is the broadcast address RH_BROADCAST_ADDRESS (255), the message will \n    /// be sent as a broadcast, but receiving nodes do not acknowledge, and sendtoWait() returns true immediately\n    /// without waiting for any acknowledgements.\n    /// \\param[in] address The address to send the message to.\n    /// \\param[in] buf Pointer to the binary message to send\n    /// \\param[in] len Number of octets to send\n    /// \\return true if the message was transmitted and an acknowledgement was received.\n    bool sendtoWait(uint8_t* buf, uint8_t len, uint8_t address);\n\n    /// If there is a valid message available for this node, send an acknowledgement to the SRC\n    /// address (blocking until this is complete), then copy the message to buf and return true\n    /// else return false. \n    /// If a message is copied, *len is set to the length..\n    /// If from is not NULL, the SRC address is placed in *from.\n    /// If to is not NULL, the DEST address is placed in *to.\n    /// This is the preferred function for getting messages addressed to this node.\n    /// If the message is not a broadcast, acknowledge to the sender before returning.\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Available space in buf. Set to the actual number of octets copied.\n    /// \\param[in] from If present and not NULL, the referenced uint8_t will be set to the SRC address\n    /// \\param[in] to If present and not NULL, the referenced uint8_t will be set to the DEST address\n    /// \\param[in] id If present and not NULL, the referenced uint8_t will be set to the ID\n    /// \\param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS\n    /// (not just those addressed to this node).\n    /// \\return true if a valid message was copied to buf\n    bool recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* from = NULL, uint8_t* to = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);\n\n    /// Similar to recvfromAck(), this will block until either a valid message available for this node\n    /// or the timeout expires. Starts the receiver automatically.\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Available space in buf. Set to the actual number of octets copied.\n    /// \\param[in] timeout Maximum time to wait in milliseconds\n    /// \\param[in] from If present and not NULL, the referenced uint8_t will be set to the SRC address\n    /// \\param[in] to If present and not NULL, the referenced uint8_t will be set to the DEST address\n    /// \\param[in] id If present and not NULL, the referenced uint8_t will be set to the ID\n    /// \\param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS\n    /// (not just those addressed to this node).\n    /// \\return true if a valid message was copied to buf\n    bool recvfromAckTimeout(uint8_t* buf, uint8_t* len,  uint16_t timeout, uint8_t* from = NULL, uint8_t* to = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);\n\n    /// Returns the number of retransmissions \n    /// we have had to send since starting or since the last call to resetRetransmissions().\n    /// \\return The number of retransmissions since initialisation.\n    uint32_t retransmissions();\n\n    /// Resets the count of the number of retransmissions \n    /// to 0. \n    void resetRetransmissions(); \n\nprotected:\n    /// Send an ACK for the message id to the given from address\n    /// Blocks until the ACK has been sent\n    void acknowledge(uint8_t id, uint8_t from);\n\n    /// Checks whether the message currently in the Rx buffer is a new message, not previously received\n    /// based on the from address and the sequence.  If it is new, it is acknowledged and returns true\n    /// \\return true if there is a message received and it is a new message\n    bool haveNewMessage();\n\nprivate:\n    /// Count of retransmissions we have had to send\n    uint32_t _retransmissions;\n\n    /// The last sequence number to be used\n    /// Defaults to 0\n    uint8_t _lastSequenceNumber;\n\n    // Retransmit timeout (milliseconds)\n    /// Defaults to 200\n    uint16_t _timeout;\n\n    // Retries (0 means one try only)\n    /// Defaults to 3\n    uint8_t _retries;\n\n    /// Array of the last seen sequence number indexed by node address that sent it\n    /// It is used for duplicate detection. Duplicated messages are re-acknowledged when received \n    /// (this is generally due to lost ACKs, causing the sender to retransmit, even though we have already\n    /// received that message)\n    uint8_t _seenIds[256];\n};\n\n/// @example rf22_reliable_datagram_client.pde\n/// @example rf22_reliable_datagram_server.pde\n\n#endif\n\n"
  },
  {
    "path": "RHRouter.cpp",
    "content": "// RHRouter.cpp\n//\n// Define addressed datagram\n// \n// Part of the Arduino RH library for operating with HopeRF RH compatible transceivers \n// (see http://www.hoperf.com)\n// RHDatagram will be received only by the addressed node or all nodes within range if the \n// to address is RH_BROADCAST_ADDRESS\n//\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// $Id: RHRouter.cpp,v 1.7 2015/08/13 02:45:47 mikem Exp $\n\n#include <RHRouter.h>\n\nRHRouter::RoutedMessage RHRouter::_tmpMessage;\n\n////////////////////////////////////////////////////////////////////\n// Constructors\nRHRouter::RHRouter(RHGenericDriver& driver, uint8_t thisAddress) \n    : RHReliableDatagram(driver, thisAddress)\n{\n    _max_hops = RH_DEFAULT_MAX_HOPS;\n    clearRoutingTable();\n}\n\n////////////////////////////////////////////////////////////////////\n// Public methods\nbool RHRouter::init()\n{\n    bool ret = RHReliableDatagram::init();\n    if (ret)\n\t_max_hops = RH_DEFAULT_MAX_HOPS;\n    return ret;\n}\n\n////////////////////////////////////////////////////////////////////\nvoid RHRouter::setMaxHops(uint8_t max_hops)\n{\n    _max_hops = max_hops;\n}\n\n////////////////////////////////////////////////////////////////////\nvoid RHRouter::addRouteTo(uint8_t dest, uint8_t next_hop, uint8_t state)\n{\n    uint8_t i;\n\n    // First look for an existing entry we can update\n    for (i = 0; i < RH_ROUTING_TABLE_SIZE; i++)\n    {\n\tif (_routes[i].dest == dest)\n\t{\n\t    _routes[i].dest = dest;\n\t    _routes[i].next_hop = next_hop;\n\t    _routes[i].state = state;\n\t    return;\n\t}\n    }\n\n    // Look for an invalid entry we can use\n    for (i = 0; i < RH_ROUTING_TABLE_SIZE; i++)\n    {\n\tif (_routes[i].state == Invalid)\n\t{\n\t    _routes[i].dest = dest;\n\t    _routes[i].next_hop = next_hop;\n\t    _routes[i].state = state;\n\t    return;\n\t}\n    }\n\n    // Need to make room for a new one\n    retireOldestRoute();\n    // Should be an invalid slot now\n    for (i = 0; i < RH_ROUTING_TABLE_SIZE; i++)\n    {\n\tif (_routes[i].state == Invalid)\n\t{\n\t    _routes[i].dest = dest;\n\t    _routes[i].next_hop = next_hop;\n\t    _routes[i].state = state;\n\t}\n    }\n}\n\n////////////////////////////////////////////////////////////////////\nRHRouter::RoutingTableEntry* RHRouter::getRouteTo(uint8_t dest)\n{\n    uint8_t i;\n    for (i = 0; i < RH_ROUTING_TABLE_SIZE; i++)\n\tif (_routes[i].dest == dest && _routes[i].state != Invalid)\n\t    return &_routes[i];\n    return NULL;\n}\n\n////////////////////////////////////////////////////////////////////\nvoid RHRouter::deleteRoute(uint8_t index)\n{\n    // Delete a route by copying following routes on top of it\n    memcpy(&_routes[index], &_routes[index+1], \n\t   sizeof(RoutingTableEntry) * (RH_ROUTING_TABLE_SIZE - index - 1));\n    _routes[RH_ROUTING_TABLE_SIZE - 1].state = Invalid;\n}\n\n////////////////////////////////////////////////////////////////////\nvoid RHRouter::printRoutingTable()\n{\n#ifdef RH_HAVE_SERIAL\n    uint8_t i;\n    for (i = 0; i < RH_ROUTING_TABLE_SIZE; i++)\n    {\n\tSerial.print(i, DEC);\n\tSerial.print(\" Dest: \");\n\tSerial.print(_routes[i].dest, DEC);\n\tSerial.print(\" Next Hop: \");\n\tSerial.print(_routes[i].next_hop, DEC);\n\tSerial.print(\" State: \");\n\tSerial.println(_routes[i].state, DEC);\n    }\n#endif\n}\n\n////////////////////////////////////////////////////////////////////\nbool RHRouter::deleteRouteTo(uint8_t dest)\n{\n    uint8_t i;\n    for (i = 0; i < RH_ROUTING_TABLE_SIZE; i++)\n    {\n\tif (_routes[i].dest == dest)\n\t{\n\t    deleteRoute(i);\n\t    return true;\n\t}\n    }\n    return false;\n}\n\n////////////////////////////////////////////////////////////////////\nvoid RHRouter::retireOldestRoute()\n{\n    // We just obliterate the first in the table and clear the last\n    deleteRoute(0);\n}\n\n////////////////////////////////////////////////////////////////////\nvoid RHRouter::clearRoutingTable()\n{\n    uint8_t i;\n    for (i = 0; i < RH_ROUTING_TABLE_SIZE; i++)\n\t_routes[i].state = Invalid;\n}\n\n\nuint8_t RHRouter::sendtoWait(uint8_t* buf, uint8_t len, uint8_t dest, uint8_t flags)\n{\n    return sendtoFromSourceWait(buf, len, dest, _thisAddress, flags);\n}\n\n////////////////////////////////////////////////////////////////////\n// Waits for delivery to the next hop (but not for delivery to the final destination)\nuint8_t RHRouter::sendtoFromSourceWait(uint8_t* buf, uint8_t len, uint8_t dest, uint8_t source, uint8_t flags)\n{\n    if (((uint16_t)len + sizeof(RoutedMessageHeader)) > _driver.maxMessageLength())\n\treturn RH_ROUTER_ERROR_INVALID_LENGTH;\n\n    // Construct a RH RouterMessage message\n    _tmpMessage.header.source = source;\n    _tmpMessage.header.dest = dest;\n    _tmpMessage.header.hops = 0;\n    _tmpMessage.header.id = _lastE2ESequenceNumber++;\n    _tmpMessage.header.flags = flags;\n    memcpy(_tmpMessage.data, buf, len);\n\n    return route(&_tmpMessage, sizeof(RoutedMessageHeader)+len);\n}\n\n////////////////////////////////////////////////////////////////////\nuint8_t RHRouter::route(RoutedMessage* message, uint8_t messageLen)\n{\n    // Reliably deliver it if possible. See if we have a route:\n    uint8_t next_hop = RH_BROADCAST_ADDRESS;\n    if (message->header.dest != RH_BROADCAST_ADDRESS)\n    {\n\tRoutingTableEntry* route = getRouteTo(message->header.dest);\n\tif (!route)\n\t    return RH_ROUTER_ERROR_NO_ROUTE;\n\tnext_hop = route->next_hop;\n    }\n\n    if (!RHReliableDatagram::sendtoWait((uint8_t*)message, messageLen, next_hop))\n\treturn RH_ROUTER_ERROR_UNABLE_TO_DELIVER;\n\n    return RH_ROUTER_ERROR_NONE;\n}\n\n////////////////////////////////////////////////////////////////////\n// Subclasses may want to override this to peek at messages going past\nvoid RHRouter::peekAtMessage(RoutedMessage* message, uint8_t messageLen)\n{\n    // Default does nothing\n}\n\n////////////////////////////////////////////////////////////////////\nbool RHRouter::recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* source, uint8_t* dest, uint8_t* id, uint8_t* flags)\n{  \n    uint8_t tmpMessageLen = sizeof(_tmpMessage);\n    uint8_t _from;\n    uint8_t _to;\n    uint8_t _id;\n    uint8_t _flags;\n    if (RHReliableDatagram::recvfromAck((uint8_t*)&_tmpMessage, &tmpMessageLen, &_from, &_to, &_id, &_flags))\n    {\n\t// Here we simulate networks with limited visibility between nodes\n\t// so we can test routing\n#ifdef RH_TEST_NETWORK\n\tif (\n#if RH_TEST_NETWORK==1\n\t    // This network looks like 1-2-3-4\n\t       (_thisAddress == 1 && _from == 2)\n\t    || (_thisAddress == 2 && (_from == 1 || _from == 3))\n\t    || (_thisAddress == 3 && (_from == 2 || _from == 4))\n\t    || (_thisAddress == 4 && _from == 3)\n\t    \n#elif RH_TEST_NETWORK==2\n\t       // This network looks like 1-2-4\n\t       //                         | | |\n\t       //                         --3--\n\t       (_thisAddress == 1 && (_from == 2 || _from == 3))\n\t    ||  _thisAddress == 2\n\t    ||  _thisAddress == 3\n\t    || (_thisAddress == 4 && (_from == 2 || _from == 3))\n\n#elif RH_TEST_NETWORK==3\n\t       // This network looks like 1-2-4\n\t       //                         |   |\n\t       //                         --3--\n\t       (_thisAddress == 1 && (_from == 2 || _from == 3))\n\t    || (_thisAddress == 2 && (_from == 1 || _from == 4))\n\t    || (_thisAddress == 3 && (_from == 1 || _from == 4))\n\t    || (_thisAddress == 4 && (_from == 2 || _from == 3))\n\n#elif RH_TEST_NETWORK==4\n\t       // This network looks like 1-2-3\n\t       //                           |\n\t       //                           4\n\t       (_thisAddress == 1 && _from == 2)\n\t    ||  _thisAddress == 2\n\t    || (_thisAddress == 3 && _from == 2)\n\t    || (_thisAddress == 4 && _from == 2)\n\n#endif\n)\n\t{\n\t    // OK\n\t}\n\telse\n\t{\n\t    return false; // Pretend we got nothing\n\t}\n#endif\n\n\tpeekAtMessage(&_tmpMessage, tmpMessageLen);\n\t// See if its for us or has to be routed\n\tif (_tmpMessage.header.dest == _thisAddress || _tmpMessage.header.dest == RH_BROADCAST_ADDRESS)\n\t{\n\t    // Deliver it here\n\t    if (source) *source  = _tmpMessage.header.source;\n\t    if (dest)   *dest    = _tmpMessage.header.dest;\n\t    if (id)     *id      = _tmpMessage.header.id;\n\t    if (flags)  *flags   = _tmpMessage.header.flags;\n\t    uint8_t msgLen = tmpMessageLen - sizeof(RoutedMessageHeader);\n\t    if (*len > msgLen)\n\t\t*len = msgLen;\n\t    memcpy(buf, _tmpMessage.data, *len);\n\t    return true; // Its for you!\n\t}\n\telse if (   _tmpMessage.header.dest != RH_BROADCAST_ADDRESS\n\t\t && _tmpMessage.header.hops++ < _max_hops)\n\t{\n\t    // Maybe it has to be routed to the next hop\n\t    // REVISIT: if it fails due to no route or unable to deliver to the next hop, \n\t    // tell the originator. BUT HOW?\n\t    route(&_tmpMessage, tmpMessageLen);\n\t}\n\t// Discard it and maybe wait for another\n    }\n    return false;\n}\n\n////////////////////////////////////////////////////////////////////\nbool RHRouter::recvfromAckTimeout(uint8_t* buf, uint8_t* len, uint16_t timeout, uint8_t* source, uint8_t* dest, uint8_t* id, uint8_t* flags)\n{  \n    unsigned long starttime = millis();\n    int32_t timeLeft;\n    while ((timeLeft = timeout - (millis() - starttime)) > 0)\n    {\n\tif (waitAvailableTimeout(timeLeft))\n\t{\n\t    if (recvfromAck(buf, len, source, dest, id, flags))\n\t\treturn true;\n\t}\n\tYIELD;\n    }\n    return false;\n}\n\n"
  },
  {
    "path": "RHRouter.h",
    "content": "// RHRouter.h\n//\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// $Id: RHRouter.h,v 1.9 2014/08/10 20:55:17 mikem Exp $\n\n#ifndef RHRouter_h\n#define RHRouter_h\n\n#include <RHReliableDatagram.h>\n\n// Default max number of hops we will route\n#define RH_DEFAULT_MAX_HOPS 30\n\n// The default size of the routing table we keep\n#define RH_ROUTING_TABLE_SIZE 10\n\n// Error codes\n#define RH_ROUTER_ERROR_NONE              0\n#define RH_ROUTER_ERROR_INVALID_LENGTH    1\n#define RH_ROUTER_ERROR_NO_ROUTE          2\n#define RH_ROUTER_ERROR_TIMEOUT           3\n#define RH_ROUTER_ERROR_NO_REPLY          4\n#define RH_ROUTER_ERROR_UNABLE_TO_DELIVER 5\n\n// This size of RH_ROUTER_MAX_MESSAGE_LEN is OK for Arduino Mega, but too big for\n// Duemilanova. Size of 50 works with the sample router programs on Duemilanova.\n#define RH_ROUTER_MAX_MESSAGE_LEN (RH_MAX_MESSAGE_LEN - sizeof(RHRouter::RoutedMessageHeader))\n//#define RH_ROUTER_MAX_MESSAGE_LEN 50\n\n// These allow us to define a simulated network topology for testing purposes\n// See RHRouter.cpp for details\n//#define RH_TEST_NETWORK 1\n//#define RH_TEST_NETWORK 2\n//#define RH_TEST_NETWORK 3\n//#define RH_TEST_NETWORK 4\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHRouter RHRouter.h <RHRouter.h>\n/// \\brief RHReliableDatagram subclass for sending addressed, optionally acknowledged datagrams\n/// multi-hop routed across a network.\n///\n/// Manager class that extends RHReliableDatagram to define addressed messages\n/// That are reliably transmitted and routed across a network. Each message is transmitted reliably \n/// between each hop in order to get from the source node to the destination node.\n///\n/// With RHRouter, routes are hard wired. This means that each node must have programmed \n/// in it how to reach each of the other nodes it will be trying to communicate with. \n/// This means you must specify the next-hop node address for each of the destination nodes, \n/// using the addRouteTo() function. \n///\n/// When sendtoWait() is called with a new message to deliver, and the destination address,\n/// RHRouter looks up the next hop node for the destination node. It then uses \n/// RHReliableDatagram to (reliably) deliver the message to the next hop \n/// (which is expected also to be running an RHRouter). If that next-hop node is not\n/// the final destination, it will also look up the next hop for the destination node and \n/// (reliably) deliver the message to the next hop. By this method, messages can be delivered \n/// across a network of nodes, even if each node cannot hear all of the others in the network.\n/// Each time a message is received for another node and retransmitted to the next hop, \n/// the HOPS filed in teh header is incremented. If a message is received for routing to another node \n/// which has exceed the routers max_hops, the message wioll be dropped and ignored. \n/// This helps prevent infinite routing loops.\n///\n/// RHRouter supports messages with a dest of RH_BROADCAST_ADDRESS. Such messages are not routed, \n/// and are broadcast (once) to all nodes within range.\n///\n/// The recvfromAck() function is responsible not just for receiving and delivering \n/// messages addressed to this node (or RH_BROADCAST_ADDRESS), but \n/// it is also responsible for routing other message to their next hop. This means that it is important to \n/// call recvfromAck() or recvfromAckTimeout() frequently in your main loop. recvfromAck() will return \n/// false if it receives a message but it is not for this node.\n///\n/// RHRouter does not provide reliable end-to-end delivery, but uses reliable hop-to-hop delivery. \n/// If a message is unable to be delivered to an end node during to a delivery failure between 2 hops, \n/// the source node will not be told about it.\n///\n/// Note: This class is most useful for networks of nodes that are essentially static \n/// (i.e. the nodes dont move around), and for which the \n/// routing never changes. If that is not the case for your proposed network, see RHMesh instead.\n///\n/// \\par The Routing Table\n///\n/// The routing table is a local table in RHRouter that holds the information about the next hop node \n/// address for each destination address you may want to send a message to. It is your responsibility \n/// to make sure every node in an RHRouter network has been configured with a unique address and the \n/// routing information so that messages are correctly routed across the network from source node to \n/// destination node. This is usually done once in setup() by calling addRouteTo(). \n/// The hardwired routing will in general be different on each node, and will depend on the physical \n/// topololgy of the network.\n/// You can also use addRouteTo() to change a route and \n/// deleteRouteTo() to delete a route at run time. Youcan also clear the entire routing table\n///\n/// The Routing Table has limited capacity for entries (defined by RH_ROUTING_TABLE_SIZE, which is 10)\n/// if more than RH_ROUTING_TABLE_SIZE are added, the oldest (first) one will be removed by calling \n/// retireOldestRoute()\n///\n/// \\par Message Format\n///\n/// RHRouter add to the lower level RHReliableDatagram (and even lower level RH) class message formats. \n/// In those lower level classes, the hop-to-hop message headers are in the RH message headers, \n/// and are handled automcatically by tyhe RH hardware.\n/// RHRouter and its subclasses add an end-to-end addressing header in the payload of the RH message, \n/// and before the RHRouter application data.\n/// - 1 octet DEST, the destination node address (ie the address of the final \n///   destination node for this message)\n/// - 1 octet SOURCE, the source node address (ie the address of the originating node that first sent \n///   the message).\n/// - 1 octet HOPS, the number of hops this message has traversed so far.\n/// - 1 octet ID, an incrementing message ID for end-to-end message tracking for use by subclasses. \n///   Not used by RHRouter.\n/// - 1 octet FLAGS, a bitmask for use by subclasses. Not used by RHRouter.\n/// - 0 or more octets DATA, the application payload data. The length of this data is implicit \n///   in the length of the entire message.\n///\n/// You should be careful to note that there are ID and FLAGS fields in the low level per-hop \n/// message header too. These are used only for hop-to-hop, and in general will be different to \n/// the ones at the RHRouter level.\n///\n/// \\par Testing\n///\n/// Bench testing of such networks is notoriously difficult, especially simulating limited radio \n/// connectivity between some nodes.\n/// To assist testing (both during RH development and for your own networks) \n/// RHRouter.cpp has the ability to \n/// simulate a number of different small network topologies. Each simulated network supports 4 nodes with \n/// addresses 1 to 4. It operates by pretending to not hear RH messages from certain other nodes.\n/// You can enable testing with a \\#define TEST_NETWORK in RHRouter.h\n/// The sample programs rf22_mesh_* rely on this feature.\n///\n/// Part of the Arduino RH library for operating with HopeRF RH compatible transceivers \n/// (see http://www.hoperf.com)\nclass RHRouter : public RHReliableDatagram\n{\npublic:\n\n    /// Defines the structure of the RHRouter message header, used to keep track of end-to-end delivery parameters\n    typedef struct\n    {\n\tuint8_t    dest;       ///< Destination node address\n\tuint8_t    source;     ///< Originator node address\n\tuint8_t    hops;       ///< Hops traversed so far\n\tuint8_t    id;         ///< Originator sequence number\n\tuint8_t    flags;      ///< Originator flags\n\t// Data follows, Length is implicit in the overall message length\n    } RoutedMessageHeader;\n\n    /// Defines the structure of a RHRouter message\n    typedef struct\n    {\n\tRoutedMessageHeader header;    ///< end-to-end delivery header\n\tuint8_t             data[RH_ROUTER_MAX_MESSAGE_LEN]; ///< Application payload data\n    } RoutedMessage;\n\n    /// Values for the possible states for routes\n    typedef enum\n    {\n\tInvalid = 0,           ///< No valid route is known\n\tDiscovering,           ///< Discovering a route (not currently used)\n\tValid                  ///< Route is valid\n    } RouteState;\n\n    /// Defines an entry in the routing table\n    typedef struct\n    {\n\tuint8_t      dest;      ///< Destination node address\n\tuint8_t      next_hop;  ///< Send via this next hop address\n\tuint8_t      state;     ///< State of this route, one of RouteState\n    } RoutingTableEntry;\n\n    /// Constructor. \n    /// \\param[in] driver The RadioHead driver to use to transport messages.\n    /// \\param[in] thisAddress The address to assign to this node. Defaults to 0\n    RHRouter(RHGenericDriver& driver, uint8_t thisAddress = 0);\n\n    /// Initialises this instance and the radio module connected to it.\n    /// Overrides the init() function in RH.\n    /// Sets max_hops to the default of RH_DEFAULT_MAX_HOPS (30)\n    bool init();\n\n    /// Sets the max_hops to the given value\n    /// This controls the maximum number of hops allowed between source and destination nodes\n    /// Messages that are not delivered by the time their HOPS field exceeds max_hops on a \n    /// routing node will be dropped and ignored.\n    /// \\param [in] max_hops The new value for max_hops\n    void setMaxHops(uint8_t max_hops);\n\n    /// Adds a route to the local routing table, or updates it if already present.\n    /// If there is not enough room the oldest (first) route will be deleted by calling retireOldestRoute().\n    /// \\param [in] dest The destination node address. RH_BROADCAST_ADDRESS is permitted.\n    /// \\param [in] next_hop The address of the next hop to send messages destined for dest\n    /// \\param [in] state The satte of the route. Defaults to Valid\n    void addRouteTo(uint8_t dest, uint8_t next_hop, uint8_t state = Valid);\n\n    /// Finds and returns a RoutingTableEntry for the given destination node\n    /// \\param [in] dest The desired destination node address.\n    /// \\return pointer to a RoutingTableEntry for dest\n    RoutingTableEntry* getRouteTo(uint8_t dest);\n\n    /// Deletes from the local routing table any route for the destination node.\n    /// \\param [in] dest The destination node address\n    /// \\return true if the route was present\n    bool deleteRouteTo(uint8_t dest);\n\n    /// Deletes the oldest (first) route from the \n    /// local routing table\n    void retireOldestRoute();\n\n    /// Clears all entries from the \n    /// local routing table\n    void clearRoutingTable();\n\n    /// If RH_HAVE_SERIAL is defined, this will print out the contents of the local \n    /// routing table using Serial\n    void printRoutingTable();\n\n    /// Sends a message to the destination node. Initialises the RHRouter message header \n    /// (the SOURCE address is set to the address of this node, HOPS to 0) and calls \n    /// route() which looks up in the routing table the next hop to deliver to and sends the \n    /// message to the next hop. Waits for an acknowledgement from the next hop \n    /// (but not from the destination node (if that is different).\n    /// \\param [in] buf The application message data\n    /// \\param [in] len Number of octets in the application message data. 0 is permitted\n    /// \\param [in] dest The destination node address\n    /// \\param [in] flags Optional flags for use by subclasses or application layer, \n    ///             delivered end-to-end to the dest address. The receiver can recover the flags with recvFromAck().\n    /// \\return The result code:\n    ///         - RH_ROUTER_ERROR_NONE Message was routed and delivered to the next hop \n    ///           (not necessarily to the final dest address)\n    ///         - RH_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table\n    ///         - RH_ROUTER_ERROR_UNABLE_TO_DELIVER Not able to deliver to the next hop \n    ///           (usually because it dod not acknowledge due to being off the air or out of range\n    uint8_t sendtoWait(uint8_t* buf, uint8_t len, uint8_t dest, uint8_t flags = 0);\n\n    /// Similar to sendtoWait() above, but spoofs the source address.\n    /// For internal use only during routing\n    /// \\param [in] buf The application message data.\n    /// \\param [in] len Number of octets in the application message data. 0 is permitted.\n    /// \\param [in] dest The destination node address.\n    /// \\param [in] source The (fake) originating node address.\n    /// \\param [in] flags Optional flags for use by subclasses or application layer, \n    ///             delivered end-to-end to the dest address. The receiver can recover the flags with recvFromAck().\n    /// \\return The result code:\n    ///         - RH_ROUTER_ERROR_NONE Message was routed and deliverd to the next hop \n    ///           (not necessarily to the final dest address)\n    ///         - RH_ROUTER_ERROR_NO_ROUTE There was no route for dest in the local routing table\n    ///         - RH_ROUTER_ERROR_UNABLE_TO_DELIVER Noyt able to deliver to the next hop \n    ///           (usually because it dod not acknowledge due to being off the air or out of range\n    uint8_t sendtoFromSourceWait(uint8_t* buf, uint8_t len, uint8_t dest, uint8_t source, uint8_t flags = 0);\n\n    /// Starts the receiver if it is not running already.\n    /// If there is a valid message available for this node (or RH_BROADCAST_ADDRESS), \n    /// send an acknowledgement to the last hop\n    /// address (blocking until this is complete), then copy the application message payload data\n    /// to buf and return true\n    /// else return false. \n    /// If a message is copied, *len is set to the length..\n    /// If from is not NULL, the originator SOURCE address is placed in *source.\n    /// If to is not NULL, the DEST address is placed in *dest. This might be this nodes address or \n    /// RH_BROADCAST_ADDRESS. \n    /// This is the preferred function for getting messages addressed to this node.\n    /// If the message is not a broadcast, acknowledge to the sender before returning.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Available space in buf. Set to the actual number of octets copied.\n    /// \\param[in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address\n    /// \\param[in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address\n    /// \\param[in] id If present and not NULL, the referenced uint8_t will be set to the ID\n    /// \\param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS\n    /// (not just those addressed to this node).\n    /// \\return true if a valid message was recvived for this node copied to buf\n    bool recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* source = NULL, uint8_t* dest = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);\n\n    /// Starts the receiver if it is not running already.\n    /// Similar to recvfromAck(), this will block until either a valid message available for this node\n    /// or the timeout expires. \n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Available space in buf. Set to the actual number of octets copied.\n    /// \\param[in] timeout Maximum time to wait in milliseconds\n    /// \\param[in] source If present and not NULL, the referenced uint8_t will be set to the SOURCE address\n    /// \\param[in] dest If present and not NULL, the referenced uint8_t will be set to the DEST address\n    /// \\param[in] id If present and not NULL, the referenced uint8_t will be set to the ID\n    /// \\param[in] flags If present and not NULL, the referenced uint8_t will be set to the FLAGS\n    /// (not just those addressed to this node).\n    /// \\return true if a valid message was copied to buf\n    bool recvfromAckTimeout(uint8_t* buf, uint8_t* len,  uint16_t timeout, uint8_t* source = NULL, uint8_t* dest = NULL, uint8_t* id = NULL, uint8_t* flags = NULL);\n\nprotected:\n\n    /// Lets sublasses peek at messages going \n    /// past before routing or local delivery.\n    /// Called by recvfromAck() immediately after it gets the message from RHReliableDatagram\n    /// \\param [in] message Pointer to the RHRouter message that was received.\n    /// \\param [in] messageLen Length of message in octets\n    virtual void peekAtMessage(RoutedMessage* message, uint8_t messageLen);\n\n    /// Finds the next-hop route and sends the message via RHReliableDatagram::sendtoWait().\n    /// This is virtual, which lets subclasses override or intercept the route() function.\n    /// Called by sendtoWait after the message header has been filled in.\n    /// \\param [in] message Pointer to the RHRouter message to be sent.\n    /// \\param [in] messageLen Length of message in octets\n    virtual uint8_t route(RoutedMessage* message, uint8_t messageLen);\n\n    /// Deletes a specific rout entry from therouting table\n    /// \\param [in] index The 0 based index of the routing table entry to delete\n    void deleteRoute(uint8_t index);\n\n    /// The last end-to-end sequence number to be used\n    /// Defaults to 0\n    uint8_t _lastE2ESequenceNumber;\n\n    /// The maximum number of hops permitted in routed messages.\n    /// If a routed message would exceed this number of hops it is dropped and ignored.\n    uint8_t              _max_hops;\n\nprivate:\n\n    /// Temporary mesage buffer\n    static RoutedMessage _tmpMessage;\n\n    /// Local routing table\n    RoutingTableEntry    _routes[RH_ROUTING_TABLE_SIZE];\n};\n\n/// @example rf22_router_client.pde\n/// @example rf22_router_server1.pde\n/// @example rf22_router_server2.pde\n/// @example rf22_router_server3.pde\n#endif\n\n"
  },
  {
    "path": "RHSPIDriver.cpp",
    "content": "// RHSPIDriver.cpp\n//\n// Copyright (C) 2014 Mike McCauley\n// $Id: RHSPIDriver.cpp,v 1.10 2015/12/16 04:55:33 mikem Exp $\n\n#include <RHSPIDriver.h>\n\nRHSPIDriver::RHSPIDriver(uint8_t slaveSelectPin, RHGenericSPI& spi)\n    : \n    _spi(spi),\n    _slaveSelectPin(slaveSelectPin)\n{\n}\n\nbool RHSPIDriver::init()\n{\n    // start the SPI library with the default speeds etc:\n    // On Arduino Due this defaults to SPI1 on the central group of 6 SPI pins\n    _spi.begin();\n\n    // Initialise the slave select pin\n    // On Maple, this must be _after_ spi.begin\n    pinMode(_slaveSelectPin, OUTPUT);\n    digitalWrite(_slaveSelectPin, HIGH);\n\n    delay(100);\n    return true;\n}\n\nuint8_t RHSPIDriver::spiRead(uint8_t reg)\n{\n    uint8_t val;\n    RPI_CE0_CE1_FIX;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    _spi.transfer(reg & ~RH_SPI_WRITE_MASK); // Send the address with the write mask off\n    val = _spi.transfer(0); // The written value is ignored, reg value is read\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return val;\n}\n\nuint8_t RHSPIDriver::spiWrite(uint8_t reg, uint8_t val)\n{\n    uint8_t status = 0;\n    RPI_CE0_CE1_FIX;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    status = _spi.transfer(reg | RH_SPI_WRITE_MASK); // Send the address with the write mask on\n    _spi.transfer(val); // New value follows\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return status;\n}\n\nuint8_t RHSPIDriver::spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len)\n{\n    uint8_t status = 0;\n    RPI_CE0_CE1_FIX;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    status = _spi.transfer(reg & ~RH_SPI_WRITE_MASK); // Send the start address with the write mask off\n    while (len--)\n\t*dest++ = _spi.transfer(0);\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return status;\n}\n\nuint8_t RHSPIDriver::spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len)\n{\n    uint8_t status = 0;\n    RPI_CE0_CE1_FIX;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    status = _spi.transfer(reg | RH_SPI_WRITE_MASK); // Send the start address with the write mask on\n    while (len--)\n\t_spi.transfer(*src++);\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return status;\n}\n\nvoid RHSPIDriver::setSlaveSelectPin(uint8_t slaveSelectPin)\n{\n    _slaveSelectPin = slaveSelectPin;\n}\n "
  },
  {
    "path": "RHSPIDriver.h",
    "content": "// RHSPIDriver.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2014 Mike McCauley\n// $Id: RHSPIDriver.h,v 1.10 2015/12/16 04:55:33 mikem Exp $\n\n#ifndef RHSPIDriver_h\n#define RHSPIDriver_h\n\n#include <RHGenericDriver.h>\n#include <RHHardwareSPI.h>\n\n// This is the bit in the SPI address that marks it as a write\n#define RH_SPI_WRITE_MASK 0x80\n\n#if (RH_PLATFORM == RH_PLATFORM_RASPI)\n#define RPI_CE0_CE1_FIX { \\\n          if (_slaveSelectPin!=7) {   \\\n            bcm2835_gpio_fsel(7,BCM2835_GPIO_FSEL_OUTP); \\\n            bcm2835_gpio_write(7,HIGH); \\\n          }                           \\\n          if (_slaveSelectPin!=8) {   \\\n            bcm2835_gpio_fsel(8,BCM2835_GPIO_FSEL_OUTP); \\\n            bcm2835_gpio_write(8,HIGH); \\\n          }                           \\\n        }\n#else\n#define RPI_CE0_CE1_FIX {}\n#endif\n\n\nclass RHGenericSPI;\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHSPIDriver RHSPIDriver.h <RHSPIDriver.h>\n/// \\brief Base class for a RadioHead drivers that use the SPI bus\n/// to communicate with its transport hardware.\n///\n/// This class can be subclassed by Drivers that require to use the SPI bus.\n/// It can be configured to use either the RHHardwareSPI class (if there is one available on the platform)\n/// of the bitbanged RHSoftwareSPI class. The default behaviour is to use a pre-instantiated built-in RHHardwareSPI\n/// interface.\n///\n/// SPI bus access is protected by ATOMIC_BLOCK_START and ATOMIC_BLOCK_END, which will ensure interrupts \n/// are disabled during access.\n/// \n/// The read and write routines implement commonly used SPI conventions: specifically that the MSB\n/// of the first byte transmitted indicates that it is a write and the remaining bits indicate the rehgister to access)\n/// This can be overriden \n/// in subclasses if necessaryor an alternative class, RHNRFSPIDriver can be used to access devices like \n/// Nordic NRF series radios, which have different requirements.\n///\n/// Application developers are not expected to instantiate this class directly: \n/// it is for the use of Driver developers.\nclass RHSPIDriver : public RHGenericDriver\n{\npublic:\n    /// Constructor\n    /// \\param[in] slaveSelectPin The controler pin to use to select the desired SPI device. This pin will be driven LOW\n    /// during SPI communications with the SPI device that uis iused by this Driver.\n    /// \\param[in] spi Reference to the SPI interface to use. The default is to use a default built-in Hardware interface.\n    RHSPIDriver(uint8_t slaveSelectPin = SS, RHGenericSPI& spi = hardware_spi);\n\n    /// Initialise the Driver transport hardware and software.\n    /// Make sure the Driver is properly configured before calling init().\n    /// \\return true if initialisation succeeded.\n    bool init();\n\n    /// Reads a single register from the SPI device\n    /// \\param[in] reg Register number\n    /// \\return The value of the register\n    uint8_t        spiRead(uint8_t reg);\n\n    /// Writes a single byte to the SPI device\n    /// \\param[in] reg Register number\n    /// \\param[in] val The value to write\n    /// \\return Some devices return a status byte during the first data transfer. This byte is returned.\n    ///  it may or may not be meaningfule depending on the the type of device being accessed.\n    uint8_t           spiWrite(uint8_t reg, uint8_t val);\n\n    /// Reads a number of consecutive registers from the SPI device using burst read mode\n    /// \\param[in] reg Register number of the first register\n    /// \\param[in] dest Array to write the register values to. Must be at least len bytes\n    /// \\param[in] len Number of bytes to read\n    /// \\return Some devices return a status byte during the first data transfer. This byte is returned.\n    ///  it may or may not be meaningfule depending on the the type of device being accessed.\n    uint8_t           spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);\n\n    /// Write a number of consecutive registers using burst write mode\n    /// \\param[in] reg Register number of the first register\n    /// \\param[in] src Array of new register values to write. Must be at least len bytes\n    /// \\param[in] len Number of bytes to write\n    /// \\return Some devices return a status byte during the first data transfer. This byte is returned.\n    ///  it may or may not be meaningfule depending on the the type of device being accessed.\n    uint8_t           spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len);\n\n    /// Set or change the pin to be used for SPI slave select.\n    /// This can be called at any time to change the\n    /// pin that will be used for slave select in subsquent SPI operations.\n    /// \\param[in] slaveSelectPin The pin to use\n    void setSlaveSelectPin(uint8_t slaveSelectPin);\n\nprotected:\n    /// Reference to the RHGenericSPI instance to use to transfer data with teh SPI device\n    RHGenericSPI&       _spi;\n\n    /// The pin number of the Slave Select pin that is used to select the desired device.\n    uint8_t             _slaveSelectPin;\n};\n\n#endif\n"
  },
  {
    "path": "RHSoftwareSPI.cpp",
    "content": "// SoftwareSPI.cpp\n// Author: Chris Lapa (chris@lapa.com.au)\n// Copyright (C) 2014 Chris Lapa\n// Contributed by Chris Lapa\n\n#include <RHSoftwareSPI.h>\n\nRHSoftwareSPI::RHSoftwareSPI(Frequency frequency, BitOrder bitOrder, DataMode dataMode)\n    :\n    RHGenericSPI(frequency, bitOrder, dataMode)\n{\n    setPins(12, 11, 13);\n}\n\n// Caution: on Arduino Uno and many other CPUs, digitalWrite is quite slow, taking about 4us\n// digitalWrite is also slow, taking about 3.5us\n// resulting in very slow SPI bus speeds using this technique, up to about 120us per octet of transfer\nuint8_t RHSoftwareSPI::transfer(uint8_t data) \n{\n    uint8_t readData;\n    uint8_t writeData;\n    uint8_t builtReturn;\n    uint8_t mask;\n    \n    if (_bitOrder == BitOrderMSBFirst)\n    {\n\tmask = 0x80;\n    }\n    else\n    {\n\tmask = 0x01;\n    }\n    builtReturn = 0;\n    readData = 0;\n\n    for (uint8_t count=0; count<8; count++)\n    {\n\tif (data & mask)\n\t{\n\t    writeData = HIGH;\n\t}\n\telse\n\t{\n\t    writeData = LOW;\n\t}\n\n\tif (_clockPhase == 1)\n\t{\n\t    // CPHA=1, miso/mosi changing state now\n\t    digitalWrite(_mosi, writeData);\n\t    digitalWrite(_sck, ~_clockPolarity);\n\t    delayPeriod();\n\n\t    // CPHA=1, miso/mosi stable now\n\t    readData = digitalRead(_miso);\n\t    digitalWrite(_sck, _clockPolarity);\n\t    delayPeriod();\n\t}\n\telse\n\t{\n\t    // CPHA=0, miso/mosi changing state now\n\t    digitalWrite(_mosi, writeData);\n\t    digitalWrite(_sck, _clockPolarity);\n\t    delayPeriod();\n\n\t    // CPHA=0, miso/mosi stable now\n\t    readData = digitalRead(_miso);\n\t    digitalWrite(_sck, ~_clockPolarity);\n\t    delayPeriod();\n\t}\n\t\t\t\n\tif (_bitOrder == BitOrderMSBFirst)\n\t{\n\t    mask >>= 1;\n\t    builtReturn |= (readData << (7 - count));\n\t}\n\telse\n\t{\n\t    mask <<= 1;\n\t    builtReturn |= (readData << count);\n\t}\n    }\n\n    digitalWrite(_sck, _clockPolarity);\n\n    return builtReturn;\n}\n\n/// Initialise the SPI library\nvoid RHSoftwareSPI::begin()\n{\n    if (_dataMode == DataMode0 ||\n\t_dataMode == DataMode1)\n    {\n\t_clockPolarity = LOW;\n    }\n    else\n    {\n\t_clockPolarity = HIGH;\n    }\n\t\t\n    if (_dataMode == DataMode0 ||\n\t_dataMode == DataMode2)\n    {\n\t_clockPhase = 0;\n    }\n    else\n    {\n\t_clockPhase = 1;\n    }\n    digitalWrite(_sck, _clockPolarity);\n\n    // Caution: these counts assume that digitalWrite is very fast, which is usually not true\n    switch (_frequency)\n    {\n\tcase Frequency1MHz:\n\t    _delayCounts = 8;\n\t    break;\n\n\tcase Frequency2MHz:\n\t    _delayCounts = 4;\n\t    break;\n\n\tcase Frequency4MHz:\n\t    _delayCounts = 2;\n\t    break;\n\n\tcase Frequency8MHz:\n\t    _delayCounts = 1;\n\t    break;\n\n\tcase Frequency16MHz:\n\t    _delayCounts = 0;\n\t    break;\n    }\n}\n\n/// Disables the SPI bus usually, in this case\n/// there is no hardware controller to disable.\nvoid RHSoftwareSPI::end() { }\n\n/// Sets the pins used by this SoftwareSPIClass instance.\n/// \\param[in] miso master in slave out pin used\n/// \\param[in] mosi master out slave in pin used\n/// \\param[in] sck clock pin used\nvoid RHSoftwareSPI::setPins(uint8_t miso, uint8_t mosi, uint8_t sck)\n{\n    _miso = miso;\n    _mosi = mosi;\n    _sck = sck;\n\n    pinMode(_miso, INPUT);\n    pinMode(_mosi, OUTPUT);\n    pinMode(_sck, OUTPUT);\n    digitalWrite(_sck, _clockPolarity);\n}\n\n\nvoid RHSoftwareSPI::delayPeriod()\n{\n    for (uint8_t count = 0; count < _delayCounts; count++)\n    {\n\t__asm__ __volatile__ (\"nop\");\n    }\n}\n\n"
  },
  {
    "path": "RHSoftwareSPI.h",
    "content": "// SoftwareSPI.h\n// Author: Chris Lapa (chris@lapa.com.au)\n// Copyright (C) 2014 Chris Lapa\n// Contributed by Chris Lapa\n\n#ifndef RHSoftwareSPI_h\n#define RHSoftwareSPI_h\n\n#include <RHGenericSPI.h>\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RHSoftwareSPI RHSoftwareSPI.h <RHSoftwareSPI.h>\n/// \\brief Encapsulate a software SPI interface\n///\n/// This concrete subclass of RHGenericSPI enapsulates a bit-banged software SPI interface.\n/// Caution: this software SPI interface will be much slower than hardware SPI on most\n/// platforms.\n///\n/// \\par Usage\n///\n/// Usage varies slightly depending on what driver you are using.\n///\n/// For RF22, for example:\n/// \\code\n/// #include <RHSoftwareSPI.h>\n/// RHSoftwareSPI spi;\n/// RH_RF22 driver(SS, 2, spi);\n/// RHReliableDatagram(driver, CLIENT_ADDRESS);\n/// void setup()\n/// {\n///    spi.setPins(6, 5, 7); // Or whatever SPI pins you need\n///    ....\n/// }\n/// \\endcode\nclass RHSoftwareSPI : public RHGenericSPI \n{\npublic:\n\n    /// Constructor\n    /// Creates an instance of a bit-banged software SPI interface.\n    /// Sets the SPI pins to the defaults of \n    /// MISO = 12, MOSI = 11, SCK = 13. If you need other assigments, call setPins() before\n    /// calling manager.init() or driver.init().\n    /// \\param[in] frequency One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency\n    /// is mapped to the closest available bus frequency on the platform. CAUTION: the achieved\n    /// frequency will almost certainly be very much slower on most platforms. eg on Arduino Uno, the\n    /// the clock rate is likely to be at best around 46kHz.\n    /// \\param[in] bitOrder Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or \n    /// RHGenericSPI::BitOrderLSBFirst.\n    /// \\param[in] dataMode Selects the SPI bus data mode. One of RHGenericSPI::DataMode\n    RHSoftwareSPI(Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);\n\n    /// Transfer a single octet to and from the SPI interface\n    /// \\param[in] data The octet to send\n    /// \\return The octet read from SPI while the data octet was sent.\n    uint8_t transfer(uint8_t data);\n\n    /// Initialise the software SPI library\n    /// Call this after configuring the SPI interface and before using it to transfer data.\n    /// Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high. \n    void begin();\n\n    /// Disables the SPI bus usually, in this case\n    /// there is no hardware controller to disable.\n    void end();\n\n    /// Sets the pins used by this SoftwareSPIClass instance.\n    /// The defaults are: MISO = 12, MOSI = 11, SCK = 13.\n    /// \\param[in] miso master in slave out pin used\n    /// \\param[in] mosi master out slave in pin used\n    /// \\param[in] sck clock pin used\n    void setPins(uint8_t miso = 12, uint8_t mosi = 11, uint8_t sck = 13);\n\nprivate:\n\n    /// Delay routine for bus timing.\n    void delayPeriod();\n\nprivate:\n    uint8_t _miso;\n    uint8_t _mosi;\n    uint8_t _sck;\n    uint8_t _bitOrder;\n    uint8_t _delayCounts;\n    uint8_t _clockPolarity;\n    uint8_t _clockPhase;\n};\n\n#endif\n"
  },
  {
    "path": "RHTcpProtocol.h",
    "content": "// RH_TcpProtocol.h\n// Author: Mike McCauley (mikem@aierspayce.com)\n// Definition of protocol messages sent and received by RH_TCP\n// Copyright (C) 2014 Mike McCauley\n// $Id: RHTcpProtocol.h,v 1.3 2014/05/22 06:07:09 mikem Exp $\n\n/// This file contains the definitions of message structures passed between\n/// RH_TCP and the etherSimulator\n#ifndef RH_TcpProtocol_h\n#define RH_TcpProtocol_h\n\n#define RH_TCP_MESSAGE_TYPE_NOP               0\n#define RH_TCP_MESSAGE_TYPE_THISADDRESS       1\n#define RH_TCP_MESSAGE_TYPE_PACKET            2\n\n// Maximum message length (including the headers) we are willing to support\n#define RH_TCP_MAX_PAYLOAD_LEN 255\n\n// The length of the headers we add.\n// The headers are inside the RF69's payload and are therefore encrypted if encryption is enabled\n#define RH_TCP_HEADER_LEN 4\n\n\n// This is the maximum message length that can be supported by this protocol. \n#define RH_TCP_MAX_MESSAGE_LEN (RH_TCP_MAX_PAYLOAD_LEN - RH_TCP_HEADER_LEN)\n\n#pragma pack(push, 1) // No padding\n\n/// \\brief Generic RH_TCP simulator message structure\ntypedef struct\n{\n    uint32_t        length; ///< Number of octets following, in network byte order\n    uint8_t         payload[RH_TCP_MAX_PAYLOAD_LEN + 1]; ///< Payload\n}   RHTcpMessage;\n\n/// \\brief Generic RH_TCP  message structure with message type\ntypedef struct\n{\n    uint32_t        length; ///< Number of octets following, in network byte order\n    uint8_t         type;  ///< One of RH_TCP_MESSAGE_TYPE_*\n    uint8_t         payload[RH_TCP_MAX_PAYLOAD_LEN]; ///< Payload\n}   RHTcpTypeMessage;\n\n/// \\brief RH_TCP message Notifies the server of thisAddress of this client\ntypedef struct\n{\n    uint32_t        length; ///< Number of octets following, in network byte order\n    uint8_t         type;   ///< == RH_TCP_MESSAGE_TYPE_THISADDRESS\n    uint8_t         thisAddress; ///< Node address\n}   RHTcpThisAddress;\n\n/// \\brief RH_TCP radio message passed to or from the simulator\ntypedef struct\n{\n    uint32_t        length; ///< Number of octets following, in network byte order\n    uint8_t         type;   ///< == RH_TCP_MESSAGE_TYPE_PACKET\n    uint8_t         to;     ///< Node address of the recipient\n    uint8_t         from;   ///< Node address of the sender\n    uint8_t         id;     ///< Message sequence number\n    uint8_t         flags;  ///< Message flags\n    uint8_t         payload[RH_TCP_MAX_MESSAGE_LEN]; ///< 0 or more, length deduced from length above\n}   RHTcpPacket;\n\n#pragma pack(pop)\n\n#endif\n"
  },
  {
    "path": "RH_ASK.cpp",
    "content": "// RH_ASK.cpp\n//\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_ASK.cpp,v 1.20 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_ASK.h>\n#include <RHCRC.h>\n\n#if (RH_PLATFORM == RH_PLATFORM_STM32) // Maple etc\nHardwareTimer timer(MAPLE_TIMER);\n\n#endif\n\n#if (RH_PLATFORM == RH_PLATFORM_ESP8266)\n    // interrupt handler and related code must be in RAM on ESP8266,\n    // according to issue #46.\n    #define INTERRUPT_ATTR ICACHE_RAM_ATTR\n#else\n    #define INTERRUPT_ATTR\n#endif\n\n// RH_ASK on Arduino uses Timer 1 to generate interrupts 8 times per bit interval\n// Define RH_ASK_ARDUINO_USE_TIMER2 if you want to use Timer 2 instead of Timer 1 on Arduino\n// You may need this to work around other librraies that insist on using timer 1\n// Should be moved to header file\n//#define RH_ASK_ARDUINO_USE_TIMER2\n\n// Interrupt handler uses this to find the most recently initialised instance of this driver\nstatic RH_ASK* thisASKDriver;\n\n// 4 bit to 6 bit symbol converter table\n// Used to convert the high and low nybbles of the transmitted data\n// into 6 bit symbols for transmission. Each 6-bit symbol has 3 1s and 3 0s \n// with at most 3 consecutive identical bits\nstatic uint8_t symbols[] =\n{\n    0xd,  0xe,  0x13, 0x15, 0x16, 0x19, 0x1a, 0x1c, \n    0x23, 0x25, 0x26, 0x29, 0x2a, 0x2c, 0x32, 0x34\n};\n\n// This is the value of the start symbol after 6-bit conversion and nybble swapping\n#define RH_ASK_START_SYMBOL 0xb38\n\nRH_ASK::RH_ASK(uint16_t speed, uint8_t rxPin, uint8_t txPin, uint8_t pttPin, bool pttInverted)\n    :\n    _speed(speed),\n    _rxPin(rxPin),\n    _txPin(txPin),\n    _pttPin(pttPin),\n    _pttInverted(pttInverted),\n    _rxInverted(false)\n{\n    // Initialise the first 8 nibbles of the tx buffer to be the standard\n    // preamble. We will append messages after that. 0x38, 0x2c is the start symbol before\n    // 6-bit conversion to RH_ASK_START_SYMBOL\n    uint8_t preamble[RH_ASK_PREAMBLE_LEN] = {0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x38, 0x2c};\n    memcpy(_txBuf, preamble, sizeof(preamble));\n}\n\nbool RH_ASK::init()\n{\n    if (!RHGenericDriver::init())\n\treturn false;\n    thisASKDriver = this;\n\n#if (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)\n #ifdef RH_ASK_PTT_PIN \t\t\t\t\n    RH_ASK_PTT_DDR  |=  (1<<RH_ASK_PTT_PIN); \n    RH_ASK_TX_DDR   |=  (1<<RH_ASK_TX_PIN);\n    RH_ASK_RX_DDR   &= ~(1<<RH_ASK_RX_PIN);\n #else\n    RH_ASK_TX_DDR   |=  (1<<RH_ASK_TX_PIN);\n    RH_ASK_RX_DDR   &= ~(1<<RH_ASK_RX_PIN);\n #endif\n#else\n    // Set up digital IO pins for arduino\n    pinMode(_txPin, OUTPUT);\n    pinMode(_rxPin, INPUT);\n    pinMode(_pttPin, OUTPUT);\n#endif\n\n    // Ready to go\n    setModeIdle();\n    timerSetup();\n\n    return true;\n}\n\n// Put these prescaler structs in PROGMEM, not on the stack\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) || (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)\n #if defined(RH_ASK_ARDUINO_USE_TIMER2)\n // Timer 2 has different prescalers\n PROGMEM static const uint16_t prescalers[] = {0, 1, 8, 32, 64, 128, 256, 3333}; \n #else\n PROGMEM static const uint16_t prescalers[] = {0, 1, 8, 64, 256, 1024, 3333}; \n #endif\n #define NUM_PRESCALERS (sizeof(prescalers) / sizeof( uint16_t))\n#endif\n\n// Common function for setting timer ticks @ prescaler values for speed\n// Returns prescaler index into {0, 1, 8, 64, 256, 1024} array\n// and sets nticks to compare-match value if lower than max_ticks\n// returns 0 & nticks = 0 on fault\nuint8_t RH_ASK::timerCalc(uint16_t speed, uint16_t max_ticks, uint16_t *nticks)\n{\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) || (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)\n    // Clock divider (prescaler) values - 0/3333: error flag\n    uint8_t prescaler;     // index into array & return bit value\n    unsigned long ulticks; // calculate by ntick overflow\n\n    // Div-by-zero protection\n    if (speed == 0)\n    {\n        // signal fault\n        *nticks = 0;\n        return 0;\n    }\n\n    // test increasing prescaler (divisor), decreasing ulticks until no overflow\n    // 1/Fraction of second needed to xmit one bit\n    unsigned long inv_bit_time = ((unsigned long)speed) * 8;\n    for (prescaler=1; prescaler < NUM_PRESCALERS; prescaler += 1)\n    {\n\t// Integer arithmetic courtesy Jim Remington\n\t// 1/Amount of time per CPU clock tick (in seconds)\n\tuint16_t prescalerValue;\n\tmemcpy_P(&prescalerValue, &prescalers[prescaler], sizeof(uint16_t));\n        unsigned long inv_clock_time = F_CPU / ((unsigned long)prescalerValue);\n        // number of prescaled ticks needed to handle bit time @ speed\n        ulticks = inv_clock_time / inv_bit_time;\n\n        // Test if ulticks fits in nticks bitwidth (with 1-tick safety margin)\n        if ((ulticks > 1) && (ulticks < max_ticks))\n            break; // found prescaler\n\n        // Won't fit, check with next prescaler value\n    }\n\n\n    // Check for error\n    if ((prescaler == 6) || (ulticks < 2) || (ulticks > max_ticks))\n    {\n        // signal fault\n        *nticks = 0;\n        return 0;\n    }\n\n    *nticks = ulticks;\n    return prescaler;\n#else\n    return 0; // not implemented or needed on other platforms\n#endif\n}\n\n// The idea here is to get 8 timer interrupts per bit period\nvoid RH_ASK::timerSetup()\n{\n#if (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)\n    uint16_t nticks;\n    uint8_t prescaler = timerCalc(_speed, (uint16_t)-1, &nticks);\n    if (!prescaler) return;\n    _COMB(TCCR,RH_ASK_TIMER_INDEX,A)= 0;\t\t\t\t\t\n    _COMB(TCCR,RH_ASK_TIMER_INDEX,B)= _BV(WGM12);\t\t\t\t\n    _COMB(TCCR,RH_ASK_TIMER_INDEX,B)|= prescaler;\t\t\t\t\n    _COMB(OCR,RH_ASK_TIMER_INDEX,A)= nticks;\t\t\t\t\t\n    _COMB(TI,MSK,RH_ASK_TIMER_INDEX)|= _BV(_COMB(OCIE,RH_ASK_TIMER_INDEX,A));\n\n#elif (RH_PLATFORM == RH_PLATFORM_MSP430) // LaunchPad specific\n    // Calculate the counter overflow count based on the required bit speed\n    // and CPU clock rate\n    uint16_t ocr1a = (F_CPU / 8UL) / _speed;\n    \n    // This code is for Energia/MSP430\n    TA0CCR0 = ocr1a;\t\t\t\t// Ticks for 62,5 us\n    TA0CTL = TASSEL_2 + MC_1;       // SMCLK, up mode\n    TA0CCTL0 |= CCIE;               // CCR0 interrupt enabled\n\n#elif (RH_PLATFORM == RH_PLATFORM_ARDUINO) // Arduino specific\n    uint16_t nticks; // number of prescaled ticks needed\n    uint8_t prescaler; // Bit values for CS0[2:0]\n\n #ifdef RH_PLATFORM_ATTINY\n    // figure out prescaler value and counter match value\n    // REVISIT: does not correctly handle 1MHz clock speeds, only works with 8MHz clocks\n    // At 1MHz clock, get 1/8 of the expected baud rate\n    prescaler = timerCalc(_speed, (uint8_t)-1, &nticks);\n    if (!prescaler)\n        return; // fault\n\n    TCCR0A = 0;\n    TCCR0A = _BV(WGM01); // Turn on CTC mode / Output Compare pins disconnected\n\n    // convert prescaler index to TCCRnB prescaler bits CS00, CS01, CS02\n    TCCR0B = 0;\n    TCCR0B = prescaler; // set CS00, CS01, CS02 (other bits not needed)\n\n\n    // Number of ticks to count before firing interrupt\n    OCR0A = uint8_t(nticks);\n\n    // Set mask to fire interrupt when OCF0A bit is set in TIFR0\n   #ifdef TIMSK0\n    // ATtiny84\n    TIMSK0 |= _BV(OCIE0A);\n   #else\n    // ATtiny85\n    TIMSK |= _BV(OCIE0A);\n   #endif\n\n\n #elif defined(__arm__) && defined(CORE_TEENSY)\n    // on Teensy 3.0 (32 bit ARM), use an interval timer\n    IntervalTimer *t = new IntervalTimer();\n    void TIMER1_COMPA_vect(void);\n    t->begin(TIMER1_COMPA_vect, 125000 / _speed);\n\n #elif defined (__arm__) && defined(ARDUINO_ARCH_SAMD)\n    // Arduino Zero\n    #define RH_ASK_ZERO_TIMER TC3\n    // Clock speed is 48MHz, prescaler of 64 gives a good range of available speeds vs precision\n    #define RH_ASK_ZERO_PRESCALER 64\n    #define RH_ASK_ZERO_TIMER_IRQ TC3_IRQn\n\n    // Enable clock for TC\n    REG_GCLK_CLKCTRL = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_TCC2_TC3)) ;\n    while ( GCLK->STATUS.bit.SYNCBUSY == 1 ); // wait for sync\n    \n    // The type cast must fit with the selected timer mode\n    TcCount16* TC = (TcCount16*)RH_ASK_ZERO_TIMER; // get timer struct\n    \n    TC->CTRLA.reg &= ~TC_CTRLA_ENABLE;   // Disable TC\n    while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync\n    \n    TC->CTRLA.reg |= TC_CTRLA_MODE_COUNT16;  // Set Timer counter Mode to 16 bits\n    while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync\n    TC->CTRLA.reg |= TC_CTRLA_WAVEGEN_MFRQ; // Set TC as Match Frequency\n    while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync\n\n    // Compute the count required to achieve the requested baud (with 8 interrupts per bit)\n    uint32_t rc = (VARIANT_MCK / _speed) / RH_ASK_ZERO_PRESCALER / 8;\n    \n    TC->CTRLA.reg |= TC_CTRLA_PRESCALER_DIV64;   // Set prescaler to agree with RH_ASK_ZERO_PRESCALER\n    while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync\n    \n    TC->CC[0].reg = rc; // FIXME\n    while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync\n    \n    // Interrupts\n    TC->INTENSET.reg = 0;              // disable all interrupts\n    TC->INTENSET.bit.MC0 = 1;          // enable compare match to CC0\n    \n    // Enable InterruptVector\n    NVIC_ClearPendingIRQ(RH_ASK_ZERO_TIMER_IRQ);\n    NVIC_EnableIRQ(RH_ASK_ZERO_TIMER_IRQ);\n    \n    // Enable TC\n    TC->CTRLA.reg |= TC_CTRLA_ENABLE;\n    while (TC->STATUS.bit.SYNCBUSY == 1); // wait for sync\n    \n #elif defined(__arm__) && defined(ARDUINO_SAM_DUE)\n    // Arduino Due\n    // Clock speed is 84MHz\n    // Due has 9 timers in 3 blocks of 3.\n    // We use timer 1 TC1_IRQn on TC0 channel 1, since timers 0, 2, 3, 4, 5 are used by the Servo library\n    #define RH_ASK_DUE_TIMER TC0\n    #define RH_ASK_DUE_TIMER_CHANNEL 1\n    #define RH_ASK_DUE_TIMER_IRQ TC1_IRQn\n    pmc_set_writeprotect(false);\n    pmc_enable_periph_clk(RH_ASK_DUE_TIMER_IRQ);\n    \n    // Clock speed 4 can handle all reasonable _speeds we might ask for. Its divisor is 128\n    // and we want 8 interrupts per bit\n    uint32_t rc = (VARIANT_MCK / _speed) / 128 / 8;\n    TC_Configure(RH_ASK_DUE_TIMER, RH_ASK_DUE_TIMER_CHANNEL, \n\t\t TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);\n    TC_SetRC(RH_ASK_DUE_TIMER, RH_ASK_DUE_TIMER_CHANNEL, rc);\n    // Enable the RC Compare Interrupt\n    RH_ASK_DUE_TIMER->TC_CHANNEL[RH_ASK_DUE_TIMER_CHANNEL].TC_IER = TC_IER_CPCS;\n    NVIC_ClearPendingIRQ(RH_ASK_DUE_TIMER_IRQ);\n    NVIC_EnableIRQ(RH_ASK_DUE_TIMER_IRQ);\n    TC_Start(RH_ASK_DUE_TIMER, RH_ASK_DUE_TIMER_CHANNEL);\n\n #else\n    // This is the path for most Arduinos\n    // figure out prescaler value and counter match value\n  #if defined(RH_ASK_ARDUINO_USE_TIMER2)\n    prescaler = timerCalc(_speed, (uint8_t)-1, &nticks);\n    if (!prescaler)\n        return; // fault\n    // Use timer 2\n    TCCR2A = _BV(WGM21); // Turn on CTC mode)\n    // convert prescaler index to TCCRnB prescaler bits CS10, CS11, CS12\n    TCCR2B = prescaler;\n\n    // Caution: special procedures for setting 16 bit regs\n    // is handled by the compiler\n    OCR2A = nticks;\n    // Enable interrupt\n   #ifdef TIMSK2\n    // atmega168\n    TIMSK2 |= _BV(OCIE2A);\n   #else\n    // others\n    TIMSK |= _BV(OCIE2A);\n   #endif // TIMSK2\n  #else\n    // Use timer 1\n    prescaler = timerCalc(_speed, (uint16_t)-1, &nticks);    \n    if (!prescaler)\n        return; // fault\n    TCCR1A = 0; // Output Compare pins disconnected\n    TCCR1B = _BV(WGM12); // Turn on CTC mode\n\n    // convert prescaler index to TCCRnB prescaler bits CS10, CS11, CS12\n    TCCR1B |= prescaler;\n\n    // Caution: special procedures for setting 16 bit regs\n    // is handled by the compiler\n    OCR1A = nticks;\n    // Enable interrupt\n   #ifdef TIMSK1\n    // atmega168\n    TIMSK1 |= _BV(OCIE1A);\n   #else\n    // others\n    TIMSK |= _BV(OCIE1A);\n   #endif // TIMSK1\n  #endif\n #endif\n\n#elif (RH_PLATFORM == RH_PLATFORM_STM32) // Maple etc\n    // Pause the timer while we're configuring it\n    timer.pause();\n    timer.setPeriod((1000000/8)/_speed);\n    // Set up an interrupt on channel 1\n    timer.setChannel1Mode(TIMER_OUTPUT_COMPARE);\n    timer.setCompare(TIMER_CH1, 1);  // Interrupt 1 count after each update\n    void interrupt(); // defined below\n    timer.attachCompare1Interrupt(interrupt);\n    \n    // Refresh the timer's count, prescale, and overflow\n    timer.refresh();\n    \n    // Start the timer counting\n    timer.resume();\n\n#elif (RH_PLATFORM == RH_PLATFORM_STM32F2) // Photon\n    // Inspired by SparkIntervalTimer\n    // We use Timer 6\n    void TimerInterruptHandler(); // Forward declaration for interrupt handler\n    #define SYSCORECLOCK\t60000000UL  // Timer clock tree uses core clock / 2\n    TIM_TimeBaseInitTypeDef timerInitStructure;\n    NVIC_InitTypeDef nvicStructure;\n    TIM_TypeDef* TIMx;\n    uint32_t period = (1000000 / 8) / _speed; // In microseconds\n    uint16_t prescaler = (uint16_t)(SYSCORECLOCK / 1000000UL) - 1; //To get TIM counter clock = 1MHz\n\n    attachSystemInterrupt(SysInterrupt_TIM6_Update, TimerInterruptHandler);\n    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);\n    nvicStructure.NVIC_IRQChannel = TIM6_DAC_IRQn;\n    TIMx = TIM6;\n    nvicStructure.NVIC_IRQChannelPreemptionPriority = 10;\n    nvicStructure.NVIC_IRQChannelSubPriority = 1;\n    nvicStructure.NVIC_IRQChannelCmd = ENABLE;\n    NVIC_Init(&nvicStructure);\n    timerInitStructure.TIM_Prescaler = prescaler;\n    timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;\n    timerInitStructure.TIM_Period = period;\n    timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;\n    timerInitStructure.TIM_RepetitionCounter = 0;\n    \n    TIM_TimeBaseInit(TIMx, &timerInitStructure);\n    TIM_ITConfig(TIMx, TIM_IT_Update, ENABLE);\n    TIM_Cmd(TIMx, ENABLE);\n\n#elif (RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE)\n    // UsingChipKIT Core on Arduino IDE\n    uint32_t chipkit_timer_interrupt_handler(uint32_t currentTime); // Forward declaration\n    attachCoreTimerService(chipkit_timer_interrupt_handler);\n\n#elif (RH_PLATFORM == RH_PLATFORM_UNO32)\n    // Under old MPIDE, which has been discontinued:\n    // ON Uno32 we use timer1\n    OpenTimer1(T1_ON | T1_PS_1_1 | T1_SOURCE_INT, (F_CPU / 8) / _speed);\n    ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_1);\n\n#elif (RH_PLATFORM == RH_PLATFORM_ESP8266)\n    void INTERRUPT_ATTR esp8266_timer_interrupt_handler(); // Forward declarat\n    // The - 120 is a heuristic to correct for interrupt handling overheads\n    _timerIncrement = (clockCyclesPerMicrosecond() * 1000000 / 8 / _speed) - 120;\n    timer0_isr_init();\n    timer0_attachInterrupt(esp8266_timer_interrupt_handler);\n    timer0_write(ESP.getCycleCount() + _timerIncrement);\n//    timer0_write(ESP.getCycleCount() + 41660000);\n#endif\n\n}\n\nvoid INTERRUPT_ATTR RH_ASK::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\t// Disable the transmitter hardware\n\twritePtt(LOW);\n\twriteTx(LOW);\n\t_mode = RHModeIdle;\n    }\n}\n\nvoid RH_ASK::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\t// Disable the transmitter hardware\n\twritePtt(LOW);\n\twriteTx(LOW);\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_ASK::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\t// PRepare state varibles for a new transmission\n\t_txIndex = 0;\n\t_txBit = 0;\n\t_txSample = 0;\n\n\t// Enable the transmitter hardware\n\twritePtt(HIGH);\n\n\t_mode = RHModeTx;\n    }\n}\n\n// Call this often\nbool RH_ASK::available()\n{\n    if (_mode == RHModeTx)\n\treturn false;\n    setModeRx();\n    if (_rxBufFull)\n    {\n\tvalidateRxBuf();\n\t_rxBufFull= false;\n    }\n    return _rxBufValid;\n}\n\nbool RH_ASK::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n\n    if (buf && len)\n    {\n\t// Skip the length and 4 headers that are at the beginning of the rxBuf\n\t// and drop the trailing 2 bytes of FCS\n\tuint8_t message_len = _rxBufLen-RH_ASK_HEADER_LEN - 3;\n\tif (*len > message_len)\n\t    *len = message_len;\n\tmemcpy(buf, _rxBuf+RH_ASK_HEADER_LEN+1, *len);\n    }\n    _rxBufValid = false; // Got the most recent message, delete it\n//    printBuffer(\"recv:\", buf, *len);\n    return true;\n}\n\n// Caution: this may block\nbool RH_ASK::send(const uint8_t* data, uint8_t len)\n{\n    uint8_t i;\n    uint16_t index = 0;\n    uint16_t crc = 0xffff;\n    uint8_t *p = _txBuf + RH_ASK_PREAMBLE_LEN; // start of the message area\n    uint8_t count = len + 3 + RH_ASK_HEADER_LEN; // Added byte count and FCS and headers to get total number of bytes\n\n    if (len > RH_ASK_MAX_MESSAGE_LEN)\n\treturn false;\n\n    // Wait for transmitter to become available\n    waitPacketSent();\n\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    // Encode the message length\n    crc = RHcrc_ccitt_update(crc, count);\n    p[index++] = symbols[count >> 4];\n    p[index++] = symbols[count & 0xf];\n\n    // Encode the headers\n    crc = RHcrc_ccitt_update(crc, _txHeaderTo);\n    p[index++] = symbols[_txHeaderTo >> 4];\n    p[index++] = symbols[_txHeaderTo & 0xf];\n    crc = RHcrc_ccitt_update(crc, _txHeaderFrom);\n    p[index++] = symbols[_txHeaderFrom >> 4];\n    p[index++] = symbols[_txHeaderFrom & 0xf];\n    crc = RHcrc_ccitt_update(crc, _txHeaderId);\n    p[index++] = symbols[_txHeaderId >> 4];\n    p[index++] = symbols[_txHeaderId & 0xf];\n    crc = RHcrc_ccitt_update(crc, _txHeaderFlags);\n    p[index++] = symbols[_txHeaderFlags >> 4];\n    p[index++] = symbols[_txHeaderFlags & 0xf];\n\n    // Encode the message into 6 bit symbols. Each byte is converted into \n    // 2 6-bit symbols, high nybble first, low nybble second\n    for (i = 0; i < len; i++)\n    {\n\tcrc = RHcrc_ccitt_update(crc, data[i]);\n\tp[index++] = symbols[data[i] >> 4];\n\tp[index++] = symbols[data[i] & 0xf];\n    }\n\n    // Append the fcs, 16 bits before encoding (4 6-bit symbols after encoding)\n    // Caution: VW expects the _ones_complement_ of the CCITT CRC-16 as the FCS\n    // VW sends FCS as low byte then hi byte\n    crc = ~crc;\n    p[index++] = symbols[(crc >> 4)  & 0xf];\n    p[index++] = symbols[crc & 0xf];\n    p[index++] = symbols[(crc >> 12) & 0xf];\n    p[index++] = symbols[(crc >> 8)  & 0xf];\n\n    // Total number of 6-bit symbols to send\n    _txBufLen = index + RH_ASK_PREAMBLE_LEN;\n\n    // Start the low level interrupt handler sending symbols\n    setModeTx();\n\n    return true;\n}\n\n// Read the RX data input pin, taking into account platform type and inversion.\nbool INTERRUPT_ATTR RH_ASK::readRx()\n{\n    bool value;\n#if (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)\n    value = ((RH_ASK_RX_PORT & (1<<RH_ASK_RX_PIN)) ? 1 : 0);\n#else\n    value = digitalRead(_rxPin);\n#endif\n    return value ^ _rxInverted;\n}\n\n// Write the TX output pin, taking into account platform type.\nvoid INTERRUPT_ATTR RH_ASK::writeTx(bool value)\n{\n#if (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)\n    ((value) ? (RH_ASK_TX_PORT |= (1<<RH_ASK_TX_PIN)) : (RH_ASK_TX_PORT &= ~(1<<RH_ASK_TX_PIN)));\n#else\n    digitalWrite(_txPin, value);\n#endif\n}\n\n// Write the PTT output pin, taking into account platform type and inversion.\nvoid INTERRUPT_ATTR RH_ASK::writePtt(bool value)\n{\n#if (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)\n #if RH_ASK_PTT_PIN \n    ((value) ? (RH_ASK_PTT_PORT |= (1<<RH_ASK_PTT_PIN)) : (RH_ASK_PTT_PORT &= ~(1<<RH_ASK_PTT_PIN)));\n #else\n    ((value) ? (RH_ASK_TX_PORT |= (1<<RH_ASK_TX_PIN)) : (RH_ASK_TX_PORT &= ~(1<<RH_ASK_TX_PIN)));\n #endif\n#else\n    digitalWrite(_pttPin, value ^ _pttInverted);\n#endif\n}\n\nuint8_t RH_ASK::maxMessageLength()\n{\n    return RH_ASK_MAX_MESSAGE_LEN;\n}\n\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) \n #if defined(RH_PLATFORM_ATTINY)\n  #define RH_ASK_TIMER_VECTOR TIM0_COMPA_vect\n #else // Assume Arduino Uno (328p or similar)\n  #if defined(RH_ASK_ARDUINO_USE_TIMER2)\n   #define RH_ASK_TIMER_VECTOR TIMER2_COMPA_vect\n  #else\n   #define RH_ASK_TIMER_VECTOR TIMER1_COMPA_vect\n  #endif\n #endif \n#elif (RH_ASK_PLATFORM == RH_ASK_PLATFORM_GENERIC_AVR8)\n #define __COMB(a,b,c) (a##b##c)\n #define _COMB(a,b,c) __COMB(a,b,c)\n #define RH_ASK_TIMER_VECTOR _COMB(TIMER,RH_ASK_TIMER_INDEX,_COMPA_vect)\n#endif\n\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(__arm__) && defined(CORE_TEENSY)\t\nvoid TIMER1_COMPA_vect(void)\n{\n    thisASKDriver->handleTimerInterrupt();\n}\n\n#elif (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && defined(ARDUINO_ARCH_SAMD)\n// Arduino Zero\nvoid TC3_Handler()\n{\n    // The type cast must fit with the selected timer mode\n    TcCount16* TC = (TcCount16*)RH_ASK_ZERO_TIMER; // get timer struct\n    TC->INTFLAG.bit.MC0 = 1;\n    thisASKDriver->handleTimerInterrupt();\n}\n\n#elif (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(__arm__) && defined(ARDUINO_SAM_DUE)\n// Arduino Due\nvoid TC1_Handler()\n{\n    TC_GetStatus(RH_ASK_DUE_TIMER, 1);\n    thisASKDriver->handleTimerInterrupt();\n}\n\n#elif (RH_PLATFORM == RH_PLATFORM_ARDUINO) || (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)\n// This is the interrupt service routine called when timer1 overflows\n// Its job is to output the next bit from the transmitter (every 8 calls)\n// and to call the PLL code if the receiver is enabled\n//ISR(SIG_OUTPUT_COMPARE1A)\nISR(RH_ASK_TIMER_VECTOR)\n{\n    thisASKDriver->handleTimerInterrupt();\n}\n\n#elif (RH_PLATFORM == RH_PLATFORM_MSP430) || (RH_PLATFORM == RH_PLATFORM_STM32)\n// LaunchPad, Maple\nvoid interrupt()\n{\n    thisASKDriver->handleTimerInterrupt();\n}\n\n#elif (RH_PLATFORM == RH_PLATFORM_STM32F2) // Photon\nvoid TimerInterruptHandler()\n{\n    thisASKDriver->handleTimerInterrupt();\n}\n\n#elif (RH_PLATFORM == RH_PLATFORM_MSP430) \ninterrupt(TIMER0_A0_VECTOR) Timer_A_int(void) \n{\n    thisASKDriver->handleTimerInterrupt();\n};\n\n#elif (RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE)\n// Using ChipKIT Core on Arduino IDE\nuint32_t chipkit_timer_interrupt_handler(uint32_t currentTime) \n{\n    thisASKDriver->handleTimerInterrupt();\n    return (currentTime + ((CORE_TICK_RATE * 1000)/8)/thisASKDriver->speed());\n}\n\n#elif (RH_PLATFORM == RH_PLATFORM_UNO32)\n// Under old MPIDE, which has been discontinued:\nextern \"C\"\n{\n void __ISR(_TIMER_1_VECTOR, ipl1) timerInterrupt(void)\n {\n    thisASKDriver->handleTimerInterrupt();\n    mT1ClearIntFlag(); // Clear timer 1 interrupt flag\n}\n}\n#elif (RH_PLATFORM == RH_PLATFORM_ESP8266)\nvoid INTERRUPT_ATTR esp8266_timer_interrupt_handler()\n{  \n//    timer0_write(ESP.getCycleCount() + 41660000);\n//    timer0_write(ESP.getCycleCount() + (clockCyclesPerMicrosecond() * 100) - 120 );\n    timer0_write(ESP.getCycleCount() + thisASKDriver->_timerIncrement);\n//    static int toggle = 0;\n//  toggle = (toggle == 1) ? 0 : 1;\n//  digitalWrite(4, toggle);\n    thisASKDriver->handleTimerInterrupt();\n}\n\n#endif\n\n// Convert a 6 bit encoded symbol into its 4 bit decoded equivalent\nuint8_t INTERRUPT_ATTR RH_ASK::symbol_6to4(uint8_t symbol)\n{\n    uint8_t i;\n    uint8_t count;\n    \n    // Linear search :-( Could have a 64 byte reverse lookup table?\n    // There is a little speedup here courtesy Ralph Doncaster:\n    // The shortcut works because bit 5 of the symbol is 1 for the last 8\n    // symbols, and it is 0 for the first 8.\n    // So we only have to search half the table\n    for (i = (symbol>>2) & 8, count=8; count-- ; i++)\n\tif (symbol == symbols[i]) return i;\n\n    return 0; // Not found\n}\n\n// Check whether the latest received message is complete and uncorrupted\n// We should always check the FCS at user level, not interrupt level\n// since it is slow\nvoid RH_ASK::validateRxBuf()\n{\n    uint16_t crc = 0xffff;\n    // The CRC covers the byte count, headers and user data\n    for (uint8_t i = 0; i < _rxBufLen; i++)\n\tcrc = RHcrc_ccitt_update(crc, _rxBuf[i]);\n    if (crc != 0xf0b8) // CRC when buffer and expected CRC are CRC'd\n    {\n\t// Reject and drop the message\n\t_rxBad++;\n\t_rxBufValid = false;\n\treturn;\n    }\n\n    // Extract the 4 headers that follow the message length\n    _rxHeaderTo    = _rxBuf[1];\n    _rxHeaderFrom  = _rxBuf[2];\n    _rxHeaderId    = _rxBuf[3];\n    _rxHeaderFlags = _rxBuf[4];\n    if (_promiscuous ||\n\t_rxHeaderTo == _thisAddress ||\n\t_rxHeaderTo == RH_BROADCAST_ADDRESS)\n    {\n\t_rxGood++;\n\t_rxBufValid = true;\n    }\n}\n\nvoid INTERRUPT_ATTR RH_ASK::receiveTimer()\n{\n    bool rxSample = readRx();\n\n    // Integrate each sample\n    if (rxSample)\n\t_rxIntegrator++;\n\n    if (rxSample != _rxLastSample)\n    {\n\t// Transition, advance if ramp > 80, retard if < 80\n\t_rxPllRamp += ((_rxPllRamp < RH_ASK_RAMP_TRANSITION) \n\t\t\t   ? RH_ASK_RAMP_INC_RETARD \n\t\t\t   : RH_ASK_RAMP_INC_ADVANCE);\n\t_rxLastSample = rxSample;\n    }\n    else\n    {\n\t// No transition\n\t// Advance ramp by standard 20 (== 160/8 samples)\n\t_rxPllRamp += RH_ASK_RAMP_INC;\n    }\n    if (_rxPllRamp >= RH_ASK_RX_RAMP_LEN)\n    {\n\t// Add this to the 12th bit of _rxBits, LSB first\n\t// The last 12 bits are kept\n\t_rxBits >>= 1;\n\n\t// Check the integrator to see how many samples in this cycle were high.\n\t// If < 5 out of 8, then its declared a 0 bit, else a 1;\n\tif (_rxIntegrator >= 5)\n\t    _rxBits |= 0x800;\n\n\t_rxPllRamp -= RH_ASK_RX_RAMP_LEN;\n\t_rxIntegrator = 0; // Clear the integral for the next cycle\n\n\tif (_rxActive)\n\t{\n\t    // We have the start symbol and now we are collecting message bits,\n\t    // 6 per symbol, each which has to be decoded to 4 bits\n\t    if (++_rxBitCount >= 12)\n\t    {\n\t\t// Have 12 bits of encoded message == 1 byte encoded\n\t\t// Decode as 2 lots of 6 bits into 2 lots of 4 bits\n\t\t// The 6 lsbits are the high nybble\n\t\tuint8_t this_byte = \n\t\t    (symbol_6to4(_rxBits & 0x3f)) << 4 \n\t\t    | symbol_6to4(_rxBits >> 6);\n\n\t\t// The first decoded byte is the byte count of the following message\n\t\t// the count includes the byte count and the 2 trailing FCS bytes\n\t\t// REVISIT: may also include the ACK flag at 0x40\n\t\tif (_rxBufLen == 0)\n\t\t{\n\t\t    // The first byte is the byte count\n\t\t    // Check it for sensibility. It cant be less than 7, since it\n\t\t    // includes the byte count itself, the 4 byte header and the 2 byte FCS\n\t\t    _rxCount = this_byte;\n\t\t    if (_rxCount < 7 || _rxCount > RH_ASK_MAX_PAYLOAD_LEN)\n\t\t    {\n\t\t\t// Stupid message length, drop the whole thing\n\t\t\t_rxActive = false;\n\t\t\t_rxBad++;\n                        return;\n\t\t    }\n\t\t}\n\t\t_rxBuf[_rxBufLen++] = this_byte;\n\n\t\tif (_rxBufLen >= _rxCount)\n\t\t{\n\t\t    // Got all the bytes now\n\t\t    _rxActive = false;\n\t\t    _rxBufFull = true;\n\t\t    setModeIdle();\n\t\t}\n\t\t_rxBitCount = 0;\n\t    }\n\t}\n\t// Not in a message, see if we have a start symbol\n\telse if (_rxBits == RH_ASK_START_SYMBOL)\n\t{\n\t    // Have start symbol, start collecting message\n\t    _rxActive = true;\n\t    _rxBitCount = 0;\n\t    _rxBufLen = 0;\n\t}\n    }\n}\n\nvoid INTERRUPT_ATTR RH_ASK::transmitTimer()\n{\n    if (_txSample++ == 0)\n    {\n\t// Send next bit\n\t// Symbols are sent LSB first\n\t// Finished sending the whole message? (after waiting one bit period \n\t// since the last bit)\n\tif (_txIndex >= _txBufLen)\n\t{\n\t    setModeIdle();\n\t    _txGood++;\n\t}\n\telse\n\t{\n\t    writeTx(_txBuf[_txIndex] & (1 << _txBit++));\n\t    if (_txBit >= 6)\n\t    {\n\t\t_txBit = 0;\n\t\t_txIndex++;\n\t    }\n\t}\n    }\n\t\n    if (_txSample > 7)\n\t_txSample = 0;\n}\n\nvoid INTERRUPT_ATTR RH_ASK::handleTimerInterrupt()\n{\n    if (_mode == RHModeRx)\n\treceiveTimer(); // Receiving\n    else if (_mode == RHModeTx)\n        transmitTimer(); // Transmitting\n}\n\n"
  },
  {
    "path": "RH_ASK.h",
    "content": "// RH_ASK.h\n//\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_ASK.h,v 1.16 2016/07/07 00:02:53 mikem Exp $\n\n#ifndef RH_ASK_h\n#define RH_ASK_h\n\n#include <RHGenericDriver.h>\n\n// Maximum message length (including the headers, byte count and FCS) we are willing to support\n// This is pretty arbitrary\n#define RH_ASK_MAX_PAYLOAD_LEN 67\n\n// The length of the headers we add (To, From, Id, Flags)\n// The headers are inside the payload and are therefore protected by the FCS\n#define RH_ASK_HEADER_LEN 4\n\n// This is the maximum message length that can be supported by this library. \n// Can be pre-defined to a smaller size (to save SRAM) prior to including this header\n// Here we allow for 1 byte message length, 4 bytes headers, user data and 2 bytes of FCS\n#ifndef RH_ASK_MAX_MESSAGE_LEN\n #define RH_ASK_MAX_MESSAGE_LEN (RH_ASK_MAX_PAYLOAD_LEN - RH_ASK_HEADER_LEN - 3)\n#endif\n\n#if !defined(RH_ASK_RX_SAMPLES_PER_BIT)\n/// Number of samples per bit\n #define RH_ASK_RX_SAMPLES_PER_BIT 8\n#endif //RH_ASK_RX_SAMPLES_PER_BIT  \n\n/// The size of the receiver ramp. Ramp wraps modulo this number\n#define RH_ASK_RX_RAMP_LEN 160\n\n// Ramp adjustment parameters\n// Standard is if a transition occurs before RH_ASK_RAMP_TRANSITION (80) in the ramp,\n// the ramp is retarded by adding RH_ASK_RAMP_INC_RETARD (11)\n// else by adding RH_ASK_RAMP_INC_ADVANCE (29)\n// If there is no transition it is adjusted by RH_ASK_RAMP_INC (20)\n/// Internal ramp adjustment parameter\n#define RH_ASK_RAMP_INC (RH_ASK_RX_RAMP_LEN/RH_ASK_RX_SAMPLES_PER_BIT)\n/// Internal ramp adjustment parameter\n#define RH_ASK_RAMP_TRANSITION RH_ASK_RX_RAMP_LEN/2\n/// Internal ramp adjustment parameter\n#define RH_ASK_RAMP_ADJUST 9\n/// Internal ramp adjustment parameter\n#define RH_ASK_RAMP_INC_RETARD (RH_ASK_RAMP_INC-RH_ASK_RAMP_ADJUST)\n/// Internal ramp adjustment parameter\n#define RH_ASK_RAMP_INC_ADVANCE (RH_ASK_RAMP_INC+RH_ASK_RAMP_ADJUST)\n\n/// Outgoing message bits grouped as 6-bit words\n/// 36 alternating 1/0 bits, followed by 12 bits of start symbol (together called the preamble)\n/// Followed immediately by the 4-6 bit encoded byte count, \n/// message buffer and 2 byte FCS\n/// Each byte from the byte count on is translated into 2x6-bit words\n/// Caution, each symbol is transmitted LSBit first, \n/// but each byte is transmitted high nybble first\n/// This is the number of 6 bit nibbles in the preamble\n#define RH_ASK_PREAMBLE_LEN 8\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_ASK RH_ASK.h <RH_ASK.h>\n/// \\brief Driver to send and receive unaddressed, unreliable datagrams via inexpensive ASK (Amplitude Shift Keying) or \n/// OOK (On Off Keying) RF transceivers.\n///\n/// The message format and software technology is based on our earlier VirtualWire library \n/// (http://www.airspayce.com/mikem/arduino/VirtualWire), with which it is compatible.\n/// See http://www.airspayce.com/mikem/arduino/VirtualWire.pdf for more details. \n/// VirtualWire is now obsolete and unsupported and is replaced by this library.\n///\n/// RH_ASK is a Driver for Arduino, Maple and others that provides features to send short\n/// messages, without addressing, retransmit or acknowledgment, a bit like UDP\n/// over wireless, using ASK (amplitude shift keying). Supports a number of\n/// inexpensive radio transmitters and receivers. All that is required is\n/// transmit data, receive data and (for transmitters, optionally) a PTT\n/// transmitter enable. Can also be used over various analog connections (not just a data radio), \n/// such as the audio channel of an A/V sender, or long TTL lines.\n///\n/// It is intended to be compatible with the RF Monolithics (www.rfm.com)\n/// Virtual Wire protocol, but this has not been tested.\n///\n/// Does not use the Arduino UART. Messages are sent with a training preamble,\n/// message length and checksum. Messages are sent with 4-to-6 bit encoding\n/// for good DC balance, and a CRC checksum for message integrity.\n///\n/// But why not just use a UART connected directly to the\n/// transmitter/receiver? As discussed in the RFM documentation, ASK receivers\n/// require a burst of training pulses to synchronize the transmitter and\n/// receiver, and also requires good balance between 0s and 1s in the message\n/// stream in order to maintain the DC balance of the message. UARTs do not\n/// provide these. They work a bit with ASK wireless, but not as well as this\n/// code.\n///\n/// \\par Theory of operation\n///\n/// See ASH Transceiver Software Designer's Guide of 2002.08.07\n///   http://wireless.murata.com/media/products/apnotes/tr_swg05.pdf?ref=rfm.com\n///\n/// http://web.engr.oregonstate.edu/~moon/research/files/cas2_mar_07_dpll.pdf while not directly relevant \n/// is also interesting.\n///\n/// \\par Implementation Details\n///\n/// Messages of up to RH_ASK_MAX_PAYLOAD_LEN (67) bytes can be sent\n/// Each message is transmitted as:\n///\n/// - 36 bit training preamble consisting of 0-1 bit pairs\n/// - 12 bit start symbol 0xb38\n/// - 1 byte of message length byte count (4 to 30), count includes byte count and FCS bytes\n/// - n message bytes (uincluding 4 bytes of header), maximum n is RH_ASK_MAX_MESSAGE_LEN + 4 (64)\n/// - 2 bytes FCS, sent low byte-hi byte\n///\n/// Everything after the start symbol is encoded 4 to 6 bits, Therefore a byte in the message\n/// is encoded as 2x6 bit symbols, sent hi nybble, low nybble. Each symbol is sent LSBit\n/// first. The message may consist of any binary digits.\n/// \n/// The Arduino Diecimila clock rate is 16MHz => 62.5ns/cycle.\n/// For an RF bit rate of 2000 bps, need 500microsec bit period.\n/// The ramp requires 8 samples per bit period, so need 62.5microsec per sample => interrupt tick is 62.5microsec.\n///\n/// The maximum packet length consists of\n/// (6 + 2 + RH_ASK_MAX_MESSAGE_LEN*2) * 6 = 768 bits = 0.384 secs (at 2000 bps).\n/// where RH_ASK_MAX_MESSAGE_LEN is RH_ASK_MAX_PAYLOAD_LEN - 7 (= 60).\n/// The code consists of an ISR interrupt handler. Most of the work is done in the interrupt\n/// handler for both transmit and receive, but some is done from the user level. Expensive\n/// functions like CRC computations are always done in the user level.\n///\n/// \\par Supported Hardware\n///\n/// A range of communications\n/// hardware is supported. The ones listed below are available in common retail\n/// outlets in Australia and other countries for under $10 per unit. Many\n/// other modules may also work with this software. \n///\n/// Runs on a wide range of Arduino processors using Arduino IDE 1.0 or later.\n/// Also runs on on Energia, \n/// with MSP430G2553 / G2452 and Arduino with ATMega328 (courtesy Yannick DEVOS - XV4Y), \n/// but untested by us. It also runs on Teensy 3.0 (courtesy of Paul\n/// Stoffregen), but untested by us. Also compiles and runs on ATtiny85 in\n/// Arduino environment, courtesy r4z0r7o3. Also compiles on maple-ide-v0.0.12,\n/// and runs on Maple, flymaple 1.1 etc. Runs on ATmega8/168 (Arduino Diecimila,\n/// Uno etc), ATmega328 and can run on almost any other AVR8 platform,\n/// without relying on the Arduino framework, by properly configuring the\n/// library editing the RH_ASK.h header file for describing the access\n/// to IO pins and for setting up the timer.\n/// Runs on ChipKIT Core supported processors such as Uno32 etc.\n///\n/// - Receivers\n///  - RX-B1 (433.92MHz) (also known as ST-RX04-ASK)\n///  - RFM83C from HopeRF http://www.hoperfusa.com/details.jsp?pid=126\n/// - Transmitters: \n///  - TX-C1 (433.92MHz)\n///  - RFM85 from HopeRF http://www.hoperfusa.com/details.jsp?pid=127\n/// - Transceivers\n///  - DR3100 (433.92MHz)\n///\n/// \\par Connecting to Arduino\n///\n/// Most transmitters can be connected to Arduino like this:\n\n/// \\code\n/// Arduino                         Transmitter\n///  GND------------------------------GND\n///  D12------------------------------Data\n///  5V-------------------------------VCC\n/// \\endcode\n///\n/// Most receivers can be connected to Arduino like this:\n/// \\code\n/// Arduino                         Receiver\n///  GND------------------------------GND\n///  D11------------------------------Data\n///  5V-------------------------------VCC\n///                                   SHUT (not connected)\n///                                   WAKEB (not connected)\n///                                   GND |\n///                                   ANT |- connect to your antenna syetem\n/// \\endcode\n///\n/// RH_ASK works with ATTiny85, using Arduino 1.0.5 and tinycore from\n/// https://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0100-0018.zip\n/// Tested with the examples ask_transmitter and ask_receiver on ATTiny85.\n/// Caution: The RAM memory requirements on an ATTiny85 are *very* tight. Even the bare bones\n/// ask_transmitter sketch barely fits in eh RAM available on the ATTiny85. Its unlikely to work on \n/// smaller ATTinys such as the ATTiny45 etc. If you have wierd behaviour, consider\n/// reducing the size of RH_ASK_MAX_PAYLOAD_LEN to the minimum you can work with.\n/// Caution: the default internal clock speed on an ATTiny85 is 1MHz. You MUST set the internal clock speed\n/// to 8MHz. You can do this with Arduino IDE, tineycore and ArduinoISP by setting the board type to \"ATtiny85@8MHz',\n/// setting theProgrammer to 'Arduino as ISP' and selecting Tools->Burn Bootloader. This does not actually burn a\n/// bootloader into the tiny, it just changes the fuses so the chip runs at 8MHz. \n/// If you run the chip at 1MHz, you will get RK_ASK speeds 1/8th of the expected.\n///\n/// Initialise RH_ASK for ATTiny85 like this:\n/// // #include <SPI.h> // comment this out, not needed\n/// RH_ASK driver(2000, 4, 3); // 200bps, TX on D3 (pin 2), RX on D4 (pin 3)\n/// then:\n/// Connect D3 (pin 2) as the output to the transmitter\n/// Connect D4 (pin 3) as the input from the receiver.\n/// \n///\n/// For testing purposes you can connect 2 Arduino RH_ASK instances directly, by\n/// connecting pin 12 of one to 11 of the other and vice versa, like this for a duplex connection:\n///\n/// \\code\n/// Arduino 1         wires         Arduino 1\n///  D11-----------------------------D12\n///  D12-----------------------------D11\n///  GND-----------------------------GND\n/// \\endcode\n///\n/// You can also connect 2 RH_ASK instances over a suitable analog\n/// transmitter/receiver, such as the audio channel of an A/V transmitter/receiver. You may need\n/// buffers at each end of the connection to convert the 0-5V digital output to a suitable analog voltage.\n///\n/// Measured power output from RFM85 at 5V was 18dBm.\n///\n/// \\par ESP8266\n/// This module has been tested with the ESP8266 using an ESP-12 on a breakout board \n/// ESP-12E SMD Adaptor Board with Power Regulator from tronixlabs \n/// http://tronixlabs.com.au/wireless/esp8266/esp8266-esp-12e-smd-adaptor-board-with-power-regulator-australia/\n/// compiled on Arduino 1.6.5 and the ESP8266 support 2.0 installed with Board Manager.\n/// CAUTION: do not use pin 11 for IO with this chip: it will cause the sketch to hang. Instead\n/// use constructor arguments to configure different pins, eg:\n/// \\code\n/// RH_ASK driver(2000, 2, 4, 5);\n/// \\endcode\n/// Which will initialise the driver at 2000 bps, recieve on GPIO2, transmit on GPIO4, PTT on GPIO5.\n/// Caution: on the tronixlabs breakout board, pins 4 and 5 may be labelled vice-versa.\n///\n/// \\par Timers\n/// The RH_ASK driver uses a timer-driven interrupt to generate 8 interrupts per bit period. RH_ASK\n/// takes over a timer on Arduino-like platforms. By default it takes over Timer 1. You can force it\n/// to use Timer 2 instead by enabling the define RH_ASK_ARDUINO_USE_TIMER2 near the top of RH_ASK.cpp\n/// On Arduino Zero it takes over timer TC3. On Arduino Due it takes over timer\n/// TC0. On ESP8266, takes over timer0 (which conflicts with ServoTimer0).\n///\n/// Caution: ATTiny85 has only 2 timers, one (timer 0) usually used for\n/// millis() and one (timer 1) for PWM analog outputs. The RH_ASK Driver\n/// library, when built for ATTiny85, takes over timer 0, which prevents use\n/// of millis() etc but does permit analog outputs. This will affect the accuracy of millis() and time\n/// measurement.\nclass RH_ASK : public RHGenericDriver\n{\npublic:\n    /// Constructor.\n    /// At present only one instance of RH_ASK per sketch is supported.\n    /// \\param[in] speed The desired bit rate in bits per second\n    /// \\param[in] rxPin The pin that is used to get data from the receiver\n    /// \\param[in] txPin The pin that is used to send data to the transmitter\n    /// \\param[in] pttPin The pin that is connected to the transmitter controller. It will be set HIGH to enable the transmitter (unless pttInverted is true).\n    /// \\param[in] pttInverted true if you desire the pttin to be inverted so that LOW wil enable the transmitter.\n    RH_ASK(uint16_t speed = 2000, uint8_t rxPin = 11, uint8_t txPin = 12, uint8_t pttPin = 10, bool pttInverted = false);\n\n    /// Initialise the Driver transport hardware and software.\n    /// Make sure the Driver is properly configured before calling init().\n    /// \\return true if initialisation succeeded.\n    virtual bool    init();\n\n    /// Tests whether a new message is available\n    /// from the Driver. \n    /// On most drivers, this will also put the Driver into RHModeRx mode until\n    /// a message is actually received bythe transport, when it wil be returned to RHModeIdle.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a new, complete, error-free uncollected message is available to be retreived by recv()\n    virtual bool    available();\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    virtual bool    recv(uint8_t* buf, uint8_t* len);\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is NOT permitted. \n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send (> 0)\n    /// \\return true if the message length was valid and it was correctly queued for transmit\n    virtual bool    send(const uint8_t* data, uint8_t len);\n\n    /// Returns the maximum message length \n    /// available in this Driver.\n    /// \\return The maximum legal message length\n    virtual uint8_t maxMessageLength();\n\n    /// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, \n    /// disables them.\n    void           setModeIdle();\n\n    /// If current mode is Tx or Idle, changes it to Rx. \n    /// Starts the receiver in the RF69.\n    void           setModeRx();\n\n    /// If current mode is Rx or Idle, changes it to Rx. F\n    /// Starts the transmitter in the RF69.\n    void           setModeTx();\n\n    /// dont call this it used by the interrupt handler\n    void            handleTimerInterrupt();\n\n    /// Returns the current speed in bits per second\n    /// \\return The current speed in bits per second\n    uint16_t        speed() { return _speed;}\n\n#if (RH_PLATFORM == RH_PLATFORM_ESP8266)\n    /// ESP8266 timer0 increment value\n    uint32_t _timerIncrement;\n#endif\n\nprotected:\n    /// Helper function for calculating timer ticks\n    uint8_t         timerCalc(uint16_t speed, uint16_t max_ticks, uint16_t *nticks);\n\n    /// Set up the timer and its interrutps so the interrupt handler is called at the right frequency\n    void            timerSetup();\n\n    /// Read the rxPin in a platform dependent way, taking into account whether it is inverted or not\n    bool            readRx();\n\n    /// Write the txPin in a platform dependent way\n    void            writeTx(bool value);\n\n    /// Write the txPin in a platform dependent way, taking into account whether it is inverted or not\n    void            writePtt(bool value);\n\n    /// Translates a 6 bit symbol to its 4 bit plaintext equivalent\n    uint8_t         symbol_6to4(uint8_t symbol);\n\n    /// The receiver handler function, called a 8 times the bit rate\n    void            receiveTimer();\n\n    /// The transmitter handler function, called a 8 times the bit rate \n    void            transmitTimer();\n\n    /// Check whether the latest received message is complete and uncorrupted\n    /// We should always check the FCS at user level, not interrupt level\n    /// since it is slow\n    void            validateRxBuf();\n\n    /// Configure bit rate in bits per second\n    uint16_t        _speed;\n\n    /// The configure receiver pin\n    uint8_t         _rxPin;\n\n    /// The configure transmitter pin\n    uint8_t         _txPin;\n\n    /// The configured transmitter enable pin\n    uint8_t         _pttPin;\n\n    /// True of the sense of the rxPin is to be inverted\n    bool            _rxInverted;\n\n    /// True of the sense of the pttPin is to be inverted\n    bool            _pttInverted;\n\n    // Used in the interrupt handlers\n    /// Buf is filled but not validated\n    volatile bool   _rxBufFull;\n\n    /// Buf is full and valid\n    volatile bool   _rxBufValid;\n\n    /// Last digital input from the rx data pin\n    volatile bool   _rxLastSample;\n\n    /// This is the integrate and dump integral. If there are <5 0 samples in the PLL cycle\n    /// the bit is declared a 0, else a 1\n    volatile uint8_t _rxIntegrator;\n\n    /// PLL ramp, varies between 0 and RH_ASK_RX_RAMP_LEN-1 (159) over \n    /// RH_ASK_RX_SAMPLES_PER_BIT (8) samples per nominal bit time. \n    /// When the PLL is synchronised, bit transitions happen at about the\n    /// 0 mark. \n    volatile uint8_t _rxPllRamp;\n\n    /// Flag indicates if we have seen the start symbol of a new message and are\n    /// in the processes of reading and decoding it\n    volatile uint8_t _rxActive;\n\n    /// Last 12 bits received, so we can look for the start symbol\n    volatile uint16_t _rxBits;\n\n    /// How many bits of message we have received. Ranges from 0 to 12\n    volatile uint8_t _rxBitCount;\n    \n    /// The incoming message buffer\n    uint8_t _rxBuf[RH_ASK_MAX_PAYLOAD_LEN];\n    \n    /// The incoming message expected length\n    volatile uint8_t _rxCount;\n    \n    /// The incoming message buffer length received so far\n    volatile uint8_t _rxBufLen;\n\n    /// Index of the next symbol to send. Ranges from 0 to vw_tx_len\n    uint8_t _txIndex;\n\n    /// Bit number of next bit to send\n    uint8_t _txBit;\n\n    /// Sample number for the transmitter. Runs 0 to 7 during one bit interval\n    uint8_t _txSample;\n\n    /// The transmitter buffer in _symbols_ not data octets\n    uint8_t _txBuf[(RH_ASK_MAX_PAYLOAD_LEN * 2) + RH_ASK_PREAMBLE_LEN];\n\n    /// Number of symbols in _txBuf to be sent;\n    uint8_t _txBufLen;\n\n};\n\n/// @example ask_reliable_datagram_client.pde\n/// @example ask_reliable_datagram_server.pde\n/// @example ask_transmitter.pde\n/// @example ask_receiver.pde\n#endif\n"
  },
  {
    "path": "RH_CC110.cpp",
    "content": "// RH_CC110.cpp\n//\n// Driver for Texas Instruments CC110L transceiver.\n//\n// Copyright (C) 2016 Mike McCauley\n// $Id: RH_CC110.cpp,v 1.5 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_CC110.h>\n\n// Interrupt vectors for the 3 Arduino interrupt pins\n// Each interrupt can be handled by a different instance of RH_CC110, allowing you to have\n// 2 or more LORAs per Arduino\nRH_CC110* RH_CC110::_deviceForInterrupt[RH_CC110_NUM_INTERRUPTS] = {0, 0, 0};\nuint8_t RH_CC110::_interruptCount = 0; // Index into _deviceForInterrupt for next device\n\n// We need 2 tables of modem configuration registers, since some values change depending on the Xtal frequency\n// These are indexed by the values of ModemConfigChoice\n// Canned modem configurations generated with the TI SmartRF Studio v7 version 2.3.0 on boodgie\n// based on the sample 'Typical settings'\n// Stored in flash (program) memory to save SRAM\n// For 26MHz crystals\nPROGMEM static const RH_CC110::ModemConfig MODEM_CONFIG_TABLE_26MHZ[] =\n{\n    // 0B    0C    10    11    12    15    19    1A    1B    1C    1D    21    22    23    24    25    26    2C    2D    2E\n    {0x06, 0x00, 0xf5, 0x83, 0x13, 0x15, 0x16, 0x6c, 0x03, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb1_2Fd5_2\n    {0x06, 0x00, 0xf6, 0x83, 0x13, 0x15, 0x16, 0x6c, 0x03, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb2_4Fd5_2\n    {0x06, 0x00, 0xc7, 0x83, 0x13, 0x40, 0x16, 0x6c, 0x43, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb4_8Fd25_4\n    {0x06, 0x00, 0xc8, 0x93, 0x13, 0x34, 0x16, 0x6c, 0x43, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb10Fd19\n    {0x06, 0x00, 0xca, 0x83, 0x13, 0x35, 0x16, 0x6c, 0x43, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb38_4Fd20\n    {0x08, 0x00, 0x7b, 0x83, 0x13, 0x42, 0x1d, 0x1c, 0xc7, 0x00, 0xb2, 0xb6, 0x10, 0xea, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb76_8Fd32\n    {0x08, 0x00, 0x5b, 0xf8, 0x13, 0x47, 0x1d, 0x1c, 0xc7, 0x00, 0xb2, 0xb6, 0x10, 0xea, 0x2a, 0x00, 0x1f, 0x81, 0x31, 0x09}, // GFSK_Rb100Fd47\n    {0x0c, 0x00, 0x2d, 0x3b, 0x13, 0x62, 0x1d, 0x1c, 0xc7, 0x00, 0xb0, 0xb6, 0x10, 0xea, 0x2a, 0x00, 0x1f, 0x88, 0x31, 0x09}, // GFSK_Rb250Fd127\n};\n\n// For 27MHz crystals\nPROGMEM static const RH_CC110::ModemConfig MODEM_CONFIG_TABLE_27MHZ[] =\n{\n    // 0B    0C    10    11    12    15    19    1A    1B    1C    1D    21    22    23    24    25    26    2C    2D    2E\n    {0x06, 0x00, 0xf5, 0x75, 0x13, 0x14, 0x16, 0x6c, 0x03, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb1_2Fd5_2\n    {0x06, 0x00, 0xf6, 0x75, 0x13, 0x14, 0x16, 0x6c, 0x03, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb2_4Fd5_2\n    {0x06, 0x00, 0xc7, 0x75, 0x13, 0x37, 0x16, 0x6c, 0x43, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb4_8Fd25_4\n    {0x06, 0x00, 0xc8, 0x84, 0x13, 0x33, 0x16, 0x6c, 0x43, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb10Fd19\n    {0x06, 0x00, 0xca, 0x75, 0x13, 0x34, 0x16, 0x6c, 0x43, 0x40, 0x91, 0x56, 0x10, 0xe9, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb38_4Fd20\n    {0x08, 0x00, 0x7b, 0x75, 0x13, 0x42, 0x1d, 0x1c, 0xc7, 0x00, 0xb2, 0xb6, 0x10, 0xea, 0x2a, 0x00, 0x1f, 0x81, 0x35, 0x09}, // GFSK_Rb76_8Fd32\n    {0x08, 0x00, 0x5b, 0xf8, 0x13, 0x47, 0x1d, 0x1c, 0xc7, 0x00, 0xb2, 0xb6, 0x10, 0xea, 0x2a, 0x00, 0x1f, 0x81, 0x31, 0x09}, // GFSK_Rb100Fd47\n    {0x0c, 0x00, 0x2d, 0x2f, 0x13, 0x62, 0x1d, 0x1c, 0xc7, 0x00, 0xb0, 0xb6, 0x10, 0xea, 0x2a, 0x00, 0x1f, 0x88, 0x31, 0x09}, // GFSK_Rb250Fd127\n};\n\n// These power outputs are based on the suggested optimum values for \n// multilayer inductors in the 915MHz frequency band. Per table 5-15.\n// Yes these are not linear.\n// Caution: this table is indexed by the values of enum TransmitPower\n// Do not change one without changing the other.\n// If you do not like these values, use setPaTable() directly.\nPROGMEM static const uint8_t paPowerValues[] = \n{\n    0x03, // -30dBm\n    0x0e, // -20dBm\n    0x1e, // -15dBm\n    0x27, // -10dBm\n    0x8e, // 0dBm\n    0xcd, // 5dBm\n    0xc7, // 7dBm\n    0xc0, // 10dBm\n};\n\nRH_CC110::RH_CC110(uint8_t slaveSelectPin, uint8_t interruptPin, bool is27MHz, RHGenericSPI& spi)\n    :\n    RHNRFSPIDriver(slaveSelectPin, spi),\n    _rxBufValid(false),\n    _is27MHz(is27MHz)\n{\n    _interruptPin = interruptPin;\n    _myInterruptIndex = 0xff; // Not allocated yet\n}\n\nbool RH_CC110::init()\n{\n    if (!RHNRFSPIDriver::init())\n\treturn false;\n\n    // Determine the interrupt number that corresponds to the interruptPin\n    int interruptNumber = digitalPinToInterrupt(_interruptPin);\n    if (interruptNumber == NOT_AN_INTERRUPT)\n\treturn false;\n#ifdef RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER\n    interruptNumber = _interruptPin;\n#endif\n\n    // Reset the chip\n    // Strobe the reset\n    uint8_t val = spiCommand(RH_CC110_STROBE_30_SRES); // Reset\n    delay(100);\n    val = spiCommand(RH_CC110_STROBE_36_SIDLE); // IDLE\n    if (val != 0x0f)\n\treturn false; // No chip there or reset failed.\n\n    // Add by Adrien van den Bossche <vandenbo@univ-tlse2.fr> for Teensy\n    // ARM M4 requires the below. else pin interrupt doesn't work properly.\n    // On all other platforms, its innocuous, belt and braces\n    pinMode(_interruptPin, INPUT); \n\n    // Set up interrupt handler\n    // Since there are a limited number of interrupt glue functions isr*() available,\n    // we can only support a limited number of devices simultaneously\n    // ON some devices, notably most Arduinos, the interrupt pin passed in is actuallt the \n    // interrupt number. You have to figure out the interruptnumber-to-interruptpin mapping\n    // yourself based on knwledge of what Arduino board you are running on.\n    if (_myInterruptIndex == 0xff)\n    {\n\t// First run, no interrupt allocated yet\n\tif (_interruptCount <= RH_CC110_NUM_INTERRUPTS)\n\t    _myInterruptIndex = _interruptCount++;\n\telse\n\t    return false; // Too many devices, not enough interrupt vectors\n    }\n    _deviceForInterrupt[_myInterruptIndex] = this;\n    if (_myInterruptIndex == 0)\n\tattachInterrupt(interruptNumber, isr0, RISING);\n    else if (_myInterruptIndex == 1)\n\tattachInterrupt(interruptNumber, isr1, RISING);\n    else if (_myInterruptIndex == 2)\n\tattachInterrupt(interruptNumber, isr2, RISING);\n    else\n\treturn false; // Too many devices, not enough interrupt vectors\n\n    spiWriteRegister(RH_CC110_REG_02_IOCFG0, RH_CC110_GDO_CFG_CRC_OK_AUTORESET);  // gdo0 interrupt on CRC_OK\n    spiWriteRegister(RH_CC110_REG_06_PKTLEN, RH_CC110_MAX_PAYLOAD_LEN); // max packet length\n    spiWriteRegister(RH_CC110_REG_07_PKTCTRL1, RH_CC110_CRC_AUTOFLUSH); // no append status, crc autoflush, no addr check\n    spiWriteRegister(RH_CC110_REG_08_PKTCTRL0, RH_CC110_PKT_FORMAT_NORMAL | RH_CC110_CRC_EN | RH_CC110_LENGTH_CONFIG_VARIABLE);\n    spiWriteRegister(RH_CC110_REG_13_MDMCFG1, RH_CC110_NUM_PREAMBLE_4); // 4 preamble bytes, chan spacing not used\n    spiWriteRegister(RH_CC110_REG_17_MCSM1, RH_CC110_CCA_MODE_RSSI_PACKET | RH_CC110_RXOFF_MODE_RX | RH_CC110_TXOFF_MODE_IDLE);\n    spiWriteRegister(RH_CC110_REG_18_MCSM0, RH_CC110_FS_AUTOCAL_FROM_IDLE | RH_CC110_PO_TIMEOUT_64); // cal when going to tx or rx\n    spiWriteRegister(RH_CC110_REG_20_WORCTRL, 0xfb); // from smartrf\n    spiWriteRegister(RH_CC110_REG_29_FSTEST, 0x59); // from smartrf\n    spiWriteRegister(RH_CC110_REG_2A_PTEST, 0x7f); // from smartrf\n    spiWriteRegister(RH_CC110_REG_2B_AGCTEST, 0x3f); // from smartrf\n\n    // Set some reasonable default values\n    uint8_t syncWords[] = { 0xd3, 0x91 };\n    setSyncWords(syncWords, sizeof(syncWords));\n    setTxPower(TransmitPower5dBm);\n    setFrequency(915.0);\n    setModemConfig(GFSK_Rb1_2Fd5_2);\n    return true;\n}\n\nvoid RH_CC110::setIs27MHz(bool is27MHz)\n{\n    _is27MHz = is27MHz;\n}\n\n// C++ level interrupt handler for this instance\n// We use this to get RxDone and TxDone interrupts\nvoid RH_CC110::handleInterrupt()\n{\n//    Serial.println(\"I\");\n    if (_mode == RHModeRx)\n    {\n\t// Radio is confgigured to stay in RX until we move it to IDLE after a CRC_OK message for us\n\t// We only get interrupts in RX mode, on CRC_OK\n\t// CRC OK\n\t_lastRssi = spiBurstReadRegister(RH_CC110_REG_34_RSSI); // Was set when sync word was detected\n\t_bufLen = spiReadRegister(RH_CC110_REG_3F_FIFO);\n\tif (_bufLen < 4)\n\t{\n\t    // Something wrong there, flush the FIFO\n\t    spiCommand(RH_CC110_STROBE_3A_SFRX);\n\t    clearRxBuf();\n\t    return;\n\t}\n\tspiBurstRead(RH_CC110_REG_3F_FIFO | RH_CC110_SPI_BURST_MASK | RH_CC110_SPI_READ_MASK, _buf, _bufLen);\n\t// All good so far. See if its for us\n\tvalidateRxBuf(); \n\tif (_rxBufValid)\n\t    setModeIdle(); // Done\n    }\n}\n\n// These are low level functions that call the interrupt handler for the correct\n// instance of RH_CC110.\n// 3 interrupts allows us to have 3 different devices\nvoid RH_CC110::isr0()\n{\n    if (_deviceForInterrupt[0])\n\t_deviceForInterrupt[0]->handleInterrupt();\n}\nvoid RH_CC110::isr1()\n{\n    if (_deviceForInterrupt[1])\n\t_deviceForInterrupt[1]->handleInterrupt();\n}\nvoid RH_CC110::isr2()\n{\n    if (_deviceForInterrupt[2])\n\t_deviceForInterrupt[2]->handleInterrupt();\n}\n\nuint8_t RH_CC110::spiReadRegister(uint8_t reg)\n{\n    return spiRead((reg & 0x3f) | RH_CC110_SPI_READ_MASK);\n}\n\nuint8_t RH_CC110::spiBurstReadRegister(uint8_t reg)\n{\n    return spiRead((reg & 0x3f) | RH_CC110_SPI_READ_MASK | RH_CC110_SPI_BURST_MASK);\n}\n\nuint8_t RH_CC110::spiWriteRegister(uint8_t reg, uint8_t val)\n{\n    return spiWrite((reg & 0x3f), val);\n}\n\nuint8_t  RH_CC110::spiBurstWriteRegister(uint8_t reg, const uint8_t* src, uint8_t len)\n{\n    return spiBurstWrite((reg & 0x3f) | RH_CC110_SPI_BURST_MASK, src, len);\n}\n\nbool RH_CC110::printRegisters()\n{\n#ifdef RH_HAVE_SERIAL\n    uint8_t i;\n    for (i = 0; i <= 0x2f; i++)\n    {\n\tSerial.print(i, HEX);\n\tSerial.print(\": \");\n\tSerial.println(spiReadRegister(i), HEX);\n    }\n    // Burst registers\n    for (i = 0x30; i <= 0x3e; i++)\n    {\n\tSerial.print(i, HEX);\n\tSerial.print(\": \");\n\tSerial.println(spiBurstReadRegister(i), HEX);\n    }\n#endif\n    return true;\n}\n\n// Check whether the latest received message is complete and uncorrupted\nvoid RH_CC110::validateRxBuf()\n{\n    if (_bufLen < 4)\n\treturn; // Too short to be a real message\n    // Extract the 4 headers\n    _rxHeaderTo    = _buf[0];\n    _rxHeaderFrom  = _buf[1];\n    _rxHeaderId    = _buf[2];\n    _rxHeaderFlags = _buf[3];\n    if (_promiscuous ||\n\t_rxHeaderTo == _thisAddress ||\n\t_rxHeaderTo == RH_BROADCAST_ADDRESS)\n    {\n\t_rxGood++;\n\t_rxBufValid = true;\n    }\n}\n\nbool RH_CC110::available()\n{\n    if (_mode == RHModeTx)\n\treturn false;\n    if (_rxBufValid) // Will be set by the interrupt handler when a good message is received\n\treturn true;\n    setModeRx(); // Make sure we are receiving\n    return false; // Nothing yet\n}\n\nvoid RH_CC110::clearRxBuf()\n{\n    ATOMIC_BLOCK_START;\n    _rxBufValid = false;\n    _bufLen = 0;\n    ATOMIC_BLOCK_END;\n}\n\nbool RH_CC110::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n\n    if (buf && len)\n    {\n\tATOMIC_BLOCK_START;\n\t// Skip the 4 headers that are at the beginning of the rxBuf\n\tif (*len > _bufLen - RH_CC110_HEADER_LEN)\n\t    *len = _bufLen - RH_CC110_HEADER_LEN;\n\tmemcpy(buf, _buf + RH_CC110_HEADER_LEN, *len);\n\tATOMIC_BLOCK_END;\n    }\n    clearRxBuf(); // This message accepted and cleared\n\n    return true;\n}\n\nbool RH_CC110::send(const uint8_t* data, uint8_t len)\n{\n    if (len > RH_CC110_MAX_MESSAGE_LEN)\n\treturn false;\n\n    waitPacketSent(); // Make sure we dont interrupt an outgoing message\n    setModeIdle();\n\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    spiWriteRegister(RH_CC110_REG_3F_FIFO, len + RH_CC110_HEADER_LEN);\n    spiWriteRegister(RH_CC110_REG_3F_FIFO,_txHeaderTo);\n    spiWriteRegister(RH_CC110_REG_3F_FIFO,_txHeaderFrom);\n    spiWriteRegister(RH_CC110_REG_3F_FIFO,_txHeaderId);\n    spiWriteRegister(RH_CC110_REG_3F_FIFO,_txHeaderFlags);\n    spiBurstWriteRegister(RH_CC110_REG_3F_FIFO, data, len);\n\n    // Radio returns to Idle when TX is finished\n    // need waitPacketSent() to detect change of _mode and TX completion\n    setModeTx();\n\n    return true;\n}\n\nuint8_t RH_CC110::maxMessageLength()\n{\n    return RH_CC110_MAX_MESSAGE_LEN;\n}\n\nvoid RH_CC110::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\tspiCommand(RH_CC110_STROBE_36_SIDLE);\n\t_mode = RHModeIdle;\n    }\n}\n\nbool RH_CC110::sleep()\n{\n    if (_mode != RHModeSleep)\n    {\n\tspiCommand(RH_CC110_STROBE_39_SPWD);\n\t_mode = RHModeSleep;\n    }\n    return true;\n}\n\nvoid RH_CC110::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\t// Radio is configuewd to stay in RX mode\n\t// only receipt of a CRC_OK wil cause us to return it to IDLE\n\tspiCommand(RH_CC110_STROBE_34_SRX);\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_CC110::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\tspiCommand(RH_CC110_STROBE_35_STX);\n\t_mode = RHModeTx;\n    }\n}\n\nuint8_t RH_CC110::statusRead()\n{\t\n    return spiCommand(RH_CC110_STROBE_3D_SNOP);\n}\n\n// Sigh, this chip has no TXDONE type interrupt, so we have to poll\nbool RH_CC110::waitPacketSent()\n{\n    // If we are not currently in transmit mode, there is no packet to wait for\n    if (_mode != RHModeTx)\n\treturn false;\n\n    // Caution: may transition through CALIBRATE\n    while ((statusRead() & RH_CC110_STATUS_STATE) != RH_CC110_STATUS_IDLE)\n\tYIELD;\n\n    _mode = RHModeIdle;\n    return true;\n}\n\nbool RH_CC110::setTxPower(TransmitPower power)\n{\n    if (power > sizeof(paPowerValues))\n\treturn false;\n\n    uint8_t patable[2];\n    memcpy_P(&patable[0], (void*)&paPowerValues[power], sizeof(uint8_t));\n    patable[1] = 0x00;\n    setPaTable(patable, sizeof(patable));\n    return true;\n}\n\nvoid RH_CC110::setPaTable(uint8_t* patable, uint8_t patablesize)\n{\n    spiBurstWriteRegister(RH_CC110_REG_3E_PATABLE, patable, patablesize);\n}\n\nbool RH_CC110::setFrequency(float centre)\n{\n    // From section 5.21: fcarrier = fxosc / 2^16 * FREQ\n    uint32_t FREQ;\n    float fxosc = _is27MHz ? 27.0 : 26.0;\n    FREQ = (uint32_t)(centre * 65536 / fxosc);\n    // Some trivial checks\n    if (FREQ & 0xff000000)\n\treturn false;\n    spiWriteRegister(RH_CC110_REG_0D_FREQ2, (FREQ >> 16) & 0xff);\n    spiWriteRegister(RH_CC110_REG_0E_FREQ1, (FREQ >> 8) & 0xff);\n    spiWriteRegister(RH_CC110_REG_0F_FREQ0, FREQ & 0xff);\n\n    // Radio is configured to calibrate automatically whenever it enters RX or TX mode\n    // so no need to check for PLL lock here\n    return true;\n}\n\n// Sets registers from a canned modem configuration structure\nvoid RH_CC110::setModemRegisters(const ModemConfig* config)\n{\n    spiWriteRegister(RH_CC110_REG_0B_FSCTRL1,  config->reg_0b);\n    spiWriteRegister(RH_CC110_REG_0C_FSCTRL0,  config->reg_0c);\n    spiWriteRegister(RH_CC110_REG_10_MDMCFG4,  config->reg_10);\n    spiWriteRegister(RH_CC110_REG_11_MDMCFG3,  config->reg_11);\n    spiWriteRegister(RH_CC110_REG_12_MDMCFG2,  config->reg_12);\n    spiWriteRegister(RH_CC110_REG_15_DEVIATN,  config->reg_15);\n    spiWriteRegister(RH_CC110_REG_19_FOCCFG,   config->reg_19);\n    spiWriteRegister(RH_CC110_REG_1A_BSCFG,    config->reg_1a);\n    spiWriteRegister(RH_CC110_REG_1B_AGCCTRL2, config->reg_1b);\n    spiWriteRegister(RH_CC110_REG_1C_AGCCTRL1, config->reg_1c);\n    spiWriteRegister(RH_CC110_REG_1D_AGCCTRL0, config->reg_1d);\n    spiWriteRegister(RH_CC110_REG_21_FREND1,   config->reg_21);\n    spiWriteRegister(RH_CC110_REG_22_FREND0,   config->reg_22);\n    spiWriteRegister(RH_CC110_REG_23_FSCAL3,   config->reg_23);\n    spiWriteRegister(RH_CC110_REG_24_FSCAL2,   config->reg_24);\n    spiWriteRegister(RH_CC110_REG_25_FSCAL1,   config->reg_25);\n    spiWriteRegister(RH_CC110_REG_26_FSCAL0,   config->reg_26);\n    spiWriteRegister(RH_CC110_REG_2C_TEST2,    config->reg_2c);\n    spiWriteRegister(RH_CC110_REG_2D_TEST1,    config->reg_2d);\n    spiWriteRegister(RH_CC110_REG_2E_TEST0,    config->reg_2e);\n}\n\n// Set one of the canned Modem configs\n// Returns true if its a valid choice\nbool RH_CC110::setModemConfig(ModemConfigChoice index)\n{\n    if (index > (signed int)(sizeof(MODEM_CONFIG_TABLE_27MHZ) / sizeof(ModemConfig)))\n        return false;\n\n    const RH_CC110::ModemConfig *p = _is27MHz ? MODEM_CONFIG_TABLE_27MHZ : MODEM_CONFIG_TABLE_26MHZ ;\n    RH_CC110::ModemConfig cfg;\n    memcpy_P(&cfg, p + index, sizeof(RH_CC110::ModemConfig));\n    setModemRegisters(&cfg);\n\n    return true;\n}\n\nvoid RH_CC110::setSyncWords(const uint8_t* syncWords, uint8_t len)\n{\n    if (!syncWords || len != 2)\n\treturn; // Only 2 byte sync words are supported\n\n    spiWriteRegister(RH_CC110_REG_04_SYNC1, syncWords[0]);\n    spiWriteRegister(RH_CC110_REG_05_SYNC0, syncWords[1]);\n}\n"
  },
  {
    "path": "RH_CC110.h",
    "content": "// RH_CC110.h\n//\n// Definitions for Texas Instruments CC110L transceiver.\n// http://www.ti.com/lit/ds/symlink/cc110l.pdf\n// As used in Anaren CC110L Air Module BoosterPack\n// https://www.anaren.com/air/cc110l-air-module-boosterpack-embedded-antenna-module-anaren\n// \n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2016 Mike McCauley\n// $Id: RH_CC110.h,v 1.5 2016/04/04 01:40:12 mikem Exp $\n// \n\n#ifndef RH_CC110_h\n#define RH_CC110_h\n\n\n#include <RHNRFSPIDriver.h>\n\n// This is the maximum number of interrupts the driver can support\n// Most Arduinos can handle 2, Megas can handle more\n#define RH_CC110_NUM_INTERRUPTS 3\n\n// Max number of octets the FIFO can hold\n#define RH_CC110_FIFO_SIZE 64\n\n// This is the maximum number of bytes that can be carried by the chip\n// We use some for headers, keeping fewer for RadioHead messages\n#define RH_CC110_MAX_PAYLOAD_LEN RH_CC110_FIFO_SIZE\n\n// The length of the headers we add.\n// The headers are inside the chip payload\n#define RH_CC110_HEADER_LEN 4\n\n// This is the maximum message length that can be supported by this driver. \n// Can be pre-defined to a smaller size (to save SRAM) prior to including this header\n// Here we allow for 1 byte message length, 4 bytes headers, user data \n#ifndef RH_CC110_MAX_MESSAGE_LEN\n #define RH_CC110_MAX_MESSAGE_LEN (RH_CC110_MAX_PAYLOAD_LEN - RH_CC110_HEADER_LEN - 1)\n#endif\n\n#define RH_CC110_SPI_READ_MASK  0x80\n#define RH_CC110_SPI_BURST_MASK 0x40\n\n// Register definitions from Table 5-22\n#define RH_CC110_REG_00_IOCFG2                 0x00\n#define RH_CC110_REG_01_IOCFG1                 0x01\n#define RH_CC110_REG_02_IOCFG0                 0x02\n#define RH_CC110_REG_03_FIFOTHR                0x03\n#define RH_CC110_REG_04_SYNC1                  0x04\n#define RH_CC110_REG_05_SYNC0                  0x05\n#define RH_CC110_REG_06_PKTLEN                 0x06\n#define RH_CC110_REG_07_PKTCTRL1               0x07\n#define RH_CC110_REG_08_PKTCTRL0               0x08\n#define RH_CC110_REG_09_ADDR                   0x09\n#define RH_CC110_REG_0A_CHANNR                 0x0a\n#define RH_CC110_REG_0B_FSCTRL1                0x0b\n#define RH_CC110_REG_0C_FSCTRL0                0x0c\n#define RH_CC110_REG_0D_FREQ2                  0x0d\n#define RH_CC110_REG_0E_FREQ1                  0x0e\n#define RH_CC110_REG_0F_FREQ0                  0x0f\n#define RH_CC110_REG_10_MDMCFG4                0x10\n#define RH_CC110_REG_11_MDMCFG3                0x11\n#define RH_CC110_REG_12_MDMCFG2                0x12\n#define RH_CC110_REG_13_MDMCFG1                0x13\n#define RH_CC110_REG_14_MDMCFG0                0x14\n#define RH_CC110_REG_15_DEVIATN                0x15\n#define RH_CC110_REG_16_MCSM2                  0x16\n#define RH_CC110_REG_17_MCSM1                  0x17\n#define RH_CC110_REG_18_MCSM0                  0x18\n#define RH_CC110_REG_19_FOCCFG                 0x19\n#define RH_CC110_REG_1A_BSCFG                  0x1a\n#define RH_CC110_REG_1B_AGCCTRL2               0x1b\n#define RH_CC110_REG_1C_AGCCTRL1               0x1c\n#define RH_CC110_REG_1D_AGCCTRL0               0x1d\n#define RH_CC110_REG_1E_WOREVT1                0x1e\n#define RH_CC110_REG_1F_WOREVT0                0x1f\n#define RH_CC110_REG_20_WORCTRL                0x20\n#define RH_CC110_REG_21_FREND1                 0x21\n#define RH_CC110_REG_22_FREND0                 0x22\n#define RH_CC110_REG_23_FSCAL3                 0x23\n#define RH_CC110_REG_24_FSCAL2                 0x24\n#define RH_CC110_REG_25_FSCAL1                 0x25\n#define RH_CC110_REG_26_FSCAL0                 0x26\n#define RH_CC110_REG_27_RCCTRL1                0x28\n#define RH_CC110_REG_28_RCCTRL0                0x29\n#define RH_CC110_REG_29_FSTEST                 0x2a\n#define RH_CC110_REG_2A_PTEST                  0x2b\n#define RH_CC110_REG_2B_AGCTEST                0x2c\n#define RH_CC110_REG_2C_TEST2                  0x2c\n#define RH_CC110_REG_2D_TEST1                  0x2d\n#define RH_CC110_REG_2E_TEST0                  0x2e\n\n// Single byte read and write version of registers 0x30 to 0x3f. Strobes\n// use spiCommand()\n#define RH_CC110_STROBE_30_SRES                0x30\n#define RH_CC110_STROBE_31_SFSTXON             0x31\n#define RH_CC110_STROBE_32_SXOFF               0x32\n#define RH_CC110_STROBE_33_SCAL                0x33\n#define RH_CC110_STROBE_34_SRX                 0x34\n#define RH_CC110_STROBE_35_STX                 0x35\n#define RH_CC110_STROBE_36_SIDLE               0x36\n\n#define RH_CC110_STROBE_39_SPWD                0x39\n#define RH_CC110_STROBE_3A_SFRX                0x3a\n#define RH_CC110_STROBE_3B_SFTX                0x3b\n\n#define RH_CC110_STROBE_3D_SNOP                0x3d\n\n\n// Burst read from these registers gives more data:\n// use spiBurstReadRegister()\n#define RH_CC110_REG_30_PARTNUM                0x30\n#define RH_CC110_REG_31_VERSION                0x31\n#define RH_CC110_REG_32_FREQEST                0x32\n#define RH_CC110_REG_33_CRC_REG                0x33\n#define RH_CC110_REG_34_RSSI                   0x34\n#define RH_CC110_REG_35_MARCSTATE              0x35\n\n#define RH_CC110_REG_38_PKTSTATUS              0x38\n\n#define RH_CC110_REG_3A_TXBYTES                0x3a\n#define RH_CC110_REG_3B_RXBYTES                0x3b\n\n// PATABLE, TXFIFO, RXFIFO also support burst\n#define RH_CC110_REG_3E_PATABLE                0x3e\n#define RH_CC110_REG_3F_FIFO                   0x3f\n\n// Status Byte\n#define RH_CC110_STATUS_CHIP_RDY            0x80\n#define RH_CC110_STATUS_STATE               0x70\n#define RH_CC110_STATUS_IDLE                0x00\n#define RH_CC110_STATUS_RX                  0x10\n#define RH_CC110_STATUS_TX                  0x20\n#define RH_CC110_STATUS_FSTXON              0x30\n#define RH_CC110_STATUS_CALIBRATE           0x40\n#define RH_CC110_STATUS_SETTLING            0x50\n#define RH_CC110_STATUS_RXFIFO_OVERFLOW     0x60\n#define RH_CC110_STATUS_TXFIFO_UNDERFLOW    0x70\n#define RH_CC110_STATUS_FIFOBYTES_AVAILABLE 0x0f\n\n// Register contents\n// Chip Status Byte, read from header, data or command strobe\n#define RH_CC110_CHIP_RDY                   0x80\n#define RH_CC110_STATE                      0x70\n#define RH_CC110_FIFO_BYTES_AVAILABLE       0x0f\n\n// Register bit field definitions\n// #define RH_CC110_REG_00_IOCFG2                 0x00\n// #define RH_CC110_REG_01_IOCFG1                 0x01\n// #define RH_CC110_REG_02_IOCFG0                 0x02\n#define RH_CC110_GDO_CFG_RX_FIFO_THR              0x00\n#define RH_CC110_GDO_CFG_RX_FIFO_FULL             0x01\n#define RH_CC110_GDO_CFG_TX_FIFO_THR              0x02\n#define RH_CC110_GDO_CFG_TX_FIFO_EMPTY            0x03\n#define RH_CC110_GDO_CFG_RX_FIFO_OVERFLOW         0x04\n#define RH_CC110_GDO_CFG_TX_FIFO_UNDEFLOOW        0x05\n#define RH_CC110_GDO_CFG_SYNC                     0x06\n#define RH_CC110_GDO_CFG_CRC_OK_AUTORESET         0x07\n#define RH_CC110_GDO_CFG_CCA                      0x09\n#define RH_CC110_GDO_CFG_LOCK_DETECT              0x0a\n#define RH_CC110_GDO_CFG_SERIAL_CLOCK             0x0b\n#define RH_CC110_GDO_CFG_SYNCHRONOUS_SDO          0x0c\n#define RH_CC110_GDO_CFG_SDO                      0x0d\n#define RH_CC110_GDO_CFG_CARRIER                  0x0e\n#define RH_CC110_GDO_CFG_CRC_OK                   0x0f\n#define RH_CC110_GDO_CFG_PA_PD                    0x1b\n#define RH_CC110_GDO_CFG_LNA_PD                   0x1c\n#define RH_CC110_GDO_CFG_CLK_32K                  0x27\n#define RH_CC110_GDO_CFG_CHIP_RDYN                0x29\n#define RH_CC110_GDO_CFG_XOSC_STABLE              0x2b\n#define RH_CC110_GDO_CFG_HIGH_IMPEDANCE           0x2e\n#define RH_CC110_GDO_CFG_0                        0x2f\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_1           0x30\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_1_5         0x31\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_2           0x32\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_3           0x33\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_4           0x34\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_6           0x35\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_8           0x36\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_12          0x37\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_16          0x38\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_24          0x39\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_32          0x3a\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_48          0x3b\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_64          0x3c\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_96          0x3d\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_128         0x3e\n#define RH_CC110_GDO_CFG_CLK_XOSC_DIV_192         0x3f\n\n// #define RH_CC110_REG_03_FIFOTHR                0x03\n#define RH_CC110_ADC_RETENTION                    0x80\n\n#define RH_CC110_CLOSE_IN_RX                      0x30\n#define RH_CC110_CLOSE_IN_RX_0DB                  0x00\n#define RH_CC110_CLOSE_IN_RX_6DB                  0x10\n#define RH_CC110_CLOSE_IN_RX_12DB                 0x20\n#define RH_CC110_CLOSE_IN_RX_18DB                 0x30\n\n#define RH_CC110_FIFO_THR                         0x0f\n\n// #define RH_CC110_REG_04_SYNC1                  0x04\n// #define RH_CC110_REG_05_SYNC0                  0x05\n// #define RH_CC110_REG_06_PKTLEN                 0x06\n// #define RH_CC110_REG_07_PKTCTRL1               0x07\n#define RH_CC110_CRC_AUTOFLUSH                    0x08\n#define RH_CC110_APPEND_STATUS                    0x04\n#define RH_CC110_ADDR_CHK                         0x03\n// can or the next 2:\n#define RH_CC110_ADDR_CHK_ADDRESS                 0x01\n#define RH_CC110_ADDR_CHK_BROADCAST               0x02\n\n\n// #define RH_CC110_REG_08_PKTCTRL0               0x08\n#define RH_CC110_PKT_FORMAT                       0x30\n#define RH_CC110_PKT_FORMAT_NORMAL                0x00\n#define RH_CC110_PKT_FORMAT_SYNC_SERIAL           0x10\n#define RH_CC110_PKT_FORMAT_RANDOM_TX             0x20\n#define RH_CC110_PKT_FORMAT_ASYNC_SERIAL          0x30\n\n#define RH_CC110_CRC_EN                           0x04\n\n#define RH_CC110_LENGTH_CONFIG                    0x03\n#define RH_CC110_LENGTH_CONFIG_FIXED              0x00\n#define RH_CC110_LENGTH_CONFIG_VARIABLE           0x01\n#define RH_CC110_LENGTH_CONFIG_INFINITE           0x02\n\n// #define RH_CC110_REG_09_ADDR                   0x09\n// #define RH_CC110_REG_0A_CHANNR                 0x0a\n// #define RH_CC110_REG_0B_FSCTRL1                0x0b\n// #define RH_CC110_REG_0C_FSCTRL0                0x0c\n// #define RH_CC110_REG_0D_FREQ2                  0x0d\n// #define RH_CC110_REG_0E_FREQ1                  0x0e\n// #define RH_CC110_REG_0F_FREQ0                  0x0f\n// #define RH_CC110_REG_10_MDMCFG4                0x10\n#define RH_CC110_CHANBW_E                         0xc0\n#define RH_CC110_CHANBW_M                         0x30\n#define RH_CC110_DRATE_E                          0x0f\n\n// #define RH_CC110_REG_11_MDMCFG3                0x11\n// #define RH_CC110_REG_12_MDMCFG2                0x12\n#define RH_CC110_DEM_DCFILT_OFF                   0x80\n#define RH_CC110_MOD_FORMAT                       0x70\n#define RH_CC110_MOD_FORMAT_2FSK                  0x00\n#define RH_CC110_MOD_FORMAT_GFSK                  0x10\n#define RH_CC110_MOD_FORMAT_OOK                   0x30\n#define RH_CC110_MOD_FORMAT_4FSK                  0x40\n#define RH_CC110_MANCHESTER_EN                    0x08\n#define RH_CC110_SYNC_MODE                        0x07\n#define RH_CC110_SYNC_MODE_NONE                   0x00\n#define RH_CC110_SYNC_MODE_15_16                  0x01\n#define RH_CC110_SYNC_MODE_16_16                  0x02\n#define RH_CC110_SYNC_MODE_30_32                  0x03\n#define RH_CC110_SYNC_MODE_NONE_CARRIER           0x04\n#define RH_CC110_SYNC_MODE_15_16_CARRIER          0x05\n#define RH_CC110_SYNC_MODE_16_16_CARRIER          0x06\n#define RH_CC110_SYNC_MODE_30_32_CARRIER          0x07\n\n// #define RH_CC110_REG_13_MDMCFG1                0x13\n#define RH_CC110_NUM_PREAMBLE                     0x70\n#define RH_CC110_NUM_PREAMBLE_2                   0x00\n#define RH_CC110_NUM_PREAMBLE_3                   0x10\n#define RH_CC110_NUM_PREAMBLE_4                   0x20\n#define RH_CC110_NUM_PREAMBLE_6                   0x30\n#define RH_CC110_NUM_PREAMBLE_8                   0x40\n#define RH_CC110_NUM_PREAMBLE_12                  0x50\n#define RH_CC110_NUM_PREAMBLE_16                  0x60\n#define RH_CC110_NUM_PREAMBLE_24                  0x70\n\n#define RH_CC110_CHANSPC_E                        0x03\n\n// #define RH_CC110_REG_14_MDMCFG0                0x14\n// #define RH_CC110_REG_15_DEVIATN                0x15\n#define RH_CC110_DEVIATION_E                      0x70\n#define RH_CC110_DEVIATION_M                      0x07\n\n// #define RH_CC110_REG_16_MCSM2                  0x16\n#define RH_CC110_RX_TIME_RSSI                     0x10\n\n// #define RH_CC110_REG_17_MCSM1                  0x17\n#define RH_CC110_CCA_MODE                         0x30\n#define RH_CC110_CCA_MODE_ALWAYS                  0x00\n#define RH_CC110_CCA_MODE_RSSI                    0x10\n#define RH_CC110_CCA_MODE_PACKET                  0x20\n#define RH_CC110_CCA_MODE_RSSI_PACKET             0x30\n#define RH_CC110_RXOFF_MODE                       0x0c\n#define RH_CC110_RXOFF_MODE_IDLE                  0x00\n#define RH_CC110_RXOFF_MODE_FSTXON                0x04\n#define RH_CC110_RXOFF_MODE_TX                    0x08\n#define RH_CC110_RXOFF_MODE_RX                    0x0c\n#define RH_CC110_TXOFF_MODE                       0x03\n#define RH_CC110_TXOFF_MODE_IDLE                  0x00\n#define RH_CC110_TXOFF_MODE_FSTXON                0x01\n#define RH_CC110_TXOFF_MODE_TX                    0x02\n#define RH_CC110_TXOFF_MODE_RX                    0x03\n\n// #define RH_CC110_REG_18_MCSM0                  0x18\n#define RH_CC110_FS_AUTOCAL                       0x30\n#define RH_CC110_FS_AUTOCAL_NEVER                 0x00\n#define RH_CC110_FS_AUTOCAL_FROM_IDLE             0x10\n#define RH_CC110_FS_AUTOCAL_TO_IDLE               0x20\n#define RH_CC110_FS_AUTOCAL_TO_IDLE_4             0x30\n#define RH_CC110_PO_TIMEOUT                       0x0c\n#define RH_CC110_PO_TIMEOUT_1                     0x00\n#define RH_CC110_PO_TIMEOUT_16                    0x04\n#define RH_CC110_PO_TIMEOUT_64                    0x08\n#define RH_CC110_PO_TIMEOUT_256                   0x0c\n#define RH_CC110_XOSC_FORCE_ON                    0x01\n\n// #define RH_CC110_REG_19_FOCCFG                 0x19\n#define RH_CC110_FOC_BS_CS_GATE                   0x20\n#define RH_CC110_FOC_PRE_K                        0x18\n#define RH_CC110_FOC_PRE_K_0                      0x00\n#define RH_CC110_FOC_PRE_K_1                      0x08\n#define RH_CC110_FOC_PRE_K_2                      0x10\n#define RH_CC110_FOC_PRE_K_3                      0x18\n#define RH_CC110_FOC_POST_K                       0x04\n#define RH_CC110_FOC_LIMIT                        0x03\n#define RH_CC110_FOC_LIMIT_0                      0x00\n#define RH_CC110_FOC_LIMIT_8                      0x01\n#define RH_CC110_FOC_LIMIT_4                      0x02\n#define RH_CC110_FOC_LIMIT_2                      0x03\n\n// #define RH_CC110_REG_1A_BSCFG                  0x1a\n#define RH_CC110_BS_PRE_K                         0xc0\n#define RH_CC110_BS_PRE_K_1                       0x00\n#define RH_CC110_BS_PRE_K_2                       0x40\n#define RH_CC110_BS_PRE_K_3                       0x80\n#define RH_CC110_BS_PRE_K_4                       0xc0\n#define RH_CC110_BS_PRE_KP                        0x30\n#define RH_CC110_BS_PRE_KP_1                      0x00\n#define RH_CC110_BS_PRE_KP_2                      0x10\n#define RH_CC110_BS_PRE_KP_3                      0x20\n#define RH_CC110_BS_PRE_KP_4                      0x30\n#define RH_CC110_BS_POST_KI                       0x08\n#define RH_CC110_BS_POST_KP                       0x04\n#define RH_CC110_BS_LIMIT                         0x03\n#define RH_CC110_BS_LIMIT_0                       0x00\n#define RH_CC110_BS_LIMIT_3                       0x01\n#define RH_CC110_BS_LIMIT_6                       0x02\n#define RH_CC110_BS_LIMIT_12                      0x03\n\n// #define RH_CC110_REG_1B_AGCCTRL2               0x1b\n#define RH_CC110_MAX_DVA_GAIN                     0xc0\n#define RH_CC110_MAX_DVA_GAIN_ALL                 0x00\n#define RH_CC110_MAX_DVA_GAIN_ALL_LESS_1          0x40\n#define RH_CC110_MAX_DVA_GAIN_ALL_LESS_2          0x80\n#define RH_CC110_MAX_DVA_GAIN_ALL_LESS_3          0xc0\n#define RH_CC110_MAX_LNA_GAIN                     0x38\n\n#define RH_CC110_MAGN_TARGET                      0x07\n#define RH_CC110_MAGN_TARGET_24DB                 0x00\n#define RH_CC110_MAGN_TARGET_27DB                 0x01\n#define RH_CC110_MAGN_TARGET_30DB                 0x02\n#define RH_CC110_MAGN_TARGET_33DB                 0x03\n#define RH_CC110_MAGN_TARGET_36DB                 0x04\n#define RH_CC110_MAGN_TARGET_38DB                 0x05\n#define RH_CC110_MAGN_TARGET_40DB                 0x06\n#define RH_CC110_MAGN_TARGET_42DB                 0x07\n\n// #define RH_CC110_REG_1C_AGCCTRL1               0x1c\n#define RH_CC110_AGC_LNA_PRIORITY                 0x40\n#define RH_CC110_CARRIER_SENSE_REL_THR            0x30\n#define RH_CC110_CARRIER_SENSE_REL_THR_0DB        0x00\n#define RH_CC110_CARRIER_SENSE_REL_THR_6DB        0x10\n#define RH_CC110_CARRIER_SENSE_REL_THR_10DB       0x20\n#define RH_CC110_CARRIER_SENSE_REL_THR_14DB       0x30\n#define RH_CC110_CARRIER_SENSE_ABS_THR            0x0f\n\n// #define RH_CC110_REG_1D_AGCCTRL0               0x1d\n#define RH_CC110_HYST_LEVEL                       0xc0\n#define RH_CC110_HYST_LEVEL_NONE                  0x00\n#define RH_CC110_HYST_LEVEL_LOW                   0x40\n#define RH_CC110_HYST_LEVEL_MEDIUM                0x80\n#define RH_CC110_HYST_LEVEL_HIGH                  0xc0\n#define RH_CC110_WAIT_TIME                        0x30\n#define RH_CC110_WAIT_TIME_8                      0x00\n#define RH_CC110_WAIT_TIME_16                     0x10\n#define RH_CC110_WAIT_TIME_24                     0x20\n#define RH_CC110_WAIT_TIME_32                     0x30\n#define RH_CC110_AGC_FREEZE                       0x0c\n#define RH_CC110_AGC_FILTER_LENGTH                0x03\n#define RH_CC110_AGC_FILTER_LENGTH_8              0x00\n#define RH_CC110_AGC_FILTER_LENGTH_16             0x01\n#define RH_CC110_AGC_FILTER_LENGTH_32             0x02\n#define RH_CC110_AGC_FILTER_LENGTH_64             0x03\n\n// #define RH_CC110_REG_1E_WOREVT1                0x1e\n// #define RH_CC110_REG_1F_WOREVT0                0x1f\n// #define RH_CC110_REG_20_WORCTRL                0x20\n// #define RH_CC110_REG_21_FREND1                 0x21\n#define RH_CC110_LNA_CURRENT                      0xc0\n#define RH_CC110_LNA2MIX_CURRENT                  0x30\n#define RH_CC110_LODIV_BUF_CURRENT_RX             0x0c\n#define RH_CC110_MIX_CURRENT                      0x03\n\n// #define RH_CC110_REG_22_FREND0                 0x22\n#define RH_CC110_LODIV_BUF_CURRENT_TX             0x30\n#define RH_CC110_PA_POWER                         0x07\n\n// #define RH_CC110_REG_23_FSCAL3                 0x23\n#define RH_CC110_FSCAL3_7_6                       0xc0\n#define RH_CC110_CHP_CURR_CAL_EN                  0x30\n#define RH_CC110_FSCAL3_3_0                       0x0f\n\n// #define RH_CC110_REG_24_FSCAL2                 0x24\n#define RH_CC110_VCO_CORE_H_EN                    0x20\n#define RH_CC110_FSCAL2                           0x1f\n\n// #define RH_CC110_REG_25_FSCAL1                 0x25\n#define RH_CC110_FSCAL1                           0x3f\n\n// #define RH_CC110_REG_26_FSCAL0                 0x26\n#define RH_CC110_FSCAL0                           0x7f\n\n// #define RH_CC110_REG_27_RCCTRL1                0x28\n// #define RH_CC110_REG_28_RCCTRL0                0x29\n// #define RH_CC110_REG_29_FSTEST                 0x2a\n// #define RH_CC110_REG_2A_PTEST                  0x2b\n// #define RH_CC110_REG_2B_AGCTEST                0x2c\n// #define RH_CC110_REG_2C_TEST2                  0x2c\n// #define RH_CC110_REG_2D_TEST1                  0x2d\n// #define RH_CC110_REG_2E_TEST0                  0x2e\n#define RH_CC110_TEST0_7_2                        0xfc\n#define RH_CC110_VCO_SEL_CAL_EN                   0x02\n#define RH_CC110_TEST0_0                          0x01\n\n// #define RH_CC110_REG_30_PARTNUM                0x30\n// #define RH_CC110_REG_31_VERSION                0x31\n// #define RH_CC110_REG_32_FREQEST                0x32\n// #define RH_CC110_REG_33_CRC_REG                0x33\n#define RH_CC110_CRC_REG_CRC_OK                   0x80\n\n// #define RH_CC110_REG_34_RSSI                   0x34\n// #define RH_CC110_REG_35_MARCSTATE              0x35\n#define RH_CC110_MARC_STATE                       0x1f\n#define RH_CC110_MARC_STATE_SLEEP                 0x00\n#define RH_CC110_MARC_STATE_IDLE                  0x01\n#define RH_CC110_MARC_STATE_XOFF                  0x02\n#define RH_CC110_MARC_STATE_VCOON_MC              0x03\n#define RH_CC110_MARC_STATE_REGON_MC              0x04\n#define RH_CC110_MARC_STATE_MANCAL                0x05\n#define RH_CC110_MARC_STATE_VCOON                 0x06\n#define RH_CC110_MARC_STATE_REGON                 0x07\n#define RH_CC110_MARC_STATE_STARTCAL              0x08\n#define RH_CC110_MARC_STATE_BWBOOST               0x09\n#define RH_CC110_MARC_STATE_FS_LOCK               0x0a\n#define RH_CC110_MARC_STATE_IFADCON               0x0b\n#define RH_CC110_MARC_STATE_ENDCAL                0x0c\n#define RH_CC110_MARC_STATE_RX                    0x0d\n#define RH_CC110_MARC_STATE_RX_END                0x0e\n#define RH_CC110_MARC_STATE_RX_RST                0x0f\n#define RH_CC110_MARC_STATE_TXRX_SWITCH           0x10\n#define RH_CC110_MARC_STATE_RXFIFO_OVERFLOW       0x11\n#define RH_CC110_MARC_STATE_FSTXON                0x12\n#define RH_CC110_MARC_STATE_TX                    0x13\n#define RH_CC110_MARC_STATE_TX_END                0x14\n#define RH_CC110_MARC_STATE_RXTX_SWITCH           0x15\n#define RH_CC110_MARC_STATE_TXFIFO_UNDERFLOW      0x16\n\n// #define RH_CC110_REG_38_PKTSTATUS              0x38\n#define RH_CC110_PKTSTATUS_CRC_OK                 0x80\n#define RH_CC110_PKTSTATUS_CS                     0x40\n#define RH_CC110_PKTSTATUS_CCA                    0x10\n#define RH_CC110_PKTSTATUS_SFD                    0x08\n#define RH_CC110_PKTSTATUS_GDO2                   0x04\n#define RH_CC110_PKTSTATUS_GDO0                   0x01\n\n// #define RH_CC110_REG_3A_TXBYTES                0x3a\n#define RH_CC110_TXFIFO_UNDERFLOW                 0x80\n#define RH_CC110_NUM_TXBYTES                      0x7f\n\n// #define RH_CC110_REG_3B_RXBYTES                0x3b\n#define RH_CC110_RXFIFO_UNDERFLOW                 0x80\n#define RH_CC110_NUM_RXBYTES                      0x7f\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_CC110 RH_CC110.h <RH_CC110.h>\n/// \\brief Send and receive addressed, reliable, acknowledged datagrams by Texas Instruments CC110L and compatible transceivers and modules.\n///\n/// The TI CC110L is a low cost tranceiver chip capable of 300 to 928MHz and with a wide range of modulation types and speeds.\n/// The chip is typically provided on a module that also includes the antenna and coupling hardware\n/// and is therefore capable of a more restricted frequency range.\n///\n/// Supported modules include:\n/// - Anaren AIR BoosterPack 430BOOST-CC110L \n///\n/// This base class provides basic functions for sending and receiving unaddressed, unreliable datagrams\n/// of arbitrary length to 59 octets per packet at a selected data rate and modulation type. \n/// Use one of the Manager classes to get addressing and \n/// acknowledgement reliability, routing, meshes etc.\n///\n/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and \n/// data rate, and with identical network addresses.\n///\n/// Several CC110L modules can be connected to an Arduino, permitting the construction of translators\n/// and frequency changers, etc.\n///\n/// Several GFSK modulation schemes are provided and may be selected by calling setModemConfig(). No FSK or OOK \n/// modulation schemes are provided though the implementor may configure the mnodem characteristics directly \n/// by calling setModemRegisters().\n///\n/// Implementation based on:\n/// http://www.ti.com/lit/ds/symlink/cc110l.pdf\n/// and\n/// https://www.anaren.com/air/cc110l-air-module-boosterpack-embedded-antenna-module-anaren\n///\n/// \\par Crystal Frequency\n///\n/// Modules based on the CC110L may contain a crystal oscillator with one of 2 possible frequencies: 26MHz or 27MHz.\n/// A number of radio configuration parameters (including carrier frequency and data rates) depend on the\n/// crystal oscillator frequency. The chip has no knowledge of the frequency, so it is up to the implementer\n/// to tell the driver the oscillator frequency by passing in the appropriate value of is27MHz to the constructor (default 26MHz)\n/// or by calling setIs27MHz() before calling init().\n/// Failure to correctly set this flag will cause incorrect frequency and modulation\n/// characteristics to be used. \n///\n/// Caution: it is not easy to determine what the actual crystal frequency is on some modules. For example, \n/// the documentation for the Anaren BoosterPack indictes a 26MHz crystal, but measurements on the devices delivered here\n/// indicate a 27MHz crystal is actually installed. TI recommend 27MHz for \n///\n/// \\par Packet Format\n///\n/// - 2 octets sync (a configurable network address)\n/// - 1 octet message length\n/// - 4 to 63 octets of payload consisting of:\n///   - 1 octet TO header\n///   - 1 octet FROM header\n///   - 1 octet ID header\n///   - 1 octet FLAGS header\n///   - 0 to 59 octets of user message\n/// - 2 octets CRC \n///\n/// \\par Connecting CC110L to Arduino\n/// \n/// Warning: the CC110L is a 3.3V part, and exposing it to 5V on any pin will damage it. Ensure you are using a 3.3V \n/// MCU or use level shifters. We tested with Teensy 3.1.\n///\n/// The electrical connection between a CC110L module and the Arduino or other processor\n/// require 3.3V, the 3 x SPI pins (SCK, SDI, SDO), \n/// a Chip Select pin and an Interrupt pin.\n/// Examples below assume the Anaren BoosterPack. Caution: the pin numbering on the Anaren BoosterPack\n/// is a bit counter-intuitive: the direction of number on J1 is the reverse of J2. Check the pin numbers\n/// stencilied on the front of the board to be sure.\n///\n/// \\code\n///                 Teensy 3.1   CC110L pin name         Anaren BoosterPack pin\n///                 3.3V---------VDD   (3.3V in)              J1-1\n///          SS pin D10----------CSn   (chip select in)       J2-8\n///         SCK pin D13----------SCLK  (SPI clock in)         J1-7\n///        MOSI pin D11----------MOSI  (SPI data in)          J2-5\n///        MISO pin D12----------MISO  (SPI data out)         J2-4\n///                 D2-----------GDO0  (Interrupt output)     J2-9\n///                 GND----------GND   (ground in)            J2-10\n/// \\endcode\n/// and use the default RH_CC110 constructor. You can use other pins by passing the appropriate arguments\n/// to the RH_CC110 constructor, depending on what your MCU supports.\n///\n/// For the Particle Photon:\n/// \\code\n///                 Photon   CC110L pin name         Anaren BoosterPack pin\n///                 3.3V---------VDD   (3.3V in)              J1-1\n///          SS pin A2-----------CSn   (chip select in)       J2-8\n///         SCK pin A3-----------SCLK  (SPI clock in)         J1-7\n///        MOSI pin A5-----------MOSI  (SPI data in)          J2-5\n///        MISO pin A4-----------MISO  (SPI data out)         J2-4\n///                 D2-----------GDO0  (Interrupt output)     J2-9\n///                 GND----------GND   (ground in)            J2-10\n/// \\endcode\n/// and use the default RH_CC110 constructor. You can use other pins by passing the appropriate arguments\n/// to the RH_CC110 constructor, depending on what your MCU supports.\n///\n/// \\par Example programs\n///\n/// Several example programs are provided.\n///\n/// \\par Radio operating strategy and defaults\n///\n/// The radio is enabled at all times and switched between RX, TX and IDLE modes.\n/// When RX is enabled (by calling available() or setModeRx()) the radio will stay in RX mode until a \n/// valid CRC correct message addressed to thiis node is received, when it will transition to IDLE.\n/// When TX is enabled (by calling send()) it will stay in TX mode until the message has ben sent\n/// and waitPacketSent() is called when it wil transition to IDLE \n///(this radio has no 'packet sent' interrupt that could be used, so polling\n/// with waitPacketSent() is required\n///\n/// The modulation schemes supported include the GFSK schemes provided by default in the TI SmartRF Suite.\n/// This software allows you to get the correct register values for diferent modulation schemes. All the modulation\n/// schemes prvided in the driver are based on the recommended register values given by SmartRF.\n/// Other schemes such a 2-FSK, 4-FSK and OOK are suported by the chip, but canned configurations are not provided with this driver. \n/// The implementer may choose to create their own modem configurations and pass them to setModemRegisters().\n///\nclass RH_CC110 : public RHNRFSPIDriver\n{\npublic:\n\n    /// \\brief Defines register configuration values for a desired modulation\n    ///\n    /// Defines values for various configuration fields and registers to \n    /// achieve a desired modulation speed and frequency deviation.\n    typedef struct\n    {\n\tuint8_t reg_0b;    ///< RH_CC110_REG_0B_FSCTRL1\n\tuint8_t reg_0c;    ///< RH_CC110_REG_0C_FSCTRL0\n\tuint8_t reg_10;    ///< RH_CC110_REG_10_MDMCFG4\n\tuint8_t reg_11;    ///< RH_CC110_REG_11_MDMCFG3\n\tuint8_t reg_12;    ///< RH_CC110_REG_12_MDMCFG2\n\tuint8_t reg_15;    ///< RH_CC110_REG_15_DEVIATN\n\tuint8_t reg_19;    ///< RH_CC110_REG_19_FOCCFG\n\tuint8_t reg_1a;    ///< RH_CC110_REG_1A_BSCFG\n\tuint8_t reg_1b;    ///< RH_CC110_REG_1B_AGCCTRL2\n\tuint8_t reg_1c;    ///< RH_CC110_REG_1C_AGCCTRL1\n\tuint8_t reg_1d;    ///< RH_CC110_REG_1D_AGCCTRL0\n\tuint8_t reg_21;    ///< RH_CC110_REG_21_FREND1\n\tuint8_t reg_22;    ///< RH_CC110_REG_22_FREND0\n\tuint8_t reg_23;    ///< RH_CC110_REG_23_FSCAL3\n\tuint8_t reg_24;    ///< RH_CC110_REG_24_FSCAL2\n\tuint8_t reg_25;    ///< RH_CC110_REG_25_FSCAL1\n\tuint8_t reg_26;    ///< RH_CC110_REG_26_FSCAL0\n\tuint8_t reg_2c;    ///< RH_CC110_REG_2C_TEST2\n\tuint8_t reg_2d;    ///< RH_CC110_REG_2D_TEST1\n\tuint8_t reg_2e;    ///< RH_CC110_REG_2E_TEST0\n    } ModemConfig;\n\n\n    /// Choices for setModemConfig() for a selected subset of common modulation types,\n    /// and data rates. If you need another configuration, use the register calculator.\n    /// and call setModemRegisters() with your desired settings.\n    /// These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic\n    /// definitions and not their integer equivalents: its possible that new values will be\n    /// introduced in later versions (though we will try to avoid it).\n    /// All configs use SYNC_MODE = RH_CC110_SYNC_MODE_16_16 (2 byte sync)\n    typedef enum\n    {\n\tGFSK_Rb1_2Fd5_2 = 0,   ///< GFSK, Data Rate: 1.2kBaud, Dev: 5.2kHz, RX BW 58kHz, optimised for sensitivity\n\tGFSK_Rb2_4Fd5_2,       ///< GFSK, Data Rate: 2.4kBaud, Dev: 5.2kHz, RX BW 58kHz, optimised for sensitivity\n\tGFSK_Rb4_8Fd25_4,      ///< GFSK, Data Rate: 4.8kBaud, Dev: 25.4kHz, RX BW 100kHz, optimised for sensitivity\n\tGFSK_Rb10Fd19,         ///< GFSK, Data Rate: 10kBaud, Dev: 19kHz, RX BW 100kHz, optimised for sensitivity\n\tGFSK_Rb38_4Fd20,       ///< GFSK, Data Rate: 38.4kBaud, Dev: 20kHz, RX BW 100kHz, optimised for sensitivity\n\tGFSK_Rb76_8Fd32,       ///< GFSK, Data Rate: 76.8kBaud, Dev: 32kHz, RX BW 232kHz, optimised for sensitivity\n\tGFSK_Rb100Fd47,        ///< GFSK, Data Rate: 100kBaud, Dev: 47kHz, RX BW 325kHz, optimised for sensitivity\n\tGFSK_Rb250Fd127,       ///< GFSK, Data Rate: 250kBaud, Dev: 127kHz, RX BW 540kHz, optimised for sensitivity\n    } ModemConfigChoice;\n\n    /// These power outputs are based on the suggested optimum values for \n    /// multilayer inductors in the 915MHz frequency band. Per table 5-15.\n    /// Caution: these enum values are indexes into PaPowerValues. \n    /// Do not change one without changing the other. Use the symbolic names, not the integer values\n    typedef enum\n    {\n\tTransmitPowerM30dBm = 0,      ///< -30dBm\n\tTransmitPowerM20dBm,          ///< -20dBm\n\tTransmitPowerM15dBm,          ///< -15dBm\n\tTransmitPowerM10dBm,          ///< -10dBm\n\tTransmitPower0dBm,            ///< 0dBm\n\tTransmitPower5dBm,            ///< 5dBm\n\tTransmitPower7dBm,            ///< 7dBm\n\tTransmitPower10dBm,           ///< 10dBm\n    } TransmitPower;\n\n    /// Constructor. You can have multiple instances, but each instance must have its own\n    /// interrupt and slave select pin. After constructing, you must call init() to initialise the interface\n    /// and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient\n    /// distinct interrupt lines, one for each instance.\n    /// \\param[in] slaveSelectPin the Arduino pin number of the output to use to select the CC110L before\n    /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)\n    /// \\param[in] interruptPin The interrupt Pin number that is connected to the CC110L GDO0 interrupt line. \n    /// Defaults to pin 2.\n    /// Caution: You must specify an interrupt capable pin.\n    /// On many Arduino boards, there are limitations as to which pins may be used as interrupts.\n    /// On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin.\n    /// On other Arduinos pins 2 or 3. \n    /// See http://arduino.cc/en/Reference/attachInterrupt for more details.\n    /// On Chipkit Uno32, pins 38, 2, 7, 8, 35.\n    /// On other boards, any digital pin may be used.\n    /// \\param[in] is27MHz Set to true if your CC110 is equipped with a 27MHz crystal oscillator. Defaults to false.\n    /// \\param[in] spi Pointer to the SPI interface object to use. \n    ///                Defaults to the standard Arduino hardware SPI interface\n    RH_CC110(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, bool is27MHz = false, RHGenericSPI& spi = hardware_spi);\n\n    /// Initialise the Driver transport hardware and software.\n    /// Make sure the Driver is properly configured before calling init().\n    /// In particular, ensure you have called setIs27MHz(true) if your module has a 27MHz crystal oscillator.\n    /// After init(), the following default characteristics are set:\n    /// TxPower: TransmitPower5dBm\n    /// Frequency: 915.0\n    /// Modulation: GFSK_Rb1_2Fd5_2 (GFSK, Data Rate: 1.2kBaud, Dev: 5.2kHz, RX BW 58kHz, optimised for sensitivity)\n    /// Sync Words: 0xd3, 0x91\n    /// \\return true if initialisation succeeded.\n    virtual bool    init();\n\n    /// Prints the value of all chip registers\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// For debugging purposes only.\n    /// \\return true on success\n    bool printRegisters();\n\n    /// Blocks until the current message (if any) \n    /// has been transmitted\n    /// \\return true on success, false if the chip is not in transmit mode or other transmit failure\n    virtual bool waitPacketSent();\n\n    /// Tests whether a new message is available\n    /// from the Driver. \n    /// On most drivers, this will also put the Driver into RHModeRx mode until\n    /// a message is actually received by the transport, when it will be returned to RHModeIdle\n    /// and available() will return true.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a new, complete, error-free uncollected message is available to be retreived by recv()\n    virtual bool    available();\n\n    /// Turns the receiver on if it not already on (after wiaint gor any currenly transmitting message to complete).\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf. The message cannot be retreived again.\n    virtual bool    recv(uint8_t* buf, uint8_t* len);\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is permitted. \n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send\n    /// \\return true if the message length was valid and it was correctly queued for transmit\n    virtual bool    send(const uint8_t* data, uint8_t len);\n\n    /// Returns the maximum message length \n    /// available in this Driver.\n    /// \\return The maximum legal message length\n    virtual uint8_t maxMessageLength();\n\n    /// If current mode is Sleep, Rx or Tx changes it to Idle. If the transmitter or receiver is running, \n    /// disables them.\n    void           setModeIdle();\n\n    /// If current mode is Tx or Idle, changes it to Rx. \n    /// Starts the receiver. The radio will stay in Rx mode until a CRC correct message addressed to this node\n    /// is received, or the ode is changed to Tx, Idle or Sleep.\n    void           setModeRx();\n\n    /// If current mode is Rx or Idle, changes it to Tx.\n    /// Starts the transmitter sending the current message.\n    void           setModeTx();\n\n    /// Sets the radio into low-power sleep mode.\n    /// If successful, the transport will stay in sleep mode until woken by \n    /// changing mode to idle, transmit or receive (eg by calling send(), recv(), available() etc)\n    /// Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode.\n    /// Caution: waking up from sleep loses values from registers 0x29 through 0x2e\n    /// \\return true if sleep mode was successfully entered.\n    virtual bool    sleep();\n\n    /// Set the Power Amplifier power setting.\n    /// The PaTable settings are based on are based on the suggested optimum values for \n    /// multilayer inductors in the 915MHz frequency band. Per table 5-15.\n    /// If these values are not suitable, use setPaTable() directly.\n    /// Caution: be a good neighbour and use the lowest power setting compatible with your application.\n    /// Caution: Permissable power settings for your area may depend on frequency and modulation characteristics: \n    /// consult local authorities.\n    /// param[in] power One of TransmitPower enum values \n    bool setTxPower(TransmitPower power);\n\n    /// Indicates the presence of 27MHz crystal oscillator.\n    /// You must indicate to the driver if your CC110L is equipped with a 27MHz crystal oscillator (26MHz is the default \n    /// in the constructor).\n    /// This should be called before calling init() if you have a 27MHz crystal.\n    /// It can be called after calling init() but you must reset the frequency (with setFrequency()) and modulation \n    /// (with setModemConfig()) afterwards.\n    /// \\param[in] is27MHz Pass true if the CC110L has a 27MHz crystal (default is true).\n    void setIs27MHz(bool is27MHz = true);\n\n    /// Sets the transmitter and receiver \n    /// centre frequency.\n    /// Caution: permissable frequency bands will depend on you country and area: consult local authorities.\n    /// \\param[in] centre Frequency in MHz. 300.0 to 928.0\n    /// \\return true if the selected frquency centre is within range\n    bool        setFrequency(float centre);\n\n    /// Sets all the registers required to configure the data modem in the CC110, including the data rate, \n    /// bandwidths etc. You cas use this to configure the modem with custom configuraitons if none of the \n    /// canned configurations in ModemConfigChoice suit you.\n    /// \\param[in] config A ModemConfig structure containing values for the modem configuration registers.\n    void           setModemRegisters(const ModemConfig* config);\n\n    /// Select one of the predefined modem configurations. If you need a modem configuration not provided \n    /// here, use setModemRegisters() with your own ModemConfig.\n    /// \\param[in] index The configuration choice.\n    /// \\return true if index is a valid choice.\n    bool        setModemConfig(ModemConfigChoice index);\n\n    /// Sets the sync words for transmit and receive in registers RH_CC110_REG_04_SYNC1 and RH_CC110_REG_05_SYNC0.\n    /// Caution: SyncWords should be set to the same \n    /// value on all nodes in your network. Nodes with different SyncWords set will never receive\n    /// each others messages, so different SyncWords can be used to isolate different\n    /// networks from each other. Default is { 0xd3, 0x91 }.\n    /// \\param[in] syncWords Array of sync words, 2 octets long\n    /// \\param[in] len Number of sync words to set. MUST be 2.\n    void setSyncWords(const uint8_t* syncWords, uint8_t len);\n\nprotected:\n    /// This is a low level function to handle the interrupts for one instance of RH_RF95.\n    /// Called automatically by isr*()\n    /// Should not need to be called by user code.\n    void           handleInterrupt();\n\n    /// Reads a single register from the CC110L\n    /// \\param[in] reg Register number, one of RH_CC110_REG\n    /// \\return The value of the register\n    uint8_t spiReadRegister(uint8_t reg);\n\n    /// Reads a single register in burst mode.\n    /// On the CC110L, some registers yield different data when read in burst mode\n    /// as opposed to single byte mode.\n    /// \\param[in] reg Register number, one of RH_CC110_REG (burst mode readable)\n    /// \\return The value of the register after a burst read\n    uint8_t spiBurstReadRegister(uint8_t reg);\n\n    /// Writes to a single single register on the CC110L\n    /// \\param[in] reg Register number, one of RH_CC110L_REG_*\n    /// \\param[in] val The value to write\n    /// \\return returns the chip status byte per table 5.2\n    uint8_t spiWriteRegister(uint8_t reg, uint8_t val);\n\n    /// Write a number of bytes to a burst capable register\n    /// \\param[in] reg Register number of the first register, one of RH_CC110L_REG_*\n    /// \\param[in] src Array of new register values to write. Must be at least len bytes\n    /// \\param[in] len Number of bytes to write\n    /// \\return the chip status byte per table 5.2\n    uint8_t  spiBurstWriteRegister(uint8_t reg, const uint8_t* src, uint8_t len);\n    \n    /// Examine the receive buffer to determine whether the message is for this node\n    /// Sets _rxBufValid.\n    void validateRxBuf();\n\n    /// Clear our local receive buffer\n    void clearRxBuf();\n\n    /// Reads and returns the status byte by issuing the SNOP strobe\n    /// \\return The value of the status byte per Table 5-2\n    uint8_t statusRead();\n\n    /// Sets the PaTable registers directly.\n    /// Ensure you use suitable PATABLE values per Tbale 5-15 or 5-16\n    /// You may need to do this to implement an OOK modulation scheme.\n    void setPaTable(uint8_t* patable, uint8_t patablesize);\n    \nprivate:\n    /// Low level interrupt service routine for device connected to interrupt 0\n    static void         isr0();\n\n    /// Low level interrupt service routine for device connected to interrupt 1\n    static void         isr1();\n\n    /// Low level interrupt service routine for device connected to interrupt 1\n    static void         isr2();\n\n    /// Array of instances connected to interrupts 0 and 1\n    static RH_CC110*     _deviceForInterrupt[];\n\n    /// Index of next interrupt number to use in _deviceForInterrupt\n    static uint8_t      _interruptCount;\n\n    /// The configured interrupt pin connected to this instance\n    uint8_t             _interruptPin;\n\n    /// The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated)\n    /// else 0xff\n    uint8_t             _myInterruptIndex;\n\n    /// Number of octets in the buffer\n    volatile uint8_t    _bufLen;\n    \n    /// The receiver/transmitter buffer\n    uint8_t             _buf[RH_CC110_MAX_PAYLOAD_LEN];\n\n    /// True when there is a valid message in the buffer\n    volatile bool       _rxBufValid;\n\n    /// True if crystal oscillator is 26 MHz, not 26MHz.\n    bool                _is27MHz;\n};\n\n/// @example cc110_client.pde\n/// @example cc110_server.pde\n\n#endif\n"
  },
  {
    "path": "RH_MRF89.cpp",
    "content": "// RH_MRF89.cpp\n//\n// Copyright (C) 2015 Mike McCauley\n// $Id: RH_MRF89.cpp,v 1.8 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_MRF89.h>\n#define BAND_915\n#define DATA_RATE_200\n#define LNA_GAIN LNA_GAIN_0_DB\n#define TX_POWER TX_POWER_13_DB\n\n// Interrupt vectors for the 3 Arduino interrupt pins\n// Each interrupt can be handled by a different instance of RH_MRF89, allowing you to have\n// 2 or more LORAs per Arduino\nRH_MRF89* RH_MRF89::_deviceForInterrupt[RH_MRF89_NUM_INTERRUPTS] = {0, 0, 0};\nuint8_t RH_MRF89::_interruptCount = 0; // Index into _deviceForInterrupt for next device\n\n// These are indexed by the values of ModemConfigChoice\n// Values based on sample modulation values from MRF89XA.h\n// TXIPOLFV set to be more than Fd\nPROGMEM static const RH_MRF89::ModemConfig MODEM_CONFIG_TABLE[] =\n{\n    // MODSEL, FDVAL, BRVAL, FILCREG=(PASFILV|BUTFILV), TXIPOLFV\n    // FSK, No Manchester, Whitening\n    { RH_MRF89_MODSEL_FSK, 0x0B, 0x63, 0x40 | 0x01, 0x20 }, // FSK_Rb2Fd33\n    { RH_MRF89_MODSEL_FSK, 0x0B, 0x27, 0x40 | 0x01, 0x20 }, // FSK_Rb5Fd33\n    { RH_MRF89_MODSEL_FSK, 0x0B, 0x13, 0x40 | 0x01, 0x20 }, // FSK_Rb10Fd33\n    { RH_MRF89_MODSEL_FSK, 0x09, 0x09, 0x70 | 0x02, 0x20 }, // FSK_Rb20Fd40\n    { RH_MRF89_MODSEL_FSK, 0x04, 0x04, 0xB0 | 0x05, 0x40 }, // FSK_Rb40Fd80\n    { RH_MRF89_MODSEL_FSK, 0x03, 0x03, 0xD0 | 0x06, 0x40 }, // FSK_Rb50Fd100\n    { RH_MRF89_MODSEL_FSK, 0x02, 0x02, 0xE0 | 0x09, 0x60 }, // FSK_Rb66Fd133\n    { RH_MRF89_MODSEL_FSK, 0x01, 0x01, 0xF0 | 0x0F, 0x80 }, // FSK_Rb100Fd200\n    { RH_MRF89_MODSEL_FSK, 0x01, 0x00, 0xF0 | 0x0F, 0x80 }  // FSK_Rb200Fd200\n\n};\n\n\nRH_MRF89::RH_MRF89(uint8_t csconPin, uint8_t csdatPin, uint8_t interruptPin, RHGenericSPI& spi)\n    :\n    RHNRFSPIDriver(csconPin, spi),\n    _csconPin(csconPin),\n    _csdatPin(csdatPin),\n    _interruptPin(interruptPin)\n{\n    _myInterruptIndex = 0xff; // Not allocated yet\n}\n\nbool RH_MRF89::init()\n{\n    // MRF89 data cant handle SPI greater than 1MHz.  \n    // Sigh on teensy at 1MHz, need special delay after writes, see RHNRFSPIDriver::spiWrite\n    _spi.setFrequency(RHGenericSPI::Frequency1MHz);\n    if (!RHNRFSPIDriver::init())\n\treturn false;\n\n    // Initialise the chip select pins\n    pinMode(_csconPin, OUTPUT);\n    digitalWrite(_csconPin, HIGH);\n    pinMode(_csdatPin, OUTPUT);\n    digitalWrite(_csdatPin, HIGH);\n\n    // Determine the interrupt number that corresponds to the interruptPin\n    int interruptNumber = digitalPinToInterrupt(_interruptPin);\n    if (interruptNumber == NOT_AN_INTERRUPT)\n\treturn false;\n#ifdef RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER\n    interruptNumber = _interruptPin;\n#endif\n\n    // Make sure we are not in some unexpected mode from a previous run    \n    setOpMode(RH_MRF89_CMOD_STANDBY); \n\n    // No way to check the device type but lets trivially check there is something there\n    // by trying to change a register:\n    spiWriteRegister(RH_MRF89_REG_02_FDEVREG, 0xaa);\n    if (spiReadRegister(RH_MRF89_REG_02_FDEVREG) != 0xaa)\n\treturn false;\n    spiWriteRegister(RH_MRF89_REG_02_FDEVREG, 0x3); // Back to the default for FDEV\n    if (spiReadRegister(RH_MRF89_REG_02_FDEVREG) != 0x3)\n\treturn false;\n\n    // Add by Adrien van den Bossche <vandenbo@univ-tlse2.fr> for Teensy\n    // ARM M4 requires the below. else pin interrupt doesn't work properly.\n    // On all other platforms, its innocuous, belt and braces\n    pinMode(_interruptPin, INPUT); \n\n    // Set up interrupt handler\n    // Since there are a limited number of interrupt glue functions isr*() available,\n    // we can only support a limited number of devices simultaneously\n    // On some devices, notably most Arduinos, the interrupt pin passed in is actually the \n    // interrupt number. You have to figure out the interruptnumber-to-interruptpin mapping\n    // yourself based on knowledge of what Arduino board you are running on.\n    if (_myInterruptIndex == 0xff)\n    {\n\t// First run, no interrupt allocated yet\n\tif (_interruptCount <= RH_MRF89_NUM_INTERRUPTS)\n\t    _myInterruptIndex = _interruptCount++;\n\telse\n\t    return false; // Too many devices, not enough interrupt vectors\n    }\n    _deviceForInterrupt[_myInterruptIndex] = this;\n    if (_myInterruptIndex == 0)\n\tattachInterrupt(interruptNumber, isr0, RISING);\n    else if (_myInterruptIndex == 1)\n\tattachInterrupt(interruptNumber, isr1, RISING);\n    else if (_myInterruptIndex == 2)\n\tattachInterrupt(interruptNumber, isr2, RISING);\n    else\n\treturn false; // Too many devices, not enough interrupt vectors\n\n    // When used with the MRF89XAM9A module, per 75017B.pdf section 1.3, need:\n    // crystal freq = 12.8MHz\n    // clock output disabled\n    // frequency bands 902-915 or 915-928\n    // VCOT 60mV\n    // OOK max 28kbps\n    // Based on 70622C.pdf, section 3.12: \n    spiWriteRegister(RH_MRF89_REG_00_GCONREG, RH_MRF89_CMOD_STANDBY | RH_MRF89_FBS_950_960 | RH_MRF89_VCOT_60MV);\n    spiWriteRegister(RH_MRF89_REG_01_DMODREG, RH_MRF89_MODSEL_FSK | RH_MRF89_OPMODE_PACKET); // FSK, Packet mode, LNA 0dB\n    spiWriteRegister(RH_MRF89_REG_02_FDEVREG, 0); // Set by setModemConfig\n    spiWriteRegister(RH_MRF89_REG_03_BRSREG,  0); // Set by setModemConfig\n    spiWriteRegister(RH_MRF89_REG_04_FLTHREG, 0); // Set by setModemConfig (OOK only)\n    spiWriteRegister(RH_MRF89_REG_05_FIFOCREG, RH_MRF89_FSIZE_64);\n    spiWriteRegister(RH_MRF89_REG_06_R1CREG, 0); // Set by setFrequency\n    spiWriteRegister(RH_MRF89_REG_07_P1CREG, 0); // Set by setFrequency\n    spiWriteRegister(RH_MRF89_REG_08_S1CREG, 0); // Set by setFrequency\n    spiWriteRegister(RH_MRF89_REG_09_R2CREG, 0); // Frequency set 2 not used\n    spiWriteRegister(RH_MRF89_REG_0A_P2CREG, 0); // Frequency set 2 not used\n    spiWriteRegister(RH_MRF89_REG_0B_S2CREG, 0); // Frequency set 2 not used\n    spiWriteRegister(RH_MRF89_REG_0C_PACREG, RH_MRF89_PARC_23);\n    // IRQ0 rx mode: SYNC (not used)\n    // IRQ1 rx mode: CRCOK\n    // IRQ1 tx mode: TXDONE\n    spiWriteRegister(RH_MRF89_REG_0D_FTXRXIREG, RH_MRF89_IRQ0RXS_PACKET_SYNC | RH_MRF89_IRQ1RXS_PACKET_CRCOK | RH_MRF89_IRQ1TX);\n    spiWriteRegister(RH_MRF89_REG_0E_FTPRIREG, RH_MRF89_LENPLL);\n    spiWriteRegister(RH_MRF89_REG_0F_RSTHIREG, 0x00); // default not used if no RSSI interrupts\n    spiWriteRegister(RH_MRF89_REG_10_FILCREG, 0); // Set by setModemConfig\n\n    spiWriteRegister(RH_MRF89_REG_11_PFCREG, 0x38);// 100kHz, recommended, but not used, see RH_MRF89_REG_12_SYNCREG OOK only?\n    spiWriteRegister(RH_MRF89_REG_12_SYNCREG, RH_MRF89_SYNCREN | RH_MRF89_SYNCWSZ_32); // No polyphase, no bsync, sync, 0 errors\n    spiWriteRegister(RH_MRF89_REG_13_RSVREG, 0x07);//default\n//    spiWriteRegister(RH_MRF89_REG_14_RSTSREG, 0x00); // NO, read only\n    spiWriteRegister(RH_MRF89_REG_15_OOKCREG, 0x00); // Set by setModemConfig OOK only\n    spiWriteRegister(RH_MRF89_REG_16_SYNCV31REG, 0x69); // Set by setSyncWords\n    spiWriteRegister(RH_MRF89_REG_17_SYNCV23REG, 0x81); // Set by setSyncWords\n    spiWriteRegister(RH_MRF89_REG_18_SYNCV15REG, 0x7E); // Set by setSyncWords\n    spiWriteRegister(RH_MRF89_REG_19_SYNCV07REG, 0x96); // Set by setSyncWords\n    // TXIPOLFV set by setModemConfig. power set by setTxPower\n    spiWriteRegister(RH_MRF89_REG_1A_TXCONREG, 0xf0 | RH_MRF89_TXOPVAL_13DBM); // TX cutoff freq=375kHz,\n    spiWriteRegister(RH_MRF89_REG_1B_CLKOREG, 0x00); // Disable clock output to save power\n    spiWriteRegister(RH_MRF89_REG_1C_PLOADREG, 0x40); // payload=64bytes (no RX-filtering on packet length)\n    spiWriteRegister(RH_MRF89_REG_1D_NADDSREG, 0x00); // Node Address (0=default) Not used\n    spiWriteRegister(RH_MRF89_REG_1E_PKTCREG, RH_MRF89_PKTLENF | RH_MRF89_PRESIZE_4 | RH_MRF89_WHITEON | RH_MRF89_CHKCRCEN | RH_MRF89_ADDFIL_OFF);\n    spiWriteRegister(RH_MRF89_REG_1F_FCRCREG, 0x00); // default (FIFO access in standby=write, clear FIFO on CRC mismatch)\n\n    // Looking OK now\n    // Set some suitable defaults:\n    setPreambleLength(3); // The default\n    uint8_t syncwords[] = { 0x69, 0x81, 0x7e, 0x96 }; // Same as RH_MRF89XA\n    setSyncWords(syncwords, sizeof(syncwords));\n    setTxPower(RH_MRF89_TXOPVAL_1DBM);\n    if (!setFrequency(915.4))\n\treturn false;\n    // Some slow, reliable default speed and modulation\n    if (!setModemConfig(FSK_Rb20Fd40))\n\treturn false;\n\n    return true;\n}\n\nbool RH_MRF89::printRegisters()\n{\n#ifdef RH_HAVE_SERIAL\n    uint8_t i;\n    for (i = 0; i <= 0x1f; i++)\n    {\n\tSerial.print(i, HEX);\n\tSerial.print(\": \");\n\tSerial.println(spiReadRegister(i), HEX);\n    }\n#endif\n    return true;\n}\n\n// C++ level interrupt handler for this instance\n// MRF89XA is unusual in that it has 2 interrupt lines, and not a single, combined one.\n// Only one of the several interrupt lines (IRQ1) from the RFM95 needs to be\n// connnected to the processor.\n// We use this to get CRCOK and TXDONE  interrupts\nvoid RH_MRF89::handleInterrupt()\n{\n//    Serial.println(\"I\");\n    if (_mode == RHModeTx)\n    {\n//    Serial.println(\"T\");\n\t// TXDONE\n\t// Transmit is complete\n\t_txGood++;\n\tsetModeIdle();\n    }\n    else if (_mode == RHModeRx)\n    {\n//\tSerial.println(\"R\");\n\t// CRCOK\n\t// We have received a packet.\n        // First byte in FIFO is packet length\n\n\t// REVISIT: Capture last rssi from RSTSREG\n\t// based roughly on Figure 3-9\n\t_lastRssi = (spiReadRegister(RH_MRF89_REG_14_RSTSREG) >> 1) - 120;\n\n\t_bufLen = spiReadData();\n\tif (_bufLen < 4)\n\t{\n\t    // Drain the FIFO\n\t    uint8_t i;\n\t    for (i = 0; spiReadRegister(RH_MRF89_REG_0D_FTXRXIREG) & RH_MRF89_FIFOEMPTY; i++)\n\t\tspiReadData();\n\t    clearRxBuf();\n\t    return;\n\t}\n\t\n\t// Now drain all the data from the FIFO into _buf\n\tuint8_t i;\n\tfor (i = 0; spiReadRegister(RH_MRF89_REG_0D_FTXRXIREG) & RH_MRF89_FIFOEMPTY; i++)\n\t    _buf[i] = spiReadData();\n\n\t// All good. See if its for us\n\tvalidateRxBuf(); \n\tif (_rxBufValid)\n\t    setModeIdle(); // Got one \n    }\n}\n\n// These are low level functions that call the interrupt handler for the correct\n// instance of RH_MRF89.\n// 3 interrupts allows us to have 3 different devices\nvoid RH_MRF89::isr0()\n{\n    if (_deviceForInterrupt[0])\n\t_deviceForInterrupt[0]->handleInterrupt();\n}\nvoid RH_MRF89::isr1()\n{\n    if (_deviceForInterrupt[1])\n\t_deviceForInterrupt[1]->handleInterrupt();\n}\nvoid RH_MRF89::isr2()\n{\n    if (_deviceForInterrupt[2])\n\t_deviceForInterrupt[2]->handleInterrupt();\n}\n\nuint8_t RH_MRF89::spiReadRegister(uint8_t reg)\n{\n    // Tell the chip we want to talk to the configuration registers\n    setSlaveSelectPin(_csconPin);\n    digitalWrite(_csdatPin, HIGH);\n    return spiRead(((reg & 0x1f) << 1) | RH_MRF89_SPI_READ_MASK);\n}\n\nuint8_t RH_MRF89::spiWriteRegister(uint8_t reg, uint8_t val)\n{\n    // Tell the chip we want to talk to the configuration registers\n    setSlaveSelectPin(_csconPin);\n    digitalWrite(_csdatPin, HIGH);\n    // Hmmm, on teensy 3.1, needed some special behaviour in RHNRFSPIDriver::spiWrite\n    // because otherwise, CSCON returns high before the final clock goes low,\n    // which prevents the MRF89XA spi write succeeding. Clock must be low when CSCON goes high.\n    return spiWrite(((reg & 0x1f) << 1), val);\n}\n\nuint8_t RH_MRF89::spiWriteData(uint8_t data)\n{\n    spiWriteRegister(RH_MRF89_REG_1F_FCRCREG, RH_MRF89_ACFCRC); // Write to FIFO\n    setSlaveSelectPin(_csdatPin);\n    digitalWrite(_csconPin, HIGH);\n    return spiCommand(data);\n}\n\nuint8_t RH_MRF89::spiWriteData(const uint8_t* data, uint8_t len)\n{\n    spiWriteRegister(RH_MRF89_REG_1F_FCRCREG, RH_MRF89_ACFCRC); // Write to FIFO\n    setSlaveSelectPin(_csdatPin);\n    digitalWrite(_csconPin, HIGH);\n\n    uint8_t status = 0;\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    while (len--)\n\t_spi.transfer(*data++);\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return status;\n\n}\n\nuint8_t RH_MRF89::spiReadData()\n{\n    spiWriteRegister(RH_MRF89_REG_1F_FCRCREG, RH_MRF89_ACFCRC | RH_MRF89_FRWAXS); // Read from FIFO\n    setSlaveSelectPin(_csdatPin);\n    digitalWrite(_csconPin, HIGH);\n    return spiCommand(0);\n}\n\nvoid RH_MRF89::setOpMode(uint8_t mode)\n{\n    // REVISIT: do we need to have time delays when switching between modes?\n    uint8_t val = spiReadRegister(RH_MRF89_REG_00_GCONREG);\n    val = (val & ~RH_MRF89_CMOD) | (mode & RH_MRF89_CMOD);\n    spiWriteRegister(RH_MRF89_REG_00_GCONREG, val);\n}\n\nvoid RH_MRF89::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\tsetOpMode(RH_MRF89_CMOD_STANDBY);\n\t_mode = RHModeIdle;\n    }\n}\n\nbool RH_MRF89::sleep()\n{\n    if (_mode != RHModeSleep)\n    {\n\tsetOpMode(RH_MRF89_CMOD_SLEEP);\n\t_mode = RHModeSleep;\n    }\n    return true;\n}\n\nvoid RH_MRF89::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\tsetOpMode(RH_MRF89_CMOD_RECEIVE);\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_MRF89::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\tsetOpMode(RH_MRF89_CMOD_TRANSMIT);\n\t_mode = RHModeTx;\n    }\n}\n\nvoid RH_MRF89::setTxPower(uint8_t power)\n{\n    uint8_t txconreg = spiReadRegister(RH_MRF89_REG_1A_TXCONREG);\n    txconreg |= (power & RH_MRF89_TXOPVAL);\n    spiWriteRegister(RH_MRF89_REG_1A_TXCONREG, txconreg);\n}\n\nbool RH_MRF89::available()\n{\n    if (_mode == RHModeTx)\n\treturn false;\n    setModeRx();\n\n    return _rxBufValid; // Will be set by the interrupt handler when a good message is received\n}\n\nbool RH_MRF89::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n\n    if (buf && len)\n    {\n\tATOMIC_BLOCK_START;\n\t// Skip the 4 headers that are at the beginning of the rxBuf\n\tif (*len > _bufLen - RH_MRF89_HEADER_LEN)\n\t    *len = _bufLen - RH_MRF89_HEADER_LEN;\n\tmemcpy(buf, _buf + RH_MRF89_HEADER_LEN, *len);\n\tATOMIC_BLOCK_END;\n    }\n    clearRxBuf(); // This message accepted and cleared\n\n    return true;\n}\n\nbool RH_MRF89::send(const uint8_t* data, uint8_t len)\n{\n    if (len > RH_MRF89_MAX_MESSAGE_LEN)\n\treturn false;\n    \n    waitPacketSent(); // Make sure we dont interrupt an outgoing message\n    setModeIdle();\n    \n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    // First octet is the length of the chip payload\n    // 0 length messages are transmitted but never trigger a receive!\n    spiWriteData(len + RH_MRF89_HEADER_LEN);\n    spiWriteData(_txHeaderTo);\n    spiWriteData(_txHeaderFrom);\n    spiWriteData(_txHeaderId);\n    spiWriteData(_txHeaderFlags);\n    spiWriteData(data, len);\n    setModeTx(); // Start transmitting\n\n    return true;\n}\n\nuint8_t RH_MRF89::maxMessageLength()\n{\n    return RH_MRF89_MAX_MESSAGE_LEN;\n}\n\n// Check whether the latest received message is complete and uncorrupted\nvoid RH_MRF89::validateRxBuf()\n{\n    if (_bufLen < 4)\n\treturn; // Too short to be a real message\n    // Extract the 4 headers\n    _rxHeaderTo    = _buf[0];\n    _rxHeaderFrom  = _buf[1];\n    _rxHeaderId    = _buf[2];\n    _rxHeaderFlags = _buf[3];\n    if (_promiscuous ||\n\t_rxHeaderTo == _thisAddress ||\n\t_rxHeaderTo == RH_BROADCAST_ADDRESS)\n    {\n\t_rxGood++;\n\t_rxBufValid = true;\n    }\n}\n\nvoid RH_MRF89::clearRxBuf()\n{\n    ATOMIC_BLOCK_START;\n    _rxBufValid = false;\n    _bufLen = 0;\n    ATOMIC_BLOCK_END;\n}\n\nbool RH_MRF89::verifyPLLLock()\n{\n    // Verify PLL-lock per instructions in Note 1 section 3.12\n    // Need to do this after changing frequency.\n    uint8_t ftpriVal = spiReadRegister(RH_MRF89_REG_0E_FTPRIREG);\n    spiWriteRegister(RH_MRF89_REG_0E_FTPRIREG, ftpriVal | RH_MRF89_LSTSPLL); // Clear PLL lock bit\n    setOpMode(RH_MRF89_CMOD_FS);\n    unsigned long ulStartTime = millis();\n    while ((millis() - ulStartTime < 1000))\n    {\n        ftpriVal = spiReadRegister(RH_MRF89_REG_0E_FTPRIREG);\n        if ((ftpriVal & RH_MRF89_LSTSPLL) != 0)\n            break;\n    }\n    setOpMode(RH_MRF89_CMOD_STANDBY);\n    return ((ftpriVal & RH_MRF89_LSTSPLL) != 0);\n}\n\nbool RH_MRF89::setFrequency(float centre)\n{\n    // REVISIT: FSK only: its different for OOK :-(\n\n    uint8_t FBS;\n    if (centre >= 902.0 && centre < 915.0)\n    {\n\tFBS = RH_MRF89_FBS_902_915;\n    }\n    else if (centre >= 915.0 && centre <= 928.0)\n    {\n\tFBS = RH_MRF89_FBS_915_928;\n    }\n    else if (centre >= 950.0 && centre <= 960.0)\n    {\n\t// Not all modules support this frequency band:\n\t// The MRF98XAM9A does not\n\tFBS = RH_MRF89_FBS_950_960;\n    }\n//    else if (centre >= 863.0 && centre <= 870.0)\n//    {\n//\t// Not all modules support this frequency band:\n//\t// The MRF98XAM9A does not\n//\tFBS = RH_MRF89_FBS_950_960; // Yes same as above\n//    }\n    else\n    {\n\t// Cant do this freq\n\treturn false;\n    }\n\n    // Based on frequency calcs done in MRF89XA.h\n//    uint8_t R = 100; // Recommended\n    uint8_t R = 119; // Also recommended :-(\n    uint32_t centre_kHz = centre * 1000;\n    uint32_t xtal_kHz = (RH_MRF89_XTAL_FREQ * 1000);\n    uint32_t compare = (centre_kHz * 8 * (R + 1)) / (9 * xtal_kHz);\n    uint8_t P = ((compare - 75) / 76) + 1;\n    uint8_t S = compare - (75 * (P + 1));\n\n    // Now set the new register values:\n    uint8_t val = spiReadRegister(RH_MRF89_REG_00_GCONREG);\n    val = (val & ~RH_MRF89_FBS) | (FBS & RH_MRF89_FBS);\n    spiWriteRegister(RH_MRF89_REG_00_GCONREG, val);\n\n    spiWriteRegister(RH_MRF89_REG_06_R1CREG, R); \n    spiWriteRegister(RH_MRF89_REG_07_P1CREG, P); \n    spiWriteRegister(RH_MRF89_REG_08_S1CREG, S); \n\n    return verifyPLLLock();\n}\n\n// Set one of the canned FSK Modem configs\n// Returns true if its a valid choice\nbool RH_MRF89::setModemConfig(ModemConfigChoice index)\n{\n    if (index > (signed int)(sizeof(MODEM_CONFIG_TABLE) / sizeof(ModemConfig)))\n        return false;\n\n    RH_MRF89::ModemConfig cfg;\n    memcpy_P(&cfg, &MODEM_CONFIG_TABLE[index], sizeof(cfg));\n\n    // Now update the registers\n    uint8_t val = spiReadRegister(RH_MRF89_REG_01_DMODREG);\n    val = (val & ~RH_MRF89_MODSEL) | cfg.MODSEL;\n    spiWriteRegister(RH_MRF89_REG_01_DMODREG, val);\n\n    spiWriteRegister(RH_MRF89_REG_02_FDEVREG, cfg.FDVAL);\n    spiWriteRegister(RH_MRF89_REG_03_BRSREG,  cfg.BRVAL);\n    spiWriteRegister(RH_MRF89_REG_10_FILCREG, cfg.FILCREG);\n\n    // The sample configs in MRF89XA.h all use TXIPOLFV = 0xf0 => 375kHz, which is too wide for most modulations\n    val = spiReadRegister(RH_MRF89_REG_1A_TXCONREG);\n    val = (val & ~RH_MRF89_TXIPOLFV) | (cfg.TXIPOLFV & RH_MRF89_TXIPOLFV);\n    spiWriteRegister(RH_MRF89_REG_1A_TXCONREG, val);\n\n    return true;\n}\n\nvoid RH_MRF89::setPreambleLength(uint8_t bytes)\n{\n    if (bytes >= 1 && bytes <= 4)\n    {\n\tbytes--;\n\tuint8_t pktcreg = spiReadRegister(RH_MRF89_REG_1E_PKTCREG);\n\tpktcreg = (pktcreg & ~RH_MRF89_PRESIZE) | ((bytes << 5) & RH_MRF89_PRESIZE);\n\tspiWriteRegister(RH_MRF89_REG_1E_PKTCREG, pktcreg);\n    }\n}\n\nvoid RH_MRF89::setSyncWords(const uint8_t* syncWords, uint8_t len)\n{\n    if (syncWords && (len > 0 and len <= 4))\n    {\n\tuint8_t syncreg = spiReadRegister(RH_MRF89_REG_12_SYNCREG);\n\tsyncreg = (syncreg & ~RH_MRF89_SYNCWSZ) | (((len - 1) << 3) & RH_MRF89_SYNCWSZ);\n\tspiWriteRegister(RH_MRF89_REG_12_SYNCREG, syncreg);\n\tuint8_t i;\n\tfor (i = 0; i < 4; i++)\n\t{\n\t    if (len > i)\n\t\tspiWriteRegister(RH_MRF89_REG_16_SYNCV31REG + i, syncWords[i]);\n\t}\n    }\n}\n\n"
  },
  {
    "path": "RH_MRF89.h",
    "content": "// RH_MRF89.h\n//\n// Definitions for Microchip MRF89XA family radios radios per:\n// http://ww1.microchip.com/downloads/en/DeviceDoc/70622C.pdf\n// http://ww1.microchip.com/downloads/en/DeviceDoc/75017B.pdf\n//\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2015 Mike McCauley\n// $Id: RH_MRF89.h,v 1.6 2015/12/17 10:58:13 mikem Exp $\n// \n\n#ifndef RH_RF95_h\n#define RH_RF95_h\n\n#include <RHNRFSPIDriver.h>\n\n// This is the maximum number of interrupts the driver can support\n// Most Arduinos can handle 2, Megas can handle more\n#define RH_MRF89_NUM_INTERRUPTS 3\n\n// Max number of octets the MRF89XA Rx/Tx FIFO can hold\n#define RH_MRF89_FIFO_SIZE 64\n\n// This is the maximum number of bytes that can be carried by the MRF89XA.\n// We use some for headers, keeping fewer for RadioHead messages\n#define RH_MRF89_MAX_PAYLOAD_LEN RH_MRF89_FIFO_SIZE\n\n// The length of the headers we add.\n// The headers are inside the MRF89XA payload\n#define RH_MRF89_HEADER_LEN 4\n    \n// This is the maximum user message length that can be supported by this driver. \n// Can be pre-defined to a smaller size (to save SRAM) prior to including this header\n// Here we allow for 4 bytes headers, user data. Message length and CRC are automatically encoded and decoded by \n// the MRF89XA\n#ifndef RH_MRF89_MAX_MESSAGE_LEN\n #define RH_MRF89_MAX_MESSAGE_LEN (RH_MRF89_MAX_PAYLOAD_LEN - RH_MRF89_HEADER_LEN)\n#endif\n\n// Bits that must be set to do a SPI read\n#define RH_MRF89_SPI_READ_MASK              0x40\n\n// The MRF89XA crystal frequency in MHz\n#define RH_MRF89_XTAL_FREQ                  12.8\n\n// Register names from Figure 2-18\n#define RH_MRF89_REG_00_GCONREG             0x00\n#define RH_MRF89_REG_01_DMODREG             0x01\n#define RH_MRF89_REG_02_FDEVREG             0x02\n#define RH_MRF89_REG_03_BRSREG              0x03\n#define RH_MRF89_REG_04_FLTHREG             0x04\n#define RH_MRF89_REG_05_FIFOCREG            0x05\n#define RH_MRF89_REG_06_R1CREG              0x06\n#define RH_MRF89_REG_07_P1CREG              0x07\n#define RH_MRF89_REG_08_S1CREG              0x08\n#define RH_MRF89_REG_09_R2CREG              0x09\n#define RH_MRF89_REG_0A_P2CREG              0x0a\n#define RH_MRF89_REG_0B_S2CREG              0x0b\n#define RH_MRF89_REG_0C_PACREG              0x0c\n#define RH_MRF89_REG_0D_FTXRXIREG           0x0d\n#define RH_MRF89_REG_0E_FTPRIREG            0x0e\n#define RH_MRF89_REG_0F_RSTHIREG            0x0f\n#define RH_MRF89_REG_10_FILCREG             0x10\n#define RH_MRF89_REG_11_PFCREG              0x11\n#define RH_MRF89_REG_12_SYNCREG             0x12\n// Hmm the addresses of the next 2 is ambiguous in the docs\n// this seems to agree with whats in the chip:\n#define RH_MRF89_REG_13_RSVREG              0x13\n#define RH_MRF89_REG_14_RSTSREG             0x14\n#define RH_MRF89_REG_15_OOKCREG             0x15\n#define RH_MRF89_REG_16_SYNCV31REG          0x16\n#define RH_MRF89_REG_17_SYNCV23REG          0x17\n#define RH_MRF89_REG_18_SYNCV15REG          0x18\n#define RH_MRF89_REG_19_SYNCV07REG          0x19\n#define RH_MRF89_REG_1A_TXCONREG            0x1a\n#define RH_MRF89_REG_1B_CLKOREG             0x1b\n#define RH_MRF89_REG_1C_PLOADREG            0x1c\n#define RH_MRF89_REG_1D_NADDSREG            0x1d\n#define RH_MRF89_REG_1E_PKTCREG             0x1e\n#define RH_MRF89_REG_1F_FCRCREG             0x1f\n\n// Register bitfield definitions\n//#define RH_MRF89_REG_00_GCONREG             0x00\n#define RH_MRF89_CMOD                       0xe0\n#define RH_MRF89_CMOD_TRANSMIT              0x80\n#define RH_MRF89_CMOD_RECEIVE               0x60\n#define RH_MRF89_CMOD_FS                    0x40\n#define RH_MRF89_CMOD_STANDBY               0x20\n#define RH_MRF89_CMOD_SLEEP                 0x00\n\n#define RH_MRF89_FBS                        0x18\n#define RH_MRF89_FBS_950_960                0x10\n#define RH_MRF89_FBS_915_928                0x08\n#define RH_MRF89_FBS_902_915                0x00\n\n#define RH_MRF89_VCOT                       0x06\n#define RH_MRF89_VCOT_180MV                 0x06\n#define RH_MRF89_VCOT_120MV                 0x04\n#define RH_MRF89_VCOT_60MV                  0x02\n#define RH_MRF89_VCOT_TANK                  0x00\n\n#define RH_MRF89_RPS                        0x01\n\n//#define RH_MRF89_REG_01_DMODREG             0x01\n#define RH_MRF89_MODSEL                     0xc0\n#define RH_MRF89_MODSEL_FSK                 0x80\n#define RH_MRF89_MODSEL_OOK                 0x40\n\n#define RH_MRF89_DMODE0                     0x20\n\n#define RH_MRF89_OOKTYP                     0x18\n#define RH_MRF89_OOKTYP_AVERAGE             0x10\n#define RH_MRF89_OOKTYP_PEAK                0x08\n#define RH_MRF89_OOKTYP_FIXED               0x00\n\n#define RH_MRF89_DMODE1                     0x04\n\n#define RH_MRF89_IFGAIN                     0x03\n#define RH_MRF89_IFGAIN_M13P5               0x03\n#define RH_MRF89_IFGAIN_M9                  0x02\n#define RH_MRF89_IFGAIN_M4P5                0x01\n#define RH_MRF89_IFGAIN_0                   0x00\n\n// DMODE1 and DMODE1:\n#define RH_MRF89_OPMODE_CONTINUOUS          0x00\n#define RH_MRF89_OPMODE_BUFFER              RH_MRF89_DMODE0\n#define RH_MRF89_OPMODE_PACKET              RH_MRF89_DMODE1\n\n//#define RH_MRF89_REG_03_BRSREG              0x03\n#define RH_MRF89_BRVAL                      0x7f\n\n//#define RH_MRF89_REG_05_FIFOCREG            0x05\n#define RH_MRF89_FSIZE                      0xc0\n#define RH_MRF89_FSIZE_64                   0xc0\n#define RH_MRF89_FSIZE_48                   0x80\n#define RH_MRF89_FSIZE_32                   0x40\n#define RH_MRF89_FSIZE_16                   0x00\n\n#define RH_MRF89_FTINT                      0x3f\n\n//#define RH_MRF89_REG_0C_PACREG              0x0c\n#define RH_MRF89_PARC                       0x18\n#define RH_MRF89_PARC_23                    0x18\n#define RH_MRF89_PARC_15                    0x10\n#define RH_MRF89_PARC_8P5                   0x08\n#define RH_MRF89_PARC_3                     0x00\n\n//#define RH_MRF89_REG_0D_FTXRXIREG           0x0d\n#define RH_MRF89_IRQ0RXS                    0xc0\n#define RH_MRF89_IRQ0RXS_CONT_RSSI          0x40\n#define RH_MRF89_IRQ0RXS_CONT_SYNC          0x00\n#define RH_MRF89_IRQ0RXS_BUFFER_SYNC        0xc0\n#define RH_MRF89_IRQ0RXS_BUFFER_FIFOEMPTY   0x80\n#define RH_MRF89_IRQ0RXS_BUFFER_WRITEBYTE   0x40\n#define RH_MRF89_IRQ0RXS_BUFFER_NONE        0x00\n#define RH_MRF89_IRQ0RXS_PACKET_SYNC        0xc0\n#define RH_MRF89_IRQ0RXS_PACKET_FIFOEMPTY   0x80\n#define RH_MRF89_IRQ0RXS_PACKET_WRITEBYTE   0x40\n#define RH_MRF89_IRQ0RXS_PACKET_PLREADY     0x00\n\n#define RH_MRF89_IRQ1RXS                    0x30\n#define RH_MRF89_IRQ1RXS_CONT_DCLK          0x00\n#define RH_MRF89_IRQ1RXS_BUFFER_FIFO_THRESH 0x30\n#define RH_MRF89_IRQ1RXS_BUFFER_RSSI        0x20\n#define RH_MRF89_IRQ1RXS_BUFFER_FIFOFULL    0x10\n#define RH_MRF89_IRQ1RXS_BUFFER_NONE        0x00\n#define RH_MRF89_IRQ1RXS_PACKET_FIFO_THRESH 0x30\n#define RH_MRF89_IRQ1RXS_PACKET_RSSI        0x20\n#define RH_MRF89_IRQ1RXS_PACKET_FIFOFULL    0x10\n#define RH_MRF89_IRQ1RXS_PACKET_CRCOK       0x00\n\n#define RH_MRF89_IRQ1TX                     0x08\n#define RH_MRF89_FIFOFULL                   0x04\n#define RH_MRF89_FIFOEMPTY                  0x02\n#define RH_MRF89_FOVRUN                     0x01\n\n//#define RH_MRF89_REG_0E_FTPRIREG            0x0e\n#define RH_MRF89_FIFOFM                     0x80\n#define RH_MRF89_FIFOFSC                    0x40\n#define RH_MRF89_TXDONE                     0x20\n#define RH_MRF89_IRQ0TXST                   0x10\n#define RH_MRF89_RIRQS                      0x04\n#define RH_MRF89_LSTSPLL                    0x02\n#define RH_MRF89_LENPLL                     0x01\n\n//#define RH_MRF89_REG_10_FILCREG             0x10\n#define RH_MRF89_PASFILV                    0xf0\n#define RH_MRF89_PASFILV_987KHZ             0xf0\n#define RH_MRF89_PASFILV_676KHZ             0xe0\n#define RH_MRF89_PASFILV_514KHZ             0xd0\n#define RH_MRF89_PASFILV_458KHZ             0xc0\n#define RH_MRF89_PASFILV_414KHZ             0xb0\n#define RH_MRF89_PASFILV_378KHZ             0xa0\n#define RH_MRF89_PASFILV_321KHZ             0x90\n#define RH_MRF89_PASFILV_262KHZ             0x80\n#define RH_MRF89_PASFILV_234KHZ             0x70\n#define RH_MRF89_PASFILV_211KHZ             0x60\n#define RH_MRF89_PASFILV_184KHZ             0x50\n#define RH_MRF89_PASFILV_157KHZ             0x40\n#define RH_MRF89_PASFILV_137KHZ             0x30\n#define RH_MRF89_PASFILV_109KHZ             0x20\n#define RH_MRF89_PASFILV_82KHZ              0x10\n#define RH_MRF89_PASFILV_65KHZ              0x00\n\n#define RH_MRF89_BUTFILV                    0x0f\n#define RH_MRF89_BUTFILV_25KHZ              0x00\n#define RH_MRF89_BUTFILV_50KHZ              0x01\n#define RH_MRF89_BUTFILV_75KHZ              0x02\n#define RH_MRF89_BUTFILV_100KHZ             0x03\n#define RH_MRF89_BUTFILV_125KHZ             0x04\n#define RH_MRF89_BUTFILV_150KHZ             0x05\n#define RH_MRF89_BUTFILV_175KHZ             0x06\n#define RH_MRF89_BUTFILV_200KHZ             0x07\n#define RH_MRF89_BUTFILV_225KHZ             0x08\n#define RH_MRF89_BUTFILV_250KHZ             0x09\n#define RH_MRF89_BUTFILV_275KHZ             0x0a\n#define RH_MRF89_BUTFILV_300KHZ             0x0b\n#define RH_MRF89_BUTFILV_325KHZ             0x0c\n#define RH_MRF89_BUTFILV_350KHZ             0x0d\n#define RH_MRF89_BUTFILV_375KHZ             0x0e\n#define RH_MRF89_BUTFILV_400KHZ             0x0f\n\n//#define RH_MRF89_REG_11_PFCREG              0x11\n#define RH_MRF89_POLCFV                     0xf0\n\n//#define RH_MRF89_REG_12_SYNCREG             0x12\n#define RH_MRF89_POLFILEN                   0x80\n#define RH_MRF89_BSYNCEN                    0x40\n#define RH_MRF89_SYNCREN                    0x20\n#define RH_MRF89_SYNCWSZ                    0x18\n#define RH_MRF89_SYNCWSZ_32                 0x18\n#define RH_MRF89_SYNCWSZ_24                 0x10\n#define RH_MRF89_SYNCWSZ_16                 0x08\n#define RH_MRF89_SYNCWSZ_8                  0x00\n#define RH_MRF89_SYNCTEN                    0x06\n#define RH_MRF89_SYNCTEN_3                  0x06\n#define RH_MRF89_SYNCTEN_2                  0x04\n#define RH_MRF89_SYNCTEN_1                  0x02\n#define RH_MRF89_SYNCTEN_0                  0x00\n\n//#define RH_MRF89_REG_15_OOKCREG             0x15\n#define RH_MRF89_OOTHSV                     0xe0\n#define RH_MRF89_OOTHSV_6P0DB               0xe0\n#define RH_MRF89_OOTHSV_5P0DB               0xc0\n#define RH_MRF89_OOTHSV_4P0DB               0xa0\n#define RH_MRF89_OOTHSV_3P0DB               0x80\n#define RH_MRF89_OOTHSV_2P0DB               0x60\n#define RH_MRF89_OOTHSV_1P5DB               0x40\n#define RH_MRF89_OOTHSV_1P0DB               0x20\n#define RH_MRF89_OOTHSV_0P5DB               0x00\n\n#define RH_MRF89_OOKTHPV                    0x1c\n#define RH_MRF89_OOKTHPV_16                 0x1c\n#define RH_MRF89_OOKTHPV_8                  0x18\n#define RH_MRF89_OOKTHPV_4                  0x14\n#define RH_MRF89_OOKTHPV_2                  0x10\n#define RH_MRF89_OOKTHPV_1_IN_8             0x0c\n#define RH_MRF89_OOKTHPV_1_IN_4             0x08\n#define RH_MRF89_OOKTHPV_1_IN_2             0x04\n#define RH_MRF89_OOKTHPV_1_IN_1             0x00\n\n#define RH_MRF89_OOKATHC                    0x03\n#define RH_MRF89_OOKATHC_32PI               0x03\n#define RH_MRF89_OOKATHC_8PI                0x00\n\n//#define RH_MRF89_REG_1A_TXCONREG            0x1a\n#define RH_MRF89_TXIPOLFV                   0xf0\n\n#define RH_MRF89_TXOPVAL                    0x0e\n#define RH_MRF89_TXOPVAL_M8DBM              0x0e\n#define RH_MRF89_TXOPVAL_M5DBM              0x0c\n#define RH_MRF89_TXOPVAL_M2DBM              0x0a\n#define RH_MRF89_TXOPVAL_1DBM               0x08\n#define RH_MRF89_TXOPVAL_4DBM               0x06\n#define RH_MRF89_TXOPVAL_7DBM               0x04\n#define RH_MRF89_TXOPVAL_10DBM              0x02\n#define RH_MRF89_TXOPVAL_13DBM              0x00\n\n//#define RH_MRF89_REG_1B_CLKOREG             0x1b\n#define RH_MRF89_CLKOCNTRL                  0x80\n#define RH_MRF89_CLKOFREQ                   0x7c\n\n//#define RH_MRF89_REG_1C_PLOADREG            0x1c\n#define RH_MRF89_MCHSTREN                   0x80\n#define RH_MRF89_PLDPLEN                    0x7f\n\n//#define RH_MRF89_REG_1E_PKTCREG             0x1e\n#define RH_MRF89_PKTLENF                    0x80\n\n#define RH_MRF89_PRESIZE                    0x60\n#define RH_MRF89_PRESIZE_4                  0x60\n#define RH_MRF89_PRESIZE_3                  0x40\n#define RH_MRF89_PRESIZE_2                  0x20\n#define RH_MRF89_PRESIZE_1                  0x00\n\n#define RH_MRF89_WHITEON                    0x10\n#define RH_MRF89_CHKCRCEN                   0x08\n\n#define RH_MRF89_ADDFIL                     0x06\n#define RH_MRF89_ADDFIL_NODEADDR_00_FF      0x06\n#define RH_MRF89_ADDFIL_NODEADDR_00         0x04\n#define RH_MRF89_ADDFIL_NODEADDR            0x02\n#define RH_MRF89_ADDFIL_OFF                 0x00\n\n#define RH_MRF89_STSCRCEN                   0x01\n\n//#define RH_MRF89_REG_1F_FCRCREG             0x1f\n#define RH_MRF89_ACFCRC                     0x80\n#define RH_MRF89_FRWAXS                     0x40\n\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_MRF89 RH_MRF89.h <RH_MRF89.h>\n/// \\brief Send and receive addressed, reliable, acknowledged datagrams by Microchip MRF89XA and compatible transceivers.\n/// and modules.\n///\n/// The Microchip MRF89XA http://ww1.microchip.com/downloads/en/DeviceDoc/70622C.pdf is a low cost 900MHz\n/// bancd transceiver chip.\n/// It is commonly used on preassembled modules with supporting circcuits and antennas, such as \n/// the MRF89XAM9A http://www.microchip.com/wwwproducts/Devices.aspx?product=MRF89XAM9A\n/// This class supports all such modules\n///\n/// This base class provides basic functions for sending and receiving unaddressed, unreliable datagrams\n/// of arbitrary length to 59 octets per packet. Use one of the Manager classes to get addressing and \n/// acknowledgement reliability, routing, meshes etc.\n///\n/// Several MRF89XA modules can be connected to an Arduino, permitting the construction of translators\n/// and frequency changers, etc. Each instance requires 2 chip select pins, and interrupt pin the standard 3 SPI pins.\n/// \n/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and \n/// data rate, and with identical network addresses.\n///\n/// Example Arduino programs are included to show the main modes of use.\n///\n/// All messages sent and received by this class conform to this packet format:\n///\n/// - 3 octets PREAMBLE\n/// - 2 to 4 octets NETWORK ADDRESS (also call Sync Word)\n/// - 1 octet message length bits packet control field\n/// - 4 to 63 octets PAYLOAD, consisting of:\n///   - 1 octet TO header\n///   - 1 octet FROM header\n///   - 1 octet ID header\n///   - 1 octet FLAGS header\n///   - 0 to 59 octets of user message\n/// - 2 octets CRC \n///\n/// The payload is whitened. No Manchester encoding is used.\n///\n/// \\par Connecting MRF89XA to Arduino\n///\n/// The electrical connection between the MRF89XA and the Arduino require 3.3V, the 3 x SPI pins (SCK, SDI, SDO), \n/// a 2 Chip Select pins (/CSCON and /CSDAT) and an interrupt.\n///\n/// Caution: the MRF89XA is a 3.3V part and is not tolerant of 5V inputs. Connecting MRF89XA directly to a 5V\n/// MCU such as most Arduinos will damage the MRF89XA.\n///\n/// Connect the MRF89XA to most 3.3V Arduinos or Teensy 3.1 like this (use 3.3V not 5V).\n/// \\code\n///                 Teensy       MRF89XAM9A\n///               3.3V-----------VIN   (3.3V in)\n///             pin D9-----------/CSDAT (data chip select in)\n///          SS pin D10----------/CSCON (configuration chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------SDI   (SPI Data in)\n///        MISO pin D12----------SDO   (SPI data out)\n///                 D2-----------IRQ1  (Interrupt 1 output)\n///                              IRQ0  (Interrupt 0 output, not connected)\n///                 GND----------GND   (ground in)\n/// \\endcode\n/// You can use other pins for /CSDAT, /CSCON, IRQ1 by passing appropriate arguments to the constructor.\n///\n/// \\par Example programs\n///\n/// Several example programs are provided.\n///\nclass RH_MRF89 : public RHNRFSPIDriver\n{\npublic:\n\n    /// \\brief Defines register configuration values for a desired modulation\n    ///\n    /// Defines values for various configuration fields and registers to \n    /// achieve a desired modulation speed and frequency deviation.\n    typedef struct\n    {\n\tuint8_t MODSEL;    ///< Value for MODSEL in RH_MRF89_REG_01_DMODREG\n\tuint8_t FDVAL;     ///< Value for FDVAL in RH_MRF89_REG_02_FDEVREG\n\tuint8_t BRVAL;     ///< Value for BRVAL RH_MRF89_REG_03_BRSREG\n\tuint8_t FILCREG;   ///< Value for PASFILV | BUTFILV in RH_MRF89_REG_10_FILCREG\n\tuint8_t TXIPOLFV;  ///< Value for TXIPOLFV in RH_MRF89_REG_1A_TXCONREG\n    } ModemConfig;\n\n    /// Choices for setModemConfig() for a selected subset of common\n    /// data rates and frequency deviations.\n    /// Rb is the data rate in kbps. Fd is the FSK Frequency deviation in kHz.\n    /// These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic\n    /// definitions and not their integer equivalents: its possible that new values will be\n    /// introduced in later versions (though we will try to avoid it).\n    /// OOK is not yet supported.\n    /// Based on sample configs in MRF89XA.h from Microchip\n    typedef enum\n    {\n\tFSK_Rb2Fd33 = 0,   ///< FSK, No Manchester, Whitened, Rb = 2kbs,    Fd = 33kHz\n\tFSK_Rb5Fd33,\t   ///< FSK, No Manchester, Whitened, Rb = 5kbs,    Fd = 33kHz\n\tFSK_Rb10Fd33,\t   ///< FSK, No Manchester, Whitened, Rb = 10kbs,   Fd = 33kHz\n\tFSK_Rb20Fd40,\t   ///< FSK, No Manchester, Whitened, Rb = 20kbs,   Fd = 40kHz\n\tFSK_Rb40Fd80,\t   ///< FSK, No Manchester, Whitened, Rb = 40kbs,   Fd = 80kHz\n\tFSK_Rb50Fd100,\t   ///< FSK, No Manchester, Whitened, Rb = 50kbs,   Fd = 100kHz\n\tFSK_Rb66Fd133,\t   ///< FSK, No Manchester, Whitened, Rb = 66kbs,   Fd = 133kHz\n\tFSK_Rb100Fd200,\t   ///< FSK, No Manchester, Whitened, Rb = 100kbs,  Fd = 200kHz\n\tFSK_Rb200Fd200\t   ///< FSK, No Manchester, Whitened, Rb = 200kbs,  Fd = 200kHz\n    } ModemConfigChoice;\n\n    /// Constructor.\n    /// Constructor. You can have multiple instances, but each instance must have its own\n    /// interrupt and 2 slave select pins. After constructing, you must call init() to initialise the interface\n    /// and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient\n    /// distinct interrupt lines, one for each instance.\n    /// \\param[in] csconPin the Arduino pin number connected to the CSCON pin of the MRF89XA.\n    /// Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)\n    /// \\param[in] csdatPin the Arduino pin number connected to the CSDAT pin of the MRF89XA.\n    /// Defaults to 9.\n    /// \\param[in] interruptPin The interrupt Pin number that is connected to the IRQ1 pin of the MRF89XA.\n    /// Defaults to pin 2. (IRQ0 pin of the MRF89XA does not need to be connected).\n    /// \\param[in] spi Pointer to the SPI interface object to use. \n    ///                Defaults to the standard Arduino hardware SPI interface\n    RH_MRF89(uint8_t csconPin = SS, uint8_t csdatPin = 9, uint8_t interruptPin = 2, RHGenericSPI& spi = hardware_spi);\n\n    /// Initialise the Driver transport hardware and software.\n    /// Make sure the Driver is properly configured before calling init().\n    /// \\return true if initialisation succeeded.\n    virtual bool    init();\n\n    /// Prints the value of all chip registers\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// For debugging purposes only.\n    /// \\return true on success\n    bool printRegisters();\n\n    /// Sets the radio into low-power sleep mode.\n    /// If successful, the transport will stay in sleep mode until woken by \n    /// changing mode to idle, transmit or receive (eg by calling send(), recv(), available() etc)\n    /// Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode.\n    /// \\return true if sleep mode was successfully entered.\n    virtual bool    sleep();\n\n    /// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, \n    /// disables them.\n    void           setModeIdle();\n\n    /// If current mode is Tx or Idle, changes it to Rx. \n    /// Starts the receiver in the radio.\n    // the next valid packet received will cause available() to be true.\n    void           setModeRx();\n\n    /// If current mode is Rx or Idle, changes it to Rx. F\n    /// Starts the transmitter in the radio.\n    void           setModeTx();\n\n    /// Sets the transmitter power output level in register RH_MRF89_REG_1A_TXCONREG.\n    /// Be a good neighbour and set the lowest power level you need.\n    /// After init(), the power will be set to RH_MRF89_TXOPVAL_1DBM (1dBm)\n    /// The highest power available is RH_MRF89_TXOPVAL_13DBM (13dBm)\n    /// Caution: In some countries you may only select certain higher power levels if you\n    /// are also using frequency hopping. Make sure you are aware of the legal\n    /// limitations and regulations in your region.\n    /// Caution: in some countries the maximum permitted power level may depend on the Bit rate\n    /// \\param[in] power Transmitter power level, one of RH_MRF89_TXOPVAL*\n    void           setTxPower(uint8_t power);\n\n    /// Select one of the predefined modem configurations. If you need a modem configuration not provided \n    /// here, use setModemRegisters() with your own ModemConfig.\n    /// \\param[in] index The configuration choice.\n    /// \\return true if index is a valid choice.\n    bool        setModemConfig(ModemConfigChoice index);\n\n    /// Tests whether a new message is available\n    /// from the Driver. \n    /// On most drivers, this will also put the Driver into RHModeRx mode until\n    /// a message is actually received by the transport, when it will be returned to RHModeIdle.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a new, complete, error-free uncollected message is available to be retreived by recv()\n    virtual bool    available();\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    virtual bool    recv(uint8_t* buf, uint8_t* len);\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is permitted. \n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send\n    /// \\return true if the message length was valid and it was correctly queued for transmit\n    virtual bool    send(const uint8_t* data, uint8_t len);\n\n    /// Returns the maximum message length \n    /// available in this Driver.\n    /// \\return The maximum legal message length\n    virtual uint8_t maxMessageLength();\n\n    /// Sets the centre frequency in MHz.\n    /// Permitted ranges are: 902.0 to 928.0 and 950.0 to 960.0 (inclusive)\n    /// Caution not all freqs are supported on all modules: check your module specifications\n    /// Caution: not all available and supported frequencies are legal in every country: check \n    /// Regulatory Approval eg for MRF89XAM9A (in 75015B.pdf)\n    /// Australia 915.0 to 928.0\n    bool            setFrequency(float centre);\n\n    /// Sets the length of the preamble\n    /// in bytes.\n    /// Caution: this should be set to the same \n    /// value on all nodes in your network. Default is 4.\n    /// Sets the message preamble length in RH_MRF89_REG_1E_PKTCREG\n    /// \\param[in] bytes Preamble length in bytes of 8 bits each.  \n    void           setPreambleLength(uint8_t bytes);\n\n    /// Sets the sync words for transmit and receive in registers RH_MRF89_REG_16_SYNCV31REG\n    /// et seq.\n    /// Caution: SyncWords should be set to the same \n    /// value on all nodes in your network. Nodes with different SyncWords set will never receive\n    /// each others messages, so different SyncWords can be used to isolate different\n    /// networks from each other. Default is { 0x69, 0x81, 0x7e, 0x96 }.\n    /// Caution, sync words of 2 bytes and less do not work well with this chip.\n    /// \\param[in] syncWords Array of sync words, 1 to 4 octets long\n    /// \\param[in] len Number of sync words to set, 1 to 4.\n    void            setSyncWords(const uint8_t* syncWords = NULL, uint8_t len = 0);\n\nprotected:\n\n    /// Called automatically when a CRCOK or TXDONE interrupt occurs.\n    /// Handles the interrupt.\n    void handleInterrupt();\n\n    /// Reads a single register from the MRF89XA\n    /// \\param[in] reg Register number, one of RH_MRF89_REG\n    /// \\return The value of the register\n    uint8_t spiReadRegister(uint8_t reg);\n\n    /// Writes to a single single register on the MRF89XA\n    /// \\param[in] reg Register number, one of RH_MRF89_REG_*\n    /// \\param[in] val The value to write\n    /// \\return the current value of RH_MRF89_REG_00_GCONREG (read while the command is sent)\n    uint8_t spiWriteRegister(uint8_t reg, uint8_t val);\n\n    /// Writes a single byte to the MRF89XA data FIFO.\n    /// \\param[in] data The data value to write\n    /// \\return 0\n    uint8_t spiWriteData(uint8_t data);\n\n    /// Write a number of bytes from a buffer to the MRF89XA data FIFO.\n    /// \\param[in] data Pointer to a buffer containing the len bytes to be written\n    /// \\param[in] len The number of bytes to write to teh FIFO\n    /// \\return 0;\n    uint8_t spiWriteData(const uint8_t* data, uint8_t len);\n\n    /// Reads a single byte from the MRF89XA data FIFO.\n    /// \\return The next data byte in the FIFO\n    uint8_t spiReadData();\n\n    /// Sets the operating mode in the CMOD bits in RH_MRF89_REG_00_GCONREG\n    /// which controls what mode the MRF89XA is running in\n    /// \\param[in] mode One of RH_MRF89_CMOD_*\n    void    setOpMode(uint8_t mode);\n\n    /// Verifies that the MRF89XA PLL has locked on the slected frequency.\n    /// This needs to be called if the frequency is changed\n    bool    verifyPLLLock();\n\n    /// Examine the revceive buffer to determine whether the message is for this node\n    void validateRxBuf();\n\n    /// Clear our local receive buffer\n    void clearRxBuf();\n\n\nprivate:\n    /// Low level interrupt service routine for device connected to interrupt 0\n    static void         isr0();\n\n    /// Low level interrupt service routine for device connected to interrupt 1\n    static void         isr1();\n\n    /// Low level interrupt service routine for device connected to interrupt 1\n    static void         isr2();\n\n    /// Array of instances connected to interrupts 0 and 1\n    static RH_MRF89*     _deviceForInterrupt[];\n\n    /// Index of next interrupt number to use in _deviceForInterrupt\n    static uint8_t      _interruptCount;\n\n    // Sigh: this chip has 2 differnt chip selects.\n    // We have to set one or the other as the SPI slave select pin depending\n    // on which block of registers we are accessing\n    uint8_t             _csconPin;\n    uint8_t             _csdatPin;\n\n    /// The configured interrupt pin connected to this instance\n    uint8_t             _interruptPin;\n\n    /// The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated)\n    /// else 0xff\n    uint8_t             _myInterruptIndex;\n\n    /// Number of octets in the buffer\n    volatile uint8_t    _bufLen;\n    \n    /// The receiver/transmitter buffer\n    uint8_t             _buf[RH_MRF89_MAX_PAYLOAD_LEN];\n\n    /// True when there is a valid message in the buffer\n    volatile bool       _rxBufValid;\n\n};\n\n/// @example mrf89_client.pde\n/// @example mrf89_server.pde\n\n#endif\n"
  },
  {
    "path": "RH_NRF24.cpp",
    "content": "// NRF24.cpp\n//\n// Copyright (C) 2012 Mike McCauley\n// $Id: RH_NRF24.cpp,v 1.23 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_NRF24.h>\n\nRH_NRF24::RH_NRF24(uint8_t chipEnablePin, uint8_t slaveSelectPin, RHGenericSPI& spi)\n    :\n    RHNRFSPIDriver(slaveSelectPin, spi),\n    _rxBufValid(0)\n{\n    _configuration = RH_NRF24_EN_CRC | RH_NRF24_CRCO; // Default: 2 byte CRC enabled\n    _chipEnablePin = chipEnablePin;\n}\n\nbool RH_NRF24::init()\n{\n    // Teensy with nRF24 is unreliable at 8MHz:\n    // so is Arduino with RF73\n    _spi.setFrequency(RHGenericSPI::Frequency1MHz);\n    if (!RHNRFSPIDriver::init())\n\treturn false;\n\n    // Initialise the slave select pin\n    pinMode(_chipEnablePin, OUTPUT);\n    digitalWrite(_chipEnablePin, LOW);\n  \n    // Clear interrupts\n    spiWriteRegister(RH_NRF24_REG_07_STATUS, RH_NRF24_RX_DR | RH_NRF24_TX_DS | RH_NRF24_MAX_RT);\n    // Enable dynamic payload length on all pipes\n    spiWriteRegister(RH_NRF24_REG_1C_DYNPD, RH_NRF24_DPL_ALL);\n    // Enable dynamic payload length, disable payload-with-ack, enable noack\n    spiWriteRegister(RH_NRF24_REG_1D_FEATURE, RH_NRF24_EN_DPL | RH_NRF24_EN_DYN_ACK);\n    // Test if there is actually a device connected and responding\n    // CAUTION: RFM73 and version 2.0 silicon may require ACTIVATE\n    if (spiReadRegister(RH_NRF24_REG_1D_FEATURE) != (RH_NRF24_EN_DPL | RH_NRF24_EN_DYN_ACK))\n    { \n\tspiWrite(RH_NRF24_COMMAND_ACTIVATE, 0x73);\n        // Enable dynamic payload length, disable payload-with-ack, enable noack\n        spiWriteRegister(RH_NRF24_REG_1D_FEATURE, RH_NRF24_EN_DPL | RH_NRF24_EN_DYN_ACK);\n        if (spiReadRegister(RH_NRF24_REG_1D_FEATURE) != (RH_NRF24_EN_DPL | RH_NRF24_EN_DYN_ACK))\n            return false;\n    }\n\n    // Make sure we are powered down\n    setModeIdle();\n\n    // Flush FIFOs\n    flushTx();\n    flushRx();\n\n    setChannel(2); // The default, in case it was set by another app without powering down\n    setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm);\n\n    return true;\n}\n\n// Use the register commands to read and write the registers\nuint8_t RH_NRF24::spiReadRegister(uint8_t reg)\n{\n    return spiRead((reg & RH_NRF24_REGISTER_MASK) | RH_NRF24_COMMAND_R_REGISTER);\n}\n\nuint8_t RH_NRF24::spiWriteRegister(uint8_t reg, uint8_t val)\n{\n    return spiWrite((reg & RH_NRF24_REGISTER_MASK) | RH_NRF24_COMMAND_W_REGISTER, val);\n}\n\nuint8_t RH_NRF24::spiBurstReadRegister(uint8_t reg, uint8_t* dest, uint8_t len)\n{\n    return spiBurstRead((reg & RH_NRF24_REGISTER_MASK) | RH_NRF24_COMMAND_R_REGISTER, dest, len);\n}\n\nuint8_t RH_NRF24::spiBurstWriteRegister(uint8_t reg, uint8_t* src, uint8_t len)\n{\n    return spiBurstWrite((reg & RH_NRF24_REGISTER_MASK) | RH_NRF24_COMMAND_W_REGISTER, src, len);\n}\n\nuint8_t RH_NRF24::statusRead()\n{\n    // status is a side-effect of NOP, faster than reading reg 07\n    return spiCommand(RH_NRF24_COMMAND_NOP); \n}\n\nuint8_t RH_NRF24::flushTx()\n{\n    return spiCommand(RH_NRF24_COMMAND_FLUSH_TX);\n}\n\nuint8_t RH_NRF24::flushRx()\n{\n    return spiCommand(RH_NRF24_COMMAND_FLUSH_RX);\n}\n\nbool RH_NRF24::setChannel(uint8_t channel)\n{\n    spiWriteRegister(RH_NRF24_REG_05_RF_CH, channel & RH_NRF24_RF_CH);\n    return true;\n}\n\nbool RH_NRF24::setOpMode(uint8_t mode)\n{\n    _configuration = mode;\n    return true;\n}\n\nbool RH_NRF24::setNetworkAddress(uint8_t* address, uint8_t len)\n{\n    if (len < 3 || len > 5)\n\treturn false;\n\n    // Set both TX_ADDR and RX_ADDR_P0 for auto-ack with Enhanced shockwave\n    spiWriteRegister(RH_NRF24_REG_03_SETUP_AW, len-2);\t// Mapping [3..5] = [1..3]\n    spiBurstWriteRegister(RH_NRF24_REG_0A_RX_ADDR_P0, address, len);\n    spiBurstWriteRegister(RH_NRF24_REG_10_TX_ADDR, address, len);\n    return true;\n}\n\nbool RH_NRF24::setRF(DataRate data_rate, TransmitPower power)\n{\n    uint8_t value = (power << 1) & RH_NRF24_PWR;\n    // Ugly mapping of data rates to noncontiguous 2 bits:\n    if (data_rate == DataRate250kbps)\n\tvalue |= RH_NRF24_RF_DR_LOW;\n    else if (data_rate == DataRate2Mbps)\n\tvalue |= RH_NRF24_RF_DR_HIGH;\n    // else DataRate1Mbps, 00\n\n    // RFM73 needs this:\n    value |= RH_NRF24_LNA_HCURR;\n    \n    spiWriteRegister(RH_NRF24_REG_06_RF_SETUP, value);\n    // If we were using auto-ack, we would have to set the appropriate timeout in reg 4 here\n    // see NRF24::setRF()\n    return true;\n}\n\nvoid RH_NRF24::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\tspiWriteRegister(RH_NRF24_REG_00_CONFIG, _configuration);\n\tdigitalWrite(_chipEnablePin, LOW);\n\t_mode = RHModeIdle;\n    }\n}\n\nbool RH_NRF24::sleep()\n{\n    if (_mode != RHModeSleep)\n    {\n\tspiWriteRegister(RH_NRF24_REG_00_CONFIG, 0); // Power Down mode\n\tdigitalWrite(_chipEnablePin, LOW);\n\t_mode = RHModeSleep;\n\treturn true;\n    }\n    return false; // Already there?\n}\n\nvoid RH_NRF24::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\tspiWriteRegister(RH_NRF24_REG_00_CONFIG, _configuration | RH_NRF24_PWR_UP | RH_NRF24_PRIM_RX);\n\tdigitalWrite(_chipEnablePin, HIGH);\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_NRF24::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\t// Its the CE rising edge that puts us into TX mode\n\t// CE staying high makes us go to standby-II when the packet is sent\n\tdigitalWrite(_chipEnablePin, LOW);\n\t// Ensure DS is not set\n\tspiWriteRegister(RH_NRF24_REG_07_STATUS, RH_NRF24_TX_DS | RH_NRF24_MAX_RT);\n\tspiWriteRegister(RH_NRF24_REG_00_CONFIG, _configuration | RH_NRF24_PWR_UP);\n\tdigitalWrite(_chipEnablePin, HIGH);\n\t_mode = RHModeTx;\n    }\n}\n\nbool RH_NRF24::send(const uint8_t* data, uint8_t len)\n{\n    if (len > RH_NRF24_MAX_MESSAGE_LEN)\n\treturn false;\n\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    // Set up the headers\n    _buf[0] = _txHeaderTo;\n    _buf[1] = _txHeaderFrom;\n    _buf[2] = _txHeaderId;\n    _buf[3] = _txHeaderFlags;\n    memcpy(_buf+RH_NRF24_HEADER_LEN, data, len);\n    spiBurstWrite(RH_NRF24_COMMAND_W_TX_PAYLOAD_NOACK, _buf, len + RH_NRF24_HEADER_LEN);\n    setModeTx();\n    // Radio will return to Standby II mode after transmission is complete\n    _txGood++;\n    return true;\n}\n\nbool RH_NRF24::waitPacketSent()\n{\n    // If we are not currently in transmit mode, there is no packet to wait for\n    if (_mode != RHModeTx)\n\treturn false;\n\n    // Wait for either the Data Sent or Max ReTries flag, signalling the \n    // end of transmission\n    // We dont actually use auto-ack, so prob dont expect to see RH_NRF24_MAX_RT\n    uint8_t status;\n    while (!((status = statusRead()) & (RH_NRF24_TX_DS | RH_NRF24_MAX_RT)))\n\tYIELD;\n\n    // Must clear RH_NRF24_MAX_RT if it is set, else no further comm\n    if (status & RH_NRF24_MAX_RT)\n\tflushTx();\n    setModeIdle();\n    spiWriteRegister(RH_NRF24_REG_07_STATUS, RH_NRF24_TX_DS | RH_NRF24_MAX_RT);\n    // Return true if data sent, false if MAX_RT\n    return status & RH_NRF24_TX_DS;\n}\n\nbool RH_NRF24::isSending()\n{\n    return !(spiReadRegister(RH_NRF24_REG_00_CONFIG) & RH_NRF24_PRIM_RX) && \n\t   !(statusRead() & (RH_NRF24_TX_DS | RH_NRF24_MAX_RT));\n}\n\nbool RH_NRF24::printRegisters()\n{\n#ifdef RH_HAVE_SERIAL\n    // Iterate over register range, but don't process registers not in use.\n    for (uint8_t r = RH_NRF24_REG_00_CONFIG; r <= RH_NRF24_REG_1D_FEATURE; r++)\n    {\n      if ((r <= RH_NRF24_REG_17_FIFO_STATUS) || (r >= RH_NRF24_REG_1C_DYNPD))\n      {\n        Serial.print(r, HEX);\n        Serial.print(\": \");\n        uint8_t len = 1;\n        // Address registers are 5 bytes in size\n        if (    (RH_NRF24_REG_0A_RX_ADDR_P0 == r)\n             || (RH_NRF24_REG_0B_RX_ADDR_P1 == r)\n             || (RH_NRF24_REG_10_TX_ADDR    == r) )\n        {\n          len = 5;\n        }\n        uint8_t buf[5];\n        spiBurstReadRegister(r, buf, len);\n        for (uint8_t j = 0; j < len; ++j)\n        {\n          Serial.print(buf[j], HEX);\n          Serial.print(\" \");\n        }\n        Serial.println(\"\");\n      }\n    }\n#endif\n\n    return true;\n}\n\n// Check whether the latest received message is complete and uncorrupted\nvoid RH_NRF24::validateRxBuf()\n{\n    if (_bufLen < 4)\n\treturn; // Too short to be a real message\n    // Extract the 4 headers\n    _rxHeaderTo    = _buf[0];\n    _rxHeaderFrom  = _buf[1];\n    _rxHeaderId    = _buf[2];\n    _rxHeaderFlags = _buf[3];\n    if (_promiscuous ||\n\t_rxHeaderTo == _thisAddress ||\n\t_rxHeaderTo == RH_BROADCAST_ADDRESS)\n    {\n\t_rxGood++;\n\t_rxBufValid = true;\n    }\n}\n\nbool RH_NRF24::available()\n{\n    if (!_rxBufValid)\n    {\n\tif (_mode == RHModeTx)\n\t    return false;\n\tsetModeRx();\n\tif (spiReadRegister(RH_NRF24_REG_17_FIFO_STATUS) & RH_NRF24_RX_EMPTY)\n\t    return false;\n\t// Manual says that messages > 32 octets should be discarded\n\tuint8_t len = spiRead(RH_NRF24_COMMAND_R_RX_PL_WID);\n\tif (len > 32)\n\t{\n\t    flushRx();\n\t    clearRxBuf();\n\t    setModeIdle();\n\t    return false;\n\t}\n\t// Clear read interrupt\n\tspiWriteRegister(RH_NRF24_REG_07_STATUS, RH_NRF24_RX_DR);\n\t// Get the message into the RX buffer, so we can inspect the headers\n\tspiBurstRead(RH_NRF24_COMMAND_R_RX_PAYLOAD, _buf, len);\n\t_bufLen = len;\n\t// 140 microsecs (32 octet payload)\n\tvalidateRxBuf(); \n\tif (_rxBufValid)\n\t    setModeIdle(); // Got one\n    }\n    return _rxBufValid;\n}\n\nvoid RH_NRF24::clearRxBuf()\n{\n    _rxBufValid = false;\n    _bufLen = 0;\n}\n\nbool RH_NRF24::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n    if (buf && len)\n    {\n\t// Skip the 4 headers that are at the beginning of the rxBuf\n\tif (*len > _bufLen-RH_NRF24_HEADER_LEN)\n\t    *len = _bufLen-RH_NRF24_HEADER_LEN;\n\tmemcpy(buf, _buf+RH_NRF24_HEADER_LEN, *len);\n    }\n    clearRxBuf(); // This message accepted and cleared\n    return true;\n}\n\nuint8_t RH_NRF24::maxMessageLength()\n{\n    return RH_NRF24_MAX_MESSAGE_LEN;\n}\n"
  },
  {
    "path": "RH_NRF24.h",
    "content": "// RH_NRF24.h\n// Author: Mike McCauley\n// Copyright (C) 2012 Mike McCauley\n// $Id: RH_NRF24.h,v 1.19 2016/07/07 00:02:53 mikem Exp $\n//\n\n#ifndef RH_NRF24_h\n#define RH_NRF24_h\n\n#include <RHGenericSPI.h>\n#include <RHNRFSPIDriver.h>\n\n// This is the maximum number of bytes that can be carried by the nRF24.\n// We use some for headers, keeping fewer for RadioHead messages\n#define RH_NRF24_MAX_PAYLOAD_LEN 32\n\n// The length of the headers we add.\n// The headers are inside the nRF24 payload\n#define RH_NRF24_HEADER_LEN 4\n\n// This is the maximum RadioHead user message length that can be supported by this library. Limited by\n// the supported message lengths in the nRF24\n#define RH_NRF24_MAX_MESSAGE_LEN (RH_NRF24_MAX_PAYLOAD_LEN-RH_NRF24_HEADER_LEN)\n\n// SPI Command names\n#define RH_NRF24_COMMAND_R_REGISTER                        0x00\n#define RH_NRF24_COMMAND_W_REGISTER                        0x20\n#define RH_NRF24_COMMAND_ACTIVATE                          0x50 // only on RFM73 ?\n#define RH_NRF24_COMMAND_R_RX_PAYLOAD                      0x61\n#define RH_NRF24_COMMAND_W_TX_PAYLOAD                      0xa0\n#define RH_NRF24_COMMAND_FLUSH_TX                          0xe1\n#define RH_NRF24_COMMAND_FLUSH_RX                          0xe2\n#define RH_NRF24_COMMAND_REUSE_TX_PL                       0xe3\n#define RH_NRF24_COMMAND_R_RX_PL_WID                       0x60\n#define RH_NRF24_COMMAND_W_ACK_PAYLOAD(pipe)               (0xa8|(pipe&0x7))\n#define RH_NRF24_COMMAND_W_TX_PAYLOAD_NOACK                0xb0\n#define RH_NRF24_COMMAND_NOP                               0xff\n\n// Register names\n#define RH_NRF24_REGISTER_MASK                             0x1f\n#define RH_NRF24_REG_00_CONFIG                             0x00\n#define RH_NRF24_REG_01_EN_AA                              0x01\n#define RH_NRF24_REG_02_EN_RXADDR                          0x02\n#define RH_NRF24_REG_03_SETUP_AW                           0x03\n#define RH_NRF24_REG_04_SETUP_RETR                         0x04\n#define RH_NRF24_REG_05_RF_CH                              0x05\n#define RH_NRF24_REG_06_RF_SETUP                           0x06\n#define RH_NRF24_REG_07_STATUS                             0x07\n#define RH_NRF24_REG_08_OBSERVE_TX                         0x08\n#define RH_NRF24_REG_09_RPD                                0x09\n#define RH_NRF24_REG_0A_RX_ADDR_P0                         0x0a\n#define RH_NRF24_REG_0B_RX_ADDR_P1                         0x0b\n#define RH_NRF24_REG_0C_RX_ADDR_P2                         0x0c\n#define RH_NRF24_REG_0D_RX_ADDR_P3                         0x0d\n#define RH_NRF24_REG_0E_RX_ADDR_P4                         0x0e\n#define RH_NRF24_REG_0F_RX_ADDR_P5                         0x0f\n#define RH_NRF24_REG_10_TX_ADDR                            0x10\n#define RH_NRF24_REG_11_RX_PW_P0                           0x11\n#define RH_NRF24_REG_12_RX_PW_P1                           0x12\n#define RH_NRF24_REG_13_RX_PW_P2                           0x13\n#define RH_NRF24_REG_14_RX_PW_P3                           0x14\n#define RH_NRF24_REG_15_RX_PW_P4                           0x15\n#define RH_NRF24_REG_16_RX_PW_P5                           0x16\n#define RH_NRF24_REG_17_FIFO_STATUS                        0x17\n#define RH_NRF24_REG_1C_DYNPD                              0x1c\n#define RH_NRF24_REG_1D_FEATURE                            0x1d\n\n// These register masks etc are named wherever possible\n// corresponding to the bit and field names in the nRF24L01 Product Specification\n// #define RH_NRF24_REG_00_CONFIG                             0x00\n#define RH_NRF24_MASK_RX_DR                                0x40\n#define RH_NRF24_MASK_TX_DS                                0x20\n#define RH_NRF24_MASK_MAX_RT                               0x10\n#define RH_NRF24_EN_CRC                                    0x08\n#define RH_NRF24_CRCO                                      0x04\n#define RH_NRF24_PWR_UP                                    0x02\n#define RH_NRF24_PRIM_RX                                   0x01\n\n// #define RH_NRF24_REG_01_EN_AA                              0x01\n#define RH_NRF24_ENAA_P5                                   0x20\n#define RH_NRF24_ENAA_P4                                   0x10\n#define RH_NRF24_ENAA_P3                                   0x08\n#define RH_NRF24_ENAA_P2                                   0x04\n#define RH_NRF24_ENAA_P1                                   0x02\n#define RH_NRF24_ENAA_P0                                   0x01\n\n// #define RH_NRF24_REG_02_EN_RXADDR                          0x02\n#define RH_NRF24_ERX_P5                                    0x20\n#define RH_NRF24_ERX_P4                                    0x10\n#define RH_NRF24_ERX_P3                                    0x08\n#define RH_NRF24_ERX_P2                                    0x04\n#define RH_NRF24_ERX_P1                                    0x02\n#define RH_NRF24_ERX_P0                                    0x01\n\n// #define RH_NRF24_REG_03_SETUP_AW                           0x03\n#define RH_NRF24_AW_3_BYTES                                0x01\n#define RH_NRF24_AW_4_BYTES                                0x02\n#define RH_NRF24_AW_5_BYTES                                0x03\n\n// #define RH_NRF24_REG_04_SETUP_RETR                         0x04\n#define RH_NRF24_ARD                                       0xf0\n#define RH_NRF24_ARC                                       0x0f\n\n// #define RH_NRF24_REG_05_RF_CH                              0x05\n#define RH_NRF24_RF_CH                                     0x7f\n\n// #define RH_NRF24_REG_06_RF_SETUP                           0x06\n#define RH_NRF24_CONT_WAVE                                 0x80\n#define RH_NRF24_RF_DR_LOW                                 0x20\n#define RH_NRF24_PLL_LOCK                                  0x10\n#define RH_NRF24_RF_DR_HIGH                                0x08\n#define RH_NRF24_PWR                                       0x06\n#define RH_NRF24_PWR_m18dBm                                0x00\n#define RH_NRF24_PWR_m12dBm                                0x02\n#define RH_NRF24_PWR_m6dBm                                 0x04\n#define RH_NRF24_PWR_0dBm                                  0x06\n#define RH_NRF24_LNA_HCURR                                 0x01\n\n// #define RH_NRF24_REG_07_STATUS                             0x07\n#define RH_NRF24_RX_DR                                     0x40\n#define RH_NRF24_TX_DS                                     0x20\n#define RH_NRF24_MAX_RT                                    0x10\n#define RH_NRF24_RX_P_NO                                   0x0e\n#define RH_NRF24_STATUS_TX_FULL                            0x01\n\n// #define RH_NRF24_REG_08_OBSERVE_TX                         0x08\n#define RH_NRF24_PLOS_CNT                                  0xf0\n#define RH_NRF24_ARC_CNT                                   0x0f\n\n// #define RH_NRF24_REG_09_RPD                                0x09\n#define RH_NRF24_RPD                                       0x01\n\n// #define RH_NRF24_REG_17_FIFO_STATUS                        0x17\n#define RH_NRF24_TX_REUSE                                  0x40\n#define RH_NRF24_TX_FULL                                   0x20\n#define RH_NRF24_TX_EMPTY                                  0x10\n#define RH_NRF24_RX_FULL                                   0x02\n#define RH_NRF24_RX_EMPTY                                  0x01\n\n// #define RH_NRF24_REG_1C_DYNPD                              0x1c\n#define RH_NRF24_DPL_ALL                                   0x3f\n#define RH_NRF24_DPL_P5                                    0x20\n#define RH_NRF24_DPL_P4                                    0x10\n#define RH_NRF24_DPL_P3                                    0x08\n#define RH_NRF24_DPL_P2                                    0x04\n#define RH_NRF24_DPL_P1                                    0x02\n#define RH_NRF24_DPL_P0                                    0x01\n\n// #define RH_NRF24_REG_1D_FEATURE                            0x1d\n#define RH_NRF24_EN_DPL                                    0x04\n#define RH_NRF24_EN_ACK_PAY                                0x02\n#define RH_NRF24_EN_DYN_ACK                                0x01\n\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_NRF24 RH_NRF24.h <RH_NRF24.h>\n/// \\brief Send and receive addressed, reliable, acknowledged datagrams by nRF24L01 and compatible transceivers.\n///\n/// Supported transceivers include:\n/// - Nordic nRF24 based 2.4GHz radio modules, such as nRF24L01 http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01\n/// and other compatible transceivers. \n/// - nRF24L01p with PA and LNA modules that produce a higher power output similar to this one: \n/// http://www.elecfreaks.com/wiki/index.php?title=2.4G_Wireless_nRF24L01p_with_PA_and_LNA\n/// - Sparkfun WRL-00691 module with nRF24L01 https://www.sparkfun.com/products/691 \n/// or WRL-00705 https://www.sparkfun.com/products/705 etc.\n/// - Hope-RF RFM73 http://www.hoperf.com/rf/2.4g_module/RFM73.htm and \n/// http://www.anarduino.com/details.jsp?pid=121\n/// and compatible devices (such as BK2423). nRF24L01 and RFM73 can interoperate\n/// with each other.\n///\n/// This base class provides basic functions for sending and receiving unaddressed, unreliable datagrams\n/// of arbitrary length to 28 octets per packet. Use one of the Manager classes to get addressing and \n/// acknowledgement reliability, routing, meshes etc.\n///\n/// The nRF24L01 (http://www.sparkfun.com/datasheets/Wireless/Nordic/nRF24L01P_Product_Specification_1_0.pdf)\n/// is a low-cost 2.4GHz ISM transceiver module. It supports a number of channel frequencies in the 2.4GHz band\n/// and a range of data rates.\n///\n/// This library provides functions for sending and receiving messages of up to 28 octets on any \n/// frequency supported by the nRF24L01, at a selected data rate.\n///\n/// Several nRF24L01 modules can be connected to an Arduino, permitting the construction of translators\n/// and frequency changers, etc.\n///\n/// The nRF24 transceiver is configured to use Enhanced Shockburst with no acknowledgement and no retransmits.\n/// TX_ADDR and RX_ADDR_P0 are set to the network address. If you need the low level auto-acknowledgement\n/// feature supported by this chip, you can use our original NRF24 library \n/// at http://www.airspayce.com/mikem/arduino/NRF24\n///\n/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and \n/// data rate, and with identical network addresses.\n///\n/// Example Arduino programs are included to show the main modes of use.\n///\n/// \\par Packet Format\n///\n/// All messages sent and received by this class conform to this packet format, as specified by \n/// the nRF24L01 product specification:\n///\n/// - 1 octets PREAMBLE\n/// - 3 to 5 octets NETWORK ADDRESS\n/// - 9 bits packet control field\n/// - 0 to 32 octets PAYLOAD, consisting of:\n///   - 1 octet TO header\n///   - 1 octet FROM header\n///   - 1 octet ID header\n///   - 1 octet FLAGS header\n///   - 0 to 28 octets of user message\n/// - 2 octets CRC \n///\n/// \\par Connecting nRF24L01 to Arduino\n///\n/// The electrical connection between the nRF24L01 and the Arduino require 3.3V, the 3 x SPI pins (SCK, SDI, SDO), \n/// a Chip Enable pin and a Slave Select pin.\n/// If you are using the Sparkfun WRL-00691 module, it has a voltage regulator on board and \n/// can be should with 5V VCC if possible.\n/// The examples below assume the Sparkfun WRL-00691 module\n///\n/// Connect the nRF24L01 to most Arduino's like this (Caution, Arduino Mega has different pins for SPI, \n/// see below). Use these same connections for Teensy 3.1 (use 3.3V not 5V Vcc).\n/// \\code\n///                 Arduino      Sparkfun WRL-00691\n///                 5V-----------VCC   (3.3V to 7V in)\n///             pin D8-----------CE    (chip enable in)\n///          SS pin D10----------CSN   (chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------SDI   (SPI Data in)\n///        MISO pin D12----------SDO   (SPI data out)\n///                              IRQ   (Interrupt output, not connected)\n///                 GND----------GND   (ground in)\n/// \\endcode\n///\n/// For an Arduino Leonardo (the SPI pins do not come out on the Digital pins as for normal Arduino, but only\n/// appear on the ICSP header)\n/// \\code\n///                Leonardo      Sparkfun WRL-00691\n///                 5V-----------VCC   (3.3V to 7V in)\n///             pin D8-----------CE    (chip enable in)\n///          SS pin D10----------CSN   (chip select in)\n///      SCK ICSP pin 3----------SCK   (SPI clock in)\n///     MOSI ICSP pin 4----------SDI   (SPI Data in)\n///     MISO ICSP pin 1----------SDO   (SPI data out)\n///                              IRQ   (Interrupt output, not connected)\n///                 GND----------GND   (ground in)\n/// \\endcode\n/// and initialise the NRF24 object like this to explicitly set the SS pin\n/// NRF24 nrf24(8, 10);\n///\n/// For an Arduino Due (the SPI pins do not come out on the Digital pins as for normal Arduino, but only\n/// appear on the SPI header). Use the same connections for Yun with 5V or 3.3V.\n/// \\code\n///                Due      Sparkfun WRL-00691\n///               3.3V-----------VCC   (3.3V to 7V in)\n///             pin D8-----------CE    (chip enable in)\n///          SS pin D10----------CSN   (chip select in)\n///       SCK SPI pin 3----------SCK   (SPI clock in)\n///      MOSI SPI pin 4----------SDI   (SPI Data in)\n///      MISO SPI pin 1----------SDO   (SPI data out)\n///                              IRQ   (Interrupt output, not connected)\n///                 GND----------GND   (ground in)\n/// \\endcode\n/// and initialise the NRF24 object with the default constructor\n/// NRF24 nrf24;\n///\n/// For an Arduino Mega:\n/// \\code\n///                 Mega         Sparkfun WRL-00691\n///                 5V-----------VCC   (3.3V to 7V in)\n///             pin D8-----------CE    (chip enable in)\n///          SS pin D53----------CSN   (chip select in)\n///         SCK pin D52----------SCK   (SPI clock in)\n///        MOSI pin D51----------SDI   (SPI Data in)\n///        MISO pin D50----------SDO   (SPI data out)\n///                              IRQ   (Interrupt output, not connected)\n///                 GND----------GND   (ground in)\n/// \\endcode\n/// and you can then use the constructor RH_NRF24(8, 53). \n///\n/// For an Itead Studio IBoard Pro http://imall.iteadstudio.com/iboard-pro.html, connected by hardware SPI to the \n/// ITDB02 Parallel LCD Module Interface pins:\n/// \\code\n///  IBoard Signal=ITDB02 pin          Sparkfun WRL-00691\n///        3.3V      37-----------VCC  (3.3V to 7V in)\n///         D2       28-----------CE   (chip enable in)\n///         D29      27----------CSN   (chip select in)\n///         SCK D52  32----------SCK   (SPI clock in)\n///        MOSI D51  34----------SDI   (SPI Data in)\n///        MISO D50  30----------SDO   (SPI data out)\n///                              IRQ   (Interrupt output, not connected)\n///        GND       39----------GND   (ground in)\n/// \\endcode\n/// And initialise like this:\n/// \\code\n/// RH_NRF24 nrf24(2, 29);\n/// \\endcode\n///\n/// For an Itead Studio IBoard Pro http://imall.iteadstudio.com/iboard-pro.html, connected by software SPI to the \n/// nRF24L01+ Module Interface pins. CAUTION: performance of software SPI is very slow and is not\n/// compatible with other modules running hardware SPI.\n/// \\code\n///  IBoard Signal=Module pin          Sparkfun WRL-00691\n///        3.3V      2----------VCC   (3.3V to 7V in)\n///         D12      3-----------CE   (chip enable in)\n///         D29      4----------CSN   (chip select in)\n///         D9       5----------SCK   (SPI clock in)\n///         D8       6----------SDI   (SPI Data in)\n///         D7       7----------SDO   (SPI data out)\n///                              IRQ   (Interrupt output, not connected)\n///        GND       1----------GND   (ground in)\n/// \\endcode\n/// And initialise like this:\n/// \\code\n/// #include <SPI.h>\n/// #include <RH_NRF24.h>\n/// #include <RHSoftwareSPI.h>\n/// Singleton instance of the radio driver\n/// RHSoftwareSPI spi;\n/// RH_NRF24 nrf24(12, 11, spi);\n/// void setup() {\n///     spi.setPins(7, 8, 9);\n///     ....\n/// \\endcode\n///\n///\n/// For Raspberry Pi with Sparkfun WRL-00691 \n/// \\code\n///     Raspberry Pi P1 pin          Sparkfun WRL-00691\n///             5V      2-----------VCC   (3.3V to 7V in)\n///         GPIO25      22-----------CE   (chip enable in)\n///         GPIO8       24----------CSN   (chip select in)\n///         GPIO11      23----------SCK   (SPI clock in)\n///         GPIO10      19----------SDI   (SPI Data in)\n///         GPIO9       21----------SDO   (SPI data out)\n///                                 IRQ   (Interrupt output, not connected)\n///            GND       6----------GND   (ground in)\n/// \\endcode\n/// and initialise like this:\n/// \\code\n///  RH_NRF24 nrf24(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_24);\n/// \\endcode\n/// See the example program and Makefile in examples/raspi. Requires bcm2835 library to be previously installed.\n/// \\code\n/// cd examples/raspi\n/// make\n/// sudo ./RasPiRH\n/// \\endcode\n/// \\code\n///\n/// You can override the default settings for the CSN and CE pins \n/// in the NRF24() constructor if you wish to connect the slave select CSN to other than the normal one for your \n/// Arduino (D10 for Diecimila, Uno etc and D53 for Mega)\n///\n/// Caution: on some Arduinos such as the Mega 2560, if you set the slave select pin to be other than the usual SS \n/// pin (D53 on  Mega 2560), you may need to set the usual SS pin to be an output to force the Arduino into SPI \n/// master mode.\n///\n/// Caution: this module has not been proved to work with Leonardo, at least without level \n/// shifters between the nRF24 and the Leonardo. Tests seem to indicate that such level shifters would be required\n/// with Leonardo to make it work.\n///\n/// It is possible to have 2 radios conected to one arduino, provided each radio has its own \n/// CSN and CE line (SCK, SDI and SDO are common to both radios)\n///\n/// \\par SPI Interface\n///\n/// You can interface to nRF24L01 with with hardware or software SPI. Use of software SPI with the RHSoftwareSPI \n/// class depends on a fast enough processor and digitalOut() functions to achieve a high enough SPI bus frequency.\n/// If you observe reliable behaviour with the default hardware SPI RHHardwareSPI, but unreliable behaviour \n/// with Software SPI RHSoftwareSPI, it may be due to slow CPU performance.\n///\n/// Initialisation example with hardware SPI\n/// \\code\n/// #include <RH_NRF24.h>\n/// RH_NRF24 driver;\n/// RHReliableDatagram manager(driver, CLIENT_ADDRESS);\n/// \\endcode\n///\n/// Initialisation example with software SPI\n/// \\code\n/// #include <RH_NRF24.h>\n/// #include <RHSoftwareSPI.h>\n/// RHSoftwareSPI spi;\n/// RH_NRF24 driver(8, 10, spi);\n/// RHReliableDatagram manager(driver, CLIENT_ADDRESS);\n/// \\endcode\n///\n/// \\par Example programs\n///\n/// Several example programs are provided.\n///\n/// \\par Radio Performance\n///\n/// Frequency accuracy may be debatable. For nominal frequency of 2401.000 MHz (ie channel 1), \n/// my Yaesu VR-5000 receiver indicated the center frequency for my test radios\n/// was 2401.121 MHz. Its not clear to me if the Yaesu\n/// is the source of the error, but I tend to believe it, which would make the nRF24l01 frequency out by 121kHz.\n///\n/// The measured power output for a nRF24L01p with PA and LNA set to 0dBm output is about 18dBm.\n/// \n/// \\par Radio operating strategy and defaults\n///\n/// The radio is enabled all the time, and switched between TX and RX modes depending on \n/// whether there is any data to send. Sending data sets the radio to TX mode.\n/// After data is sent, the radio automatically returns to Standby II mode. Calling waitAvailable() or\n/// waitAvailableTimeout() starts the radio in RX mode.\n///\n/// The radio is configured by default to Channel 2, 2Mbps, 0dBm power, 5 bytes address, payload width 1, CRC enabled\n/// 2 byte CRC, No Auto-Ack mode. Enhanced shockburst is used. \n/// TX and P0 are set to the Network address. Node addresses and decoding are handled with the RH_NRF24 module.\n///\n/// \\par Memory\n///\n/// Memory usage of this class is minimal. The compiled client and server sketches are about 6000 bytes on Arduino. \n/// The reliable client and server sketches compile to about 8500 bytes on Arduino.\n/// RAM requirements are minimal.\n///\nclass RH_NRF24 : public RHNRFSPIDriver\n{\npublic:\n\n    /// \\brief Defines convenient values for setting data rates in setRF()\n    typedef enum\n    {\n\tDataRate1Mbps = 0,   ///< 1 Mbps\n\tDataRate2Mbps,       ///< 2 Mbps\n\tDataRate250kbps      ///< 250 kbps\n    } DataRate;\n\n    /// \\brief Convenient values for setting transmitter power in setRF()\n    /// These are designed to agree with the values for RF_PWR in RH_NRF24_REG_06_RF_SETUP\n    /// To be passed to setRF();\n    typedef enum\n    {\n\t// Add 20dBm for nRF24L01p with PA and LNA modules\n\tTransmitPowerm18dBm = 0,        ///< On nRF24, -18 dBm\n\tTransmitPowerm12dBm,            ///< On nRF24, -12 dBm\n\tTransmitPowerm6dBm,             ///< On nRF24, -6 dBm\n\tTransmitPower0dBm,              ///< On nRF24, 0 dBm\n\t// Sigh, different power levels for the same bit patterns on RFM73:\n\t// On RFM73P-S, there is a Tx power amp, so expect higher power levels, up to 20dBm. Alas\n\t// there is no clear documentation on the power for different settings :-(\n\tRFM73TransmitPowerm10dBm = 0,   ///< On RFM73, -10 dBm\n\tRFM73TransmitPowerm5dBm,        ///< On RFM73, -5 dBm\n\tRFM73TransmitPowerm0dBm,        ///< On RFM73, 0 dBm\n\tRFM73TransmitPower5dBm          ///< On RFM73, 5 dBm. 20dBm on RFM73P-S2 ?\n\n    } TransmitPower;\n\n    /// Constructor. You can have multiple instances, but each instance must have its own\n    /// chip enable and slave select pin. \n    /// After constructing, you must call init() to initialise the interface\n    /// and the radio module\n    /// \\param[in] chipEnablePin the Arduino pin to use to enable the chip for transmit/receive\n    /// \\param[in] slaveSelectPin the Arduino pin number of the output to use to select the NRF24 before\n    /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, \n    /// D10 for Maple)\n    /// \\param[in] spi Pointer to the SPI interface object to use. \n    ///                Defaults to the standard Arduino hardware SPI interface\n    RH_NRF24(uint8_t chipEnablePin = 8, uint8_t slaveSelectPin = SS, RHGenericSPI& spi = hardware_spi);\n  \n    /// Initialises this instance and the radio module connected to it.\n    /// The following steps are taken:g\n    /// - Set the chip enable and chip select pins to output LOW, HIGH respectively.\n    /// - Initialise the SPI output pins\n    /// - Initialise the SPI interface library to 8MHz (Hint, if you want to lower\n    /// the SPI frequency (perhaps where you have other SPI shields, low voltages etc), \n    /// call SPI.setClockDivider() after init()).\n    /// -Flush the receiver and transmitter buffers\n    /// - Set the radio to receive with powerUpRx();\n    /// \\return  true if everything was successful\n    bool        init();\n\n    /// Reads a single register from the NRF24\n    /// \\param[in] reg Register number, one of RH_NRF24_REG_*\n    /// \\return The value of the register\n    uint8_t        spiReadRegister(uint8_t reg);\n\n    /// Writes a single byte to the NRF24, and at the same time reads the current STATUS register\n    /// \\param[in] reg Register number, one of RH_NRF24_REG_*\n    /// \\param[in] val The value to write\n    /// \\return the current STATUS (read while the command is sent)\n    uint8_t        spiWriteRegister(uint8_t reg, uint8_t val);\n\n    /// Reads a number of consecutive registers from the NRF24 using burst read mode\n    /// \\param[in] reg Register number of the first register, one of RH_NRF24_REG_*\n    /// \\param[in] dest Array to write the register values to. Must be at least len bytes\n    /// \\param[in] len Number of bytes to read\n    /// \\return the current STATUS (read while the command is sent)\n    uint8_t           spiBurstReadRegister(uint8_t reg, uint8_t* dest, uint8_t len);\n\n    /// Write a number of consecutive registers using burst write mode\n    /// \\param[in] reg Register number of the first register, one of RH_NRF24_REG_*\n    /// \\param[in] src Array of new register values to write. Must be at least len bytes\n    /// \\param[in] len Number of bytes to write\n    /// \\return the current STATUS (read while the command is sent)\n    uint8_t        spiBurstWriteRegister(uint8_t reg, uint8_t* src, uint8_t len);\n\n    /// Reads and returns the device status register NRF24_REG_02_DEVICE_STATUS\n    /// \\return The value of the device status register\n    uint8_t        statusRead();\n  \n    /// Sets the transmit and receive channel number.\n    /// The frequency used is (2400 + channel) MHz\n    /// \\return true on success\n    bool setChannel(uint8_t channel);\n\n    /// Sets the chip configuration that will be used to set\n    /// the NRF24 NRF24_REG_00_CONFIG register when in Idle mode. This allows you to change some\n    /// chip configuration for compatibility with libraries other than this one.\n    /// You should not normally need to call this.\n    /// Defaults to NRF24_EN_CRC| RH_NRF24_CRCO, which is the standard configuration for this library \n    /// (2 byte CRC enabled).\n    /// \\param[in] mode The chip configuration to be used whe in Idle mode.\n    /// \\return true on success\n    bool setOpMode(uint8_t mode);\n\n    /// Sets the Network address.\n    /// Only nodes with the same network address can communicate with each other. You \n    /// can set different network addresses in different sets of nodes to isolate them from each other.\n    /// Internally, this sets the nRF24 TX_ADDR and RX_ADDR_P0 to be the given network address.\n    /// The default network address is 0xE7E7E7E7E7\n    /// \\param[in] address The new network address. Must match the network address of any receiving node(s).\n    /// \\param[in] len Number of bytes of address to set (3 to 5).\n    /// \\return true on success, false if len is not in the range 3-5 inclusive.\n    bool setNetworkAddress(uint8_t* address, uint8_t len);\n\n    /// Sets the data rate and transmitter power to use. Note that the nRF24 and the RFM73 have different\n    /// available power levels, and for convenience, 2 different sets of values are available in the \n    /// RH_NRF24::TransmitPower enum. The ones with the RFM73 only have meaning on the RFM73 and compatible\n    /// devces. The others are for the nRF24.\n    /// \\param [in] data_rate The data rate to use for all packets transmitted and received. One of RH_NRF24::DataRate.\n    /// \\param [in] power Transmitter power. One of RH_NRF24::TransmitPower.\n    /// \\return true on success\n    bool setRF(DataRate data_rate, TransmitPower power);\n\n    /// Sets the radio in power down mode, with the configuration set to the\n    /// last value from setOpMode().\n    /// Sets chip enable to LOW.\n    void setModeIdle();\n\n    /// Sets the radio in RX mode.\n    /// Sets chip enable to HIGH to enable the chip in RX mode.\n    void setModeRx();\n\n    /// Sets the radio in TX mode.\n    /// Pulses the chip enable LOW then HIGH to enable the chip in TX mode.\n    void setModeTx();\n\n    /// Sends data to the address set by setTransmitAddress()\n    /// Sets the radio to TX mode\n    /// \\param [in] data Data bytes to send.\n    /// \\param [in] len Number of data bytes to send\n    /// \\return true on success (which does not necessarily mean the receiver got the message, only that the message was\n    /// successfully transmitted).\n    bool send(const uint8_t* data, uint8_t len);\n\n    /// Blocks until the current message (if any) \n    /// has been transmitted\n    /// \\return true on success, false if the chip is not in transmit mode or other transmit failure\n    virtual bool waitPacketSent();\n\n    /// Indicates if the chip is in transmit mode and \n    /// there is a packet currently being transmitted\n    /// \\return true if the chip is in transmit mode and there is a transmission in progress\n    bool isSending();\n\n    /// Prints the value of all chip registers\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// For debugging purposes only.\n    /// \\return true on success\n    bool printRegisters();\n\n    /// Checks whether a received message is available.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a complete, valid message has been received and is able to be retrieved by\n    /// recv()\n    bool        available();\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    bool        recv(uint8_t* buf, uint8_t* len);\n\n    /// The maximum message length supported by this driver\n    /// \\return The maximum message length supported by this driver\n    uint8_t maxMessageLength();\n\n    /// Sets the radio into Power Down mode.\n    /// If successful, the radio will stay in Power Down mode until woken by \n    /// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc)\n    /// Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode.\n    /// \\return true if sleep mode was successfully entered.\n    virtual bool    sleep();\n\nprotected:\n    /// Flush the TX FIFOs\n    /// \\return the value of the device status register\n    uint8_t flushTx();\n\n    /// Flush the RX FIFOs\n    /// \\return the value of the device status register\n    uint8_t flushRx();\n\n    /// Examine the receive buffer to determine whether the message is for this node\n    void validateRxBuf();\n\n    /// Clear our local receive buffer\n    void clearRxBuf();\n\nprivate:\n    /// This idle mode chip configuration\n    uint8_t             _configuration;\n\n    /// the number of the chip enable pin\n    uint8_t             _chipEnablePin;\n\n    /// Number of octets in the buffer\n    uint8_t             _bufLen;\n    \n    /// The receiver/transmitter buffer\n    uint8_t             _buf[RH_NRF24_MAX_PAYLOAD_LEN];\n\n    /// True when there is a valid message in the buffer\n    bool                _rxBufValid;\n};\n\n/// @example nrf24_client.pde\n/// @example nrf24_server.pde\n/// @example nrf24_reliable_datagram_client.pde\n/// @example nrf24_reliable_datagram_server.pde\n/// @example RasPiRH.cpp\n\n#endif \n"
  },
  {
    "path": "RH_NRF51.cpp",
    "content": "// NRF51.cpp\n//\n// Per: nRF51_Series_Reference_manual v3.0.pdf\n// Copyright (C) 2012 Mike McCauley\n// $Id: RH_NRF51.cpp,v 1.3 2017/01/13 01:29:36 mikem Exp mikem $\n\n// Set by Arduino IDE and RadioHead.h when compiling for nRF51 or nRF52 chips:\n\n#include <RH_NRF51.h>\n\n#if RH_PLATFORM==RH_PLATFORM_NRF51\n\n\nRH_NRF51::RH_NRF51()\n    : _rxBufValid(false)\n#if RH_NRF51_HAVE_ENCRYPTION\n      , _encrypting(false)\n#endif\n{\n}\n\nbool RH_NRF51::init()\n{\n    // Enable the High Frequency clock to the system as a whole\n    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;\n    NRF_CLOCK->TASKS_HFCLKSTART = 1;\n    /* Wait for the external oscillator to start up */\n    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)\n\t;\n    \n    // Disable and reset the radio\n    NRF_RADIO->POWER = RADIO_POWER_POWER_Disabled;\n    NRF_RADIO->POWER = RADIO_POWER_POWER_Enabled;\n    NRF_RADIO->EVENTS_DISABLED = 0;\n    NRF_RADIO->TASKS_DISABLE   = 1;\n    // Wait until we are in DISABLE state\n    while (NRF_RADIO->EVENTS_DISABLED == 0) {}\n\n    // Physical on-air address is set in PREFIX0 + BASE0 by setNetworkAddress\n    NRF_RADIO->TXADDRESS    = 0x00;\t// Use logical address 0 (PREFIX0 + BASE0)\n    NRF_RADIO->RXADDRESSES  = 0x01;\t// Enable reception on logical address 0 (PREFIX0 + BASE0)\n\n    // Configure the CRC\n    NRF_RADIO->CRCCNF = (RADIO_CRCCNF_LEN_Two << RADIO_CRCCNF_LEN_Pos); // Number of checksum bits\n    NRF_RADIO->CRCINIT = 0xFFFFUL;      // Initial value      \n    NRF_RADIO->CRCPOLY = 0x11021UL;     // CRC poly: x^16+x^12^x^5+1\n\n    // These shorts will make the radio transition from Ready to Start to Disable automatically\n    // for both TX and RX, which makes for much shorter on-air times\n    NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Enabled << RADIO_SHORTS_READY_START_Pos)\n\t              | (RADIO_SHORTS_END_DISABLE_Enabled << RADIO_SHORTS_END_DISABLE_Pos);\n\n    NRF_RADIO->PCNF0 =   (8 << RADIO_PCNF0_LFLEN_Pos) // Payload size length in bits\n\t               | (1 << RADIO_PCNF0_S0LEN_Pos) // S0 is 1 octet\n\t               | (8 << RADIO_PCNF0_S1LEN_Pos); // S1 is 1 octet\n\n    // Make sure we are powered down\n    setModeIdle();\n\n    // Set a default network address\n    uint8_t default_network_address[] = {0xE7, 0xE7, 0xE7, 0xE7, 0xE7};\n    setNetworkAddress(default_network_address, sizeof(default_network_address));\n\n    setChannel(2); // The default, in case it was set by another app without powering down\n    setRF(RH_NRF51::DataRate2Mbps, RH_NRF51::TransmitPower0dBm);\n    setEncryptionKey(NULL);\n    return true;\n}\n\nbool RH_NRF51::setChannel(uint8_t channel)\n{\n    NRF_RADIO->FREQUENCY = ((channel << RADIO_FREQUENCY_FREQUENCY_Pos) & RADIO_FREQUENCY_FREQUENCY_Msk);\n    return true;\n}\n\nbool RH_NRF51::setNetworkAddress(uint8_t* address, uint8_t len)\n{\n    if (len < 3 || len > 5)\n\treturn false;\n\n    // First byte is the prefix, remainder are base\n    NRF_RADIO->PREFIX0\t  = ((address[0] << RADIO_PREFIX0_AP0_Pos) & RADIO_PREFIX0_AP0_Msk);\n    uint32_t base;\n    memcpy(&base, address+1, len-1);\n    NRF_RADIO->BASE0 = base;\n\n    NRF_RADIO->PCNF1 =  (\n\t(((sizeof(_buf)) << RADIO_PCNF1_MAXLEN_Pos)  & RADIO_PCNF1_MAXLEN_Msk)  // maximum length of payload\n\t| (((0UL)        << RADIO_PCNF1_STATLEN_Pos) & RADIO_PCNF1_STATLEN_Msk)\t// expand the payload with 0 bytes\n\t| (((len-1)      << RADIO_PCNF1_BALEN_Pos)   & RADIO_PCNF1_BALEN_Msk)); // base address length in number of bytes.\n\n    return true;\n}\n\nbool RH_NRF51::setRF(DataRate data_rate, TransmitPower power)\n{\n    uint8_t mode;\n    uint8_t p;\n\n    if (data_rate == DataRate2Mbps)\n\tmode = RADIO_MODE_MODE_Nrf_2Mbit;\n    else if (data_rate == DataRate1Mbps)\n\tmode = RADIO_MODE_MODE_Nrf_1Mbit;\n    else if (data_rate == DataRate250kbps)\n\tmode = RADIO_MODE_MODE_Nrf_250Kbit;\n    else\n\treturn false;// Invalid\n\n    if      (power == TransmitPower4dBm)\n\tp = RADIO_TXPOWER_TXPOWER_Pos4dBm;\n    else if (power == TransmitPower0dBm)\n\tp = RADIO_TXPOWER_TXPOWER_0dBm;\n    else if (power == TransmitPowerm4dBm)\n\tp = RADIO_TXPOWER_TXPOWER_Neg4dBm;\n    else if (power == TransmitPowerm8dBm)\n\tp = RADIO_TXPOWER_TXPOWER_Neg8dBm;\n    else if (power == TransmitPowerm12dBm)\n\tp = RADIO_TXPOWER_TXPOWER_Neg12dBm;\n    else if (power == TransmitPowerm16dBm)\n\tp = RADIO_TXPOWER_TXPOWER_Neg16dBm;\n    else if (power == TransmitPowerm20dBm)\n\tp = RADIO_TXPOWER_TXPOWER_Neg20dBm;\n    else if (power == TransmitPowerm30dBm)\n\tp = RADIO_TXPOWER_TXPOWER_Neg30dBm;\n    else\n\treturn false; // Invalid\n\n\n    NRF_RADIO->TXPOWER = ((p << RADIO_TXPOWER_TXPOWER_Pos) & RADIO_TXPOWER_TXPOWER_Msk);\n    NRF_RADIO->MODE    = ((mode << RADIO_MODE_MODE_Pos) & RADIO_MODE_MODE_Msk);\n\n    return true;\n}\n\nvoid RH_NRF51::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\tNRF_RADIO->EVENTS_DISABLED = 0U;\n\tNRF_RADIO->TASKS_DISABLE = 1;\n\twhile (NRF_RADIO->EVENTS_DISABLED == 0U)\n\t    ; // wait for the radio to be disabled\n\tNRF_RADIO->EVENTS_END = 0U;\n\t_mode = RHModeIdle;\n    }\n}\n\nvoid RH_NRF51::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\tsetModeIdle(); // Can only start RX from DISABLE state\n\n#if RH_NRF51_HAVE_ENCRYPTION\n\t// Maybe set the AES CCA module for the correct encryption mode\n\tif (_encrypting)\n\t    NRF_CCM->MODE = (CCM_MODE_MODE_Decryption << CCM_MODE_MODE_Pos); // Decrypt\n\tNRF_CCM->MICSTATUS = 0;\t\n#endif\n\n\t// Radio will transition automatically to Disable state when a message is received\n\tNRF_RADIO->PACKETPTR = (uint32_t)_buf;\n\tNRF_RADIO->EVENTS_READY = 0U;\n\tNRF_RADIO->TASKS_RXEN = 1;\n\tNRF_RADIO->EVENTS_END = 0U; // So we can detect end of reception\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_NRF51::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\tsetModeIdle(); // Can only start RX from DISABLE state\n\n\t// Sigh: it seems that it takes longer to start the receiver than the transmitter for this type\n\t// of radio, so if a message is received and an ACK or reply is sent to soon, the original transmitter\n\t// may not see the reply. So we delay here to make sure the receiver is ready.\n\t// Yes, I know this is very ugly\n\tdelay(1);\n\n#if RH_NRF51_HAVE_ENCRYPTION\n\t// Maybe set the AES CCA module for the correct encryption mode\n\tif (_encrypting)\n\t    NRF_CCM->MODE = (CCM_MODE_MODE_Encryption << CCM_MODE_MODE_Pos); // Encrypt\n#endif\t    \n\t// Radio will transition automatically to Disable state at the end of transmission\n\tNRF_RADIO->PACKETPTR = (uint32_t)_buf;\n\tNRF_RADIO->EVENTS_READY = 0U;\n\tNRF_RADIO->TASKS_TXEN = 1;\n\tNRF_RADIO->EVENTS_END = 0U; // So we can detect end of transmission\n\t_mode = RHModeTx;\n    }\n}\n\nbool RH_NRF51::send(const uint8_t* data, uint8_t len)\n{\n    if (len > RH_NRF51_MAX_MESSAGE_LEN)\n\treturn false;\n\n#if RH_NRF51_HAVE_ENCRYPTION\n    if (_encrypting && len > RH_NRF51_MAX_ENCRYPTED_MESSAGE_LEN)\n\treturn false;\n#endif\n\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    // Set up the headers\n    _buf[0] = 0; // S0\n    _buf[1] = len + RH_NRF51_HEADER_LEN;\n    _buf[2] = 0; // S1\n    // The following octets are subject to encryption\n    _buf[3] = _txHeaderTo;\n    _buf[4] = _txHeaderFrom;\n    _buf[5] = _txHeaderId;\n    _buf[6] = _txHeaderFlags;\n    memcpy(_buf+RH_NRF51_HEADER_LEN, data, len);\n    _rxBufValid = false;\n    setModeTx();\n\n    // Radio will return to Disabled state after transmission is complete\n    _txGood++;\n    return true;\n}\n\nbool RH_NRF51::waitPacketSent()\n{\n    // If we are not currently in transmit mode, there is no packet to wait for\n    if (_mode != RHModeTx)\n\treturn false;\n\n    // When the Disabled event occurs we know the transmission has completed\n    while (!NRF_RADIO->EVENTS_END)\n    {\n\tYIELD;\n    }\n    setModeIdle();\n\n    return true;\n}\n\nbool RH_NRF51::isSending()\n{\n    return (NRF_RADIO->STATE == RADIO_STATE_STATE_Tx) ? true : false;\n}\n\nbool RH_NRF51::printRegisters()\n{\n#ifdef RH_HAVE_SERIAL\n    uint16_t i;\n    uint32_t* p = (uint32_t*)NRF_RADIO;\n    for (i = 0; (p + i) < (uint32_t*) (((NRF_RADIO_Type*)NRF_RADIO) + 1); i++)\n    {\n\tSerial.print(\"Offset: \");\n\tSerial.print(i, DEC);\n\tSerial.print(\" \");\n\tSerial.println(*(p+i), HEX);\n    }\n#endif\n\n    return true;\n}\n\n// Check whether the latest received message is complete and uncorrupted\nvoid RH_NRF51::validateRxBuf()\n{\n    if (_buf[1] < RH_NRF51_HEADER_LEN)\n\treturn; // Too short to be a real message\n    // Extract the 4 headers following S0, LEN and S1\n    _rxHeaderTo    = _buf[3];\n    _rxHeaderFrom  = _buf[4];\n    _rxHeaderId    = _buf[5];\n    _rxHeaderFlags = _buf[6];\n\n    if (_promiscuous ||\n\t_rxHeaderTo == _thisAddress ||\n\t_rxHeaderTo == RH_BROADCAST_ADDRESS)\n    {\n\t_rxGood++;\n\t_rxBufValid = true;\n    }\n}\n\nvoid RH_NRF51::setEncryptionKey(uint8_t* key)\n{\n#if RH_NRF51_HAVE_ENCRYPTION\n    if (key)\n    {\n\t// Configure for on-the-fly encryption\n\t// Set the key\n\tmemset(_encryption_cnf, 0, sizeof(_encryption_cnf));\n\tmemcpy(_encryption_cnf, key, RH_NRF51_ENCRYPTION_KEY_LENGTH);\n\t// AES configuration data area\n\t// Note that the IV (Nonce) is not set, defaults to 0s\n\tNRF_CCM->CNFPTR  = (uint32_t)_encryption_cnf;\n\n\t// Set AES CCM input and putput buffers\n\t// Make sure the _buf is encrypted and put back into _buf\n\tNRF_CCM->INPTR  = (uint32_t)_buf;\n\tNRF_CCM->OUTPTR = (uint32_t)_buf;\n\t// Also need to set SCRATCHPTR temp buffer os size 16+MAXPACKETSIZE in RAM\n\t// FIXME: shared buffers if several radios\n\tNRF_CCM->SCRATCHPTR = (uint32_t)_scratch;\n\n\t// SHORT from RADIO READY to AESCCM KSGEN using PPI predefined channel 24\n\t// Also RADIO ADDRESS to AESCCM CRYPT using PPI predefined channel 25\n\tNRF_PPI->CHENSET =   (PPI_CHENSET_CH24_Enabled << PPI_CHENSET_CH24_Pos) \n\t                   | (PPI_CHENSET_CH25_Enabled << PPI_CHENSET_CH25_Pos)\n\t    ;\n\n\t// SHORT from AESCCM ENDKSGEN to AESCCM CRYPT\n\tNRF_CCM->SHORTS = (CCM_SHORTS_ENDKSGEN_CRYPT_Enabled << CCM_SHORTS_ENDKSGEN_CRYPT_Pos);\n\n\t// Enable the CCM module\n\tNRF_CCM->ENABLE = (CCM_ENABLE_ENABLE_Enabled << CCM_ENABLE_ENABLE_Pos);\n\n\t_encrypting = true;\n    }\n    else\n    {\n\t// Disable the CCM module\n\tNRF_CCM->ENABLE = (CCM_ENABLE_ENABLE_Disabled << CCM_ENABLE_ENABLE_Pos);\n\t_encrypting = false;\n    }\n#endif\n}\n\nbool RH_NRF51::available()\n{\n    if (!_rxBufValid)\n    {\n\tif (_mode == RHModeTx)\n\t    return false;\n\tsetModeRx();\n\tif (!NRF_RADIO->EVENTS_END)\n\t    return false; // No message yet\n\tsetModeIdle();\n#if RH_NRF51_HAVE_ENCRYPTION\n\t// If encryption is enabled, the decrypted message is not available yet, and there seems\n\t// to be no way to be sure when its ready, but a delay of 2ms is enough\n\tif (_encrypting)\n\t    delay(2);\n#endif\n        if (!NRF_RADIO->CRCSTATUS)\n\t{\n\t    // Bad CRC, restart the radio\t    \n\t    _rxBad++;\n\t    setModeRx();\n\t    return false;\n\t}\n\tvalidateRxBuf(); \n\tif (!_rxBufValid)\n\t    setModeRx(); // Try for another\n    }\n    return _rxBufValid;\n}\n\nvoid RH_NRF51::clearRxBuf()\n{\n    _rxBufValid = false;\n    _buf[1] = 0;\n}\n\nbool RH_NRF51::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n    if (buf && len)\n    {\n\t// Skip the 4 headers that are at the beginning of the rxBuf\n\t// the payload length is the first octet in _buf\n\tif (*len > _buf[1]-RH_NRF51_HEADER_LEN)\n\t    *len = _buf[1]-RH_NRF51_HEADER_LEN;\n\tmemcpy(buf, _buf+RH_NRF51_HEADER_LEN, *len);\n    }\n    clearRxBuf(); // This message accepted and cleared\n    return true;\n}\n\nuint8_t RH_NRF51::maxMessageLength()\n{\n#if RH_NRF51_HAVE_ENCRYPTION\n    if (_encrypting)\n\treturn RH_NRF51_MAX_ENCRYPTED_MESSAGE_LEN;\n#endif\n    return RH_NRF51_MAX_MESSAGE_LEN;\n}\n\nfloat RH_NRF51::get_temperature()\n{\n    NRF_TEMP->EVENTS_DATARDY = 0;\n    NRF_TEMP->TASKS_START = 1;\n    \n    while (!NRF_TEMP->EVENTS_DATARDY)\n\t;\n    return NRF_TEMP->TEMP * 0.25;\n}\n\n#endif // NRF51\n"
  },
  {
    "path": "RH_NRF51.h",
    "content": "// RH_NRF51.h\n// Author: Mike McCauley\n// Copyright (C) 2015 Mike McCauley\n// $Id: RH_NRF51.h,v 1.4 2017/01/12 23:58:00 mikem Exp $\n//\n\n#ifndef RH_NRF51_h\n#define RH_NRF51_h\n\n#include <RHGenericDriver.h>\n\n// This is the maximum number of bytes that can be carried by the nRF51.\n// We use some for headers, keeping fewer for RadioHead messages\n#define RH_NRF51_MAX_PAYLOAD_LEN 254\n\n// The length of the headers we add.\n// The headers are inside the nRF51 payload\n// We add:\n// S0 (not used)\n// LEN\n// S1 (not used)\n// to\n// from\n// id\n// flags\n#define RH_NRF51_HEADER_LEN 7\n\n// This is the maximum RadioHead user message length that can be supported by this library. Limited by\n// the supported message lengths in the nRF51\n#define RH_NRF51_MAX_MESSAGE_LEN (RH_NRF51_MAX_PAYLOAD_LEN-RH_NRF51_HEADER_LEN)\n\n// Define to be 1 if you want to support AES CCA encryption using the built-in\n// encryption engine.\n#define RH_NRF51_HAVE_ENCRYPTION 1\n\n// When encryption is enabled, have a much shorter max message length\n#define RH_NRF51_MAX_ENCRYPTED_MESSAGE_LEN (27-4)\n\n// The required length of the AES encryption key\n#define RH_NRF51_ENCRYPTION_KEY_LENGTH 16\n\n// This is the size of the CCM data structure for AES encryption\n// REVISIT: use a struct?\n#define RH_NRF51_AES_CCM_CNF_SIZE 33\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_NRF51 RH_NRF51.h <RH_NRF51.h>\n/// \\brief Send and receive addressed datagrams by nRF51 and nRF52 compatible transceivers.\n///\n/// Supported transceivers include:\n/// - Nordic nRF51 based 2.4GHz radio modules, such as nRF51822 \n/// and other compatible chips, such as used in RedBearLabs devices like:\n/// http://store.redbearlab.com/products/redbearlab-nrf51822\n/// http://store.redbearlab.com/products/blenano\n/// and\n/// Sparkfun nRF52832 breakout board, with Arduino 1.6.13 and\n/// Sparkfun nRF52 boards manager 0.2.3\n///\n/// This base class provides basic functions for sending and receiving unaddressed, unreliable datagrams\n/// of arbitrary length to 254 octets per packet. Use one of the Manager classes to get addressing and \n/// acknowledgement reliability, routing, meshes etc.\n///\n/// The nRF51822 (https://www.nordicsemi.com/eng/Products/Bluetooth-Smart-Bluetooth-low-energy/nRF51822)\n/// and nRF52832 (https://learn.sparkfun.com/tutorials/nrf52832-breakout-board-hookup-guide)\n/// is a complete SoC (system on a chip) with ARM microprocessor and 2.4 GHz radio, which supports a range of channels \n/// and transmission bit rates. Chip antenna is on-board.\n///\n/// This library provides functions for sending and receiving messages of up to 254 octets on any \n/// frequency supported by the nRF51822/nRF52832, at a selected data rate.\n///\n/// The nRF51 transceiver is configured to use Enhanced Shockburst with no acknowledgement and no retransmits.\n/// TXADDRESS and RXADDRESSES:RXADDR0 (ie pipe 0) are the logical address used. The on-air network address\n/// is set in BASE0 and PREFIX0. SHORTS is used to automatically transition the radio between Ready, Start and Disable.\n/// No interrupts are used.\n///\n/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and \n/// data rate, and with identical network addresses.\n///\n/// Example programs are included to show the main modes of use.\n///\n/// \\par Packet Format\n///\n/// All messages sent and received by this class conform to this packet format. It is NOT compatible\n/// with the one used by RH_NRF24 and the nRF24L01 product specification, mainly because the nRF24 only supports\n/// 6 bits of message length.\n///\n/// - 1 octets PREAMBLE\n/// - 3 to 5 octets NETWORK ADDRESS\n/// - 1 octet S0 (not used, required if encryption used)\n/// - 8 bits PAYLOAD LENGTH\n/// - 1 octet S1 (not used, required if encryption used)\n/// - 0 to 251 octets PAYLOAD (possibly encrypted), consisting of:\n///   - 1 octet TO header\n///   - 1 octet FROM header\n///   - 1 octet ID header\n///   - 1 octet FLAGS header\n///   - 0 to 247 octets of user message\n/// - 2 octets CRC (Algorithm x^16+x^12^x^5+1 with initial value 0xFFFF).\n///\n/// \\par Example programs\n///\n/// Several example programs are provided.\n///\n/// The sample programs are designed to be built using Arduino 1.6.4 or later using the procedures outlined\n/// in http://redbearlab.com/getting-started-nrf51822/\n/// or with Sparkfun nRF52832 breakout board, with Arduino 1.6.13 and\n/// Sparkfun nRF52 boards manager 0.2.3 using the procedures outlined in\n/// https://learn.sparkfun.com/tutorials/nrf52832-breakout-board-hookup-guide\n///\n/// \\par Radio Performance\n///\n/// At DataRate2Mbps (2Mb/s), payload length vs airtime:\n/// 0 bytes takes about 70us, 128 bytes takes 520us, 254 bytes take 1020us.\n/// You can extrapolate linearly to slower data rates.\n///\n/// The RF powers claimed by the chip manufacturer have not been independently verified here.\n///\n/// \\par Memory\n///\n/// The compiled client and server sketches are about 42k bytes on Arduino. \n/// The reliable client and server sketches compile to about 43k bytes on Arduino. Unfortunately the \n/// Arduino build environmnet does not drop unused clsses and code, so the resulting programs include\n/// all the unused classes ad code. This needs to be revisited.\n/// RAM requirements are minimal.\n///\nclass RH_NRF51 : public RHGenericDriver\n{\npublic:\n\n    /// \\brief Defines convenient values for setting data rates in setRF()\n    typedef enum\n    {\n\tDataRate1Mbps = 0,   ///< 1 Mbps\n\tDataRate2Mbps,       ///< 2 Mbps\n\tDataRate250kbps      ///< 250 kbps\n    } DataRate;\n\n    /// \\brief Convenient values for setting transmitter power in setRF()\n    typedef enum\n    {\n\t// Add 20dBm for nRF24L01p with PA and LNA modules\n\tTransmitPower4dBm = 0,        ///<  4 dBm\n\tTransmitPower0dBm,            ///<  0 dBm\n\tTransmitPowerm4dBm,           ///< -4 dBm\n\tTransmitPowerm8dBm,           ///< -8 dBm\n\tTransmitPowerm12dBm,          ///< -12 dBm\n\tTransmitPowerm16dBm,          ///< -16 dBm\n\tTransmitPowerm20dBm,          ///< -20 dBm\n\tTransmitPowerm30dBm,          ///< -30 dBm\n    } TransmitPower;\n\n    /// Constructor.\n    /// After constructing, you must call init() to initialise the interface\n    /// and the radio module\n    RH_NRF51();\n  \n    /// Initialises this instance and the radio module connected to it.\n    /// The following steps are taken:\n    /// - Start the processors High Frequency clock  DC/DC converter and \n    /// - Disable and reset the radio\n    /// - Set the logical channel to 0 for transmit and receive (only pipe 0 is used)\n    /// - Configure the CRC (2 octets, algorithm x^16+x^12^x^5+1 with initial value 0xffff)\n    /// - Set the default network address of 0xE7E7E7E7E7\n    /// - Set channel to 2\n    /// - Set data rate to DataRate2Mbps\n    /// - Set TX power to TransmitPower0dBm\n    /// \\return  true if everything was successful\n    bool        init();\n\n    /// Sets the transmit and receive channel number.\n    /// The frequency used is (2400 + channel) MHz\n    /// \\return true on success\n    bool setChannel(uint8_t channel);\n\n    /// Sets the Network address.\n    /// Only nodes with the same network address can communicate with each other. You \n    /// can set different network addresses in different sets of nodes to isolate them from each other.\n    /// Internally, this sets the nRF51 BASE0 and PREFIX0 to be the given network address.\n    /// The first octet of the address is used for PREFIX0 and the rest is used for BASE0. BALEN is\n    /// set to the approprtae base length.\n    /// The default network address is 0xE7E7E7E7E7.\n    /// \\param[in] address The new network address. Must match the network address of any receiving node(s).\n    /// \\param[in] len Number of bytes of address to set (3 to 5).\n    /// \\return true on success, false if len is not in the range 3-5 inclusive.\n    bool setNetworkAddress(uint8_t* address, uint8_t len);\n\n    /// Sets the data rate and transmitter power to use.\n    /// \\param [in] data_rate The data rate to use for all packets transmitted and received. One of RH_NRF51::DataRate.\n    /// \\param [in] power Transmitter power. One of RH_NRF51::TransmitPower.\n    /// \\return true on success\n    bool setRF(DataRate data_rate, TransmitPower power);\n\n    /// Sets the radio in power down mode, with the configuration set to the\n    /// last value from setOpMode().\n    /// Sets chip enable to LOW.\n    void setModeIdle();\n\n    /// Sets the radio in RX mode.\n    void setModeRx();\n\n    /// Sets the radio in TX mode.\n    void setModeTx();\n\n    /// Sends data to the address set by setTransmitAddress()\n    /// Sets the radio to TX mode.\n    /// Caution: when encryption is enabled, the maximum message length is reduced to 23 octets.\n    /// \\param [in] data Data bytes to send.\n    /// \\param [in] len Number of data bytes to send\n    /// \\return true on success (which does not necessarily mean the receiver got the message, only that the message was\n    /// successfully transmitted). False if the message is too long or was otherwise not transmitted.\n    bool send(const uint8_t* data, uint8_t len);\n\n    /// Blocks until the current message (if any) \n    /// has been transmitted\n    /// \\return true on success, false if the chip is not in transmit mode or other transmit failure\n    virtual bool waitPacketSent();\n\n    /// Indicates if the chip is in transmit mode and \n    /// there is a packet currently being transmitted\n    /// \\return true if the chip is in transmit mode and there is a transmission in progress\n    bool isSending();\n\n    /// Prints the value of all NRF_RADIO registers.\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// For debugging purposes only.\n    /// Caution: there are 1024 of them (many reserved and set to 0).\n    /// \\return true on success\n    bool printRegisters();\n\n    /// Checks whether a received message is available.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a complete, valid message has been received and is able to be retrieved by\n    /// recv()\n    bool        available();\n\n    /// Turns the receiver on if it not already on.\n    /// Once a message with CRC correct is received, the receiver will be returned to Idle mode.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    bool        recv(uint8_t* buf, uint8_t* len);\n\n    /// Enables AES encryption and sets the AES encryption key, used\n    /// to encrypt and decrypt all messages using the on-chip AES CCM mode encryption engine. \n    /// The default is disabled.\n    /// In the AES configuration, the message counter and IV is always set to 0, which\n    /// means the same keystream is used for every message with a given key.\n    /// Caution: when encryption is enabled, the maximum message length is reduced to 23 octets.\n    /// \\param[in] key The key to use. Must be 16 bytes long. The same key must be installed\n    /// in other instances of RH_RF51, otherwise communications will not work correctly. If key is NULL,\n    /// encryption is disabled, which is the default.\n    void           setEncryptionKey(uint8_t* key = NULL);\n\n    /// The maximum message length supported by this driver\n    /// \\return The maximum message length supported by this driver\n    uint8_t maxMessageLength();\n\n    /// Reeads the current die temperature using the built in TEMP peripheral.\n    /// Blocks while the temperature is measured, which takes about 30 microseconds.\n    // \\return the current die temperature in degrees C.\n    float get_temperature();\n\nprotected:\n    /// Examine the receive buffer to determine whether the message is for this node\n    void validateRxBuf();\n\n    /// Clear our local receive buffer\n    void clearRxBuf();\n\nprivate:\n    /// The receiver/transmitter buffer\n    /// First octet is the payload length, remainder is the payload\n    uint8_t             _buf[RH_NRF51_MAX_PAYLOAD_LEN+1];\n\n    /// True when there is a valid message in the buffer\n    bool                _rxBufValid;\n\n#if RH_NRF51_HAVE_ENCRYPTION\n    /// True if an AES key has been specified and that we are therfore encrypting\n    /// and decrypting messages on the fly\n    bool                _encrypting;\n\n    /// Scratch area for AES encryption\n    uint8_t             _scratch[RH_NRF51_MAX_PAYLOAD_LEN+1+16];\n\n    /// Where the AES encryption key and IV are stored\n    uint8_t             _encryption_cnf[RH_NRF51_AES_CCM_CNF_SIZE];\n#endif\n};\n\n/// @example nrf51_client.pde\n/// @example nrf51_server.pde\n/// @example nrf51_reliable_datagram_client.pde\n/// @example nrf51_reliable_datagram_server.pde\n/// @example nrf51_audio_tx.pde\n/// @example nrf51_audio_rx.pde\n#endif \n"
  },
  {
    "path": "RH_NRF905.cpp",
    "content": "// RH_NRF905.cpp\n//\n// Copyright (C) 2012 Mike McCauley\n// $Id: RH_NRF905.cpp,v 1.7 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_NRF905.h>\n\nRH_NRF905::RH_NRF905(uint8_t chipEnablePin, uint8_t txEnablePin, uint8_t slaveSelectPin, RHGenericSPI& spi)\n    :\n    RHNRFSPIDriver(slaveSelectPin, spi)\n{\n    _chipEnablePin = chipEnablePin;\n    _txEnablePin   = txEnablePin;\n}\n\nbool RH_NRF905::init()\n{\n#if defined (__MK20DX128__) || defined (__MK20DX256__)\n    // Teensy is unreliable at 8MHz:\n    _spi.setFrequency(RHGenericSPI::Frequency1MHz);\n#else\n    _spi.setFrequency(RHGenericSPI::Frequency8MHz);\n#endif\n    if (!RHNRFSPIDriver::init())\n\treturn false;\n\n    // Initialise the slave select pin and the tx Enable pin\n    pinMode(_chipEnablePin, OUTPUT);\n    pinMode(_txEnablePin, OUTPUT);\n    digitalWrite(_chipEnablePin, LOW);\n    digitalWrite(_txEnablePin, LOW);\n\n    // Configure the chip\n    // CRC 16 bits enabled. 16MHz crystal freq\n    spiWriteRegister(RH_NRF905_CONFIG_9, RH_NRF905_CONFIG_9_CRC_EN | RH_NRF905_CONFIG_9_CRC_MODE_16BIT | RH_NRF905_CONFIG_9_XOF_16MHZ);\n\n    // Make sure we are powered down\n    setModeIdle();\n\n    // Some innocuous defaults\n    setChannel(108, LOW); // 433.2 MHz\n    setRF(RH_NRF905::TransmitPowerm10dBm);\n\n    return true;\n}\n\n// Use the register commands to read and write the registers\nuint8_t RH_NRF905::spiReadRegister(uint8_t reg)\n{\n    return spiRead((reg & RH_NRF905_REG_MASK) | RH_NRF905_REG_R_CONFIG);\n}\n\nuint8_t RH_NRF905::spiWriteRegister(uint8_t reg, uint8_t val)\n{\n    return spiWrite((reg & RH_NRF905_REG_MASK) | RH_NRF905_REG_W_CONFIG, val);\n}\n\nuint8_t RH_NRF905::spiBurstReadRegister(uint8_t reg, uint8_t* dest, uint8_t len)\n{\n    return spiBurstRead((reg & RH_NRF905_REG_MASK) | RH_NRF905_REG_R_CONFIG, dest, len);\n}\n\nuint8_t RH_NRF905::spiBurstWriteRegister(uint8_t reg, uint8_t* src, uint8_t len)\n{\n    return spiBurstWrite((reg & RH_NRF905_REG_MASK) | RH_NRF905_REG_W_CONFIG, src, len);\n}\n\nuint8_t RH_NRF905::statusRead()\n{\n    // The status is a byproduct of sending a command\n    return spiCommand(0);\n}\n\nbool RH_NRF905::setChannel(uint16_t channel, bool hiFrequency)\n{\n    spiWriteRegister(RH_NRF905_CONFIG_0, channel & RH_NRF905_CONFIG_0_CH_NO);\n    // Set or clear the high bit of the channel\n    uint8_t bit8 = (channel >> 8) & 0x01;\n    uint8_t reg1 = spiReadRegister(RH_NRF905_CONFIG_1);\n    reg1 = (reg1 & ~0x01) | bit8;\n    // Set or clear the HFREQ_PLL bit\n    reg1 &= ~RH_NRF905_CONFIG_1_HFREQ_PLL;\n    if (hiFrequency)\n\treg1 |= RH_NRF905_CONFIG_1_HFREQ_PLL;\n    spiWriteRegister(RH_NRF905_CONFIG_1, reg1);\n    return true;\n}\n\nbool RH_NRF905::setNetworkAddress(uint8_t* address, uint8_t len)\n{\n    if (len < 1 || len > 4)\n\treturn false;\n    // Set RX_AFW and TX_AFW\n    spiWriteRegister(RH_NRF905_CONFIG_2, len | (len << 4));\n    spiBurstWrite(RH_NRF905_REG_W_TX_ADDRESS, address, len);\n    spiBurstWriteRegister(RH_NRF905_CONFIG_5, address, len);\n    return true;\n}\n\nbool RH_NRF905::setRF(TransmitPower power)\n{\n    // Enum definitions of power are the same numerical values as the register\n    uint8_t reg1 = spiReadRegister(RH_NRF905_CONFIG_1);\n    reg1 &= ~RH_NRF905_CONFIG_1_PA_PWR;\n    reg1 |= ((power & 0x3) << 2) & RH_NRF905_CONFIG_1_PA_PWR;\n    spiWriteRegister(RH_NRF905_CONFIG_1, reg1);\n    return true;\n}\n\nvoid RH_NRF905::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\tdigitalWrite(_chipEnablePin, LOW);\n\tdigitalWrite(_txEnablePin, LOW);\n\t_mode = RHModeIdle;\n    }\n}\n\nvoid RH_NRF905::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\tdigitalWrite(_txEnablePin, LOW);\n\tdigitalWrite(_chipEnablePin, HIGH);\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_NRF905::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\t// Its the high transition that puts us into TX mode\n\tdigitalWrite(_txEnablePin, HIGH);\n\tdigitalWrite(_chipEnablePin, HIGH);\n\t_mode = RHModeTx;\n    }\n}\n\nbool RH_NRF905::send(const uint8_t* data, uint8_t len)\n{\n    if (len > RH_NRF905_MAX_MESSAGE_LEN)\n\treturn false;\n\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    // Set up the headers\n    _buf[0] = _txHeaderTo;\n    _buf[1] = _txHeaderFrom;\n    _buf[2] = _txHeaderId;\n    _buf[3] = _txHeaderFlags;\n    _buf[4] = len;\n    memcpy(_buf+RH_NRF905_HEADER_LEN, data, len);\n    spiBurstWrite(RH_NRF905_REG_W_TX_PAYLOAD, _buf, len + RH_NRF905_HEADER_LEN);\n    setModeTx();\n    // Radio will return to Standby mode after transmission is complete\n    _txGood++;\n    return true;\n}\n\nbool RH_NRF905::waitPacketSent()\n{\n    if (_mode != RHModeTx)\n\treturn false;\n\n    while (!(statusRead() & RH_NRF905_STATUS_DR))\n\tYIELD;\n    setModeIdle();\n    return true;\n}\n\nbool RH_NRF905::isSending()\n{\n    if (_mode != RHModeTx)\n\treturn false;\n    \n    return !(statusRead() & RH_NRF905_STATUS_DR);\n}\n\nbool RH_NRF905::printRegister(uint8_t reg)\n{\n#ifdef RH_HAVE_SERIAL\n    Serial.print(reg, HEX);\n    Serial.print(\": \");\n    Serial.println(spiReadRegister(reg), HEX);\n#endif\n\n    return true;\n}\n\nbool RH_NRF905::printRegisters()\n{\n    uint8_t registers[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};\n\n    uint8_t i;\n    for (i = 0; i < sizeof(registers); i++)\n\tprintRegister(registers[i]);\n    return true;\n}\n\n// Check whether the latest received message is complete and uncorrupted\nvoid RH_NRF905::validateRxBuf()\n{\n    // Check the length\n    uint8_t len = _buf[4];\n    if (len > RH_NRF905_MAX_MESSAGE_LEN)\n\treturn; // Silly LEN header\n\n    // Extract the 4 headers\n    _rxHeaderTo    = _buf[0];\n    _rxHeaderFrom  = _buf[1];\n    _rxHeaderId    = _buf[2];\n    _rxHeaderFlags = _buf[3];\n    if (_promiscuous ||\n\t_rxHeaderTo == _thisAddress ||\n\t_rxHeaderTo == RH_BROADCAST_ADDRESS)\n    {\n\t_rxGood++;\n\t_bufLen = len + RH_NRF905_HEADER_LEN; // _buf still includes the headers\n\t_rxBufValid = true;\n    }\n}\n\nbool RH_NRF905::available()\n{\n    if (!_rxBufValid)\n    {\n\tif (_mode == RHModeTx)\n\t    return false;\n\tsetModeRx();\n\tif (!(statusRead() & RH_NRF905_STATUS_DR))\n\t    return false;\n\t// Get the message into the RX buffer, so we can inspect the headers\n\t// we still dont know how long is the user message\n\tspiBurstRead(RH_NRF905_REG_R_RX_PAYLOAD, _buf, RH_NRF905_MAX_PAYLOAD_LEN);\n\tvalidateRxBuf(); \n\tif (_rxBufValid)\n\t    setModeIdle(); // Got one\n\n    }\n    return _rxBufValid;\n}\n\nvoid RH_NRF905::clearRxBuf()\n{\n    _rxBufValid = false;\n    _bufLen = 0;\n}\n\nbool RH_NRF905::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n    if (buf && len)\n    {\n\t// Skip the 4 headers that are at the beginning of the rxBuf\n\tif (*len > _bufLen-RH_NRF905_HEADER_LEN)\n\t    *len = _bufLen-RH_NRF905_HEADER_LEN;\n\tmemcpy(buf, _buf+RH_NRF905_HEADER_LEN, *len);\n    }\n    clearRxBuf(); // This message accepted and cleared\n    return true;\n}\n\nuint8_t RH_NRF905::maxMessageLength()\n{\n    return RH_NRF905_MAX_MESSAGE_LEN;\n}\n"
  },
  {
    "path": "RH_NRF905.h",
    "content": "// RH_NRF905.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_NRF905.h,v 1.10 2017/01/12 23:58:00 mikem Exp $\n//\n\n#ifndef RH_NRF905_h\n#define RH_NRF905_h\n\n#include <RHGenericSPI.h>\n#include <RHNRFSPIDriver.h>\n\n// This is the maximum (and only) number of bytes that can be carried by the nRF905.\n// We use some for headers, leaving fewer for RadioHead messages\n#define RH_NRF905_MAX_PAYLOAD_LEN 32\n\n// The length of the headers we add.\n// The headers are inside the nRF905 payload\n// As well as the usual TO, FROM, ID, FLAGS, we also need LEN, since\n// nRF905 only has fixed width messages.\n// REVISIT: could we have put the LEN into the FLAGS field?\n#define RH_NRF905_HEADER_LEN 5\n\n// This is the maximum RadioHead user message length that can be supported by this library. Limited by\n// the supported message lengths in the nRF905\n#define RH_NRF905_MAX_MESSAGE_LEN (RH_NRF905_MAX_PAYLOAD_LEN-RH_NRF905_HEADER_LEN)\n\n// Register names\n#define RH_NRF905_REG_MASK                   0x0f\n#define RH_NRF905_REG_W_CONFIG               0x00\n#define RH_NRF905_REG_R_CONFIG               0x10\n#define RH_NRF905_REG_W_TX_PAYLOAD           0x20\n#define RH_NRF905_REG_R_TX_PAYLOAD           0x21\n#define RH_NRF905_REG_W_TX_ADDRESS           0x22\n#define RH_NRF905_REG_R_TX_ADDRESS           0x23\n#define RH_NRF905_REG_R_RX_PAYLOAD           0x24\n#define RH_NRF905_REG_CHANNEL_CONFIG         0x80\n\n// Configuration register\n#define RH_NRF905_CONFIG_0                    0x00\n#define RH_NRF905_CONFIG_0_CH_NO              0xff\n\n#define RH_NRF905_CONFIG_1                    0x01\n#define RH_NRF905_CONFIG_1_AUTO_RETRAN        0x20\n#define RH_NRF905_CONFIG_1_RX_RED_PWR         0x10\n#define RH_NRF905_CONFIG_1_PA_PWR             0x0c\n#define RH_NRF905_CONFIG_1_PA_PWR_N10DBM      0x00\n#define RH_NRF905_CONFIG_1_PA_PWR_N2DBM       0x04\n#define RH_NRF905_CONFIG_1_PA_PWR_6DBM        0x08\n#define RH_NRF905_CONFIG_1_PA_PWR_10DBM       0x0c\n#define RH_NRF905_CONFIG_1_HFREQ_PLL          0x02\n#define RH_NRF905_CONFIG_1_CH_NO              0x01\n\n#define RH_NRF905_CONFIG_2                    0x02\n#define RH_NRF905_CONFIG_2_TX_AFW             0x70\n#define RH_NRF905_CONFIG_2_RX_AFW             0x07\n\n#define RH_NRF905_CONFIG_3                    0x03\n#define RH_NRF905_CONFIG_3_RX_PW              0x3f\n\n#define RH_NRF905_CONFIG_4                    0x04\n#define RH_NRF905_CONFIG_4_TX_PW              0x3f\n\n#define RH_NRF905_CONFIG_5                    0x05\n#define RH_NRF905_CONFIG_5_RX_ADDRESS         0xff\n\n#define RH_NRF905_CONFIG_6                    0x06\n#define RH_NRF905_CONFIG_6_RX_ADDRESS         0xff\n\n#define RH_NRF905_CONFIG_7                    0x07\n#define RH_NRF905_CONFIG_7_RX_ADDRESS         0xff\n\n#define RH_NRF905_CONFIG_8                    0x08\n#define RH_NRF905_CONFIG_8_RX_ADDRESS         0xff\n\n#define RH_NRF905_CONFIG_9                    0x09\n#define RH_NRF905_CONFIG_9_CRC_MODE_16BIT     0x80\n#define RH_NRF905_CONFIG_9_CRC_EN             0x40\n#define RH_NRF905_CONFIG_9_XOF                0x38\n#define RH_NRF905_CONFIG_9_XOF_4MHZ           0x00\n#define RH_NRF905_CONFIG_9_XOF_8MHZ           0x08\n#define RH_NRF905_CONFIG_9_XOF_12MHZ          0x10\n#define RH_NRF905_CONFIG_9_XOF_16MHZ          0x18\n#define RH_NRF905_CONFIG_9_XOF_20MHZ          0x20\n#define RH_NRF905_CONFIG_9_UP_CLK_EN          0x04\n#define RH_NRF905_CONFIG_9_UP_CLK_FREQ        0x03\n#define RH_NRF905_CONFIG_9_UP_CLK_FREQ_4MHZ   0x00\n#define RH_NRF905_CONFIG_9_UP_CLK_FREQ_2MHZ   0x01\n#define RH_NRF905_CONFIG_9_UP_CLK_FREQ_1MHZ   0x02\n#define RH_NRF905_CONFIG_9_UP_CLK_FREQ_500KHZ 0x03\n\n// Status register is always read as first byte\n#define RH_NRF905_STATUS_AM                   0x80\n#define RH_NRF905_STATUS_DR                   0x20\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_NRF905 RH_NRF905.h <RH_NRF905.h>\n/// \\brief Send and receive addressed, reliable, acknowledged datagrams by nRF905 and compatible transceivers.\n///\n/// This base class provides basic functions for sending and receiving unaddressed, unreliable datagrams\n/// of arbitrary length to 28 octets per packet. Use one of the Manager classes to get addressing and \n/// acknowledgement reliability, routing, meshes etc.\n///\n/// The nRF905 transceiver is configured to use Enhanced Shockburst with 16 Bit CRC, and 32 octet packets.\n///\n/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency\n/// and with identical network addresses.\n///\n/// The nRF905 from Nordic Semiconductor http://www.nordicsemi.com/eng/Products/Sub-1-GHz-RF/nRF905\n/// (http://www.nordicsemi.com/jpn/nordic/content_download/2452/29528/file/Product_Specification_nRF905_v1.5.pdf)\n/// is a low-cost 433/868/915 MHz ISM transceiver module. It supports a number of channel frequencies at\n/// 100kHz deviation and 50kHz bandwidth with Manchester encoding.\n///\n/// We tested with inexpensive nRF905 modules from eBay, similar to:\n/// http://www.aliexpress.com/store/product/Free-ship-NRF905-433MHz-Wireless-Transmission-Module-Transceiver-Module-with-Antenna-for-the-433MHz-ISM-band/513046_607163305.html\n///\n/// This library provides functions for sending and receiving messages of up to 27 octets on any \n/// frequency supported by the nRF905.\n///\n/// Several nRF905 modules can be connected to an Arduino, permitting the construction of translators\n/// and frequency changers, etc.\n///\n/// Example Arduino programs are included to show the main modes of use.\n///\n/// \\par Packet Format\n///\n/// All messages sent and received by this class conform to this fixed length packet format\n///\n/// - 4 octets NETWORK ADDRESS\n/// - 32 octets PAYLOAD, consisting of:\n///   - 1 octet TO header\n///   - 1 octet FROM header\n///   - 1 octet ID header\n///   - 1 octet FLAGS header\n///   - 1 octet user message length header\n///   - 0 to 27 octets of user message, trailing octets after the user message length are ignored\n/// - 2 octets CRC \n///\n/// All messages sent and received by this driver are 32 octets. The user message length is embedded in the message.\n///\n/// \\par Connecting nRF905\n///\n/// The nRF905 is a 3.3V part is is *NOT* 5V tolerant. So you MUST use a 3.3V CPU such as Teensy, Arduino Due etc\n/// or else provide for level shifters between the CPU and the nRF905. Failure to consider this will probably\n/// break your nRF905.\n///\n/// The electrical connection between the nRF905 and the CPU require 3.3V, the 3 x SPI pins (SCK, SDI, SDO), \n/// a Chip Enable pin, a Transmit Enable pin and a Slave Select pin.\n///\n/// The examples below assume the commonly found cheap Chinese nRF905 modules. The RH_RF905 driver assumes the \n/// the nRF905 has a 16MHz crystal.\n///\n/// Connect the nRF905 to Teensy (or Arduino with suitable level shifters) like this\n/// \\code\n///                 CPU          nRF905 module\n///                 3V3----------VCC   (3.3V)\n///             pin D8-----------CE    (chip enable in)\n///             pin D9-----------TX_EN (transmit enable in)\n///          SS pin D10----------CSN   (chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------MOSI  (SPI Data in)\n///        MISO pin D12----------MISO  (SPI data out)\n///                 GND----------GND   (ground in)\n/// \\endcode\n///\n/// Caution: Arduino Due is a 3.3V part and is not 5V tolerant (so too is the nRF905 module\n/// so they can be connected directly together. Unlike other Arduinos the Due has it default SPI \n/// connections on a dedicated 6 pin SPI header in the center of the board, which is \n/// physically compatible with Uno, Leonardo and Mega2560. A little dot marks pin 1 on the header.\n/// You must connect to these\n/// and *not* to the usual Arduino SPI pins Digital 11, 12 and 13.\n/// See http://21stdigitalhome.blogspot.com.au/2013/02/arduino-due-hardware-spi.html\n///\n/// Connect the nRF905 to Arduino Due like this\n/// \\code\n///                      CPU          nRF905 module\n///                      3V3----------VCC   (3.3V)\n///                  pin D8-----------CE    (chip enable in)\n///                  pin D9-----------TX_EN (transmit enable in)\n///               SS pin D10----------CSN   (chip select in)\n///  SCK on SPI header pin 3----------SCK   (SPI clock in)\n/// MOSI on SPI header pin 4----------MOSI  (SPI Data in)\n/// MISO on SPI header pin 1----------MISO  (SPI data out)\n///                      GND----------GND   (ground in)\n/// \\endcode\n///\n/// and you can then use the default constructor RH_NRF905(). \n/// You can override the default settings for the CE, TX_EN and CSN pins \n/// in the NRF905() constructor if you wish to connect the slave select CSN to other than the normal one for your \n/// CPU.\n///\n/// It is possible to have 2 radios conected to one CPU, provided each radio has its own \n/// CSN, TX_EN and CE line (SCK, MOSI and MISO are common to both radios)\n///\n/// \\par Transmitter Power\n///\n/// You can control the transmitter power to be one of 4 power levels: -10, -2, 6 or 10dBm,\n/// using the setRF() function, eg:\n/// \\code\n/// nrf905.setRF(RH_NRF905::TransmitPower10dBm);\n/// \\endcode\n///\n/// We have made some actual power measurements against\n/// programmed power for an nRF905 module from www.rfinchina.com under the following conditions:\n/// - Teensy 3.1\n/// - nRF905 module (with SMA antenna connector) wired to Teensy as described above, channel 108.\n/// - 20cm SMA-SMA cable\n/// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)\n/// - Tektronix TDS220 scope to measure the Vout from power head\n/// \\code\n/// Program power           Measured Power\n///    dBm                         dBm\n///    -10                        -16\n///    -2                         -8\n///    6                           0\n///    10                          8\n/// \\endcode\n/// (Caution: we dont claim laboratory accuracy for these measurements)\n/// You would not expect to get anywhere near these powers to air with a simple 1/4 wavelength wire antenna.\n///\n/// \\par Example programs\n///\n/// Several example programs are provided. They work out of the box with Teensy 3.1 and Arduino Due \n/// connected as show above.\n///\n/// \\par Radio Performance\n///\n/// Frequency accuracy may be debatable.\n/// \n/// \\par Memory\n///\n/// Memory usage of this class is minimal. The compiled client and server sketches are about 16000 bytes on Teensy. \n///\nclass RH_NRF905 : public RHNRFSPIDriver\n{\npublic:\n    /// \\brief Convenient values for setting transmitter power in setRF()\n    /// These are designed to agree with the values for RH_NRF905_CONFIG_1_PA_PWR after\n    /// left shifting by 2\n    /// To be passed to setRF();\n    typedef enum\n    {\n\tTransmitPowerm10dBm = 0,  ///< -10 dBm\n\tTransmitPowerm2dBm,       ///< -2 dBm\n\tTransmitPower6dBm,        ///< 6 dBm\n\tTransmitPower10dBm        ///< 10 dBm\n    } TransmitPower;\n\n    /// Constructor. You can have multiple instances, but each instance must have its own\n    /// chip enable and slave select pin. \n    /// After constructing, you must call init() to initialise the interface\n    /// and the radio module\n    /// \\param[in] chipEnablePin the Arduino pin to use to enable the chip for transmit/receive\n    /// \\param[in] txEnablePin the Arduino pin cponnected to the txEn pin on the radio that enable transmit mode\n    /// \\param[in] slaveSelectPin the Arduino pin number of the output to use to select the NRF905 before\n    /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, \n    /// D10 for Maple, Teensy)\n    /// \\param[in] spi Pointer to the SPI interface object to use. \n    ///                Defaults to the standard Arduino hardware SPI interface\n    RH_NRF905(uint8_t chipEnablePin = 8, uint8_t txEnablePin = 9, uint8_t slaveSelectPin = SS, RHGenericSPI& spi = hardware_spi);\n  \n    /// Initialises this instance and the radio module connected to it.\n    /// The following steps are taken:g\n    /// - Set the chip enable and chip select pins to output LOW, HIGH respectively.\n    /// - Initialise the SPI output pins\n    /// - Initialise the SPI interface library to 8MHz (Hint, if you want to lower\n    /// the SPI frequency (perhaps where you have other SPI shields, low voltages etc), \n    /// call SPI.setClockDivider() after init()).\n    /// -Flush the receiver and transmitter buffers\n    /// - Set the radio to receive with powerUpRx();\n    /// \\return  true if everything was successful\n    bool        init();\n\n    /// Reads a single register from the NRF905\n    /// \\param[in] reg Register number, one of NR905_REG_*\n    /// \\return The value of the register\n    uint8_t        spiReadRegister(uint8_t reg);\n\n    /// Writes a single byte to the NRF905, and at the ame time reads the current STATUS register\n    /// \\param[in] reg Register number, one of NRF905_REG_*\n    /// \\param[in] val The value to write\n    /// \\return the current STATUS (read while the command is sent)\n    uint8_t        spiWriteRegister(uint8_t reg, uint8_t val);\n\n    /// Reads a number of consecutive registers from the NRF905 using burst read mode\n    /// \\param[in] reg Register number of the first register, one of NRF905_REG_*\n    /// \\param[in] dest Array to write the register values to. Must be at least len bytes\n    /// \\param[in] len Number of bytes to read\n    /// \\return the current STATUS (read while the command is sent)\n    uint8_t           spiBurstReadRegister(uint8_t reg, uint8_t* dest, uint8_t len);\n\n    /// Write a number of consecutive registers using burst write mode\n    /// \\param[in] reg Register number of the first register, one of NRF905_REG_*\n    /// \\param[in] src Array of new register values to write. Must be at least len bytes\n    /// \\param[in] len Number of bytes to write\n    /// \\return the current STATUS (read while the command is sent)\n    uint8_t        spiBurstWriteRegister(uint8_t reg, uint8_t* src, uint8_t len);\n\n    /// Reads and returns the device status register NRF905_REG_02_DEVICE_STATUS\n    /// \\return The value of the device status register\n    uint8_t        statusRead();\n  \n    /// Sets the transmit and receive channel number.\n    /// The RF frequency used is (422.4 + channel/10) * (1+hiFrequency) MHz\n    /// \\param[in] channel The channel number. \n    /// \\param[in] hiFrequency false for low frequency band (422.4MHz and up), true for high frequency band (845MHz and up)\n    /// \\return true on success\n    bool setChannel(uint16_t channel, bool hiFrequency = false);\n\n    /// Sets the Network address.\n    /// Only nodes with the same network address can communicate with each other. You \n    /// can set different network addresses in different sets of nodes to isolate them from each other.\n    /// The default network address is 0xE7E7E7E7\n    /// \\param[in] address The new network address. Must match the network address of any receiving node(s).\n    /// \\param[in] len Number of bytes of address to set (1 to 4).\n    /// \\return true on success, false if len is not in the range 1-4 inclusive.\n    bool setNetworkAddress(uint8_t* address, uint8_t len);\n\n    /// Sets the transmitter power to use\n    /// \\param [in] power Transmitter power. One of NRF905::TransmitPower.\n    /// \\return true on success\n    bool setRF(TransmitPower power);\n\n    /// Sets the radio in power down mode.\n    /// Sets chip enable to LOW.\n    /// \\return true on success\n    void setModeIdle();\n\n    /// Sets the radio in RX mode.\n    /// Sets chip enable to HIGH to enable the chip in RX mode.\n    /// \\return true on success\n    void setModeRx();\n\n    /// Sets the radio in TX mode.\n    /// Pulses the chip enable LOW then HIGH to enable the chip in TX mode.\n    /// \\return true on success\n    void setModeTx();\n\n    /// Sends data to the address set by setTransmitAddress()\n    /// Sets the radio to TX mode\n    /// \\param [in] data Data bytes to send.\n    /// \\param [in] len Number of data bytes to set in the TX buffer. The actual size of the \n    /// transmitted data payload is set by setPayloadSize. Maximum message length actually \n    /// transmitted is RH_NRF905_MAX_MESSAGE_LEN = 27.\n    /// \\return true on success (which does not necessarily mean the receiver got the message, only that the message was\n    /// successfully transmitted). Returns false if the requested message length exceeds RH_NRF905_MAX_MESSAGE_LEN.\n    bool send(const uint8_t* data, uint8_t len);\n\n    /// Blocks until the current message (if any) \n    /// has been transmitted\n    /// \\return true on success, false if the chip is not in transmit mode\n    virtual bool waitPacketSent();\n\n    /// Indicates if the chip is in transmit mode and \n    /// there is a packet currently being transmitted\n    /// \\return true if the chip is in transmit mode and there is a transmission in progress\n    bool isSending();\n\n    /// Prints the value of a single chip register\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// For debugging purposes only.\n    /// \\return true on success\n    bool printRegister(uint8_t reg);\n\n    /// Prints the value of all chip registers\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// For debugging purposes only.\n    /// \\return true on success\n    bool printRegisters();\n\n    /// Checks whether a received message is available.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a complete, valid message has been received and is able to be retrieved by\n    /// recv()\n    bool available();\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    bool recv(uint8_t* buf, uint8_t* len);\n\n    /// The maximum message length supported by this driver\n    /// \\return The maximum message length supported by this driver\n    uint8_t maxMessageLength();\n\nprotected:\n    /// Examine the revceive buffer to determine whether the message is for this node\n    void validateRxBuf();\n\n    /// Clear our local receive buffer\n    void clearRxBuf();\n\nprivate:\n    /// This idle mode chip configuration\n    uint8_t             _configuration;\n\n    /// the number of the chip enable pin\n    uint8_t             _chipEnablePin;\n\n    /// The number of the transmit enable pin\n    uint8_t             _txEnablePin;\n\n    /// Number of octets in the buffer\n    uint8_t             _bufLen;\n    \n    /// The receiver/transmitter buffer\n    uint8_t             _buf[RH_NRF905_MAX_PAYLOAD_LEN];\n\n    /// True when there is a valid message in the buffer\n    bool                _rxBufValid;\n};\n\n/// @example nrf905_client.pde\n/// @example nrf905_server.pde\n/// @example nrf905_reliable_datagram_client.pde\n/// @example nrf905_reliable_datagram_server.pde\n\n#endif\n"
  },
  {
    "path": "RH_RF22.cpp",
    "content": "// RH_RF22.cpp\n//\n// Copyright (C) 2011 Mike McCauley\n// $Id: RH_RF22.cpp,v 1.27 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_RF22.h>\n\n// Interrupt vectors for the 2 Arduino interrupt pins\n// Each interrupt can be handled by a different instance of RH_RF22, allowing you to have\n// 2 RH_RF22s per Arduino\nRH_RF22* RH_RF22::_deviceForInterrupt[RH_RF22_NUM_INTERRUPTS] = {0, 0, 0};\nuint8_t RH_RF22::_interruptCount = 0; // Index into _deviceForInterrupt for next device\n\n// These are indexed by the values of ModemConfigChoice\n// Canned modem configurations generated with \n// http://www.hoperf.com/upload/rf/RH_RF22B%2023B%2031B%2042B%2043B%20Register%20Settings_RevB1-v5.xls\n// Stored in flash (program) memory to save SRAM\nPROGMEM static const RH_RF22::ModemConfig MODEM_CONFIG_TABLE[] =\n{\n    { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x00, 0x08 }, // Unmodulated carrier\n    { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x33, 0x08 }, // FSK, PN9 random modulation, 2, 5\n\n    // All the following enable FIFO with reg 71\n    //  1c,   1f,   20,   21,   22,   23,   24,   25,   2c,   2d,   2e,   58,   69,   6e,   6f,   70,   71,   72\n    // FSK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm\n    { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x22, 0x08 }, // 2, 5\n    { 0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x22, 0x3a }, // 2.4, 36\n    { 0x1d, 0x03, 0xa1, 0x20, 0x4e, 0xa5, 0x00, 0x13, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x22, 0x48 }, // 4.8, 45\n    { 0x1e, 0x03, 0xd0, 0x00, 0x9d, 0x49, 0x00, 0x45, 0x40, 0x0a, 0x20, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x22, 0x48 }, // 9.6, 45\n    { 0x2b, 0x03, 0x34, 0x02, 0x75, 0x25, 0x07, 0xff, 0x40, 0x0a, 0x1b, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x22, 0x0f }, // 19.2, 9.6\n    { 0x02, 0x03, 0x68, 0x01, 0x3a, 0x93, 0x04, 0xd5, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x22, 0x1f }, // 38.4, 19.6\n    { 0x06, 0x03, 0x45, 0x01, 0xd7, 0xdc, 0x07, 0x6e, 0x40, 0x0a, 0x2d, 0x80, 0x60, 0x0e, 0xbf, 0x0c, 0x22, 0x2e }, // 57.6. 28.8\n    { 0x8a, 0x03, 0x60, 0x01, 0x55, 0x55, 0x02, 0xad, 0x40, 0x0a, 0x50, 0x80, 0x60, 0x20, 0x00, 0x0c, 0x22, 0xc8 }, // 125, 125\n\n    { 0x2b, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x09, 0x40, 0x0a, 0x1d,  0x80, 0x60, 0x04, 0x32, 0x2c, 0x22, 0x04 }, // 512 baud, FSK, 2.5 Khz fd for POCSAG compatibility\n    { 0x27, 0x03, 0xa1, 0xe0, 0x10, 0xc7, 0x00, 0x06, 0x40, 0x0a, 0x1d,  0x80, 0x60, 0x04, 0x32, 0x2c, 0x22, 0x07 }, // 512 baud, FSK, 4.5 Khz fd for POCSAG compatibility\n\n    // GFSK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm\n    // These differ from FSK only in register 71, for the modulation type\n    { 0x2b, 0x03, 0xf4, 0x20, 0x41, 0x89, 0x00, 0x36, 0x40, 0x0a, 0x1d, 0x80, 0x60, 0x10, 0x62, 0x2c, 0x23, 0x08 }, // 2, 5\n    { 0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x23, 0x3a }, // 2.4, 36\n    { 0x1d, 0x03, 0xa1, 0x20, 0x4e, 0xa5, 0x00, 0x13, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x23, 0x48 }, // 4.8, 45\n    { 0x1e, 0x03, 0xd0, 0x00, 0x9d, 0x49, 0x00, 0x45, 0x40, 0x0a, 0x20, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x23, 0x48 }, // 9.6, 45\n    { 0x2b, 0x03, 0x34, 0x02, 0x75, 0x25, 0x07, 0xff, 0x40, 0x0a, 0x1b, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x23, 0x0f }, // 19.2, 9.6\n    { 0x02, 0x03, 0x68, 0x01, 0x3a, 0x93, 0x04, 0xd5, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x23, 0x1f }, // 38.4, 19.6\n    { 0x06, 0x03, 0x45, 0x01, 0xd7, 0xdc, 0x07, 0x6e, 0x40, 0x0a, 0x2d, 0x80, 0x60, 0x0e, 0xbf, 0x0c, 0x23, 0x2e }, // 57.6. 28.8\n    { 0x8a, 0x03, 0x60, 0x01, 0x55, 0x55, 0x02, 0xad, 0x40, 0x0a, 0x50, 0x80, 0x60, 0x20, 0x00, 0x0c, 0x23, 0xc8 }, // 125, 125\n\n    // OOK, No Manchester, Max Rb err <1%, Xtal Tol 20ppm\n    { 0x51, 0x03, 0x68, 0x00, 0x3a, 0x93, 0x01, 0x3d, 0x2c, 0x11, 0x28, 0x80, 0x60, 0x09, 0xd5, 0x2c, 0x21, 0x08 }, // 1.2, 75\n    { 0xc8, 0x03, 0x39, 0x20, 0x68, 0xdc, 0x00, 0x6b, 0x2a, 0x08, 0x2a, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x21, 0x08 }, // 2.4, 335\n    { 0xc8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x29, 0x04, 0x29, 0x80, 0x60, 0x27, 0x52, 0x2c, 0x21, 0x08 }, // 4.8, 335\n    { 0xb8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x82, 0x29, 0x80, 0x60, 0x4e, 0xa5, 0x2c, 0x21, 0x08 }, // 9.6, 335\n    { 0xa8, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x41, 0x29, 0x80, 0x60, 0x9d, 0x49, 0x2c, 0x21, 0x08 }, // 19.2, 335\n    { 0x98, 0x03, 0x9c, 0x00, 0xd1, 0xb7, 0x00, 0xd4, 0x28, 0x20, 0x29, 0x80, 0x60, 0x09, 0xd5, 0x0c, 0x21, 0x08 }, // 38.4, 335\n    { 0x98, 0x03, 0x96, 0x00, 0xda, 0x74, 0x00, 0xdc, 0x28, 0x1f, 0x29, 0x80, 0x60, 0x0a, 0x3d, 0x0c, 0x21, 0x08 }, // 40, 335\n};\n\nRH_RF22::RH_RF22(uint8_t slaveSelectPin, uint8_t interruptPin, RHGenericSPI& spi)\n    :\n    RHSPIDriver(slaveSelectPin, spi)\n{\n    _interruptPin = interruptPin;\n    _idleMode = RH_RF22_XTON; // Default idle state is READY mode\n    _polynomial = CRC_16_IBM; // Historical\n    _myInterruptIndex = 0xff; // Not allocated yet\n}\n\nvoid RH_RF22::setIdleMode(uint8_t idleMode)\n{\n    _idleMode = idleMode;\n}\n\nbool RH_RF22::init()\n{\n    if (!RHSPIDriver::init())\n\treturn false;\n\n    // Determine the interrupt number that corresponds to the interruptPin\n    int interruptNumber = digitalPinToInterrupt(_interruptPin);\n    if (interruptNumber == NOT_AN_INTERRUPT)\n\treturn false;\n#ifdef RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER\n    interruptNumber = _interruptPin;\n#endif\n\n    // Software reset the device\n    reset();\n\n    // Get the device type and check it\n    // This also tests whether we are really connected to a device\n    _deviceType = spiRead(RH_RF22_REG_00_DEVICE_TYPE);\n    if (   _deviceType != RH_RF22_DEVICE_TYPE_RX_TRX\n        && _deviceType != RH_RF22_DEVICE_TYPE_TX)\n    {\n\treturn false;\n    }\n\n    // Add by Adrien van den Bossche <vandenbo@univ-tlse2.fr> for Teensy\n    // ARM M4 requires the below. else pin interrupt doesn't work properly.\n    // On all other platforms, its innocuous, belt and braces\n    pinMode(_interruptPin, INPUT); \n\n    // Enable interrupt output on the radio. Interrupt line will now go high until\n    // an interrupt occurs\n    spiWrite(RH_RF22_REG_05_INTERRUPT_ENABLE1, RH_RF22_ENTXFFAEM | RH_RF22_ENRXFFAFULL | RH_RF22_ENPKSENT | RH_RF22_ENPKVALID | RH_RF22_ENCRCERROR | RH_RF22_ENFFERR);\n    spiWrite(RH_RF22_REG_06_INTERRUPT_ENABLE2, RH_RF22_ENPREAVAL);\n\n    // Set up interrupt handler\n    // Since there are a limited number of interrupt glue functions isr*() available,\n    // we can only support a limited number of devices simultaneously\n    // On some devices, notably most Arduinos, the interrupt pin passed in is actually the \n    // interrupt number. You have to figure out the interruptnumber-to-interruptpin mapping\n    // yourself based on knowledge of what Arduino board you are running on.\n    if (_myInterruptIndex == 0xff)\n    {\n\t// First run, no interrupt allocated yet\n\tif (_interruptCount <= RH_RF22_NUM_INTERRUPTS)\n\t    _myInterruptIndex = _interruptCount++;\n\telse\n\t    return false; // Too many devices, not enough interrupt vectors\n    }\n    _deviceForInterrupt[_myInterruptIndex] = this;\n    if (_myInterruptIndex == 0)\n\tattachInterrupt(interruptNumber, isr0, FALLING);\n    else if (_myInterruptIndex == 1)\n\tattachInterrupt(interruptNumber, isr1, FALLING);\n    else if (_myInterruptIndex == 2)\n\tattachInterrupt(interruptNumber, isr2, FALLING);\n    else\n\treturn false; // Too many devices, not enough interrupt vectors\n\n    setModeIdle();\n\n    clearTxBuf();\n    clearRxBuf();\n\n    // Most of these are the POR default\n    spiWrite(RH_RF22_REG_7D_TX_FIFO_CONTROL2, RH_RF22_TXFFAEM_THRESHOLD);\n    spiWrite(RH_RF22_REG_7E_RX_FIFO_CONTROL,  RH_RF22_RXFFAFULL_THRESHOLD);\n    spiWrite(RH_RF22_REG_30_DATA_ACCESS_CONTROL, RH_RF22_ENPACRX | RH_RF22_ENPACTX | RH_RF22_ENCRC | (_polynomial & RH_RF22_CRC));\n\n    // Configure the message headers\n    // Here we set up the standard packet format for use by the RH_RF22 library\n    // 8 nibbles preamble\n    // 2 SYNC words 2d, d4\n    // Header length 4 (to, from, id, flags)\n    // 1 octet of data length (0 to 255)\n    // 0 to 255 octets data\n    // 2 CRC octets as CRC16(IBM), computed on the header, length and data\n    // On reception the to address is check for validity against RH_RF22_REG_3F_CHECK_HEADER3\n    // or the broadcast address of 0xff\n    // If no changes are made after this, the transmitted\n    // to address will be 0xff, the from address will be 0xff\n    // and all such messages will be accepted. This permits the out-of the box\n    // RH_RF22 config to act as an unaddresed, unreliable datagram service\n    spiWrite(RH_RF22_REG_32_HEADER_CONTROL1, RH_RF22_BCEN_HEADER3 | RH_RF22_HDCH_HEADER3);\n    spiWrite(RH_RF22_REG_33_HEADER_CONTROL2, RH_RF22_HDLEN_4 | RH_RF22_SYNCLEN_2);\n\n    setPreambleLength(8);\n    uint8_t syncwords[] = { 0x2d, 0xd4 };\n    setSyncWords(syncwords, sizeof(syncwords));\n    setPromiscuous(false); \n\n    // Set some defaults. An innocuous ISM frequency, and reasonable pull-in\n    setFrequency(434.0, 0.05);\n//    setFrequency(900.0);\n    // Some slow, reliable default speed and modulation\n    setModemConfig(FSK_Rb2_4Fd36);\n//    setModemConfig(FSK_Rb125Fd125);\n    setGpioReversed(false);\n    // Lowish power\n    setTxPower(RH_RF22_TXPOW_8DBM);\n\n    return true;\n}\n\n// C++ level interrupt handler for this instance\nvoid RH_RF22::handleInterrupt()\n{\n    uint8_t _lastInterruptFlags[2];\n    // Read the interrupt flags which clears the interrupt\n    spiBurstRead(RH_RF22_REG_03_INTERRUPT_STATUS1, _lastInterruptFlags, 2);\n\n#if 0\n    // DEVELOPER TESTING ONLY\n    // Caution: Serial printing in this interrupt routine can cause mysterious crashes\n    Serial.print(\"interrupt \");\n    Serial.print(_lastInterruptFlags[0], HEX);\n    Serial.print(\" \");\n    Serial.println(_lastInterruptFlags[1], HEX);\n    if (_lastInterruptFlags[0] == 0 && _lastInterruptFlags[1] == 0)\n\tSerial.println(\"FUNNY: no interrupt!\");\n#endif\n\n#if 0\n    // DEVELOPER TESTING ONLY\n    // TESTING: fake an RH_RF22_IFFERROR\n    static int counter = 0;\n    if (_lastInterruptFlags[0] & RH_RF22_IPKSENT && counter++ == 10)\n    {\n\t_lastInterruptFlags[0] = RH_RF22_IFFERROR;\n\tcounter = 0;\n    }\n#endif\n\n    if (_lastInterruptFlags[0] & RH_RF22_IFFERROR)\n    {\n\tresetFifos(); // Clears the interrupt\n\tif (_mode == RHModeTx)\n\t    restartTransmit();\n\telse if (_mode == RHModeRx)\n\t    clearRxBuf();\n//\tSerial.println(\"IFFERROR\");  \n    }\n    // Caution, any delay here may cause a FF underflow or overflow\n    if (_lastInterruptFlags[0] & RH_RF22_ITXFFAEM)\n    {\n\t// See if more data has to be loaded into the Tx FIFO \n  \tsendNextFragment();\n//\tSerial.println(\"ITXFFAEM\");  \n    }\n    if (_lastInterruptFlags[0] & RH_RF22_IRXFFAFULL)\n    {\n\t// Caution, any delay here may cause a FF overflow\n\t// Read some data from the Rx FIFO\n\treadNextFragment();\n//\tSerial.println(\"IRXFFAFULL\"); \n    }\n    if (_lastInterruptFlags[0] & RH_RF22_IEXT)\n    {\n\t// This is not enabled by the base code, but users may want to enable it\n\thandleExternalInterrupt();\n//\tSerial.println(\"IEXT\"); \n    }\n    if (_lastInterruptFlags[1] & RH_RF22_IWUT)\n    {\n\t// This is not enabled by the base code, but users may want to enable it\n\thandleWakeupTimerInterrupt();\n//\tSerial.println(\"IWUT\"); \n    }\n    if (_lastInterruptFlags[0] & RH_RF22_IPKSENT)\n    {\n//\tSerial.println(\"IPKSENT\");   \n\t_txGood++; \n\t// Transmission does not automatically clear the tx buffer.\n\t// Could retransmit if we wanted\n\t// RH_RF22 transitions automatically to Idle\n\t_mode = RHModeIdle;\n    }\n    if (_lastInterruptFlags[0] & RH_RF22_IPKVALID)\n    {\n\tuint8_t len = spiRead(RH_RF22_REG_4B_RECEIVED_PACKET_LENGTH);\n//\tSerial.println(\"IPKVALID\");   \n\n\t// May have already read one or more fragments\n\t// Get any remaining unread octets, based on the expected length\n\t// First make sure we dont overflow the buffer in the case of a stupid length\n\t// or partial bad receives\n\tif (   len >  RH_RF22_MAX_MESSAGE_LEN\n\t    || len < _bufLen)\n\t{\n\t    _rxBad++;\n\t    _mode = RHModeIdle;\n\t    clearRxBuf();\n\t    return; // Hmmm receiver buffer overflow. \n\t}\n\n\tspiBurstRead(RH_RF22_REG_7F_FIFO_ACCESS, _buf + _bufLen, len - _bufLen);\n\t_rxHeaderTo = spiRead(RH_RF22_REG_47_RECEIVED_HEADER3);\n\t_rxHeaderFrom = spiRead(RH_RF22_REG_48_RECEIVED_HEADER2);\n\t_rxHeaderId = spiRead(RH_RF22_REG_49_RECEIVED_HEADER1);\n\t_rxHeaderFlags = spiRead(RH_RF22_REG_4A_RECEIVED_HEADER0);\n\t_rxGood++;\n\t_bufLen = len;\n\t_mode = RHModeIdle;\n\t_rxBufValid = true;\n    }\n    if (_lastInterruptFlags[0] & RH_RF22_ICRCERROR)\n    {\n//\tSerial.println(\"ICRCERR\");  \n\t_rxBad++;\n\tclearRxBuf();\n\tresetRxFifo();\n\t_mode = RHModeIdle;\n\tsetModeRx(); // Keep trying\n    }\n    if (_lastInterruptFlags[1] & RH_RF22_IPREAVAL)\n    {\n//\tSerial.println(\"IPREAVAL\");  \n\t_lastRssi = (int8_t)(-120 + ((spiRead(RH_RF22_REG_26_RSSI) / 2)));\n\t_lastPreambleTime = millis();\n\tresetRxFifo();\n\tclearRxBuf();\n    }\n}\n\n// These are low level functions that call the interrupt handler for the correct\n// instance of RH_RF22.\n// 3 interrupts allows us to have 3 different devices\nvoid RH_RF22::isr0()\n{\n    if (_deviceForInterrupt[0])\n\t_deviceForInterrupt[0]->handleInterrupt();\n}\nvoid RH_RF22::isr1()\n{\n    if (_deviceForInterrupt[1])\n\t_deviceForInterrupt[1]->handleInterrupt();\n}\nvoid RH_RF22::isr2()\n{\n    if (_deviceForInterrupt[2])\n\t_deviceForInterrupt[2]->handleInterrupt();\n}\n\nvoid RH_RF22::reset()\n{\n    spiWrite(RH_RF22_REG_07_OPERATING_MODE1, RH_RF22_SWRES);\n    // Wait for it to settle\n    delay(1); // SWReset time is nominally 100usec\n}\n\nuint8_t RH_RF22::statusRead()\n{\n    return spiRead(RH_RF22_REG_02_DEVICE_STATUS);\n}\n\nuint8_t RH_RF22::adcRead(uint8_t adcsel,\n                      uint8_t adcref ,\n                      uint8_t adcgain, \n                      uint8_t adcoffs)\n{\n    uint8_t configuration = adcsel | adcref | (adcgain & RH_RF22_ADCGAIN);\n    spiWrite(RH_RF22_REG_0F_ADC_CONFIGURATION, configuration | RH_RF22_ADCSTART);\n    spiWrite(RH_RF22_REG_10_ADC_SENSOR_AMP_OFFSET, adcoffs);\n\n    // Conversion time is nominally 305usec\n    // Wait for the DONE bit\n    while (!(spiRead(RH_RF22_REG_0F_ADC_CONFIGURATION) & RH_RF22_ADCDONE))\n\t;\n    // Return the value  \n    return spiRead(RH_RF22_REG_11_ADC_VALUE);\n}\n\nuint8_t RH_RF22::temperatureRead(uint8_t tsrange, uint8_t tvoffs)\n{\n    spiWrite(RH_RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION, tsrange | RH_RF22_ENTSOFFS);\n    spiWrite(RH_RF22_REG_13_TEMPERATURE_VALUE_OFFSET, tvoffs);\n    return adcRead(RH_RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR | RH_RF22_ADCREF_BANDGAP_VOLTAGE); \n}\n\nuint16_t RH_RF22::wutRead()\n{\n    uint8_t buf[2];\n    spiBurstRead(RH_RF22_REG_17_WAKEUP_TIMER_VALUE1, buf, 2);\n    return ((uint16_t)buf[0] << 8) | buf[1]; // Dont rely on byte order\n}\n\n// RFM-22 doc appears to be wrong: WUT for wtm = 10000, r, = 0, d = 0 is about 1 sec\nvoid RH_RF22::setWutPeriod(uint16_t wtm, uint8_t wtr, uint8_t wtd)\n{\n    uint8_t period[3];\n\n    period[0] = ((wtr & 0xf) << 2) | (wtd & 0x3);\n    period[1] = wtm >> 8;\n    period[2] = wtm & 0xff;\n    spiBurstWrite(RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1, period, sizeof(period));\n}\n\n// Returns true if centre + (fhch * fhs) is within limits\n// Caution, different versions of the RH_RF22 support different max freq\n// so YMMV\nbool RH_RF22::setFrequency(float centre, float afcPullInRange)\n{\n    uint8_t fbsel = RH_RF22_SBSEL;\n    uint8_t afclimiter;\n    if (centre < 240.0 || centre > 960.0) // 930.0 for early silicon\n\treturn false;\n    if (centre >= 480.0)\n    {\n\tif (afcPullInRange < 0.0 || afcPullInRange > 0.318750)\n\t    return false;\n\tcentre /= 2;\n\tfbsel |= RH_RF22_HBSEL;\n\tafclimiter = afcPullInRange * 1000000.0 / 1250.0;\n    }\n    else\n    {\n\tif (afcPullInRange < 0.0 || afcPullInRange > 0.159375)\n\t    return false;\n\tafclimiter = afcPullInRange * 1000000.0 / 625.0;\n    }\n    centre /= 10.0;\n    float integerPart = floor(centre);\n    float fractionalPart = centre - integerPart;\n\n    uint8_t fb = (uint8_t)integerPart - 24; // Range 0 to 23\n    fbsel |= fb;\n    uint16_t fc = fractionalPart * 64000;\n    spiWrite(RH_RF22_REG_73_FREQUENCY_OFFSET1, 0);  // REVISIT\n    spiWrite(RH_RF22_REG_74_FREQUENCY_OFFSET2, 0);\n    spiWrite(RH_RF22_REG_75_FREQUENCY_BAND_SELECT, fbsel);\n    spiWrite(RH_RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1, fc >> 8);\n    spiWrite(RH_RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0, fc & 0xff);\n    spiWrite(RH_RF22_REG_2A_AFC_LIMITER, afclimiter);\n    return !(statusRead() & RH_RF22_FREQERR);\n}\n\n// Step size in 10kHz increments\n// Returns true if centre + (fhch * fhs) is within limits\nbool RH_RF22::setFHStepSize(uint8_t fhs)\n{\n    spiWrite(RH_RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE, fhs);\n    return !(statusRead() & RH_RF22_FREQERR);\n}\n\n// Adds fhch * fhs to centre frequency\n// Returns true if centre + (fhch * fhs) is within limits\nbool RH_RF22::setFHChannel(uint8_t fhch)\n{\n    spiWrite(RH_RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT, fhch);\n    return !(statusRead() & RH_RF22_FREQERR);\n}\n\nuint8_t RH_RF22::rssiRead()\n{\n    return spiRead(RH_RF22_REG_26_RSSI);\n}\n\nuint8_t RH_RF22::ezmacStatusRead()\n{\n    return spiRead(RH_RF22_REG_31_EZMAC_STATUS);\n}\n\nvoid RH_RF22::setOpMode(uint8_t mode)\n{\n    spiWrite(RH_RF22_REG_07_OPERATING_MODE1, mode);\n}\n\nvoid RH_RF22::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\tsetOpMode(_idleMode);\n\t_mode = RHModeIdle;\n    }\n}\n\nbool RH_RF22::sleep()\n{\n    if (_mode != RHModeSleep)\n    {\n\tsetOpMode(0);\n\t_mode = RHModeSleep;\n    }\n    return true;\n}\n\nvoid RH_RF22::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\tsetOpMode(_idleMode | RH_RF22_RXON);\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_RF22::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\tsetOpMode(_idleMode | RH_RF22_TXON);\n\t// Hmmm, if you dont clear the RX FIFO here, then it appears that going\n\t// to transmit mode in the middle of a receive can corrupt the\n\t// RX FIFO\n\tresetRxFifo();\n\t_mode = RHModeTx;\n    }\n}\n\nvoid RH_RF22::setTxPower(uint8_t power)\n{\n    spiWrite(RH_RF22_REG_6D_TX_POWER, power | RH_RF22_LNA_SW); // On RF23, LNA_SW must be set.\n}\n\n// Sets registers from a canned modem configuration structure\nvoid RH_RF22::setModemRegisters(const ModemConfig* config)\n{\n    spiWrite(RH_RF22_REG_1C_IF_FILTER_BANDWIDTH,                    config->reg_1c);\n    spiWrite(RH_RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE,      config->reg_1f);\n    spiBurstWrite(RH_RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE, &config->reg_20, 6);\n    spiBurstWrite(RH_RF22_REG_2C_OOK_COUNTER_VALUE_1,              &config->reg_2c, 3);\n    spiWrite(RH_RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING,           config->reg_58);\n    spiWrite(RH_RF22_REG_69_AGC_OVERRIDE1,                          config->reg_69);\n    spiBurstWrite(RH_RF22_REG_6E_TX_DATA_RATE1,                    &config->reg_6e, 5);\n}\n\n// Set one of the canned FSK Modem configs\n// Returns true if its a valid choice\nbool RH_RF22::setModemConfig(ModemConfigChoice index)\n{\n    if (index > (signed int)(sizeof(MODEM_CONFIG_TABLE) / sizeof(ModemConfig)))\n        return false;\n\n    RH_RF22::ModemConfig cfg;\n    memcpy_P(&cfg, &MODEM_CONFIG_TABLE[index], sizeof(RH_RF22::ModemConfig));\n    setModemRegisters(&cfg);\n\n    return true;\n}\n\n// REVISIT: top bit is in Header Control 2 0x33\nvoid RH_RF22::setPreambleLength(uint8_t nibbles)\n{\n    spiWrite(RH_RF22_REG_34_PREAMBLE_LENGTH, nibbles);\n}\n\n// Caution doesnt set sync word len in Header Control 2 0x33\nvoid RH_RF22::setSyncWords(const uint8_t* syncWords, uint8_t len)\n{\n    spiBurstWrite(RH_RF22_REG_36_SYNC_WORD3, syncWords, len);\n}\n\nvoid RH_RF22::clearRxBuf()\n{\n    ATOMIC_BLOCK_START;\n    _bufLen = 0;\n    _rxBufValid = false;\n    ATOMIC_BLOCK_END;\n}\n\nbool RH_RF22::available()\n{\n    if (!_rxBufValid)\n    {\n\tif (_mode == RHModeTx)\n\t    return false;\n\tsetModeRx(); // Make sure we are receiving\n    }\n    return _rxBufValid;\n}\n\nbool RH_RF22::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n\n    if (buf && len)\n    {\n\tATOMIC_BLOCK_START;\n\tif (*len > _bufLen)\n\t    *len = _bufLen;\n\tmemcpy(buf, _buf, *len);\n\tATOMIC_BLOCK_END;\n    }\n    clearRxBuf();\n//    printBuffer(\"recv:\", buf, *len);\n    return true;\n}\n\nvoid RH_RF22::clearTxBuf()\n{\n    ATOMIC_BLOCK_START;\n    _bufLen = 0;\n    _txBufSentIndex = 0;\n    ATOMIC_BLOCK_END;\n}\n\nvoid RH_RF22::startTransmit()\n{\n    sendNextFragment(); // Actually the first fragment\n    spiWrite(RH_RF22_REG_3E_PACKET_LENGTH, _bufLen); // Total length that will be sent\n    setModeTx(); // Start the transmitter, turns off the receiver\n}\n\n// Restart the transmission of a packet that had a problem\nvoid RH_RF22::restartTransmit()\n{\n    _mode = RHModeIdle;\n    _txBufSentIndex = 0;\n//\t    Serial.println(\"Restart\");\n    startTransmit();\n}\n\nbool RH_RF22::send(const uint8_t* data, uint8_t len)\n{\n    bool ret = true;\n    waitPacketSent();\n\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    ATOMIC_BLOCK_START;\n    spiWrite(RH_RF22_REG_3A_TRANSMIT_HEADER3, _txHeaderTo);\n    spiWrite(RH_RF22_REG_3B_TRANSMIT_HEADER2, _txHeaderFrom);\n    spiWrite(RH_RF22_REG_3C_TRANSMIT_HEADER1, _txHeaderId);\n    spiWrite(RH_RF22_REG_3D_TRANSMIT_HEADER0, _txHeaderFlags);\n    if (!fillTxBuf(data, len))\n\tret = false;\n    else\n\tstartTransmit();\n    ATOMIC_BLOCK_END;\n//    printBuffer(\"send:\", data, len);\n    return ret;\n}\n\nbool RH_RF22::fillTxBuf(const uint8_t* data, uint8_t len)\n{\n    clearTxBuf();\n    if (!len)\n\treturn false; \n    return appendTxBuf(data, len);\n}\n\nbool RH_RF22::appendTxBuf(const uint8_t* data, uint8_t len)\n{\n    if (((uint16_t)_bufLen + len) > RH_RF22_MAX_MESSAGE_LEN)\n\treturn false;\n    ATOMIC_BLOCK_START;\n    memcpy(_buf + _bufLen, data, len);\n    _bufLen += len;\n    ATOMIC_BLOCK_END;\n//    printBuffer(\"txbuf:\", _buf, _bufLen);\n    return true;\n}\n\n// Assumption: there is currently <= RH_RF22_TXFFAEM_THRESHOLD bytes in the Tx FIFO\nvoid RH_RF22::sendNextFragment()\n{\n    if (_txBufSentIndex < _bufLen)\n    {\n\t// Some left to send?\n\tuint8_t len = _bufLen - _txBufSentIndex;\n\t// But dont send too much\n\tif (len > (RH_RF22_FIFO_SIZE - RH_RF22_TXFFAEM_THRESHOLD - 1))\n\t    len = (RH_RF22_FIFO_SIZE - RH_RF22_TXFFAEM_THRESHOLD - 1);\n\tspiBurstWrite(RH_RF22_REG_7F_FIFO_ACCESS, _buf + _txBufSentIndex, len);\n//\tprintBuffer(\"frag:\", _buf  + _txBufSentIndex, len);\n\t_txBufSentIndex += len;\n    }\n}\n\n// Assumption: there are at least RH_RF22_RXFFAFULL_THRESHOLD in the RX FIFO\n// That means it should only be called after a RXFFAFULL interrupt\nvoid RH_RF22::readNextFragment()\n{\n    if (((uint16_t)_bufLen + RH_RF22_RXFFAFULL_THRESHOLD) > RH_RF22_MAX_MESSAGE_LEN)\n\treturn; // Hmmm receiver overflow. Should never occur\n\n    // Read the RH_RF22_RXFFAFULL_THRESHOLD octets that should be there\n    spiBurstRead(RH_RF22_REG_7F_FIFO_ACCESS, _buf + _bufLen, RH_RF22_RXFFAFULL_THRESHOLD);\n    _bufLen += RH_RF22_RXFFAFULL_THRESHOLD;\n}\n\n// Clear the FIFOs\nvoid RH_RF22::resetFifos()\n{\n    spiWrite(RH_RF22_REG_08_OPERATING_MODE2, RH_RF22_FFCLRRX | RH_RF22_FFCLRTX);\n    spiWrite(RH_RF22_REG_08_OPERATING_MODE2, 0);\n}\n\n// Clear the Rx FIFO\nvoid RH_RF22::resetRxFifo()\n{\n    spiWrite(RH_RF22_REG_08_OPERATING_MODE2, RH_RF22_FFCLRRX);\n    spiWrite(RH_RF22_REG_08_OPERATING_MODE2, 0);\n    _rxBufValid = false;\n}\n\n// CLear the TX FIFO\nvoid RH_RF22::resetTxFifo()\n{\n    spiWrite(RH_RF22_REG_08_OPERATING_MODE2, RH_RF22_FFCLRTX);\n    spiWrite(RH_RF22_REG_08_OPERATING_MODE2, 0);\n}\n\n// Default implmentation does nothing. Override if you wish\nvoid RH_RF22::handleExternalInterrupt()\n{\n}\n\n// Default implmentation does nothing. Override if you wish\nvoid RH_RF22::handleWakeupTimerInterrupt()\n{\n}\n\nvoid RH_RF22::setPromiscuous(bool promiscuous)\n{\n    RHSPIDriver::setPromiscuous(promiscuous);\n    spiWrite(RH_RF22_REG_43_HEADER_ENABLE3, promiscuous ? 0x00 : 0xff);\n}\n\nbool RH_RF22::setCRCPolynomial(CRCPolynomial polynomial)\n{\n    if (polynomial >= CRC_CCITT &&\n\tpolynomial <= CRC_Biacheva)\n    {\n\t_polynomial = polynomial;\n\treturn true;\n    }\n    else\n\treturn false;\n}\n\nuint8_t RH_RF22::maxMessageLength()\n{\n    return RH_RF22_MAX_MESSAGE_LEN;\n}\n\nvoid RH_RF22::setThisAddress(uint8_t thisAddress)\n{\n    RHSPIDriver::setThisAddress(thisAddress);\n    spiWrite(RH_RF22_REG_3F_CHECK_HEADER3, thisAddress);\n}\n\nuint32_t RH_RF22::getLastPreambleTime()\n{\n    return _lastPreambleTime;\n}\n\nvoid RH_RF22::setGpioReversed(bool gpioReversed)\n{\n    // Ensure the antenna can be switched automatically according to transmit and receive\n    // This assumes GPIO0(out) is connected to TX_ANT(in) to enable tx antenna during transmit\n    // This assumes GPIO1(out) is connected to RX_ANT(in) to enable rx antenna during receive\n    if (gpioReversed)\n    {\n\t// Reversed for HAB-RFM22B-BOA HAB-RFM22B-BO, also Si4432 sold by Dorji.com via Tindie.com.\n\tspiWrite(RH_RF22_REG_0B_GPIO_CONFIGURATION0, 0x15) ; // RX state\n\tspiWrite(RH_RF22_REG_0C_GPIO_CONFIGURATION1, 0x12) ; // TX state\n    }\n    else\n    {\n\tspiWrite(RH_RF22_REG_0B_GPIO_CONFIGURATION0, 0x12) ; // TX state\n\tspiWrite(RH_RF22_REG_0C_GPIO_CONFIGURATION1, 0x15) ; // RX state\n    }\n}\n\n"
  },
  {
    "path": "RH_RF22.h",
    "content": "// RH_RF22.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2011 Mike McCauley\n// $Id: RH_RF22.h,v 1.31 2016/08/17 01:53:21 mikem Exp $\n//\n\n#ifndef RH_RF22_h\n#define RH_RF22_h\n\n#include <RHGenericSPI.h>\n#include <RHSPIDriver.h>\n\n// This is the maximum number of interrupts the library can support\n// Most Arduinos can handle 2, Megas can handle more\n#define RH_RF22_NUM_INTERRUPTS 3\n\n// This is the bit in the SPI address that marks it as a write\n#define RH_RF22_SPI_WRITE_MASK 0x80\n\n// This is the maximum message length that can be supported by this library. Limited by\n// the single message length octet in the header. \n// Yes, 255 is correct even though the FIFO size in the RF22 is only\n// 64 octets. We use interrupts to refill the Tx FIFO during transmission and to empty the\n// Rx FIFO during reception\n// Can be pre-defined to a smaller size (to save SRAM) prior to including this header\n#ifndef RH_RF22_MAX_MESSAGE_LEN\n//#define RH_RF22_MAX_MESSAGE_LEN 255\n#define RH_RF22_MAX_MESSAGE_LEN 50\n#endif\n\n// Max number of octets the RF22 Rx and Tx FIFOs can hold\n#define RH_RF22_FIFO_SIZE 64\n\n// These values we set for FIFO thresholds (4, 55) are actually the same as the POR values\n#define RH_RF22_TXFFAEM_THRESHOLD 4\n#define RH_RF22_RXFFAFULL_THRESHOLD 55\n\n// Number of registers to be passed to setModemConfig(). Obsolete.\n#define RH_RF22_NUM_MODEM_CONFIG_REGS 18\n\n// Register names\n#define RH_RF22_REG_00_DEVICE_TYPE                         0x00\n#define RH_RF22_REG_01_VERSION_CODE                        0x01\n#define RH_RF22_REG_02_DEVICE_STATUS                       0x02\n#define RH_RF22_REG_03_INTERRUPT_STATUS1                   0x03\n#define RH_RF22_REG_04_INTERRUPT_STATUS2                   0x04\n#define RH_RF22_REG_05_INTERRUPT_ENABLE1                   0x05\n#define RH_RF22_REG_06_INTERRUPT_ENABLE2                   0x06\n#define RH_RF22_REG_07_OPERATING_MODE1                     0x07\n#define RH_RF22_REG_08_OPERATING_MODE2                     0x08\n#define RH_RF22_REG_09_OSCILLATOR_LOAD_CAPACITANCE         0x09\n#define RH_RF22_REG_0A_UC_OUTPUT_CLOCK                     0x0a\n#define RH_RF22_REG_0B_GPIO_CONFIGURATION0                 0x0b\n#define RH_RF22_REG_0C_GPIO_CONFIGURATION1                 0x0c\n#define RH_RF22_REG_0D_GPIO_CONFIGURATION2                 0x0d\n#define RH_RF22_REG_0E_IO_PORT_CONFIGURATION               0x0e\n#define RH_RF22_REG_0F_ADC_CONFIGURATION                   0x0f\n#define RH_RF22_REG_10_ADC_SENSOR_AMP_OFFSET               0x10\n#define RH_RF22_REG_11_ADC_VALUE                           0x11\n#define RH_RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION      0x12\n#define RH_RF22_REG_13_TEMPERATURE_VALUE_OFFSET            0x13\n#define RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1                0x14\n#define RH_RF22_REG_15_WAKEUP_TIMER_PERIOD2                0x15\n#define RH_RF22_REG_16_WAKEUP_TIMER_PERIOD3                0x16\n#define RH_RF22_REG_17_WAKEUP_TIMER_VALUE1                 0x17\n#define RH_RF22_REG_18_WAKEUP_TIMER_VALUE2                 0x18\n#define RH_RF22_REG_19_LDC_MODE_DURATION                   0x19\n#define RH_RF22_REG_1A_LOW_BATTERY_DETECTOR_THRESHOLD      0x1a\n#define RH_RF22_REG_1B_BATTERY_VOLTAGE_LEVEL               0x1b\n#define RH_RF22_REG_1C_IF_FILTER_BANDWIDTH                 0x1c\n#define RH_RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE         0x1d\n#define RH_RF22_REG_1E_AFC_TIMING_CONTROL                  0x1e\n#define RH_RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE   0x1f\n#define RH_RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE    0x20\n#define RH_RF22_REG_21_CLOCK_RECOVERY_OFFSET2              0x21\n#define RH_RF22_REG_22_CLOCK_RECOVERY_OFFSET1              0x22\n#define RH_RF22_REG_23_CLOCK_RECOVERY_OFFSET0              0x23\n#define RH_RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1    0x24\n#define RH_RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0    0x25\n#define RH_RF22_REG_26_RSSI                                0x26\n#define RH_RF22_REG_27_RSSI_THRESHOLD                      0x27\n#define RH_RF22_REG_28_ANTENNA_DIVERSITY1                  0x28\n#define RH_RF22_REG_29_ANTENNA_DIVERSITY2                  0x29\n#define RH_RF22_REG_2A_AFC_LIMITER                         0x2a\n#define RH_RF22_REG_2B_AFC_CORRECTION_READ                 0x2b\n#define RH_RF22_REG_2C_OOK_COUNTER_VALUE_1                 0x2c\n#define RH_RF22_REG_2D_OOK_COUNTER_VALUE_2                 0x2d\n#define RH_RF22_REG_2E_SLICER_PEAK_HOLD                    0x2e\n#define RH_RF22_REG_30_DATA_ACCESS_CONTROL                 0x30\n#define RH_RF22_REG_31_EZMAC_STATUS                        0x31\n#define RH_RF22_REG_32_HEADER_CONTROL1                     0x32\n#define RH_RF22_REG_33_HEADER_CONTROL2                     0x33\n#define RH_RF22_REG_34_PREAMBLE_LENGTH                     0x34\n#define RH_RF22_REG_35_PREAMBLE_DETECTION_CONTROL1         0x35\n#define RH_RF22_REG_36_SYNC_WORD3                          0x36\n#define RH_RF22_REG_37_SYNC_WORD2                          0x37\n#define RH_RF22_REG_38_SYNC_WORD1                          0x38\n#define RH_RF22_REG_39_SYNC_WORD0                          0x39\n#define RH_RF22_REG_3A_TRANSMIT_HEADER3                    0x3a\n#define RH_RF22_REG_3B_TRANSMIT_HEADER2                    0x3b\n#define RH_RF22_REG_3C_TRANSMIT_HEADER1                    0x3c\n#define RH_RF22_REG_3D_TRANSMIT_HEADER0                    0x3d\n#define RH_RF22_REG_3E_PACKET_LENGTH                       0x3e\n#define RH_RF22_REG_3F_CHECK_HEADER3                       0x3f\n#define RH_RF22_REG_40_CHECK_HEADER2                       0x40\n#define RH_RF22_REG_41_CHECK_HEADER1                       0x41\n#define RH_RF22_REG_42_CHECK_HEADER0                       0x42\n#define RH_RF22_REG_43_HEADER_ENABLE3                      0x43\n#define RH_RF22_REG_44_HEADER_ENABLE2                      0x44\n#define RH_RF22_REG_45_HEADER_ENABLE1                      0x45\n#define RH_RF22_REG_46_HEADER_ENABLE0                      0x46\n#define RH_RF22_REG_47_RECEIVED_HEADER3                    0x47\n#define RH_RF22_REG_48_RECEIVED_HEADER2                    0x48\n#define RH_RF22_REG_49_RECEIVED_HEADER1                    0x49\n#define RH_RF22_REG_4A_RECEIVED_HEADER0                    0x4a\n#define RH_RF22_REG_4B_RECEIVED_PACKET_LENGTH              0x4b\n#define RH_RF22_REG_50_ANALOG_TEST_BUS_SELECT              0x50\n#define RH_RF22_REG_51_DIGITAL_TEST_BUS_SELECT             0x51\n#define RH_RF22_REG_52_TX_RAMP_CONTROL                     0x52\n#define RH_RF22_REG_53_PLL_TUNE_TIME                       0x53\n#define RH_RF22_REG_55_CALIBRATION_CONTROL                 0x55\n#define RH_RF22_REG_56_MODEM_TEST                          0x56\n#define RH_RF22_REG_57_CHARGE_PUMP_TEST                    0x57\n#define RH_RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING        0x58\n#define RH_RF22_REG_59_DIVIDER_CURRENT_TRIMMING            0x59\n#define RH_RF22_REG_5A_VCO_CURRENT_TRIMMING                0x5a\n#define RH_RF22_REG_5B_VCO_CALIBRATION                     0x5b\n#define RH_RF22_REG_5C_SYNTHESIZER_TEST                    0x5c\n#define RH_RF22_REG_5D_BLOCK_ENABLE_OVERRIDE1              0x5d\n#define RH_RF22_REG_5E_BLOCK_ENABLE_OVERRIDE2              0x5e\n#define RH_RF22_REG_5F_BLOCK_ENABLE_OVERRIDE3              0x5f\n#define RH_RF22_REG_60_CHANNEL_FILTER_COEFFICIENT_ADDRESS  0x60\n#define RH_RF22_REG_61_CHANNEL_FILTER_COEFFICIENT_VALUE    0x61\n#define RH_RF22_REG_62_CRYSTAL_OSCILLATOR_POR_CONTROL      0x62\n#define RH_RF22_REG_63_RC_OSCILLATOR_COARSE_CALIBRATION    0x63\n#define RH_RF22_REG_64_RC_OSCILLATOR_FINE_CALIBRATION      0x64\n#define RH_RF22_REG_65_LDO_CONTROL_OVERRIDE                0x65\n#define RH_RF22_REG_66_LDO_LEVEL_SETTINGS                  0x66\n#define RH_RF22_REG_67_DELTA_SIGMA_ADC_TUNING1             0x67\n#define RH_RF22_REG_68_DELTA_SIGMA_ADC_TUNING2             0x68\n#define RH_RF22_REG_69_AGC_OVERRIDE1                       0x69\n#define RH_RF22_REG_6A_AGC_OVERRIDE2                       0x6a\n#define RH_RF22_REG_6B_GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6b\n#define RH_RF22_REG_6C_GFSK_FIR_FILTER_COEFFICIENT_VALUE   0x6c\n#define RH_RF22_REG_6D_TX_POWER                            0x6d\n#define RH_RF22_REG_6E_TX_DATA_RATE1                       0x6e\n#define RH_RF22_REG_6F_TX_DATA_RATE0                       0x6f\n#define RH_RF22_REG_70_MODULATION_CONTROL1                 0x70\n#define RH_RF22_REG_71_MODULATION_CONTROL2                 0x71\n#define RH_RF22_REG_72_FREQUENCY_DEVIATION                 0x72\n#define RH_RF22_REG_73_FREQUENCY_OFFSET1                   0x73\n#define RH_RF22_REG_74_FREQUENCY_OFFSET2                   0x74\n#define RH_RF22_REG_75_FREQUENCY_BAND_SELECT               0x75\n#define RH_RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1          0x76\n#define RH_RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0          0x77\n#define RH_RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT    0x79\n#define RH_RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE         0x7a\n#define RH_RF22_REG_7C_TX_FIFO_CONTROL1                    0x7c\n#define RH_RF22_REG_7D_TX_FIFO_CONTROL2                    0x7d\n#define RH_RF22_REG_7E_RX_FIFO_CONTROL                     0x7e\n#define RH_RF22_REG_7F_FIFO_ACCESS                         0x7f\n\n// These register masks etc are named wherever possible\n// corresponding to the bit and field names in the RF-22 Manual\n// RH_RF22_REG_00_DEVICE_TYPE                      0x00\n#define RH_RF22_DEVICE_TYPE_RX_TRX                 0x08\n#define RH_RF22_DEVICE_TYPE_TX                     0x07\n\n// RH_RF22_REG_02_DEVICE_STATUS                    0x02\n#define RH_RF22_FFOVL                              0x80\n#define RH_RF22_FFUNFL                             0x40\n#define RH_RF22_RXFFEM                             0x20\n#define RH_RF22_HEADERR                            0x10\n#define RH_RF22_FREQERR                            0x08\n#define RH_RF22_LOCKDET                            0x04\n#define RH_RF22_CPS                                0x03\n#define RH_RF22_CPS_IDLE                           0x00\n#define RH_RF22_CPS_RX                             0x01\n#define RH_RF22_CPS_TX                             0x10\n\n// RH_RF22_REG_03_INTERRUPT_STATUS1                0x03\n#define RH_RF22_IFFERROR                           0x80\n#define RH_RF22_ITXFFAFULL                         0x40\n#define RH_RF22_ITXFFAEM                           0x20\n#define RH_RF22_IRXFFAFULL                         0x10\n#define RH_RF22_IEXT                               0x08\n#define RH_RF22_IPKSENT                            0x04\n#define RH_RF22_IPKVALID                           0x02\n#define RH_RF22_ICRCERROR                          0x01\n\n// RH_RF22_REG_04_INTERRUPT_STATUS2                0x04\n#define RH_RF22_ISWDET                             0x80\n#define RH_RF22_IPREAVAL                           0x40\n#define RH_RF22_IPREAINVAL                         0x20\n#define RH_RF22_IRSSI                              0x10\n#define RH_RF22_IWUT                               0x08\n#define RH_RF22_ILBD                               0x04\n#define RH_RF22_ICHIPRDY                           0x02\n#define RH_RF22_IPOR                               0x01\n\n// RH_RF22_REG_05_INTERRUPT_ENABLE1                0x05\n#define RH_RF22_ENFFERR                            0x80\n#define RH_RF22_ENTXFFAFULL                        0x40\n#define RH_RF22_ENTXFFAEM                          0x20\n#define RH_RF22_ENRXFFAFULL                        0x10\n#define RH_RF22_ENEXT                              0x08\n#define RH_RF22_ENPKSENT                           0x04\n#define RH_RF22_ENPKVALID                          0x02\n#define RH_RF22_ENCRCERROR                         0x01\n\n// RH_RF22_REG_06_INTERRUPT_ENABLE2                0x06\n#define RH_RF22_ENSWDET                            0x80\n#define RH_RF22_ENPREAVAL                          0x40\n#define RH_RF22_ENPREAINVAL                        0x20\n#define RH_RF22_ENRSSI                             0x10\n#define RH_RF22_ENWUT                              0x08\n#define RH_RF22_ENLBDI                             0x04\n#define RH_RF22_ENCHIPRDY                          0x02\n#define RH_RF22_ENPOR                              0x01\n\n// RH_RF22_REG_07_OPERATING_MODE                   0x07\n#define RH_RF22_SWRES                              0x80\n#define RH_RF22_ENLBD                              0x40\n#define RH_RF22_ENWT                               0x20\n#define RH_RF22_X32KSEL                            0x10\n#define RH_RF22_TXON                               0x08\n#define RH_RF22_RXON                               0x04\n#define RH_RF22_PLLON                              0x02\n#define RH_RF22_XTON                               0x01\n\n// RH_RF22_REG_08_OPERATING_MODE2                  0x08\n#define RH_RF22_ANTDIV                             0xc0\n#define RH_RF22_RXMPK                              0x10\n#define RH_RF22_AUTOTX                             0x08\n#define RH_RF22_ENLDM                              0x04\n#define RH_RF22_FFCLRRX                            0x02\n#define RH_RF22_FFCLRTX                            0x01\n\n// RH_RF22_REG_0F_ADC_CONFIGURATION                0x0f\n#define RH_RF22_ADCSTART                           0x80\n#define RH_RF22_ADCDONE                            0x80\n#define RH_RF22_ADCSEL                             0x70\n#define RH_RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR 0x00\n#define RH_RF22_ADCSEL_GPIO0_SINGLE_ENDED          0x10\n#define RH_RF22_ADCSEL_GPIO1_SINGLE_ENDED          0x20\n#define RH_RF22_ADCSEL_GPIO2_SINGLE_ENDED          0x30\n#define RH_RF22_ADCSEL_GPIO0_GPIO1_DIFFERENTIAL    0x40\n#define RH_RF22_ADCSEL_GPIO1_GPIO2_DIFFERENTIAL    0x50\n#define RH_RF22_ADCSEL_GPIO0_GPIO2_DIFFERENTIAL    0x60\n#define RH_RF22_ADCSEL_GND                         0x70\n#define RH_RF22_ADCREF                             0x0c\n#define RH_RF22_ADCREF_BANDGAP_VOLTAGE             0x00\n#define RH_RF22_ADCREF_VDD_ON_3                    0x08\n#define RH_RF22_ADCREF_VDD_ON_2                    0x0c\n#define RH_RF22_ADCGAIN                            0x03\n\n// RH_RF22_REG_10_ADC_SENSOR_AMP_OFFSET            0x10\n#define RH_RF22_ADCOFFS                            0x0f\n\n// RH_RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION   0x12\n#define RH_RF22_TSRANGE                            0xc0\n#define RH_RF22_TSRANGE_M64_64C                    0x00\n#define RH_RF22_TSRANGE_M64_192C                   0x40\n#define RH_RF22_TSRANGE_0_128C                     0x80\n#define RH_RF22_TSRANGE_M40_216F                   0xc0\n#define RH_RF22_ENTSOFFS                           0x20\n#define RH_RF22_ENTSTRIM                           0x10\n#define RH_RF22_TSTRIM                             0x0f\n\n// RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1             0x14\n#define RH_RF22_WTR                                0x3c\n#define RH_RF22_WTD                                0x03\n\n// RH_RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE      0x1d\n#define RH_RF22_AFBCD                              0x80\n#define RH_RF22_ENAFC                              0x40\n#define RH_RF22_AFCGEARH                           0x38\n#define RH_RF22_AFCGEARL                           0x07\n\n// RH_RF22_REG_1E_AFC_TIMING_CONTROL               0x1e\n#define RH_RF22_SWAIT_TIMER                        0xc0\n#define RH_RF22_SHWAIT                             0x38\n#define RH_RF22_ANWAIT                             0x07\n\n// RH_RF22_REG_30_DATA_ACCESS_CONTROL              0x30\n#define RH_RF22_ENPACRX                            0x80\n#define RH_RF22_MSBFRST                            0x00\n#define RH_RF22_LSBFRST                            0x40\n#define RH_RF22_CRCHDRS                            0x00\n#define RH_RF22_CRCDONLY                           0x20\n#define RH_RF22_SKIP2PH                            0x10\n#define RH_RF22_ENPACTX                            0x08\n#define RH_RF22_ENCRC                              0x04\n#define RH_RF22_CRC                                0x03\n#define RH_RF22_CRC_CCITT                          0x00\n#define RH_RF22_CRC_CRC_16_IBM                     0x01\n#define RH_RF22_CRC_IEC_16                         0x02\n#define RH_RF22_CRC_BIACHEVA                       0x03\n\n// RH_RF22_REG_32_HEADER_CONTROL1                  0x32\n#define RH_RF22_BCEN                               0xf0\n#define RH_RF22_BCEN_NONE                          0x00\n#define RH_RF22_BCEN_HEADER0                       0x10\n#define RH_RF22_BCEN_HEADER1                       0x20\n#define RH_RF22_BCEN_HEADER2                       0x40\n#define RH_RF22_BCEN_HEADER3                       0x80\n#define RH_RF22_HDCH                               0x0f\n#define RH_RF22_HDCH_NONE                          0x00\n#define RH_RF22_HDCH_HEADER0                       0x01\n#define RH_RF22_HDCH_HEADER1                       0x02\n#define RH_RF22_HDCH_HEADER2                       0x04\n#define RH_RF22_HDCH_HEADER3                       0x08\n\n// RH_RF22_REG_33_HEADER_CONTROL2                  0x33\n#define RH_RF22_HDLEN                              0x70\n#define RH_RF22_HDLEN_0                            0x00\n#define RH_RF22_HDLEN_1                            0x10\n#define RH_RF22_HDLEN_2                            0x20\n#define RH_RF22_HDLEN_3                            0x30\n#define RH_RF22_HDLEN_4                            0x40\n#define RH_RF22_VARPKLEN                           0x00\n#define RH_RF22_FIXPKLEN                           0x08\n#define RH_RF22_SYNCLEN                            0x06\n#define RH_RF22_SYNCLEN_1                          0x00\n#define RH_RF22_SYNCLEN_2                          0x02\n#define RH_RF22_SYNCLEN_3                          0x04\n#define RH_RF22_SYNCLEN_4                          0x06\n#define RH_RF22_PREALEN8                           0x01\n\n// RH_RF22_REG_6D_TX_POWER                         0x6d\n// https://www.sparkfun.com/datasheets/Wireless/General/RFM22B.pdf\n#define RH_RF22_PAPEAKVAL                          0x80\n#define RH_RF22_PAPEAKEN                           0x40\n#define RH_RF22_PAPEAKLVL                          0x30\n#define RH_RF22_PAPEAKLVL6_5                       0x00\n#define RH_RF22_PAPEAKLVL7                         0x10\n#define RH_RF22_PAPEAKLVL7_5                       0x20\n#define RH_RF22_PAPEAKLVL8                         0x30\n#define RH_RF22_LNA_SW                             0x08\n#define RH_RF22_TXPOW                              0x07\n#define RH_RF22_TXPOW_4X31                         0x08 // Not used in RFM22B\n// For RFM22B:\n#define RH_RF22_TXPOW_1DBM                         0x00\n#define RH_RF22_TXPOW_2DBM                         0x01\n#define RH_RF22_TXPOW_5DBM                         0x02\n#define RH_RF22_TXPOW_8DBM                         0x03\n#define RH_RF22_TXPOW_11DBM                        0x04\n#define RH_RF22_TXPOW_14DBM                        0x05 \n#define RH_RF22_TXPOW_17DBM                        0x06 \n#define RH_RF22_TXPOW_20DBM                        0x07 \n// RFM23B only:\n#define RH_RF22_RF23B_TXPOW_M8DBM                  0x00 // -8dBm\n#define RH_RF22_RF23B_TXPOW_M5DBM                  0x01 // -5dBm\n#define RH_RF22_RF23B_TXPOW_M2DBM                  0x02 // -2dBm\n#define RH_RF22_RF23B_TXPOW_1DBM                   0x03 // 1dBm\n#define RH_RF22_RF23B_TXPOW_4DBM                   0x04 // 4dBm\n#define RH_RF22_RF23B_TXPOW_7DBM                   0x05 // 7dBm\n#define RH_RF22_RF23B_TXPOW_10DBM                  0x06 // 10dBm\n#define RH_RF22_RF23B_TXPOW_13DBM                  0x07 // 13dBm\n// RFM23BP only:\n#define RH_RF22_RF23BP_TXPOW_28DBM                 0x05 // 28dBm\n#define RH_RF22_RF23BP_TXPOW_29DBM                 0x06 // 29dBm\n#define RH_RF22_RF23BP_TXPOW_30DBM                 0x07 // 30dBm\n\n// RH_RF22_REG_71_MODULATION_CONTROL2              0x71\n#define RH_RF22_TRCLK                              0xc0\n#define RH_RF22_TRCLK_NONE                         0x00\n#define RH_RF22_TRCLK_GPIO                         0x40\n#define RH_RF22_TRCLK_SDO                          0x80\n#define RH_RF22_TRCLK_NIRQ                         0xc0\n#define RH_RF22_DTMOD                              0x30\n#define RH_RF22_DTMOD_DIRECT_GPIO                  0x00\n#define RH_RF22_DTMOD_DIRECT_SDI                   0x10\n#define RH_RF22_DTMOD_FIFO                         0x20\n#define RH_RF22_DTMOD_PN9                          0x30\n#define RH_RF22_ENINV                              0x08\n#define RH_RF22_FD8                                0x04\n#define RH_RF22_MODTYP                             0x30\n#define RH_RF22_MODTYP_UNMODULATED                 0x00\n#define RH_RF22_MODTYP_OOK                         0x01\n#define RH_RF22_MODTYP_FSK                         0x02\n#define RH_RF22_MODTYP_GFSK                        0x03\n\n\n// RH_RF22_REG_75_FREQUENCY_BAND_SELECT            0x75\n#define RH_RF22_SBSEL                              0x40\n#define RH_RF22_HBSEL                              0x20\n#define RH_RF22_FB                                 0x1f\n\n// Define this to include Serial printing in diagnostic routines\n#define RH_RF22_HAVE_SERIAL\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_RF22 RH_RF22.h <RH_RF22.h>\n/// \\brief Driver to send and receive unaddressed, unreliable datagrams via an RF22 and compatible radio transceiver.\n///\n/// Works with RF22, RF23 based radio modules, and compatible chips and modules, including:\n/// - RF22 bare module: http://www.sparkfun.com/products/10153\n///   (Caution, that is a 3.3V part, and requires a 3.3V CPU such as Teensy etc or level shifters)\n/// - RF22 shield: http://www.sparkfun.com/products/11018 \n/// - RF22 integrated board http://www.anarduino.com/miniwireless\n/// - RFM23BP bare module: http://www.anarduino.com/details.jsp?pid=130 \n/// - Silicon Labs Si4430/31/32 based modules. S4432 is equivalent to RF22. Si4431/30 is equivalent to RF23.\n///\n/// Data based on https://www.sparkfun.com/datasheets/Wireless/General/RFM22B.pdf\n///\n/// \\par Overview\n///\n/// This base class provides basic functions for sending and receiving unaddressed, \n/// unreliable datagrams of arbitrary length to 255 octets per packet.\n///\n/// Manager classes may use this class to implement reliable, addressed datagrams and streams, \n/// mesh routers, repeaters, translators etc.\n///\n/// On transmission, the TO and FROM addresses default to 0x00, unless changed by a subclass. \n/// On reception the TO addressed is checked against the node address (defaults to 0x00) or the\n/// broadcast address (which is 0xff). The ID and FLAGS are set to 0, and not checked by this class.\n/// This permits use of the this base RH_RF22 class as an \n/// unaddressed, unreliable datagram service without the use of one the RadioHead Manager classes.\n///\n/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and \n/// modulation scheme.\n///\n/// \\par Details\n///\n/// This Driver provides an object-oriented interface for sending and receiving data messages with Hope-RF\n/// RF22 and RF23 based radio modules, and compatible chips and modules, \n/// including the RFM22B transceiver module such as \n/// this bare module: http://www.sparkfun.com/products/10153\n/// and this shield: http://www.sparkfun.com/products/11018\n/// and this module: http://www.hoperfusa.com/details.jsp?pid=131\n/// and this integrated board: http://www.anarduino.com/miniwireless\n/// and RF23BP modules such as this http://www.anarduino.com/details.jsp?pid=130\n///\n/// The Hope-RF (http://www.hoperf.com) RFM22B (http://www.hoperf.com/rf_fsk/fsk/RFM22B.htm) \n/// is a low-cost ISM transceiver module. It supports FSK, GFSK, OOK over a wide \n/// range of frequencies and programmable data rates.\n/// Manual can be found at https://www.sparkfun.com/datasheets/Wireless/General/RFM22.PDF\n///\n/// This library provides functions for sending and receiving messages of up to 255 octets on any \n/// frequency supported by the RF22B, in a range of predefined data rates and frequency deviations. \n/// Frequency can be set with 312Hz precision to any frequency from 240.0MHz to 960.0MHz.\n///\n/// Up to 3 RF22B modules can be connected to an Arduino, permitting the construction of translators\n/// and frequency changers, etc.\n///\n/// The following modulation types are suppported with a range of modem configurations for \n/// common data rates and frequency deviations:\n/// - GFSK Gaussian Frequency Shift Keying\n/// - FSK Frequency Shift Keying\n/// - OOK On-Off Keying\n///\n/// Support for other RF22B features such as on-chip temperature measurement, analog-digital \n/// converter, transmitter power control etc is also provided.\n///\n/// Tested on Arduino Diecimila, Uno and Mega with arduino-0021, 1.0.5\n/// on OpenSuSE 13.1 and avr-libc-1.6.1-1.15,\n/// cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5.\n/// With HopeRF RFM22 modules that appear to have RF22B chips on board:\n///    - Device Type Code = 0x08 (RX/TRX)\n///    - Version Code = 0x06\n/// Works on Duo. Works with Sparkfun RFM22 Wireless shields. Works with RFM22 modules from http://www.hoperfusa.com/\n/// Works with Arduino 1.0 to at least 1.0.5. Works on Maple, Flymaple, Uno32 (with ChipKIT Core with Arduino IDE).\n///\n/// \\par Packet Format\n///\n/// All messages sent and received by this Driver must conform to this packet format:\n///\n/// - 8 nibbles (4 octets) PREAMBLE\n/// - 2 octets SYNC 0x2d, 0xd4\n/// - 4 octets HEADER: (TO, FROM, ID, FLAGS)\n/// - 1 octet LENGTH (0 to 255), number of octets in DATA\n/// - 0 to 255 octets DATA\n/// - 2 octets CRC computed with CRC16(IBM), computed on HEADER, LENGTH and DATA\n///\n/// For technical reasons, the message format is not protocol compatible with the \n/// 'HopeRF Radio Transceiver Message Library for Arduino' http://www.airspayce.com/mikem/arduino/HopeRF from the same author. Nor is it compatible with \n/// 'Virtual Wire' http://www.airspayce.com/mikem/arduino/VirtualWire.pdf also from the same author.\n///\n/// \\par Connecting RFM-22 to Arduino\n///\n/// If you have the Sparkfun RFM22 Shield (https://www.sparkfun.com/products/11018)\n/// the connections described below are done for you on the shield, no changes required, \n/// just add headers and plug it in to an Arduino (but not and Arduino Mega, see below)\n///\n/// The physical connection between the RF22B and the Arduino requires 3.3V,\n/// the 3 x SPI pins (SCK, SDI, SDO), a Slave Select pin and an interrupt pin.\n///\n/// Note: some devices may need a pullup resister on the SDO line.\n///\n/// Note also that on the RFM22B (but not the RFM23B), it is required to control the TX_ANT and\n/// RX_ANT pins of the RFM22 in order to control the antenna connection properly. The RH_RF22\n/// driver is configured by default so that GPIO0 and GPIO1 outputs can\n/// control TX_ANT and RX_ANT input pins respectively automatically. On RFM22, \n/// you must connect GPIO0\n/// to TX_ANT and GPIO1 to RX_ANT for this automatic antenna switching to\n/// occur.  See setGpioReversed() for more details. These connections are not required on RFM23B.\n///\n/// If you are using the Sparkfun RF22 shield, it will work with any 5V arduino without modification.\n/// Connect the RFM-22 module to most Arduino's like this (Caution, Arduino Mega has different pins for SPI, \n/// see below).\n/// \\code\n///                 Arduino      RFM-22B\n///                 GND----------GND-\\ (ground in)\n///                              SDN-/ (shutdown in)\n///                 3V3----------VCC   (3.3V in)\n/// interrupt 0 pin D2-----------NIRQ  (interrupt request out)\n///          SS pin D10----------NSEL  (chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------SDI   (SPI Data in)\n///        MISO pin D12----------SDO   (SPI data out)\n///                           /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)\n///                           \\--TX_ANT (TX antenna control in) RFM22B only\n///                           /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)\n///                           \\--RX_ANT (RX antenna control in) RFM22B only\n/// \\endcode\n/// For an Arduino Mega:\n/// \\code\n///                 Mega         RFM-22B\n///                 GND----------GND-\\ (ground in)\n///                              SDN-/ (shutdown in)\n///                 3V3----------VCC   (3.3V in)\n/// interrupt 0 pin D2-----------NIRQ  (interrupt request out)\n///          SS pin D53----------NSEL  (chip select in)\n///         SCK pin D52----------SCK   (SPI clock in)\n///        MOSI pin D51----------SDI   (SPI Data in)\n///        MISO pin D50----------SDO   (SPI data out)\n///                           /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)\n///                           \\--TX_ANT (TX antenna control in) RFM22B only\n///                           /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)\n///                           \\--RX_ANT (RX antenna control in) RFM22B only\n/// \\endcode\n/// For Chipkit Uno32. Caution: you must also ensure jumper JP4 on the Uno32 is set to RD4\n/// \\code\n///                 Arduino      RFM-22B\n///                 GND----------GND-\\ (ground in)\n///                              SDN-/ (shutdown in)\n///                 3V3----------VCC   (3.3V in)\n/// interrupt 0 pin D38----------NIRQ  (interrupt request out)\n///          SS pin D10----------NSEL  (chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------SDI   (SPI Data in)\n///        MISO pin D12----------SDO   (SPI data out)\n///                           /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)\n///                           \\--TX_ANT (TX antenna control in) RFM22B only\n///                           /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)\n///                           \\--RX_ANT (RX antenna control in) RFM22B only\n/// \\endcode\n/// For Teensy 3.1\n/// \\code\n///                 Teensy      RFM-22B\n///                 GND----------GND-\\ (ground in)\n///                              SDN-/ (shutdown in)\n///                 3V3----------VCC   (3.3V in)\n/// interrupt 2 pin D2-----------NIRQ  (interrupt request out)\n///          SS pin D10----------NSEL  (chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------SDI   (SPI Data in)\n///        MISO pin D12----------SDO   (SPI data out)\n///                           /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)\n///                           \\--TX_ANT (TX antenna control in) RFM22B only\n///                           /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)\n///                           \\--RX_ANT (RX antenna control in) RFM22B only\n/// \\endcode\n/// For an Arduino Due (the SPI pins do not come out on the Digital pins as for normal Arduino, but only\n/// appear on the SPI header)\n/// \\code\n///                 Due      RFM-22B\n///                 GND----------GND-\\ (ground in)\n///                              SDN-/ (shutdown in)\n///                 5V-----------VCC   (5V in)\n/// interrupt 0 pin D2-----------NIRQ  (interrupt request out)\n///          SS pin D10----------NSEL  (chip select in)\n///       SCK SPI pin 3----------SCK   (SPI clock in)\n///      MOSI SPI pin 4----------SDI   (SPI Data in)\n///      MISO SPI pin 1----------SDO   (SPI data out)\n///                           /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)\n///                           \\--TX_ANT (TX antenna control in) RFM22B only\n///                           /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)\n///                           \\--RX_ANT (RX antenna control in) RFM22B only\n/// \\endcode\n/// and use the default constructor:\n/// RH_RF22 driver;\n\n/// For connecting an Arduino to an RFM23BP module. Note that the antenna control pins are reversed \n/// compared to the RF22.\n/// \\code\n///                 Arduino      RFM-23BP\n///                 GND----------GND-\\ (ground in)\n///                              SDN-/ (shutdown in)\n///                 5V-----------VCC   (5V in)\n/// interrupt 0 pin D2-----------NIRQ  (interrupt request out)\n///          SS pin D10----------NSEL  (chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------SDI   (SPI Data in)\n///        MISO pin D12----------SDO   (SPI data out)\n///                           /--GPIO0 (GPIO0 out to control receiver antenna RXON)\n///                           \\--RXON   (RX antenna control in)\n///                           /--GPIO1 (GPIO1 out to control transmitter antenna TXON)\n///                           \\--TXON   (TX antenna control in)\n/// \\endcode\n///\n/// and you can then use the default constructor RH_RF22(). \n/// You can override the default settings for the SS pin and the interrupt \n/// in the RH_RF22 constructor if you wish to connect the slave select SS to other than the normal one for your \n/// Arduino (D10 for Diecimila, Uno etc and D53 for Mega)\n/// or the interrupt request to other than pin D2 (Caution, different processors have different constraints as to the \n/// pins available for interrupts).\n///\n/// If you have an Arduino Zero, you should note that you cannot use Pin 2 for the interrupt line \n/// (Pin 2 is for the NMI only), instead you can use any other pin (we use Pin 3) and initialise RH_RF69 like this:\n/// \\code\n/// // Slave Select is pin 10, interrupt is Pin 3\n/// RH_RF22 driver(10, 3);\n/// \\endcode\n///\n/// It is possible to have 2 radios connected to one Arduino, provided each radio has its own \n/// SS and interrupt line (SCK, SDI and SDO are common to both radios)\n///\n/// Caution: on some Arduinos such as the Mega 2560, if you set the slave select pin to be other than the usual SS \n/// pin (D53 on  Mega 2560), you may need to set the usual SS pin to be an output to force the Arduino into SPI \n/// master mode.\n///\n/// Caution: Power supply requirements of the RF22 module may be relevant in some circumstances: \n/// RF22 modules are capable of pulling 80mA+ at full power, where Arduino's 3.3V line can\n/// give 50mA. You may need to make provision for alternate power supply for\n/// the RF22, especially if you wish to use full transmit power, and/or you have\n/// other shields demanding power. Inadequate power for the RF22 is reported to cause symptoms such as:\n/// - reset's/bootups terminate with \"init failed\" messages\n/// -random termination of communication after 5-30 packets sent/received\n/// -\"fake ok\" state, where initialization passes fluently, but communication doesn't happen\n/// -shields hang Arduino boards, especially during the flashing\n///\n/// Caution: some RF22 breakout boards (such as the HAB-RFM22B-BOA  HAB-RFM22B-BO) reportedly \n/// have the TX_ANT and RX_ANT pre-connected to GPIO0 and GPIO1 round the wrong way. You can work with this\n/// if you use setGpioReversed().\n///\n/// Caution: If you are using a bare RF22 module without IO level shifters, you may have difficulty connecting\n/// to a 5V arduino. The RF22 module is 3.3V and its IO pins are 3.3V not 5V. Some Arduinos (Diecimila and\n/// Uno) seem to work OK with this, and some (Mega) do not always work reliably. Your Mileage May Vary.\n/// For best result, use level shifters, or use a RF22 shield or board with level shifters built in, \n/// such as the Sparkfun RFM22 shield http://www.sparkfun.com/products/11018. \n/// You could also use a 3.3V IO Arduino such as a Pro. \n/// It is recognised that it is difficult to connect \n/// the Sparkfun RFM22 shield to a Mega, since the SPI pins on the Mega are different to other Arduinos, \n/// But it is possible, by bending the SPI pins (D10, D11, D12, D13) on the \n/// shield out of the way before plugging it in to the Mega and jumpering the shield pins to the Mega like this:\n/// \\code\n///   RF22 Shield        Mega\n///     D10              D53\n///     D13              D52\n///     D11              D51\n///     D12              D50\n/// \\endcode\n/// \n/// \\par Interrupts\n///\n/// The Driver uses interrupts to react to events in the RF22 module, \n/// such as the reception of a new packet, or the completion of transmission of a packet. \n/// The RH_RF22 interrupt service routine reads status from and writes data\n/// to the the RF22 module via the SPI interface. It is very important therefore,\n/// that if you are using the RF22 library with another SPI based deviced, that you\n/// disable interrupts while you transfer data to and from that other device.\n/// Use cli() to disable interrupts and sei() to reenable them.\n///\n/// \\par SPI Interface\n///\n/// The RF22 module uses the SPI bus to communicate with the Arduino. Arduino\n/// IDE includes a hardware SPI class to communicate with SPI devices using\n/// the SPI facilities built into the Atmel chips, over the standard designated\n/// SPI pins MOSI, MISO, SCK, which are usually on Arduino pins 11, 12 and 13\n/// respectively (or 51, 50, 52 on a Mega).\n///\n/// By default, the RH_RF22 Driver uses the Hardware SPI interface to\n/// communicate with the RF22 module. However, if your RF22 SPI is connected to\n/// the Arduino through non-standard pins, or the standard Hardware SPI\n/// interface will not work for you, you can instead use a bit-banged Software\n/// SPI class RHSoftwareSPI, which can be configured to work on any Arduino digital IO pins.\n/// See the documentation of RHSoftwareSPI for details.\n///\n/// The advantages of the Software SPI interface are that it can be used on\n/// any Arduino pins, not just the usual dedicated hardware pins. The\n/// disadvantage is that it is significantly slower then hardware.\n/// If you observe reliable behaviour with the default hardware SPI RHHardwareSPI, but unreliable behaviour \n/// with Software SPI RHSoftwareSPI, it may be due to slow CPU performance.\n///\n/// Initialisation example with hardware SPI\n/// \\code\n/// #include <RH_RF22.h>\n/// RH_RF22 driver;\n/// RHReliableDatagram manager(driver, CLIENT_ADDRESS);\n/// \\endcode\n///\n/// Initialisation example with software SPI\n/// \\code\n/// #include <RH_RF22.h>\n/// #include <RHSoftwareSPI.h>\n/// RHSoftwareSPI spi;\n/// RH_RF22 driver(10, 2, spi);\n/// RHReliableDatagram manager(driver, CLIENT_ADDRESS);\n/// \\endcode\n///\n/// \\par Memory\n///\n/// The RH_RF22 Driver requires non-trivial amounts of memory. The sample programs all compile to \n/// about 9 to 14kbytes each on Arduino, which will fit in the flash proram memory of most Arduinos. However, \n/// the RAM requirements are more critical. Most sample programs above will run on Duemilanova, \n/// but not on Diecimila. Even on Duemilanova, the RAM requirements are very close to the \n/// available memory of 2kbytes. Therefore, you should be vary sparing with RAM use in programs that use \n/// the RH_RF22 Driver on Duemilanova.\n///\n/// The sample RHRouter and RHMesh programs compile to about 14kbytes, \n/// and require more RAM than the others. \n/// They will not run on Duemilanova or Diecimila, but will run on Arduino Mega.\n///\n/// It is often hard to accurately identify when you are hitting RAM limits on Arduino. \n/// The symptoms can include:\n/// - Mysterious crashes and restarts\n/// - Changes in behaviour when seemingly unrelated changes are made (such as adding print() statements)\n/// - Hanging\n/// - Output from Serial.print() not appearing\n/// \n/// With an Arduino Mega, with 8 kbytes of SRAM, there is much more RAM headroom for \n/// your own elaborate programs. \n/// This library is reported to work with Arduino Pro Mini, but that has not been tested by me.\n///\n/// The RF22M modules use an inexpensive crystal to control the frequency synthesizer, and therfore you can expect \n/// the transmitter and receiver frequencies to be subject to the usual inaccuracies of such crystals. The RF22\n/// contains an AFC circuit to compensate for differences in transmitter and receiver frequencies. \n/// It does this by altering the receiver frequency during reception by up to the pull-in frequency range. \n/// This RF22 library enables the AFC and by default sets the pull-in frequency range to\n/// 0.05MHz, which should be sufficient to handle most situations. However, if you observe unexplained packet losses\n/// or failure to operate correctly all the time it may be because your modules have a wider frequency difference, and\n/// you may need to set the afcPullInRange to a different value, using setFrequency();\n///\n/// \\par Transmitter Power\n///\n/// You can control the transmitter power on the RF22 and RF23 transceivers\n/// with the RH_RF22::setTxPower() function. The argument can be any of the\n/// RH_RF22_TXPOW_* (for RFM22) or RH_RF22_RF23B_TXPOW_* (for RFM23) values. \n/// The default is RH_RF22_TXPOW_8DBM/RH_RF22_RF23B_TXPOW_1DBM . Eg:\n/// \\code\n/// driver.setTxPower(RH_RF22_TXPOW_2DBM);\n/// \\endcode\n///\n/// The RF23BP has higher power capability, there are\n/// several power settings that are specific to the RF23BP only:\n///\n/// - RH_RF22_RF23BP_TXPOW_28DBM\n/// - RH_RF22_RF23BP_TXPOW_29DBM\n/// - RH_RF22_RF23BP_TXPOW_38DBM\n///\n/// CAUTION: the high power settings available on the RFM23BP require\n/// significant power supply current.  For example at +30dBm, the typical chip\n/// supply current is 550mA. This will overwhelm some small CPU board power\n/// regulators and USB supplies. If you use this chip at high power make sure\n/// you have an adequate supply current providing full 5V to the RFM23BP (and\n/// the CPU if required), otherwise you can expect strange behaviour like\n/// hanging, stopping, incorrect power levels, RF power amp overheating etc.\n/// You must also ensure that the RFM23BP GPIO pins are connected to the\n/// antenna switch control pins like so:\n////\n/// \\code\n/// GPIO0 <-> RXON\n/// GPIO1 <-> TXON\n/// \\endcode\n///\n/// The RF output impedance of the RFM22BP module is 50 ohms.  In our\n/// experiments we found that the most critical issue (besides a suitable\n/// power supply) is to ensure that the antenna impedance is also near 50\n/// ohms. Connecting a simple 1/4 wavelength (ie a 17.3cm single wire)\n/// directly to the antenna output <b>will not work at full 30dBm power</b>,\n/// and will result in the transmitter hanging and/or the power amp\n/// overheating. Connect a proper 50 ohm impedance transmission line or\n/// antenna, and prevent RF radiation into the radio and arduino modules,\n/// in order to get full, reliable power. Our tests show that a 433MHz\n/// RFM23BP feeding a 50 ohm transmission line with a VHF discone antenna at\n/// the end results in full power output and the power amp transistor on the\n/// RFM22BP module runnning slightly warm but not hot. We recommend you use\n/// the services of a competent RF engineer when trying to use this high power\n/// module.\n///\n/// Note: with RFM23BP, the reported maximum possible power when operating on 3.3V is 27dBm.\n///\n/// We have made some actual power measurements against\n/// programmed power for Sparkfun RFM22 wireless module under the following conditions:\n/// - Sparkfun RFM22 wireless module, Duemilanove, USB power\n/// - 10cm RG58C/U soldered direct to RFM22 module ANT and GND\n/// - bnc connecteor\n/// - 12dB attenuator\n/// - BNC-SMA adapter\n/// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)\n/// - Tektronix TDS220 scope to measure the Vout from power head\n/// \\code\n/// Program power           Measured Power\n///    dBm                         dBm\n///    1                           -5.6\n///    2                           -3.8\n///    5                           -2.2\n///    8                           -0.6\n///    11                           1.2\n///    14                           11.6\n///    17                           14.4\n///    20                           18.0\n/// \\endcode\n/// (Caution: we dont claim laboratory accuracy for these measurements)\n/// You would not expect to get anywhere near these powers to air with a simple 1/4 wavelength wire antenna.\n///\n/// \\par Performance\n///\n/// Some simple speed performance tests have been conducted.\n/// In general packet transmission rate will be limited by the modulation scheme.\n/// Also, if your code does any slow operations like Serial printing it will also limit performance. \n/// We disabled any printing in the tests below.\n/// We tested with RH_RF22::GFSK_Rb125Fd125, which is probably the fastest scheme available.\n/// We tested with a 13 octet message length, over a very short distance of 10cm.\n///\n/// Transmission (no reply) tests with modulation RH_RF22::GFSK_Rb125Fd125 and a \n/// 13 octet message show about 330 messages per second transmitted.\n///\n/// Transmit-and-wait-for-a-reply tests with modulation RH_RF22::GFSK_Rb125Fd125 and a \n/// 13 octet message (send and receive) show about 160 round trips per second.\n///\n/// \\par Compatibility with RF22 library\n/// The RH_RF22 driver is based on our earlier RF22 library http://www.airspayce.com/mikem/arduino/RF22\n/// We have tried hard to be as compatible as possible with the earlier RF22 library, but there are some differences:\n/// - Different constructor.\n/// - Indexes for some modem configurations have changed (we recommend you use the symbolic names, not integer indexes).\n///\n/// The major difference is that under RadioHead, you are\n/// required to create 2 objects (ie RH_RF22 and a manager) instead of just one object under RF22\n/// (ie RHMesh, RHRouter, RHReliableDatagram or RHDatagram).\n/// It may be sufficient or you to change for example:\n/// \\code\n/// RF22ReliableDatagram rf22(CLIENT_ADDRESS);\n/// \\endcode\n/// to:\n/// \\code\n/// RH_RF22 driver;\n/// RHReliableDatagram rf22(driver, CLIENT_ADDRESS);\n/// \\endcode\n/// and any instance of RF22_MAX_MESSAGE_LEN to RH_RF22_MAX_MESSAGE_LEN\n///\n/// RadioHead version 1.6 changed the way the interrupt pin number is\n/// specified on Arduino and Uno32 platforms. If your code previously\n/// specifed a non-default interrupt pin number in the RH_RF22 constructor,\n/// you may need to review your code to specify the correct interrrupt pin\n/// (and not the interrupt number as before).\nclass RH_RF22 : public RHSPIDriver\n{\npublic:\n\n    /// \\brief Defines register values for a set of modem configuration registers\n    ///\n    /// Defines register values for a set of modem configuration registers\n    /// that can be passed to setModemConfig()\n    /// if none of the choices in ModemConfigChoice suit your need\n    /// setModemConfig() writes the register values to the appropriate RH_RF22 registers\n    /// to set the desired modulation type, data rate and deviation/bandwidth.\n    /// Suitable values for these registers can be computed using the register calculator at\n    /// http://www.hoperf.com/upload/rf/RF22B%2023B%2031B%2042B%2043B%20Register%20Settings_RevB1-v5.xls\n    typedef struct\n    {\n\tuint8_t    reg_1c;   ///< Value for register RH_RF22_REG_1C_IF_FILTER_BANDWIDTH\n\tuint8_t    reg_1f;   ///< Value for register RH_RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE\n\tuint8_t    reg_20;   ///< Value for register RH_RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE\n\tuint8_t    reg_21;   ///< Value for register RH_RF22_REG_21_CLOCK_RECOVERY_OFFSET2 \n\tuint8_t    reg_22;   ///< Value for register RH_RF22_REG_22_CLOCK_RECOVERY_OFFSET1 \n\tuint8_t    reg_23;   ///< Value for register RH_RF22_REG_23_CLOCK_RECOVERY_OFFSET0\n\tuint8_t    reg_24;   ///< Value for register RH_RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1\n\tuint8_t    reg_25;   ///< Value for register RH_RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0 \n\tuint8_t    reg_2c;   ///< Value for register RH_RF22_REG_2C_OOK_COUNTER_VALUE_1 \n\tuint8_t    reg_2d;   ///< Value for register RH_RF22_REG_2D_OOK_COUNTER_VALUE_2\n\tuint8_t    reg_2e;   ///< Value for register RH_RF22_REG_2E_SLICER_PEAK_HOLD \n\tuint8_t    reg_58;   ///< Value for register RH_RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING\n\tuint8_t    reg_69;   ///< Value for register RH_RF22_REG_69_AGC_OVERRIDE1 \n\tuint8_t    reg_6e;   ///< Value for register RH_RF22_REG_6E_TX_DATA_RATE1\n\tuint8_t    reg_6f;   ///< Value for register RH_RF22_REG_6F_TX_DATA_RATE0 \n\tuint8_t    reg_70;   ///< Value for register RH_RF22_REG_70_MODULATION_CONTROL1\n\tuint8_t    reg_71;   ///< Value for register RH_RF22_REG_71_MODULATION_CONTROL2\n\tuint8_t    reg_72;   ///< Value for register RH_RF22_REG_72_FREQUENCY_DEVIATION\n    } ModemConfig;\n  \n    /// Choices for setModemConfig() for a selected subset of common modulation types,\n    /// and data rates. If you need another configuration, use the register calculator.\n    /// and call setModemRegisters() with your desired settings.\n    /// These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic\n    /// definitions and not their integer equivalents: its possible that new values will be\n    /// introduced in later versions (though we will try to avoid it).\n    typedef enum\n    {\n\tUnmodulatedCarrier = 0, ///< Unmodulated carrier for testing\n\tFSK_PN9_Rb2Fd5,      ///< FSK, No Manchester, Rb = 2kbs, Fd = 5kHz, PN9 random modulation for testing\n\n\tFSK_Rb2Fd5,\t     ///< FSK, No Manchester, Rb = 2kbs,    Fd = 5kHz\n\tFSK_Rb2_4Fd36,       ///< FSK, No Manchester, Rb = 2.4kbs,  Fd = 36kHz\n\tFSK_Rb4_8Fd45,       ///< FSK, No Manchester, Rb = 4.8kbs,  Fd = 45kHz\n\tFSK_Rb9_6Fd45,       ///< FSK, No Manchester, Rb = 9.6kbs,  Fd = 45kHz\n\tFSK_Rb19_2Fd9_6,     ///< FSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz\n\tFSK_Rb38_4Fd19_6,    ///< FSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz\n\tFSK_Rb57_6Fd28_8,    ///< FSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz\n\tFSK_Rb125Fd125,      ///< FSK, No Manchester, Rb = 125kbs,  Fd = 125kHz\n\tFSK_Rb_512Fd2_5,     ///< FSK, No Manchester, Rb = 512bs,  Fd = 2.5kHz, for POCSAG compatibility\n\tFSK_Rb_512Fd4_5,     ///< FSK, No Manchester, Rb = 512bs,  Fd = 4.5kHz, for POCSAG compatibility\n\n\tGFSK_Rb2Fd5,         ///< GFSK, No Manchester, Rb = 2kbs,    Fd = 5kHz\n\tGFSK_Rb2_4Fd36,      ///< GFSK, No Manchester, Rb = 2.4kbs,  Fd = 36kHz\n\tGFSK_Rb4_8Fd45,      ///< GFSK, No Manchester, Rb = 4.8kbs,  Fd = 45kHz\n\tGFSK_Rb9_6Fd45,      ///< GFSK, No Manchester, Rb = 9.6kbs,  Fd = 45kHz\n\tGFSK_Rb19_2Fd9_6,    ///< GFSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz\n\tGFSK_Rb38_4Fd19_6,   ///< GFSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz\n\tGFSK_Rb57_6Fd28_8,   ///< GFSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz\n\tGFSK_Rb125Fd125,     ///< GFSK, No Manchester, Rb = 125kbs,  Fd = 125kHz\n\n\tOOK_Rb1_2Bw75,       ///< OOK, No Manchester, Rb = 1.2kbs,  Rx Bandwidth = 75kHz\n\tOOK_Rb2_4Bw335,      ///< OOK, No Manchester, Rb = 2.4kbs,  Rx Bandwidth = 335kHz\n\tOOK_Rb4_8Bw335,      ///< OOK, No Manchester, Rb = 4.8kbs,  Rx Bandwidth = 335kHz\n\tOOK_Rb9_6Bw335,      ///< OOK, No Manchester, Rb = 9.6kbs,  Rx Bandwidth = 335kHz\n\tOOK_Rb19_2Bw335,     ///< OOK, No Manchester, Rb = 19.2kbs, Rx Bandwidth = 335kHz\n\tOOK_Rb38_4Bw335,     ///< OOK, No Manchester, Rb = 38.4kbs, Rx Bandwidth = 335kHz\n\tOOK_Rb40Bw335        ///< OOK, No Manchester, Rb = 40kbs,   Rx Bandwidth = 335kHz\n\n    } ModemConfigChoice;\n\n    /// \\brief Defines the available choices for CRC\n    /// Types of permitted CRC polynomials, to be passed to setCRCPolynomial()\n    /// They deliberately have the same numeric values as the crc[1:0] field of Register\n    /// RH_RF22_REG_30_DATA_ACCESS_CONTROL\n    typedef enum\n    {\n\tCRC_CCITT = 0,       ///< CCITT\n\tCRC_16_IBM = 1,      ///< CRC-16 (IBM) The default used by RH_RF22 driver\n\tCRC_IEC_16 = 2,      ///< IEC-16\n\tCRC_Biacheva = 3     ///< Biacheva\n    } CRCPolynomial;\n\n    /// Constructor. You can have multiple instances, but each instance must have its own\n    /// interrupt and slave select pin. After constructing, you must call init() to initialise the interface\n    /// and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient\n    /// distinct interrupt lines, one for each instance.\n    /// \\param[in] slaveSelectPin the Arduino pin number of the output to use to select the RH_RF22 before\n    /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)\n    /// \\param[in] interruptPin The interrupt Pin number that is connected to the RF22 NIRQ interrupt line. \n    /// Defaults to pin 2, as required by sparkfun RFM22 module shields.\n    /// Caution: You must specify an interrupt capable pin.\n    /// On many Arduino boards, there are limitations as to which pins may be used as interrupts.\n    /// On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin.\n    /// On other Arduinos pins 2 or 3. \n    /// See http://arduino.cc/en/Reference/attachInterrupt for more details.\n    /// On Chipkit Uno32, pins 38, 2, 7, 8, 35.\n    /// On other boards, any digital pin may be used.\n    /// \\param[in] spi Pointer to the SPI interface object to use. \n    ///                Defaults to the standard Arduino hardware SPI interface\n    RH_RF22(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, RHGenericSPI& spi = hardware_spi);\n  \n    /// Initialises this instance and the radio module connected to it.\n    /// The following steps are taken:\n    /// - Initialise the slave select pin and the SPI interface library\n    /// - Software reset the RH_RF22 module\n    /// - Checks the connected RH_RF22 module is either a RH_RF22_DEVICE_TYPE_RX_TRX or a RH_RF22_DEVICE_TYPE_TX\n    /// - Attaches an interrupt handler\n    /// - Configures the RH_RF22 module\n    /// - Sets the frequency to 434.0 MHz\n    /// - Sets the modem data rate to FSK_Rb2_4Fd36\n    /// \\return  true if everything was successful\n    bool        init();\n\n    /// Issues a software reset to the \n    /// RH_RF22 module. Blocks for 1ms to ensure the reset is complete.\n    void           reset();\n\n    /// Reads and returns the device status register RH_RF22_REG_02_DEVICE_STATUS\n    /// \\return The value of the device status register\n    uint8_t        statusRead();\n  \n    /// Reads a value from the on-chip analog-digital converter\n    /// \\param[in] adcsel Selects the ADC input to measure. One of RH_RF22_ADCSEL_*. Defaults to the \n    /// internal temperature sensor\n    /// \\param[in] adcref Specifies the refernce voltage to use. One of RH_RF22_ADCREF_*. \n    /// Defaults to the internal bandgap voltage.\n    /// \\param[in] adcgain Amplifier gain selection. \n    /// \\param[in] adcoffs Amplifier offseet (0 to 15).\n    /// \\return The analog value. 0 to 255.\n    uint8_t        adcRead(uint8_t adcsel = RH_RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR,\n\t\t\t   uint8_t adcref = RH_RF22_ADCREF_BANDGAP_VOLTAGE,\n\t\t\t   uint8_t adcgain = 0, \n\t\t\t   uint8_t adcoffs = 0);\n\n    /// Reads the on-chip temperature sensor\n    /// \\param[in] tsrange Specifies the temperature range to use. One of RH_RF22_TSRANGE_*\n    /// \\param[in] tvoffs Specifies the temperature value offset. This is actually signed value \n    /// added to the measured temperature value\n    /// \\return The measured temperature.\n    uint8_t        temperatureRead(uint8_t tsrange = RH_RF22_TSRANGE_M64_64C, uint8_t tvoffs = 0);   \n\n    /// Reads the wakeup timer value in registers RH_RF22_REG_17_WAKEUP_TIMER_VALUE1 \n    /// and RH_RF22_REG_18_WAKEUP_TIMER_VALUE2\n    /// \\return The wakeup timer value \n    uint16_t       wutRead();\n\n    /// Sets the wakeup timer period registers RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1,\n    /// RH_RF22_REG_15_WAKEUP_TIMER_PERIOD2 and RH_RF22_R<EG_16_WAKEUP_TIMER_PERIOD3\n    /// \\param[in] wtm Wakeup timer mantissa value\n    /// \\param[in] wtr Wakeup timer exponent R value\n    /// \\param[in] wtd Wakeup timer exponent D value\n    void           setWutPeriod(uint16_t wtm, uint8_t wtr = 0, uint8_t wtd = 0);\n\n    /// Sets the transmitter and receiver centre frequency\n    /// \\param[in] centre Frequency in MHz. 240.0 to 960.0. Caution, some versions of RH_RF22 and derivatives \n    /// implemented more restricted frequency ranges.\n    /// \\param[in] afcPullInRange Sets the AF Pull In Range in MHz. Defaults to 0.05MHz (50kHz). \n    /// Range is 0.0 to 0.159375\n    /// for frequencies 240.0 to 480MHz, and 0.0 to 0.318750MHz for  frequencies 480.0 to 960MHz, \n    /// \\return true if the selected frquency centre + (fhch * fhs) is within range and the afcPullInRange \n    /// is within range\n    bool        setFrequency(float centre, float afcPullInRange = 0.05);\n\n    /// Sets the frequency hopping step size.\n    /// \\param[in] fhs Frequency Hopping step size in 10kHz increments\n    /// \\return true if centre + (fhch * fhs) is within limits\n    bool        setFHStepSize(uint8_t fhs);\n\n    /// Sets the frequncy hopping channel. Adds fhch * fhs to centre frequency\n    /// \\param[in] fhch The channel number\n    /// \\return true if the selected frquency centre + (fhch * fhs) is within range\n    bool        setFHChannel(uint8_t fhch);\n\n    /// Reads and returns the current RSSI value from register RH_RF22_REG_26_RSSI. Caution: this is\n    /// in internal units (see figure 31 of RFM22B/23B documentation), not in dBm. If you want to find the RSSI in dBm\n    /// of the last received message, use lastRssi() instead.\n    /// \\return The current RSSI value \n    uint8_t        rssiRead();\n\n    /// Reads and returns the current EZMAC value from register RH_RF22_REG_31_EZMAC_STATUS\n    /// \\return The current EZMAC value\n    uint8_t        ezmacStatusRead();\n\n    /// Sets the parameters for the RH_RF22 Idle mode in register RH_RF22_REG_07_OPERATING_MODE. \n    /// Idle mode is the mode the RH_RF22 will be in when not transmitting or receiving. The default idle mode \n    /// is RH_RF22_XTON ie READY mode. \n    /// \\param[in] mode Mask of mode bits, using RH_RF22_SWRES, RH_RF22_ENLBD, RH_RF22_ENWT, \n    /// RH_RF22_X32KSEL, RH_RF22_PLLON, RH_RF22_XTON.\n    void           setOpMode(uint8_t mode);\n\n    /// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, \n    /// disables them.\n    void           setModeIdle();\n\n    /// If current mode is Tx or Idle, changes it to Rx. \n    /// Starts the receiver in the RH_RF22.\n    void           setModeRx();\n\n    /// If current mode is Rx or Idle, changes it to Rx. \n    /// Starts the transmitter in the RH_RF22.\n    void           setModeTx();\n\n    /// Sets the transmitter power output level in register RH_RF22_REG_6D_TX_POWER.\n    /// Be a good neighbour and set the lowest power level you need.\n    /// After init(), the power will be set to RH_RF22::RH_RF22_TXPOW_8DBM on RF22B\n    /// or RH_RF22_RF23B_TXPOW_1DBM on an RF23B.\n    /// The highest power available on RF22B is RH_RF22::RH_RF22_TXPOW_20DBM (20dBm).\n    /// The highest power available on RF23B is RH_RF22::RH_RF22_RF23B_TXPOW_13DBM (13dBm).\n    /// Higher powers are available on RF23BP (using RH_RF22_RF23BP_TXPOW_*), \n    /// and then only with an adequate power supply. See comments above.\n    /// Caution: In some countries you may only select certain higher power levels if you\n    /// are also using frequency hopping. Make sure you are aware of the legal\n    /// limitations and regulations in your region.\n    /// \\param[in] power Transmitter power level, one of RH_RF22_*TXPOW_*\n    void           setTxPower(uint8_t power);\n\n    /// Sets all the registered required to configure the data modem in the RH_RF22, including the data rate, \n    /// bandwidths etc. You cas use this to configure the modem with custom configuraitons if none of the \n    /// canned configurations in ModemConfigChoice suit you.\n    /// \\param[in] config A ModemConfig structure containing values for the modem configuration registers.\n    void           setModemRegisters(const ModemConfig* config);\n\n    /// Select one of the predefined modem configurations. If you need a modem configuration not provided \n    /// here, use setModemRegisters() with your own ModemConfig.\n    /// \\param[in] index The configuration choice.\n    /// \\return true if index is a valid choice.\n    bool        setModemConfig(ModemConfigChoice index);\n\n    /// Starts the receiver and checks whether a received message is available.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a complete, valid message has been received and is able to be retrieved by\n    /// recv()\n    bool        available();\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    bool        recv(uint8_t* buf, uint8_t* len);\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is NOT permitted. \n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send (> 0)\n    /// \\return true if the message length was valid and it was correctly queued for transmit\n    bool        send(const uint8_t* data, uint8_t len);\n\n    /// Sets the length of the preamble\n    /// in 4-bit nibbles. \n    /// Caution: this should be set to the same \n    /// value on all nodes in your network. Default is 8.\n    /// Sets the message preamble length in RH_RF22_REG_34_PREAMBLE_LENGTH\n    /// \\param[in] nibbles Preamble length in nibbles of 4 bits each.  \n    void           setPreambleLength(uint8_t nibbles);\n\n    /// Sets the sync words for transmit and receive in registers RH_RF22_REG_36_SYNC_WORD3 \n    /// to RH_RF22_REG_39_SYNC_WORD0\n    /// Caution: SyncWords should be set to the same \n    /// value on all nodes in your network. Nodes with different SyncWords set will never receive\n    /// each others messages, so different SyncWords can be used to isolate different\n    /// networks from each other. Default is { 0x2d, 0xd4 }.\n    /// \\param[in] syncWords Array of sync words, 1 to 4 octets long\n    /// \\param[in] len Number of sync words to set, 1 to 4.\n    void           setSyncWords(const uint8_t* syncWords, uint8_t len);\n\n    /// Tells the receiver to accept messages with any TO address, not just messages\n    /// addressed to thisAddress or the broadcast address\n    /// \\param[in] promiscuous true if you wish to receive messages with any TO address\n    virtual void   setPromiscuous(bool promiscuous);\n\n    /// Sets the CRC polynomial to be used to generate the CRC for both receive and transmit\n    /// otherwise the default of CRC_16_IBM will be used.\n    /// \\param[in] polynomial One of RH_RF22::CRCPolynomial choices CRC_*\n    /// \\return true if polynomial is a valid option for this radio.\n    bool setCRCPolynomial(CRCPolynomial polynomial);\n\n    /// Configures GPIO pins for reversed GPIO connections to the antenna switch.\n    /// Normally on RF22 modules, GPIO0(out) is connected to TX_ANT(in) to enable tx antenna during transmit\n    /// and GPIO1(out) is connected to RX_ANT(in) to enable rx antenna during receive. The RH_RF22 driver\n    /// configures the GPIO pins during init() so the antenna switch works as expected.\n    /// However, some RF22 modules, such as HAB-RFM22B-BOA HAB-RFM22B-BO, also Si4432 sold by Dorji.com via Tindie.com\n    /// have these GPIO pins reversed, so that GPIO0 is connected to RX_ANT.\n    /// Call this function with a true argument after init() and before transmitting\n    /// in order to configure the module for reversed GPIO pins.\n    /// \\param[in] gpioReversed Set to true if your RF22 module has reversed GPIO antenna switch connections.\n    void setGpioReversed(bool gpioReversed = false);\n\n    /// Returns the time in millis since the last preamble was received, and when the last\n    /// RSSI measurement was made.\n    uint32_t getLastPreambleTime();\n\n    /// The maximum message length supported by this driver\n    /// \\return The maximum message length supported by this driver\n    uint8_t maxMessageLength();\n\n    /// Sets the radio into low-power sleep mode.\n    /// If successful, the transport will stay in sleep mode until woken by \n    /// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc)\n    /// Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode.\n    /// \\return true if sleep mode was successfully entered.\n    virtual bool    sleep();\n\nprotected:\n    /// This is a low level function to handle the interrupts for one instance of RH_RF22.\n    /// Called automatically by isr*()\n    /// Should not need to be called.\n    void           handleInterrupt();\n\n    /// Clears the receiver buffer.\n    /// Internal use only\n    void           clearRxBuf();\n\n    /// Clears the transmitter buffer\n    /// Internal use only\n    void           clearTxBuf();\n\n    /// Fills the transmitter buffer with the data of a mesage to be sent\n    /// \\param[in] data Array of data bytes to be sent (1 to 255)\n    /// \\param[in] len Number of data bytes in data (> 0)\n    /// \\return true if the message length is valid\n    bool           fillTxBuf(const uint8_t* data, uint8_t len);\n\n    /// Appends the transmitter buffer with the data of a mesage to be sent\n    /// \\param[in] data Array of data bytes to be sent (0 to 255)\n    /// \\param[in] len Number of data bytes in data\n    /// \\return false if the resulting message would exceed RH_RF22_MAX_MESSAGE_LEN, else true\n    bool           appendTxBuf(const uint8_t* data, uint8_t len);\n\n    /// Internal function to load the next fragment of \n    /// the current message into the transmitter FIFO\n    /// Internal use only\n    void           sendNextFragment();\n\n    ///  function to copy the next fragment from \n    /// the receiver FIF) into the receiver buffer\n    void           readNextFragment();\n\n    /// Clears the RF22 Rx and Tx FIFOs\n    /// Internal use only\n    void           resetFifos();\n\n    /// Clears the RF22 Rx FIFO\n    /// Internal use only\n    void           resetRxFifo();\n\n    /// Clears the RF22 Tx FIFO\n    /// Internal use only\n    void           resetTxFifo();\n\n    /// This function will be called by handleInterrupt() if an RF22 external interrupt occurs. \n    /// This can only happen if external interrupts are enabled in the RF22 \n    /// (which they are not by default). \n    /// Subclasses may override this function to get control when an RF22 external interrupt occurs. \n    virtual void   handleExternalInterrupt();\n\n    /// This function will be called by handleInterrupt() if an RF22 wakeup timer interrupt occurs. \n    /// This can only happen if wakeup timer interrupts are enabled in theRF22 \n    /// (which they are not by default). \n    /// Subclasses may override this function to get control when an RF22 wakeup timer interrupt occurs. \n    virtual void   handleWakeupTimerInterrupt();\n\n    /// Start the transmission of the contents \n    /// of the Tx buffer\n    void           startTransmit();\n\n    /// ReStart the transmission of the contents \n    /// of the Tx buffer after a atransmission failure\n    void           restartTransmit();\n\n    void           setThisAddress(uint8_t thisAddress);\n\n    /// Sets the radio operating mode for the case when the driver is idle (ie not\n    /// transmitting or receiving), allowing you to control the idle mode power requirements\n    /// at the expense of slower transitions to transmit and receive modes.\n    /// By default, the idle mode is RH_RF22_XTON,\n    /// but eg setIdleMode(RH_RF22_PLL) will provide a much lower\n    /// idle current but slower transitions. Call this function after init().\n    /// \\param[in] idleMode The chip operating mode to use when the driver is idle. One of the valid definitions for RH_RF22_REG_07_OPERATING_MODE\n    void setIdleMode(uint8_t idleMode);\n\nprotected:\n    /// Low level interrupt service routine for RF22 connected to interrupt 0\n    static void         isr0();\n\n    /// Low level interrupt service routine for RF22 connected to interrupt 1\n    static void         isr1();\n\n    /// Low level interrupt service routine for RF22 connected to interrupt 1\n    static void         isr2();\n\n    /// Array of instances connected to interrupts 0 and 1\n    static RH_RF22*     _deviceForInterrupt[];\n\n    /// Index of next interrupt number to use in _deviceForInterrupt\n    static uint8_t      _interruptCount;\n\n    /// The configured interrupt pin connected to this instance\n    uint8_t             _interruptPin;\n\n    /// The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated)\n    /// else 0xff\n    uint8_t             _myInterruptIndex;\n\n    /// The radio mode to use when mode is idle\n    uint8_t             _idleMode; \n\n    /// The device type reported by the RF22\n    uint8_t             _deviceType;\n\n    /// The selected CRC polynomial\n    CRCPolynomial       _polynomial;\n\n    // These volatile members may get changed in the interrupt service routine\n    /// Number of octets in the receiver buffer\n    volatile uint8_t    _bufLen;\n    \n    /// The receiver buffer\n    uint8_t             _buf[RH_RF22_MAX_MESSAGE_LEN];\n\n    /// True when there is a valid message in the Rx buffer\n    volatile bool       _rxBufValid;\n\n    /// Index into TX buffer of the next to send chunk\n    volatile uint8_t    _txBufSentIndex;\n  \n    /// Time in millis since the last preamble was received (and the last time the RSSI was measured)\n    uint32_t            _lastPreambleTime;\n};\n\n/// @example rf22_client.pde\n/// @example rf22_server.pde\n\n#endif \n"
  },
  {
    "path": "RH_RF24.cpp",
    "content": "// RH_RF24.cpp\n//\n// Copyright (C) 2011 Mike McCauley\n// $Id: RH_RF24.cpp,v 1.18 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_RF24.h>\n// Generated with Silicon Labs WDS software:\n#include \"radio_config_Si4460.h\"\n\n// Interrupt vectors for the 3 Arduino interrupt pins\n// Each interrupt can be handled by a different instance of RH_RF24, allowing you to have\n// 2 or more RF24s per Arduino\nRH_RF24* RH_RF24::_deviceForInterrupt[RH_RF24_NUM_INTERRUPTS] = {0, 0, 0};\nuint8_t RH_RF24::_interruptCount = 0; // Index into _deviceForInterrupt for next device\n\n// This configuration data is defined in radio_config_Si4460.h \n// which was generated with the Silicon Labs WDS program\nPROGMEM const uint8_t RFM26_CONFIGURATION_DATA[] = RADIO_CONFIGURATION_DATA_ARRAY;\n\n// These configurations were all generated originally by the Silicon LAbs WDS configuration tool, configured with\n// a 30MHz XO. \n// The configurations were imported into RH_RF24, the complete properties set dumped to a file with printRegisters, then \n// RH_RF24_property_data/convert.pl was used to generate the entry for this table.\n// Contributions of new complete and tested ModemConfigs ready to add to this list will be readily accepted.\n// Casual suggestions of new schemes without working examples will probably be passed over.\n// Devices with an XO of other than 30MHz will result in incorrect radio frequency and other settings.\nPROGMEM static const RH_RF24::ModemConfig MODEM_CONFIG_TABLE[] =\n{\n    // These were generated with convert.pl from data in RH_RF24_property_data\n    // FSK_Rb0_5Fd1\n    { 0x02, 0x00, 0x13, 0x88, 0x01, 0x00, 0x00, 0x46, 0x01, 0x34, 0x11, 0x02, 0x71, 0x00, 0xd1, 0xb7, 0x00, 0x69, 0x02, 0x36, 0x80, 0x01, 0x5a, 0xfc, 0xe2, 0x11, 0x89, 0x89, 0x00, 0x02, 0xff, 0xff, 0x00, 0x2b, 0x02, 0x81, 0x00, 0xad, 0x3a, 0xff, 0xba, 0x0f, 0x51, 0xcf, 0xa9, 0xc9, 0xfc, 0x1b, 0x1e, 0x0f, 0x01, 0xfc, 0xfd, 0x15, 0xff, 0x00, 0x0f, 0xff, 0xba, 0x0f, 0x51, 0xcf, 0xa9, 0xc9, 0xfc, 0x1b, 0x1e, 0x0f, 0x01, 0xfc, 0xfd, 0x15, 0xff, 0x00, 0x0f, 0x3f, 0x2c, 0x0e, 0x04, 0x0c, 0x73, },\n\n    // FSK_Rb5Fd10\n    { 0x02, 0x00, 0xc3, 0x50, 0x01, 0x00, 0x02, 0xbb, 0x01, 0x30, 0x20, 0x01, 0x77, 0x01, 0x5d, 0x86, 0x00, 0xaf, 0x02, 0x36, 0x80, 0x0f, 0x15, 0x87, 0xe2, 0x11, 0x52, 0x52, 0x00, 0x02, 0xff, 0xff, 0x00, 0x2a, 0x02, 0x83, 0x01, 0x20, 0x40, 0xff, 0xba, 0x0f, 0x51, 0xcf, 0xa9, 0xc9, 0xfc, 0x1b, 0x1e, 0x0f, 0x01, 0xfc, 0xfd, 0x15, 0xff, 0x00, 0x0f, 0xff, 0xba, 0x0f, 0x51, 0xcf, 0xa9, 0xc9, 0xfc, 0x1b, 0x1e, 0x0f, 0x01, 0xfc, 0xfd, 0x15, 0xff, 0x00, 0x0f, 0x3f, 0x2c, 0x0e, 0x04, 0x0c, 0x73, },\n\n    // FSK_Rb50Fd100\n    { 0x02, 0x07, 0xa1, 0x20, 0x01, 0x00, 0x1b, 0x4f, 0x01, 0x00, 0x10, 0x00, 0xc8, 0x02, 0x8f, 0x5c, 0x01, 0x48, 0x02, 0x36, 0x80, 0x92, 0x0a, 0x46, 0xe2, 0x11, 0x2c, 0x2c, 0x00, 0x02, 0xff, 0xff, 0x00, 0x29, 0x02, 0x83, 0x02, 0x7f, 0x40, 0xff, 0xc4, 0x30, 0x7f, 0xf5, 0xb5, 0xb8, 0xde, 0x05, 0x17, 0x16, 0x0c, 0x03, 0x00, 0x15, 0xff, 0x00, 0x00, 0xff, 0xc4, 0x30, 0x7f, 0xf5, 0xb5, 0xb8, 0xde, 0x05, 0x17, 0x16, 0x0c, 0x03, 0x00, 0x15, 0xff, 0x00, 0x00, 0x3f, 0x2c, 0x0e, 0x04, 0x0c, 0x73, },\n  \n    //FSK_Rb150Fd300\n    { 0x02, 0x16, 0xe3, 0x60, 0x01, 0x00, 0x51, 0xec, 0x01, 0x00, 0x30, 0x00, 0xc8, 0x02, 0x8f, 0x5c, 0x01, 0x48, 0x02, 0x47, 0x83, 0x6a, 0x04, 0xb5, 0xe2, 0x22, 0x16, 0x16, 0x00, 0x02, 0xff, 0xff, 0x00, 0x29, 0x02, 0x83, 0x02, 0x7f, 0x40, 0xff, 0xc4, 0x30, 0x7f, 0xf5, 0xb5, 0xb8, 0xde, 0x05, 0x17, 0x16, 0x0c, 0x03, 0x00, 0x15, 0xff, 0x00, 0x00, 0xff, 0xc4, 0x30, 0x7f, 0xf5, 0xb5, 0xb8, 0xde, 0x05, 0x17, 0x16, 0x0c, 0x03, 0x00, 0x15, 0xff, 0x00, 0x00, 0x3f, 0x39, 0x04, 0x05, 0x04, 0x01, },\n\n    // GFSK_Rb0_5Fd1\n    { 0x03, 0x00, 0x4e, 0x20, 0x05, 0x00, 0x00, 0x46, 0x01, 0x34, 0x11, 0x02, 0x71, 0x00, 0xd1, 0xb7, 0x00, 0x69, 0x02, 0x36, 0x80, 0x01, 0x5a, 0xfc, 0xe2, 0x11, 0x89, 0x89, 0x00, 0x1a, 0xff, 0xff, 0x00, 0x2b, 0x02, 0x81, 0x00, 0x68, 0x3a, 0xff, 0xba, 0x0f, 0x51, 0xcf, 0xa9, 0xc9, 0xfc, 0x1b, 0x1e, 0x0f, 0x01, 0xfc, 0xfd, 0x15, 0xff, 0x00, 0x0f, 0xff, 0xba, 0x0f, 0x51, 0xcf, 0xa9, 0xc9, 0xfc, 0x1b, 0x1e, 0x0f, 0x01, 0xfc, 0xfd, 0x15, 0xff, 0x00, 0x0f, 0x3f, 0x2c, 0x0e, 0x04, 0x0c, 0x73, },\n\n    // GFSK_Rb5Fd10\n    { 0x03, 0x03, 0x0d, 0x40, 0x05, 0x00, 0x02, 0xbb, 0x01, 0x30, 0x20, 0x01, 0x77, 0x01, 0x5d, 0x86, 0x00, 0xaf, 0x02, 0x36, 0x80, 0x0f, 0x15, 0x87, 0xe2, 0x11, 0x52, 0x52, 0x00, 0x1a, 0xff, 0xff, 0x00, 0x2a, 0x02, 0x83, 0x00, 0xad, 0x40, 0xff, 0xba, 0x0f, 0x51, 0xcf, 0xa9, 0xc9, 0xfc, 0x1b, 0x1e, 0x0f, 0x01, 0xfc, 0xfd, 0x15, 0xff, 0x00, 0x0f, 0xff, 0xba, 0x0f, 0x51, 0xcf, 0xa9, 0xc9, 0xfc, 0x1b, 0x1e, 0x0f, 0x01, 0xfc, 0xfd, 0x15, 0xff, 0x00, 0x0f, 0x3f, 0x2c, 0x0e, 0x04, 0x0c, 0x73, },\n\n    // GFSK_Rb50Fd100\n    { 0x03, 0x0f, 0x42, 0x40, 0x09, 0x00, 0x1b, 0x4f, 0x01, 0x00, 0x10, 0x00, 0xc8, 0x02, 0x8f, 0x5c, 0x01, 0x48, 0x02, 0x36, 0x80, 0x92, 0x0a, 0x46, 0xe2, 0x11, 0x2c, 0x2c, 0x00, 0x1a, 0xff, 0xff, 0x00, 0x29, 0x02, 0x83, 0x01, 0x7f, 0x40, 0xff, 0xc4, 0x30, 0x7f, 0xf5, 0xb5, 0xb8, 0xde, 0x05, 0x17, 0x16, 0x0c, 0x03, 0x00, 0x15, 0xff, 0x00, 0x00, 0xff, 0xc4, 0x30, 0x7f, 0xf5, 0xb5, 0xb8, 0xde, 0x05, 0x17, 0x16, 0x0c, 0x03, 0x00, 0x15, 0xff, 0x00, 0x00, 0x3f, 0x2c, 0x0e, 0x04, 0x0c, 0x73, },\n\n    // GFSK_Rb150Fd300\n    { 0x03, 0x2d, 0xc6, 0xc0, 0x09, 0x00, 0x51, 0xec, 0x01, 0x00, 0x30, 0x00, 0xc8, 0x02, 0x8f, 0x5c, 0x01, 0x48, 0x02, 0x47, 0x83, 0x6a, 0x04, 0xb5, 0xe2, 0x22, 0x16, 0x16, 0x00, 0x1a, 0xff, 0xff, 0x00, 0x29, 0x02, 0x83, 0x01, 0x7f, 0x40, 0xff, 0xc4, 0x30, 0x7f, 0xf5, 0xb5, 0xb8, 0xde, 0x05, 0x17, 0x16, 0x0c, 0x03, 0x00, 0x15, 0xff, 0x00, 0x00, 0xff, 0xc4, 0x30, 0x7f, 0xf5, 0xb5, 0xb8, 0xde, 0x05, 0x17, 0x16, 0x0c, 0x03, 0x00, 0x15, 0xff, 0x00, 0x00, 0x3f, 0x39, 0x04, 0x05, 0x04, 0x01, },\n\n    // OOK_Rb5Bw30\n    { 0x01, 0x00, 0xc3, 0x50, 0x01, 0x00, 0x00, 0x00, 0x00, 0x34, 0x10, 0x00, 0x3f, 0x08, 0x31, 0x27, 0x04, 0x10, 0x02, 0x12, 0x00, 0x2c, 0x03, 0xf9, 0x62, 0x11, 0x0e, 0x0e, 0x00, 0x02, 0xff, 0xff, 0x00, 0x27, 0x00, 0x00, 0x07, 0xff, 0x40, 0xcc, 0xa1, 0x30, 0xa0, 0x21, 0xd1, 0xb9, 0xc9, 0xea, 0x05, 0x12, 0x11, 0x0a, 0x04, 0x15, 0xfc, 0x03, 0x00, 0xcc, 0xa1, 0x30, 0xa0, 0x21, 0xd1, 0xb9, 0xc9, 0xea, 0x05, 0x12, 0x11, 0x0a, 0x04, 0x15, 0xfc, 0x03, 0x00, 0x3f, 0x2c, 0x0e, 0x04, 0x0c, 0x73, },\n\n    // OOK_Rb10Bw40\n    { 0x01, 0x01, 0x86, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x32, 0x20, 0x00, 0x5e, 0x05, 0x76, 0x1a, 0x02, 0xb9, 0x02, 0x12, 0x00, 0x57, 0x02, 0xb0, 0x62, 0x11, 0x15, 0x15, 0x00, 0x02, 0xff, 0xff, 0x00, 0x28, 0x00, 0x00, 0x07, 0xff, 0x40, 0xa2, 0x81, 0x26, 0xaf, 0x3f, 0xee, 0xc8, 0xc7, 0xdb, 0xf2, 0x02, 0x08, 0x07, 0x03, 0x15, 0xfc, 0x0f, 0x00, 0xa2, 0x81, 0x26, 0xaf, 0x3f, 0xee, 0xc8, 0xc7, 0xdb, 0xf2, 0x02, 0x08, 0x07, 0x03, 0x15, 0xfc, 0x0f, 0x00, 0x3f, 0x2c, 0x0e, 0x04, 0x0c, 0x73, },\n\n};\n\nRH_RF24::RH_RF24(uint8_t slaveSelectPin, uint8_t interruptPin, uint8_t sdnPin, RHGenericSPI& spi)\n    :\n    RHSPIDriver(slaveSelectPin, spi)\n{\n    _interruptPin = interruptPin;\n    _sdnPin = sdnPin;\n    _idleMode = RH_RF24_DEVICE_STATE_READY;\n    _myInterruptIndex = 0xff; // Not allocated yet\n}\n\nvoid RH_RF24::setIdleMode(uint8_t idleMode)\n{\n    _idleMode = idleMode;\n}\n\nbool RH_RF24::init()\n{\n    if (!RHSPIDriver::init())\n\treturn false;\n\n    // Determine the interrupt number that corresponds to the interruptPin\n    int interruptNumber = digitalPinToInterrupt(_interruptPin);\n    if (interruptNumber == NOT_AN_INTERRUPT)\n\treturn false;\n#ifdef RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER\n    interruptNumber = _interruptPin;\n#endif\n\n    // Initialise the radio\n    power_on_reset();\n    cmd_clear_all_interrupts();\n    // Here we use a configuration generated by the Silicon Las Wireless Development Suite\n    // in radio_config_Si4460.h\n    // WE override a few things later that we ned to be sure of.\n    configure(RFM26_CONFIGURATION_DATA);\n\n    // Get the device type and check it\n    // This also tests whether we are really connected to a device\n    uint8_t buf[8];\n    if (!command(RH_RF24_CMD_PART_INFO, 0, 0, buf, sizeof(buf)))\n\treturn false; // SPI error? Not connected?\n    _deviceType = (buf[1] << 8) | buf[2];\n    // Check PART to be either 0x4460, 0x4461, 0x4463, 0x4464\n    if (_deviceType != 0x4460 &&\n\t_deviceType != 0x4461 &&\n\t_deviceType != 0x4463 &&\n\t_deviceType != 0x4464)\n\treturn false; // Unknown radio type, or not connected\n\n    // Add by Adrien van den Bossche <vandenbo@univ-tlse2.fr> for Teensy\n    // ARM M4 requires the below. else pin interrupt doesn't work properly.\n    // On all other platforms, its innocuous, belt and braces\n    pinMode(_interruptPin, INPUT); \n\n    // Set up interrupt handler\n    // Since there are a limited number of interrupt glue functions isr*() available,\n    // we can only support a limited number of devices simultaneously\n    // ON some devices, notably most Arduinos, the interrupt pin passed in is actuallt the \n    // interrupt number. You have to figure out the interruptnumber-to-interruptpin mapping\n    // yourself based on knwledge of what Arduino board you are running on.\n    if (_myInterruptIndex == 0xff)\n    {\n\t// First run, no interrupt allocated yet\n\tif (_interruptCount <= RH_RF24_NUM_INTERRUPTS)\n\t    _myInterruptIndex = _interruptCount++;\n\telse\n\t    return false; // Too many devices, not enough interrupt vectors\n    }\n    _deviceForInterrupt[_myInterruptIndex] = this;\n    if (_myInterruptIndex == 0)\n\tattachInterrupt(interruptNumber, isr0, FALLING);\n    else if (_myInterruptIndex == 1)\n\tattachInterrupt(interruptNumber, isr1, FALLING);\n    else if (_myInterruptIndex == 2)\n\tattachInterrupt(interruptNumber, isr2, FALLING);\n    else\n\treturn false; // Too many devices, not enough interrupt vectors\n\n    // Ensure we get the interrupts we need, irrespective of whats in the radio_config\n    uint8_t int_ctl[] = {RH_RF24_MODEM_INT_STATUS_EN | RH_RF24_PH_INT_STATUS_EN, 0xff, 0xff, 0x00 };\n    set_properties(RH_RF24_PROPERTY_INT_CTL_ENABLE, int_ctl, sizeof(int_ctl));\n\n    // RSSI Latching should be configured in MODEM_RSSI_CONTROL in radio_config\n\n    // PKT_TX_THRESHOLD and PKT_RX_THRESHOLD should be set to about 0x30 in radio_config\n\n    // Configure important RH_RF24 registers\n    // Here we set up the standard packet format for use by the RH_RF24 library:\n    // We will use FIFO Mode, with automatic packet generation\n    // We have 2 fields:\n    // Field 1 contains only the (variable) length of field 2, with CRC\n    // Field 2 contains the variable length payload and the CRC\n    // Hmmm, having no CRC on field 1 and CRC on field 2 causes CRC errors when resetting after an odd\n    // number of packets! Anyway its prob a good thing at the cost of some airtime.\n    // Hmmm, enabling WHITEN stops it working!\n    uint8_t pkt_config1[] = { 0x00 };\n    set_properties(RH_RF24_PROPERTY_PKT_CONFIG1, pkt_config1, sizeof(pkt_config1));\n\n    uint8_t pkt_len[] = { 0x02, 0x01, 0x00 };\n    set_properties(RH_RF24_PROPERTY_PKT_LEN, pkt_len, sizeof(pkt_len));\n\n    uint8_t pkt_field1[] = { 0x00, 0x01, 0x00, RH_RF24_FIELD_CONFIG_CRC_START | RH_RF24_FIELD_CONFIG_SEND_CRC | RH_RF24_FIELD_CONFIG_CHECK_CRC | RH_RF24_FIELD_CONFIG_CRC_ENABLE };\n    set_properties(RH_RF24_PROPERTY_PKT_FIELD_1_LENGTH_12_8, pkt_field1, sizeof(pkt_field1));\n\n    uint8_t pkt_field2[] = { 0x00, sizeof(_buf), 0x00, RH_RF24_FIELD_CONFIG_CRC_START | RH_RF24_FIELD_CONFIG_SEND_CRC | RH_RF24_FIELD_CONFIG_CHECK_CRC | RH_RF24_FIELD_CONFIG_CRC_ENABLE };\n    set_properties(RH_RF24_PROPERTY_PKT_FIELD_2_LENGTH_12_8, pkt_field2, sizeof(pkt_field2));\n\n    // Clear all other fields so they are never used, irrespective of the radio_config\n    uint8_t pkt_fieldn[] = { 0x00, 0x00, 0x00, 0x00 };\n    set_properties(RH_RF24_PROPERTY_PKT_FIELD_3_LENGTH_12_8, pkt_fieldn, sizeof(pkt_fieldn));\n    set_properties(RH_RF24_PROPERTY_PKT_FIELD_4_LENGTH_12_8, pkt_fieldn, sizeof(pkt_fieldn));\n    set_properties(RH_RF24_PROPERTY_PKT_FIELD_5_LENGTH_12_8, pkt_fieldn, sizeof(pkt_fieldn));\n\n    // The following can be changed later by the user if necessary.\n    // Set up default configuration\n    setCRCPolynomial(CRC_16_IBM);\n    uint8_t syncwords[] = { 0x2d, 0xd4 };\n    setSyncWords(syncwords, sizeof(syncwords)); // Same as RF22's\n    // Reasonably fast and reliable default speed and modulation\n    setModemConfig(GFSK_Rb5Fd10);\n    // 3 would be sufficient, but this is the same as RF22's\n    // actualy, 4 seems to work much better for some modulations\n    setPreambleLength(4);\n    // An innocuous ISM frequency, same as RF22's\n    setFrequency(434.0);\n    // About 2.4dBm on RFM24:\n    setTxPower(0x10); \n\n    return true;\n}\n\n// C++ level interrupt handler for this instance\nvoid RH_RF24::handleInterrupt()\n{\n    uint8_t status[8];\n    command(RH_RF24_CMD_GET_INT_STATUS, NULL, 0, status, sizeof(status));\n\n    // Decode and handle the interrupt bits we are interested in\n//    if (status[0] & RH_RF24_INT_STATUS_CHIP_INT_STATUS)\n    if (status[0] & RH_RF24_INT_STATUS_MODEM_INT_STATUS)\n    {\n//\tif (status[4] & RH_RF24_INT_STATUS_INVALID_PREAMBLE)\n\tif (status[4] & RH_RF24_INT_STATUS_INVALID_SYNC)\n\t{\n\t    // After INVALID_SYNC, sometimes the radio gets into a silly state and subsequently reports it for every packet\n\t    // Need to reset the radio and clear the RX FIFO, cause sometimes theres junk there too\n\t    _mode = RHModeIdle;\n\t    clearRxFifo();\n\t    clearBuffer();\n\t}\n    }\n    if (status[0] & RH_RF24_INT_STATUS_PH_INT_STATUS)\n    {\n\tif (status[2] & RH_RF24_INT_STATUS_CRC_ERROR)\n\t{\n\t    // CRC Error\n\t    // Radio automatically went to _idleMode\n\t    _mode = RHModeIdle;\n\t    _rxBad++;\n\n\t    clearRxFifo();\n\t    clearBuffer();\n\t}\n\tif (status[2] & RH_RF24_INT_STATUS_PACKET_SENT)\n\t{\n\t    _txGood++; \n\t    // Transmission does not automatically clear the tx buffer.\n\t    // Could retransmit if we wanted\n\t    // RH_RF24 configured to transition automatically to Idle after packet sent\n\t    _mode = RHModeIdle;\n\t    clearBuffer();\n\t}\n\tif (status[2] & RH_RF24_INT_STATUS_PACKET_RX)\n\t{\n\t    // A complete message has been received with good CRC\n\t    // Get the RSSI, configured to latch at sync detect in radio_config\n\t    uint8_t modem_status[6];\n\t    command(RH_RF24_CMD_GET_MODEM_STATUS, NULL, 0, modem_status, sizeof(modem_status));\n\t    _lastRssi = modem_status[3];\n\t    _lastPreambleTime = millis();\n\t    \n\t    // Save it in our buffer\n\t    readNextFragment();\n\t    // And see if we have a valid message\n\t    validateRxBuf();\n\t    // Radio will have transitioned automatically to the _idleMode\n\t    _mode = RHModeIdle;\n\t}\n\tif (status[2] & RH_RF24_INT_STATUS_TX_FIFO_ALMOST_EMPTY)\n\t{\n\t    // TX FIFO almost empty, maybe send another chunk, if there is one\n\t    sendNextFragment();\n\t}\n\tif (status[2] & RH_RF24_INT_STATUS_RX_FIFO_ALMOST_FULL)\n\t{\n\t    // Some more data to read, get it\n\t    readNextFragment();\n\t}\n    }\n}\n\n// Check whether the latest received message is complete and uncorrupted\nvoid RH_RF24::validateRxBuf()\n{\n    // Validate headers etc\n    if (_bufLen >= RH_RF24_HEADER_LEN)\n    {\n\t_rxHeaderTo    = _buf[0];\n\t_rxHeaderFrom  = _buf[1];\n\t_rxHeaderId    = _buf[2];\n\t_rxHeaderFlags = _buf[3];\n\tif (_promiscuous ||\n\t    _rxHeaderTo == _thisAddress ||\n\t    _rxHeaderTo == RH_BROADCAST_ADDRESS)\n\t{\n\t    // Its for us\n\t    _rxGood++;\n\t    _rxBufValid = true;\n\t}\n    }\n}\n\nbool RH_RF24::clearRxFifo()\n{\n    uint8_t fifo_clear[] = { 0x02 };\n    return command(RH_RF24_CMD_FIFO_INFO, fifo_clear, sizeof(fifo_clear));\n}\n\nvoid RH_RF24::clearBuffer()\n{\n    _bufLen = 0;\n    _txBufSentIndex = 0;\n    _rxBufValid = false;\n}\n\n// These are low level functions that call the interrupt handler for the correct\n// instance of RH_RF24.\n// 3 interrupts allows us to have 3 different devices\nvoid RH_RF24::isr0()\n{\n    if (_deviceForInterrupt[0])\n\t_deviceForInterrupt[0]->handleInterrupt();\n}\nvoid RH_RF24::isr1()\n{\n    if (_deviceForInterrupt[1])\n\t_deviceForInterrupt[1]->handleInterrupt();\n}\nvoid RH_RF24::isr2()\n{\n    if (_deviceForInterrupt[2])\n\t_deviceForInterrupt[2]->handleInterrupt();\n}\n\nbool RH_RF24::available()\n{\n    if (_mode == RHModeTx)\n\treturn false;\n    if (!_rxBufValid)\n\tsetModeRx(); // Make sure we are receiving\n    return _rxBufValid;\n}\n\nbool RH_RF24::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n    // CAUTION: first 4 octets of _buf contain the headers\n    if (buf && len && (_bufLen >= RH_RF24_HEADER_LEN))\n    {\n\tATOMIC_BLOCK_START;\n\tif (*len > _bufLen - RH_RF24_HEADER_LEN)\n\t    *len = _bufLen - RH_RF24_HEADER_LEN;\n\tmemcpy(buf, _buf + RH_RF24_HEADER_LEN, *len);\n\tATOMIC_BLOCK_END;\n    }\n    clearBuffer(); // Got the most recent message\n    return true;\n}\n\nbool RH_RF24::send(const uint8_t* data, uint8_t len)\n{\n    if (len > RH_RF24_MAX_MESSAGE_LEN)\n\treturn false;\n\n    waitPacketSent(); // Make sure we dont interrupt an outgoing message\n    setModeIdle(); // Prevent RX while filling the fifo\n\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    // Put the payload in the FIFO\n    // First the length in fixed length field 1. This wont appear in the receiver fifo since\n    // we have turned off IN_FIFO in PKT_LEN\n    _buf[0] = len + RH_RF24_HEADER_LEN;\n    // Now the rest of the payload in variable length field 2\n    // First the headers\n    _buf[1] = _txHeaderTo;\n    _buf[2] = _txHeaderFrom;\n    _buf[3] = _txHeaderId;\n    _buf[4] = _txHeaderFlags;\n    // Then the message\n    memcpy(_buf + 1 + RH_RF24_HEADER_LEN, data, len);\n    _bufLen = len + 1 + RH_RF24_HEADER_LEN;\n    _txBufSentIndex = 0;\n\n    // Set the field 2 length to the variable payload length\n    uint8_t l[] = { (uint8_t)(len + RH_RF24_HEADER_LEN)};\n    set_properties(RH_RF24_PROPERTY_PKT_FIELD_2_LENGTH_7_0, l, sizeof(l));\n\n    sendNextFragment();\n    setModeTx();\n    return true;\n}\n\n// This is different to command() since we must not wait for CTS\nbool RH_RF24::writeTxFifo(uint8_t *data, uint8_t len)\n{\n    ATOMIC_BLOCK_START;\n    // First send the command\n    digitalWrite(_slaveSelectPin, LOW);\n    _spi.transfer(RH_RF24_CMD_TX_FIFO_WRITE);\n    // Now write any write data\n    while (len--)\n\t_spi.transfer(*data++);\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return true;\n}\n\nvoid RH_RF24::sendNextFragment()\n{\n    if (_txBufSentIndex < _bufLen)\n    {\n\t// Some left to send?\n\tuint8_t len = _bufLen - _txBufSentIndex;\n\t// But dont send too much, see how much room is left\n\tuint8_t fifo_info[2];\n\tcommand(RH_RF24_CMD_FIFO_INFO, NULL, 0, fifo_info, sizeof(fifo_info));\n\t// fifo_info[1] is space left in TX FIFO\n\tif (len > fifo_info[1])\n\t    len = fifo_info[1];\n\n\twriteTxFifo(_buf + _txBufSentIndex, len);\n\t_txBufSentIndex += len;\n    }\n}\n\nvoid RH_RF24::readNextFragment()\n{\n    // Get the packet length from the RX FIFO length\n    uint8_t fifo_info[1];\n    command(RH_RF24_CMD_FIFO_INFO, NULL, 0, fifo_info, sizeof(fifo_info));\n    uint8_t fifo_len = fifo_info[0]; \n\n    // Check for overflow\n    if ((_bufLen + fifo_len) > sizeof(_buf))\n    {\n\t// Overflow pending\n\t_rxBad++;\n\tsetModeIdle();\n\tclearRxFifo();\n\tclearBuffer();\n\treturn;\n    }\n    // So we have room\n    // Now read the fifo_len bytes from the RX FIFO\n    // This is different to command() since we dont wait for CTS\n    digitalWrite(_slaveSelectPin, LOW);\n    _spi.transfer(RH_RF24_CMD_RX_FIFO_READ);\n    uint8_t* p = _buf + _bufLen;\n    uint8_t l = fifo_len;\n    while (l--)\n\t*p++ = _spi.transfer(0);\n    digitalWrite(_slaveSelectPin, HIGH);\n    _bufLen += fifo_len;\n}\n\nuint8_t RH_RF24::maxMessageLength()\n{\n    return RH_RF24_MAX_MESSAGE_LEN;\n}\n\n// Sets registers from a canned modem configuration structure\nvoid RH_RF24::setModemRegisters(const ModemConfig* config)\n{\n    // This list also generated with convert.pl\n    set_properties(0x2000, &config->prop_2000, 1);\n    set_properties(0x2003, &config->prop_2003, 1);\n    set_properties(0x2004, &config->prop_2004, 1);\n    set_properties(0x2005, &config->prop_2005, 1);\n    set_properties(0x2006, &config->prop_2006, 1);\n    set_properties(0x200b, &config->prop_200b, 1);\n    set_properties(0x200c, &config->prop_200c, 1);\n    set_properties(0x2018, &config->prop_2018, 1);\n    set_properties(0x201e, &config->prop_201e, 1);\n    set_properties(0x201f, &config->prop_201f, 1);\n    set_properties(0x2022, &config->prop_2022, 1);\n    set_properties(0x2023, &config->prop_2023, 1);\n    set_properties(0x2024, &config->prop_2024, 1);\n    set_properties(0x2025, &config->prop_2025, 1);\n    set_properties(0x2026, &config->prop_2026, 1);\n    set_properties(0x2027, &config->prop_2027, 1);\n    set_properties(0x2028, &config->prop_2028, 1);\n    set_properties(0x2029, &config->prop_2029, 1);\n    set_properties(0x202d, &config->prop_202d, 1);\n    set_properties(0x202e, &config->prop_202e, 1);\n    set_properties(0x202f, &config->prop_202f, 1);\n    set_properties(0x2030, &config->prop_2030, 1);\n    set_properties(0x2031, &config->prop_2031, 1);\n    set_properties(0x2035, &config->prop_2035, 1);\n    set_properties(0x2038, &config->prop_2038, 1);\n    set_properties(0x2039, &config->prop_2039, 1);\n    set_properties(0x203a, &config->prop_203a, 1);\n    set_properties(0x203b, &config->prop_203b, 1);\n    set_properties(0x203c, &config->prop_203c, 1);\n    set_properties(0x203d, &config->prop_203d, 1);\n    set_properties(0x203e, &config->prop_203e, 1);\n    set_properties(0x203f, &config->prop_203f, 1);\n    set_properties(0x2040, &config->prop_2040, 1);\n    set_properties(0x2043, &config->prop_2043, 1);\n    set_properties(0x2045, &config->prop_2045, 1);\n    set_properties(0x2046, &config->prop_2046, 1);\n    set_properties(0x2047, &config->prop_2047, 1);\n    set_properties(0x204e, &config->prop_204e, 1);\n    set_properties(0x2100, &config->prop_2100, 1);\n    set_properties(0x2101, &config->prop_2101, 1);\n    set_properties(0x2102, &config->prop_2102, 1);\n    set_properties(0x2103, &config->prop_2103, 1);\n    set_properties(0x2104, &config->prop_2104, 1);\n    set_properties(0x2105, &config->prop_2105, 1);\n    set_properties(0x2106, &config->prop_2106, 1);\n    set_properties(0x2107, &config->prop_2107, 1);\n    set_properties(0x2108, &config->prop_2108, 1);\n    set_properties(0x2109, &config->prop_2109, 1);\n    set_properties(0x210a, &config->prop_210a, 1);\n    set_properties(0x210b, &config->prop_210b, 1);\n    set_properties(0x210c, &config->prop_210c, 1);\n    set_properties(0x210d, &config->prop_210d, 1);\n    set_properties(0x210e, &config->prop_210e, 1);\n    set_properties(0x210f, &config->prop_210f, 1);\n    set_properties(0x2110, &config->prop_2110, 1);\n    set_properties(0x2111, &config->prop_2111, 1);\n    set_properties(0x2112, &config->prop_2112, 1);\n    set_properties(0x2113, &config->prop_2113, 1);\n    set_properties(0x2114, &config->prop_2114, 1);\n    set_properties(0x2115, &config->prop_2115, 1);\n    set_properties(0x2116, &config->prop_2116, 1);\n    set_properties(0x2117, &config->prop_2117, 1);\n    set_properties(0x2118, &config->prop_2118, 1);\n    set_properties(0x2119, &config->prop_2119, 1);\n    set_properties(0x211a, &config->prop_211a, 1);\n    set_properties(0x211b, &config->prop_211b, 1);\n    set_properties(0x211c, &config->prop_211c, 1);\n    set_properties(0x211d, &config->prop_211d, 1);\n    set_properties(0x211e, &config->prop_211e, 1);\n    set_properties(0x211f, &config->prop_211f, 1);\n    set_properties(0x2120, &config->prop_2120, 1);\n    set_properties(0x2121, &config->prop_2121, 1);\n    set_properties(0x2122, &config->prop_2122, 1);\n    set_properties(0x2123, &config->prop_2123, 1);\n    set_properties(0x2203, &config->prop_2203, 1);\n    set_properties(0x2300, &config->prop_2300, 1);\n    set_properties(0x2301, &config->prop_2301, 1);\n    set_properties(0x2303, &config->prop_2303, 1);\n    set_properties(0x2304, &config->prop_2304, 1);\n    set_properties(0x2305, &config->prop_2305, 1);\n}\n\n// Set one of the canned Modem configs\n// Returns true if its a valid choice\nbool RH_RF24::setModemConfig(ModemConfigChoice index)\n{\n    if (index > (signed int)(sizeof(MODEM_CONFIG_TABLE) / sizeof(ModemConfig)))\n        return false;\n\n    ModemConfig cfg;\n    memcpy_P(&cfg, &MODEM_CONFIG_TABLE[index], sizeof(RH_RF24::ModemConfig));\n    setModemRegisters(&cfg);\n\n    return true;\n}\n\nvoid RH_RF24::setPreambleLength(uint16_t bytes)\n{\n    uint8_t config[] = { (uint8_t)bytes, 0x14, 0x00, 0x00, \n\t\t\t RH_RF24_PREAMBLE_FIRST_1 | RH_RF24_PREAMBLE_LENGTH_BYTES | RH_RF24_PREAMBLE_STANDARD_1010};\n    set_properties(RH_RF24_PROPERTY_PREAMBLE_TX_LENGTH, config, sizeof(config));\n}\n\nbool RH_RF24::setCRCPolynomial(CRCPolynomial polynomial)\n{\n    if (polynomial >= CRC_NONE &&\n\tpolynomial <= CRC_Castagnoli)\n    {\n\t// Caution this only has effect if CRCs are enabled\n\tuint8_t config[] = { (uint8_t)((polynomial & RH_RF24_CRC_MASK) | RH_RF24_CRC_SEED_ALL_1S) };\n\treturn set_properties(RH_RF24_PROPERTY_PKT_CRC_CONFIG, config, sizeof(config));\n    }\n    else\n\treturn false;\n}\n\nvoid RH_RF24::setSyncWords(const uint8_t* syncWords, uint8_t len)\n{\n    if (len > 4 || len < 1)\n\treturn;\n    uint8_t config[] = { (uint8_t)(len-1), 0, 0, 0, 0};\n    memcpy(config+1, syncWords, len);\n    set_properties(RH_RF24_PROPERTY_SYNC_CONFIG, config, sizeof(config));\n}\n\nbool RH_RF24::setFrequency(float centre, float afcPullInRange)\n{\n    // See Si446x Data Sheet section 5.3.1\n    // Also the Si446x PLL Synthesizer / VCO_CNT Calculator Rev 0.4\n    uint8_t outdiv;\n    uint8_t band;\n    if (_deviceType == 0x4460 ||\n\t_deviceType == 0x4461 ||\n\t_deviceType == 0x4463)\n    {\n\t// Non-continuous frequency bands\n\tif (centre <= 1050.0 && centre >= 850.0)\n\t    outdiv = 4, band = 0;\n\telse if (centre <= 525.0 && centre >= 425.0)\n\t    outdiv = 8, band = 2;\n\telse if (centre <= 350.0 && centre >= 284.0)\n\t    outdiv = 12, band = 3;\n\telse if (centre <= 175.0 && centre >= 142.0)\n\t    outdiv = 24, band = 5;\n\telse \n\t    return false;\n    }\n    else\n    {\n\t// 0x4464\n\t// Continuous frequency bands\n\tif (centre <= 960.0 && centre >= 675.0)\n\t    outdiv = 4, band = 1;\n\telse if (centre < 675.0 && centre >= 450.0)\n\t    outdiv = 6, band = 2;\n\telse if (centre < 450.0 && centre >= 338.0)\n\t    outdiv = 8, band = 3;\n\telse if (centre < 338.0 && centre >= 225.0)\n\t    outdiv = 12, band = 4;\n\telse if (centre < 225.0 && centre >= 169.0)\n\t    outdiv = 16, band = 4;\n\telse if (centre < 169.0 && centre >= 119.0)\n\t    outdiv = 24, band = 5;\n\telse \n\t    return false;\n    }\n\n    // Set the MODEM_CLKGEN_BAND (not documented)\n    uint8_t modem_clkgen[] = { (uint8_t)(band + 8) };\n    if (!set_properties(RH_RF24_PROPERTY_MODEM_CLKGEN_BAND, modem_clkgen, sizeof(modem_clkgen)))\n\treturn false;\n\n    centre *= 1000000.0; // Convert to Hz\n\n    // Now generate the RF frequency properties\n    // Need the Xtal/XO freq from the radio_config file:\n    uint32_t xtal_frequency[1] = RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ;\n    unsigned long f_pfd = 2 * xtal_frequency[0] / outdiv;\n    unsigned int n = ((unsigned int)(centre / f_pfd)) - 1;\n    float ratio = centre / (float)f_pfd;\n    float rest  = ratio - (float)n;\n    unsigned long m = (unsigned long)(rest * 524288UL); \n    unsigned int m2 = m / 0x10000;\n    unsigned int m1 = (m - m2 * 0x10000) / 0x100;\n    unsigned int m0 = (m - m2 * 0x10000 - m1 * 0x100); \n\n    // PROP_FREQ_CONTROL_GROUP\n    uint8_t freq_control[] = { (uint8_t)n, (uint8_t)m2, (uint8_t)m1, (uint8_t)m0 };\n    return set_properties(RH_RF24_PROPERTY_FREQ_CONTROL_INTE, freq_control, sizeof(freq_control));\n}\n\nvoid RH_RF24::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\t// Set the antenna switch pins using the GPIO, assuming we have an RFM module with antenna switch\n\tuint8_t config[] = { RH_RF24_GPIO_HIGH, RH_RF24_GPIO_HIGH };\n\tcommand(RH_RF24_CMD_GPIO_PIN_CFG, config, sizeof(config));\n\n\tuint8_t state[] = { _idleMode };\n\tcommand(RH_RF24_CMD_REQUEST_DEVICE_STATE, state, sizeof(state));\n\t_mode = RHModeIdle;\n    }\n}\n\nbool RH_RF24::sleep()\n{\n    if (_mode != RHModeSleep)\n    {\n\tuint8_t state[] = { RH_RF24_DEVICE_STATE_SLEEP };\n\tcommand(RH_RF24_CMD_REQUEST_DEVICE_STATE, state, sizeof(state));\n\n\t_mode = RHModeSleep;\n    }\n    return true;\n}\n\nvoid RH_RF24::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\t// CAUTION: we cant clear the rx buffers here, else we set up a race condition\n\t// with the _rxBufValid test in available()\n\n\t// Tell the receiver the max data length we will accept (a TX may have changed it)\n\tuint8_t l[] = { sizeof(_buf) };\n\tset_properties(RH_RF24_PROPERTY_PKT_FIELD_2_LENGTH_7_0, l, sizeof(l));\n\t\n\t// Set the antenna switch pins using the GPIO, assuming we have an RFM module with antenna switch\n\tuint8_t gpio_config[] = { RH_RF24_GPIO_HIGH, RH_RF24_GPIO_LOW };\n\tcommand(RH_RF24_CMD_GPIO_PIN_CFG, gpio_config, sizeof(gpio_config));\n\n\tuint8_t rx_config[] = { 0x00, RH_RF24_CONDITION_RX_START_IMMEDIATE, 0x00, 0x00, _idleMode, _idleMode, _idleMode};\n\tcommand(RH_RF24_CMD_START_RX, rx_config, sizeof(rx_config));\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_RF24::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\t// Set the antenna switch pins using the GPIO, assuming we have an RFM module with antenna switch\n\tuint8_t config[] = { RH_RF24_GPIO_LOW, RH_RF24_GPIO_HIGH };\n\tcommand(RH_RF24_CMD_GPIO_PIN_CFG, config, sizeof(config));\n\n\tuint8_t tx_params[] = { 0x00, \n\t\t\t\t(uint8_t)((_idleMode << 4) | RH_RF24_CONDITION_RETRANSMIT_NO | RH_RF24_CONDITION_START_IMMEDIATE)};\n\tcommand(RH_RF24_CMD_START_TX, tx_params, sizeof(tx_params));\n\t_mode = RHModeTx;\n    }\n}\n\nvoid RH_RF24::setTxPower(uint8_t power)\n{\n    uint8_t pa_bias_clkduty = 0;\n    // These calculations valid for advertised power from Si chips at Vcc = 3.3V\n    // you may get lower power from RFM modules, depending on Vcc voltage, antenna etc\n    if (_deviceType == 0x4460)\n    {\n\t// 0x4f = 13dBm\n\tpa_bias_clkduty = 0xc0;\n\tif (power > 0x4f)\n\t    power = 0x4f;\n    }\n    else if (_deviceType == 0x4461)\n    {\n\t// 0x7f = 16dBm\n\tpa_bias_clkduty = 0xc0;\n\tif (power > 0x7f)\n\t    power = 0x7f;\n    }\n    else if (_deviceType == 0x4463 || _deviceType == 0x4464 )\n    {\n\t// 0x7f = 20dBm\n\tpa_bias_clkduty = 0x00; // Per WDS suggestion\n\tif (power > 0x7f)\n\t    power = 0x7f;\n    }\n    uint8_t power_properties[] = {0x18, 0x00, 0x00 }; // PA_MODE from WDS sugggestions (why?)\n    power_properties[1] = power;\n    power_properties[2] = pa_bias_clkduty;\n    set_properties(RH_RF24_PROPERTY_PA_MODE, power_properties, sizeof(power_properties));\n}\n\n// Caution: There was a bug in A1 hardware that will not handle 1 byte commands. \nbool RH_RF24::command(uint8_t cmd, const uint8_t* write_buf, uint8_t write_len, uint8_t* read_buf, uint8_t read_len)\n{\n    bool   done = false;\n\n    ATOMIC_BLOCK_START;\n    // First send the command\n    digitalWrite(_slaveSelectPin, LOW);\n    _spi.transfer(cmd);\n\n    // Now write any write data\n    if (write_buf && write_len)\n    {\n\twhile (write_len--)\n\t    _spi.transfer(*write_buf++);\n    }\n    // Sigh, the RFM26 at least has problems if we deselect too quickly :-(\n    // Innocuous timewaster:\n    digitalWrite(_slaveSelectPin, LOW);\n    // And finalise the command\n    digitalWrite(_slaveSelectPin, HIGH);\n\n    uint16_t count; // Number of times we have tried to get CTS\n    for (count = 0; !done && count < RH_RF24_CTS_RETRIES; count++)\n    {\n\t// Wait for the CTS\n\tdigitalWrite(_slaveSelectPin, LOW);\n\n\t_spi.transfer(RH_RF24_CMD_READ_BUF);\n\tif (_spi.transfer(0) == RH_RF24_REPLY_CTS)\n\t{\n\t    // Now read any expected reply data\n\t    if (read_buf && read_len)\n\t    {\n\t\twhile (read_len--)\n\t\t{\n\t\t    *read_buf++ = _spi.transfer(0);\n\t\t}\n\t    }\n\t    done = true;\n\t}\n\t// Sigh, the RFM26 at least has problems if we deselect too quickly :-(\n\t// Innocuous timewaster:\n\tdigitalWrite(_slaveSelectPin, LOW);\n\t// Finalise the read\n\tdigitalWrite(_slaveSelectPin, HIGH);\n    }\n    ATOMIC_BLOCK_END;\n    return done; // False if too many attempts at CTS\n}\n\nbool RH_RF24::configure(const uint8_t* commands)\n{\n    // Command strings are constructed in radio_config_Si4460.h \n    // Each command starts with a count of the bytes in that command:\n    // <bytecount> <command> <bytecount-2 bytes of args/data>\n    uint8_t next_cmd_len;\n    \n    while (memcpy_P(&next_cmd_len, commands, 1), next_cmd_len > 0)\n    {\n\tuint8_t buf[20]; // As least big as the biggest permitted command/property list of 15\n\tmemcpy_P(buf, commands+1, next_cmd_len);\n\tcommand(buf[0], buf+1, next_cmd_len - 1);\n\tcommands += (next_cmd_len + 1);\n    }\n    return true;\n}\n\nvoid RH_RF24::power_on_reset()\n{\n    // Sigh: its necessary to control the SDN pin to reset this ship. \n    // Tying it to GND does not produce reliable startups\n    // Per Si4464 Data Sheet 3.3.2\n    digitalWrite(_sdnPin, HIGH); // So we dont get a glitch after setting pinMode OUTPUT\n    pinMode(_sdnPin, OUTPUT);\n    delay(10);\n    digitalWrite(_sdnPin, LOW);\n    delay(10);\n}\n\nbool RH_RF24::cmd_clear_all_interrupts()\n{\n    uint8_t write_buf[] = { 0x00, 0x00, 0x00 }; \n    return command(RH_RF24_CMD_GET_INT_STATUS, write_buf, sizeof(write_buf));\n}\n\nbool RH_RF24::set_properties(uint16_t firstProperty, const uint8_t* values, uint8_t count)\n{\n    uint8_t buf[15];\n\n    buf[0] = firstProperty >> 8;   // GROUP\n    buf[1] = count;                // NUM_PROPS\n    buf[2] = firstProperty & 0xff; // START_PROP\n    uint8_t i;\n    for (i = 0; i < 12 && i < count; i++)\n\tbuf[3 + i] = values[i]; // DATAn\n    return command(RH_RF24_CMD_SET_PROPERTY, buf, count + 3);\n}\n\nbool RH_RF24::get_properties(uint16_t firstProperty, uint8_t* values, uint8_t count)\n{\n    if (count > 16)\n\tcount = 16;\n    uint8_t buf[3];\n    buf[0] = firstProperty >> 8;   // GROUP\n    buf[1] = count;                // NUM_PROPS\n    buf[2] = firstProperty & 0xff; // START_PROP\n    return command(RH_RF24_CMD_GET_PROPERTY, buf, sizeof(buf), values, count);\n}\n\nfloat RH_RF24::get_temperature()\n{\n    uint8_t write_buf[] = { 0x10 };\n    uint8_t read_buf[8];\n    // Takes nearly 4ms\n    command(RH_RF24_CMD_GET_ADC_READING, write_buf, sizeof(write_buf), read_buf, sizeof(read_buf));\n    uint16_t temp_adc = (read_buf[4] << 8) | read_buf[5];\n    return ((800 + read_buf[6]) / 4096.0) * temp_adc - ((read_buf[7] / 2) + 256);\n}\n\nfloat RH_RF24::get_battery_voltage()\n{\n    uint8_t write_buf[] = { 0x08 };\n    uint8_t read_buf[8];\n    // Takes nearly 4ms\n    command(RH_RF24_CMD_GET_ADC_READING, write_buf, sizeof(write_buf), read_buf, sizeof(read_buf));\n    uint16_t battery_adc = (read_buf[2] << 8) | read_buf[3];\n    return 3.0 * battery_adc / 1280;\n}\n\nfloat RH_RF24::get_gpio_voltage(uint8_t gpio)\n{\n    uint8_t write_buf[] = { 0x04 };\n    uint8_t read_buf[8];\n    write_buf[0] |= (gpio & 0x3);\n    // Takes nearly 4ms\n    command(RH_RF24_CMD_GET_ADC_READING, write_buf, sizeof(write_buf), read_buf, sizeof(read_buf));\n    uint16_t gpio_adc = (read_buf[0] << 8) | read_buf[1];\n    return 3.0 * gpio_adc / 1280;\n}\n\nuint8_t RH_RF24::frr_read(uint8_t reg)\n{\n    uint8_t ret;\n\n    // Do not wait for CTS\n    ATOMIC_BLOCK_START;\n    // First send the command\n    digitalWrite(_slaveSelectPin, LOW);\n    _spi.transfer(RH_RF24_PROPERTY_FRR_CTL_A_MODE + reg);\n    // Get the fast response\n    ret = _spi.transfer(0);\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    return ret;\n}\n\n// List of command replies to be printed by prinRegisters()\nPROGMEM static const RH_RF24::CommandInfo commands[] =\n{\n    { RH_RF24_CMD_PART_INFO,            8 },\n    { RH_RF24_CMD_FUNC_INFO,            6 },\n    { RH_RF24_CMD_GPIO_PIN_CFG,         7 },\n    { RH_RF24_CMD_FIFO_INFO,            2 },\n    { RH_RF24_CMD_PACKET_INFO,          2 },\n    { RH_RF24_CMD_GET_INT_STATUS,       8 },\n    { RH_RF24_CMD_GET_PH_STATUS,        2 },\n    { RH_RF24_CMD_GET_MODEM_STATUS,     8 },\n    { RH_RF24_CMD_GET_CHIP_STATUS,      3 },\n    { RH_RF24_CMD_REQUEST_DEVICE_STATE, 2 },\n};\n#define NUM_COMMAND_INFO (sizeof(commands)/sizeof(CommandInfo))\n\n// List of properties to be printed by printRegisters()\nPROGMEM static const uint16_t properties[] =\n{\n    RH_RF24_PROPERTY_GLOBAL_XO_TUNE,                   \n    RH_RF24_PROPERTY_GLOBAL_CLK_CFG,                   \n    RH_RF24_PROPERTY_GLOBAL_LOW_BATT_THRESH,           \n    RH_RF24_PROPERTY_GLOBAL_CONFIG,                    \n    RH_RF24_PROPERTY_GLOBAL_WUT_CONFIG,               \n    RH_RF24_PROPERTY_GLOBAL_WUT_M_15_8,\n    RH_RF24_PROPERTY_GLOBAL_WUT_M_7_0,\n    RH_RF24_PROPERTY_GLOBAL_WUT_R,\n    RH_RF24_PROPERTY_GLOBAL_WUT_LDC,\n    RH_RF24_PROPERTY_INT_CTL_ENABLE,\n    RH_RF24_PROPERTY_INT_CTL_PH_ENABLE,\n    RH_RF24_PROPERTY_INT_CTL_MODEM_ENABLE,\n    RH_RF24_PROPERTY_INT_CTL_CHIP_ENABLE,\n    RH_RF24_PROPERTY_FRR_CTL_A_MODE,\n    RH_RF24_PROPERTY_FRR_CTL_B_MODE,\n    RH_RF24_PROPERTY_FRR_CTL_C_MODE,\n    RH_RF24_PROPERTY_FRR_CTL_D_MODE,\n    RH_RF24_PROPERTY_PREAMBLE_TX_LENGTH,\n    RH_RF24_PROPERTY_PREAMBLE_CONFIG_STD_1,\n    RH_RF24_PROPERTY_PREAMBLE_CONFIG_NSTD,\n    RH_RF24_PROPERTY_PREAMBLE_CONFIG_STD_2,\n    RH_RF24_PROPERTY_PREAMBLE_CONFIG,\n    RH_RF24_PROPERTY_PREAMBLE_PATTERN_31_24,\n    RH_RF24_PROPERTY_PREAMBLE_PATTERN_23_16,\n    RH_RF24_PROPERTY_PREAMBLE_PATTERN_15_8,\n    RH_RF24_PROPERTY_PREAMBLE_PATTERN_7_0,\n    RH_RF24_PROPERTY_SYNC_CONFIG,\n    RH_RF24_PROPERTY_SYNC_BITS_31_24,\n    RH_RF24_PROPERTY_SYNC_BITS_23_16,\n    RH_RF24_PROPERTY_SYNC_BITS_15_8,\n    RH_RF24_PROPERTY_SYNC_BITS_7_0,\n    RH_RF24_PROPERTY_PKT_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_CONFIG1,\n    RH_RF24_PROPERTY_PKT_LEN,\n    RH_RF24_PROPERTY_PKT_LEN_FIELD_SOURCE,\n    RH_RF24_PROPERTY_PKT_LEN_ADJUST,\n    RH_RF24_PROPERTY_PKT_TX_THRESHOLD,\n    RH_RF24_PROPERTY_PKT_RX_THRESHOLD,\n    RH_RF24_PROPERTY_PKT_FIELD_1_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_FIELD_1_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_FIELD_1_CONFIG,\n    RH_RF24_PROPERTY_PKT_FIELD_1_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_FIELD_2_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_FIELD_2_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_FIELD_2_CONFIG,\n    RH_RF24_PROPERTY_PKT_FIELD_2_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_FIELD_3_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_FIELD_3_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_FIELD_3_CONFIG,\n    RH_RF24_PROPERTY_PKT_FIELD_3_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_FIELD_4_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_FIELD_4_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_FIELD_4_CONFIG,\n    RH_RF24_PROPERTY_PKT_FIELD_4_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_FIELD_5_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_FIELD_5_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_FIELD_5_CONFIG,\n    RH_RF24_PROPERTY_PKT_FIELD_5_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_1_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_1_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_1_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_1_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_2_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_2_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_2_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_2_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_3_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_3_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_3_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_3_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_4_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_4_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_4_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_4_CRC_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_5_LENGTH_12_8,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_5_LENGTH_7_0,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_5_CONFIG,\n    RH_RF24_PROPERTY_PKT_RX_FIELD_5_CRC_CONFIG,\n    RH_RF24_PROPERTY_MODEM_MOD_TYPE,\n    RH_RF24_PROPERTY_MODEM_MAP_CONTROL,\n    RH_RF24_PROPERTY_MODEM_DSM_CTRL,\n    RH_RF24_PROPERTY_MODEM_DATA_RATE_2,\n    RH_RF24_PROPERTY_MODEM_DATA_RATE_1,\n    RH_RF24_PROPERTY_MODEM_DATA_RATE_0,\n    RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_3,\n    RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_2,\n    RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_1,\n    RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_0,\n    RH_RF24_PROPERTY_MODEM_FREQ_DEV_2,\n    RH_RF24_PROPERTY_MODEM_FREQ_DEV_1,\n    RH_RF24_PROPERTY_MODEM_FREQ_DEV_0,\n    RH_RF24_PROPERTY_MODEM_TX_RAMP_DELAY,\n    RH_RF24_PROPERTY_MODEM_MDM_CTRL,\n    RH_RF24_PROPERTY_MODEM_IF_CONTROL,\n    RH_RF24_PROPERTY_MODEM_IF_FREQ_2,\n    RH_RF24_PROPERTY_MODEM_IF_FREQ_1,\n    RH_RF24_PROPERTY_MODEM_IF_FREQ_0,\n    RH_RF24_PROPERTY_MODEM_DECIMATION_CFG1,\n    RH_RF24_PROPERTY_MODEM_DECIMATION_CFG0,\n    RH_RF24_PROPERTY_MODEM_BCR_OSR_1,\n    RH_RF24_PROPERTY_MODEM_BCR_OSR_0,\n    RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_2,\n    RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_1,\n    RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_0,\n    RH_RF24_PROPERTY_MODEM_BCR_GAIN_1,\n    RH_RF24_PROPERTY_MODEM_BCR_GAIN_0,\n    RH_RF24_PROPERTY_MODEM_BCR_GEAR,\n    RH_RF24_PROPERTY_MODEM_BCR_MISC1,\n    RH_RF24_PROPERTY_MODEM_AFC_GEAR,\n    RH_RF24_PROPERTY_MODEM_AFC_WAIT,\n    RH_RF24_PROPERTY_MODEM_AFC_GAIN_1,\n    RH_RF24_PROPERTY_MODEM_AFC_GAIN_0,\n    RH_RF24_PROPERTY_MODEM_AFC_LIMITER_1,\n    RH_RF24_PROPERTY_MODEM_AFC_LIMITER_0,\n    RH_RF24_PROPERTY_MODEM_AFC_MISC,\n    RH_RF24_PROPERTY_MODEM_AGC_CONTROL,\n    RH_RF24_PROPERTY_MODEM_AGC_WINDOW_SIZE,\n    RH_RF24_PROPERTY_MODEM_AGC_RFPD_DECAY,\n    RH_RF24_PROPERTY_MODEM_AGC_IFPD_DECAY,\n    RH_RF24_PROPERTY_MODEM_FSK4_GAIN1,\n    RH_RF24_PROPERTY_MODEM_FSK4_GAIN0,\n    RH_RF24_PROPERTY_MODEM_FSK4_TH1,\n    RH_RF24_PROPERTY_MODEM_FSK4_TH0,\n    RH_RF24_PROPERTY_MODEM_FSK4_MAP,\n    RH_RF24_PROPERTY_MODEM_OOK_PDTC,\n    RH_RF24_PROPERTY_MODEM_OOK_CNT1,\n    RH_RF24_PROPERTY_MODEM_OOK_MISC,\n    RH_RF24_PROPERTY_MODEM_RAW_SEARCH,\n    RH_RF24_PROPERTY_MODEM_RAW_CONTROL,\n    RH_RF24_PROPERTY_MODEM_RAW_EYE_1,\n    RH_RF24_PROPERTY_MODEM_RAW_EYE_0,\n    RH_RF24_PROPERTY_MODEM_ANT_DIV_MODE,\n    RH_RF24_PROPERTY_MODEM_ANT_DIV_CONTROL,\n    RH_RF24_PROPERTY_MODEM_RSSI_THRESH,\n    RH_RF24_PROPERTY_MODEM_RSSI_JUMP_THRESH,\n    RH_RF24_PROPERTY_MODEM_RSSI_CONTROL,\n    RH_RF24_PROPERTY_MODEM_RSSI_CONTROL2,\n    RH_RF24_PROPERTY_MODEM_RSSI_COMP,\n    RH_RF24_PROPERTY_MODEM_ANT_DIV_CONT,\n    RH_RF24_PROPERTY_MODEM_CLKGEN_BAND,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE13_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE12_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE11_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE10_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE9_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE8_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE7_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE6_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE5_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE4_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE3_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE2_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE1_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE0_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM1,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM2,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM3,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE13_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE12_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE11_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE10_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE9_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE8_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE7_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE6_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE5_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE4_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE3_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE2_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE1_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE0_7_0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM0,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM1,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM2,\n    RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM3,\n    RH_RF24_PROPERTY_PA_MODE,\n    RH_RF24_PROPERTY_PA_PWR_LVL,\n    RH_RF24_PROPERTY_PA_BIAS_CLKDUTY,\n    RH_RF24_PROPERTY_PA_TC,\n    RH_RF24_PROPERTY_SYNTH_PFDCP_CPFF,\n    RH_RF24_PROPERTY_SYNTH_PFDCP_CPINT,\n    RH_RF24_PROPERTY_SYNTH_VCO_KV,\n    RH_RF24_PROPERTY_SYNTH_LPFILT3,\n    RH_RF24_PROPERTY_SYNTH_LPFILT2,\n    RH_RF24_PROPERTY_SYNTH_LPFILT1,\n    RH_RF24_PROPERTY_SYNTH_LPFILT0,\n    RH_RF24_PROPERTY_MATCH_VALUE_1,\n    RH_RF24_PROPERTY_MATCH_MASK_1,\n    RH_RF24_PROPERTY_MATCH_CTRL_1,\n    RH_RF24_PROPERTY_MATCH_VALUE_2,\n    RH_RF24_PROPERTY_MATCH_MASK_2,\n    RH_RF24_PROPERTY_MATCH_CTRL_2,\n    RH_RF24_PROPERTY_MATCH_VALUE_3,\n    RH_RF24_PROPERTY_MATCH_MASK_3,\n    RH_RF24_PROPERTY_MATCH_CTRL_3,\n    RH_RF24_PROPERTY_MATCH_VALUE_4,\n    RH_RF24_PROPERTY_MATCH_MASK_4,\n    RH_RF24_PROPERTY_MATCH_CTRL_4,\n    RH_RF24_PROPERTY_FREQ_CONTROL_INTE,\n    RH_RF24_PROPERTY_FREQ_CONTROL_FRAC_2,\n    RH_RF24_PROPERTY_FREQ_CONTROL_FRAC_1,\n    RH_RF24_PROPERTY_FREQ_CONTROL_FRAC_0,\n    RH_RF24_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_1,\n    RH_RF24_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_0,\n    RH_RF24_PROPERTY_FREQ_CONTROL_VCOCNT_RX_ADJ,\n    RH_RF24_PROPERTY_RX_HOP_CONTROL,\n    RH_RF24_PROPERTY_RX_HOP_TABLE_SIZE,\n    RH_RF24_PROPERTY_RX_HOP_TABLE_ENTRY_0,\n};\n#define\tNUM_PROPERTIES (sizeof(properties)/sizeof(uint16_t))\n\nbool RH_RF24::printRegisters()\n{  \n#ifdef RH_HAVE_SERIAL\n    uint8_t i;\n    // First print the commands that return interesting data\n    for (i = 0; i < NUM_COMMAND_INFO; i++)\n    {\n\tCommandInfo cmd;\n\tmemcpy_P(&cmd, &commands[i], sizeof(cmd));\n\tuint8_t buf[10]; // Big enough for the biggest command reply\n\tif (command(cmd.cmd, NULL, 0, buf, cmd.replyLen))\n\t{\n\t    // Print the results:\n\t    Serial.print(\"cmd: \");\n\t    Serial.print(cmd.cmd, HEX);\n\t    Serial.print(\" : \");\n\t    uint8_t j;\n\t    for (j = 0; j < cmd.replyLen; j++)\n\t    {\n\t\tSerial.print(buf[j], HEX);\n\t\tSerial.print(\" \");\n\t    }\n\t    Serial.println(\"\");\n\t}\n    }\n\n    // Now print the properties\n    for (i = 0; i < NUM_PROPERTIES; i++)\n    {\n\tuint16_t prop;\n\tmemcpy_P(&prop, &properties[i], sizeof(prop));\n\tuint8_t result;\n\tget_properties(prop, &result, 1);\n\tSerial.print(\"prop: \");\n\tSerial.print(prop, HEX);\n\tSerial.print(\": \");\n\tSerial.print(result, HEX);\n        Serial.println(\"\");\n    }\n#endif\n    return true;\n}\n"
  },
  {
    "path": "RH_RF24.h",
    "content": "// RH_RF24.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_RF24.h,v 1.15 2016/08/17 01:53:21 mikem Exp $\n//\n// Supports RF24/RF26 and RFM24/RFM26 modules in FIFO mode\n// also Si4464/63/62/61/60-A1\n// Si4063 is the same but Tx only\n//\n// Per http://www.hoperf.cn/upload/rf/RFM24.pdf\n// and http://www.hoperf.cn/upload/rf/RFM26.pdf\n// Sigh: the HopeRF documentation is utter rubbish: full of errors and incomplete. The Si446x docs are better:\n// http://www.silabs.com/Support%20Documents/TechnicalDocs/Si4464-63-61-60.pdf\n// http://www.silabs.com/Support%20Documents/TechnicalDocs/AN626.pdf\n// http://www.silabs.com/Support%20Documents/TechnicalDocs/AN627.pdf\n// http://www.silabs.com/Support%20Documents/TechnicalDocs/AN647.pdf\n// http://www.silabs.com/Support%20Documents/TechnicalDocs/AN633.pdf\n// http://www.silabs.com/Support%20Documents/TechnicalDocs/AN736.pdf\n// http://nicerf.com/manage/upfile/indexbanner/635231050196868750.pdf    (API description)\n// http://www.silabs.com/Support%20Documents/Software/Si446x%20RX_HOP%20PLL%20Calculator.xlsx\n#ifndef RH_RF24_h\n#define RH_RF24_h\n\n#include <RHGenericSPI.h>\n#include <RHSPIDriver.h>\n\n// This is the maximum number of interrupts the driver can support\n// Most Arduinos can handle 2, Megas can handle more\n#define RH_RF24_NUM_INTERRUPTS 3\n\n// Maximum payload length the RF24 can support, limited by our 1 octet message length\n#define RH_RF24_MAX_PAYLOAD_LEN 255\n\n// The length of the headers we add.\n// The headers are inside the RF24's payload\n#define RH_RF24_HEADER_LEN 4\n\n// This is the maximum message length that can be supported by this driver. \n// Can be pre-defined to a smaller size (to save SRAM) prior to including this header\n// Here we allow for message length 4 bytes of address and header and payload to be included in payload size limit.\n#ifndef RH_RF24_MAX_MESSAGE_LEN\n#define RH_RF24_MAX_MESSAGE_LEN (RH_RF24_MAX_PAYLOAD_LEN - RH_RF24_HEADER_LEN - 1)\n#endif\n\n// Max number of times we will try to read CTS from the radio\n#define RH_RF24_CTS_RETRIES 2500\n\n// RF24/RF26 API commands from table 10\n// also Si446X API DESCRIPTIONS table 1\n#define RH_RF24_CMD_NOP                        0x00\n#define RH_RF24_CMD_PART_INFO                  0x01\n#define RH_RF24_CMD_POWER_UP                   0x02\n#define RH_RF24_CMD_PATCH_IMAGE                0x04\n#define RH_RF24_CMD_FUNC_INFO                  0x10\n#define RH_RF24_CMD_SET_PROPERTY               0x11\n#define RH_RF24_CMD_GET_PROPERTY               0x12\n#define RH_RF24_CMD_GPIO_PIN_CFG               0x13\n#define RH_RF24_CMD_GET_ADC_READING            0x14\n#define RH_RF24_CMD_FIFO_INFO                  0x15\n#define RH_RF24_CMD_PACKET_INFO                0x16\n#define RH_RF24_CMD_IRCAL                      0x17\n#define RH_RF24_CMD_PROTOCOL_CFG               0x18\n#define RH_RF24_CMD_GET_INT_STATUS             0x20\n#define RH_RF24_CMD_GET_PH_STATUS              0x21\n#define RH_RF24_CMD_GET_MODEM_STATUS           0x22\n#define RH_RF24_CMD_GET_CHIP_STATUS            0x23\n#define RH_RF24_CMD_START_TX                   0x31\n#define RH_RF24_CMD_START_RX                   0x32\n#define RH_RF24_CMD_REQUEST_DEVICE_STATE       0x33\n#define RH_RF24_CMD_CHANGE_STATE               0x34\n#define RH_RF24_CMD_RX_HOP                     0x36\n#define RH_RF24_CMD_READ_BUF                   0x44\n#define RH_RF24_CMD_FAST_RESPONSE_A            0x50\n#define RH_RF24_CMD_FAST_RESPONSE_B            0x51\n#define RH_RF24_CMD_FAST_RESPONSE_C            0x53\n#define RH_RF24_CMD_FAST_RESPONSE_D            0x57\n#define RH_RF24_CMD_TX_FIFO_WRITE              0x66\n#define RH_RF24_CMD_RX_FIFO_READ               0x77\n\n// The Clear To Send signal from the radio\n#define RH_RF24_REPLY_CTS                      0xff\n\n//#define RH_RF24_CMD_START_TX                   0x31\n#define RH_RF24_CONDITION_TX_COMPLETE_STATE      0xf0\n#define RH_RF24_CONDITION_RETRANSMIT_NO          0x00\n#define RH_RF24_CONDITION_RETRANSMIT_YES         0x04\n#define RH_RF24_CONDITION_START_IMMEDIATE        0x00\n#define RH_RF24_CONDITION_START_AFTER_WUT        0x01\n\n//#define RH_RF24_CMD_START_RX                   0x32\n#define RH_RF24_CONDITION_RX_START_IMMEDIATE     0x00\n\n//#define RH_RF24_CMD_REQUEST_DEVICE_STATE       0x33\n#define RH_RF24_DEVICE_STATE_NO_CHANGE           0x00\n#define RH_RF24_DEVICE_STATE_SLEEP               0x01\n#define RH_RF24_DEVICE_STATE_SPI_ACTIVE          0x02\n#define RH_RF24_DEVICE_STATE_READY               0x03\n#define RH_RF24_DEVICE_STATE_ALSO_READY          0x04\n#define RH_RF24_DEVICE_STATE_TUNE_TX             0x05\n#define RH_RF24_DEVICE_STATE_TUNE_RX             0x06\n#define RH_RF24_DEVICE_STATE_TX                  0x07\n#define RH_RF24_DEVICE_STATE_RX                  0x08\n\n// Properties for API Description AN625 Section 2.2\n#define RH_RF24_PROPERTY_GLOBAL_XO_TUNE                   0x0000\n#define RH_RF24_PROPERTY_GLOBAL_CLK_CFG                   0x0001\n#define RH_RF24_PROPERTY_GLOBAL_LOW_BATT_THRESH           0x0002\n#define RH_RF24_PROPERTY_GLOBAL_CONFIG                    0x0003\n#define RH_RF24_PROPERTY_GLOBAL_WUT_CONFIG                0x0004\n#define RH_RF24_PROPERTY_GLOBAL_WUT_M_15_8                0x0005\n#define RH_RF24_PROPERTY_GLOBAL_WUT_M_7_0                 0x0006\n#define RH_RF24_PROPERTY_GLOBAL_WUT_R                     0x0007\n#define RH_RF24_PROPERTY_GLOBAL_WUT_LDC                   0x0008\n#define RH_RF24_PROPERTY_INT_CTL_ENABLE                   0x0100\n#define RH_RF24_PROPERTY_INT_CTL_PH_ENABLE                0x0101\n#define RH_RF24_PROPERTY_INT_CTL_MODEM_ENABLE             0x0102\n#define RH_RF24_PROPERTY_INT_CTL_CHIP_ENABLE              0x0103\n#define RH_RF24_PROPERTY_FRR_CTL_A_MODE                   0x0200\n#define RH_RF24_PROPERTY_FRR_CTL_B_MODE                   0x0201\n#define RH_RF24_PROPERTY_FRR_CTL_C_MODE                   0x0202\n#define RH_RF24_PROPERTY_FRR_CTL_D_MODE                   0x0203\n#define RH_RF24_PROPERTY_PREAMBLE_TX_LENGTH               0x1000\n#define RH_RF24_PROPERTY_PREAMBLE_CONFIG_STD_1            0x1001\n#define RH_RF24_PROPERTY_PREAMBLE_CONFIG_NSTD             0x1002\n#define RH_RF24_PROPERTY_PREAMBLE_CONFIG_STD_2            0x1003\n#define RH_RF24_PROPERTY_PREAMBLE_CONFIG                  0x1004\n#define RH_RF24_PROPERTY_PREAMBLE_PATTERN_31_24           0x1005\n#define RH_RF24_PROPERTY_PREAMBLE_PATTERN_23_16           0x1006\n#define RH_RF24_PROPERTY_PREAMBLE_PATTERN_15_8            0x1007\n#define RH_RF24_PROPERTY_PREAMBLE_PATTERN_7_0             0x1008\n#define RH_RF24_PROPERTY_SYNC_CONFIG                      0x1100\n#define RH_RF24_PROPERTY_SYNC_BITS_31_24                  0x1101\n#define RH_RF24_PROPERTY_SYNC_BITS_23_16                  0x1102\n#define RH_RF24_PROPERTY_SYNC_BITS_15_8                   0x1103\n#define RH_RF24_PROPERTY_SYNC_BITS_7_0                    0x1104\n#define RH_RF24_PROPERTY_PKT_CRC_CONFIG                   0x1200\n#define RH_RF24_PROPERTY_PKT_CONFIG1                      0x1206\n#define RH_RF24_PROPERTY_PKT_LEN                          0x1208\n#define RH_RF24_PROPERTY_PKT_LEN_FIELD_SOURCE             0x1209\n#define RH_RF24_PROPERTY_PKT_LEN_ADJUST                   0x120a\n#define RH_RF24_PROPERTY_PKT_TX_THRESHOLD                 0x120b\n#define RH_RF24_PROPERTY_PKT_RX_THRESHOLD                 0x120c\n#define RH_RF24_PROPERTY_PKT_FIELD_1_LENGTH_12_8          0x120d\n#define RH_RF24_PROPERTY_PKT_FIELD_1_LENGTH_7_0           0x120e\n#define RH_RF24_PROPERTY_PKT_FIELD_1_CONFIG               0x120f\n#define RH_RF24_PROPERTY_PKT_FIELD_1_CRC_CONFIG           0x1210\n#define RH_RF24_PROPERTY_PKT_FIELD_2_LENGTH_12_8          0x1211\n#define RH_RF24_PROPERTY_PKT_FIELD_2_LENGTH_7_0           0x1212\n#define RH_RF24_PROPERTY_PKT_FIELD_2_CONFIG               0x1213\n#define RH_RF24_PROPERTY_PKT_FIELD_2_CRC_CONFIG           0x1214\n#define RH_RF24_PROPERTY_PKT_FIELD_3_LENGTH_12_8          0x1215\n#define RH_RF24_PROPERTY_PKT_FIELD_3_LENGTH_7_0           0x1216\n#define RH_RF24_PROPERTY_PKT_FIELD_3_CONFIG               0x1217\n#define RH_RF24_PROPERTY_PKT_FIELD_3_CRC_CONFIG           0x1218\n#define RH_RF24_PROPERTY_PKT_FIELD_4_LENGTH_12_8          0x1219\n#define RH_RF24_PROPERTY_PKT_FIELD_4_LENGTH_7_0           0x121a\n#define RH_RF24_PROPERTY_PKT_FIELD_4_CONFIG               0x121b\n#define RH_RF24_PROPERTY_PKT_FIELD_4_CRC_CONFIG           0x121c\n#define RH_RF24_PROPERTY_PKT_FIELD_5_LENGTH_12_8          0x121d\n#define RH_RF24_PROPERTY_PKT_FIELD_5_LENGTH_7_0           0x121e\n#define RH_RF24_PROPERTY_PKT_FIELD_5_CONFIG               0x121f\n#define RH_RF24_PROPERTY_PKT_FIELD_5_CRC_CONFIG           0x1220\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_1_LENGTH_12_8       0x1221\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_1_LENGTH_7_0        0x1222\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_1_CONFIG            0x1223\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_1_CRC_CONFIG        0x1224\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_2_LENGTH_12_8       0x1225\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_2_LENGTH_7_0        0x1226\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_2_CONFIG            0x1227\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_2_CRC_CONFIG        0x1228\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_3_LENGTH_12_8       0x1229\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_3_LENGTH_7_0        0x122a\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_3_CONFIG            0x122b\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_3_CRC_CONFIG        0x122c\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_4_LENGTH_12_8       0x122d\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_4_LENGTH_7_0        0x122e\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_4_CONFIG            0x122f\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_4_CRC_CONFIG        0x1230\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_5_LENGTH_12_8       0x1231\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_5_LENGTH_7_0        0x1232\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_5_CONFIG            0x1233\n#define RH_RF24_PROPERTY_PKT_RX_FIELD_5_CRC_CONFIG        0x1234\n#define RH_RF24_PROPERTY_MODEM_MOD_TYPE                   0x2000\n#define RH_RF24_PROPERTY_MODEM_MAP_CONTROL                0x2001\n#define RH_RF24_PROPERTY_MODEM_DSM_CTRL                   0x2002\n#define RH_RF24_PROPERTY_MODEM_DATA_RATE_2                0x2003\n#define RH_RF24_PROPERTY_MODEM_DATA_RATE_1                0x2004\n#define RH_RF24_PROPERTY_MODEM_DATA_RATE_0                0x2005\n#define RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_3              0x2006\n#define RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_2              0x2007\n#define RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_1              0x2008\n#define RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_0              0x2009\n#define RH_RF24_PROPERTY_MODEM_FREQ_DEV_2                 0x200a\n#define RH_RF24_PROPERTY_MODEM_FREQ_DEV_1                 0x200b\n#define RH_RF24_PROPERTY_MODEM_FREQ_DEV_0                 0x200c\n#define RH_RF24_PROPERTY_MODEM_TX_RAMP_DELAY              0x2018\n#define RH_RF24_PROPERTY_MODEM_MDM_CTRL                   0x2019\n#define RH_RF24_PROPERTY_MODEM_IF_CONTROL                 0x201a\n#define RH_RF24_PROPERTY_MODEM_IF_FREQ_2                  0x201b\n#define RH_RF24_PROPERTY_MODEM_IF_FREQ_1                  0x201c\n#define RH_RF24_PROPERTY_MODEM_IF_FREQ_0                  0x201d\n#define RH_RF24_PROPERTY_MODEM_DECIMATION_CFG1            0x201e\n#define RH_RF24_PROPERTY_MODEM_DECIMATION_CFG0            0x201f\n#define RH_RF24_PROPERTY_MODEM_BCR_OSR_1                  0x2022\n#define RH_RF24_PROPERTY_MODEM_BCR_OSR_0                  0x2023\n#define RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_2           0x2024\n#define RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_1           0x2025\n#define RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_0           0x2026\n#define RH_RF24_PROPERTY_MODEM_BCR_GAIN_1                 0x2027\n#define RH_RF24_PROPERTY_MODEM_BCR_GAIN_0                 0x2028\n#define RH_RF24_PROPERTY_MODEM_BCR_GEAR                   0x2029\n#define RH_RF24_PROPERTY_MODEM_BCR_MISC1                  0x202a\n#define RH_RF24_PROPERTY_MODEM_AFC_GEAR                   0x202c\n#define RH_RF24_PROPERTY_MODEM_AFC_WAIT                   0x202d\n#define RH_RF24_PROPERTY_MODEM_AFC_GAIN_1                 0x202e\n#define RH_RF24_PROPERTY_MODEM_AFC_GAIN_0                 0x202f\n#define RH_RF24_PROPERTY_MODEM_AFC_LIMITER_1              0x2030\n#define RH_RF24_PROPERTY_MODEM_AFC_LIMITER_0              0x2031\n#define RH_RF24_PROPERTY_MODEM_AFC_MISC                   0x2032\n#define RH_RF24_PROPERTY_MODEM_AGC_CONTROL                0x2035\n#define RH_RF24_PROPERTY_MODEM_AGC_WINDOW_SIZE            0x2038\n#define RH_RF24_PROPERTY_MODEM_AGC_RFPD_DECAY             0x2039\n#define RH_RF24_PROPERTY_MODEM_AGC_IFPD_DECAY             0x203a\n#define RH_RF24_PROPERTY_MODEM_FSK4_GAIN1                 0x203b\n#define RH_RF24_PROPERTY_MODEM_FSK4_GAIN0                 0x203c\n#define RH_RF24_PROPERTY_MODEM_FSK4_TH1                   0x203d\n#define RH_RF24_PROPERTY_MODEM_FSK4_TH0                   0x203e\n#define RH_RF24_PROPERTY_MODEM_FSK4_MAP                   0x203f\n#define RH_RF24_PROPERTY_MODEM_OOK_PDTC                   0x2040\n#define RH_RF24_PROPERTY_MODEM_OOK_CNT1                   0x2042\n#define RH_RF24_PROPERTY_MODEM_OOK_MISC                   0x2043\n#define RH_RF24_PROPERTY_MODEM_RAW_SEARCH                 0x2044\n#define RH_RF24_PROPERTY_MODEM_RAW_CONTROL                0x2045\n#define RH_RF24_PROPERTY_MODEM_RAW_EYE_1                  0x2046\n#define RH_RF24_PROPERTY_MODEM_RAW_EYE_0                  0x2047\n#define RH_RF24_PROPERTY_MODEM_ANT_DIV_MODE               0x2048\n#define RH_RF24_PROPERTY_MODEM_ANT_DIV_CONTROL            0x2049\n#define RH_RF24_PROPERTY_MODEM_RSSI_THRESH                0x204a\n#define RH_RF24_PROPERTY_MODEM_RSSI_JUMP_THRESH           0x204b\n#define RH_RF24_PROPERTY_MODEM_RSSI_CONTROL               0x204c\n#define RH_RF24_PROPERTY_MODEM_RSSI_CONTROL2              0x204d\n#define RH_RF24_PROPERTY_MODEM_RSSI_COMP                  0x204e\n#define RH_RF24_PROPERTY_MODEM_ANT_DIV_CONT               0x2049\n#define RH_RF24_PROPERTY_MODEM_CLKGEN_BAND                0x2051\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE13_7_0  0x2100\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE12_7_0  0x2101\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE11_7_0  0x2102\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE10_7_0  0x2103\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE9_7_0   0x2104\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE8_7_0   0x2105\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE7_7_0   0x2106\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE6_7_0   0x2107\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE5_7_0   0x2108\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE4_7_0   0x2109\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE3_7_0   0x210a\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE2_7_0   0x210b\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE1_7_0   0x210c\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE0_7_0   0x210d\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM0      0x210e\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM1      0x210f\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM2      0x2110\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM3      0x2111\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE13_7_0  0x2112\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE12_7_0  0x2113\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE11_7_0  0x2114\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE10_7_0  0x2115\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE9_7_0   0x2116\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE8_7_0   0x2117\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE7_7_0   0x2118\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE6_7_0   0x2119\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE5_7_0   0x211a\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE4_7_0   0x211b\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE3_7_0   0x211c\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE2_7_0   0x211d\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE1_7_0   0x211e\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE0_7_0   0x211f\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM0      0x2120\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM1      0x2121\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM2      0x2122\n#define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM3      0x2123\n#define RH_RF24_PROPERTY_PA_MODE                          0x2200\n#define RH_RF24_PROPERTY_PA_PWR_LVL                       0x2201\n#define RH_RF24_PROPERTY_PA_BIAS_CLKDUTY                  0x2202\n#define RH_RF24_PROPERTY_PA_TC                            0x2203\n#define RH_RF24_PROPERTY_SYNTH_PFDCP_CPFF                 0x2300\n#define RH_RF24_PROPERTY_SYNTH_PFDCP_CPINT                0x2301\n#define RH_RF24_PROPERTY_SYNTH_VCO_KV                     0x2302\n#define RH_RF24_PROPERTY_SYNTH_LPFILT3                    0x2303\n#define RH_RF24_PROPERTY_SYNTH_LPFILT2                    0x2304\n#define RH_RF24_PROPERTY_SYNTH_LPFILT1                    0x2305\n#define RH_RF24_PROPERTY_SYNTH_LPFILT0                    0x2306\n#define RH_RF24_PROPERTY_MATCH_VALUE_1                    0x3000\n#define RH_RF24_PROPERTY_MATCH_MASK_1                     0x3001\n#define RH_RF24_PROPERTY_MATCH_CTRL_1                     0x3002\n#define RH_RF24_PROPERTY_MATCH_VALUE_2                    0x3003\n#define RH_RF24_PROPERTY_MATCH_MASK_2                     0x3004\n#define RH_RF24_PROPERTY_MATCH_CTRL_2                     0x3005\n#define RH_RF24_PROPERTY_MATCH_VALUE_3                    0x3006\n#define RH_RF24_PROPERTY_MATCH_MASK_3                     0x3007\n#define RH_RF24_PROPERTY_MATCH_CTRL_3                     0x3008\n#define RH_RF24_PROPERTY_MATCH_VALUE_4                    0x3009\n#define RH_RF24_PROPERTY_MATCH_MASK_4                     0x300a\n#define RH_RF24_PROPERTY_MATCH_CTRL_4                     0x300b\n#define RH_RF24_PROPERTY_FREQ_CONTROL_INTE                0x4000\n#define RH_RF24_PROPERTY_FREQ_CONTROL_FRAC_2              0x4001\n#define RH_RF24_PROPERTY_FREQ_CONTROL_FRAC_1              0x4002\n#define RH_RF24_PROPERTY_FREQ_CONTROL_FRAC_0              0x4003\n#define RH_RF24_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_1 0x4004\n#define RH_RF24_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_0 0x4005\n#define RH_RF24_PROPERTY_FREQ_CONTROL_VCOCNT_RX_ADJ       0x4007\n#define RH_RF24_PROPERTY_RX_HOP_CONTROL                   0x5000\n#define RH_RF24_PROPERTY_RX_HOP_TABLE_SIZE                0x5001\n#define RH_RF24_PROPERTY_RX_HOP_TABLE_ENTRY_0             0x5002\n\n//#define RH_RF24_CMD_GPIO_PIN_CFG               0x13\n#define RH_RF24_GPIO_NO_CHANGE                   0\n#define RH_RF24_GPIO_DISABLED                    1\n#define RH_RF24_GPIO_LOW                         2\n#define RH_RF24_GPIO_HIGH                        3\n#define RH_RF24_GPIO_INPUT                       4\n#define RH_RF24_GPIO_32_KHZ_CLOCK                5\n#define RH_RF24_GPIO_BOOT_CLOCK                  6\n#define RH_RF24_GPIO_DIVIDED_MCU_CLOCK           7\n#define RH_RF24_GPIO_CTS                         8\n#define RH_RF24_GPIO_INV_CTS                     9\n#define RH_RF24_GPIO_HIGH_ON_CMD_OVERLAP         10\n#define RH_RF24_GPIO_SPI_DATA_OUT                11\n#define RH_RF24_GPIO_HIGH_AFTER_RESET            12\n#define RH_RF24_GPIO_HIGH_AFTER_CALIBRATION      13\n#define RH_RF24_GPIO_HIGH_AFTER_WUT              14\n#define RH_RF24_GPIO_UNUSED_0                    15\n#define RH_RF24_GPIO_TX_DATA_CLOCK               16\n#define RH_RF24_GPIO_RX_DATA_CLOCK               17\n#define RH_RF24_GPIO_UNUSED_1                    18\n#define RH_RF24_GPIO_TX_DATA                     19\n#define RH_RF24_GPIO_RX_DATA                     20\n#define RH_RF24_GPIO_RX_RAW_DATA                 21\n#define RH_RF24_GPIO_ANTENNA_1_SWITCH            22\n#define RH_RF24_GPIO_ANTENNA_2_SWITCH            23\n#define RH_RF24_GPIO_VALID_PREAMBLE              24\n#define RH_RF24_GPIO_INVALID_PREAMBLE            25\n#define RH_RF24_GPIO_SYNC_DETECTED               26\n#define RH_RF24_GPIO_RSSI_ABOVE_CAT              27\n#define RH_RF24_GPIO_TX_STATE                    32\n#define RH_RF24_GPIO_RX_STATE                    33\n#define RH_RF24_GPIO_RX_FIFO_ALMOST_FULL         34\n#define RH_RF24_GPIO_TX_FIFO_ALMOST_EMPTY        35\n#define RH_RF24_GPIO_BATT_LOW                    36\n#define RH_RF24_GPIO_RSSI_ABOVE_CAT_LOW          37\n#define RH_RF24_GPIO_HOP                         38\n#define RH_RF24_GPIO_HOP_TABLE_WRAPPED           39\n\n// #define RH_RF24_CMD_GET_INT_STATUS             0x20\n#define RH_RF24_INT_STATUS_CHIP_INT_STATUS                0x04\n#define RH_RF24_INT_STATUS_MODEM_INT_STATUS               0x02\n#define RH_RF24_INT_STATUS_PH_INT_STATUS                  0x01\n#define RH_RF24_INT_STATUS_FILTER_MATCH                   0x80\n#define RH_RF24_INT_STATUS_FILTER_MISS                    0x40\n#define RH_RF24_INT_STATUS_PACKET_SENT                    0x20\n#define RH_RF24_INT_STATUS_PACKET_RX                      0x10\n#define RH_RF24_INT_STATUS_CRC_ERROR                      0x08\n#define RH_RF24_INT_STATUS_TX_FIFO_ALMOST_EMPTY           0x02\n#define RH_RF24_INT_STATUS_RX_FIFO_ALMOST_FULL            0x01\n#define RH_RF24_INT_STATUS_INVALID_SYNC                   0x20\n#define RH_RF24_INT_STATUS_RSSI_JUMP                      0x10\n#define RH_RF24_INT_STATUS_RSSI                           0x08\n#define RH_RF24_INT_STATUS_INVALID_PREAMBLE               0x04\n#define RH_RF24_INT_STATUS_PREAMBLE_DETECT                0x02\n#define RH_RF24_INT_STATUS_SYNC_DETECT                    0x01\n#define RH_RF24_INT_STATUS_CAL                            0x40\n#define RH_RF24_INT_STATUS_FIFO_UNDERFLOW_OVERFLOW_ERROR  0x20\n#define RH_RF24_INT_STATUS_STATE_CHANGE                   0x10\n#define RH_RF24_INT_STATUS_CMD_ERROR                      0x08\n#define RH_RF24_INT_STATUS_CHIP_READY                     0x04\n#define RH_RF24_INT_STATUS_LOW_BATT                       0x02\n#define RH_RF24_INT_STATUS_WUT                            0x01\n\n//#define RH_RF24_PROPERTY_FRR_CTL_A_MODE                   0x0200\n//#define RH_RF24_PROPERTY_FRR_CTL_B_MODE                   0x0201\n//#define RH_RF24_PROPERTY_FRR_CTL_C_MODE                   0x0202\n//#define RH_RF24_PROPERTY_FRR_CTL_D_MODE                   0x0203\n#define RH_RF24_FRR_MODE_DISABLED                         0\n#define RH_RF24_FRR_MODE_GLOBAL_STATUS                    1\n#define RH_RF24_FRR_MODE_GLOBAL_INTERRUPT_PENDING         2\n#define RH_RF24_FRR_MODE_PACKET_HANDLER_STATUS            3\n#define RH_RF24_FRR_MODE_PACKET_HANDLER_INTERRUPT_PENDING 4\n#define RH_RF24_FRR_MODE_MODEM_STATUS                     5\n#define RH_RF24_FRR_MODE_MODEM_INTERRUPT_PENDING          6\n#define RH_RF24_FRR_MODE_CHIP_STATUS                      7\n#define RH_RF24_FRR_MODE_CHIP_INTERRUPT_PENDING           8\n#define RH_RF24_FRR_MODE_CURRENT_STATE                    9\n#define RH_RF24_FRR_MODE_LATCHED_RSSI                     10\n\n//#define RH_RF24_PROPERTY_INT_CTL_ENABLE                   0x0100\n#define RH_RF24_CHIP_INT_STATUS_EN                        0x04\n#define RH_RF24_MODEM_INT_STATUS_EN                       0x02\n#define RH_RF24_PH_INT_STATUS_EN                          0x01\n\n//#define RH_RF24_PROPERTY_PREAMBLE_CONFIG                  0x1004\n#define RH_RF24_PREAMBLE_FIRST_1                          0x20\n#define RH_RF24_PREAMBLE_FIRST_0                          0x00\n#define RH_RF24_PREAMBLE_LENGTH_NIBBLES                   0x00\n#define RH_RF24_PREAMBLE_LENGTH_BYTES                     0x10\n#define RH_RF24_PREAMBLE_MAN_CONST                        0x08\n#define RH_RF24_PREAMBLE_MAN_ENABLE                       0x02\n#define RH_RF24_PREAMBLE_NON_STANDARD                     0x00\n#define RH_RF24_PREAMBLE_STANDARD_1010                    0x01\n#define RH_RF24_PREAMBLE_STANDARD_0101                    0x02\n\n//#define RH_RF24_PROPERTY_SYNC_CONFIG                      0x1100\n#define RH_RF24_SYNC_CONFIG_SKIP_TX                       0x80\n#define RH_RF24_SYNC_CONFIG_RX_ERRORS_MASK                0x70\n#define RH_RF24_SYNC_CONFIG_4FSK                          0x08\n#define RH_RF24_SYNC_CONFIG_MANCH                         0x04\n#define RH_RF24_SYNC_CONFIG_LENGTH_MASK                   0x03\n\n//#define RH_RF24_PROPERTY_PKT_CRC_CONFIG                   0x1200\n#define RH_RF24_CRC_SEED_ALL_0S                           0x00\n#define RH_RF24_CRC_SEED_ALL_1S                           0x80\n#define RH_RF24_CRC_MASK                                  0x0f\n#define RH_RF24_CRC_NONE                                  0x00\n#define RH_RF24_CRC_ITU_T                                 0x01\n#define RH_RF24_CRC_IEC_16                                0x02\n#define RH_RF24_CRC_BIACHEVA                              0x03\n#define RH_RF24_CRC_16_IBM                                0x04\n#define RH_RF24_CRC_CCITT                                 0x05\n#define RH_RF24_CRC_KOOPMAN                               0x06\n#define RH_RF24_CRC_IEEE_802_3                            0x07\n#define RH_RF24_CRC_CASTAGNOLI                            0x08\n\n//#define RH_RF24_PROPERTY_PKT_CONFIG1                      0x1206\n#define RH_RF24_PH_FIELD_SPLIT                            0x80\n#define RH_RF24_PH_RX_DISABLE                             0x40\n#define RH_RF24_4FSK_EN                                   0x20\n#define RH_RF24_RX_MULTI_PKT                              0x10\n#define RH_RF24_MANCH_POL                                 0x08\n#define RH_RF24_CRC_INVERT                                0x04\n#define RH_RF24_CRC_ENDIAN                                0x02\n#define RH_RF24_BIT_ORDER                                 0x01\n\n//#define RH_RF24_PROPERTY_PKT_FIELD_1_CONFIG               0x120f\n//#define RH_RF24_PROPERTY_PKT_FIELD_2_CONFIG               0x1213\n//#define RH_RF24_PROPERTY_PKT_FIELD_3_CONFIG               0x1217\n//#define RH_RF24_PROPERTY_PKT_FIELD_4_CONFIG               0x121b\n//#define RH_RF24_PROPERTY_PKT_FIELD_5_CONFIG               0x121f\n#define RH_RF24_FIELD_CONFIG_4FSK                         0x10\n#define RH_RF24_FIELD_CONFIG_WHITEN                       0x02\n#define RH_RF24_FIELD_CONFIG_MANCH                        0x01\n\n//#define RH_RF24_PROPERTY_PKT_RX_FIELD_1_CRC_CONFIG        0x1224\n//#define RH_RF24_PROPERTY_PKT_RX_FIELD_2_CRC_CONFIG        0x1228\n//#define RH_RF24_PROPERTY_PKT_RX_FIELD_3_CRC_CONFIG        0x122c\n//#define RH_RF24_PROPERTY_PKT_RX_FIELD_4_CRC_CONFIG        0x1230\n//#define RH_RF24_PROPERTY_PKT_RX_FIELD_5_CRC_CONFIG        0x1234\n#define RH_RF24_FIELD_CONFIG_CRC_START                     0x80\n#define RH_RF24_FIELD_CONFIG_SEND_CRC                      0x20\n#define RH_RF24_FIELD_CONFIG_CHECK_CRC                     0x08\n#define RH_RF24_FIELD_CONFIG_CRC_ENABLE                    0x02\n\n\n\n\n//#define RH_RF24_PROPERTY_MODEM_MOD_TYPE                   0x2000\n#define RH_RF24_TX_DIRECT_MODE_TYPE_SYNCHRONOUS           0x00\n#define RH_RF24_TX_DIRECT_MODE_TYPE_ASYNCHRONOUS          0x80\n#define RH_RF24_TX_DIRECT_MODE_GPIO0                      0x00\n#define RH_RF24_TX_DIRECT_MODE_GPIO1                      0x20\n#define RH_RF24_TX_DIRECT_MODE_GPIO2                      0x40\n#define RH_RF24_TX_DIRECT_MODE_GPIO3                      0x60\n#define RH_RF24_MOD_SOURCE_PACKET_HANDLER                 0x00\n#define RH_RF24_MOD_SOURCE_DIRECT_MODE                    0x08\n#define RH_RF24_MOD_SOURCE_RANDOM_GENERATOR               0x10\n#define RH_RF24_MOD_TYPE_CW                               0x00\n#define RH_RF24_MOD_TYPE_OOK                              0x01\n#define RH_RF24_MOD_TYPE_2FSK                             0x02\n#define RH_RF24_MOD_TYPE_2GFSK                            0x03\n#define RH_RF24_MOD_TYPE_4FSK                             0x04\n#define RH_RF24_MOD_TYPE_4GFSK                            0x05\n\n//    RH_RF24_PROPERTY_PA_MODE                          0x2200\n#define RH_RF24_PA_MODE_1_GROUP                           0x04\n#define RH_RF24_PA_MODE_2_GROUPS                          0x08\n#define RH_RF24_PA_MODE_CLASS_E                           0x00\n#define RH_RF24_PA_MODE_SWITCH_CURRENT                    0x01\n\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_RF24 RH_RF24.h <RH_RF24.h>\n/// \\brief Driver to send and receive unaddressed, unreliable datagrams via an RF24 and compatible radio transceiver.\n///\n/// Works with \n/// - Silicon Labs Si4460/1/2/3/4 transceiver chips\n/// - The equivalent HopeRF RF24/25/26/27 transceiver chips\n/// - HopeRF Complete modules: RFM24W/26W/27W\n///\n/// \\par Overview\n///\n/// This class provides basic functions for sending and receiving unaddressed, \n/// unreliable datagrams of arbitrary length to 250 octets per packet.\n///\n/// Manager classes may use this class to implement reliable, addressed datagrams and streams, \n/// mesh routers, repeaters, translators etc.\n///\n/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and \n/// modulation scheme.\n///\n/// This Driver provides an object-oriented interface for sending and receiving data messages with Hope-RF\n/// RF24 and compatible radio modules, such as the RFM24W module.\n///\n/// The Hope-RF (http://www.hoperf.com) RF24 family is a low-cost ISM transceiver\n/// chip. It supports FSK, GFSK, OOK over a wide range of frequencies and\n/// programmable data rates. HopeRF also sell these chips on modules which includes\n/// a crystal and antenna coupling circuits: RFM24W, RFM26W and RFM27W\n///\n/// This Driver provides functions for sending and receiving messages of up\n/// to 250 octets on any frequency supported by the RF24, in a range of\n/// predefined data rates and frequency deviations. Frequency can be set\n/// to any frequency from 142.0MHz to 1050.0MHz. Caution: most modules only support a more limited\n/// range of frequencies due to antenna tuning.\n///\n/// Up to 2 RFM24 modules can be connected to an Arduino (3 on a Mega),\n/// permitting the construction of translators and frequency changers, etc.\n///\n/// The following modulation types are suppported with a range of modem configurations for \n/// common data rates and frequency deviations:\n/// - OOK On-Off Keying\n/// - GFSK Gaussian Frequency Shift Keying\n/// - FSK Frequency Shift Keying\n///\n/// Support for other RF24 features such as on-chip temperature measurement, \n/// transmitter power control etc is also provided.\n///\n/// RH_RF24 uses interrupts to detect and handle events in the radio chip. The RF24 family has\n/// TX and RX FIFOs of 64 bytes, but through the use of interrupt, the RH_RF24 driver can send longer \n/// messages by filling or emptying the FIFOs on-the-fly.\n///\n/// Tested on Anarduino Mini http://www.anarduino.com/mini/ with arduino-1.0.5\n/// on OpenSuSE 13.1\n///\n/// \\par Packet Format\n///\n/// All messages sent and received by this RH_RF24 Driver conform to this packet format:\n///\n/// - 4 octets PREAMBLE (configurable)\n/// - 2 octets SYNC 0x2d, 0xd4 (configurable, so you can use this as a network filter)\n/// - Field containing 1 octet of message length and 2 octet CRC protecting this field\n/// - Field 2 containing at least 4 octets, and 2 octet CRC protecting this field:\n///  + 4 octets HEADER: (TO, FROM, ID, FLAGS)\n///  + 0 to 250 octets DATA \n///  + 2 octets CRC, computed on HEADER and DATA\n///\n/// \\par Connecting RFM-24 to Arduino\n///\n/// For RFM24/RFM26 and Teensy 3.1 or Anarduino Mini\n/// \\code\n///                 Teensy      RFM-24/RFM26\n///                 GND----------GND (ground in)\n///                 3V3----------VCC   (3.3V in)\n/// interrupt 2 pin D2-----------NIRQ  (interrupt request out)\n///          SS pin D10----------NSEL  (chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------SDI   (SPI Data in)\n///        MISO pin D12----------SDO   (SPI data out)\n///                 D9-----------SDN   (shutdown in)\n///                           /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)\n///                           \\--TX_ANT (TX antenna control in) RFM22B only\n///                           /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)\n///                           \\--RX_ANT (RX antenna control in) RFM22B only\n/// \\endcode\n/// Caution: tying the radio SDN pin to ground (though it might appear from the data sheets to make sense) \n/// does not always produce a reliable radio startup. So this driver controls the SDN pin directly.\n/// Note: the GPIO0-TX_ANT and GPIO1-RX_ANT connections are not required for the 11dBm RFM24W, \n/// which has no antenna switch.\n///\n/// If you have an Arduino Zero, you should note that you cannot use Pin 2 for the interrupt line \n/// (Pin 2 is for the NMI only), instead you can use any other pin (we use Pin 3) and initialise RH_RF69 like this:\n/// \\code\n/// // Slave Select is pin 10, interrupt is Pin 3\n/// RH_RF24 driver(10, 3);\n/// \\endcode\n///\n/// \\par Customising\n///\n/// The library will work out of the box with the provided examples on a radio with a 30MHz crystal, \n/// over the full frequency range and with\n/// a wide range of predefined modem configurations schemes and speeds. However, you may want to \n/// change the default behaviour of this library. There are several ways you can do this:\n///\n/// - Use the RH_RF24 API based on this documentation\n/// - Create your own ModemConfig and pass it to setModemreeegisters()\n/// - Generate a new radio_config_Si4460.h using the Silicon Labs WDS software package\n/// - Write directly to the radio registers and properties using command() and set_properties()\n///\n/// If your radio module has an XO crystal of other than 30MHz, you can change the value of \n/// RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ in radio_config_Si4460.h \n/// \\par RSSI\n///\n/// The RSSI (Received Signal Strength Indicator) is measured and latched after the message sync bytes are received.\n/// The latched RSSI is available from the lastRssi() member functionafter the complete message is received. \n/// Although lastRssi() \n/// supposedly returns a signed integer, in the case of this radio it actually returns an unsigned 8 bit integer (uint8_t)\n/// and you will have to cast the return value to use it:\n/// \\code\n/// uint8_t lastRssi = (uint8_t)rf24.lastRssi();\n/// \\endcode\n/// The units of RSSI are arbitrary and relative, with larger unsigned numbers indicating a stronger signal. Values up to 255\n/// are seen with radios in close proximity to each other. Lower limit of receivable strength is about 70.\n///\n/// \\par Transmitter Power\n///\n/// You can control the transmitter power on the RF24/25/26/27 transceiver\n/// with the RH_RF24::setTxPower() function. The argument can be any of\n/// 0x00 to 0x4f (for RFM24/Si4460) or\n/// 0x00 to 0x7f (for others)\n/// 0x00 will yield no measurable power. For other settings there is a non-linear correlation with actual\n/// RF power output (see below)\n/// The default is 0x10. Eg:\n/// \\code\n/// driver.setTxPower(0x10);\n/// \\endcode\n///\n/// We have made some actual power measurements against\n/// programmed power\n/// - Anarduino Mini with RFM24-433 and RFM26-433 at Vcc = 3.3V, in CW mode, 434MHz\n/// - 10cm RG58C/U soldered direct to RFM69 module ANT and GND\n/// - bnc connecteor\n/// - 12dB attenuator\n/// - BNC-SMA adapter\n/// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)\n/// - Digitech QM-1460 digital multimeter\n/// \\code\n/// Program power           Measured Power dBm\n///    HEX                  RFM24                RFM26\n///    0x00                 not measurable       not measurable\n///    0x01                 -20.4                -20.6\n///    0x0f                 2.4                  4.8\n///    0x1f                 9.4                  11.0\n///    0x2f                 11.2                 14.2\n///    0x3f                 11.6                 16.4\n///    0x4f                 11.6                 18.0\n///    0x5f                                      18.6\n///    0x6f                                      19.0\n///    0x7f                                      19.2\n/// \\endcode\n/// Caution: the actual radiated power output will depend heavily on the power supply voltage and the antenna.\n\nclass RH_RF24 : public RHSPIDriver\n{\npublic:\n    /// \\brief Defines property values for a set of modem configuration registers\n    ///\n    /// Defines property values for a set of modem configuration registers\n    /// that can be passed to setModemRegisters() if none of the choices in\n    /// ModemConfigChoice suit your need setModemRegisters() writes the\n    /// property values from this structure to the appropriate RF24 properties\n    /// to set the desired modulation type, data rate and deviation/bandwidth.\n    typedef struct\n    {\n\tuint8_t   prop_2000;   ///< Value for property RH_RF24_PROPERTY_MODEM_MOD_TYPE\n\tuint8_t   prop_2003;   ///< Value for property RH_RF24_PROPERTY_MODEM_DATA_RATE_2\n\tuint8_t   prop_2004;   ///< Value for property RH_RF24_PROPERTY_MODEM_DATA_RATE_1\n\tuint8_t   prop_2005;   ///< Value for property RH_RF24_PROPERTY_MODEM_DATA_RATE_0\n\tuint8_t   prop_2006;   ///< Value for property RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_3\n\tuint8_t   prop_200a;   ///< Value for property RH_RF24_PROPERTY_MODEM_FREQ_DEV_2\n\tuint8_t   prop_200b;   ///< Value for property RH_RF24_PROPERTY_MODEM_FREQ_DEV_1\n\tuint8_t   prop_200c;   ///< Value for property RH_RF24_PROPERTY_MODEM_FREQ_DEV_0\n\tuint8_t   prop_2018;   ///< Value for property RH_RF24_PROPERTY_MODEM_TX_RAMP_DELAY\n\tuint8_t   prop_201e;   ///< Value for property RH_RF24_PROPERTY_MODEM_DECIMATION_CFG1\n\tuint8_t   prop_201f;   ///< Value for property RH_RF24_PROPERTY_MODEM_DECIMATION_CFG0\n\tuint8_t   prop_2022;   ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_OSR_1\n\tuint8_t   prop_2023;   ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_OSR_0\n\tuint8_t   prop_2024;   ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_2\n\tuint8_t   prop_2025;   ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_1\n\tuint8_t   prop_2026;   ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_0\n\tuint8_t   prop_2027;   ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_GAIN_1\n\tuint8_t   prop_2028;   ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_GAIN_0\n\tuint8_t   prop_2029;   ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_GEAR\n\tuint8_t   prop_202d;   ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_WAIT\n\tuint8_t   prop_202e;   ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_GAIN_1\n\tuint8_t   prop_202f;   ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_GAIN_0\n\tuint8_t   prop_2030;   ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_LIMITER_1\n\tuint8_t   prop_2031;   ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_LIMITER_0\n\tuint8_t   prop_2035;   ///< Value for property RH_RF24_PROPERTY_MODEM_AGC_CONTROL\n\tuint8_t   prop_2038;   ///< Value for property RH_RF24_PROPERTY_MODEM_AGC_WINDOW_SIZE\n\tuint8_t   prop_2039;   ///< Value for property RH_RF24_PROPERTY_MODEM_AGC_RFPD_DECAY\n\tuint8_t   prop_203a;   ///< Value for property RH_RF24_PROPERTY_MODEM_AGC_IFPD_DECAY\n\tuint8_t   prop_203b;   ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_GAIN1\n\tuint8_t   prop_203c;   ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_GAIN0\n\tuint8_t   prop_203d;   ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_TH1\n\tuint8_t   prop_203e;   ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_TH0\n\tuint8_t   prop_203f;   ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_MAP\n\tuint8_t   prop_2040;   ///< Value for property RH_RF24_PROPERTY_MODEM_OOK_PDTC\n\tuint8_t   prop_2043;   ///< Value for property RH_RF24_PROPERTY_MODEM_OOK_MISC\n\tuint8_t   prop_2045;   ///< Value for property RH_RF24_PROPERTY_MODEM_RAW_CONTROL\n\tuint8_t   prop_2046;   ///< Value for property RH_RF24_PROPERTY_MODEM_RAW_EYE_1\n\tuint8_t   prop_2047;   ///< Value for property RH_RF24_PROPERTY_MODEM_RAW_EYE_0\n\tuint8_t   prop_204e;   ///< Value for property RH_RF24_PROPERTY_MODEM_RSSI_COMP\n\tuint8_t   prop_2100;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE13_7_0\n\tuint8_t   prop_2101;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE12_7_0\n\tuint8_t   prop_2102;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE11_7_0\n\tuint8_t   prop_2103;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE10_7_0\n\tuint8_t   prop_2104;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE9_7_0\n\tuint8_t   prop_2105;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE8_7_0\n\tuint8_t   prop_2106;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE7_7_0\n\tuint8_t   prop_2107;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE6_7_0\n\tuint8_t   prop_2108;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE5_7_0\n\tuint8_t   prop_2109;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE4_7_0\n\tuint8_t   prop_210a;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE3_7_0\n\tuint8_t   prop_210b;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE2_7_0\n\tuint8_t   prop_210c;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE1_7_0\n\tuint8_t   prop_210d;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE0_7_0\n\tuint8_t   prop_210e;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM0\n\tuint8_t   prop_210f;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM1\n\tuint8_t   prop_2110;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM2\n\tuint8_t   prop_2111;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM3\n\tuint8_t   prop_2112;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE13_7_0\n\tuint8_t   prop_2113;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE12_7_0\n\tuint8_t   prop_2114;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE11_7_0\n\tuint8_t   prop_2115;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE10_7_0\n\tuint8_t   prop_2116;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE9_7_0\n\tuint8_t   prop_2117;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE8_7_0\n\tuint8_t   prop_2118;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE7_7_0\n\tuint8_t   prop_2119;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE6_7_0\n\tuint8_t   prop_211a;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE5_7_0\n\tuint8_t   prop_211b;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE4_7_0\n\tuint8_t   prop_211c;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE3_7_0\n\tuint8_t   prop_211d;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE2_7_0\n\tuint8_t   prop_211e;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE1_7_0\n\tuint8_t   prop_211f;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE0_7_0\n\tuint8_t   prop_2120;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM0\n\tuint8_t   prop_2121;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM1\n\tuint8_t   prop_2122;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM2\n\tuint8_t   prop_2123;   ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM3\n\tuint8_t   prop_2203;   ///< Value for property RH_RF24_PROPERTY_PA_TC\n\tuint8_t   prop_2300;   ///< Value for property RH_RF24_PROPERTY_SYNTH_PFDCP_CPFF\n\tuint8_t   prop_2301;   ///< Value for property RH_RF24_PROPERTY_SYNTH_PFDCP_CPINT\n\tuint8_t   prop_2303;   ///< Value for property RH_RF24_PROPERTY_SYNTH_LPFILT3\n\tuint8_t   prop_2304;   ///< Value for property RH_RF24_PROPERTY_SYNTH_LPFILT2\n\tuint8_t   prop_2305;   ///< Value for property RH_RF24_PROPERTY_SYNTH_LPFILT1\n    } ModemConfig;\n  \n    /// Choices for setModemConfig() for a selected subset of common\n    /// modulation types, and data rates. If you need another configuration,\n    /// use the register calculator.  and call setModemRegisters() with your\n    /// desired settings.  \n    /// These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic\n    /// definitions and not their integer equivalents: its possible that values will be\n    /// changed in later versions (though we will try to avoid it).\n    /// Contributions of new complete and tested ModemConfigs ready to add to this list will be readily accepted.\n    typedef enum\n    {\n\tFSK_Rb0_5Fd1 = 0,         ///< FSK  Rb = 0.5kbs, Fd = 1kHz\n\tFSK_Rb5Fd10,              ///< FSK  Rb = 5kbs,   Fd = 10kHz\n\tFSK_Rb50Fd100,            ///< FSK  Rb = 50kbs,  Fd = 100kHz\n\tFSK_Rb150Fd300,           ///< FSK  Rb = 50kbs,  Fd = 100kHz\n\n\tGFSK_Rb0_5Fd1,            ///< GFSK Rb = 0.5kbs, Fd = 1kHz\n\tGFSK_Rb5Fd10,             ///< GFSK Rb = 5kbs,   Fd = 10kHz\n\tGFSK_Rb50Fd100,           ///< GFSK Rb = 50kbs,  Fd = 100kHz\n\tGFSK_Rb150Fd300,          ///< GFSK Rb = 150kbs, Fd = 300kHz\n\t\n\t// We were unable to get any other OOKs to work\n\tOOK_Rb5Bw30,              ///< OOK  Rb = 5kbs,   Bw = 30kHz\n\tOOK_Rb10Bw40,             ///< OOK  Rb = 10kbs,  Bw = 40kHz\n\n\t// We were unable to get any 4FSK or 4GFSK schemes to work\n\n    } ModemConfigChoice;\n\n    /// \\brief Defines the available choices for CRC\n    /// Types of permitted CRC polynomials, to be passed to setCRCPolynomial()\n    /// They deliberately have the same numeric values as the CRC_POLYNOMIAL field of PKT_CRC_CONFIG\n    typedef enum\n    {\n\tCRC_NONE = 0,\n\tCRC_ITU_T,\n\tCRC_IEC_16,\n\tCRC_Biacheva,\n\tCRC_16_IBM,\n\tCRC_CCITT,\n\tCRC_Koopman,\n\tCRC_IEEE_802_3,\n\tCRC_Castagnoli,\n    } CRCPolynomial;\n\n    /// \\brief Defines the commands we can interrogate in printRegisters\n    typedef struct\n    {\n\tuint8_t      cmd;       ///< The command number\n\tuint8_t      replyLen;  ///< Number of bytes in the reply stream (after the CTS)\n    }   CommandInfo;\n\n    /// Constructor. You can have multiple instances, but each instance must have its own\n    /// interrupt and slave select pin. After constructing, you must call init() to initialise the interface\n    /// and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient\n    /// distinct interrupt lines, one for each instance.\n    /// \\param[in] slaveSelectPin the Arduino pin number of the output to use to select the RF24 before\n    /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)\n    /// \\param[in] interruptPin The interrupt Pin number that is connected to the RF24 DIO0 interrupt line. \n    /// Defaults to pin 2.\n    /// Caution: You must specify an interrupt capable pin.\n    /// On many Arduino boards, there are limitations as to which pins may be used as interrupts.\n    /// On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin.\n    /// On other Arduinos pins 2 or 3. \n    /// See http://arduino.cc/en/Reference/attachInterrupt for more details.\n    /// On Chipkit Uno32, pins 38, 2, 7, 8, 35.\n    /// On other boards, any digital pin may be used.\n    /// \\param [in] sdnPin The pin number connected to SDN on the radio. Defaults to pin 9. \n    ///                     Connecting SDN directly to ground does not aloways provide reliable radio startup.\n    /// \\param[in] spi Pointer to the SPI interface object to use. \n    ///                Defaults to the standard Arduino hardware SPI interface\n    RH_RF24(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, uint8_t sdnPin = 9, RHGenericSPI& spi = hardware_spi);\n  \n    /// Initialises this instance and the radio module connected to it.\n    /// The following steps are taken:\n    /// - Initialise the slave select and shutdown pins and the SPI interface library\n    /// - Checks the connected RF24 module can be communicated\n    /// - Attaches an interrupt handler\n    /// - Configures the RF24 module\n    /// - Sets the frequency to 434.0 MHz\n    /// - Sets the modem data rate to GFSK_Rb5Fd10\n    /// - Sets the tranmitter power level to 16 (about 2.4dBm on RFM4)\n    /// \\return  true if everything was successful\n    bool        init();\n    \n    /// Sets the chip mode that will be used when the RH_RF24 driver is idle (ie not transmitting or receiving)\n    /// You can use this to control the power level consumed while idle, at the cost of slower\n    /// transition to tranmit or receive states\n    /// \\param[in] idleMode The chip state to use when idle. Sensible choices might be RH_RF24_DEVICE_STATE_SLEEP or RH_RF24_DEVICE_STATE_READY\n    void        setIdleMode(uint8_t idleMode);\n\n    /// Sets the transmitter and receiver \n    /// centre frequency.\n    /// Valid frequency ranges for RFM24/Si4460, Si4461, RFM25/Si4463 are:\n    /// 142MHz to 175Mhz, 284MHz to 350MHz, 425MHz to 525MHz, 850MHz to 1050MHz.\n    /// Valid frequency ranges for RFM26/Si4464 are:\n    /// 119MHz to 960MHz.\n    /// Caution: RFM modules are designed with antenna coupling components to suit a limited band\n    /// of frequencies (marked underneath the module). It is possible to set frequencies in other bands,\n    /// but you may only get little or no power radiated.\n    /// \\param[in] centre Frequency in MHz. \n    /// \\param[in] afcPullInRange Not used\n    /// \\return true if the selected frequency is within a valid range for the connected radio and if\n    ///         setting the new frequency succeeded.\n    bool        setFrequency(float centre, float afcPullInRange = 0.05);\n\n    /// Sets all the properties required to configure the data modem in the RF24, including the data rate, \n    /// bandwidths etc. You can use this to configure the modem with custom configurations if none of the \n    /// canned configurations in ModemConfigChoice suit you.\n    /// \\param[in] config A ModemConfig structure containing values for the modem configuration registers.\n    void           setModemRegisters(const ModemConfig* config);\n\n    /// Select one of the predefined modem configurations. If you need a modem configuration not provided \n    /// here, use setModemRegisters() with your own ModemConfig. The default after init() is RH_RF24::GFSK_Rb5Fd10.\n    /// \\param[in] index The configuration choice.\n    /// \\return true if index is a valid choice.\n    bool        setModemConfig(ModemConfigChoice index);\n\n    /// Starts the receiver and checks whether a received message is available.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a complete, valid message has been received and is able to be retrieved by\n    /// recv()\n    bool        available();\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    bool        recv(uint8_t* buf, uint8_t* len);\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is NOT permitted. \n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send (> 0)\n    /// \\return true if the message length was valid and it was correctly queued for transmit\n    bool        send(const uint8_t* data, uint8_t len);\n\n    /// The maximum message length supported by this driver\n    /// \\return The maximum message length supported by this driver\n    uint8_t maxMessageLength();\n\n    /// Sets the length of the preamble\n    /// in bytes. \n    /// Caution: this should be set to the same \n    /// value on all nodes in your network. Default is 4.\n    /// \\param[in] bytes Preamble length in bytes.  \n    void           setPreambleLength(uint16_t bytes);\n\n    /// Sets the sync words for transmit and receive \n    /// Caution: SyncWords should be set to the same \n    /// value on all nodes in your network. Nodes with different SyncWords set will never receive\n    /// each others messages, so different SyncWords can be used to isolate different\n    /// networks from each other. Default is { 0x2d, 0xd4 }.\n    /// \\param[in] syncWords Array of sync words, 1 to 4 octets long. NULL if no sync words to be used.\n    /// \\param[in] len Number of sync words to set, 1 to 4. 0 if no sync words to be used.\n    void           setSyncWords(const uint8_t* syncWords = NULL, uint8_t len = 0);\n\n    /// Sets the CRC polynomial to be used to generate the CRC for both receive and transmit\n    /// otherwise the default of CRC_16_IBM will be used.\n    /// \\param[in] polynomial One of RH_RF24::CRCPolynomial choices CRC_*\n    /// \\return true if polynomial is a valid option for this radio.\n    bool setCRCPolynomial(CRCPolynomial polynomial);\n\n    /// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, \n    /// disables them.\n    void           setModeIdle();\n\n    /// If current mode is Tx or Idle, changes it to Rx. \n    /// Starts the receiver in the RF24.\n    void           setModeRx();\n\n    /// If current mode is Rx or Idle, changes it to Rx. F\n    /// Starts the transmitter in the RF24.\n    void           setModeTx();\n\n    /// Sets the transmitter power output level register PA_PWR_LVL\n    /// The power argument to this function has a non-linear correlation with the actual RF power output.\n    /// See the transmitter power table above for some examples.\n    /// Also the Si446x Data Sheet section 5.4.2 may be helpful.\n    /// Be a good neighbour and set the lowest power level you need.\n    /// Caution: legal power limits may apply in certain countries.\n    /// After init(), the power will be set to 0x10.\n    /// \\param[in] power Transmitter power level. For RFM24/Si4460, valid values are 0x00 to 0x4f. For others, 0x00 to 0x7f\n    void           setTxPower(uint8_t power);\n\n    /// Dump the values of available command replies and properties\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// Not all commands have valid replies, therefore they are not all printed.\n    /// Caution: the list is very long\n    bool           printRegisters();\n\n    /// Send a string of command bytes to the chip and get a string of reply bytes\n    /// Different RFM24 commands take different numbers of command bytes and send back different numbers\n    /// of reply bytes. See the Si446x documentaiton for more details.\n    /// Both command bytes and reply bytes are optional\n    /// \\param[in] cmd The command number. One of RH_RF24_CMD_*\n    /// \\param[in] write_buf Pointer to write_len bytes of command input bytes to send. If there are none, set to NULL.\n    /// \\param[in] write_len The number of bytes to send from write_buf. If there are none, set to 0\n    /// \\param[out] read_buf Pointer to read_len bytes of storage where the reply stream from the comand will be written.\n    ///            If none are required, set to NULL\n    /// \\param[in] read_len The number of bytes to read from the reply stream. If none required, set to 0.\n    /// \\return true if the command succeeeded.\n    bool           command(uint8_t cmd, const uint8_t* write_buf = 0, uint8_t write_len = 0, uint8_t* read_buf = 0, uint8_t read_len = 0);\n\n    /// Set one or more chip properties using the RH_RF24_CMD_SET_PROPERTY\n    /// command. See the Si446x API Description AN625 for details on what properties are available.\n    /// param[in] firstProperty The property number of the first property to set. The first value in the values array\n    ///           will be used to set this property, and any subsequent values will be used to set the following properties.\n    ///           One of RH_RF24_PROPERTY_*\n    /// param[in] values Array of 0 or more values to write the firstProperty and subsequent proerties\n    /// param[in] count The number of values in the values array\n    /// \\return true if the command succeeeded.\n    bool           set_properties(uint16_t firstProperty, const uint8_t* values, uint8_t count);\n\n    /// Get one or more chip properties using the RH_RF24_CMD_GET_PROPERTY\n    /// command. See the Si446x API Description AN625 for details on what properties are available.\n    /// param[in] firstProperty The property number of the first property to get. The first value in the values array\n    ///           will be set with this property, and any subsequent values will be set from the following properties.\n    ///           One of RH_RF24_PROPERTY_*\n    /// param[out] values Array of 0 or more values to receive the firstProperty and subsequent proerties\n    /// param[in] count The number of values in the values array\n    /// \\return true if the command succeeeded.\n    bool           get_properties(uint16_t firstProperty, uint8_t* values, uint8_t count);\n\n    /// Measures and returns the current\n    /// Chip temperature.\n    /// \\return The current chip temperature in degrees Centigrade\n    float          get_temperature();\n\n    /// Measures and returns the current\n    /// Chip Vcc supply voltage.\n    /// \\return The current chip Vcc supply voltage in Volts.\n    float          get_battery_voltage();\n\n    /// Measures and returns the current\n    /// voltage applied to a GPIO pin (which has previously been configured as a voltage input)\n    /// \\param[in] gpio The GPIO pin to read. 0 to 3.\n    /// \\return The current pin voltage in Volts.\n    float          get_gpio_voltage(uint8_t gpio);\n\n    /// Read one of the Fast Read Response registers.\n    /// The Fast Read Response register must be previously configured with the matching\n    /// RH_RF24_PROPERTY_FRR_CTL_?_MODE property to select what chip property will be available in that register.\n    /// \\param[in] reg The index of the FRR register to read. 0 means FRR A, 1 means B etc.\n    /// \\return the value read from the specified Fast Read Response register.\n    uint8_t        frr_read(uint8_t reg);\n\n    /// Sets the radio into low-power sleep mode.\n    /// If successful, the transport will stay in sleep mode until woken by \n    /// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc)\n    /// Caution: there is a time penalty as the radio takes a finte time to wake from sleep mode.\n    /// \\return true if sleep mode was successfully entered.\n    virtual bool    sleep();\n\nprotected:\n    /// This is a low level function to handle the interrupts for one instance of RF24.\n    /// Called automatically by isr*()\n    /// Should not need to be called by user code.\n    void           handleInterrupt();\n\n    /// Clears the chips RX FIFO\n    /// \\return true if successful\n    bool           clearRxFifo();\n\n    /// Clears RH_RF24's internal TX and RX buffers and counters\n    void           clearBuffer();\n\n    /// Loads the next part of the currently transmitting message \n    /// into the chips TX buffer\n    void           sendNextFragment();\n\n    /// Copies the next part of the currenrtly received message from the chips RX FIFO to the \n    /// receive buffer\n    void           readNextFragment();\n\n    /// Loads data into the chips TX FIFO\n    /// \\param[in] data Array of data bytes to be loaded\n    /// \\param[in] len Number of bytes in data to be loaded\n    /// \\return true if successful\n    bool           writeTxFifo(uint8_t *data, uint8_t len);\n\n    /// Checks the contents of the RX buffer.\n    /// If it contans a valid message adressed to this node\n    /// sets _rxBufValid.\n    void           validateRxBuf();\n\n    /// Cycles the Shutdown pin to force the cradio chip to reset\n    void           power_on_reset();\n\n    /// Sets registers, commands and properties\n    /// in the ratio according to the data in the commands array\n    /// \\param[in] commands Array of data containing radio commands in the format provided by radio_config_Si4460.h\n    /// \\return true if successful\n    bool           configure(const uint8_t* commands);\n\n    /// Clears all pending interrutps in the radio chip.\n    bool           cmd_clear_all_interrupts();\n\nprivate:\n\n    /// Low level interrupt service routine for RF24 connected to interrupt 0\n    static void         isr0();\n\n    /// Low level interrupt service routine for RF24 connected to interrupt 1\n    static void         isr1();\n\n    /// Low level interrupt service routine for RF24 connected to interrupt 1\n    static void         isr2();\n\n    /// Array of instances connected to interrupts 0 and 1\n    static RH_RF24*     _deviceForInterrupt[];\n\n    /// Index of next interrupt number to use in _deviceForInterrupt\n    static uint8_t      _interruptCount;\n\n    /// The configured interrupt pin connected to this instance\n    uint8_t             _interruptPin;\n\n    /// The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated)\n    /// else 0xff\n    uint8_t             _myInterruptIndex;\n\n    /// The configured pin connected to the SDN pin of the radio\n    uint8_t             _sdnPin;\n\n    /// The radio OP mode to use when mode is RHModeIdle\n    uint8_t             _idleMode; \n\n    /// The reported PART device type\n    uint16_t             _deviceType;\n\n    /// The selected output power in dBm\n    int8_t              _power;\n\n    /// The message length in _buf\n    volatile uint8_t    _bufLen;\n\n    /// Array of octets of the last received message or the next to transmit message\n    uint8_t             _buf[RH_RF24_MAX_PAYLOAD_LEN];\n\n    /// True when there is a valid message in the Rx buffer\n    volatile bool       _rxBufValid;\n\n    /// Index into TX buffer of the next to send chunk\n    volatile uint8_t    _txBufSentIndex;\n  \n    /// Time in millis since the last preamble was received (and the last time the RSSI was measured)\n    uint32_t            _lastPreambleTime;\n\n};\n\n/// @example rf24_client.pde\n/// @example rf24_server.pde\n/// @example rf24_reliable_datagram_client.pde\n/// @example rf24_reliable_datagram_server.pde\n\n#endif\n"
  },
  {
    "path": "RH_RF69.cpp",
    "content": "// RH_RF69.cpp\n//\n// Copyright (C) 2011 Mike McCauley\n// $Id: RH_RF69.cpp,v 1.27 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_RF69.h>\n\n// Interrupt vectors for the 3 Arduino interrupt pins\n// Each interrupt can be handled by a different instance of RH_RF69, allowing you to have\n// 2 or more RF69s per Arduino\n#ifndef RH_RF69_IRQLESS\nRH_RF69* RH_RF69::_deviceForInterrupt[RH_RF69_NUM_INTERRUPTS] = {0, 0, 0};\nuint8_t RH_RF69::_interruptCount = 0; // Index into _deviceForInterrupt for next device\n#endif\n\n// These are indexed by the values of ModemConfigChoice\n// Stored in flash (program) memory to save SRAM\n// It is important to keep the modulation index for FSK between 0.5 and 10\n// modulation index = 2 * Fdev / BR\n// Note that I have not had much success with FSK with Fd > ~5\n// You have to construct these by hand, using the data from the RF69 Datasheet :-(\n// or use the SX1231 starter kit software (Ctl-Alt-N to use that without a connected radio)\n#define CONFIG_FSK (RH_RF69_DATAMODUL_DATAMODE_PACKET | RH_RF69_DATAMODUL_MODULATIONTYPE_FSK | RH_RF69_DATAMODUL_MODULATIONSHAPING_FSK_NONE)\n#define CONFIG_GFSK (RH_RF69_DATAMODUL_DATAMODE_PACKET | RH_RF69_DATAMODUL_MODULATIONTYPE_FSK | RH_RF69_DATAMODUL_MODULATIONSHAPING_FSK_BT1_0)\n#define CONFIG_OOK (RH_RF69_DATAMODUL_DATAMODE_PACKET | RH_RF69_DATAMODUL_MODULATIONTYPE_OOK | RH_RF69_DATAMODUL_MODULATIONSHAPING_OOK_NONE)\n\n// Choices for RH_RF69_REG_37_PACKETCONFIG1:\n#define CONFIG_NOWHITE (RH_RF69_PACKETCONFIG1_PACKETFORMAT_VARIABLE | RH_RF69_PACKETCONFIG1_DCFREE_NONE | RH_RF69_PACKETCONFIG1_CRC_ON | RH_RF69_PACKETCONFIG1_ADDRESSFILTERING_NONE)\n#define CONFIG_WHITE (RH_RF69_PACKETCONFIG1_PACKETFORMAT_VARIABLE | RH_RF69_PACKETCONFIG1_DCFREE_WHITENING | RH_RF69_PACKETCONFIG1_CRC_ON | RH_RF69_PACKETCONFIG1_ADDRESSFILTERING_NONE)\n#define CONFIG_MANCHESTER (RH_RF69_PACKETCONFIG1_PACKETFORMAT_VARIABLE | RH_RF69_PACKETCONFIG1_DCFREE_MANCHESTER | RH_RF69_PACKETCONFIG1_CRC_ON | RH_RF69_PACKETCONFIG1_ADDRESSFILTERING_NONE)\nPROGMEM static const RH_RF69::ModemConfig MODEM_CONFIG_TABLE[] =\n{\n    //  02,        03,   04,   05,   06,   19,   1a,  37\n    // FSK, No Manchester, no shaping, whitening, CRC, no address filtering\n    // AFC BW == RX BW == 2 x bit rate\n    // Low modulation indexes of ~ 1 at slow speeds do not seem to work very well. Choose MI of 2.\n    { CONFIG_FSK,  0x3e, 0x80, 0x00, 0x52, 0xf4, 0xf4, CONFIG_WHITE}, // FSK_Rb2Fd5      \n    { CONFIG_FSK,  0x34, 0x15, 0x00, 0x4f, 0xf4, 0xf4, CONFIG_WHITE}, // FSK_Rb2_4Fd4_8\n    { CONFIG_FSK,  0x1a, 0x0b, 0x00, 0x9d, 0xf4, 0xf4, CONFIG_WHITE}, // FSK_Rb4_8Fd9_6\n\n    { CONFIG_FSK,  0x0d, 0x05, 0x01, 0x3b, 0xf4, 0xf4, CONFIG_WHITE}, // FSK_Rb9_6Fd19_2\n    { CONFIG_FSK,  0x06, 0x83, 0x02, 0x75, 0xf3, 0xf3, CONFIG_WHITE}, // FSK_Rb19_2Fd38_4\n    { CONFIG_FSK,  0x03, 0x41, 0x04, 0xea, 0xf2, 0xf2, CONFIG_WHITE}, // FSK_Rb38_4Fd76_8\n\n    { CONFIG_FSK,  0x02, 0x2c, 0x07, 0xae, 0xe2, 0xe2, CONFIG_WHITE}, // FSK_Rb57_6Fd120\n    { CONFIG_FSK,  0x01, 0x00, 0x08, 0x00, 0xe1, 0xe1, CONFIG_WHITE}, // FSK_Rb125Fd125\n    { CONFIG_FSK,  0x00, 0x80, 0x10, 0x00, 0xe0, 0xe0, CONFIG_WHITE}, // FSK_Rb250Fd250\n    { CONFIG_FSK,  0x02, 0x40, 0x03, 0x33, 0x42, 0x42, CONFIG_WHITE}, // FSK_Rb55555Fd50 \n\n    // MOTEINO\n    // REGAFCBW set to default 0x8A, No DC-free encoding/decoding performed\n    { CONFIG_FSK,  0x02, 0x40, 0x03, 0x33, 0x42, 0x8A, CONFIG_NOWHITE}, // FSK_MOTEINO\n\n    //  02,        03,   04,   05,   06,   19,   1a,  37\n    // GFSK (BT=1.0), No Manchester, whitening, CRC, no address filtering\n    // AFC BW == RX BW == 2 x bit rate\n    { CONFIG_GFSK, 0x3e, 0x80, 0x00, 0x52, 0xf4, 0xf5, CONFIG_WHITE}, // GFSK_Rb2Fd5\n    { CONFIG_GFSK, 0x34, 0x15, 0x00, 0x4f, 0xf4, 0xf4, CONFIG_WHITE}, // GFSK_Rb2_4Fd4_8\n    { CONFIG_GFSK, 0x1a, 0x0b, 0x00, 0x9d, 0xf4, 0xf4, CONFIG_WHITE}, // GFSK_Rb4_8Fd9_6\n\n    { CONFIG_GFSK, 0x0d, 0x05, 0x01, 0x3b, 0xf4, 0xf4, CONFIG_WHITE}, // GFSK_Rb9_6Fd19_2\n    { CONFIG_GFSK, 0x06, 0x83, 0x02, 0x75, 0xf3, 0xf3, CONFIG_WHITE}, // GFSK_Rb19_2Fd38_4\n    { CONFIG_GFSK, 0x03, 0x41, 0x04, 0xea, 0xf2, 0xf2, CONFIG_WHITE}, // GFSK_Rb38_4Fd76_8\n\n    { CONFIG_GFSK, 0x02, 0x2c, 0x07, 0xae, 0xe2, 0xe2, CONFIG_WHITE}, // GFSK_Rb57_6Fd120\n    { CONFIG_GFSK, 0x01, 0x00, 0x08, 0x00, 0xe1, 0xe1, CONFIG_WHITE}, // GFSK_Rb125Fd125\n    { CONFIG_GFSK, 0x00, 0x80, 0x10, 0x00, 0xe0, 0xe0, CONFIG_WHITE}, // GFSK_Rb250Fd250\n    { CONFIG_GFSK, 0x02, 0x40, 0x03, 0x33, 0x42, 0x42, CONFIG_WHITE}, // GFSK_Rb55555Fd50 \n\n    //  02,        03,   04,   05,   06,   19,   1a,  37\n    // OOK, No Manchester, no shaping, whitening, CRC, no address filtering\n    // with the help of the SX1231 configuration program\n    // AFC BW == RX BW\n    // All OOK configs have the default:\n    // Threshold Type: Peak\n    // Peak Threshold Step: 0.5dB\n    // Peak threshiold dec: ONce per chip\n    // Fixed threshold: 6dB\n    { CONFIG_OOK,  0x7d, 0x00, 0x00, 0x10, 0x88, 0x88, CONFIG_WHITE}, // OOK_Rb1Bw1\n    { CONFIG_OOK,  0x68, 0x2b, 0x00, 0x10, 0xf1, 0xf1, CONFIG_WHITE}, // OOK_Rb1_2Bw75\n    { CONFIG_OOK,  0x34, 0x15, 0x00, 0x10, 0xf5, 0xf5, CONFIG_WHITE}, // OOK_Rb2_4Bw4_8\n    { CONFIG_OOK,  0x1a, 0x0b, 0x00, 0x10, 0xf4, 0xf4, CONFIG_WHITE}, // OOK_Rb4_8Bw9_6\n    { CONFIG_OOK,  0x0d, 0x05, 0x00, 0x10, 0xf3, 0xf3, CONFIG_WHITE}, // OOK_Rb9_6Bw19_2\n    { CONFIG_OOK,  0x06, 0x83, 0x00, 0x10, 0xf2, 0xf2, CONFIG_WHITE}, // OOK_Rb19_2Bw38_4\n    { CONFIG_OOK,  0x03, 0xe8, 0x00, 0x10, 0xe2, 0xe2, CONFIG_WHITE}, // OOK_Rb32Bw64\n\n//    { CONFIG_FSK,  0x68, 0x2b, 0x00, 0x52, 0x55, 0x55, CONFIG_WHITE}, // works: Rb1200 Fd 5000 bw10000, DCC 400\n//    { CONFIG_FSK,  0x0c, 0x80, 0x02, 0x8f, 0x52, 0x52, CONFIG_WHITE}, // works 10/40/80\n//    { CONFIG_FSK,  0x0c, 0x80, 0x02, 0x8f, 0x53, 0x53, CONFIG_WHITE}, // works 10/40/40\n\n};\nRH_RF69::RH_RF69(uint8_t slaveSelectPin, uint8_t interruptPin, RHGenericSPI& spi)\n    :\n    RHSPIDriver(slaveSelectPin, spi)\n{\n    _idleMode = RH_RF69_OPMODE_MODE_STDBY;\n#ifndef RH_RF69_IRQLESS\n    _interruptPin = interruptPin;\n    _myInterruptIndex = 0xff; // Not allocated yet\n#endif\n}\n\nvoid RH_RF69::setIdleMode(uint8_t idleMode)\n{\n    _idleMode = idleMode;\n}\n\nbool RH_RF69::init()\n{\n    if (!RHSPIDriver::init())\n\treturn false;\n\n#ifndef RH_RF69_IRQLESS\n    // Determine the interrupt number that corresponds to the interruptPin\n    int interruptNumber = digitalPinToInterrupt(_interruptPin);\n    if (interruptNumber == NOT_AN_INTERRUPT)\n\treturn false;\n#ifdef RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER\n    interruptNumber = _interruptPin;\n#endif\n#endif // ndef RH_RF69_IRQLESS\n\n    // Get the device type and check it\n    // This also tests whether we are really connected to a device\n    // My test devices return 0x24\n    _deviceType = spiRead(RH_RF69_REG_10_VERSION);\n    if (_deviceType == 00 ||\n\t_deviceType == 0xff)\n\treturn false;\n\n#ifndef RH_RF69_IRQLESS\n\n    // Add by Adrien van den Bossche <vandenbo@univ-tlse2.fr> for Teensy\n    // ARM M4 requires the below. else pin interrupt doesn't work properly.\n    // On all other platforms, its innocuous, belt and braces\n    pinMode(_interruptPin, INPUT); \n\n    // Set up interrupt handler\n    // Since there are a limited number of interrupt glue functions isr*() available,\n    // we can only support a limited number of devices simultaneously\n    // ON some devices, notably most Arduinos, the interrupt pin passed in is actuallt the \n    // interrupt number. You have to figure out the interruptnumber-to-interruptpin mapping\n    // yourself based on knwledge of what Arduino board you are running on.\n    if (_myInterruptIndex == 0xff)\n    {\n\t// First run, no interrupt allocated yet\n\tif (_interruptCount <= RH_RF69_NUM_INTERRUPTS)\n\t    _myInterruptIndex = _interruptCount++;\n\telse\n\t    return false; // Too many devices, not enough interrupt vectors\n    }\n    _deviceForInterrupt[_myInterruptIndex] = this;\n    if (_myInterruptIndex == 0)\n\tattachInterrupt(interruptNumber, isr0, RISING);\n    else if (_myInterruptIndex == 1)\n\tattachInterrupt(interruptNumber, isr1, RISING);\n    else if (_myInterruptIndex == 2)\n\tattachInterrupt(interruptNumber, isr2, RISING);\n    else\n\treturn false; // Too many devices, not enough interrupt vectors\n\n#endif // ndef RH_RF69_IRQLESS\n\n    setModeIdle();\n\n    // Configure important RH_RF69 registers\n    // Here we set up the standard packet format for use by the RH_RF69 library:\n    // 4 bytes preamble\n    // 2 SYNC words 2d, d4\n    // 2 CRC CCITT octets computed on the header, length and data (this in the modem config data)\n    // 0 to 60 bytes data\n    // RSSI Threshold -114dBm\n    // We dont use the RH_RF69s address filtering: instead we prepend our own headers to the beginning\n    // of the RH_RF69 payload\n    spiWrite(RH_RF69_REG_3C_FIFOTHRESH, RH_RF69_FIFOTHRESH_TXSTARTCONDITION_NOTEMPTY | 0x0f); // thresh 15 is default\n    // RSSITHRESH is default\n//    spiWrite(RH_RF69_REG_29_RSSITHRESH, 220); // -110 dbM\n    // SYNCCONFIG is default. SyncSize is set later by setSyncWords()\n//    spiWrite(RH_RF69_REG_2E_SYNCCONFIG, RH_RF69_SYNCCONFIG_SYNCON); // auto, tolerance 0\n    // PAYLOADLENGTH is default\n//    spiWrite(RH_RF69_REG_38_PAYLOADLENGTH, RH_RF69_FIFO_SIZE); // max size only for RX\n    // PACKETCONFIG 2 is default \n    spiWrite(RH_RF69_REG_6F_TESTDAGC, RH_RF69_TESTDAGC_CONTINUOUSDAGC_IMPROVED_LOWBETAOFF);\n    // If high power boost set previously, disable it\n    spiWrite(RH_RF69_REG_5A_TESTPA1, RH_RF69_TESTPA1_NORMAL);\n    spiWrite(RH_RF69_REG_5C_TESTPA2, RH_RF69_TESTPA2_NORMAL);\n\n    // The following can be changed later by the user if necessary.\n    // Set up default configuration\n    uint8_t syncwords[] = { 0x2d, 0xd4 };\n    setSyncWords(syncwords, sizeof(syncwords)); // Same as RF22's\n    // Reasonably fast and reliable default speed and modulation\n    setModemConfig(GFSK_Rb250Fd250);\n\n    // 3 would be sufficient, but this is the same as RF22's\n    setPreambleLength(4);\n    // An innocuous ISM frequency, same as RF22's\n    setFrequency(434.0);\n    // No encryption\n    setEncryptionKey(NULL);\n    // +13dBm, same as power-on default\n    setTxPower(13); \n\n    return true;\n}\n\n// C++ level interrupt handler for this instance\n// RH_RF69 is unusual in Mthat it has several interrupt lines, and not a single, combined one.\n// On Moteino, only one of the several interrupt lines (DI0) from the RH_RF69 is connnected to the processor.\n// We use this to get PACKETSDENT and PAYLOADRADY interrupts.\n#ifndef RH_RF69_IRQLESS\nvoid RH_RF69::handleInterrupt()\n{\n    // Get the interrupt cause\n    uint8_t irqflags2 = spiRead(RH_RF69_REG_28_IRQFLAGS2);\n    if (_mode == RHModeTx && (irqflags2 & RH_RF69_IRQFLAGS2_PACKETSENT))\n    {\n\t// A transmitter message has been fully sent\n\tsetModeIdle(); // Clears FIFO\n\t_txGood++;\n//\tSerial.println(\"PACKETSENT\");\n    }\n    // Must look for PAYLOADREADY, not CRCOK, since only PAYLOADREADY occurs _after_ AES decryption\n    // has been done\n    if (_mode == RHModeRx && (irqflags2 & RH_RF69_IRQFLAGS2_PAYLOADREADY))\n    {\n\t// A complete message has been received with good CRC\n\t_lastRssi = -((int8_t)(spiRead(RH_RF69_REG_24_RSSIVALUE) >> 1));\n\t_lastPreambleTime = millis();\n\n\tsetModeIdle();\n\t// Save it in our buffer\n\treadFifo();\n//\tSerial.println(\"PAYLOADREADY\");\n    }\n}\n#endif // ndef RH_RF69_IRQLESS\n\n// Low level function reads the FIFO and checks the address\n// Caution: since we put our headers in what the RH_RF69 considers to be the payload, if encryption is enabled\n// we have to suffer the cost of decryption before we can determine whether the address is acceptable. \n// Performance issue?\nvoid RH_RF69::readFifo()\n{\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    _spi.transfer(RH_RF69_REG_00_FIFO); // Send the start address with the write mask off\n    uint8_t payloadlen = _spi.transfer(0); // First byte is payload len (counting the headers)\n    if (payloadlen <= RH_RF69_MAX_ENCRYPTABLE_PAYLOAD_LEN &&\n\tpayloadlen >= RH_RF69_HEADER_LEN)\n    {\n\t_rxHeaderTo = _spi.transfer(0);\n\t// Check addressing\n\tif (_promiscuous ||\n\t    _rxHeaderTo == _thisAddress ||\n\t    _rxHeaderTo == RH_BROADCAST_ADDRESS)\n\t{\n\t    // Get the rest of the headers\n\t    _rxHeaderFrom  = _spi.transfer(0);\n\t    _rxHeaderId    = _spi.transfer(0);\n\t    _rxHeaderFlags = _spi.transfer(0);\n\t    // And now the real payload\n\t    for (_bufLen = 0; _bufLen < (payloadlen - RH_RF69_HEADER_LEN); _bufLen++)\n\t\t_buf[_bufLen] = _spi.transfer(0);\n\t    _rxGood++;\n\t    _rxBufValid = true;\n\t}\n    }\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n    // Any junk remaining in the FIFO will be cleared next time we go to receive mode.\n}\n\n// These are low level functions that call the interrupt handler for the correct\n// instance of RH_RF69.\n// 3 interrupts allows us to have 3 different devices\n#ifndef RH_RF69_IRQLESS\nvoid RH_RF69::isr0()\n{\n    if (_deviceForInterrupt[0])\n\t_deviceForInterrupt[0]->handleInterrupt();\n}\nvoid RH_RF69::isr1()\n{\n    if (_deviceForInterrupt[1])\n\t_deviceForInterrupt[1]->handleInterrupt();\n}\nvoid RH_RF69::isr2()\n{\n    if (_deviceForInterrupt[2])\n\t_deviceForInterrupt[2]->handleInterrupt();\n}\n#endif // ndef RH_RF69_IRQLESS\n\n\nint8_t RH_RF69::temperatureRead()\n{\n    // Caution: must be ins standby.\n//    setModeIdle();\n    spiWrite(RH_RF69_REG_4E_TEMP1, RH_RF69_TEMP1_TEMPMEASSTART); // Start the measurement\n    while (spiRead(RH_RF69_REG_4E_TEMP1) & RH_RF69_TEMP1_TEMPMEASRUNNING)\n\t; // Wait for the measurement to complete\n    return 166 - spiRead(RH_RF69_REG_4F_TEMP2); // Very approximate, based on observation\n}\n\nbool RH_RF69::setFrequency(float centre, float afcPullInRange)\n{\n    // Frf = FRF / FSTEP\n    uint32_t frf = (uint32_t)((centre * 1000000.0) / RH_RF69_FSTEP);\n    spiWrite(RH_RF69_REG_07_FRFMSB, (frf >> 16) & 0xff);\n    spiWrite(RH_RF69_REG_08_FRFMID, (frf >> 8) & 0xff);\n    spiWrite(RH_RF69_REG_09_FRFLSB, frf & 0xff);\n\n    // afcPullInRange is not used\n    return true;\n}\n\nint8_t RH_RF69::rssiRead()\n{\n    // Force a new value to be measured\n    // Hmmm, this hangs forever!\n#if 0\n    spiWrite(RH_RF69_REG_23_RSSICONFIG, RH_RF69_RSSICONFIG_RSSISTART);\n    while (!(spiRead(RH_RF69_REG_23_RSSICONFIG) & RH_RF69_RSSICONFIG_RSSIDONE))\n\t;\n#endif\n    return -((int8_t)(spiRead(RH_RF69_REG_24_RSSIVALUE) >> 1));\n}\n\nvoid RH_RF69::setOpMode(uint8_t mode)\n{\n    uint8_t opmode = spiRead(RH_RF69_REG_01_OPMODE);\n    opmode &= ~RH_RF69_OPMODE_MODE;\n    opmode |= (mode & RH_RF69_OPMODE_MODE);\n    spiWrite(RH_RF69_REG_01_OPMODE, opmode);\n\n    // Wait for mode to change.\n    while (!(spiRead(RH_RF69_REG_27_IRQFLAGS1) & RH_RF69_IRQFLAGS1_MODEREADY))\n\t;\n}\n\nvoid RH_RF69::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\tif (_power >= 18)\n\t{\n\t    // If high power boost, return power amp to receive mode\n\t    spiWrite(RH_RF69_REG_5A_TESTPA1, RH_RF69_TESTPA1_NORMAL);\n\t    spiWrite(RH_RF69_REG_5C_TESTPA2, RH_RF69_TESTPA2_NORMAL);\n\t}\n\tsetOpMode(_idleMode);\n\t_mode = RHModeIdle;\n    }\n}\n\nbool RH_RF69::sleep()\n{\n    if (_mode != RHModeSleep)\n    {\n\tspiWrite(RH_RF69_REG_01_OPMODE, RH_RF69_OPMODE_MODE_SLEEP);\n\t_mode = RHModeSleep;\n    }\n    return true;\n}\n\nvoid RH_RF69::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\tif (_power >= 18)\n\t{\n\t    // If high power boost, return power amp to receive mode\n\t    spiWrite(RH_RF69_REG_5A_TESTPA1, RH_RF69_TESTPA1_NORMAL);\n\t    spiWrite(RH_RF69_REG_5C_TESTPA2, RH_RF69_TESTPA2_NORMAL);\n\t}\n\tspiWrite(RH_RF69_REG_25_DIOMAPPING1, RH_RF69_DIOMAPPING1_DIO0MAPPING_01); // Set interrupt line 0 PayloadReady\n\tsetOpMode(RH_RF69_OPMODE_MODE_RX); // Clears FIFO\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_RF69::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\tif (_power >= 18)\n\t{\n\t    // Set high power boost mode\n\t    // Note that OCP defaults to ON so no need to change that.\n\t    spiWrite(RH_RF69_REG_5A_TESTPA1, RH_RF69_TESTPA1_BOOST);\n\t    spiWrite(RH_RF69_REG_5C_TESTPA2, RH_RF69_TESTPA2_BOOST);\n\t}\n\tspiWrite(RH_RF69_REG_25_DIOMAPPING1, RH_RF69_DIOMAPPING1_DIO0MAPPING_00); // Set interrupt line 0 PacketSent\n\tsetOpMode(RH_RF69_OPMODE_MODE_TX); // Clears FIFO\n\t_mode = RHModeTx;\n    }\n}\n\nvoid RH_RF69::setTxPower(int8_t power)\n{\n    _power = power;\n\n    uint8_t palevel;\n    if (_power < -18)\n\t_power = -18;\n\n    // See http://www.hoperf.com/upload/rfchip/RF69-V1.2.pdf section 3.3.6\n    // for power formulas\n    if (_power <= 13)\n    {\n\t// -18dBm to +13dBm\n\tpalevel = RH_RF69_PALEVEL_PA0ON | ((_power + 18) & RH_RF69_PALEVEL_OUTPUTPOWER);\n    }\n    else if (_power >= 18)\n    {\n\t// +18dBm to +20dBm\n\t// Need PA1+PA2\n\t// Also need PA boost settings change when tx is turned on and off, see setModeTx()\n\tpalevel = RH_RF69_PALEVEL_PA1ON | RH_RF69_PALEVEL_PA2ON | ((_power + 11) & RH_RF69_PALEVEL_OUTPUTPOWER);\n    }\n    else\n    {\n\t// +14dBm to +17dBm\n\t// Need PA1+PA2\n\tpalevel = RH_RF69_PALEVEL_PA1ON | RH_RF69_PALEVEL_PA2ON | ((_power + 14) & RH_RF69_PALEVEL_OUTPUTPOWER);\n    }\n    spiWrite(RH_RF69_REG_11_PALEVEL, palevel);\n}\n\n// Sets registers from a canned modem configuration structure\nvoid RH_RF69::setModemRegisters(const ModemConfig* config)\n{\n    spiBurstWrite(RH_RF69_REG_02_DATAMODUL,     &config->reg_02, 5);\n    spiBurstWrite(RH_RF69_REG_19_RXBW,          &config->reg_19, 2);\n    spiWrite(RH_RF69_REG_37_PACKETCONFIG1,       config->reg_37);\n}\n\n// Set one of the canned FSK Modem configs\n// Returns true if its a valid choice\nbool RH_RF69::setModemConfig(ModemConfigChoice index)\n{\n    if (index > (signed int)(sizeof(MODEM_CONFIG_TABLE) / sizeof(ModemConfig)))\n        return false;\n\n    ModemConfig cfg;\n    memcpy_P(&cfg, &MODEM_CONFIG_TABLE[index], sizeof(RH_RF69::ModemConfig));\n    setModemRegisters(&cfg);\n\n    return true;\n}\n\n// Return the canned FSK Modem configs\nbool RH_RF69::getModemConfig(ModemConfigChoice index, ModemConfig* config)\n{\n  if (index > (signed int)(sizeof(MODEM_CONFIG_TABLE) / sizeof(ModemConfig)))\n    return false;\n\n  memcpy_P(config, &MODEM_CONFIG_TABLE[index], sizeof(RH_RF69::ModemConfig));\n\n  return true;\n}\n\nvoid RH_RF69::setPreambleLength(uint16_t bytes)\n{\n    spiWrite(RH_RF69_REG_2C_PREAMBLEMSB, bytes >> 8);\n    spiWrite(RH_RF69_REG_2D_PREAMBLELSB, bytes & 0xff);\n}\n\nvoid RH_RF69::setSyncWords(const uint8_t* syncWords, uint8_t len)\n{\n    uint8_t syncconfig = spiRead(RH_RF69_REG_2E_SYNCCONFIG);\n    if (syncWords && len && len <= 4)\n    {\n\tspiBurstWrite(RH_RF69_REG_2F_SYNCVALUE1, syncWords, len);\n\tsyncconfig |= RH_RF69_SYNCCONFIG_SYNCON;\n    }\n    else\n\tsyncconfig &= ~RH_RF69_SYNCCONFIG_SYNCON;\n    syncconfig &= ~RH_RF69_SYNCCONFIG_SYNCSIZE;\n    syncconfig |= (len-1) << 3;\n    spiWrite(RH_RF69_REG_2E_SYNCCONFIG, syncconfig);\n}\n\nvoid RH_RF69::setEncryptionKey(uint8_t* key)\n{\n    if (key)\n    {\n\tspiBurstWrite(RH_RF69_REG_3E_AESKEY1, key, 16);\n\tspiWrite(RH_RF69_REG_3D_PACKETCONFIG2, spiRead(RH_RF69_REG_3D_PACKETCONFIG2) | RH_RF69_PACKETCONFIG2_AESON);\n    }\n    else\n    {\n\tspiWrite(RH_RF69_REG_3D_PACKETCONFIG2, spiRead(RH_RF69_REG_3D_PACKETCONFIG2) & ~RH_RF69_PACKETCONFIG2_AESON);\n    }\n}\n\nbool RH_RF69::available()\n{\n#ifdef RH_RF69_IRQLESS\n    // As we have not enabled IRQ, ne need to check internal IRQ register of device\n    uint8_t irqflags2 = spiRead(RH_RF69_REG_28_IRQFLAGS2);\n\n    if (_mode == RHModeRx && (irqflags2 & RH_RF69_IRQFLAGS2_PAYLOADREADY))\n    {\n    // A complete message has been received with good CRC\n    _lastRssi = -((int8_t)(spiRead(RH_RF69_REG_24_RSSIVALUE) >> 1));\n    _lastPreambleTime = millis();\n\n    setModeIdle();\n\n    // Save it in our buffer\n    readFifo();\n    }\n#endif // defined RH_RF69_IRQLESS\n\n    if (_mode == RHModeTx)\n\treturn false;\n    setModeRx(); // Make sure we are receiving\n    return _rxBufValid;\n}\n\nbool RH_RF69::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n\n    if (buf && len)\n    {\n\tATOMIC_BLOCK_START;\n\tif (*len > _bufLen)\n\t    *len = _bufLen;\n\tmemcpy(buf, _buf, *len);\n\tATOMIC_BLOCK_END;\n    }\n    _rxBufValid = false; // Got the most recent message\n//    printBuffer(\"recv:\", buf, *len);\n    return true;\n}\n\nbool RH_RF69::send(const uint8_t* data, uint8_t len)\n{\n    if (len > RH_RF69_MAX_MESSAGE_LEN)\n\treturn false;\n\n    waitPacketSent(); // Make sure we dont interrupt an outgoing message\n    setModeIdle(); // Prevent RX while filling the fifo\n\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    ATOMIC_BLOCK_START;\n    digitalWrite(_slaveSelectPin, LOW);\n    _spi.transfer(RH_RF69_REG_00_FIFO | RH_RF69_SPI_WRITE_MASK); // Send the start address with the write mask on\n    _spi.transfer(len + RH_RF69_HEADER_LEN); // Include length of headers\n    // First the 4 headers\n    _spi.transfer(_txHeaderTo);\n    _spi.transfer(_txHeaderFrom);\n    _spi.transfer(_txHeaderId);\n    _spi.transfer(_txHeaderFlags);\n    // Now the payload\n    while (len--)\n\t_spi.transfer(*data++);\n    digitalWrite(_slaveSelectPin, HIGH);\n    ATOMIC_BLOCK_END;\n\n    setModeTx(); // Start the transmitter\n    return true;\n}\n\n#ifdef RH_RF69_IRQLESS\n// Since we have no interrupts, we need to implement our own \n// waitPacketSent for the driver by reading RF69 internal register\nbool RH_RF69::waitPacketSent()\n{\n    // If we are not currently in transmit mode, there is no packet to wait for\n    if (_mode != RHModeTx)\n    return false;\n\n    while (!(spiRead(RH_RF69_REG_28_IRQFLAGS2) & RH_RF69_IRQFLAGS2_PACKETSENT)){\n      YIELD;\n    }\n\n    // A transmitter message has been fully sent\n    setModeIdle(); // Clears FIFO\n    _txGood++;\n    return true;\n}\n#endif // defined RH_RF69_IRQLESS\n\nuint8_t RH_RF69::maxMessageLength()\n{\n    return RH_RF69_MAX_MESSAGE_LEN;\n}\n\nbool RH_RF69::printRegister(uint8_t reg)\n{  \n#ifdef RH_HAVE_SERIAL\n    Serial.print(reg, HEX);\n    Serial.print(\" \");\n    Serial.println(spiRead(reg), HEX);\n#endif\n    return true;\n}\n\nbool RH_RF69::printRegisters()\n{  \n    uint8_t i;\n    for (i = 0; i < 0x50; i++)\n\tprintRegister(i);\n    // Non-contiguous registers\n    printRegister(RH_RF69_REG_58_TESTLNA);\n    printRegister(RH_RF69_REG_6F_TESTDAGC);\n    printRegister(RH_RF69_REG_71_TESTAFC);\n    \n    return true;\n}\n"
  },
  {
    "path": "RH_RF69.h",
    "content": "// RH_RF69.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_RF69.h,v 1.33 2017/01/12 23:58:00 mikem Exp $\n//\n///\n\n\n#ifndef RH_RF69_h\n#define RH_RF69_h\n\n#include <RHGenericSPI.h>\n#include <RHSPIDriver.h>\n\n// If you don't want to use interupts (mainly to win one I/O pin) then\n// you just need to uncomment this line, if you're on Raspberry PI \n// it will be set automaticly below\n//#define RH_RF69_IRQLESS\n\n#if (RH_PLATFORM == RH_PLATFORM_RASPI)\n// No IRQ used on Raspberry PI\n#ifndef RH_RF69_IRQLESS\n#define RH_RF69_IRQLESS\n#endif\n#endif // RH_PLATFORM_RASPI PI\n\n// The crystal oscillator frequency of the RF69 module\n#define RH_RF69_FXOSC 32000000.0\n\n// The Frequency Synthesizer step = RH_RF69_FXOSC / 2^^19\n#define RH_RF69_FSTEP  (RH_RF69_FXOSC / 524288)\n\n// This is the maximum number of interrupts the driver can support\n// Most Arduinos can handle 2, Megas can handle more\n#define RH_RF69_NUM_INTERRUPTS 3\n\n// This is the bit in the SPI address that marks it as a write\n#define RH_RF69_SPI_WRITE_MASK 0x80\n\n// Max number of octets the RH_RF69 Rx and Tx FIFOs can hold\n#define RH_RF69_FIFO_SIZE 66\n\n// Maximum encryptable payload length the RF69 can support\n#define RH_RF69_MAX_ENCRYPTABLE_PAYLOAD_LEN 64\n\n// The length of the headers we add.\n// The headers are inside the RF69's payload and are therefore encrypted if encryption is enabled\n#define RH_RF69_HEADER_LEN 4\n\n// This is the maximum message length that can be supported by this driver. Limited by\n// the size of the FIFO, since we are unable to support on-the-fly filling and emptying \n// of the FIFO.\n// Can be pre-defined to a smaller size (to save SRAM) prior to including this header\n// Here we allow for 4 bytes of address and header and payload to be included in the 64 byte encryption limit.\n// the one byte payload length is not encrpyted\n#ifndef RH_RF69_MAX_MESSAGE_LEN\n#define RH_RF69_MAX_MESSAGE_LEN (RH_RF69_MAX_ENCRYPTABLE_PAYLOAD_LEN - RH_RF69_HEADER_LEN)\n#endif\n\n// Keep track of the mode the RF69 is in\n#define RH_RF69_MODE_IDLE         0\n#define RH_RF69_MODE_RX           1\n#define RH_RF69_MODE_TX           2\n\n// This is the default node address,\n#define RH_RF69_DEFAULT_NODE_ADDRESS 0\n\n// Register names\n#define RH_RF69_REG_00_FIFO                                 0x00\n#define RH_RF69_REG_01_OPMODE                               0x01\n#define RH_RF69_REG_02_DATAMODUL                            0x02\n#define RH_RF69_REG_03_BITRATEMSB                           0x03\n#define RH_RF69_REG_04_BITRATELSB                           0x04\n#define RH_RF69_REG_05_FDEVMSB                              0x05\n#define RH_RF69_REG_06_FDEVLSB                              0x06\n#define RH_RF69_REG_07_FRFMSB                               0x07\n#define RH_RF69_REG_08_FRFMID                               0x08\n#define RH_RF69_REG_09_FRFLSB                               0x09\n#define RH_RF69_REG_0A_OSC1                                 0x0a\n#define RH_RF69_REG_0B_AFCCTRL                              0x0b\n#define RH_RF69_REG_0C_RESERVED                             0x0c\n#define RH_RF69_REG_0D_LISTEN1                              0x0d\n#define RH_RF69_REG_0E_LISTEN2                              0x0e\n#define RH_RF69_REG_0F_LISTEN3                              0x0f\n#define RH_RF69_REG_10_VERSION                              0x10\n#define RH_RF69_REG_11_PALEVEL                              0x11\n#define RH_RF69_REG_12_PARAMP                               0x12\n#define RH_RF69_REG_13_OCP                                  0x13\n#define RH_RF69_REG_14_RESERVED                             0x14\n#define RH_RF69_REG_15_RESERVED                             0x15\n#define RH_RF69_REG_16_RESERVED                             0x16\n#define RH_RF69_REG_17_RESERVED                             0x17\n#define RH_RF69_REG_18_LNA                                  0x18\n#define RH_RF69_REG_19_RXBW                                 0x19\n#define RH_RF69_REG_1A_AFCBW                                0x1a\n#define RH_RF69_REG_1B_OOKPEAK                              0x1b\n#define RH_RF69_REG_1C_OOKAVG                               0x1c\n#define RH_RF69_REG_1D_OOKFIX                               0x1d\n#define RH_RF69_REG_1E_AFCFEI                               0x1e\n#define RH_RF69_REG_1F_AFCMSB                               0x1f\n#define RH_RF69_REG_20_AFCLSB                               0x20\n#define RH_RF69_REG_21_FEIMSB                               0x21\n#define RH_RF69_REG_22_FEILSB                               0x22\n#define RH_RF69_REG_23_RSSICONFIG                           0x23\n#define RH_RF69_REG_24_RSSIVALUE                            0x24\n#define RH_RF69_REG_25_DIOMAPPING1                          0x25\n#define RH_RF69_REG_26_DIOMAPPING2                          0x26\n#define RH_RF69_REG_27_IRQFLAGS1                            0x27\n#define RH_RF69_REG_28_IRQFLAGS2                            0x28\n#define RH_RF69_REG_29_RSSITHRESH                           0x29\n#define RH_RF69_REG_2A_RXTIMEOUT1                           0x2a\n#define RH_RF69_REG_2B_RXTIMEOUT2                           0x2b\n#define RH_RF69_REG_2C_PREAMBLEMSB                          0x2c\n#define RH_RF69_REG_2D_PREAMBLELSB                          0x2d\n#define RH_RF69_REG_2E_SYNCCONFIG                           0x2e\n#define RH_RF69_REG_2F_SYNCVALUE1                           0x2f\n// another 7 sync word bytes follow, 30 through 36 inclusive\n#define RH_RF69_REG_37_PACKETCONFIG1                        0x37\n#define RH_RF69_REG_38_PAYLOADLENGTH                        0x38\n#define RH_RF69_REG_39_NODEADRS                             0x39\n#define RH_RF69_REG_3A_BROADCASTADRS                        0x3a\n#define RH_RF69_REG_3B_AUTOMODES                            0x3b\n#define RH_RF69_REG_3C_FIFOTHRESH                           0x3c\n#define RH_RF69_REG_3D_PACKETCONFIG2                        0x3d\n#define RH_RF69_REG_3E_AESKEY1                              0x3e\n// Another 15 AES key bytes follow\n#define RH_RF69_REG_4E_TEMP1                                0x4e\n#define RH_RF69_REG_4F_TEMP2                                0x4f\n#define RH_RF69_REG_58_TESTLNA                              0x58\n#define RH_RF69_REG_5A_TESTPA1                              0x5a\n#define RH_RF69_REG_5C_TESTPA2                              0x5c\n#define RH_RF69_REG_6F_TESTDAGC                             0x6f\n#define RH_RF69_REG_71_TESTAFC                              0x71\n\n// These register masks etc are named wherever possible\n// corresponding to the bit and field names in the RFM69 Manual\n\n// RH_RF69_REG_01_OPMODE\n#define RH_RF69_OPMODE_SEQUENCEROFF                         0x80\n#define RH_RF69_OPMODE_LISTENON                             0x40\n#define RH_RF69_OPMODE_LISTENABORT                          0x20\n#define RH_RF69_OPMODE_MODE                                 0x1c\n#define RH_RF69_OPMODE_MODE_SLEEP                           0x00\n#define RH_RF69_OPMODE_MODE_STDBY                           0x04\n#define RH_RF69_OPMODE_MODE_FS                              0x08\n#define RH_RF69_OPMODE_MODE_TX                              0x0c\n#define RH_RF69_OPMODE_MODE_RX                              0x10\n\n// RH_RF69_REG_02_DATAMODUL\n#define RH_RF69_DATAMODUL_DATAMODE                          0x60\n#define RH_RF69_DATAMODUL_DATAMODE_PACKET                   0x00\n#define RH_RF69_DATAMODUL_DATAMODE_CONT_WITH_SYNC           0x40\n#define RH_RF69_DATAMODUL_DATAMODE_CONT_WITHOUT_SYNC        0x60\n#define RH_RF69_DATAMODUL_MODULATIONTYPE                    0x18\n#define RH_RF69_DATAMODUL_MODULATIONTYPE_FSK                0x00\n#define RH_RF69_DATAMODUL_MODULATIONTYPE_OOK                0x08\n#define RH_RF69_DATAMODUL_MODULATIONSHAPING                 0x03\n#define RH_RF69_DATAMODUL_MODULATIONSHAPING_FSK_NONE        0x00\n#define RH_RF69_DATAMODUL_MODULATIONSHAPING_FSK_BT1_0       0x01\n#define RH_RF69_DATAMODUL_MODULATIONSHAPING_FSK_BT0_5       0x02\n#define RH_RF69_DATAMODUL_MODULATIONSHAPING_FSK_BT0_3       0x03\n#define RH_RF69_DATAMODUL_MODULATIONSHAPING_OOK_NONE        0x00\n#define RH_RF69_DATAMODUL_MODULATIONSHAPING_OOK_BR          0x01\n#define RH_RF69_DATAMODUL_MODULATIONSHAPING_OOK_2BR         0x02\n\n// RH_RF69_REG_11_PALEVEL\n#define RH_RF69_PALEVEL_PA0ON                               0x80\n#define RH_RF69_PALEVEL_PA1ON                               0x40\n#define RH_RF69_PALEVEL_PA2ON                               0x20\n#define RH_RF69_PALEVEL_OUTPUTPOWER                         0x1f\n\n// RH_RF69_REG_23_RSSICONFIG\n#define RH_RF69_RSSICONFIG_RSSIDONE                         0x02\n#define RH_RF69_RSSICONFIG_RSSISTART                        0x01\n\n// RH_RF69_REG_25_DIOMAPPING1\n#define RH_RF69_DIOMAPPING1_DIO0MAPPING                     0xc0\n#define RH_RF69_DIOMAPPING1_DIO0MAPPING_00                  0x00\n#define RH_RF69_DIOMAPPING1_DIO0MAPPING_01                  0x40\n#define RH_RF69_DIOMAPPING1_DIO0MAPPING_10                  0x80\n#define RH_RF69_DIOMAPPING1_DIO0MAPPING_11                  0xc0\n\n#define RH_RF69_DIOMAPPING1_DIO1MAPPING                     0x30\n#define RH_RF69_DIOMAPPING1_DIO1MAPPING_00                  0x00\n#define RH_RF69_DIOMAPPING1_DIO1MAPPING_01                  0x10\n#define RH_RF69_DIOMAPPING1_DIO1MAPPING_10                  0x20\n#define RH_RF69_DIOMAPPING1_DIO1MAPPING_11                  0x30\n\n#define RH_RF69_DIOMAPPING1_DIO2MAPPING                     0x0c\n#define RH_RF69_DIOMAPPING1_DIO2MAPPING_00                  0x00\n#define RH_RF69_DIOMAPPING1_DIO2MAPPING_01                  0x04\n#define RH_RF69_DIOMAPPING1_DIO2MAPPING_10                  0x08\n#define RH_RF69_DIOMAPPING1_DIO2MAPPING_11                  0x0c\n\n#define RH_RF69_DIOMAPPING1_DIO3MAPPING                     0x03\n#define RH_RF69_DIOMAPPING1_DIO3MAPPING_00                  0x00\n#define RH_RF69_DIOMAPPING1_DIO3MAPPING_01                  0x01\n#define RH_RF69_DIOMAPPING1_DIO3MAPPING_10                  0x02\n#define RH_RF69_DIOMAPPING1_DIO3MAPPING_11                  0x03\n\n// RH_RF69_REG_26_DIOMAPPING2\n#define RH_RF69_DIOMAPPING2_DIO4MAPPING                     0xc0\n#define RH_RF69_DIOMAPPING2_DIO4MAPPING_00                  0x00\n#define RH_RF69_DIOMAPPING2_DIO4MAPPING_01                  0x40\n#define RH_RF69_DIOMAPPING2_DIO4MAPPING_10                  0x80\n#define RH_RF69_DIOMAPPING2_DIO4MAPPING_11                  0xc0\n\n#define RH_RF69_DIOMAPPING2_DIO5MAPPING                     0x30\n#define RH_RF69_DIOMAPPING2_DIO5MAPPING_00                  0x00\n#define RH_RF69_DIOMAPPING2_DIO5MAPPING_01                  0x10\n#define RH_RF69_DIOMAPPING2_DIO5MAPPING_10                  0x20\n#define RH_RF69_DIOMAPPING2_DIO5MAPPING_11                  0x30\n\n#define RH_RF69_DIOMAPPING2_CLKOUT                          0x07\n#define RH_RF69_DIOMAPPING2_CLKOUT_FXOSC_                   0x00\n#define RH_RF69_DIOMAPPING2_CLKOUT_FXOSC_2                  0x01\n#define RH_RF69_DIOMAPPING2_CLKOUT_FXOSC_4                  0x02\n#define RH_RF69_DIOMAPPING2_CLKOUT_FXOSC_8                  0x03\n#define RH_RF69_DIOMAPPING2_CLKOUT_FXOSC_16                 0x04\n#define RH_RF69_DIOMAPPING2_CLKOUT_FXOSC_32                 0x05\n#define RH_RF69_DIOMAPPING2_CLKOUT_FXOSC_RC                 0x06\n#define RH_RF69_DIOMAPPING2_CLKOUT_FXOSC_OFF                0x07\n\n// RH_RF69_REG_27_IRQFLAGS1\n#define RH_RF69_IRQFLAGS1_MODEREADY                         0x80\n#define RH_RF69_IRQFLAGS1_RXREADY                           0x40\n#define RH_RF69_IRQFLAGS1_TXREADY                           0x20\n#define RH_RF69_IRQFLAGS1_PLLLOCK                           0x10\n#define RH_RF69_IRQFLAGS1_RSSI                              0x08\n#define RH_RF69_IRQFLAGS1_TIMEOUT                           0x04\n#define RH_RF69_IRQFLAGS1_AUTOMODE                          0x02\n#define RH_RF69_IRQFLAGS1_SYNADDRESSMATCH                   0x01\n\n// RH_RF69_REG_28_IRQFLAGS2\n#define RH_RF69_IRQFLAGS2_FIFOFULL                          0x80\n#define RH_RF69_IRQFLAGS2_FIFONOTEMPTY                      0x40\n#define RH_RF69_IRQFLAGS2_FIFOLEVEL                         0x20\n#define RH_RF69_IRQFLAGS2_FIFOOVERRUN                       0x10\n#define RH_RF69_IRQFLAGS2_PACKETSENT                        0x08\n#define RH_RF69_IRQFLAGS2_PAYLOADREADY                      0x04\n#define RH_RF69_IRQFLAGS2_CRCOK                             0x02\n\n// RH_RF69_REG_2E_SYNCCONFIG\n#define RH_RF69_SYNCCONFIG_SYNCON                           0x80\n#define RH_RF69_SYNCCONFIG_FIFOFILLCONDITION_MANUAL         0x40\n#define RH_RF69_SYNCCONFIG_SYNCSIZE                         0x38\n#define RH_RF69_SYNCCONFIG_SYNCSIZE_1                       0x00\n#define RH_RF69_SYNCCONFIG_SYNCSIZE_2                       0x08\n#define RH_RF69_SYNCCONFIG_SYNCSIZE_3                       0x10\n#define RH_RF69_SYNCCONFIG_SYNCSIZE_4                       0x18\n#define RH_RF69_SYNCCONFIG_SYNCSIZE_5                       0x20\n#define RH_RF69_SYNCCONFIG_SYNCSIZE_6                       0x28\n#define RH_RF69_SYNCCONFIG_SYNCSIZE_7                       0x30\n#define RH_RF69_SYNCCONFIG_SYNCSIZE_8                       0x38\n#define RH_RF69_SYNCCONFIG_SYNCSIZE_SYNCTOL                 0x07\n\n// RH_RF69_REG_37_PACKETCONFIG1\n#define RH_RF69_PACKETCONFIG1_PACKETFORMAT_VARIABLE         0x80\n#define RH_RF69_PACKETCONFIG1_DCFREE                        0x60\n#define RH_RF69_PACKETCONFIG1_DCFREE_NONE                   0x00\n#define RH_RF69_PACKETCONFIG1_DCFREE_MANCHESTER             0x20\n#define RH_RF69_PACKETCONFIG1_DCFREE_WHITENING              0x40\n#define RH_RF69_PACKETCONFIG1_DCFREE_RESERVED               0x60\n#define RH_RF69_PACKETCONFIG1_CRC_ON                        0x10\n#define RH_RF69_PACKETCONFIG1_CRCAUTOCLEAROFF               0x08\n#define RH_RF69_PACKETCONFIG1_ADDRESSFILTERING              0x06\n#define RH_RF69_PACKETCONFIG1_ADDRESSFILTERING_NONE         0x00\n#define RH_RF69_PACKETCONFIG1_ADDRESSFILTERING_NODE         0x02\n#define RH_RF69_PACKETCONFIG1_ADDRESSFILTERING_NODE_BC      0x04\n#define RH_RF69_PACKETCONFIG1_ADDRESSFILTERING_RESERVED     0x06\n\n// RH_RF69_REG_3C_FIFOTHRESH\n#define RH_RF69_FIFOTHRESH_TXSTARTCONDITION_NOTEMPTY        0x80\n#define RH_RF69_FIFOTHRESH_FIFOTHRESHOLD                    0x7f\n\n// RH_RF69_REG_3D_PACKETCONFIG2\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_1BIT           0x00  // Default\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_2BITS          0x10\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_4BITS          0x20\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_8BITS          0x30\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_16BITS         0x40\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_32BITS         0x50\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_64BITS         0x60\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_128BITS        0x70\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_256BITS        0x80\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_512BITS        0x90\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_1024BITS       0xA0\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_2048BITS       0xB0\n#define RH_RF69_PACKETCONFIG2_RXRESTARTDELAY_NONE           0xC0\n#define RH_RF69_PACKETCONFIG2_INTERPACKETRXDELAY            0xf0\n#define RH_RF69_PACKETCONFIG2_RESTARTRX                     0x04\n#define RH_RF69_PACKETCONFIG2_AUTORXRESTARTON               0x02\n#define RH_RF69_PACKETCONFIG2_AESON                         0x01\n\n// RH_RF69_REG_4E_TEMP1\n#define RH_RF69_TEMP1_TEMPMEASSTART                         0x08\n#define RH_RF69_TEMP1_TEMPMEASRUNNING                       0x04\n\n// RH_RF69_REG_5A_TESTPA1\n#define RH_RF69_TESTPA1_NORMAL                              0x55\n#define RH_RF69_TESTPA1_BOOST                               0x5d\n\n// RH_RF69_REG_5C_TESTPA2\n#define RH_RF69_TESTPA2_NORMAL                              0x70\n#define RH_RF69_TESTPA2_BOOST                               0x7c\n\n// RH_RF69_REG_6F_TESTDAGC\n#define RH_RF69_TESTDAGC_CONTINUOUSDAGC_NORMAL              0x00\n#define RH_RF69_TESTDAGC_CONTINUOUSDAGC_IMPROVED_LOWBETAON  0x20\n#define RH_RF69_TESTDAGC_CONTINUOUSDAGC_IMPROVED_LOWBETAOFF 0x30\n\n// Define this to include Serial printing in diagnostic routines\n#define RH_RF69_HAVE_SERIAL\n\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_RF69 RH_RF69.h <RH_RF69.h>\n/// \\brief Driver to send and receive unaddressed, unreliable datagrams via an RF69 and compatible radio transceiver.\n///\n/// Works with \n/// - the excellent Moteino and Moteino-USB \n/// boards from LowPowerLab http://lowpowerlab.com/moteino/\n/// - compatible chips and modules such as RFM69W, RFM69HW, RFM69CW, RFM69HCW (Semtech SX1231, SX1231H),\n/// - RFM69 modules from http://www.hoperfusa.com such as http://www.hoperfusa.com/details.jsp?pid=145\n/// - Anarduino MiniWireless -CW and -HW boards http://www.anarduino.com/miniwireless/ including\n///  the marvellous high powered MinWireless-HW (with 20dBm output for excellent range)\n/// - the excellent Rocket Scream Mini Ultra Pro with the RFM69HCW \n///   http://www.rocketscream.com/blog/product/mini-ultra-pro-with-radio/\n/// - The excellent Talk2 Whisper Node boards \n///   (https://talk2.wisen.com.au/ and https://bitbucket.org/talk2/whisper-node-avr), \n///   an Arduino compatible board, which include an on-board RF69 radio, external antenna, \n///   run on 2xAAA batteries and support low power operations. RF69 examples work without modification.\n///   Use Arduino Board Manager to install the Talk2 code support as described in \n///   https://bitbucket.org/talk2/whisper-node-avr\n/// - The excellent Adafruit Feather. These are excellent boards that are available with a variety of radios. \n///   We tested with the \n///   Feather 32u4 with RFM69HCW radio, with Arduino IDE 1.6.8 and the Adafruit AVR Boards board manager version 1.6.10.\n///   https://www.adafruit.com/products/3076\n///\n/// \\par Overview\n///\n/// This class provides basic functions for sending and receiving unaddressed, \n/// unreliable datagrams of arbitrary length to 64 octets per packet.\n///\n/// Manager classes may use this class to implement reliable, addressed datagrams and streams, \n/// mesh routers, repeaters, translators etc.\n///\n/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and \n/// modulation scheme.\n///\n/// This Driver provides an object-oriented interface for sending and receiving data messages with Hope-RF\n/// RF69B and compatible radio modules, such as the RFM69 module.\n///\n/// The Hope-RF (http://www.hoperf.com) RF69 is a low-cost ISM transceiver\n/// chip. It supports FSK, GFSK, OOK over a wide range of frequencies and\n/// programmable data rates. It also suports AES encryption of up to 64 octets\n/// of payload It is available prepackaged on modules such as the RFM69W. And\n/// such modules can be prepacked on processor boards such as the Moteino from\n/// LowPowerLabs (which is what we used to develop the RH_RF69 driver)\n///\n/// This Driver provides functions for sending and receiving messages of up\n/// to 60 octets on any frequency supported by the RF69, in a range of\n/// predefined data rates and frequency deviations.  Frequency can be set with\n/// 61Hz precision to any frequency from 240.0MHz to 960.0MHz. Caution: most modules only support a more limited\n/// range of frequencies due to antenna tuning.\n///\n/// Up to 2 RF69B modules can be connected to an Arduino (3 on a Mega),\n/// permitting the construction of translators and frequency changers, etc.\n///\n/// The following modulation types are suppported with a range of modem configurations for \n/// common data rates and frequency deviations:\n/// - GFSK Gaussian Frequency Shift Keying\n/// - FSK Frequency Shift Keying\n///\n/// Support for other RF69 features such as on-chip temperature measurement, \n/// transmitter power control etc is also provided.\n///\n/// Tested on USB-Moteino with arduino-1.0.5\n/// on OpenSuSE 13.1\n///\n/// \\par Packet Format\n///\n/// All messages sent and received by this RH_RF69 Driver conform to this packet format:\n///\n/// - 4 octets PREAMBLE\n/// - 2 octets SYNC 0x2d, 0xd4 (configurable, so you can use this as a network filter)\n/// - 1 octet RH_RF69 payload length\n/// - 4 octets HEADER: (TO, FROM, ID, FLAGS)\n/// - 0 to 60 octets DATA \n/// - 2 octets CRC computed with CRC16(IBM), computed on HEADER and DATA\n///\n/// For technical reasons, the message format is not protocol compatible with the\n/// 'HopeRF Radio Transceiver Message Library for Arduino'\n/// http://www.airspayce.com/mikem/arduino/HopeRF from the same author. Nor is\n/// it compatible with messages sent by 'Virtual Wire'\n/// http://www.airspayce.com/mikem/arduino/VirtualWire.pdf also from the same\n/// author.  Nor is it compatible with messages sent by 'RF22'\n/// http://www.airspayce.com/mikem/arduino/RF22 also from the same author.\n///\n/// \\par Connecting RFM-69 to Arduino\n///\n/// We tested with Moteino, which is an Arduino Uno compatible with the RFM69W\n/// module on-board. Therefore it needs no connections other than the USB\n/// programming connection and an antenna to make it work.\n///\n/// If you have a bare RFM69W that you want to connect to an Arduino, you\n/// might use these connections: CAUTION: you must use a 3.3V type\n/// Arduino, otherwise you will also need voltage level shifters between the\n/// Arduino and the RFM69.  CAUTION, you must also ensure you connect an\n/// antenna\n/// \n/// \\code\n///                 Arduino      RFM69W\n///                 GND----------GND   (ground in)\n///                 3V3----------3.3V  (3.3V in)\n/// interrupt 0 pin D2-----------DIO0  (interrupt request out)\n///          SS pin D10----------NSS   (chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------MOSI  (SPI Data in)\n///        MISO pin D12----------MISO  (SPI Data out)\n/// \\endcode\n///\n/// For Arduino Due, use these connections:\n/// \\code\n///                 Arduino      RFM69W\n///                 GND----------GND   (ground in)\n///                 3V3----------3.3V  (3.3V in)\n/// interrupt 0 pin D2-----------DIO0  (interrupt request out)\n///          SS pin D10----------NSS   (chip select in)\n///       SCK SPI pin 3----------SCK   (SPI clock in)\n///      MOSI SPI pin 4----------MOSI  (SPI Data in)\n///      MISO SPI pin 1----------MISO  (SPI Data out)\n/// \\endcode\n///\n/// With these connections, you can then use the default constructor RH_RF69().\n/// You can override the default settings for the SS pin and the interrupt in\n/// the RH_RF69 constructor if you wish to connect the slave select SS to other\n/// than the normal one for your Arduino (D10 for Diecimila, Uno etc and D53\n/// for Mega) or the interrupt request to other than pin D2 (Caution,\n/// different processors have different constraints as to the pins available\n/// for interrupts).\n///\n/// If you have a Teensy 3.1 and a compatible RFM69 breakout board, you will need to \n/// construct the RH_RF69 instance like this:\n/// \\code\n/// RH_RF69 driver(15, 16);\n/// \\endcode\n///\n/// If you have a MoteinoMEGA https://lowpowerlab.com/shop/moteinomega\n/// with RFM69 on board, you dont need to make any wiring connections \n/// (the RFM69 module is soldered onto the MotienoMEGA), but you must initialise the RH_RF69\n/// constructor like this:\n/// \\code\n/// RH_RF69 driver(4, 2);\n/// \\endcode\n/// Make sure you have the MoteinoMEGA core installed in your Arduino hardware folder as described in the\n/// documentation for the MoteinoMEGA.\n///\n/// If you have an Arduino M0 Pro from arduino.org, \n/// you should note that you cannot use Pin 2 for the interrupt line \n/// (Pin 2 is for the NMI only). The same comments apply to Pin 4 on Arduino Zero from arduino.cc.\n/// Instead you can use any other pin (we use Pin 3) and initialise RH_RF69 like this:\n/// \\code\n/// // Slave Select is pin 10, interrupt is Pin 3\n/// RH_RF69 driver(10, 3);\n/// \\endcode\n///\n/// If you have a Rocket Scream Mini Ultra Pro with the RFM69HCW\n/// - Ensure you have Arduino SAMD board support 1.6.5 or later in Arduino IDE 1.6.8 or later.\n/// - The radio SS is hardwired to pin D5 and the DIO0 interrupt to pin D2, \n/// so you need to initialise the radio like this:\n/// \\code\n/// RH_RF69 driver(5, 2);\n/// \\endcode\n/// - The name of the serial port on that board is 'SerialUSB', not 'Serial', so this may be helpful at the top of our\n///   sample sketches:\n/// \\code\n/// #define Serial SerialUSB\n/// \\endcode\n/// - You also need this in setup before radio initialisation  \n/// \\code\n/// // Ensure serial flash is not interfering with radio communication on SPI bus\n///  pinMode(4, OUTPUT);\n///  digitalWrite(4, HIGH);\n/// \\endcode\n/// - and if you have a 915MHz part, you need this after driver/manager intitalisation:\n/// \\code\n/// rf69.setFrequency(915.0);\n/// rf69.setTxPower(20);\n/// \\endcode\n/// which adds up to modifying sample sketches something like:\n/// \\code\n/// #include <SPI.h>\n/// #include <RH_RF69.h>\n/// RH_RF69 rf69(5, 2); // Rocket Scream Mini Ultra Pro with the RFM69HCW\n/// #define Serial SerialUSB\n/// \n/// void setup() \n/// {\n///   // Ensure serial flash is not interfering with radio communication on SPI bus\n///   pinMode(4, OUTPUT);\n///   digitalWrite(4, HIGH);\n/// \n///   Serial.begin(9600);\n///   while (!Serial) ; // Wait for serial port to be available\n///   if (!rf69.init())\n///     Serial.println(\"init failed\");\n///   rf69.setFrequency(915.0);\n///   rf69.setTxPower(20);\n/// }\n/// ...\n/// \\endcode\n///\n/// If you have a talk2 Whisper Node board with on-board RF69 radio, \n/// the example rf69_* sketches work without modifications. Initialise the radio like\n/// with the default constructor:\n/// \\code\n///  RH_RF69 driver;\n/// \\endcode\n///\n/// If you have a Feather 32u4 with RFM69HCW you need to initialise the driver like:\n/// \\code\n///  RH_RF69 driver(8, 7);\n/// \\endcode\n/// and since the radio is the high power HCW model, you must set the Tx power in the\n/// range 14 to 20 like this:\n/// \\code\n///  driver.setTxPower(14);\n/// \\endcode\n///\n/// It is possible to have 2 or more radios connected to one Arduino, provided\n/// each radio has its own SS and interrupt line (SCK, SDI and SDO are common\n/// to all radios)\n///\n/// Caution: on some Arduinos such as the Mega 2560, if you set the slave\n/// select pin to be other than the usual SS pin (D53 on Mega 2560), you may\n/// need to set the usual SS pin to be an output to force the Arduino into SPI\n/// master mode.\n///\n/// Caution: Power supply requirements of the RF69 module may be relevant in some circumstances: \n/// RF69 modules are capable of pulling 45mA+ at full power, where Arduino's 3.3V line can\n/// give 50mA. You may need to make provision for alternate power supply for\n/// the RF69, especially if you wish to use full transmit power, and/or you have\n/// other shields demanding power. Inadequate power for the RF69 is likely to cause symptoms such as:\n/// -reset's/bootups terminate with \"init failed\" messages\n/// -random termination of communication after 5-30 packets sent/received\n/// -\"fake ok\" state, where initialization passes fluently, but communication doesn't happen\n/// -shields hang Arduino boards, especially during the flashing\n/// \\par Interrupts\n///\n/// The RH_RF69 driver uses interrupts to react to events in the RF69 module,\n/// such as the reception of a new packet, or the completion of transmission\n/// of a packet.  The RH_RF69 driver interrupt service routine reads status from\n/// and writes data to the the RF69 module via the SPI interface. It is very\n/// important therefore, that if you are using the RH_RF69 driver with another\n/// SPI based deviced, that you disable interrupts while you transfer data to\n/// and from that other device.  Use cli() to disable interrupts and sei() to\n/// reenable them.\n///\n/// \\par Memory\n///\n/// The RH_RF69 driver requires non-trivial amounts of memory. The sample\n/// programs above all compile to about 8kbytes each, which will fit in the\n/// flash proram memory of most Arduinos. However, the RAM requirements are\n/// more critical. Therefore, you should be vary sparing with RAM use in\n/// programs that use the RH_RF69 driver.\n///\n/// It is often hard to accurately identify when you are hitting RAM limits on Arduino. \n/// The symptoms can include:\n/// - Mysterious crashes and restarts\n/// - Changes in behaviour when seemingly unrelated changes are made (such as adding print() statements)\n/// - Hanging\n/// - Output from Serial.print() not appearing\n/// \n/// \\par Automatic Frequency Control (AFC)\n///\n/// The RF69 module is configured by the RH_RF69 driver to always use AFC.\n///\n/// \\par Transmitter Power\n///\n/// You can control the transmitter power on the RF69 transceiver\n/// with the RH_RF69::setTxPower() function. The argument can be any of\n/// -18 to +13 (for RF69W) or -14 to 20 (for RF69HW) \n/// The default is 13. Eg:\n/// \\code\n/// driver.setTxPower(-5);\n/// \\endcode\n///\n/// We have made some actual power measurements against\n/// programmed power for Moteino (with RF69W)\n/// - Moteino (with RF69W), USB power\n/// - 10cm RG58C/U soldered direct to RFM69 module ANT and GND\n/// - bnc connecteor\n/// - 12dB attenuator\n/// - BNC-SMA adapter\n/// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)\n/// - Tektronix TDS220 scope to measure the Vout from power head\n/// \\code\n/// Program power           Measured Power\n///    dBm                         dBm\n///    -18                         -17\n///    -16                         -16\n///    -14                         -14\n///    -12                         -12\n///    -10                         -9\n///    -8                          -7\n///    -6                          -4\n///    -4                          -3\n///    -2                          -2\n///    0                           0.2\n///    2                           3\n///    4                           5\n///    6                           7\n///    8                           10\n///    10                          13\n///    12                          14\n///    13                          15\n///    14                         -51\n///    20                         -51\n/// \\endcode\n/// We have also made some actual power measurements against\n/// programmed power for Anarduino MiniWireless with RFM69-HW\n/// Anarduino MiniWireless (with RFM69-HW), USB power\n/// - 10cm RG58C/U soldered direct to RFM69 module ANT and GND\n/// - bnc connecteor\n/// - 2x12dB attenuators\n/// - BNC-SMA adapter\n/// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)\n/// - Tektronix TDS220 scope to measure the Vout from power head\n/// \\code\n/// Program power           Measured Power\n///    dBm                         dBm\n///    -18                         no measurable output\n///    0                           no measurable output\n///    13                          no measurable output\n///    14                          11\n///    15                          12\n///    16                          12.4\n///    17                          14\n///    18                          15\n///    19                          15.8\n///    20                          17\n/// \\endcode\n/// (Caution: we dont claim laboratory accuracy for these measurements)\n/// You would not expect to get anywhere near these powers to air with a simple 1/4 wavelength wire antenna.\n/// Caution: although the RFM69 appears to have a PC antenna on board, you will get much better power and range even \n/// with just a 1/4 wave wire antenna.\n///\n/// \\par Performance\n///\n/// Some simple speed performance tests have been conducted.\n/// In general packet transmission rate will be limited by the modulation scheme.\n/// Also, if your code does any slow operations like Serial printing it will also limit performance. \n/// We disabled any printing in the tests below.\n/// We tested with RH_RF69::GFSK_Rb250Fd250, which is probably the fastest scheme available.\n/// We tested with a 13 octet message length, over a very short distance of 10cm.\n///\n/// Transmission (no reply) tests with modulation RH_RF69::GFSK_Rb250Fd250 and a \n/// 13 octet message show about 152 messages per second transmitted and received.\n///\n/// Transmit-and-wait-for-a-reply tests with modulation RH_RF69::GFSK_Rb250Fd250 and a \n/// 13 octet message (send and receive) show about 68 round trips per second.\n///\nclass RH_RF69 : public RHSPIDriver\n{\npublic:\n\n    /// \\brief Defines register values for a set of modem configuration registers\n    ///\n    /// Defines register values for a set of modem configuration registers\n    /// that can be passed to setModemRegisters() if none of the choices in\n    /// ModemConfigChoice suit your need setModemRegisters() writes the\n    /// register values from this structure to the appropriate RF69 registers\n    /// to set the desired modulation type, data rate and deviation/bandwidth.\n    typedef struct\n    {\n\tuint8_t    reg_02;   ///< Value for register RH_RF69_REG_02_DATAMODUL\n\tuint8_t    reg_03;   ///< Value for register RH_RF69_REG_03_BITRATEMSB\n\tuint8_t    reg_04;   ///< Value for register RH_RF69_REG_04_BITRATELSB\n\tuint8_t    reg_05;   ///< Value for register RH_RF69_REG_05_FDEVMSB\n\tuint8_t    reg_06;   ///< Value for register RH_RF69_REG_06_FDEVLSB\n\tuint8_t    reg_19;   ///< Value for register RH_RF69_REG_19_RXBW\n\tuint8_t    reg_1a;   ///< Value for register RH_RF69_REG_1A_AFCBW\n\tuint8_t    reg_37;   ///< Value for register RH_RF69_REG_37_PACKETCONFIG1\n    } ModemConfig;\n  \n    /// Choices for setModemConfig() for a selected subset of common\n    /// modulation types, and data rates. If you need another configuration,\n    /// use the register calculator.  and call setModemRegisters() with your\n    /// desired settings.  \n    /// These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic\n    /// definitions and not their integer equivalents: its possible that new values will be\n    /// introduced in later versions (though we will try to avoid it).\n    /// CAUTION: some of these configurations do not work corectly and are marked as such.\n    typedef enum\n    {\n\tFSK_Rb2Fd5 = 0,\t   ///< FSK, Whitening, Rb = 2kbs,    Fd = 5kHz\n\tFSK_Rb2_4Fd4_8,    ///< FSK, Whitening, Rb = 2.4kbs,  Fd = 4.8kHz \n\tFSK_Rb4_8Fd9_6,    ///< FSK, Whitening, Rb = 4.8kbs,  Fd = 9.6kHz \n\tFSK_Rb9_6Fd19_2,   ///< FSK, Whitening, Rb = 9.6kbs,  Fd = 19.2kHz\n\tFSK_Rb19_2Fd38_4,  ///< FSK, Whitening, Rb = 19.2kbs, Fd = 38.4kHz\n\tFSK_Rb38_4Fd76_8,  ///< FSK, Whitening, Rb = 38.4kbs, Fd = 76.8kHz\n\tFSK_Rb57_6Fd120,   ///< FSK, Whitening, Rb = 57.6kbs, Fd = 120kHz\n\tFSK_Rb125Fd125,    ///< FSK, Whitening, Rb = 125kbs,  Fd = 125kHz\n\tFSK_Rb250Fd250,    ///< FSK, Whitening, Rb = 250kbs,  Fd = 250kHz\n\tFSK_Rb55555Fd50,   ///< FSK, Whitening, Rb = 55555kbs,Fd = 50kHz for RFM69 lib compatibility\n\tFSK_MOTEINO,       ///< FSK, No Whitening, Rb = 55555kbs,Fd = 50kHz, No DC-Free for RFM69 lib compatibility\n\n\tGFSK_Rb2Fd5,\t    ///< GFSK, Whitening, Rb = 2kbs,    Fd = 5kHz\n\tGFSK_Rb2_4Fd4_8,    ///< GFSK, Whitening, Rb = 2.4kbs,  Fd = 4.8kHz\n\tGFSK_Rb4_8Fd9_6,    ///< GFSK, Whitening, Rb = 4.8kbs,  Fd = 9.6kHz\n\tGFSK_Rb9_6Fd19_2,   ///< GFSK, Whitening, Rb = 9.6kbs,  Fd = 19.2kHz\n\tGFSK_Rb19_2Fd38_4,  ///< GFSK, Whitening, Rb = 19.2kbs, Fd = 38.4kHz\n\tGFSK_Rb38_4Fd76_8,  ///< GFSK, Whitening, Rb = 38.4kbs, Fd = 76.8kHz\n\tGFSK_Rb57_6Fd120,   ///< GFSK, Whitening, Rb = 57.6kbs, Fd = 120kHz\n\tGFSK_Rb125Fd125,    ///< GFSK, Whitening, Rb = 125kbs,  Fd = 125kHz\n\tGFSK_Rb250Fd250,    ///< GFSK, Whitening, Rb = 250kbs,  Fd = 250kHz\n\tGFSK_Rb55555Fd50,   ///< GFSK, Whitening, Rb = 55555kbs,Fd = 50kHz\n\n\tOOK_Rb1Bw1,         ///< OOK, Whitening, Rb = 1kbs,    Rx Bandwidth = 1kHz. \n\tOOK_Rb1_2Bw75,      ///< OOK, Whitening, Rb = 1.2kbs,  Rx Bandwidth = 75kHz. \n\tOOK_Rb2_4Bw4_8,     ///< OOK, Whitening, Rb = 2.4kbs,  Rx Bandwidth = 4.8kHz. \n\tOOK_Rb4_8Bw9_6,     ///< OOK, Whitening, Rb = 4.8kbs,  Rx Bandwidth = 9.6kHz. \n\tOOK_Rb9_6Bw19_2,    ///< OOK, Whitening, Rb = 9.6kbs,  Rx Bandwidth = 19.2kHz. \n\tOOK_Rb19_2Bw38_4,   ///< OOK, Whitening, Rb = 19.2kbs, Rx Bandwidth = 38.4kHz. \n\tOOK_Rb32Bw64,       ///< OOK, Whitening, Rb = 32kbs,   Rx Bandwidth = 64kHz. \n\n//\tTest,\n    } ModemConfigChoice;\n\n    /// Constructor. You can have multiple instances, but each instance must have its own\n    /// interrupt and slave select pin. After constructing, you must call init() to initialise the interface\n    /// and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient\n    /// distinct interrupt lines, one for each instance.\n    /// \\param[in] slaveSelectPin the Arduino pin number of the output to use to select the RF69 before\n    /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)\n    /// \\param[in] interruptPin The interrupt Pin number that is connected to the RF69 DIO0 interrupt line. \n    /// Defaults to pin 2.\n    /// Caution: You must specify an interrupt capable pin.\n    /// On many Arduino boards, there are limitations as to which pins may be used as interrupts.\n    /// On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin.\n    /// On Arduino Zero from arduino.cc, any digital pin other than 4.\n    /// On Arduino M0 Pro from arduino.org, any digital pin other than 2.\n    /// On other Arduinos pins 2 or 3. \n    /// See http://arduino.cc/en/Reference/attachInterrupt for more details.\n    /// On Chipkit Uno32, pins 38, 2, 7, 8, 35.\n    /// On other boards, any digital pin may be used.\n    /// \\param[in] spi Pointer to the SPI interface object to use. \n    ///                Defaults to the standard Arduino hardware SPI interface\n    RH_RF69(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, RHGenericSPI& spi = hardware_spi);\n  \n    /// Initialises this instance and the radio module connected to it.\n    /// The following steps are taken:\n    /// - Initialise the slave select pin and the SPI interface library\n    /// - Checks the connected RF69 module can be communicated\n    /// - Attaches an interrupt handler\n    /// - Configures the RF69 module\n    /// - Sets the frequency to 434.0 MHz\n    /// - Sets the modem data rate to FSK_Rb2Fd5\n    /// \\return  true if everything was successful\n    bool        init();\n\n    /// Reads the on-chip temperature sensor.\n    /// The RF69 must be in Idle mode (= RF69 Standby) to measure temperature.\n    /// The measurement is uncalibrated and without calibration, you can expect it to be far from\n    /// correct.\n    /// \\return The measured temperature, in degrees C from -40 to 85 (uncalibrated)\n    int8_t        temperatureRead();   \n\n    /// Sets the transmitter and receiver \n    /// centre frequency\n    /// \\param[in] centre Frequency in MHz. 240.0 to 960.0. Caution, RF69 comes in several\n    /// different frequency ranges, and setting a frequency outside that range of your radio will probably not work\n    /// \\param[in] afcPullInRange Not used\n    /// \\return true if the selected frquency centre is within range\n    bool        setFrequency(float centre, float afcPullInRange = 0.05);\n\n    /// Reads and returns the current RSSI value. \n    /// Causes the current signal strength to be measured and returned\n    /// If you want to find the RSSI\n    /// of the last received message, use lastRssi() instead.\n    /// \\return The current RSSI value on units of 0.5dB.\n    int8_t        rssiRead();\n\n    /// Sets the parameters for the RF69 OPMODE.\n    /// This is a low level device access function, and should not normally ned to be used by user code. \n    /// Instead can use stModeRx(), setModeTx(), setModeIdle()\n    /// \\param[in] mode RF69 OPMODE to set, one of RH_RF69_OPMODE_MODE_*.\n    void           setOpMode(uint8_t mode);\n\n    /// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, \n    /// disables them.\n    void           setModeIdle();\n\n    /// If current mode is Tx or Idle, changes it to Rx. \n    /// Starts the receiver in the RF69.\n    void           setModeRx();\n\n    /// If current mode is Rx or Idle, changes it to Rx. F\n    /// Starts the transmitter in the RF69.\n    void           setModeTx();\n\n    /// Sets the transmitter power output level.\n    /// Be a good neighbour and set the lowest power level you need.\n    /// Caution: legal power limits may apply in certain countries.\n    /// After init(), the power will be set to 13dBm.\n    /// \\param[in] power Transmitter power level in dBm. For RF69W, valid values are from -18 to +13 \n    /// (higher power settings disable the transmitter).\n    /// For RF69HW, valid values are from +14 to +20. Caution: at +20dBm, duty cycle is limited to 1% and a \n    /// maximum VSWR of 3:1 at the antenna port.\n    void           setTxPower(int8_t power);\n\n    /// Sets all the registers required to configure the data modem in the RF69, including the data rate, \n    /// bandwidths etc. You can use this to configure the modem with custom configurations if none of the \n    /// canned configurations in ModemConfigChoice suit you.\n    /// \\param[in] config A ModemConfig structure containing values for the modem configuration registers.\n    void           setModemRegisters(const ModemConfig* config);\n\n    /// Select one of the predefined modem configurations. If you need a modem configuration not provided \n    /// here, use setModemRegisters() with your own ModemConfig. The default after init() is RH_RF69::GFSK_Rb250Fd250.\n    /// \\param[in] index The configuration choice.\n    /// \\return true if index is a valid choice.\n    bool        setModemConfig(ModemConfigChoice index);\n\n    /// Get the values of one of the predefined modem configurations.\n    /// \n    /// \\param[in] index The configuration choice.\n    /// \\param[in] config A ModemConfig structure that will contains values of the modem configuration values.\n    /// \\return true if index is a valid choice and config has been filled with values\n    bool        getModemConfig(ModemConfigChoice index, ModemConfig* config);\n\n    /// Starts the receiver and checks whether a received message is available.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a complete, valid message has been received and is able to be retrieved by\n    /// recv()\n    bool        available();\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    bool        recv(uint8_t* buf, uint8_t* len);\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is NOT permitted. \n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send (> 0)\n    /// \\return true if the message length was valid and it was correctly queued for transmit\n    bool        send(const uint8_t* data, uint8_t len);\n\n    /// Blocks until the current message (if any) \n    /// has been transmitted\n    /// \\return true on success, false if the chip is not in transmit mode or other transmit failure\n#ifdef RH_RF69_IRQLESS\n    virtual bool   waitPacketSent();\n#endif\n\n    /// Sets the length of the preamble\n    /// in bytes. \n    /// Caution: this should be set to the same \n    /// value on all nodes in your network. Default is 4.\n    /// Sets the message preamble length in REG_0?_PREAMBLE?SB\n    /// \\param[in] bytes Preamble length in bytes.  \n    void           setPreambleLength(uint16_t bytes);\n\n    /// Sets the sync words for transmit and receive \n    /// Caution: SyncWords should be set to the same \n    /// value on all nodes in your network. Nodes with different SyncWords set will never receive\n    /// each others messages, so different SyncWords can be used to isolate different\n    /// networks from each other. Default is { 0x2d, 0xd4 }.\n    /// Caution: tests here show that with a single sync word (ie where len == 1), \n    /// RFM69 reception can be unreliable.\n    /// \\param[in] syncWords Array of sync words, 1 to 4 octets long. NULL if no sync words to be used.\n    /// \\param[in] len Number of sync words to set, 1 to 4. 0 if no sync words to be used.\n    void           setSyncWords(const uint8_t* syncWords = NULL, uint8_t len = 0);\n\n    /// Enables AES encryption and sets the AES encryption key, used\n    /// to encrypt and decrypt all messages. The default is disabled.\n    /// \\param[in] key The key to use. Must be 16 bytes long. The same key must be installed\n    /// in other instances of RF69, otherwise communications will not work correctly. If key is NULL,\n    /// encryption is disabled, which is the default.\n    void           setEncryptionKey(uint8_t* key = NULL);\n\n    /// Returns the time in millis since the most recent preamble was received, and when the most recent\n    /// RSSI measurement was made.\n    uint32_t getLastPreambleTime();\n\n    /// The maximum message length supported by this driver\n    /// \\return The maximum message length supported by this driver\n    uint8_t maxMessageLength();\n\n    /// Prints the value of a single register\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// For debugging/testing only\n    /// \\return true if successful\n    bool printRegister(uint8_t reg);\n\n    /// Prints the value of all the RF69 registers\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// For debugging/testing only\n    /// \\return true if successful\n    bool printRegisters();\n\n    /// Sets the radio operating mode for the case when the driver is idle (ie not\n    /// transmitting or receiving), allowing you to control the idle mode power requirements\n    /// at the expense of slower transitions to transmit and receive modes.\n    /// By default, the idle mode is RH_RF69_OPMODE_MODE_STDBY,\n    /// but eg setIdleMode(RH_RF69_OPMODE_MODE_SLEEP) will provide a much lower\n    /// idle current but slower transitions. Call this function after init().\n    /// \\param[in] idleMode The chip operating mode to use when the driver is idle. One of RH_RF69_OPMODE_*\n    void setIdleMode(uint8_t idleMode);\n\n    /// Sets the radio into low-power sleep mode.\n    /// If successful, the transport will stay in sleep mode until woken by \n    /// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc)\n    /// Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode.\n    /// \\return true if sleep mode was successfully entered.\n    virtual bool    sleep();\n\nprotected:\n    /// This is a low level function to handle the interrupts for one instance of RF69.\n    /// Called automatically by isr*()\n    /// Should not need to be called by user code.\n#ifndef RH_RF69_IRQLESS\n    void           handleInterrupt();\n#endif\n\n    /// Low level function to read the FIFO and put the received data into the receive buffer\n    /// Should not need to be called by user code.\n    void           readFifo();\n\nprotected:\n\n#ifndef RH_RF69_IRQLESS\n\n    /// Low level interrupt service routine for RF69 connected to interrupt 0\n    static void         isr0();\n\n    /// Low level interrupt service routine for RF69 connected to interrupt 1\n    static void         isr1();\n\n    /// Low level interrupt service routine for RF69 connected to interrupt 1\n    static void         isr2();\n\n    /// Array of instances connected to interrupts 0 and 1\n    static RH_RF69*     _deviceForInterrupt[];\n\n    /// Index of next interrupt number to use in _deviceForInterrupt\n    static uint8_t      _interruptCount;\n\n    /// The configured interrupt pin connected to this instance\n    uint8_t             _interruptPin;\n\n    /// The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated)\n    /// else 0xff\n    uint8_t             _myInterruptIndex;\n\n#endif\n\n    /// The radio OP mode to use when mode is RHModeIdle\n    uint8_t             _idleMode; \n\n    /// The reported device type\n    uint8_t             _deviceType;\n\n    /// The selected output power in dBm\n    int8_t              _power;\n\n    /// The message length in _buf\n    volatile uint8_t    _bufLen;\n\n    /// Array of octets of teh last received message or the next to transmit message\n    uint8_t             _buf[RH_RF69_MAX_MESSAGE_LEN];\n\n    /// True when there is a valid message in the Rx buffer\n    volatile bool    _rxBufValid;\n\n    /// Time in millis since the last preamble was received (and the last time the RSSI was measured)\n    uint32_t            _lastPreambleTime;\n};\n\n/// @example rf69_client.pde\n/// @example rf69_server.pde\n/// @example rf69_reliable_datagram_client.pde\n/// @example rf69_reliable_datagram_server.pde\n\n\n#endif\n"
  },
  {
    "path": "RH_RF95.cpp",
    "content": "// RH_RF95.cpp\n//\n// Copyright (C) 2011 Mike McCauley\n// $Id: RH_RF95.cpp,v 1.12 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_RF95.h>\n\n// Interrupt vectors for the 3 Arduino interrupt pins\n// Each interrupt can be handled by a different instance of RH_RF95, allowing you to have\n// 2 or more LORAs per Arduino\n#ifndef RH_RF95_IRQLESS\nRH_RF95* RH_RF95::_deviceForInterrupt[RH_RF95_NUM_INTERRUPTS] = {0, 0, 0};\nuint8_t RH_RF95::_interruptCount = 0; // Index into _deviceForInterrupt for next device\n#endif\n\n// These are indexed by the values of ModemConfigChoice\n// Stored in flash (program) memory to save SRAM\nPROGMEM static const RH_RF95::ModemConfig MODEM_CONFIG_TABLE[] =\n{\n    //  1d,     1e,      26\n    { 0x72,   0x74,    0x00}, // Bw125Cr45Sf128 (the chip default)\n    { 0x92,   0x74,    0x00}, // Bw500Cr45Sf128\n    { 0x48,   0x94,    0x00}, // Bw31_25Cr48Sf512\n    { 0x78,   0xc4,    0x00}, // Bw125Cr48Sf4096\n    \n};\n\nRH_RF95::RH_RF95(uint8_t slaveSelectPin, uint8_t interruptPin, RHGenericSPI& spi)\n    :\n    RHSPIDriver(slaveSelectPin, spi),\n    _rxBufValid(0)\n{\n#ifndef RH_RF95_IRQLESS\n    _interruptPin = interruptPin;\n    _myInterruptIndex = 0xff; // Not allocated yet\n#endif\n}\n\nbool RH_RF95::init()\n{\n    /// The reported device version\n    uint8_t deviceVersion;\n\n    if (!RHSPIDriver::init())\n\treturn false;\n\n#ifndef RH_RF95_IRQLESS\n    // Determine the interrupt number that corresponds to the interruptPin\n    int interruptNumber = digitalPinToInterrupt(_interruptPin);\n    if (interruptNumber == NOT_AN_INTERRUPT)\n\treturn false;\n#ifdef RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER\n    interruptNumber = _interruptPin;\n#endif\n#endif // ndef RH_RF95_IRQLESS\n\n    // Get the device type and check it\n    // This also tests whether we are really connected to a device\n    // My test devices return 0x83\n    deviceVersion = spiRead(RH_RF95_REG_42_VERSION);\n    if (deviceVersion == 00 ||\n    deviceVersion == 0xff)\n    return false;\n\n    // Set sleep mode, so we can also set LORA mode:\n    spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE);\n    delay(10); // Wait for sleep mode to take over from say, CAD\n    // Check we are in sleep mode, with LORA set\n    if (spiRead(RH_RF95_REG_01_OP_MODE) != (RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE))\n    {\n//\tSerial.println(spiRead(RH_RF95_REG_01_OP_MODE), HEX);\n\treturn false; // No device present?\n    }\n\n#ifndef RH_RF95_IRQLESS\n\n    // Add by Adrien van den Bossche <vandenbo@univ-tlse2.fr> for Teensy\n    // ARM M4 requires the below. else pin interrupt doesn't work properly.\n    // On all other platforms, its innocuous, belt and braces\n    pinMode(_interruptPin, INPUT); \n\n    // Set up interrupt handler\n    // Since there are a limited number of interrupt glue functions isr*() available,\n    // we can only support a limited number of devices simultaneously\n    // ON some devices, notably most Arduinos, the interrupt pin passed in is actuallt the \n    // interrupt number. You have to figure out the interruptnumber-to-interruptpin mapping\n    // yourself based on knwledge of what Arduino board you are running on.\n    if (_myInterruptIndex == 0xff)\n    {\n\t// First run, no interrupt allocated yet\n\tif (_interruptCount <= RH_RF95_NUM_INTERRUPTS)\n\t    _myInterruptIndex = _interruptCount++;\n\telse\n\t    return false; // Too many devices, not enough interrupt vectors\n    }\n    _deviceForInterrupt[_myInterruptIndex] = this;\n    if (_myInterruptIndex == 0)\n\tattachInterrupt(interruptNumber, isr0, RISING);\n    else if (_myInterruptIndex == 1)\n\tattachInterrupt(interruptNumber, isr1, RISING);\n    else if (_myInterruptIndex == 2)\n\tattachInterrupt(interruptNumber, isr2, RISING);\n    else\n\treturn false; // Too many devices, not enough interrupt vectors\n\n#endif // ndef RH_RF95_IRQLESS\n\n\n    // Set up FIFO\n    // We configure so that we can use the entire 256 byte FIFO for either receive\n    // or transmit, but not both at the same time\n    spiWrite(RH_RF95_REG_0E_FIFO_TX_BASE_ADDR, 0);\n    spiWrite(RH_RF95_REG_0F_FIFO_RX_BASE_ADDR, 0);\n\n    // Packet format is preamble + explicit-header + payload + crc\n    // Explicit Header Mode\n    // payload is TO + FROM + ID + FLAGS + message data\n    // RX mode is implmented with RXCONTINUOUS\n    // max message data length is 255 - 4 = 251 octets\n\n    setModeIdle();\n\n    // Set up default configuration\n    // No Sync Words in LORA mode.\n    setModemConfig(Bw125Cr45Sf128); // Radio default\n//    setModemConfig(Bw125Cr48Sf4096); // slow and reliable?\n    setPreambleLength(8); // Default is 8\n    // An innocuous ISM frequency, same as RF22's\n    setFrequency(434.0);\n    // Lowish power\n    setTxPower(13);\n\n    return true;\n}\n\n// C++ level interrupt handler for this instance\n// LORA is unusual in that it has several interrupt lines, and not a single, combined one.\n// On MiniWirelessLoRa, only one of the several interrupt lines (DI0) from the RFM95 is usefuly \n// connnected to the processor.\n// We use this to get RxDone and TxDone interrupts\n#ifndef RH_RF95_IRQLESS\nvoid RH_RF95::handleInterrupt()\n{\n    // Read the interrupt register\n    uint8_t irq_flags = spiRead(RH_RF95_REG_12_IRQ_FLAGS);\n    if (_mode == RHModeRx && irq_flags & (RH_RF95_RX_TIMEOUT | RH_RF95_PAYLOAD_CRC_ERROR))\n    {\n\t_rxBad++;\n    }\n    else if (_mode == RHModeRx && irq_flags & RH_RF95_RX_DONE)\n    {\n\t// Have received a packet\n\tuint8_t len = spiRead(RH_RF95_REG_13_RX_NB_BYTES);\n\n\t// Reset the fifo read ptr to the beginning of the packet\n\tspiWrite(RH_RF95_REG_0D_FIFO_ADDR_PTR, spiRead(RH_RF95_REG_10_FIFO_RX_CURRENT_ADDR));\n\tspiBurstRead(RH_RF95_REG_00_FIFO, _buf, len);\n\t_bufLen = len;\n\tspiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags\n\n\t// Remember the RSSI of this packet\n\t// this is according to the doc, but is it really correct?\n\t// weakest receiveable signals are reported RSSI at about -66\n\t_lastRssi = spiRead(RH_RF95_REG_1A_PKT_RSSI_VALUE) - 137;\n\n\t// We have received a message.\n\tvalidateRxBuf(); \n\tif (_rxBufValid)\n\t    setModeIdle(); // Got one \n    }\n    else if (_mode == RHModeTx && irq_flags & RH_RF95_TX_DONE)\n    {\n\t_txGood++;\n\tsetModeIdle();\n    }\n    else if (_mode == RHModeCad && irq_flags & RH_RF95_CAD_DONE)\n    {\n        _cad = irq_flags & RH_RF95_CAD_DETECTED;\n        setModeIdle();\n    }\n    \n    spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags\n}\n#endif // ndef RH_RF95_IRQLESS\n\n// These are low level functions that call the interrupt handler for the correct\n// instance of RH_RF95.\n// 3 interrupts allows us to have 3 different devices\n#ifndef RH_RF95_IRQLESS\nvoid RH_RF95::isr0()\n{\n    if (_deviceForInterrupt[0])\n\t_deviceForInterrupt[0]->handleInterrupt();\n}\nvoid RH_RF95::isr1()\n{\n    if (_deviceForInterrupt[1])\n\t_deviceForInterrupt[1]->handleInterrupt();\n}\nvoid RH_RF95::isr2()\n{\n    if (_deviceForInterrupt[2])\n\t_deviceForInterrupt[2]->handleInterrupt();\n}\n#endif // ndef RH_RF95_IRQLESS\n\n// Check whether the latest received message is complete and uncorrupted\nvoid RH_RF95::validateRxBuf()\n{\n    if (_bufLen < 4)\n\treturn; // Too short to be a real message\n    // Extract the 4 headers\n    _rxHeaderTo    = _buf[0];\n    _rxHeaderFrom  = _buf[1];\n    _rxHeaderId    = _buf[2];\n    _rxHeaderFlags = _buf[3];\n    if (_promiscuous ||\n\t_rxHeaderTo == _thisAddress ||\n\t_rxHeaderTo == RH_BROADCAST_ADDRESS)\n    {\n\t_rxGood++;\n\t_rxBufValid = true;\n    }\n}\n\nbool RH_RF95::available()\n{\n#ifdef RH_RF95_IRQLESS\n    // Read the interrupt register\n    uint8_t irq_flags = spiRead(RH_RF95_REG_12_IRQ_FLAGS);\n    if (_mode == RHModeRx && irq_flags & RH_RF95_RX_DONE)\n    {\n    // Have received a packet\n    uint8_t len = spiRead(RH_RF95_REG_13_RX_NB_BYTES);\n\n    // Reset the fifo read ptr to the beginning of the packet\n    spiWrite(RH_RF95_REG_0D_FIFO_ADDR_PTR, spiRead(RH_RF95_REG_10_FIFO_RX_CURRENT_ADDR));\n    spiBurstRead(RH_RF95_REG_00_FIFO, _buf, len);\n    _bufLen = len;\n    spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags\n\n    // Remember the RSSI of this packet\n    // this is according to the doc, but is it really correct?\n    // weakest receiveable signals are reported RSSI at about -66\n    _lastRssi = spiRead(RH_RF95_REG_1A_PKT_RSSI_VALUE) - 137;\n\n    // We have received a message.\n    validateRxBuf(); \n    if (_rxBufValid)\n        setModeIdle(); // Got one \n    }\n    else if (_mode == RHModeCad && irq_flags & RH_RF95_CAD_DONE)\n    {\n        _cad = irq_flags & RH_RF95_CAD_DETECTED;\n        setModeIdle();\n    }\n    \n    spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags\n\n#endif // defined RH_RF95_IRQLESS\n\n    if (_mode == RHModeTx)\n\treturn false;\n    setModeRx();\n    return _rxBufValid; // Will be set by the interrupt handler when a good message is received\n}\n\nvoid RH_RF95::clearRxBuf()\n{\n    ATOMIC_BLOCK_START;\n    _rxBufValid = false;\n    _bufLen = 0;\n    ATOMIC_BLOCK_END;\n}\n\nbool RH_RF95::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n    if (buf && len)\n    {\n\tATOMIC_BLOCK_START;\n\t// Skip the 4 headers that are at the beginning of the rxBuf\n\tif (*len > _bufLen-RH_RF95_HEADER_LEN)\n\t    *len = _bufLen-RH_RF95_HEADER_LEN;\n\tmemcpy(buf, _buf+RH_RF95_HEADER_LEN, *len);\n\tATOMIC_BLOCK_END;\n    }\n    clearRxBuf(); // This message accepted and cleared\n    return true;\n}\n\nbool RH_RF95::send(const uint8_t* data, uint8_t len)\n{\n    if (len > RH_RF95_MAX_MESSAGE_LEN)\n\treturn false;\n\n    waitPacketSent(); // Make sure we dont interrupt an outgoing message\n    setModeIdle();\n\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    // Position at the beginning of the FIFO\n    spiWrite(RH_RF95_REG_0D_FIFO_ADDR_PTR, 0);\n    // The headers\n    spiWrite(RH_RF95_REG_00_FIFO, _txHeaderTo);\n    spiWrite(RH_RF95_REG_00_FIFO, _txHeaderFrom);\n    spiWrite(RH_RF95_REG_00_FIFO, _txHeaderId);\n    spiWrite(RH_RF95_REG_00_FIFO, _txHeaderFlags);\n    // The message data\n    spiBurstWrite(RH_RF95_REG_00_FIFO, data, len);\n    spiWrite(RH_RF95_REG_22_PAYLOAD_LENGTH, len + RH_RF95_HEADER_LEN);\n\n    setModeTx(); // Start the transmitter\n    // when Tx is done, interruptHandler will fire and radio mode will return to STANDBY\n    return true;\n}\n\n#ifdef RH_RF95_IRQLESS\n// Since we have no interrupts, we need to implement our own \n// waitPacketSent for the driver by reading RF69 internal register\nbool RH_RF95::waitPacketSent()\n{\n    // If we are not currently in transmit mode, there is no packet to wait for\n    if (_mode != RHModeTx)\n    return false;\n\n    while (!(spiRead(RH_RF95_REG_12_IRQ_FLAGS) & RH_RF95_TX_DONE)){\n      YIELD;\n    }\n\n    // A transmitter message has been fully sent\n    _txGood++;\n    setModeIdle(); // Clears FIFO\n    return true;\n}\n#endif // defined RH_RF95_IRQLESS\n\nbool RH_RF95::printRegisters()\n{\n#ifdef RH_HAVE_SERIAL\n    uint8_t registers[] = { 0x01, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x014, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27};\n\n    uint8_t i;\n    for (i = 0; i < sizeof(registers); i++)\n    {\n\tSerial.print(registers[i], HEX);\n\tSerial.print(\": \");\n\tSerial.println(spiRead(registers[i]), HEX);\n    }\n#endif\n    return true;\n}\n\nuint8_t RH_RF95::maxMessageLength()\n{\n    return RH_RF95_MAX_MESSAGE_LEN;\n}\n\nbool RH_RF95::setFrequency(float centre)\n{\n    // Frf = FRF / FSTEP\n    uint32_t frf = (centre * 1000000.0) / RH_RF95_FSTEP;\n    spiWrite(RH_RF95_REG_06_FRF_MSB, (frf >> 16) & 0xff);\n    spiWrite(RH_RF95_REG_07_FRF_MID, (frf >> 8) & 0xff);\n    spiWrite(RH_RF95_REG_08_FRF_LSB, frf & 0xff);\n\n    return true;\n}\n\nvoid RH_RF95::setModeIdle()\n{\n    if (_mode != RHModeIdle)\n    {\n\tspiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_STDBY);\n\t_mode = RHModeIdle;\n    }\n}\n\nbool RH_RF95::sleep()\n{\n    if (_mode != RHModeSleep)\n    {\n\tspiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_SLEEP);\n\t_mode = RHModeSleep;\n    }\n    return true;\n}\n\nvoid RH_RF95::setModeRx()\n{\n    if (_mode != RHModeRx)\n    {\n\tspiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_RXCONTINUOUS);\n\tspiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x00); // Interrupt on RxDone\n\t_mode = RHModeRx;\n    }\n}\n\nvoid RH_RF95::setModeTx()\n{\n    if (_mode != RHModeTx)\n    {\n\tspiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_TX);\n\tspiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x40); // Interrupt on TxDone\n\t_mode = RHModeTx;\n    }\n}\n\nvoid RH_RF95::setTxPower(int8_t power, bool useRFO)\n{\n    // Sigh, different behaviours depending on whther the module use PA_BOOST or the RFO pin\n    // for the transmitter output\n    if (useRFO)\n    {\n\tif (power > 14)\n\t    power = 14;\n\tif (power < -1)\n\t    power = -1;\n\tspiWrite(RH_RF95_REG_09_PA_CONFIG, RH_RF95_MAX_POWER | (power + 1));\n    }\n    else\n    {\n\tif (power > 23)\n\t    power = 23;\n\tif (power < 5)\n\t    power = 5;\n\n\t// For RH_RF95_PA_DAC_ENABLE, manual says '+20dBm on PA_BOOST when OutputPower=0xf'\n\t// RH_RF95_PA_DAC_ENABLE actually adds about 3dBm to all power levels. We will us it\n\t// for 21, 22 and 23dBm\n\tif (power > 20)\n\t{\n\t    spiWrite(RH_RF95_REG_4D_PA_DAC, RH_RF95_PA_DAC_ENABLE);\n\t    power -= 3;\n\t}\n\telse\n\t{\n\t    spiWrite(RH_RF95_REG_4D_PA_DAC, RH_RF95_PA_DAC_DISABLE);\n\t}\n\n\t// RFM95/96/97/98 does not have RFO pins connected to anything. Only PA_BOOST\n\t// pin is connected, so must use PA_BOOST\n\t// Pout = 2 + OutputPower.\n\t// The documentation is pretty confusing on this topic: PaSelect says the max power is 20dBm,\n\t// but OutputPower claims it would be 17dBm.\n\t// My measurements show 20dBm is correct\n\tspiWrite(RH_RF95_REG_09_PA_CONFIG, RH_RF95_PA_SELECT | (power-5));\n    }\n}\n\n// Sets registers from a canned modem configuration structure\nvoid RH_RF95::setModemRegisters(const ModemConfig* config)\n{\n    spiWrite(RH_RF95_REG_1D_MODEM_CONFIG1,       config->reg_1d);\n    spiWrite(RH_RF95_REG_1E_MODEM_CONFIG2,       config->reg_1e);\n    spiWrite(RH_RF95_REG_26_MODEM_CONFIG3,       config->reg_26);\n}\n\n// Set one of the canned FSK Modem configs\n// Returns true if its a valid choice\nbool RH_RF95::setModemConfig(ModemConfigChoice index)\n{\n    if (index > (signed int)(sizeof(MODEM_CONFIG_TABLE) / sizeof(ModemConfig)))\n        return false;\n\n    ModemConfig cfg;\n    memcpy_P(&cfg, &MODEM_CONFIG_TABLE[index], sizeof(RH_RF95::ModemConfig));\n    setModemRegisters(&cfg);\n\n    return true;\n}\n\n// Return the  Modem configs\nbool RH_RF95::getModemConfig(ModemConfigChoice index, ModemConfig* config)\n{\n  if (index > (signed int)(sizeof(MODEM_CONFIG_TABLE) / sizeof(ModemConfig)))\n    return false;\n\n  memcpy_P(config, &MODEM_CONFIG_TABLE[index], sizeof(RH_RF95::ModemConfig));\n\n  return true;\n}\n\n\n\nvoid RH_RF95::setPreambleLength(uint16_t bytes)\n{\n    spiWrite(RH_RF95_REG_20_PREAMBLE_MSB, bytes >> 8);\n    spiWrite(RH_RF95_REG_21_PREAMBLE_LSB, bytes & 0xff);\n}\n\nbool RH_RF95::isChannelActive()\n{\n    // Set mode RHModeCad\n    if (_mode != RHModeCad)\n    {\n        spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_CAD);\n        spiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x80); // Interrupt on CadDone\n        _mode = RHModeCad;\n    }\n\n    while (_mode == RHModeCad)\n        YIELD;\n\n    return _cad;\n}\n\nvoid RH_RF95::enableTCXO()\n{\n    while ((spiRead(RH_RF95_REG_4B_TCXO) & RH_RF95_TCXO_TCXO_INPUT_ON) != RH_RF95_TCXO_TCXO_INPUT_ON)\n    {\n\tsleep();\n\tspiWrite(RH_RF95_REG_4B_TCXO, (spiRead(RH_RF95_REG_4B_TCXO) | RH_RF95_TCXO_TCXO_INPUT_ON));\n    } \n}\n"
  },
  {
    "path": "RH_RF95.h",
    "content": "// RH_RF95.h\n//\n// Definitions for HopeRF LoRa radios per:\n// http://www.hoperf.com/upload/rf/RFM95_96_97_98W.pdf\n// http://www.hoperf.cn/upload/rfchip/RF96_97_98.pdf\n//\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_RF95.h,v 1.14 2017/01/13 01:29:36 mikem Exp mikem $\n// \n\n#ifndef RH_RF95_h\n#define RH_RF95_h\n\n#include <RHSPIDriver.h>\n\n// If you don't want to use interupts (mainly to win one I/O pin) then\n// you just need to uncomment this line, if you're on Raspberry PI \n// it will be set automaticly below\n//#define RH_RF69_IRQLESS\n\n#if (RH_PLATFORM == RH_PLATFORM_RASPI)\n// No IRQ used on Raspberry PI\n#ifndef RH_RF95_IRQLESS\n#define RH_RF95_IRQLESS\n#endif\n#endif // RH_PLATFORM_RASPI PI\n\n// This is the maximum number of interrupts the driver can support\n// Most Arduinos can handle 2, Megas can handle more\n#define RH_RF95_NUM_INTERRUPTS 3\n\n// Max number of octets the LORA Rx/Tx FIFO can hold\n#define RH_RF95_FIFO_SIZE 255\n\n// This is the maximum number of bytes that can be carried by the LORA.\n// We use some for headers, keeping fewer for RadioHead messages\n#define RH_RF95_MAX_PAYLOAD_LEN RH_RF95_FIFO_SIZE\n\n// The length of the headers we add.\n// The headers are inside the LORA's payload\n#define RH_RF95_HEADER_LEN 4\n\n// This is the maximum message length that can be supported by this driver. \n// Can be pre-defined to a smaller size (to save SRAM) prior to including this header\n// Here we allow for 1 byte message length, 4 bytes headers, user data and 2 bytes of FCS\n#ifndef RH_RF95_MAX_MESSAGE_LEN\n #define RH_RF95_MAX_MESSAGE_LEN (RH_RF95_MAX_PAYLOAD_LEN - RH_RF95_HEADER_LEN)\n#endif\n\n// The crystal oscillator frequency of the module\n#define RH_RF95_FXOSC 32000000.0\n\n// The Frequency Synthesizer step = RH_RF95_FXOSC / 2^^19\n#define RH_RF95_FSTEP  (RH_RF95_FXOSC / 524288)\n\n\n// Register names (LoRa Mode, from table 85)\n#define RH_RF95_REG_00_FIFO                                0x00\n#define RH_RF95_REG_01_OP_MODE                             0x01\n#define RH_RF95_REG_02_RESERVED                            0x02\n#define RH_RF95_REG_03_RESERVED                            0x03\n#define RH_RF95_REG_04_RESERVED                            0x04\n#define RH_RF95_REG_05_RESERVED                            0x05\n#define RH_RF95_REG_06_FRF_MSB                             0x06\n#define RH_RF95_REG_07_FRF_MID                             0x07\n#define RH_RF95_REG_08_FRF_LSB                             0x08\n#define RH_RF95_REG_09_PA_CONFIG                           0x09\n#define RH_RF95_REG_0A_PA_RAMP                             0x0a\n#define RH_RF95_REG_0B_OCP                                 0x0b\n#define RH_RF95_REG_0C_LNA                                 0x0c\n#define RH_RF95_REG_0D_FIFO_ADDR_PTR                       0x0d\n#define RH_RF95_REG_0E_FIFO_TX_BASE_ADDR                   0x0e\n#define RH_RF95_REG_0F_FIFO_RX_BASE_ADDR                   0x0f\n#define RH_RF95_REG_10_FIFO_RX_CURRENT_ADDR                0x10\n#define RH_RF95_REG_11_IRQ_FLAGS_MASK                      0x11\n#define RH_RF95_REG_12_IRQ_FLAGS                           0x12\n#define RH_RF95_REG_13_RX_NB_BYTES                         0x13\n#define RH_RF95_REG_14_RX_HEADER_CNT_VALUE_MSB             0x14\n#define RH_RF95_REG_15_RX_HEADER_CNT_VALUE_LSB             0x15\n#define RH_RF95_REG_16_RX_PACKET_CNT_VALUE_MSB             0x16\n#define RH_RF95_REG_17_RX_PACKET_CNT_VALUE_LSB             0x17\n#define RH_RF95_REG_18_MODEM_STAT                          0x18\n#define RH_RF95_REG_19_PKT_SNR_VALUE                       0x19\n#define RH_RF95_REG_1A_PKT_RSSI_VALUE                      0x1a\n#define RH_RF95_REG_1B_RSSI_VALUE                          0x1b\n#define RH_RF95_REG_1C_HOP_CHANNEL                         0x1c\n#define RH_RF95_REG_1D_MODEM_CONFIG1                       0x1d\n#define RH_RF95_REG_1E_MODEM_CONFIG2                       0x1e\n#define RH_RF95_REG_1F_SYMB_TIMEOUT_LSB                    0x1f\n#define RH_RF95_REG_20_PREAMBLE_MSB                        0x20\n#define RH_RF95_REG_21_PREAMBLE_LSB                        0x21\n#define RH_RF95_REG_22_PAYLOAD_LENGTH                      0x22\n#define RH_RF95_REG_23_MAX_PAYLOAD_LENGTH                  0x23\n#define RH_RF95_REG_24_HOP_PERIOD                          0x24\n#define RH_RF95_REG_25_FIFO_RX_BYTE_ADDR                   0x25\n#define RH_RF95_REG_26_MODEM_CONFIG3                       0x26\n\n#define RH_RF95_REG_40_DIO_MAPPING1                        0x40\n#define RH_RF95_REG_41_DIO_MAPPING2                        0x41\n#define RH_RF95_REG_42_VERSION                             0x42\n\n#define RH_RF95_REG_4B_TCXO                                0x4b\n#define RH_RF95_REG_4D_PA_DAC                              0x4d\n#define RH_RF95_REG_5B_FORMER_TEMP                         0x5b\n#define RH_RF95_REG_61_AGC_REF                             0x61\n#define RH_RF95_REG_62_AGC_THRESH1                         0x62\n#define RH_RF95_REG_63_AGC_THRESH2                         0x63\n#define RH_RF95_REG_64_AGC_THRESH3                         0x64\n\n// RH_RF95_REG_01_OP_MODE                             0x01\n#define RH_RF95_LONG_RANGE_MODE                       0x80\n#define RH_RF95_ACCESS_SHARED_REG                     0x40\n#define RH_RF95_LOW_FREQUENCY_MODE                    0x08\n#define RH_RF95_MODE                                  0x07\n#define RH_RF95_MODE_SLEEP                            0x00\n#define RH_RF95_MODE_STDBY                            0x01\n#define RH_RF95_MODE_FSTX                             0x02\n#define RH_RF95_MODE_TX                               0x03\n#define RH_RF95_MODE_FSRX                             0x04\n#define RH_RF95_MODE_RXCONTINUOUS                     0x05\n#define RH_RF95_MODE_RXSINGLE                         0x06\n#define RH_RF95_MODE_CAD                              0x07\n\n// RH_RF95_REG_09_PA_CONFIG                           0x09\n#define RH_RF95_PA_SELECT                             0x80\n#define RH_RF95_MAX_POWER                             0x70\n#define RH_RF95_OUTPUT_POWER                          0x0f\n\n// RH_RF95_REG_0A_PA_RAMP                             0x0a\n#define RH_RF95_LOW_PN_TX_PLL_OFF                     0x10\n#define RH_RF95_PA_RAMP                               0x0f\n#define RH_RF95_PA_RAMP_3_4MS                         0x00\n#define RH_RF95_PA_RAMP_2MS                           0x01\n#define RH_RF95_PA_RAMP_1MS                           0x02\n#define RH_RF95_PA_RAMP_500US                         0x03\n#define RH_RF95_PA_RAMP_250US                         0x0\n#define RH_RF95_PA_RAMP_125US                         0x05\n#define RH_RF95_PA_RAMP_100US                         0x06\n#define RH_RF95_PA_RAMP_62US                          0x07\n#define RH_RF95_PA_RAMP_50US                          0x08\n#define RH_RF95_PA_RAMP_40US                          0x09\n#define RH_RF95_PA_RAMP_31US                          0x0a\n#define RH_RF95_PA_RAMP_25US                          0x0b\n#define RH_RF95_PA_RAMP_20US                          0x0c\n#define RH_RF95_PA_RAMP_15US                          0x0d\n#define RH_RF95_PA_RAMP_12US                          0x0e\n#define RH_RF95_PA_RAMP_10US                          0x0f\n\n// RH_RF95_REG_0B_OCP                                 0x0b\n#define RH_RF95_OCP_ON                                0x20\n#define RH_RF95_OCP_TRIM                              0x1f\n\n// RH_RF95_REG_0C_LNA                                 0x0c\n#define RH_RF95_LNA_GAIN                              0xe0\n#define RH_RF95_LNA_GAIN_G1                           0x20\n#define RH_RF95_LNA_GAIN_G2                           0x40\n#define RH_RF95_LNA_GAIN_G3                           0x60                \n#define RH_RF95_LNA_GAIN_G4                           0x80\n#define RH_RF95_LNA_GAIN_G5                           0xa0\n#define RH_RF95_LNA_GAIN_G6                           0xc0\n#define RH_RF95_LNA_BOOST_LF                          0x18\n#define RH_RF95_LNA_BOOST_LF_DEFAULT                  0x00\n#define RH_RF95_LNA_BOOST_HF                          0x03\n#define RH_RF95_LNA_BOOST_HF_DEFAULT                  0x00\n#define RH_RF95_LNA_BOOST_HF_150PC                    0x11\n\n// RH_RF95_REG_11_IRQ_FLAGS_MASK                      0x11\n#define RH_RF95_RX_TIMEOUT_MASK                       0x80\n#define RH_RF95_RX_DONE_MASK                          0x40\n#define RH_RF95_PAYLOAD_CRC_ERROR_MASK                0x20\n#define RH_RF95_VALID_HEADER_MASK                     0x10\n#define RH_RF95_TX_DONE_MASK                          0x08\n#define RH_RF95_CAD_DONE_MASK                         0x04\n#define RH_RF95_FHSS_CHANGE_CHANNEL_MASK              0x02\n#define RH_RF95_CAD_DETECTED_MASK                     0x01\n\n// RH_RF95_REG_12_IRQ_FLAGS                           0x12\n#define RH_RF95_RX_TIMEOUT                            0x80\n#define RH_RF95_RX_DONE                               0x40\n#define RH_RF95_PAYLOAD_CRC_ERROR                     0x20\n#define RH_RF95_VALID_HEADER                          0x10\n#define RH_RF95_TX_DONE                               0x08\n#define RH_RF95_CAD_DONE                              0x04\n#define RH_RF95_FHSS_CHANGE_CHANNEL                   0x02\n#define RH_RF95_CAD_DETECTED                          0x01\n\n// RH_RF95_REG_18_MODEM_STAT                          0x18\n#define RH_RF95_RX_CODING_RATE                        0xe0\n#define RH_RF95_MODEM_STATUS_CLEAR                    0x10\n#define RH_RF95_MODEM_STATUS_HEADER_INFO_VALID        0x08\n#define RH_RF95_MODEM_STATUS_RX_ONGOING               0x04\n#define RH_RF95_MODEM_STATUS_SIGNAL_SYNCHRONIZED      0x02\n#define RH_RF95_MODEM_STATUS_SIGNAL_DETECTED          0x01\n\n// RH_RF95_REG_1C_HOP_CHANNEL                         0x1c\n#define RH_RF95_PLL_TIMEOUT                           0x80\n#define RH_RF95_RX_PAYLOAD_CRC_IS_ON                  0x40\n#define RH_RF95_FHSS_PRESENT_CHANNEL                  0x3f\n\n// RH_RF95_REG_1D_MODEM_CONFIG1                       0x1d\n#define RH_RF95_BW                                    0xf0\n\n#define RH_RF95_BW_7_8KHZ                             0x00\n#define RH_RF95_BW_10_4KHZ                            0x10\n#define RH_RF95_BW_15_6KHZ                            0x20\n#define RH_RF95_BW_20_8KHZ                            0x30\n#define RH_RF95_BW_31_25KHZ                           0x40\n#define RH_RF95_BW_41_7KHZ                            0x50\n#define RH_RF95_BW_62_5KHZ                            0x60\n#define RH_RF95_BW_125KHZ                             0x70\n#define RH_RF95_BW_250KHZ                             0x80\n#define RH_RF95_BW_500KHZ                             0x90\n#define RH_RF95_CODING_RATE                           0x0e\n#define RH_RF95_CODING_RATE_4_5                       0x02\n#define RH_RF95_CODING_RATE_4_6                       0x04\n#define RH_RF95_CODING_RATE_4_7                       0x06\n#define RH_RF95_CODING_RATE_4_8                       0x08\n#define RH_RF95_IMPLICIT_HEADER_MODE_ON               0x01\n\n// RH_RF95_REG_1E_MODEM_CONFIG2                       0x1e\n#define RH_RF95_SPREADING_FACTOR                      0xf0\n#define RH_RF95_SPREADING_FACTOR_64CPS                0x60\n#define RH_RF95_SPREADING_FACTOR_128CPS               0x70\n#define RH_RF95_SPREADING_FACTOR_256CPS               0x80\n#define RH_RF95_SPREADING_FACTOR_512CPS               0x90\n#define RH_RF95_SPREADING_FACTOR_1024CPS              0xa0\n#define RH_RF95_SPREADING_FACTOR_2048CPS              0xb0\n#define RH_RF95_SPREADING_FACTOR_4096CPS              0xc0\n#define RH_RF95_TX_CONTINUOUS_MOE                     0x08\n\n#define RH_RF95_PAYLOAD_CRC_ON                        0x04\n#define RH_RF95_SYM_TIMEOUT_MSB                       0x03\n\n// RH_RF95_REG_4B_TCXO                                0x4b\n#define RH_RF95_TCXO_TCXO_INPUT_ON                    0x10\n\n// RH_RF95_REG_4D_PA_DAC                              0x4d\n#define RH_RF95_PA_DAC_DISABLE                        0x04\n#define RH_RF95_PA_DAC_ENABLE                         0x07\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_RF95 RH_RF95.h <RH_RF95.h>\n/// \\brief Driver to send and receive unaddressed, unreliable datagrams via a LoRa \n/// capable radio transceiver.\n///\n/// For Semtech SX1276/77/78/79 and HopeRF RF95/96/97/98 and other similar LoRa capable radios.\n/// Based on http://www.hoperf.com/upload/rf/RFM95_96_97_98W.pdf\n/// and http://www.hoperf.cn/upload/rfchip/RF96_97_98.pdf\n/// and http://www.semtech.com/images/datasheet/LoraDesignGuide_STD.pdf\n/// and http://www.semtech.com/images/datasheet/sx1276.pdf\n/// and http://www.semtech.com/images/datasheet/sx1276_77_78_79.pdf\n/// FSK/GFSK/OOK modes are not (yet) supported.\n///\n/// Works with\n/// - the excellent MiniWirelessLoRa from Anarduino http://www.anarduino.com/miniwireless\n/// - The excellent Modtronix inAir4 http://modtronix.com/inair4.html \n/// and inAir9 modules http://modtronix.com/inair9.html.\n/// - the excellent Rocket Scream Mini Ultra Pro with the RFM95W \n///   http://www.rocketscream.com/blog/product/mini-ultra-pro-with-radio/\n/// - Lora1276 module from NiceRF http://www.nicerf.com/product_view.aspx?id=99\n/// - Adafruit Feather M0 with RFM95 \n///\n/// \\par Overview\n///\n/// This class provides basic functions for sending and receiving unaddressed, \n/// unreliable datagrams of arbitrary length to 251 octets per packet.\n///\n/// Manager classes may use this class to implement reliable, addressed datagrams and streams, \n/// mesh routers, repeaters, translators etc.\n///\n/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and \n/// modulation scheme.\n///\n/// This Driver provides an object-oriented interface for sending and receiving data messages with Hope-RF\n/// RFM95/96/97/98(W), Semtech SX1276/77/78/79 and compatible radio modules in LoRa mode.\n///\n/// The Hope-RF (http://www.hoperf.com) RFM95/96/97/98(W) and Semtech SX1276/77/78/79 is a low-cost ISM transceiver\n/// chip. It supports FSK, GFSK, OOK over a wide range of frequencies and\n/// programmable data rates, and it also supports the proprietary LoRA (Long Range) mode, which\n/// is the only mode supported in this RadioHead driver.\n///\n/// This Driver provides functions for sending and receiving messages of up\n/// to 251 octets on any frequency supported by the radio, in a range of\n/// predefined Bandwidths, Spreading Factors and Coding Rates.  Frequency can be set with\n/// 61Hz precision to any frequency from 240.0MHz to 960.0MHz. Caution: most modules only support a more limited\n/// range of frequencies due to antenna tuning.\n///\n/// Up to 2 modules can be connected to an Arduino (3 on a Mega),\n/// permitting the construction of translators and frequency changers, etc.\n///\n/// Support for other features such as transmitter power control etc is\n/// also provided.\n///\n/// Tested on MinWirelessLoRa with arduino-1.0.5\n/// on OpenSuSE 13.1. \n/// Also tested with Teensy3.1, Modtronix inAir4 and Arduino 1.6.5 on OpenSuSE 13.1\n///\n/// \\par Packet Format\n///\n/// All messages sent and received by this RH_RF95 Driver conform to this packet format:\n///\n/// - LoRa mode:\n/// - 8 symbol PREAMBLE\n/// - Explicit header with header CRC (handled internally by the radio)\n/// - 4 octets HEADER: (TO, FROM, ID, FLAGS)\n/// - 0 to 251 octets DATA \n/// - CRC (handled internally by the radio)\n///\n/// \\par Connecting RFM95/96/97/98 and Semtech SX1276/77/78/79 to Arduino\n///\n/// We tested with Anarduino MiniWirelessLoRA, which is an Arduino Duemilanove compatible with a RFM96W\n/// module on-board. Therefore it needs no connections other than the USB\n/// programming connection and an antenna to make it work.\n///\n/// If you have a bare RFM95/96/97/98 that you want to connect to an Arduino, you\n/// might use these connections (untested): CAUTION: you must use a 3.3V type\n/// Arduino, otherwise you will also need voltage level shifters between the\n/// Arduino and the RFM95.  CAUTION, you must also ensure you connect an\n/// antenna.\n/// \n/// \\code\n///                 Arduino      RFM95/96/97/98\n///                 GND----------GND   (ground in)\n///                 3V3----------3.3V  (3.3V in)\n/// interrupt 0 pin D2-----------DIO0  (interrupt request out)\n///          SS pin D10----------NSS   (CS chip select in)\n///         SCK pin D13----------SCK   (SPI clock in)\n///        MOSI pin D11----------MOSI  (SPI Data in)\n///        MISO pin D12----------MISO  (SPI Data out)\n/// \\endcode\n/// With these connections, you can then use the default constructor RH_RF95().\n/// You can override the default settings for the SS pin and the interrupt in\n/// the RH_RF95 constructor if you wish to connect the slave select SS to other\n/// than the normal one for your Arduino (D10 for Diecimila, Uno etc and D53\n/// for Mega) or the interrupt request to other than pin D2 (Caution,\n/// different processors have different constraints as to the pins available\n/// for interrupts).\n///\n/// You can connect a Modtronix inAir4 or inAir9 directly to a 3.3V part such as a Teensy 3.1 like\n/// this (tested).\n/// \\code\n///                 Teensy      inAir4 inAir9\n///                 GND----------GND   (ground in)\n///                 3V3----------3.3V  (3.3V in)\n/// interrupt 0 pin D2-----------D00   (interrupt request out)\n///          SS pin D10----------CS    (CS chip select in)\n///         SCK pin D13----------CK    (SPI clock in)\n///        MOSI pin D11----------SI    (SPI Data in)\n///        MISO pin D12----------SO    (SPI Data out)\n/// \\endcode\n/// With these connections, you can then use the default constructor RH_RF95().\n/// you must also set the transmitter power with useRFO:\n/// driver.setTxPower(13, true);\n///\n/// Note that if you are using Modtronix inAir4 or inAir9,or any other module which uses the\n/// transmitter RFO pins and not the PA_BOOST pins\n/// that you must configure the power transmitter power for -1 to 14 dBm and with useRFO true. \n/// Failure to do that will result in extremely low transmit powers.\n///\n/// If you have an Arduino M0 Pro from arduino.org, \n/// you should note that you cannot use Pin 2 for the interrupt line \n/// (Pin 2 is for the NMI only). The same comments apply to Pin 4 on Arduino Zero from arduino.cc.\n/// Instead you can use any other pin (we use Pin 3) and initialise RH_RF69 like this:\n/// \\code\n/// // Slave Select is pin 10, interrupt is Pin 3\n/// RH_RF95 driver(10, 3);\n/// \\endcode\n///\n/// If you have a Rocket Scream Mini Ultra Pro with the RFM95W:\n/// - Ensure you have Arduino SAMD board support 1.6.5 or later in Arduino IDE 1.6.8 or later.\n/// - The radio SS is hardwired to pin D5 and the DIO0 interrupt to pin D2, \n/// so you need to initialise the radio like this:\n/// \\code\n/// RH_RF95 driver(5, 2);\n/// \\endcode\n/// - The name of the serial port on that board is 'SerialUSB', not 'Serial', so this may be helpful at the top of our\n///   sample sketches:\n/// \\code\n/// #define Serial SerialUSB\n/// \\endcode\n/// - You also need this in setup before radio initialisation  \n/// \\code\n/// // Ensure serial flash is not interfering with radio communication on SPI bus\n///  pinMode(4, OUTPUT);\n///  digitalWrite(4, HIGH);\n/// \\endcode\n/// - and if you have a 915MHz part, you need this after driver/manager intitalisation:\n/// \\code\n/// rf95.setFrequency(915.0);\n/// \\endcode\n/// which adds up to modifying sample sketches something like:\n/// \\code\n/// #include <SPI.h>\n/// #include <RH_RF95.h>\n/// RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W\n/// #define Serial SerialUSB\n/// \n/// void setup() \n/// {\n///   // Ensure serial flash is not interfering with radio communication on SPI bus\n///   pinMode(4, OUTPUT);\n///   digitalWrite(4, HIGH);\n/// \n///   Serial.begin(9600);\n///   while (!Serial) ; // Wait for serial port to be available\n///   if (!rf95.init())\n///     Serial.println(\"init failed\");\n///   rf95.setFrequency(915.0);\n/// }\n/// ...\n/// \\endcode\n///\n/// For Adafruit Feather M0 with RFM95, construct the driver like this:\n/// \\code\n/// RH_RF95 rf95(8, 3);\n/// \\endcode\n///\n/// It is possible to have 2 or more radios connected to one Arduino, provided\n/// each radio has its own SS and interrupt line (SCK, SDI and SDO are common\n/// to all radios)\n///\n/// Caution: on some Arduinos such as the Mega 2560, if you set the slave\n/// select pin to be other than the usual SS pin (D53 on Mega 2560), you may\n/// need to set the usual SS pin to be an output to force the Arduino into SPI\n/// master mode.\n///\n/// Caution: Power supply requirements of the RFM module may be relevant in some circumstances: \n/// RFM95/96/97/98 modules are capable of pulling 120mA+ at full power, where Arduino's 3.3V line can\n/// give 50mA. You may need to make provision for alternate power supply for\n/// the RFM module, especially if you wish to use full transmit power, and/or you have\n/// other shields demanding power. Inadequate power for the RFM is likely to cause symptoms such as:\n/// - reset's/bootups terminate with \"init failed\" messages\n/// - random termination of communication after 5-30 packets sent/received\n/// - \"fake ok\" state, where initialization passes fluently, but communication doesn't happen\n/// - shields hang Arduino boards, especially during the flashing\n///\n/// \\par Interrupts\n///\n/// The RH_RF95 driver uses interrupts to react to events in the RFM module,\n/// such as the reception of a new packet, or the completion of transmission\n/// of a packet.  The RH_RF95 driver interrupt service routine reads status from\n/// and writes data to the the RFM module via the SPI interface. It is very\n/// important therefore, that if you are using the RH_RF95 driver with another\n/// SPI based deviced, that you disable interrupts while you transfer data to\n/// and from that other device.  Use cli() to disable interrupts and sei() to\n/// reenable them.\n///\n/// \\par Memory\n///\n/// The RH_RF95 driver requires non-trivial amounts of memory. The sample\n/// programs all compile to about 8kbytes each, which will fit in the\n/// flash proram memory of most Arduinos. However, the RAM requirements are\n/// more critical. Therefore, you should be vary sparing with RAM use in\n/// programs that use the RH_RF95 driver.\n///\n/// It is often hard to accurately identify when you are hitting RAM limits on Arduino. \n/// The symptoms can include:\n/// - Mysterious crashes and restarts\n/// - Changes in behaviour when seemingly unrelated changes are made (such as adding print() statements)\n/// - Hanging\n/// - Output from Serial.print() not appearing\n///\n/// \\par Range\n///\n/// We have made some simple range tests under the following conditions:\n/// - rf95_client base station connected to a VHF discone antenna at 8m height above ground\n/// - rf95_server mobile connected to 17.3cm 1/4 wavelength antenna at 1m height, no ground plane.\n/// - Both configured for 13dBm, 434MHz, Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. Slow+long range\n/// - Minimum reported RSSI seen for successful comms was about -91\n/// - Range over flat ground through heavy trees and vegetation approx 2km.\n/// - At 20dBm (100mW) otherwise identical conditions approx 3km.\n/// - At 20dBm, along salt water flat sandy beach, 3.2km.\n///\n/// It should be noted that at this data rate, a 12 octet message takes 2 seconds to transmit.\n///\n/// At 20dBm (100mW) with Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. \n/// (Default medium range) in the conditions described above.\n/// - Range over flat ground through heavy trees and vegetation approx 2km.\n///\n/// Caution: the performance of this radio, especially with narrow bandwidths is strongly dependent on the\n/// accuracy and stability of the chip clock. HopeRF and Semtech do not appear to \n/// recommend bandwidths of less than 62.5 kHz \n/// unless you have the optional Temperature Compensated Crystal Oscillator (TCXO) installed and \n/// enabled on your radio module. See the refernece manual for more data.\n/// Also https://lowpowerlab.com/forum/rf-range-antennas-rfm69-library/lora-library-experiences-range/15/\n/// and http://www.semtech.com/images/datasheet/an120014-xo-guidance-lora-modulation.pdf\n/// \n/// \\par Transmitter Power\n///\n/// You can control the transmitter power on the RF transceiver\n/// with the RH_RF95::setTxPower() function. The argument can be any of\n/// +5 to +23 (for modules that use PA_BOOST)\n/// -1 to +14 (for modules that use RFO transmitter pin)\n/// The default is 13. Eg:\n/// \\code\n/// driver.setTxPower(10); // use PA_BOOST transmitter pin\n/// driver.setTxPower(10, true); // use PA_RFO pin transmitter pin\n/// \\endcode\n///\n/// We have made some actual power measurements against\n/// programmed power for Anarduino MiniWirelessLoRa (which has RFM96W-433Mhz installed)\n/// - MiniWirelessLoRa RFM96W-433Mhz, USB power\n/// - 30cm RG316 soldered direct to RFM96W module ANT and GND\n/// - SMA connector\n/// - 12db attenuator\n/// - SMA connector\n/// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)\n/// - Tektronix TDS220 scope to measure the Vout from power head\n/// \\code\n/// Program power           Measured Power\n///    dBm                         dBm\n///      5                           5\n///      7                           7\n///      9                           8\n///     11                          11\n///     13                          13\n///     15                          15\n///     17                          16\n///     19                          18\n///     20                          20 \n///     21                          21 \n///     22                          22 \n///     23                          23 \n/// \\endcode\n///\n/// We have also measured the actual power output from a Modtronix inAir4 http://modtronix.com/inair4.html\n/// connected to a Teensy 3.1:\n/// Teensy 3.1 this is a 3.3V part, connected directly to:\n/// Modtronix inAir4 with SMA antenna connector, connected as above:\n/// 10cm SMA-SMA cable\n/// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)\n/// - Tektronix TDS220 scope to measure the Vout from power head\n/// \\code\n/// Program power           Measured Power\n///    dBm                         dBm\n///      -1                         0\n///      1                          2\n///      3                          4\n///      5                          7\n///      7                         10\n///      9                         13\n///     11                         14.2\n///     13                         15\n///     14                         16\n/// \\endcode\n/// (Caution: we dont claim laboratory accuracy for these power measurements)\n/// You would not expect to get anywhere near these powers to air with a simple 1/4 wavelength wire antenna.\nclass RH_RF95 : public RHSPIDriver\n{\npublic:\n    /// \\brief Defines register values for a set of modem configuration registers\n    ///\n    /// Defines register values for a set of modem configuration registers\n    /// that can be passed to setModemRegisters() if none of the choices in\n    /// ModemConfigChoice suit your need setModemRegisters() writes the\n    /// register values from this structure to the appropriate registers\n    /// to set the desired spreading factor, coding rate and bandwidth\n    typedef struct\n    {\n\tuint8_t    reg_1d;   ///< Value for register RH_RF95_REG_1D_MODEM_CONFIG1\n\tuint8_t    reg_1e;   ///< Value for register RH_RF95_REG_1E_MODEM_CONFIG2\n\tuint8_t    reg_26;   ///< Value for register RH_RF95_REG_26_MODEM_CONFIG3\n    } ModemConfig;\n  \n    /// Choices for setModemConfig() for a selected subset of common\n    /// data rates. If you need another configuration,\n    /// determine the necessary settings and call setModemRegisters() with your\n    /// desired settings. It might be helpful to use the LoRa calculator mentioned in \n    /// http://www.semtech.com/images/datasheet/LoraDesignGuide_STD.pdf\n    /// These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic\n    /// definitions and not their integer equivalents: its possible that new values will be\n    /// introduced in later versions (though we will try to avoid it).\n    /// Caution: if you are using slow packet rates and long packets with RHReliableDatagram or subclasses\n    /// you may need to change the RHReliableDatagram timeout for reliable operations.\n    /// Caution: for some slow rates nad with ReliableDatagrams youi may need to increase the reply timeout \n    /// with manager.setTimeout() to\n    /// deal with the long transmission times.\n    typedef enum\n    {\n\tBw125Cr45Sf128 = 0,\t   ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range\n\tBw500Cr45Sf128,\t           ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range\n\tBw31_25Cr48Sf512,\t   ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range\n\tBw125Cr48Sf4096,           ///< Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. Slow+long range\n    } ModemConfigChoice;\n\n    /// Constructor. You can have multiple instances, but each instance must have its own\n    /// interrupt and slave select pin. After constructing, you must call init() to initialise the interface\n    /// and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient\n    /// distinct interrupt lines, one for each instance.\n    /// \\param[in] slaveSelectPin the Arduino pin number of the output to use to select the RH_RF22 before\n    /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)\n    /// \\param[in] interruptPin The interrupt Pin number that is connected to the RFM DIO0 interrupt line. \n    /// Defaults to pin 2, as required by Anarduino MinWirelessLoRa module.\n    /// Caution: You must specify an interrupt capable pin.\n    /// On many Arduino boards, there are limitations as to which pins may be used as interrupts.\n    /// On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin.\n    /// On Arduino Zero from arduino.cc, any digital pin other than 4.\n    /// On Arduino M0 Pro from arduino.org, any digital pin other than 2.\n    /// On other Arduinos pins 2 or 3. \n    /// See http://arduino.cc/en/Reference/attachInterrupt for more details.\n    /// On Chipkit Uno32, pins 38, 2, 7, 8, 35.\n    /// On other boards, any digital pin may be used.\n    /// \\param[in] spi Pointer to the SPI interface object to use. \n    ///                Defaults to the standard Arduino hardware SPI interface\n    RH_RF95(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, RHGenericSPI& spi = hardware_spi);\n  \n    /// Initialise the Driver transport hardware and software.\n    /// Make sure the Driver is properly configured before calling init().\n    /// \\return true if initialisation succeeded.\n    virtual bool    init();\n\n    /// Prints the value of all chip registers\n    /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform\n    /// For debugging purposes only.\n    /// \\return true on success\n    bool printRegisters();\n\n    /// Sets all the registered required to configure the data modem in the RF95/96/97/98, including the bandwidth, \n    /// spreading factor etc. You can use this to configure the modem with custom configurations if none of the \n    /// canned configurations in ModemConfigChoice suit you.\n    /// \\param[in] config A ModemConfig structure containing values for the modem configuration registers.\n    void           setModemRegisters(const ModemConfig* config);\n\n    /// Select one of the predefined modem configurations. If you need a modem configuration not provided \n    /// here, use setModemRegisters() with your own ModemConfig.\n    /// \\param[in] index The configuration choice.\n    /// \\return true if index is a valid choice.\n    bool        setModemConfig(ModemConfigChoice index);\n\n    /// Get the values of one of the predefined modem configurations.\n    /// \n    /// \\param[in] index The configuration choice.\n    /// \\param[in] config A ModemConfig structure that will contains values of the modem configuration values.\n    /// \\return true if index is a valid choice and config has been filled with values\n    bool        getModemConfig(ModemConfigChoice index, ModemConfig* config);\n\n    /// Tests whether a new message is available\n    /// from the Driver. \n    /// On most drivers, this will also put the Driver into RHModeRx mode until\n    /// a message is actually received by the transport, when it wil be returned to RHModeIdle.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a new, complete, error-free uncollected message is available to be retreived by recv()\n    virtual bool    available();\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    virtual bool    recv(uint8_t* buf, uint8_t* len);\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then optionally waits for Channel Activity Detection (CAD) \n    /// to show the channnel is clear (if the radio supports CAD) by calling waitCAD().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is permitted. \n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send\n    /// specify the maximum time in ms to wait. If 0 (the default) do not wait for CAD before transmitting.\n    /// \\return true if the message length was valid and it was correctly queued for transmit. Return false\n    /// if CAD was requested and the CAD timeout timed out before clear channel was detected.\n    virtual bool    send(const uint8_t* data, uint8_t len);\n\n    /// Blocks until the current message (if any) \n    /// has been transmitted\n    /// \\return true on success, false if the chip is not in transmit mode or other transmit failure\n#ifdef RH_RF95_IRQLESS\n    virtual bool   waitPacketSent();\n#endif\n\n    /// Sets the length of the preamble\n    /// in bytes. \n    /// Caution: this should be set to the same \n    /// value on all nodes in your network. Default is 8.\n    /// Sets the message preamble length in RH_RF95_REG_??_PREAMBLE_?SB\n    /// \\param[in] bytes Preamble length in bytes.  \n    void           setPreambleLength(uint16_t bytes);\n\n    /// Returns the maximum message length \n    /// available in this Driver.\n    /// \\return The maximum legal message length\n    virtual uint8_t maxMessageLength();\n\n    /// Sets the transmitter and receiver \n    /// centre frequency.\n    /// \\param[in] centre Frequency in MHz. 137.0 to 1020.0. Caution: RFM95/96/97/98 comes in several\n    /// different frequency ranges, and setting a frequency outside that range of your radio will probably not work\n    /// \\return true if the selected frquency centre is within range\n    bool        setFrequency(float centre);\n\n    /// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, \n    /// disables them.\n    void           setModeIdle();\n\n    /// If current mode is Tx or Idle, changes it to Rx. \n    /// Starts the receiver in the RF95/96/97/98.\n    void           setModeRx();\n\n    /// If current mode is Rx or Idle, changes it to Rx. F\n    /// Starts the transmitter in the RF95/96/97/98.\n    void           setModeTx();\n\n    /// Sets the transmitter power output level, and configures the transmitter pin.\n    /// Be a good neighbour and set the lowest power level you need.\n    /// Some SX1276/77/78/79 and compatible modules (such as RFM95/96/97/98) \n    /// use the PA_BOOST transmitter pin for high power output (and optionally the PA_DAC)\n    /// while some (such as the Modtronix inAir4 and inAir9) \n    /// use the RFO transmitter pin for lower power but higher efficiency.\n    /// You must set the appropriate power level and useRFO argument for your module.\n    /// Check with your module manufacturer which transmtter pin is used on your module\n    /// to ensure you are setting useRFO correctly. \n    /// Failure to do so will result in very low \n    /// transmitter power output.\n    /// Caution: legal power limits may apply in certain countries.\n    /// After init(), the power will be set to 13dBm, with useRFO false (ie PA_BOOST enabled).\n    /// \\param[in] power Transmitter power level in dBm. For RFM95/96/97/98 LORA with useRFO false, \n    /// valid values are from +5 to +23.\n    /// For Modtronix inAir4 and inAir9 with useRFO true (ie RFO pins in use), \n    /// valid values are from -1 to 14.\n    /// \\param[in] useRFO If true, enables the use of the RFO transmitter pins instead of\n    /// the PA_BOOST pin (false). Choose the correct setting for your module.\n    void           setTxPower(int8_t power, bool useRFO = false);\n\n    /// Sets the radio into low-power sleep mode.\n    /// If successful, the transport will stay in sleep mode until woken by \n    /// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc)\n    /// Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode.\n    /// \\return true if sleep mode was successfully entered.\n    virtual bool    sleep();\n\n    // Bent G Christensen (bentor@gmail.com), 08/15/2016\n    /// Use the radio's Channel Activity Detect (CAD) function to detect channel activity.\n    /// Sets the RF95 radio into CAD mode and waits until CAD detection is complete.\n    /// To be used in a listen-before-talk mechanism (Collision Avoidance)\n    /// with a reasonable time backoff algorithm.\n    /// This is called automatically by waitCAD().\n    /// \\return true if channel is in use.  \n    virtual bool    isChannelActive();\n\n    /// Enable TCXO mode\n    /// Call this immediately after init(), to force your radio to use an external \n    /// frequency source, such as a Temperature Compensated Crystal Oscillator (TCXO).\n    /// See the comments in the main documentation about the sensitivity of this radio to\n    /// clock frequency especially when using narrow bandwidths.\n    /// Leaves the module in sleep mode.\n    /// Caution, this function has not been tested by us.\n    void enableTCXO();\n\nprotected:\n    /// This is a low level function to handle the interrupts for one instance of RH_RF95.\n    /// Called automatically by isr*()\n    /// Should not need to be called by user code.\n#ifndef RH_RF95_IRQLESS\n    void           handleInterrupt();\n#endif\n\n    /// Examine the revceive buffer to determine whether the message is for this node\n    void validateRxBuf();\n\n    /// Clear our local receive buffer\n    void clearRxBuf();\n\nprivate:\n\n#ifndef RH_RF95_IRQLESS\n    /// Low level interrupt service routine for device connected to interrupt 0\n    static void         isr0();\n\n    /// Low level interrupt service routine for device connected to interrupt 1\n    static void         isr1();\n\n    /// Low level interrupt service routine for device connected to interrupt 1\n    static void         isr2();\n\n    /// Array of instances connected to interrupts 0 and 1\n    static RH_RF95*     _deviceForInterrupt[];\n\n    /// Index of next interrupt number to use in _deviceForInterrupt\n    static uint8_t      _interruptCount;\n\n    /// The configured interrupt pin connected to this instance\n    uint8_t             _interruptPin;\n\n    /// The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated)\n    /// else 0xff\n    uint8_t             _myInterruptIndex;\n\n#endif\n\n    /// Number of octets in the buffer\n    volatile uint8_t    _bufLen;\n    \n    /// The receiver/transmitter buffer\n    uint8_t             _buf[RH_RF95_MAX_PAYLOAD_LEN];\n\n    /// True when there is a valid message in the buffer\n    volatile bool       _rxBufValid;\n};\n\n/// @example rf95_client.pde\n/// @example rf95_server.pde\n/// @example rf95_reliable_datagram_client.pde\n/// @example rf95_reliable_datagram_server.pde\n\n#endif\n\n"
  },
  {
    "path": "RH_Serial.cpp",
    "content": "// RH_Serial.cpp\n//\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_Serial.cpp,v 1.13 2017/01/12 23:58:00 mikem Exp $\n\n#include <RH_Serial.h>\n#if (RH_PLATFORM == RH_PLATFORM_STM32F2)\n#else\n #include <HardwareSerial.h>\n#endif\n#include <RHCRC.h>\n\nRH_Serial::RH_Serial(HardwareSerial& serial)\n    :\n    _serial(serial),\n    _rxState(RxStateInitialising)\n{\n}\n\nHardwareSerial& RH_Serial::serial()\n{\n    return _serial;\n}\n\nbool RH_Serial::init()\n{\n    if (!RHGenericDriver::init())\n\treturn false;\n    _rxState = RxStateIdle;\n    return true;\n}\n\n// Call this often\nbool RH_Serial::available()\n{\n    while (!_rxBufValid &&_serial.available())\n\thandleRx(_serial.read());\n    return _rxBufValid;\n}\n\nvoid RH_Serial::waitAvailable()\n{\n#if (RH_PLATFORM == RH_PLATFORM_UNIX)\n    // Unix version driver in RHutil/HardwareSerial knows how to wait without polling\n    while (!available())\n\t_serial.waitAvailable();\n#else\n    RHGenericDriver::waitAvailable();\n#endif\n}\n\nbool RH_Serial::waitAvailableTimeout(uint16_t timeout)\n{\n#if (RH_PLATFORM == RH_PLATFORM_UNIX)\n    // Unix version driver in RHutil/HardwareSerial knows how to wait without polling\n    unsigned long starttime = millis();\n    while ((millis() - starttime) < timeout)\n    {\n\t_serial.waitAvailableTimeout(timeout - (millis() - starttime));\n        if (available())\n           return true;\n\tYIELD;\n    }\n    return false;\n#else\n    return RHGenericDriver::waitAvailableTimeout(timeout);\n#endif\n}\n\nvoid  RH_Serial::handleRx(uint8_t ch)\n{\n    // State machine for receiving chars\n    switch(_rxState)\n    {\n\tcase RxStateIdle:\n\t{\n\t    if (ch == DLE)\n\t\t_rxState = RxStateDLE;\n\t}\n\tbreak;\n\t    \n\tcase RxStateDLE:\n\t{\n\t    if (ch == STX)\n\t    {\n\t\tclearRxBuf();\n\t\t_rxState = RxStateData;\n\t    }\n\t    else\n\t\t_rxState = RxStateIdle;\n\t}\n\tbreak;\n\n\tcase RxStateData:\n\t{\n\t    if (ch == DLE)\n\t\t_rxState = RxStateEscape;\n\t    else\n\t\tappendRxBuf(ch);\n\t}\n\tbreak;\n\n\tcase RxStateEscape:\n\t{\n\t    if (ch == ETX)\n\t    {\n\t\t// add fcs for DLE, ETX\n\t\t_rxFcs = RHcrc_ccitt_update(_rxFcs, DLE);\n\t\t_rxFcs = RHcrc_ccitt_update(_rxFcs, ETX);\n\t\t_rxState = RxStateWaitFCS1; // End frame\n\t    }\n\t    else if (ch == DLE)\n\t    {\n\t\tappendRxBuf(ch);\n\t\t_rxState = RxStateData;\n\t    }\n\t    else\n\t\t_rxState = RxStateIdle; // Unexpected\n\t}\n\tbreak;\n\n\tcase RxStateWaitFCS1:\n\t{\n\t    _rxRecdFcs = ch << 8;\n\t    _rxState = RxStateWaitFCS2;\n\t}\n\tbreak;\n\n\tcase RxStateWaitFCS2:\n\t{\n\t    _rxRecdFcs |= ch;\n\t    _rxState = RxStateIdle;\n\t    validateRxBuf();\n\t}\n\tbreak;\n\n\tdefault: // Else some compilers complain\n\t    break; \n    }\n}\n\nvoid RH_Serial::clearRxBuf()\n{\n    _rxBufValid = false;\n    _rxFcs = 0xffff;\n    _rxBufLen = 0;\n}\n\nvoid RH_Serial::appendRxBuf(uint8_t ch)\n{\n    if (_rxBufLen < RH_SERIAL_MAX_PAYLOAD_LEN)\n    {\n\t// Normal data, save and add to FCS\n\t_rxBuf[_rxBufLen++] = ch;\n\t_rxFcs = RHcrc_ccitt_update(_rxFcs, ch);\n    }\n    // If the buffer overflows, we dont record the trailing data, and the FCS will be wrong,\n    // causing the message to be dropped when the FCS is received\n}\n\n// Check whether the latest received message is complete and uncorrupted\nvoid RH_Serial::validateRxBuf()\n{\n    if (_rxRecdFcs != _rxFcs)\n    {\n\t_rxBad++;\n\treturn;\n    }\n\n    // Extract the 4 headers\n    _rxHeaderTo    = _rxBuf[0];\n    _rxHeaderFrom  = _rxBuf[1];\n    _rxHeaderId    = _rxBuf[2];\n    _rxHeaderFlags = _rxBuf[3];\n    if (_promiscuous ||\n\t_rxHeaderTo == _thisAddress ||\n\t_rxHeaderTo == RH_BROADCAST_ADDRESS)\n    {\n\t_rxGood++;\n\t_rxBufValid = true;\n    }\n}\n\nbool RH_Serial::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n\n    if (buf && len)\n    {\n\t// Skip the 4 headers that are at the beginning of the rxBuf\n\tif (*len > _rxBufLen-RH_SERIAL_HEADER_LEN)\n\t    *len = _rxBufLen-RH_SERIAL_HEADER_LEN;\n\tmemcpy(buf, _rxBuf+RH_SERIAL_HEADER_LEN, *len);\n    }\n    clearRxBuf(); // This message accepted and cleared\n    return true;\n}\n\n// Caution: this may block\nbool RH_Serial::send(const uint8_t* data, uint8_t len)\n{\n    if (!waitCAD()) \n\treturn false;  // Check channel activity\n\n    _txFcs = 0xffff;    // Initial value\n    _serial.write(DLE); // Not in FCS\n    _serial.write(STX); // Not in FCS\n    // First the 4 headers\n    txData(_txHeaderTo);\n    txData(_txHeaderFrom);\n    txData(_txHeaderId);\n    txData(_txHeaderFlags);\n    // Now the payload\n    while (len--)\n\ttxData(*data++);\n    // End of message\n    _serial.write(DLE);\n    _txFcs = RHcrc_ccitt_update(_txFcs, DLE);\n    _serial.write(ETX);\n    _txFcs = RHcrc_ccitt_update(_txFcs, ETX);\n\n    // Now send the calculated FCS for this message\n    _serial.write((_txFcs >> 8) & 0xff);\n    _serial.write(_txFcs & 0xff);\n    return true;\n}\n\nvoid  RH_Serial::txData(uint8_t ch)\n{\n    if (ch == DLE)    // DLE stuffing required?\n\t_serial.write(DLE); // Not in FCS\n    _serial.write(ch);\n    _txFcs = RHcrc_ccitt_update(_txFcs, ch);\n}\n\nuint8_t RH_Serial::maxMessageLength()\n{\n    return RH_SERIAL_MAX_MESSAGE_LEN;\n}\n"
  },
  {
    "path": "RH_Serial.h",
    "content": "// RH_Serial.h\n//\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_Serial.h,v 1.11 2016/04/04 01:40:12 mikem Exp $\n\n// Works with any serial port. Tested with Arduino Mega connected to Serial1\n// Also works with 3DR Radio V1.3 Telemetry kit (serial at 57600baud)\n\n#ifndef RH_Serial_h\n#define RH_Serial_h\n\n#include <RHGenericDriver.h>\n\n// Special characters\n#define STX 0x02\n#define ETX 0x03\n#define DLE 0x10\n#define SYN 0x16\n\n// Maximum message length (including the headers) we are willing to support\n#define RH_SERIAL_MAX_PAYLOAD_LEN 64\n\n// The length of the headers we add.\n// The headers are inside the payload and are therefore protected by the FCS\n#define RH_SERIAL_HEADER_LEN 4\n\n// This is the maximum message length that can be supported by this library. \n// It is an arbitrary limit.\n// Can be pre-defined to a smaller size (to save SRAM) prior to including this header\n// Here we allow for 4 bytes of address and header and payload to be included in the 64 byte encryption limit.\n// the one byte payload length is not encrpyted\n#ifndef RH_SERIAL_MAX_MESSAGE_LEN\n#define RH_SERIAL_MAX_MESSAGE_LEN (RH_SERIAL_MAX_PAYLOAD_LEN - RH_SERIAL_HEADER_LEN)\n#endif\n\n#if (RH_PLATFORM == RH_PLATFORM_STM32F2)\n #define HardwareSerial USARTSerial\n#endif\n\nclass HardwareSerial;\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_Serial RH_Serial.h <RH_Serial.h>\n/// \\brief Driver to send and receive unaddressed, unreliable datagrams via a serial connection\n///\n/// This class sends and received packetized messages over a serial connection.\n/// It can be used for point-to-point or multidrop, RS232, RS488 or other serial connections as\n/// supported by your controller hardware.\n/// It can also be used to communicate via radios with serial interfaces such as:\n/// - APC220 Radio Data Module http://www.dfrobot.com/image/data/TEL0005/APC220_Datasheet.pdf\n///   http://www.dfrobot.com/image/data/TEL0005/APC220_Datasheet.pdf\n/// - 3DR Telemetry Radio https://store.3drobotics.com/products/3dr-radio\n/// - HopeRF HM-TR module http://www.hoperf.com/upload/rf_app/HM-TRS.pdf\n/// - Others\n///\n/// Compiles and runs on Linux, OSX and all the microprocessers and MCUs suported by\n/// radiohead. On Linux and OSX, a RadioHead specific version of HardwareSerial (in RHutil/HardwareSerial.*)\n/// encapsulates access to any serial port (or suported USB-serial converter)\n///\n/// The packetised messages include message encapsulation, headers, a message payload and a checksum.\n/// It therefore can support robust binary message passing with error-detection and retransmission\n/// when used with the appropriate manager. This allows reliable serial communicaitons even over very long\n/// lines where noise might otherwise affect reliablity of the communications.\n///\n/// \\par Packet Format\n///\n/// All messages sent and received by this RH_Serial Driver conform to this packet format:\n/// \\code\n/// DLE \n/// STX\n/// TO Header                (1 octet)\n/// FROM Header              (1 octet)\n/// ID Header                (1 octet)\n/// FLAGS Header             (1 octet)\n/// Message payload          (0 to 60 octets)\n/// DLE\n/// ETX\n/// Frame Check Sequence FCS CCITT CRC-16 (2 octets)\n/// \\endcode\n///\n/// If any of octets from TO header through to the end of the payload are a DLE, \n/// then they are preceded by a DLE (ie DLE stuffing).\n/// The FCS covers everything from the TO header to the ETX inclusive, but not any stuffed DLEs\n///\n/// \\par Physical connection\n///\n/// The physical connection to your serial port will depend on the type of platform you are on.\n///\n/// For example, many arduinos only support a single Serial port on pins 0 and 1, \n/// which is shared with the USB host connections. On such Arduinos, it is not possible to use both \n/// RH_Serial on the Serial port as well as using the Serial port for debugand other printing or communications.\n/// \n/// On Arduino Mega and Due, there are 4 serial ports:\n/// - Serial: this is the serial port connected to the USB interface and the programming host.\n/// - Serial1: on pins 18 (Tx) and 19 (Rx)\n/// - Serial2: on pins 16 (Tx) and 17 (Rx)\n/// - Serial3: on pins 14 (Tx) and 15 (Rx)\n///\n/// On Uno32, there are 2 serial ports:\n/// - SerialUSB: this is the port for the USB host connection.\n/// - Serial1: on pins 39 (Rx) and 40 (Tx) \n///\n/// On Maple and Flymaple, there are 4 serial ports:\n/// - SerialUSB: this is the port for the USB host connection.\n/// - Serial1: on pins 7 (Tx) and 8 (Rx)\n/// - Serial2: on pins 0 (Rx) and 1 (Tx)\n/// - Serial3: on pins 29 (Tx) and 30 (Rx)\n///\n/// On Linux and OSX there can be any number of serial ports.\n/// - On Linux, names like /dev/ttyUSB0 (for a FTDO USB-serial converter)\n/// - On OSX, names like /dev/tty.usbserial-A501YSWL (for a FTDO USB-serial converter)\n///\n/// Note that it is necessary for you to select which Serial port your RF_Serial will use and pass it to the \n/// contructor. On Linux you must pass an instance of HardwareSerial.\n///\n/// \\par Testing\n/// \n/// You can test this class and the RHReliableDatagram manager\n/// on Unix and OSX with back-to-back connected FTDI USB-serial adapters.\n/// Back-to-back means the TX of one is connected to the RX of the other and vice-versa. \n/// You should also join the ground pins.\n///\n/// Assume the 2 USB-serial adapters are connected by USB\n/// and have been assigned device names: \n/// /dev/ttyUSB0 and /dev/ttyUSB1.\n/// Build the example RHReliableDatagram client and server programs:\n/// \\code\n/// tools/simBuild examples/serial/serial_reliable_datagram_server/serial_reliable_datagram_server.pde \n/// tools/simBuild examples/serial/serial_reliable_datagram_client/serial_reliable_datagram_client.pde\n/// \\endcode\n/// In one window run the server, specifying the device to use as an environment variable:\n/// \\code\n/// RH_HARDWARESERIAL_DEVICE_NAME=/dev/ttyUSB1 ./serial_reliable_datagram_server \n/// \\endcode\n/// And in another window run the client, specifying the other device to use as an environment variable:\n/// \\code\n/// RH_HARDWARESERIAL_DEVICE_NAME=/dev/ttyUSB0 ./serial_reliable_datagram_client \n/// \\endcode\n/// You should see the 2 programs passing messages to each other.\n/// \nclass RH_Serial : public RHGenericDriver\n{\npublic:\n    /// Constructor\n    /// \\param[in] serial Reference to the HardwareSerial port which will be used by this instance.\n    /// On Unix and OSX, this is an instance of RHutil/HardwareSerial. On \n    /// Arduino and other, it is an instance of the built in HardwareSerial class.\n    RH_Serial(HardwareSerial& serial);\n\n    /// Return the HardwareSerial port in use by this instance\n    /// \\return The current HardwareSerial as a reference\n    HardwareSerial& serial();\n\n    /// Initialise the Driver transport hardware and software.\n    /// Make sure the Driver is properly configured before calling init().\n    /// \\return true if initialisation succeeded.\n    virtual bool init();\n\n    /// Tests whether a new message is available\n    /// This can be called multiple times in a timeout loop.\n    /// \\return true if a new, complete, error-free uncollected message is available to be retreived by recv()\n    virtual bool available();\n\n    /// Wait until a new message is available from the driver.\n    /// Blocks until a complete message is received as reported by available()\n    virtual void waitAvailable();\n\n    /// Wait until a new message is available from the driver or the timeout expires.\n    /// Blocks until a complete message is received as reported by available() or the timeout expires.\n    /// \\param[in] timeout The maximum time to wait in milliseconds\n    /// \\return true if a message is available as reported by available(), false on timeout.\n    virtual bool waitAvailableTimeout(uint16_t timeout);\n\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    virtual bool recv(uint8_t* buf, uint8_t* len);\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is NOT permitted. \n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send (> 0)\n    /// \\return true if the message length was valid and it was correctly queued for transmit\n    virtual bool send(const uint8_t* data, uint8_t len);\n\n    /// Returns the maximum message length \n    /// available in this Driver.\n    /// \\return The maximum legal message length\n    virtual uint8_t maxMessageLength();\n\n\nprotected:\n    /// \\brief Defines different receiver states in teh receiver state machine\n    typedef enum\n    {\n\tRxStateInitialising = 0,  ///< Before init() is called\n\tRxStateIdle,              ///< Waiting for an STX\n\tRxStateDLE,               ///< Waiting for the DLE after STX\n\tRxStateData,              ///< Receiving data\n\tRxStateEscape,            ///< Got a DLE while receiving data.\n\tRxStateWaitFCS1,          ///< Got DLE ETX, waiting for first FCS octet\n\tRxStateWaitFCS2           ///< Waiting for second FCS octet\n    } RxState;\n\n    /// HAndle a character received from the serial port. IMplements\n    /// the receiver state machine\n    void  handleRx(uint8_t ch);\n\n    /// Empties the Rx buffer\n    void  clearRxBuf();\n\n    /// Adds a charater to the Rx buffer\n    void  appendRxBuf(uint8_t ch);\n\n    /// Checks whether the Rx buffer contains valid data that is complete and uncorrupted\n    /// Check the FCS, the TO address, and extracts the headers\n    void  validateRxBuf();\n\n    /// Sends a single data octet to the serial port.\n    /// Implements DLE stuffing and keeps track of the senders FCS\n    void  txData(uint8_t ch);\n\n    /// Reference to the HardwareSerial port we will use\n    HardwareSerial& _serial;\n\n    /// The current state of the Rx state machine\n    RxState         _rxState;\n\n    /// Progressive FCS calc (CCITT CRC-16 covering all received data (but not stuffed DLEs), plus trailing DLE, ETX)\n    uint16_t        _rxFcs;\n\n    /// The received FCS at the end of the current message\n    uint16_t        _rxRecdFcs; \n\n    /// The Rx buffer\n    uint8_t         _rxBuf[RH_SERIAL_MAX_PAYLOAD_LEN];\n\n    /// Current length of data in the Rx buffer\n    uint8_t         _rxBufLen;\n\n    /// True if the data in the Rx buffer is value and uncorrupted and complete message is available for collection\n    bool            _rxBufValid;\n\n    /// FCS for transmitted data\n    uint16_t        _txFcs;\n};\n\n/// @example serial_reliable_datagram_client.pde\n/// @example serial_reliable_datagram_server.pde\n/// @example serial_gateway.pde\n\n#endif\n"
  },
  {
    "path": "RH_TCP.cpp",
    "content": "// RH_TCP.cpp\n//\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_TCP.cpp,v 1.6 2017/01/12 23:58:00 mikem Exp $\n\n#include <RadioHead.h>\n\n// This can only build on Linux and compatible systems\n#if (RH_PLATFORM == RH_PLATFORM_UNIX) \n\n#include <RH_TCP.h>\n#include <sys/types.h>\n#include <errno.h>\n#include <sys/socket.h>\n#include <netinet/in.h>\n#include <arpa/inet.h>\n#include <unistd.h>\n#include <sys/ioctl.h>\n#include <netdb.h>\n#include <string>\n\nRH_TCP::RH_TCP(const char* server)\n    : _server(server),\n      _rxBufLen(0),\n      _rxBufValid(false),\n      _socket(-1)\n{\n}\n    \nbool RH_TCP::init()\n{   \n    if (!connectToServer())\n\treturn false;\n    return sendThisAddress(_thisAddress);\n}\n    \nbool RH_TCP::connectToServer()\n{\n    struct addrinfo hints;\n    struct addrinfo *result, *rp;\n    int sfd, s;\n    struct sockaddr_storage peer_addr;\n    socklen_t peer_addr_len;\n\n    memset(&hints, 0, sizeof(struct addrinfo));\n    hints.ai_family = AF_UNSPEC;    // Allow IPv4 or IPv6\n    hints.ai_socktype = SOCK_STREAM; // Stream socket\n    hints.ai_flags = AI_PASSIVE;    // For wildcard IP address \n    hints.ai_protocol = 0;          // Any protocol \n    hints.ai_canonname = NULL;\n    hints.ai_addr = NULL;\n    hints.ai_next = NULL;\n    \n    std::string server(_server);\n    std::string port(\"4000\");\n    size_t indexOfSeparator = server.find_first_of(':');\n    if (indexOfSeparator != std::string::npos)\n    {\n\tport = server.substr(indexOfSeparator+1);\n\tserver.erase(indexOfSeparator);\n    }\n\n    s = getaddrinfo(server.c_str(), port.c_str(), &hints, &result);\n    if (s != 0) \n    {\n\tfprintf(stderr, \"RH_TCP::connect getaddrinfo failed: %s\\n\", gai_strerror(s));\n\treturn false;\n    }\n\n    // getaddrinfo() returns a list of address structures.\n    // Try each address until we successfully connect(2).\n    // If socket(2) (or connect(2)) fails, we (close the socket\n    // and) try the next address. */\n\n    for (rp = result; rp != NULL; rp = rp->ai_next) \n    {\n\t_socket = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);\n\tif (_socket == -1)\n\t    continue;\n\t\n\tif (connect(_socket, rp->ai_addr, rp->ai_addrlen) == 0)\n\t    break;                  /* Success */\n\n\tclose(_socket);\n    }\n\n    if (rp == NULL) \n    {               /* No address succeeded */\n\tfprintf(stderr, \"RH_TCP::connect could not connect to %s\\n\", _server);\n\treturn false;\n    }\n\n    freeaddrinfo(result);           /* No longer needed */\n\n    // Now make the socket non-blocking\n    int on = 1;\n    int rc = ioctl(_socket, FIONBIO, (char *)&on);\n    if (rc < 0)\n    {\n\tfprintf(stderr,\"RH_TCP::init failed to set socket non-blocking: %s\\n\", strerror(errno));\n\tclose(_socket);\n\t_socket = -1;\n\treturn false;\n    }\n    return true;\n}\n\nvoid RH_TCP::clearRxBuf()\n{\n    _rxBufValid = false;\n    _rxBufLen = 0;\n}\n\nvoid RH_TCP::checkForEvents()\n{\n    #define RH_TCP_SOCKETBUF_LEN 500\n    static uint8_t socketBuf[RH_TCP_SOCKETBUF_LEN]; // Room for several messages\n    static uint16_t socketBufLen = 0;\n\n    // Read at most the amount of space we have left in the buffer\n    ssize_t count = read(_socket, socketBuf + socketBufLen, sizeof(socketBuf) - socketBufLen);\n    if (count < 0)\n    {\n\tif (errno != EAGAIN)\n\t{\n\t    fprintf(stderr,\"RH_TCP::checkForEvents read error: %s\\n\", strerror(errno));\n\t    exit(1);\n\t}\n    }\n    else if (count == 0)\n    {\n\t// End of file\n\tfprintf(stderr,\"RH_TCP::checkForEvents unexpected end of file on read\\n\");\n\texit(1);\n    }\n    else\n    {\n\tsocketBufLen += count;\n\twhile (socketBufLen >= 5)\n\t{\n\t    RHTcpTypeMessage* message = ((RHTcpTypeMessage*)socketBuf);\n\t    uint32_t len = ntohl(message->length);\n\t    uint32_t messageLen = len + sizeof(message->length);\n\t    if (len > sizeof(socketBuf) - sizeof(message->length))\n\t    {\n\t\t// Bogus length\n\t\tfprintf(stderr, \"RH_TCP::checkForEvents read ridiculous length: %d. Corrupt message stream? Aborting\\n\", len);\n\t\texit(1);\n\t    }\n\t    if (socketBufLen >= len + sizeof(message->length))\n\t    {\n\t\t// Got at least all of this message\n\t\tif (message->type == RH_TCP_MESSAGE_TYPE_PACKET && len >= 5)\n\t\t{\n\t\t    // REVISIT: need to check if we are actually receiving?\n\t\t    // Its a new packet, extract the headers and payload\n\t\t    RHTcpPacket* packet = ((RHTcpPacket*)socketBuf);\n\t\t    _rxHeaderTo    = packet->to;\n\t\t    _rxHeaderFrom  = packet->from;\n\t\t    _rxHeaderId    = packet->id;\n\t\t    _rxHeaderFlags = packet->flags;\n\t\t    uint32_t payloadLen = len - 5;\n\t\t    if (payloadLen <= sizeof(_rxBuf))\n\t\t    {\n\t\t\t// Enough room in our receiver buffer\n\t\t\tmemcpy(_rxBuf, packet->payload, payloadLen);\n\t\t\t_rxBufLen = payloadLen;\n\t\t\t_rxBufFull = true;\n\t\t    }\n\t\t}\n\t\t// check for other message types here\n\t\t// Now remove the used message by copying the trailing bytes (maybe start of a new message?)\n\t\t// to the top of the buffer\n\t\tmemcpy(socketBuf, socketBuf + messageLen, sizeof(socketBuf) - messageLen);\n\t\tsocketBufLen -= messageLen;\n\t    }\n\t}\n    }\n}\n\nvoid RH_TCP::validateRxBuf()\n{\n    // The headers have already been extracted\n    if (_promiscuous ||\n\t_rxHeaderTo == _thisAddress ||\n\t_rxHeaderTo == RH_BROADCAST_ADDRESS)\n    {\n\t_rxGood++;\n\t_rxBufValid = true;\n    }\n}\n\nbool RH_TCP::available()\n{\n    if (_socket < 0)\n\treturn false;\n    checkForEvents();\n    if (_rxBufFull)\n    {\n\tvalidateRxBuf();\n\t_rxBufFull= false;\n    }\n    return _rxBufValid;\n}\n\n// Block until something is available\nvoid RH_TCP::waitAvailable()\n{\n    waitAvailableTimeout(0); // 0 = Wait forever\n}\n\n// Block until something is available or timeout expires\nbool RH_TCP::waitAvailableTimeout(uint16_t timeout)\n{\n    int            max_fd;\n    fd_set         input;\n    int            result;\n\n    FD_ZERO(&input);\n    FD_SET(_socket, &input);\n    max_fd = _socket + 1;\n\n    if (timeout)\n    {\n\tstruct timeval timer;\n\t// Timeout is in milliseconds\n\ttimer.tv_sec  = timeout / 1000;\n\ttimer.tv_usec = (timeout % 1000) * 1000;\n\tresult = select(max_fd, &input, NULL, NULL, &timer);\n    }\n    else\n    {\n\tresult = select(max_fd, &input, NULL, NULL, NULL);\n    }\n    if (result < 0)\n\tfprintf(stderr, \"RH_TCP::waitAvailableTimeout: select failed %s\\n\", strerror(errno));\n    return result > 0;\n}\n\nbool RH_TCP::recv(uint8_t* buf, uint8_t* len)\n{\n    if (!available())\n\treturn false;\n\n    if (buf && len)\n    {\n\tif (*len > _rxBufLen)\n\t    *len = _rxBufLen;\n\tmemcpy(buf, _rxBuf, *len);\n    }\n    clearRxBuf();\n    return true;\n}\n\nbool RH_TCP::send(const uint8_t* data, uint8_t len)\n{\n    if (!waitCAD()) \n\treturn false;  // Check channel activity (prob not possible for this driver?)\n\n    bool ret = sendPacket(data, len);\n    delay(10); // Wait for transmit to succeed. REVISIT: depends on length and speed\n    return ret;\n}\n\nuint8_t RH_TCP::maxMessageLength()\n{\n    return RH_TCP_MAX_MESSAGE_LEN;\n}\n\nvoid RH_TCP::setThisAddress(uint8_t address)\n{\n    RHGenericDriver::setThisAddress(address);\n    sendThisAddress(_thisAddress);\n}\n\nbool RH_TCP::sendThisAddress(uint8_t thisAddress)\n{\n    if (_socket < 0)\n\treturn false;\n    RHTcpThisAddress m;\n    m.length = htonl(2);\n    m.type = RH_TCP_MESSAGE_TYPE_THISADDRESS;\n    m.thisAddress = thisAddress;\n    ssize_t sent = write(_socket, &m, sizeof(m));\n    return sent > 0;\n}\n\nbool RH_TCP::sendPacket(const uint8_t* data, uint8_t len)\n{\n    if (_socket < 0)\n\treturn false;\n    RHTcpPacket m;\n    m.length = htonl(len + 4);\n    m.type  = RH_TCP_MESSAGE_TYPE_PACKET;\n    m.to    = _txHeaderTo;\n    m.from  = _txHeaderFrom;\n    m.id    = _txHeaderId;\n    m.flags = _txHeaderFlags;\n    memcpy(m.payload, data, len);\n    ssize_t sent = write(_socket, &m, len + 8);\n    return sent > 0;\n}\n\n#endif\n"
  },
  {
    "path": "RH_TCP.h",
    "content": "// RH_TCP.h\n// Author: Mike McCauley (mikem@aierspayce.com)\n// Copyright (C) 2014 Mike McCauley\n// $Id: RH_TCP.h,v 1.4 2015/08/13 02:45:47 mikem Exp $\n#ifndef RH_TCP_h\n#define RH_TCP_h\n\n#include <RHGenericDriver.h>\n#include <RHTcpProtocol.h>\n\n/////////////////////////////////////////////////////////////////////\n/// \\class RH_TCP RH_TCP.h <RH_TCP.h>\n/// \\brief Driver to send and receive unaddressed, unreliable datagrams via sockets on a Linux simulator\n///\n/// \\par Overview\n///\n/// This class is intended to support the testing of RadioHead manager classes and simulated sketches \n/// on a Linux host.\n/// RH_TCP class sends messages to and from other simulator sketches via sockets to a 'Luminiferous Ether' \n/// simulator server (provided).\n/// Multiple instances of simulated clients and servers can run on a single Linux server,\n/// passing messages to each other via the etherSimulator.pl server.\n///\n/// Simple RadioHead sketches can be compiled and run on Linux using a build script and some support files.\n///\n/// \\par Running simulated sketches\n///\n/// \\code\n/// cd whatever/RadioHead \n/// # build the client for Linux:\n/// tools/simBuild examples/simulator/simulator_reliable_datagram_client/simulator_reliable_datagram_client.pde\n/// # build the server for Linux:\n/// tools/simBuild examples/simulator/simulator_reliable_datagram_server/simulator_reliable_datagram_server.pde\n/// # in one window, run the simulator server:\n/// tools/etherSimulator.pl\n/// # in another window, run the server\n/// ./simulator_reliable_datagram_server \n/// # in another window, run the client:\n/// ./simulator_reliable_datagram_client\n/// # see output:\n/// Sending to simulator_reliable_datagram_server\n/// got reply from : 0x02: And hello back to you\n/// Sending to simulator_reliable_datagram_server\n/// got reply from : 0x02: And hello back to you\n/// Sending to simulator_reliable_datagram_server\n/// got reply from : 0x02: And hello back to you\n/// ...\n/// \\endcode\n///\n/// You can change the listen port and the simulated baud rate with \n/// command line arguments passed to etherSimulator.pl\n///\n/// \\par Implementation\n///\n/// etherServer.pl is a conventional server written in Perl.\n/// listens on a TCP socket (defaults to port 4000) for connections from sketch simulators\n/// using RH_TCP as theur driver.\n/// The simulated sketches send messages out to the 'ether' over the TCP connection to the etherServer.\n/// etherServer manages the delivery of each message to any other RH_TCP sketches that are running.\n///\n/// \\par Prerequisites\n///\n/// g++ compiler installed and in your $PATH\n/// Perl\n/// Perl POE library\n///\nclass RH_TCP : public RHGenericDriver\n{\npublic:\n    /// Constructor\n    /// \\param[in] server Name and optionally the port number of the ether simulator server to contact.\n    /// Format is \"name[:port]\", where name can be any valid host name or address (IPV4 or IPV6).\n    /// The trailing :port is optional, and port can be any valid \n    /// port name or port number.\n    RH_TCP(const char* server = \"localhost:4000\");\n\n    /// Initialise the Driver transport hardware and software.\n    /// Make sure the Driver is properly configured before calling init().\n    /// \\return true if initialisation succeeded.\n    virtual bool init();\n\n    /// Tests whether a new message is available\n    /// from the Driver. \n    /// On most drivers, this will also put the Driver into RHModeRx mode until\n    /// a message is actually received by the transport, when it will be returned to RHModeIdle.\n    /// This can be called multiple times in a timeout loop\n    /// \\return true if a new, complete, error-free uncollected message is available to be retreived by recv()\n    virtual bool available();\n\n    /// Wait until a new message is available from the driver.\n    /// Blocks until a complete message is received as reported by available()\n    virtual void waitAvailable();\n\n    /// Wait until a new message is available from the driver\n    /// or the timeout expires\n    /// Blocks until a complete message is received as reported by available()\n    /// \\param[in] timeout The maximum time to wait in milliseconds\n    /// \\return true if a message is available as reported by available()\n    virtual bool waitAvailableTimeout(uint16_t timeout);\n\n    /// Turns the receiver on if it not already on.\n    /// If there is a valid message available, copy it to buf and return true\n    /// else return false.\n    /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).\n    /// You should be sure to call this function frequently enough to not miss any messages\n    /// It is recommended that you call it in your main loop.\n    /// \\param[in] buf Location to copy the received message\n    /// \\param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.\n    /// \\return true if a valid message was copied to buf\n    virtual bool recv(uint8_t* buf, uint8_t* len);\n\n    /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().\n    /// Then loads a message into the transmitter and starts the transmitter. Note that a message length\n    /// of 0 is NOT permitted. If the message is too long for the underlying radio technology, send() will\n    /// return false and will not send the message.\n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send (> 0)\n    /// \\return true if the message length was valid and it was correctly queued for transmit\n    virtual bool send(const uint8_t* data, uint8_t len);\n\n    /// Returns the maximum message length \n    /// available in this Driver.\n    /// \\return The maximum legal message length\n    virtual uint8_t maxMessageLength();\n\n    /// Sets the address of this node. Defaults to 0xFF. Subclasses or the user may want to change this.\n    /// This will be used to test the adddress in incoming messages. In non-promiscuous mode,\n    /// only messages with a TO header the same as thisAddress or the broadcast addess (0xFF) will be accepted.\n    /// In promiscuous mode, all messages will be accepted regardless of the TO header.\n    /// In a conventional multinode system, all nodes will have a unique address \n    /// (which you could store in EEPROM).\n    /// You would normally set the header FROM address to be the same as thisAddress (though you dont have to, \n    /// allowing the possibilty of address spoofing).\n    /// \\param[in] address The address of this node.\n    void setThisAddress(uint8_t address);\n\nprotected:\n\nprivate:\n    /// Connect to the address and port specified by the server constructor argument.\n    /// Prepares the socket for use.\n    bool connectToServer();\n\n    /// Check for new messages from the ether simulator server\n    void checkForEvents();\n\n    /// Clear the receive buffer\n    void clearRxBuf();\n\n    /// Sends thisAddress to the ether simulator server\n    /// in a RHTcpThisAddress message.\n    /// \\param[in] thisAddress The node address of this node\n    /// \\return true if successful\n    bool sendThisAddress(uint8_t thisAddress);\n\n    /// Sends a message to the ether simulator server for delivery to\n    /// other nodes\n    /// \\param[in] data Array of data to be sent\n    /// \\param[in] len Number of bytes of data to send (> 0)\n    /// \\return true if successful\n    bool sendPacket(const uint8_t* data, uint8_t len);\n\n    /// Address and port of the server to which messages are sent\n    /// and received using the protocol RHTcpPRotocol\n    const char* _server;\n\n    /// The TCP socket used to communicate with the message server\n    int         _socket;\n\n    /// Buffer to receive RHTcpProtocol messages\n    uint8_t     _rxBuf[RH_TCP_MAX_PAYLOAD_LEN + 5];\n    uint16_t    _rxBufLen;\n    bool        _rxBufValid;\n\n    /// Check whether the latest received message is complete and uncorrupted\n    void            validateRxBuf();\n\n    // Used in the interrupt handlers\n    /// Buf is filled but not validated\n    volatile bool   _rxBufFull;\n\n};\n\n/// @example simulator_reliable_datagram_client.pde\n/// @example simulator_reliable_datagram_server.pde\n\n#endif\n"
  },
  {
    "path": "RHutil/HardwareSerial.cpp",
    "content": "// HardwareSerial.cpp\n//\n// Copyright (C) 2015 Mike McCauley\n// $Id: HardwareSerial.cpp,v 1.3 2015/08/13 02:45:47 mikem Exp mikem $\n\n#include <RadioHead.h>\n#if (RH_PLATFORM == RH_PLATFORM_UNIX)\n\n#include <HardwareSerial.h>\n\n#include <string.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <termios.h>\n#include <sys/ioctl.h>\n#include <sys/select.h>\n\nHardwareSerial::HardwareSerial(const char* deviceName)\n    : _deviceName(deviceName),\n      _device(-1)\n{\n    // Override device name from environment\n    char* e = getenv(\"RH_HARDWARESERIAL_DEVICE_NAME\");\n    if (e)\n\t_deviceName = e;\n}\n\nvoid HardwareSerial::begin(int baud)\n{\n    if (openDevice())\n\tsetBaud(baud);\n}\n\nvoid HardwareSerial::end()\n{\n    closeDevice();\n}\n\nvoid HardwareSerial::flush()\n{\n    tcdrain(_device);\n}\n\nint HardwareSerial::peek(void)\n{\n    printf(\"HardwareSerial::peek not implemented\\n\");\n    return 0;\n}\n\nint HardwareSerial::available()\n{\n    int bytes;\n\n    if (ioctl(_device, FIONREAD, &bytes) != 0)\n    {\n\tfprintf(stderr, \"HardwareSerial::available ioctl failed: %s\\n\", strerror(errno));\n\treturn 0;\n    }\n    return bytes;\n}\n\nint HardwareSerial::read()\n{\n    uint8_t data;\n    ssize_t result = ::read(_device, &data, 1);\n    if (result != 1)\n    {\n\tfprintf(stderr, \"HardwareSerial::read read failed: %s\\n\", strerror(errno));\n\treturn 0;\n    }\n//    printf(\"got: %02x\\n\", data);\n    return data;\n}\n\nsize_t HardwareSerial::write(uint8_t ch)\n{\n    size_t result = ::write(_device, &ch, 1);\n    if (result != 1)\n    {\n\tfprintf(stderr, \"HardwareSerial::write failed: %s\\n\", strerror(errno));\n\treturn 0;\n    }\n//    printf(\"sent: %02x\\n\", ch);\n    return 1; // OK\n}\n\nbool HardwareSerial::openDevice()\n{\n    if (_device == -1)\n\tcloseDevice();\n    _device = open(_deviceName, O_RDWR | O_NOCTTY | O_NDELAY);\n    if (_device == -1)\n    {\n\t// Could not open the port.\n\tfprintf(stderr, \"HardwareSerial::openDevice could not open %s: %s\\n\", _deviceName, strerror(errno));\n\treturn false;\n    }\n\n    // Device opened\n    fcntl(_device, F_SETFL, 0);\n    return true;\n}\n\nbool HardwareSerial::closeDevice()\n{\n    if (_device != -1)\n\tclose(_device);\n    _device = -1;\n    return true;\n}\n\nbool HardwareSerial::setBaud(int baud)\n{\n    speed_t speed;\n\n    // This is kind of ugly, but its prob better than a case\n    if (baud == 50)\n\tspeed = B50;\n    else if (baud == 75)\n\tspeed = B75;\n    else if (baud == 110)\n\tspeed = B110;\n    else if (baud == 134)\n\tspeed = B134;\n    else if (baud == 150)\n\tspeed = B150;\n    else if (baud == 200)\n\tspeed = B200;\n    else if (baud == 300)\n\tspeed = B300;\n    else if (baud == 600)\n\tspeed = B600;\n    else if (baud == 1200)\n\tspeed = B1200;\n    else if (baud == 1800)\n\tspeed = B1800;\n    else if (baud == 2400)\n\tspeed = B2400;\n    else if (baud == 4800)\n\tspeed = B4800;\n    else if (baud == 9600)\n\tspeed = B9600;\n    else if (baud == 19200)\n\tspeed = B19200;\n    else if (baud == 38400)\n\tspeed = B38400;\n    else if (baud == 57600)\n\tspeed = B57600;\n#ifdef B76800\n    else if (baud == 76800)  // Not available on Linux\n\tspeed = B76800;\n#endif\n    else if (baud == 115200)\n\tspeed = B115200;\n    else if (baud == 230400)\n\tspeed = B230400;\n#ifdef B460800\n    else if (baud == 460800) // Not available on OSX\n\tspeed = B460800;\n#endif\n#ifdef B921600\n    else if (baud == 921600) // Not available on OSX\n\tspeed = B921600;\n#endif\n    else \n    {\n\tfprintf(stderr, \"HardwareSerial::setBaud: unsupported baud rate %d\\n\", baud);\n\treturn false;\n    }\n\n    struct termios options;\n    // Get current options\n    if (tcgetattr(_device, &options) != 0)\n    {\n\tfprintf(stderr, \"HardwareSerial::setBaud: could not tcgetattr %s\\n\", strerror(errno));\n\treturn false;\n    }\n\n    // Set new speed options\n    cfsetispeed(&options, speed);\n    cfsetospeed(&options, speed);\n    // Enable the receiver and set local mode...\n    options.c_cflag |= (CLOCAL | CREAD);\n\n    // Force mode to 8,N,1\n    // to be compatible with Arduino HardwareSerial\n    // Should this be configurable? Prob not, must have 8 bits, dont need parity.\n    options.c_cflag &= ~(PARENB | CSTOPB | CSIZE);\n    options.c_cflag |= CS8;\n   \n    // Disable flow control and input character conversions\n    options.c_iflag &= ~(IXON | IXOFF | IXANY | ICRNL | INLCR);\n\n    // Raw input:\n    options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);\n\n    // Raw output\n    options.c_oflag &= ~(OPOST | OCRNL | ONLCR);\n\n    // Set the options in the port\n    if (tcsetattr(_device, TCSANOW, &options) != 0)\n    {\n\tfprintf(stderr, \"HardwareSerial::setBaud: could not tcsetattr %s\\n\", strerror(errno));\n\treturn false;\n    }\n\n    _baud = baud;\n    return true;\n}\n\n// Block until something is available\nvoid HardwareSerial::waitAvailable()\n{\n    waitAvailableTimeout(0); // 0 = Wait forever\n}\n\n// Block until something is available or timeout expires\nbool HardwareSerial::waitAvailableTimeout(uint16_t timeout)\n{\n    int            max_fd;\n    fd_set         input;\n    int            result;\n\n    FD_ZERO(&input);\n    FD_SET(_device, &input);\n    max_fd = _device + 1;\n\n    if (timeout)\n    {\n\tstruct timeval timer;\n\t// Timeout is in milliseconds\n\ttimer.tv_sec  = timeout / 1000;\n\ttimer.tv_usec = (timeout % 1000) * 1000;\n\tresult = select(max_fd, &input, NULL, NULL, &timer);\n    }\n    else\n    {\n\tresult = select(max_fd, &input, NULL, NULL, NULL);\n    }\n    if (result < 0)\n\tfprintf(stderr, \"HardwareSerial::waitAvailableTimeout: select failed %s\\n\", strerror(errno));\n    return result > 0;\n}\n\n#endif\n"
  },
  {
    "path": "RHutil/HardwareSerial.h",
    "content": "// HardwareSerial.h\n// Author: Mike McCauley (mikem@airspayce.com)\n// Copyright (C) 2015 Mike McCauley\n// $Id: HardwareSerial.h,v 1.3 2015/08/13 02:45:47 mikem Exp mikem $\n#ifndef HardwareSerial_h\n#define HardwareSerial_h\n\n#include <stdio.h>\n\n/////////////////////////////////////////////////////////////////////\n/// \\class HardwareSerial HardwareSerial.h <RHutil/HardwareSerial.h>\n/// \\brief Encapsulates a Posix compliant serial port as a HarwareSerial\n///\n/// This class provides access to a serial port on Unix and OSX.\n/// It is equivalent to HardwareSerial in Arduino, and can be used by RH_Serial\n/// We implement just enough to provide the services RadioHead needs.\n/// Additional methods not present on Arduino are also provided for waiting for characters.\n///\n/// The device port is configured for 8 bits, no parity, 1 stop bit and full raw transparency, so it can be used\n/// to send and receive any 8 bit character. A limited range of baud rates is supported.\n///\n/// \\par Device Names\n///\n/// Device naming conventions vary from OS to OS. ON linux, an FTDI serial port may have a name like\n/// /dev/ttyUSB0. On OSX, it might be something like /dev/tty.usbserial-A501YSWL\n/// \\par errors\n///\n/// A number of these methods print error messages to stderr in the event of an IO error.\nclass HardwareSerial\n{\npublic:\n    /// Constructor\n    // \\param [in] deviceName Name of the derial port device to connect to\n    HardwareSerial(const char* deviceName);\n\n    /// Open and configure the port.\n    /// The named port is opened, and the given baud rate is set.\n    /// The port is configure for raw input and output and 8,N,1 protocol\n    /// with no flow control.\n    /// This must be called before any other operations are attempted.\n    /// IO failures and unsupported baud rates will result in an error message on stderr.\n    /// \\param[in] baud The desired baud rate. The only rates supported are: 50, 75, 110, 134, 150\n    /// 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400. On some platform\n    /// such as Linux you may also use: 460800, 921600. \n    void begin(int baud);\n\n    /// Close the port.\n    /// If begin() has previously been called successfully, the device port will be closed.\n    /// It may be reopened again with another call to begin().\n    void end();\n\n    /// Flush remaining data.\n    /// Blocks until any data yet to be transmtted is sent.\n    void flush();\n\n    /// Peek at the nex available character without consuming it.\n    /// CAUTION: Not implemented.\n    int peek(void);\n\n    /// Returns the number of bytes immediately available to be read from the\n    /// device.\n    /// \\return 0 if none available else the number of characters available for immediate reading\n    int available();\n\n    /// Read and return the next available character.\n    /// If no character is available prints a message to stderr and returns 0;\n    /// \\return The next available character\n    int read();\n\n    /// Transmit a single character oin the serial port.\n    /// Returns immediately.\n    /// IO errors are repored by printing aa message to stderr.\n    /// \\param[in] ch The character to send. Anything in the range 0x00 to 0xff is permitted\n    /// \\return 1 if successful else 0\n    size_t write(uint8_t ch);\n\n    // These are not usually in HardwareSerial but we \n    // need them in a Unix environment\n\n    /// Wait until a character is available from the port.\n    void waitAvailable();\n\n    /// Wait until a a character is available from the port.\n    /// or the timeout expires\n    /// \\param[in] timeout The maximum time to wait in milliseconds. 0 means wait forever.\n    /// \\return true if a message is available as reported by available()\n    bool waitAvailableTimeout(uint16_t timeout);\n\nprotected:\n    bool openDevice();\n    bool closeDevice();\n    bool setBaud(int baud);\n\nprivate:\n    const char* _deviceName;\n    int         _device; // file desriptor\n    int         _baud;\n};\n\n#endif\n"
  },
  {
    "path": "RHutil/RasPi.cpp",
    "content": "// RasPi.cpp\n//\n// Routines for implementing RadioHead on Raspberry Pi\n// using BCM2835 library for GPIO\n//\n// Contributed by Mike Poublon and used with permission\n\n\n#include <RadioHead.h>\n\n#if (RH_PLATFORM == RH_PLATFORM_RASPI)\n#include <sys/time.h>\n#include <time.h>\n#include \"RasPi.h\"\n\n//Initialize the values for sanity\ntimeval RHStartTime;\n\nvoid SPIClass::begin()\n{\n  //Set SPI Defaults\n  uint16_t divider = BCM2835_SPI_CLOCK_DIVIDER_256;\n  uint8_t bitorder = BCM2835_SPI_BIT_ORDER_MSBFIRST;\n  uint8_t datamode = BCM2835_SPI_MODE0;\n\n  begin(divider, bitorder, datamode);\n}\n\nvoid SPIClass::begin(uint16_t divider, uint8_t bitOrder, uint8_t dataMode)\n{\n  setClockDivider(divider);\n  setBitOrder(bitOrder);\n  setDataMode(dataMode);\n\tbcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE); // RH Library code control CS line\n\n  bcm2835_spi_begin();\n\n  //bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE); // RH Library code control CS line\n\n  //Initialize a timestamp for millis calculation\n  gettimeofday(&RHStartTime, NULL);\n}\n\nvoid SPIClass::end()\n{\n  //End the SPI\n  bcm2835_spi_end();\n}\n\nvoid SPIClass::setBitOrder(uint8_t bitOrder)\n{\n  //Set the SPI bit Order\n  bcm2835_spi_setBitOrder(bitOrder);\n}\n\nvoid SPIClass::setDataMode(uint8_t mode)\n{\n  //Set SPI data mode\n  bcm2835_spi_setDataMode(mode);\n}\n\nvoid SPIClass::setClockDivider(uint16_t rate)\n{\n  //Set SPI clock divider\n  bcm2835_spi_setClockDivider(rate);\n}\n\nbyte SPIClass::transfer(byte _data)\n{\n  //Set which CS pin to use for next transfers\n  bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE);\n  //Transfer 1 byte\n  \n  //printf(\"SPIClass::transfer(%02X)\", _data);\n  byte data;\n  data = bcm2835_spi_transfer((uint8_t)_data);\n  //printf(\"=%02X\\n\", data);\n  return data;\n}\n\nvoid pinMode(unsigned char pin, unsigned char mode)\n{\n  if (pin == NOT_A_PIN)\n    return;\n  \n  if (mode == OUTPUT)\n  {\n    bcm2835_gpio_fsel(pin,BCM2835_GPIO_FSEL_OUTP);\n  }\n  else\n  {\n    bcm2835_gpio_fsel(pin,BCM2835_GPIO_FSEL_INPT);\n  }\n}\n\nvoid digitalWrite(unsigned char pin, unsigned char value)\n{\n  if (pin == NOT_A_PIN)\n    return;\n\n  bcm2835_gpio_write(pin,value);\n}\n\nunsigned char digitalRead(unsigned char pin) {\n  if (pin == NOT_A_PIN)\n    return 0;\n\n  return bcm2835_gpio_lev(pin);\n}\n\nunsigned long millis()\n{\n  //Declare a variable to store current time\n  struct timeval RHCurrentTime;\n  //Get current time\n  gettimeofday(&RHCurrentTime,NULL);\n  //Calculate the difference between our start time and the end time\n  unsigned long difference = ((RHCurrentTime.tv_sec - RHStartTime.tv_sec) * 1000);\n  difference += ((RHCurrentTime.tv_usec - RHStartTime.tv_usec)/1000);\n  //Return the calculated value\n  return difference;\n}\n\nvoid delay (unsigned long ms)\n{\n  //Implement Delay function\n  struct timespec ts;\n  ts.tv_sec=0;\n  ts.tv_nsec=(ms * 1000);\n  nanosleep(&ts,&ts);\n}\n\nlong random(long min, long max)\n{\n  long diff = max - min;\n  long ret = diff * rand() + min;\n  return ret;\n}\n\n// Dump a buffer trying to display ASCII or HEX\n// depending on contents\nvoid printbuffer(uint8_t buff[], int len)\n{\n  int i;\n  bool ascii = true;\n  \n  // Check for only printable characters\n  for (i = 0; i< len; i++) {\n    if ( buff[i]<32 || buff[i]>127) {\n      if (buff[i]!=0 || i!=len-1) {\n        ascii = false; \n        break;\n      }\n    }\n  }\n\n  // now do real display according to buffer type\n  // note each char one by one because we're not sure \n  // string will have \\0 on the end\n  for (int i = 0; i< len; i++) {\n    if (ascii) {\n      printf(\"%c\", buff[i]);\n    } else {\n      printf(\" %02X\", buff[i]);\n    }\n  }\n}\n\nvoid SerialSimulator::begin(int baud)\n{\n  //No implementation neccesary - Serial emulation on Linux = standard console\n  //\n  //Initialize a timestamp for millis calculation - we do this here as well in case SPI\n  //isn't used for some reason\n  gettimeofday(&RHStartTime, NULL);\n}\n\nsize_t SerialSimulator::println(const char* s)\n{\n  print(s);\n  printf(\"\\n\");\n}\n\nsize_t SerialSimulator::print(const char* s)\n{\n  printf(s);\n}\n\nsize_t SerialSimulator::print(unsigned int n, int base)\n{\n  if (base == DEC)\n    printf(\"%d\", n);\n  else if (base == HEX)\n    printf(\"%02x\", n);\n  else if (base == OCT)\n    printf(\"%o\", n);\n  // TODO: BIN\n}\n\nsize_t SerialSimulator::print(char ch)\n{\n  printf(\"%c\", ch);\n}\n\nsize_t SerialSimulator::println(char ch)\n{\n  printf(\"%c\\n\", ch);\n}\n\nsize_t SerialSimulator::print(unsigned char ch, int base)\n{\n  return print((unsigned int)ch, base);\n}\n\nsize_t SerialSimulator::println(unsigned char ch, int base)\n{\n  print((unsigned int)ch, base);\n  printf(\"\\n\");\n}\n\n#endif\n"
  },
  {
    "path": "RHutil/RasPi.h",
    "content": "// RasPi.h\n//\n// Routines for implementing RadioHead on Raspberry Pi\n// using BCM2835 library for GPIO\n// Contributed by Mike Poublon and used with permission\n\n#ifndef RASPI_h\n#define RASPI_h\n\n#include <bcm2835.h>\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <stdint.h>\n\ntypedef unsigned char byte;\n\n#ifndef NULL\n  #define NULL 0\n#endif\n\n#ifndef OUTPUT\n  #define OUTPUT BCM2835_GPIO_FSEL_OUTP\n#endif\n\n#ifndef INPUT\n  #define INPUT BCM2835_GPIO_FSEL_INPT\n#endif\n\n#ifndef NOT_A_PIN\n  #define NOT_A_PIN 0xFF\n#endif\n\n// No memcpy_P Raspberry PI\n#ifndef memcpy_P\n#define memcpy_P memcpy \n#endif\n\nclass SPIClass\n{\n  public:\n    static byte transfer(byte _data);\n    // SPI Configuration methods\n    static void begin(); // Default\n    static void begin(uint16_t, uint8_t, uint8_t);\n    static void end();\n    static void setBitOrder(uint8_t);\n    static void setDataMode(uint8_t);\n    static void setClockDivider(uint16_t);\n};\n\nextern SPIClass SPI;\n\nclass SerialSimulator\n{\n  public:\n    #define DEC 10\n    #define HEX 16\n    #define OCT 8\n    #define BIN 2\n\n    // TODO: move these from being inlined\n    static void begin(int baud);\n    static size_t println(const char* s);\n    static size_t print(const char* s);\n    static size_t print(unsigned int n, int base = DEC);\n    static size_t print(char ch);\n    static size_t println(char ch);\n    static size_t print(unsigned char ch, int base = DEC);\n    static size_t println(unsigned char ch, int base = DEC);\n};\n\nextern SerialSimulator Serial;\n\nvoid RasPiSetup();\n\nvoid pinMode(unsigned char pin, unsigned char mode);\n\nvoid digitalWrite(unsigned char pin, unsigned char value);\n\nunsigned char digitalRead(unsigned char pin) ;\n\nunsigned long millis();\n\nvoid delay (unsigned long delay);\n\nlong random(long min, long max);\n\nvoid printbuffer(uint8_t buff[], int len);\n\n#endif\n"
  },
  {
    "path": "RHutil/atomic.h",
    "content": "/*\n* This is port of Dean Camera's ATOMIC_BLOCK macros for AVR to ARM Cortex M3 \n* v1.0\n* Mark Pendrith, Nov 27, 2012.\n*\n* From Mark:\n* >When I ported the macros I emailed Dean to ask what attribution would be\n* >appropriate, and here is his response:\n* >\n* >>Mark,\n* >>I think it's great that you've ported the macros; consider them\n* >>public domain, to do with whatever you wish. I hope you find them >useful .\n* >>\n* >>Cheers!\n* >>- Dean \n*/\n\n#ifdef __arm__ \n#ifndef _CORTEX_M3_ATOMIC_H_\n#define _CORTEX_M3_ATOMIC_H_\n\nstatic __inline__ uint32_t __get_primask(void) \\\n{ uint32_t primask = 0; \\\n  __asm__ volatile (\"MRS %[result], PRIMASK\\n\\t\":[result]\"=r\"(primask)::); \\\n  return primask; } // returns 0 if interrupts enabled, 1 if disabled\n\nstatic __inline__ void __set_primask(uint32_t setval) \\\n{ __asm__ volatile (\"MSR PRIMASK, %[value]\\n\\t\"\"dmb\\n\\t\"\"dsb\\n\\t\"\"isb\\n\\t\"::[value]\"r\"(setval):);\n  __asm__ volatile (\"\" ::: \"memory\");}\n\nstatic __inline__ uint32_t __iSeiRetVal(void) \\\n{ __asm__ volatile (\"CPSIE i\\n\\t\"\"dmb\\n\\t\"\"dsb\\n\\t\"\"isb\\n\\t\"); \\\n  __asm__ volatile (\"\" ::: \"memory\"); return 1; }   \n\nstatic __inline__ uint32_t __iCliRetVal(void) \\\n{ __asm__ volatile (\"CPSID i\\n\\t\"\"dmb\\n\\t\"\"dsb\\n\\t\"\"isb\\n\\t\"); \\\n  __asm__ volatile (\"\" ::: \"memory\"); return 1; }   \n\nstatic __inline__ void    __iSeiParam(const uint32_t *__s) \\\n{ __asm__ volatile (\"CPSIE i\\n\\t\"\"dmb\\n\\t\"\"dsb\\n\\t\"\"isb\\n\\t\"); \\\n  __asm__ volatile (\"\" ::: \"memory\"); (void)__s; }\n\nstatic __inline__ void    __iCliParam(const uint32_t *__s) \\\n{ __asm__ volatile (\"CPSID i\\n\\t\"\"dmb\\n\\t\"\"dsb\\n\\t\"\"isb\\n\\t\"); \\\n  __asm__ volatile (\"\" ::: \"memory\"); (void)__s; }\n\nstatic __inline__ void    __iRestore(const  uint32_t *__s) \\\n{ __set_primask(*__s); __asm__ volatile (\"dmb\\n\\t\"\"dsb\\n\\t\"\"isb\\n\\t\"); \\\n  __asm__ volatile (\"\" ::: \"memory\"); }\n\n\n#define ATOMIC_BLOCK(type) \\\nfor ( type, __ToDo = __iCliRetVal(); __ToDo ; __ToDo = 0 )\n\n#define ATOMIC_RESTORESTATE \\\nuint32_t primask_save __attribute__((__cleanup__(__iRestore)))  = __get_primask()\n\n#define ATOMIC_FORCEON \\\nuint32_t primask_save __attribute__((__cleanup__(__iSeiParam))) = 0\n   \n#define NONATOMIC_BLOCK(type) \\\nfor ( type, __ToDo = __iSeiRetVal(); __ToDo ;  __ToDo = 0 )\n   \n#define NONATOMIC_RESTORESTATE \\\nuint32_t primask_save __attribute__((__cleanup__(__iRestore))) = __get_primask()\n\n#define NONATOMIC_FORCEOFF \\\nuint32_t primask_save __attribute__((__cleanup__(__iCliParam))) = 0\n\n#endif \n#endif\n"
  },
  {
    "path": "RHutil/simulator.h",
    "content": "// simulator.h\n// Lets Arduino RadioHead sketches run within a simulator on Linux as a single process\n// Copyright (C) 2014 Mike McCauley\n// $Id: simulator.h,v 1.4 2015/08/13 02:45:47 mikem Exp mikem $\n\n#ifndef simulator_h\n#define simulator_h\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <stdint.h>\n\n// Equivalent types for common Arduino types like uint8_t are in stdint.h\n\n// Access to some globals\n// Command line args passed to the process.\nextern int    _simulator_argc;\nextern char** _simulator_argv;\n\n// Definitions for various Arduino functions\nextern void delay(unsigned long ms);\nextern unsigned long millis();\nextern long random(long to);\nextern long random(long from, long to);\n\n// Equavalent to HardwareSerial in Arduino\n// but outputs to stdout\nclass SerialSimulator\n{\npublic:\n#define DEC 10\n#define HEX 16\n#define OCT 8\n#define BIN 2\n\n    // TODO: move these from being inlined\n    void begin(int baud) {}\n\n    size_t println(const char* s)\n    {\n\tprint(s);\n\treturn printf(\"\\n\");\n    }\n    size_t print(const char* s)\n    {\n\treturn printf(\"%s\", s); // This style prevent warnings from [-Wformat-security]\n    }\n    size_t print(unsigned int n, int base = DEC)\n    {\n\tif (base == DEC)\n\t    return printf(\"%d\", n);\n\telse if (base == HEX)\n\t    return printf(\"%02x\", n);\n\telse if (base == OCT)\n\t    return printf(\"%o\", n);\n\t// TODO: BIN\n\telse\n\t    return 0;\n    }\n    size_t print(char ch)\n    {\n        return printf(\"%c\", ch);\n    }\n    size_t println(char ch)\n    {\n        return printf(\"%c\\n\", ch);\n    }\n    size_t print(unsigned char ch, int base = DEC)\n    {\n\treturn print((unsigned int)ch, base);\n    }\n    size_t println(unsigned char ch, int base = DEC)\n    {\n\tprint((unsigned int)ch, base);\n\treturn printf(\"\\n\");\n    }\n\n};\n\n// Global instance of the Serial output\nextern SerialSimulator Serial;\n\n#endif\n"
  },
  {
    "path": "RadioHead.h",
    "content": "// RadioHead.h\n// Author: Mike McCauley (mikem@airspayce.com) DO NOT CONTACT THE AUTHOR DIRECTLY\n// Copyright (C) 2014 Mike McCauley\n// $Id: RadioHead.h,v 1.59 2017/01/13 01:29:36 mikem Exp mikem $\n\n/// \\mainpage RadioHead Packet Radio library for embedded microprocessors\n///\n/// This is the RadioHead Packet Radio library for embedded microprocessors.\n/// It provides a complete object-oriented library for sending and receiving packetized messages\n/// via a variety of common data radios and other transports on a range of embedded microprocessors.\n///\n/// The version of the package that this documentation refers to can be downloaded \n/// from http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.67.zip\n/// You can find the latest version at http://www.airspayce.com/mikem/arduino/RadioHead\n///\n/// You can also find online help and discussion at \n/// http://groups.google.com/group/radiohead-arduino\n/// Please use that group for all questions and discussions on this topic. \n/// Do not contact the author directly, unless it is to discuss commercial licensing.\n/// Before asking a question or reporting a bug, please read \n/// - http://en.wikipedia.org/wiki/Wikipedia:Reference_desk/How_to_ask_a_software_question\n/// - http://www.catb.org/esr/faqs/smart-questions.html\n/// - http://www.chiark.greenend.org.uk/~shgtatham/bugs.html\n///\n/// \\par Overview\n///\n/// RadioHead consists of 2 main sets of classes: Drivers and Managers.\n///\n/// - Drivers provide low level access to a range of different packet radios and other packetized message transports.\n/// - Managers provide high level message sending and receiving facilities for a range of different requirements.\n///\n/// Every RadioHead program will have an instance of a Driver to provide access to the data radio or transport, \n/// and a Manager that uses that driver to send and receive messages for the application. The programmer is required\n/// to instantiate a Driver and a Manager, and to initialise the Manager. Thereafter the facilities of the Manager\n/// can be used to send and receive messages.\n///\n/// It is also possible to use a Driver on its own, without a Manager, although this only allows unaddressed, \n/// unreliable transport via the Driver's facilities.\n///\n/// In some specialised use cases, it is possible to instantiate more than one Driver and more than one Manager.\n///\n/// A range of different common embedded microprocessor platforms are supported, allowing your project to run\n/// on your choice of processor.\n///\n/// Example programs are included to show the main modes of use.\n///\n/// \\par Drivers\n///\n/// The following Drivers are provided:\n///\n/// - RH_RF22\n/// Works with Hope-RF\n/// RF22B and RF23B based transceivers, and compatible chips and modules, \n/// including the RFM22B transceiver module such as \n/// this bare module: http://www.sparkfun.com/products/10153\n/// and this shield: http://www.sparkfun.com/products/11018 \n/// and this board: http://www.anarduino.com/miniwireless\n/// and RF23BP modules such as: http://www.anarduino.com/details.jsp?pid=130\n/// Supports GFSK, FSK and OOK. Access to other chip \n/// features such as on-chip temperature measurement, analog-digital \n/// converter, transmitter power control etc is also provided.\n///\n/// - RH_RF24\n/// Works with Silicon Labs Si4460/4461/4463/4464 family of transceivers chip, and the equivalent\n/// HopeRF RF24/26/27 family of chips and the HopeRF RFM24W/26W/27W modules.\n/// Supports GFSK, FSK and OOK. Access to other chip \n/// features such as on-chip temperature measurement, analog-digital \n/// converter, transmitter power control etc is also provided.\n///\n/// - RH_RF69 \n/// Works with Hope-RF\n/// RF69B based radio modules, such as the RFM69 module, (as used on the excellent Moteino and Moteino-USB \n/// boards from LowPowerLab http://lowpowerlab.com/moteino/ )\n/// and compatible chips and modules such as RFM69W, RFM69HW, RFM69CW, RFM69HCW (Semtech SX1231, SX1231H).\n/// Also works with Anarduino MiniWireless -CW and -HW boards http://www.anarduino.com/miniwireless/ including\n/// the marvellous high powered MinWireless-HW (with 20dBm output for excellent range).\n/// Supports GFSK, FSK.\n///\n/// - RH_NRF24\n/// Works with Nordic nRF24 based 2.4GHz radio modules, such as nRF24L01 and others.\n/// Also works with Hope-RF RFM73 \n/// and compatible devices (such as BK2423). nRF24L01 and RFM73 can interoperate\n/// with each other.\n///\n/// - RH_NRF905\n/// Works with Nordic nRF905 based 433/868/915 MHz radio modules.\n///\n/// - RH_NRF51\n/// Works with Nordic nRF51 compatible 2.4 GHz SoC/devices such as the nRF51822.\n/// Also works with Sparkfun nRF52832 breakout board, with Arduino 1.6.13 and\n/// Sparkfun nRF52 boards manager 0.2.3\n///\n/// - RH_RF95\n/// Works with Semtech SX1276/77/78/79, Modtronix inAir4 and inAir9,\n/// and HopeRF RFM95/96/97/98 and other similar LoRa capable radios.\n/// Supports Long Range (LoRa) with spread spectrum frequency hopping, large payloads etc.\n/// FSK/GFSK/OOK modes are not (yet) supported.\n///\n/// - RH_MRF89\n/// Works with Microchip MRF89XA and compatible transceivers.\n/// and modules such as MRF89XAM9A.\n///\n/// - RH_CC110\n/// Works with Texas Instruments CC110L transceivers and compatible modules such as Anaren AIR BoosterPack 430BOOST-CC110L\n///\n/// - RH_ASK\n/// Works with a range of inexpensive ASK (amplitude shift keying) RF transceivers such as RX-B1 \n/// (also known as ST-RX04-ASK) receiver; TX-C1 transmitter and DR3100 transceiver; FS1000A/XY-MK-5V transceiver;\n/// HopeRF RFM83C / RFM85. Supports ASK (OOK).\n///\n/// - RH_Serial\n/// Works with RS232, RS422, RS485, RS488 and other point-to-point and multidropped serial connections, \n/// or with TTL serial UARTs such as those on Arduino and many other processors,\n/// or with data radios with a \n/// serial port interface. RH_Serial provides packetization and error detection over any hardware or \n/// virtual serial connection. Also builds and runs on Linux and OSX.\n///\n/// - RH_TCP\n/// For use with simulated sketches compiled and running on Linux.\n/// Works with tools/etherSimulator.pl to pass messages between simulated sketches, allowing\n/// testing of Manager classes on Linux and without need for real radios or other transport hardware.\n///\n/// Drivers can be used on their own to provide unaddressed, unreliable datagrams. \n/// All drivers have the same identical API.\n/// Or you can use any Driver with any of the Managers described below.\n///\n/// We welcome contributions of well tested and well documented code to support other transports.\n///\n/// \\par Managers\n///\n/// The following Mangers are provided:\n///\n/// - RHDatagram\n/// Addressed, unreliable variable length messages, with optional broadcast facilities.\n///\n/// - RHReliableDatagram\n/// Addressed, reliable, retransmitted, acknowledged variable length messages.\n///\n/// - RHRouter\n/// Multi-hop delivery from source node to destination node via 0 or more intermediate nodes, with manual routing.\n///\n/// - RHMesh\n/// Multi-hop delivery with automatic route discovery and rediscovery.\n///\n/// Any Manager may be used with any Driver.\n///\n/// \\par Platforms\n/// \n/// A range of platforms is supported:\n///\n/// - Arduino and the Arduino IDE (version 1.0 to 1.6.5 and later)\n/// Including Diecimila, Uno, Mega, Leonardo, Yun, Due, Zero etc. http://arduino.cc/, Also similar boards such as \n///  - Moteino http://lowpowerlab.com/moteino/ \n///  - Anarduino Mini http://www.anarduino.com/mini/ \n///  - RedBearLab Blend V1.0 http://redbearlab.com/blend/ (with Arduino 1.0.5 and RedBearLab Blend Add-On version 20140701) \n///  -  MoteinoMEGA https://lowpowerlab.com/shop/moteinomega \n///     (with Arduino 1.0.5 and the MoteinoMEGA Arduino Core \n///     https://github.com/LowPowerLab/Moteino/tree/master/MEGA/Core)\n///  - ESP8266 on Arduino IDE and Boards Manager per https://github.com/esp8266/Arduino \n///    Tested using Arduino 1.6.8 with esp8266 by ESP8266 Community version 2.1.0\n///    Examples serial_reliable_datagram_* and ask_* are shown to work. \n///    CAUTION: The GHz radio included in the ESP8266 is\n///    not yet supported. \n///  - etc.\n///\n/// - ChipKIT Core with Arduino IDE on any ChipKIT Core supported Digilent processor (tested on Uno32)\n/// http://chipkit.net/wiki/index.php?title=ChipKIT_core\n///\n/// - Maple and Flymaple boards with libmaple and the Maple-IDE development environment\n/// http://leaflabs.com/devices/maple/ and http://www.open-drone.org/flymaple\n///\n/// - Teensy including Teensy 3.1 and earlier built using Arduino IDE 1.0.5 to 1.6.4 and later with \n///   teensyduino addon 1.18 to 1.23 and later.\n///   http://www.pjrc.com/teensy\n///\n/// - Particle Photon https://store.particle.io/collections/photon and ARM3 based CPU with built-in \n///   Wi-Fi transceiver and extensive IoT software suport. RadioHead does not support the built-in transceiver\n///   bt can be used to control other SPI based radios, Serial ports etc.\n///   See below for details on how to build RadioHead for Photon\n///\n/// - ATtiny built using Arduino IDE 1.0.5 with the arduino-tiny support from https://code.google.com/p/arduino-tiny/\n///   and Digispark built with Arduino 1.6.5.\n///   (Caution: these are very small processors and not all RadioHead features may be available, depending on memory requirements)\n///\n/// - nRF51 compatible Arm chips such as nRF51822 with Arduino 1.6.4 and later using the procedures\n///   in http://redbearlab.com/getting-started-nrf51822/\n///\n/// - Adafruit Feather. These are excellent boards that are available with a variety of radios. We tested with the \n///   Feather 32u4 with RFM69HCW radio, with Arduino IDE 1.6.8 and the Adafruit AVR Boards board manager version 1.6.10. \n///   https://www.adafruit.com/products/3076\n///\n/// - Raspberry Pi\n///   Uses BCM2835 library for GPIO http://www.airspayce.com/mikem/bcm2835/\n///   Currently works only with RH_NRF24 driver or other drivers that do not require interrupt support.\n///   Contributed by Mike Poublon.\n///\n/// - Linux and OSX\n///   Using the RHutil/HardwareSerial class, the RH_Serial driver and any manager will\n///   build and run on Linux and OSX. These can be used to build programs that talk securely and reliably to\n///   Arduino and other processors or to other Linux or OSX hosts on a reliable, error detected datagram\n///   protocol over a serial line.\n///\n/// Other platforms are partially supported, such as Generic AVR 8 bit processors, MSP430. \n/// We welcome contributions that will expand the range of supported platforms. \n///\n/// RadioHead is available (through the efforts of others) \n/// for PlatformIO. PlatformIO is a cross-platform code builder and the missing library manager.\n/// http://platformio.org/#!/lib/show/124/RadioHead\n///\n/// \\par History\n///\n/// RadioHead was created in April 2014, substantially based on code from some of our other earlier Radio libraries:\n///\n/// - RHMesh, RHRouter, RHReliableDatagram and RHDatagram are derived from the RF22 library version 1.39.\n/// - RH_RF22 is derived from the RF22 library version 1.39.\n/// - RH_RF69 is derived from the RF69 library version 1.2.\n/// - RH_ASK is based on the VirtualWire library version 1.26, after significant conversion to C++.\n/// - RH_Serial was new.\n/// - RH_NRF24 is based on the NRF24 library version 1.12, with some significant changes.\n///\n/// During this combination and redevelopment, we have tried to retain all the processor dependencies and support from\n/// the libraries that were contributed by other people. However not all platforms can be tested by us, so if you\n/// find that support from some platform has not been successfully migrated, please feel free to fix it and send us a \n/// patch.\n///\n/// Users of RHMesh, RHRouter, RHReliableDatagram and RHDatagram in the previous RF22 library will find that their\n/// existing code will run mostly without modification. See the RH_RF22 documentation for more details.\n///\n/// \\par Installation\n///\n/// Install in the usual way: unzip the distribution zip file to the libraries\n/// sub-folder of your sketchbook. \n/// The example sketches will be visible in in your Arduino, mpide, maple-ide or whatever.\n/// http://arduino.cc/en/Guide/Libraries\n///\n/// \\par Building for Particle Photon\n///\n/// The Photon is not supported by the Arduino IDE, so it takes a little effort to set up a build environment.\n/// Heres what we did to enable building of RadioHead example sketches on Linux, \n/// but there are other ways to skin this cat.\n/// Basic reference for getting stated is: http://particle-firmware.readthedocs.org/en/develop/build/\n/// - Download the ARM gcc cross compiler binaries and unpack it in a suitable place:\n/// \\code\n/// cd /tmp\n/// wget https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2\n/// tar xvf gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2\n/// \\endcode\n/// - If dfu-util and friends not installed on your platform, download dfu-util and friends to somewhere in your path\n/// \\code\n/// cd ~/bin\n/// wget http://dfu-util.sourceforge.net/releases/dfu-util-0.8-binaries/linux-i386/dfu-util\n/// wget http://dfu-util.sourceforge.net/releases/dfu-util-0.8-binaries/linux-i386/dfu-suffix\n/// wget http://dfu-util.sourceforge.net/releases/dfu-util-0.8-binaries/linux-i386/dfu-prefix\n/// \\endcode\n/// - Download the Particle firmware (contains headers and libraries require to compile Photon sketches) \n///   to a suitable place:\n/// \\code\n/// cd /tmp\n/// wget https://github.com/spark/firmware/archive/develop.zip\n/// unzip develop.zip\n/// \\endcode\n/// - Make a working area containing the RadioHead library source code and your RadioHead sketch. You must\n///   rename the sketch from .pde or .ino to application.cpp\n/// \\code\n/// cd /tmp\n/// mkdir RadioHead\n/// cd RadioHead\n/// cp /usr/local/projects/arduino/libraries/RadioHead/*.h .\n/// cp /usr/local/projects/arduino/libraries/RadioHead/*.cpp .\n/// cp /usr/local/projects/arduino/libraries/RadioHead/examples/cc110/cc110_client/cc110_client.pde application.cpp\n/// \\endcode\n/// - Edit application.cpp and comment out any #include <SPI.h> so it looks like:\n/// \\code\n///   // #include <SPI.h>\n/// \\endcode\n/// - Connect your Photon by USB. Put it in DFU mode as descibed in Photon documentation. Light should be flashing yellow\n/// - Compile the RadioHead sketch and install it as the user program (this does not update the rest of the\n///   Photon firmware, just the user part:\n/// \\code\n/// cd /tmp/firmware-develop/main\n/// PATH=$PATH:/tmp/gcc-arm-none-eabi-5_2-2015q4/bin make APPDIR=/tmp/RadioHead all PLATFORM=photon program-dfu\n/// \\endcode\n/// - You should see RadioHead compile without errors and download the finished sketch into the Photon.\n///\n/// \\par Compatible Hardware Suppliers\n///\n/// We have had good experiences with the following suppliers of RadioHead compatible hardware:\n///\n/// - LittleBird http://littlebirdelectronics.com.au in Australia for all manner of Arduinos and radios.\n/// - LowPowerLab http://lowpowerlab.com/moteino in USA for the excellent Moteino and Moteino-USB \n///   boards which include Hope-RF RF69B radios on-board.\n/// - Anarduino and HopeRF USA (http://www.hoperfusa.com and http://www.anarduino.com) who have a wide range\n///   of HopeRF radios and Arduino integrated modules.\n/// - SparkFun https://www.sparkfun.com/ in USA who design and sell a wide range of Arduinos and radio modules.\n///\n/// \\par Donations\n///\n/// This library is offered under a free GPL license for those who want to use it that way. \n/// We try hard to keep it up to date, fix bugs\n/// and to provide free support. If this library has helped you save time or money, please consider donating at\n/// http://www.airspayce.com or here:\n///\n/// \\htmlonly <form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\"><input type=\"hidden\" name=\"cmd\" value=\"_donations\" /> <input type=\"hidden\" name=\"business\" value=\"mikem@airspayce.com\" /> <input type=\"hidden\" name=\"lc\" value=\"AU\" /> <input type=\"hidden\" name=\"item_name\" value=\"Airspayce\" /> <input type=\"hidden\" name=\"item_number\" value=\"RadioHead\" /> <input type=\"hidden\" name=\"currency_code\" value=\"USD\" /> <input type=\"hidden\" name=\"bn\" value=\"PP-DonationsBF:btn_donateCC_LG.gif:NonHosted\" /> <input type=\"image\" alt=\"PayPal — The safer, easier way to pay online.\" name=\"submit\" src=\"https://www.paypalobjects.com/en_AU/i/btn/btn_donateCC_LG.gif\" /> <img alt=\"\" src=\"https://www.paypalobjects.com/en_AU/i/scr/pixel.gif\" width=\"1\" height=\"1\" border=\"0\" /></form> \\endhtmlonly\n/// \n/// \\par Trademarks\n///\n/// RadioHead is a trademark of AirSpayce Pty Ltd. The RadioHead mark was first used on April 12 2014 for\n/// international trade, and is used only in relation to data communications hardware and software and related services.\n/// It is not to be confused with any other similar marks covering other goods and services.\n///\n/// \\par Copyright\n///\n/// This software is Copyright (C) 2011-2016 Mike McCauley. Use is subject to license\n/// conditions. The main licensing options available are GPL V2 or Commercial:\n/// \n/// \\par Open Source Licensing GPL V2\n///\n/// This is the appropriate option if you want to share the source code of your\n/// application with everyone you distribute it to, and you also want to give them\n/// the right to share who uses it. If you wish to use this software under Open\n/// Source Licensing, you must contribute all your source code to the open source\n/// community in accordance with the GPL Version 2 when your application is\n/// distributed. See http://www.gnu.org/copyleft/gpl.html\n/// \n/// \\par Commercial Licensing\n///\n/// This is the appropriate option if you are creating proprietary applications\n/// and you are not prepared to distribute and share the source code of your\n/// application. Contact info@airspayce.com for details (do not use this address for anything other than \n/// commercial license enquiries. For all other queries, using the RadioHead mailing list).\n///\n/// \\par Revision History\n/// \\version 1.1 2014-04-14<br>\n///              Initial public release\n/// \\version 1.2 2014-04-23<br>\n///              Fixed various typos. <br>\n///              Added links to compatible Anarduino products.<br>\n///              Added RHNRFSPIDriver, RH_NRF24 classes to support Nordic NRF24 based radios.\n/// \\version 1.3 2014-04-28<br>\n///              Various documentation fixups.<br>\n///              RHDatagram::setThisAddress() did not set the local copy of thisAddress. Reported by Steve Childress.<br>\n///              Fixed a problem on Teensy with RF22 and RF69, where the interrupt pin needs to be set for input, <br>\n///              else pin interrupt doesn't work properly. Reported by Steve Childress and patched by \n///              Adrien van den Bossche. Thanks.<br>\n///              Fixed a problem that prevented RF22 honouring setPromiscuous(true). Reported by Steve Childress.<br>\n///              Updated documentation to clarify some issues to do with maximum message lengths \n///              reported by Steve Childress.<br>\n///              Added support for yield() on systems that support it (currently Arduino 1.5.5 and later)\n///              so that spin-loops can suport multitasking. Suggested by Steve Childress.<br>\n///              Added RH_RF22::setGpioReversed() so the reversal it can be configured at run-time after\n///              radio initialisation. It must now be called _after_ init(). Suggested by Steve Childress.<br>\n/// \\version 1.4 2014-04-29<br>\n///              Fixed further problems with Teensy compatibility for RH_RF22. Tested on Teensy 3.1.\n///              The example/rf22_* examples now run out of the box with the wiring connections as documented for Teensy\n///              in RH_RF22.<br>\n///              Added YIELDs to spin-loops in RHRouter, RHMesh and RHReliableDatagram, RH_NRF24.<br>\n///              Tested RH_Serial examples with Teensy 3.1: they now run out of the box.<br>\n///              Tested RH_ASK examples with Teensy 3.1: they now run out of the box.<br>\n///              Reduced default SPI speed for NRF24 from 8MHz to 1MHz on Teensy, to improve reliability when\n///              poor wiring is in use.<br>\n///              on some devices such as Teensy.<br>\n///              Tested RH_NRF24 examples with Teensy 3.1: they now run out of the box.<br>\n/// \\version 1.5 2014-04-29<br>\n///              Added support for Nordic Semiconductor nRF905 transceiver with RH_NRF905 driver. Also\n///              added examples for nRF905 and tested on Teensy 3.1\n/// \\version 1.6 2014-04-30<br>\n///              NRF905 examples were missing\n/// \\version 1.7 2014-05-03<br>\n///              Added support for Arduino Due. Tested with RH_NRF905, RH_Serial, RH_ASK.\n///              IMPORTANT CHANGE to interrupt pins on Arduino with RH_RF22 and RH_RF69 constructors:\n///              previously, you had to specify the interrupt _number_ not the interrupt _pin_. Arduinos and Uno32\n///              are now consistent with all other platforms: you must specify the interrupt pin number. Default\n///              changed to pin 2 (a common choice with RF22 shields).\n///              Removed examples/maple/maple_rf22_reliable_datagram_client and \n///              examples/maple/maple_rf22_reliable_datagram_client since the rf22 examples now work out\n///              of the box with Flymaple.\n///              Removed examples/uno32/uno32_rf22_reliable_datagram_client and \n///              examples/uno32/uno32_rf22_reliable_datagram_client since the rf22 examples now work out\n///              of the box with ChipKit Uno32.\n/// \\version 1.8 2014-05-08 <br>\n///              Added support for YIELD in Teensy 2 and 3, suggested by Steve Childress.<br>\n///              Documentation updates. Clarify use of headers and Flags<br>\n///              Fixed misalignment in RH_RF69 between ModemConfigChoice definitions and the implemented choices\n///              which meant you didnt get the choice you thought and GFSK_Rb55555Fd50 hung the transmitter.<br>\n///              Preliminary work on Linux simulator.\n/// \\version 1.9 2014-05-14 <br>\n///              Added support for using Timer 2 instead of Timer 1 on Arduino in RH_ASK when\n///              RH_ASK_ARDUINO_USE_TIMER2 is defined. With the kind assistance of\n///              Luc Small. Thanks!<br>\n///              Updated comments in RHReliableDatagram concerning servers, retries, timeouts and delays.\n///              Fixed an error in RHReliableDatagram where recvfrom return value was not checked.\n///              Reported by Steve Childress.<br>\n///              Added Linux simulator support so simple RadioHead sketches can be compiled and run on Linux.<br>\n///              Added RH_TCP driver to permit message passing between simulated sketches on Linux.<br>\n///              Added example simulator sketches.<br>\n///              Added tools/etherSimulator.pl, a simulator of the 'Luminiferous Ether' that passes\n///              messages between simulated sketches and can simulate random message loss etc.<br>\n///              Fixed a number of typos and improved some documentation.<br>\n/// \\version 1.10 2014-05-15 <br>\n///              Added support for RFM73 modules to RH_NRF24. These 2 radios are very similar, and can interoperate\n///              with each other. Added new RH_NRF24::TransmitPower enums for the RFM73, which has a different \n///              range of available powers<br>\n///              reduced the default SPI bus speed for RH_NRF24 to 1MHz, since so many modules and CPU have problems\n///              with 8MHz.<br>\n/// \\version 1.11 2014-05-18<br>\n///              Testing RH_RF22 with RFM23BP and 3.3V Teensy 3.1 and 5V Arduinos. \n///              Updated documentation with respect to GPIO and antenna\n///              control pins for RFM23. Updated documentation with respect to transmitter power control for RFM23<br>\n///              Fixed a problem with RH_RF22 driver, where GPIO TX and RX pins were not configured during\n///              initialisation, causing poor transmit power and sensitivity on those RF22/RF23 devices where GPIO controls\n///              the antenna selection pins.\n/// \\version 1.12 2014-05-20<br>\n///              Testing with RF69HW and the RH_RF69 driver. Works well with the Anarduino MiniWireless -CW and -HW \n///              boards http://www.anarduino.com/miniwireless/ including\n///              the marvellous high powered MinWireless-HW (with 20dBm output for excellent range).<br>\n///              Clarified documentation of RH_RF69::setTxPower values for different models of RF69.<br>\n///              Added RHReliableDatagram::resetRetransmissions().<br>\n///              Retransmission count precision increased to uin32_t.<br>\n///              Added data about actual power measurements from RFM22 module.<br>\n/// \\version 1.13 2014-05-23<br>\n///              setHeaderFlags(flags) changed to setHeaderFlags(set, clear), enabling any flags to be\n///              individually set and cleared by either RadioHead or application code. Requested by Steve Childress.<br>\n///              Fixed power output setting for boost power on RF69HW for 18, 19 and 20dBm.<br>\n///              Added data about actual power measurements from RFM69W and RFM69HW modules.<br>\n/// \\version 1.14 2014-05-26<br>\n///              RH_RF69::init() now always sets the PA boost back to the default settings, else can get invalid\n///              PA power modes after uploading new sketches without a power cycle. Reported by Bryan.<br>\n///              Added new macros RH_VERSION_MAJOR RH_VERSION_MINOR, with automatic maintenance in Makefile.<br>\n///              Improvements to RH_TCP: constructor now honours the server argument in the form \"servername:port\".<br>\n///              Added YIELD to RHReliableDatagram::recvfromAckTimeout. Requested by Steve Childress.<br>\n///              Fixed a problem with RH_RF22 reliable datagram acknowledgements that was introduced in version 1.13.\n///              Reported by Steve Childress.<br>\n/// \\version 1.15 2014-05-27<br>\n///              Fixed a problem with the RadioHead .zip link.\n/// \\version 1.16 2014-05-30 <br>\n///              Fixed RH_RF22 so that lastRssi() returns the signal strength in dBm. Suggested by Steve Childress.<br>\n///              Added support for getLastPreambleTime() to RH_RF69. Requested by Steve Childress.<br>\n///              RH_NRF24::init() now checks if there is a device connected and responding, else init() will fail.\n///              Suggested by Steve Brown.<br>\n///              RHSoftwareSPI now initialises default values for SPI pins MOSI = 12, MISO = 11 and SCK = 13.<br>\n///              Fixed some problems that prevented RH_NRF24 working with mixed software and hardware SPI \n///              on different devices: a race condition\n///              due to slow SPI transfers and fast acknowledgement.<br>\n/// \\version 1.17 2014-06-02 <br>\n///              Fixed a debug typo in RHReliableDatagram that was introduced in 1.16.<br>\n///              RH_NRF24 now sets default power, data rate and channel in init(), in case another\n///              app has previously set different values without powerdown.<br>\n///              Caution: there are still problems with RH_NRF24 and Software SPI. Do not use.<br>\n/// \\version 1.18 2014-06-02<br>\n///              Improvements to performance of RH_NRF24 statusRead, allowing RH_NRF24 and Software SPI\n///              to operate on slow devices like Arduino Uno.<br>\n/// \\version 1.19 2014-06-19<br>\n///              Added examples ask_transmitter.pde and ask_receiver.pde.<br>\n///              Fixed an error in the RH_RF22 doc for connection of Teensy to RF22.<br>\n///              Improved documentation of start symbol bit patterns in RH_ASK.cpp\n/// \\version 1.20 2014-06-24<br>\n///              Fixed a problem with compiling on platforms such as ATTiny where SS is not defined.<br>\n///              Added YIELD to RHMesh::recvfromAckTimeout().<br>\n/// \\version 1.21 2014-06-24<br>\n///              Fixed an issue in RH_Serial where characters might be lost with back-to-back frames.\n///              Suggested by Steve Childress.<br>\n///              Brought previous RHutil/crc16.h code into mainline RHCRC.cpp to prevent name collisions\n///              with other similarly named code in other libraries. Suggested by Steve Childress.<br>\n///              Fix SPI bus speed errors on 8MHz Arduinos.\n/// \\version 1.22 2014-07-01<br>\n///              Update RH_ASK documentation for common wiring connections.<br>\n///              Testing RH_ASK with HopeRF RFM83C/RFM85 courtesy Anarduino http://www.anarduino.com/<br>\n///              Testing RH_NRF24 with Itead Studio IBoard Pro http://imall.iteadstudio.com/iboard-pro.html\n///              using both hardware SPI on the ITDB02 Parallel LCD Module Interface pins and software SPI\n///              on the nRF24L01+ Module Interface pins. Documented wiring required.<br>\n///              Added support for AVR 1284 and 1284p, contributed by Peter Scargill.\n///              Added support for Semtech SX1276/77/78 and HopeRF RFM95/96/97/98 and other similar LoRa capable radios\n///              in LoRa mode only. Tested with the excellent MiniWirelessLoRa from \n///              Anarduino http://www.anarduino.com/miniwireless<br>\n/// \\version 1.23 2014-07-03<br>\n///              Changed the default modulation for RH_RF69 to GFSK_Rb250Fd250, since the previous default\n///              was not very reliable.<br>\n///              Documented RH_RF95 range tests.<br>\n///              Improvements to RH_RF22 RSSI readings so that lastRssi correctly returns the last message in dBm.<br>\n/// \\version 1.24 2014-07-18\n///              Added support for building RadioHead for STM32F4 Discovery boards, using the native STM Firmware libraries,\n///              in order to support Codec2WalkieTalkie (http://www.airspayce.com/mikem/Codec2WalkieTalkie)\n///              and other projects. See STM32ArduinoCompat.<br>\n///              Default modulation for RH_RF95 was incorrectly set to a very slow Bw125Cr48Sf4096\n/// \\version 1.25 2014-07-25\n///              The available() function will longer terminate any current transmission, and force receive mode. \n///              Now, if there is no unprocessed incoming message and an outgoing message is currently being transmitted, \n///              available() will return false.<br>\n///              RHRouter::sendtoWait(uint8_t*, uint8_t, uint8_t, uint8_t) renamed to sendtoFromSourceWait due to conflicts\n///              with new sendtoWait() with optional flags.<br>\n///              RHMEsh and RHRouter already supported end-to-end application layer flags, but RHMesh::sendtoWait() \n///              and RHRouter::sendToWait have now been extended to expose a way to send optional application layer flags.\n/// \\version 1.26 2014-08-12\n///              Fixed a Teensy 2.0 compile problem due yield() not available on Teensy < 3.0. <br>\n///              Adjusted the algorithm of RH_RF69::temperatureRead() to more closely reflect reality.<br>\n///              Added functions to RHGenericDriver to get driver packet statistics: rxBad(), rxGood(), txGood().<br>\n///              Added RH_RF69::printRegisters().<br>\n///              RH_RF95::printRegisters() was incorrectly printing the register index instead of the address.\n///              Reported by Phang Moh Lim.<br>\n///              RH_RF95, added definitions for some more registers that are usable in LoRa mode.<br>\n///              RH_RF95::setTxPower now uses RH_RF95_PA_DAC_ENABLE to achieve 21, 22 and 23dBm.<br>\n///              RH_RF95, updated power output measurements.<br>\n///              Testing RH_RF69 on Teensy 3.1 with RF69 on PJRC breakout board. OK.<br>\n///              Improvements so RadioHead will build under Arduino where SPI is not supported, such as \n///              ATTiny.<br>\n///              Improvements so RadioHead will build for ATTiny using Arduino IDE and tinycore arduino-tiny-0100-0018.zip.<br>\n///              Testing RH_ASK on ATTiny85. Reduced RAM footprint. \n///              Added helpful documentation. Caution: RAM memory is *very* tight on this platform.<br>\n///              RH_RF22 and RH_RF69, added setIdleMode() function to allow the idle mode radio operating state\n///              to be controlled for lower idle power consumption at the expense of slower transitions to TX and RX.<br>\n/// \\version 1.27 2014-08-13\n///              All RH_RF69 modulation schemes now have data whitening enabled by default.<br>\n///              Tested and added a number of OOK modulation schemes to RH_RF69 Modem config table.<br>\n///              Minor improvements to a number of the faster RH_RF69 modulation schemes, but some slower ones\n///              are still not working correctly.<br>\n/// \\version 1.28 2014-08-20\n///              Added new RH_RF24 driver to support Si446x, RF24/26/26, RFM24/26/27 family of transceivers.\n///              Tested with the excellent\n///              Anarduino Mini and RFM24W and RFM26W with the generous assistance of the good people at \n///              Anarduino http://www.anarduino.com.\n/// \\version 1.29 2014-08-21\n///              Fixed a compile error in RH_RF24 introduced at the last minute in hte previous release.<br>\n///              Improvements to RH_RF69 modulation schemes: now include the AFCBW in teh ModemConfig.<br>\n///              ModemConfig RH_RF69::FSK_Rb2Fd5 and RH_RF69::GFSK_Rb2Fd5 are now working.<br> \n/// \\version 1.30 2014-08-25\n///              Fixed some compile problems with ATtiny84 on Arduino 1.5.5 reported by Glen Cook.<br>\n/// \\version 1.31 2014-08-27\n///              Changed RH_RF69 FSK and GFSK modulations from Rb2_4Fd2_4 to Rb2_4Fd4_8 and FSK_Rb4_8Fd4_8 to FSK_Rb4_8Fd9_6\n///              since the previous ones were unreliable (they had modulation indexes of 1).<br>\n/// \\version 1.32 2014-08-28\n///              Testing with RedBearLab Blend board http://redbearlab.com/blend/. OK.<br>\n///              Changed more RH_RF69 FSK and GFSK slowish modulations to have modulation index of 2 instead of 1. \n///              This required chnaging the symbolic names.<br>\n/// \\version 1.33 2014-09-01\n///              Added support for sleep mode in RHGeneric driver, with new mode \n///              RHModeSleep and new virtual function sleep().<br>\n///              Added support for sleep to RH_RF69, RH_RF22, RH_NRF24, RH_RF24, RH_RF95 drivers.<br>\n/// \\version 1.34 2014-09-19\n///              Fixed compile errors in example rf22_router_test.<br>\n///              Fixed a problem with RH_NRF24::setNetworkAddress, also improvements to RH_NRF24 register printing.\n///              Patched by Yveaux.<br>\n///              Improvements to RH_NRF24 initialisation for version 2.0 silicon.<br>\n///              Fixed problem with ambigiguous print call in RH_RFM69 when compiling for Codec2.<br>\n///              Fixed a problem with RH_NRF24 on RFM73 where the LNA gain was not set properly, reducing the sensitivity\n///              of the receiver.\n/// \\version 1.35 2014-09-19\n///              Fixed a problem with interrupt setup on RH_RF95 with Teensy3.1. Reported by AD.<br>\n/// \\version 1.36 2014-09-22\n///              Improvements to interrupt pin assignments for __AVR_ATmega1284__ and__AVR_ATmega1284P__, provided by\n///              Peter Scargill.<br>\n///              Work around a bug in Arduino 1.0.6 where digitalPinToInterrupt is defined but NOT_AN_INTERRUPT is not.<br>\n///  \\version 1.37 2014-10-19\n///              Updated doc for connecting RH_NRF24 to Arduino Mega.<br>\n///              Changes to RHGenericDriver::setHeaderFlags(), so that the default for the clear argument\n///              is now RH_FLAGS_APPLICATION_SPECIFIC, which is less surprising to users.\n///              Testing with the excellent MoteinoMEGA from LowPowerLab \n///              https://lowpowerlab.com/shop/moteinomega with on-board RFM69W.\n///  \\version 1.38 2014-12-29\n///              Fixed compile warning on some platforms where RH_RF24::send and RH_RF24::writeTxFifo \n///              did not return a value.<br>\n///              Fixed some more compiler warnings in RH_RF24 on some platforms.<br>\n///              Refactored printRegisters for some radios. Printing to Serial\n///              is now controlled by the definition of RH_HAVE_SERIAL.<br>\n///              Added partial support for ARM M4 w/CMSIS with STM's Hardware Abstraction lib for \n///              Steve Childress.<br>\n///  \\version 1.39 2014-12-30\n///              Fix some compiler warnings under IAR.<br>\n///              RH_HAVE_SERIAL and Serial.print calls removed for ATTiny platforms.<br>\n///  \\version 1.40 2015-03-09\n///              Added notice about availability on PlatformIO, thanks to Ivan Kravets.<br>\n///              Fixed a problem with RH_NRF24 where short packet lengths would occasionally not be trasmitted\n///              due to a race condition with RH_NRF24_TX_DS. Reported by Mark Fox.<br>\n///  \\version 1.41 2015-03-29\n///              RH_RF22, RH_RF24, RH_RF69 and RH_RF95 improved to allow driver.init() to be called multiple\n///              times without reallocating a new interrupt, allowing the driver to be reinitialised\n///              after sleeping or powering down.\n///  \\version 1.42 2015-05-17\n///              Added support for RH_NRF24 driver on Raspberry Pi, using BCM2835\n///              library for GPIO pin IO. Contributed by Mike Poublon.<br>\n///              Tested RH_NRF24 module with NRF24L01+PA+LNA SMA Antenna Wireless Transceiver modules\n///              similar to: http://www.elecfreaks.com/wiki/index.php?title=2.4G_Wireless_nRF24L01p_with_PA_and_LNA\n///              works with no software changes. Measured max power output 18dBm.<br>\n///  \\version 1.43 2015-08-02\n///              Added RH_NRF51 driver to support Nordic nRF51 family processor with 2.4GHz radio such \n///              as nRF51822, to be built on Arduino 1.6.4 and later. Tested with RedBearLabs nRF51822 board\n///              and BLE Nano kit<br>\n///  \\version 1.44 2015-08-08\n///              Fixed errors with compiling on some platforms without serial, such as ATTiny. \n///              Reported by Friedrich Müller.<br>\n///  \\version 1.45 2015-08-13\n///              Added support for using RH_Serial on Linux and OSX (new class RHutil/HardwareSerial\n///              encapsulates serial ports on those platforms). Example examples/serial upgraded\n///              to build and run on Linux and OSX using the tools/simBuild builder.\n///              RHMesh, RHRouter and RHReliableDatagram updated so they can use RH_Serial without\n///              polling loops on Linux and OSX for CPU efficiency.<br>\n///  \\version 1.46 2015-08-14\n///              Amplified some doc concerning Linux and OSX RH_Serial. Added support for 230400\n///              baud rate in HardwareSerial.<br>\n///              Added sample sketches nrf51_audio_tx and nrf51_audio_rx which show how to\n///              build an audio TX/RX pair with RedBear nRF51822 boards and a SparkFun MCP4725 DAC board.\n///              Uses the built-in ADC of the nRF51822 to sample audio at 5kHz and transmit packets\n///              to the receiver which plays them via the DAC.<br>\n/// \\version 1.47 2015-09-18\n///              Removed top level Makefile from distribution: its only used by the developer and \n///              its presence confuses some people.<br>\n///              Fixed a problem with RHReliableDatagram with some versions of Raspberry Pi random() that causes \n///              problems: random(min, max) sometimes exceeds its max limit.\n/// \\version 1.48 2015-09-30\n///              Added support for Arduino Zero. Tested on Arduino Zero Pro.\n/// \\version 1.49 2015-10-01\n///              Fixed problems that prevented interrupts working correctly on Arduino Zero and Due.\n///              Builds and runs with 1.6.5 (with 'Arduino SAMD Boards' for Zero version 1.6.1) from arduino.cc.\n///              Arduino version 1.7.7 from arduino.org is not currently supported.\n/// \\version 1.50 2015-10-25\n///              Verified correct building and operation with Arduino 1.7.7 from arduino.org.\n///              Caution: You must burn the bootloader from 1.7.7 to the Arduino Zero before it will \n///              work with Arduino 1.7.7 from arduino.org. Conversely, you must burn the bootloader from 1.6.5 \n///              to the Arduino Zero before it will \n///              work with Arduino 1.6.5 from arduino.cc. Sigh.\n///              Fixed a problem with RH_NRF905 that prevented the power and frequency ranges being set\n///              properly. Reported by Alan Webber.\n/// \\version 1.51 2015-12-11\n///              Changes to RH_RF6::setTxPower() to be compatible with SX1276/77/78/79 modules that\n///              use RFO transmitter pins instead of PA_BOOST, such as the excellent\n///              Modtronix inAir4 http://modtronix.com/inair4.html \n///              and inAir9 modules http://modtronix.com/inair9.html. With the kind assistance of \n///              David from Modtronix.\n/// \\version 1.52 2015-12-17\n///              Added RH_MRF89 module to suport Microchip MRF89XA and compatible transceivers.\n///              and modules.<br>\n/// \\version 1.53 2016-01-02\n///              Added RH_CC110 module to support Texas Instruments CC110L and compatible transceivers and modules.<br>\n/// \\version 1.54 2016-01-29\n///              Added support for ESP8266 processor on Arduino IDE. Examples serial_reliable_datagram_* are shown to work. \n///              CAUTION: SPI not supported yet. Timers used by RH_ASK are not tested. \n///              The GHz radio included in the ESP8266 is not yet supported. \n/// \\version 1.55 2016-02-12\n///              Added macros for htons() and friends to RadioHead.h.\n///              Added example sketch serial_gateway.pde. Acts as a transparent gateway between RH_RF22 and RH_Serial, \n///              and with minor mods acts as a universal gateway between any 2 RadioHead driver networks.\n///              Initial work on supporting STM32 F2 on Particle Photon: new platform type defined.\n///              Fixed many warnings exposed by test building for Photon.\n///              Particle Photon tested support for RH_Serial, RH_ASK, SPI, RH_CC110 etc.\n///              Added notes on how to build RadioHead sketches for Photon.\n/// \\version 1.56 2016-02-18 \n///              Implemented timers for RH_ASK on ESP8266, added some doc on IO pin selection.\n/// \\version 1.57 2016-02-23\n///              Fixed an issue reported by S3B, where RH_RF22 would sometimes not clear the rxbufvalid flag.\n/// \\version 1.58 2-16-04-04\n///              Tested RH_RF69 with Arduino Due. OK. Updated doc.<br>\n///              Added support for all ChipKIT Core supported boards \n///              http://chipkit.net/wiki/index.php?title=ChipKIT_core\n///              Tested on ChipKIT Uno32.<br>\n///              Digilent Uno32 under the old MPIDE is no longer formally \n///              supported but may continue to work for some time.<br>\n/// \\version 1.59 2016-04-12\n///              Testing with the excellent Rocket Scream Mini Ultra Pro with the RFM95W and RFM69HCW modules from\n///              http://www.rocketscream.com/blog/product/mini-ultra-pro-with-radio/  (915MHz versions). Updated\n///              documentation with hints to suit. Caution: requires Arduino 1.6.8 and Arduino SAMD Boards 1.6.5.\n///              See also http://www.rocketscream.com/blog/2016/03/10/radio-range-test-with-rfm69hcw/\n///              for the vendors tests and range with the RFM69HCW version.\n///              These boards are highly recommended. They also include battery charging support.\n/// \\version 1.60 2016-06-25\n///              Tested with the excellent talk2 Whisper Node boards \n///             (https://talk2.wisen.com.au/ and https://bitbucket.org/talk2/), \n///              an Arduino Nano compatible board, which include an on-board RF69 radio, external antenna, \n///              run on 2xAA batteries and support low power operations. RF69 examples work without modification.\n///              Added support for ESP8266 SPI, provided by David Skinner.\n/// \\version 1.61 2016-07-07\n///              Patch to RH_ASK.cpp for ESP8266, to prevent crashes in interrupt handlers. Patch from Alexander Mamchits.\n/// \\version 1.62 2016-08-17\n///              Fixed a problem in RH_ASK where _rxInverted was not properly initialised. Reported by \"gno.sun.sop\".\n///              Added support for  waitCAD() and isChannelActive() and setCADTimeout() to RHGeneric.\n///              Implementation of RH_RF95::isChannelActive() allows the RF95 module to support\n///              Channel Activity Detection (CAD). Based on code contributed by Bent Guldbjerg Christensen.\n///              Implmentations of isChannelActive() plus documentation for other radio modules wil be welcomed.\n/// \\version 1.63 2016-10-20\n///              Testing with Adafruit Feather 32u4 with RFM69HCW. Updated documentation to reflect.<br>\n/// \\version 1.64 2016-12-10\n///              RHReliableDatagram now initialises _seenids. Fix from Ben Lim.<br>\n///              In RH_NRF51, added get_temperature().<br>\n///              In RH_NRF51, added support for AES packet encryption, which required a slight change \n///              to the on-air message format.<br>\n/// \\version 1.65 2017-01-11\n///              Fixed a race condition with RH_NRF51 that prevented ACKs being reliably received.<br>\n///              Removed code in RH_NRF51 that enabled the DC-DC converter. This seems not to be a necessary condition\n///              for the radio to work and is now left to the application if that is required.<br>\n///              Proven interoperation between nRF51822 and nRF52832.<br>\n///              Modification and testing of RH_NRF51 so it works with nRF52 family processors,\n///              such Sparkfun nRF52832 breakout board, with Arduino 1.6.13 and\n///              Sparkfun nRF52 boards manager 0.2.3 using the procedures outlined in\n///              https://learn.sparkfun.com/tutorials/nrf52832-breakout-board-hookup-guide<br>\n///              Caution, the Sparkfun development system for Arduino is still immature. We had to \n///              rebuild the nrfutil program since the supplied one was not suitable for \n///              the Linux host we were developing on. See https://forum.sparkfun.com/viewtopic.php?f=32&t=45071\n///              Also, after downloading a sketch in the nRF52832, the program does not start executing cleanly: \n///              you have to reset the processor again by pressing the reset button. \n///              This appears to be a problem with nrfutil, rather than a bug in RadioHead.\n/// \\version 1.66 2017-01-15\n///              Fixed some errors in (unused) register definitions in RH_RF95.h.<br>\n///              Fixed a problem that caused compilation errors in RH_NRF51 if the appropriate board \n///              support was not installed.\n///\n/// \\author  Mike McCauley. DO NOT CONTACT THE AUTHOR DIRECTLY. USE THE MAILING LIST GIVEN ABOVE\n\n#ifndef RadioHead_h\n#define RadioHead_h\n\n// Official version numbers are maintained automatically by Makefile:\n#define RH_VERSION_MAJOR 1\n#define RH_VERSION_MINOR 67\n\n// Symbolic names for currently supported platform types\n#define RH_PLATFORM_ARDUINO          1\n#define RH_PLATFORM_MSP430           2\n#define RH_PLATFORM_STM32            3\n#define RH_PLATFORM_GENERIC_AVR8     4\n#define RH_PLATFORM_UNO32            5\n#define RH_PLATFORM_UNIX             6\n#define RH_PLATFORM_STM32STD         7\n#define RH_PLATFORM_STM32F4_HAL      8 \n#define RH_PLATFORM_RASPI            9\n// Also nRF52 family:\n#define RH_PLATFORM_NRF51            10\n#define RH_PLATFORM_ESP8266          11\n#define RH_PLATFORM_STM32F2          12\n#define RH_PLATFORM_CHIPKIT_CORE     13\n\n////////////////////////////////////////////////////\n// Select platform automatically, if possible\n#ifndef RH_PLATFORM\n #if (MPIDE>=150 && defined(ARDUINO))\n  // Using ChipKIT Core on Arduino IDE\n  #define RH_PLATFORM RH_PLATFORM_CHIPKIT_CORE\n #elif defined(MPIDE)\n  // Uno32 under old MPIDE, which has been discontinued:\n  #define RH_PLATFORM RH_PLATFORM_UNO32\n#elif defined(NRF51) || defined(NRF52)\n  #define RH_PLATFORM RH_PLATFORM_NRF51\n #elif defined(ESP8266)\n  #define RH_PLATFORM RH_PLATFORM_ESP8266\n #elif defined(ARDUINO)\n  #define RH_PLATFORM RH_PLATFORM_ARDUINO\n #elif defined(__MSP430G2452__) || defined(__MSP430G2553__)\n  #define RH_PLATFORM RH_PLATFORM_MSP430\n #elif defined(MCU_STM32F103RE)\n  #define RH_PLATFORM RH_PLATFORM_STM32\n #elif defined(STM32F2XX)\n  #define RH_PLATFORM RH_PLATFORM_STM32F2\n #elif defined(USE_STDPERIPH_DRIVER)\n  #define RH_PLATFORM RH_PLATFORM_STM32STD\n #elif defined(RASPBERRY_PI)\n  #define RH_PLATFORM RH_PLATFORM_RASPI\n#elif defined(__unix__) // Linux\n  #define RH_PLATFORM RH_PLATFORM_UNIX\n#elif defined(__APPLE__) // OSX\n  #define RH_PLATFORM RH_PLATFORM_UNIX\n #else\n  #error Platform not defined! \t\n #endif\n#endif\n\n#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtinyX4__) || defined(__AVR_ATtinyX5__) || defined(__AVR_ATtiny2313__) || defined(__AVR_ATtiny4313__) || defined(__AVR_ATtinyX313__)\n #define RH_PLATFORM_ATTINY\n#endif\n\n////////////////////////////////////////////////////\n// Platform specific headers:\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO)\n #if (ARDUINO >= 100)\n  #include <Arduino.h>\n #else\n  #include <wiring.h>\n #endif\n #ifdef RH_PLATFORM_ATTINY\n  #warning Arduino TinyCore does not support hardware SPI. Use software SPI instead.\n #else\n  #include <SPI.h>\n  #define RH_HAVE_HARDWARE_SPI\n  #define RH_HAVE_SERIAL\n #endif\n\n#elif (RH_PLATFORM == RH_PLATFORM_ESP8266) // ESP8266 processor on Arduino IDE\n #include <Arduino.h>\n #include <SPI.h>\n #define RH_HAVE_HARDWARE_SPI\n #define RH_HAVE_SERIAL\n#elif (RH_PLATFORM == RH_PLATFORM_MSP430) // LaunchPad specific\n #include \"legacymsp430.h\"\n #include \"Energia.h\"\n #include <SPI.h>\n #define RH_HAVE_HARDWARE_SPI\n #define RH_HAVE_SERIAL\n\n#elif (RH_PLATFORM == RH_PLATFORM_UNO32 || RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE)\n #include <WProgram.h>\n #include <string.h>\n #include <SPI.h>\n #define RH_HAVE_HARDWARE_SPI\n #define memcpy_P memcpy\n #define RH_HAVE_SERIAL\n\n#elif (RH_PLATFORM == RH_PLATFORM_STM32) // Maple, Flymaple etc\n #include <wirish.h>\t\n #include <stdint.h>\n #include <string.h>\n #include <HardwareSPI.h>\n #define RH_HAVE_HARDWARE_SPI\n // Defines which timer to use on Maple\n #define MAPLE_TIMER 1\n #define PROGMEM\n #define memcpy_P memcpy\n #define Serial SerialUSB\n #define RH_HAVE_SERIAL\n\n#elif (RH_PLATFORM == RH_PLATFORM_STM32F2) // Particle Photon with firmware-develop\n #include <stm32f2xx.h>\n #include <application.h>\n #include <math.h> // floor\n #define RH_HAVE_SERIAL\n #define RH_HAVE_HARDWARE_SPI\n\n#elif (RH_PLATFORM == RH_PLATFORM_STM32STD) // STM32 with STM32F4xx_StdPeriph_Driver \n #include <stm32f4xx.h>\n #include <wirish.h>\t\n #include <stdint.h>\n #include <string.h>\n #include <math.h>\n #include <HardwareSPI.h>\n #define RH_HAVE_HARDWARE_SPI\n #define Serial SerialUSB\n #define RH_HAVE_SERIAL\n\n#elif (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8) \n #include <avr/io.h>\n #include <avr/interrupt.h>\n #include <util/delay.h>\n #include <string.h>\n #include <stdbool.h>\n #define RH_HAVE_HARDWARE_SPI\n #include <SPI.h>\n\n// For Steve Childress port to ARM M4 w/CMSIS with STM's Hardware Abstraction lib. \n// See ArduinoWorkarounds.h (not supplied)\n#elif (RH_PLATFORM == RH_PLATFORM_STM32F4_HAL) \n #include <ArduinoWorkarounds.h>\n #include <stm32f4xx.h> // Also using ST's CubeMX to generate I/O and CPU setup source code for IAR/EWARM, not GCC ARM.\n #include <stdint.h>\n #include <string.h>\n #include <math.h>\n #define RH_HAVE_HARDWARE_SPI // using HAL (Hardware Abstraction Libraries from ST along with CMSIS, not arduino libs or pins concept.\n\n#elif (RH_PLATFORM == RH_PLATFORM_RASPI)\n #define RH_HAVE_HARDWARE_SPI\n #define RH_HAVE_SERIAL\n #define PROGMEM\n #include <RHutil/RasPi.h>\n #include <string.h>\n //Define SS for CS0 or pin 24\n #define SS 8\n\n#elif (RH_PLATFORM == RH_PLATFORM_NRF51)\n #define RH_HAVE_SERIAL\n #define PROGMEM\n  #include <Arduino.h>\n\n#elif (RH_PLATFORM == RH_PLATFORM_UNIX) \n // Simulate the sketch on Linux and OSX\n #include <RHutil/simulator.h>\n #define RH_HAVE_SERIAL\n#include <netinet/in.h> // For htons and friends\n\n#else\n #error Platform unknown!\n#endif\n\n////////////////////////////////////////////////////\n// This is an attempt to make a portable atomic block\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO)\n#if defined(__arm__)\n  #include <RHutil/atomic.h>\n #else\n  #include <util/atomic.h>\n #endif\n #define ATOMIC_BLOCK_START     ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {\n #define ATOMIC_BLOCK_END }\n#elif (RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE)\n // UsingChipKIT Core on Arduino IDE\n #define ATOMIC_BLOCK_START unsigned int __status = disableInterrupts(); {\n #define ATOMIC_BLOCK_END } restoreInterrupts(__status);\n#elif (RH_PLATFORM == RH_PLATFORM_UNO32)\n // Under old MPIDE, which has been discontinued:\n #include <peripheral/int.h>\n #define ATOMIC_BLOCK_START unsigned int __status = INTDisableInterrupts(); {\n #define ATOMIC_BLOCK_END } INTRestoreInterrupts(__status);\n#elif (RH_PLATFORM == RH_PLATFORM_STM32F2) // Particle Photon with firmware-develop\n #define ATOMIC_BLOCK_START { int __prev = HAL_disable_irq();\n #define ATOMIC_BLOCK_END  HAL_enable_irq(__prev); }\n#elif (RH_PLATFORM == RH_PLATFORM_ESP8266)\n// See hardware/esp8266/2.0.0/cores/esp8266/Arduino.h\n #define ATOMIC_BLOCK_START { uint32_t __savedPS = xt_rsil(15);\n #define ATOMIC_BLOCK_END xt_wsr_ps(__savedPS);}\n#else \n // TO BE DONE:\n #define ATOMIC_BLOCK_START\n #define ATOMIC_BLOCK_END\n#endif\n\n////////////////////////////////////////////////////\n// Try to be compatible with systems that support yield() and multitasking\n// instead of spin-loops\n// Recent Arduino IDE or Teensy 3 has yield()\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO && ARDUINO >= 155 && !defined(RH_PLATFORM_ATTINY)) || (TEENSYDUINO && defined(__MK20DX128__))\n #define YIELD yield();\n#elif (RH_PLATFORM == RH_PLATFORM_ESP8266)\n// ESP8266 also hash it\n #define YIELD yield();\n#else\n #define YIELD\n#endif\n\n////////////////////////////////////////////////////\n// digitalPinToInterrupt is not available prior to Arduino 1.5.6 and 1.0.6\n// See http://arduino.cc/en/Reference/attachInterrupt\n#ifndef NOT_AN_INTERRUPT\n #define NOT_AN_INTERRUPT -1\n#endif\n#ifndef digitalPinToInterrupt\n #if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && !defined(__arm__)\n\n  #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)\n   // Arduino Mega, Mega ADK, Mega Pro\n   // 2->0, 3->1, 21->2, 20->3, 19->4, 18->5\n   #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : ((p) >= 18 && (p) <= 21 ? 23 - (p) : NOT_AN_INTERRUPT)))\n\n  #elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) \n   // Arduino 1284 and 1284P - See Manicbug and Optiboot\n   // 10->0, 11->1, 2->2\n   #define digitalPinToInterrupt(p) ((p) == 10 ? 0 : ((p) == 11 ? 1 : ((p) == 2 ? 2 : NOT_AN_INTERRUPT)))\n\n  #elif defined(__AVR_ATmega32U4__)\n   // Leonardo, Yun, Micro, Pro Micro, Flora, Esplora\n   // 3->0, 2->1, 0->2, 1->3, 7->4\n   #define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))\n\n  #else\n   // All other arduino except Due:\n   // Serial Arduino, Extreme, NG, BT, Uno, Diecimila, Duemilanove, Nano, Menta, Pro, Mini 04, Fio, LilyPad, Ethernet etc\n   // 2->0, 3->1\n   #define digitalPinToInterrupt(p)  ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT))\n\n  #endif\n  \n #elif (RH_PLATFORM == RH_PLATFORM_UNO32) || (RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE)\n  // Hmmm, this is correct for Uno32, but what about other boards on ChipKIT Core?\n  #define digitalPinToInterrupt(p) ((p) == 38 ? 0 : ((p) == 2 ? 1 : ((p) == 7 ? 2 : ((p) == 8 ? 3 : ((p) == 735 ? 4 : NOT_AN_INTERRUPT)))))\n\n #else\n  // Everything else (including Due and Teensy) interrupt number the same as the interrupt pin number\n  #define digitalPinToInterrupt(p) (p)\n #endif\n#endif\n\n// On some platforms, attachInterrupt() takes a pin number, not an interrupt number\n#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && (defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_SAM_DUE))\n #define RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER\n#endif\n\n// Slave select pin, some platforms such as ATTiny do not define it.\n#ifndef SS\n #define SS 10\n#endif\n\n// These defs cause trouble on some versions of Arduino\n#undef abs\n#undef round\n#undef double\n\n// Sigh: there is no widespread adoption of htons and friends in the base code, only in some WiFi headers etc\n// that have a lot of excess baggage\n#if RH_PLATFORM != RH_PLATFORM_UNIX && !defined(htons)\n// #ifndef htons\n// These predefined macros availble on modern GCC compilers\n #if   __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__\n  // Atmel processors\n  #define htons(x) ( ((x)<<8) | (((x)>>8)&0xFF) )\n  #define ntohs(x) htons(x)\n  #define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \\\n                   ((x)<< 8 & 0x00FF0000UL) | \\\n                   ((x)>> 8 & 0x0000FF00UL) | \\\n                   ((x)>>24 & 0x000000FFUL) )\n  #define ntohl(x) htonl(x)\n\n #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__\n  // Others\n  #define htons(x) (x)\n  #define ntohs(x) (x)\n  #define htonl(x) (x)\n  #define ntohl(x) (x)\n\n #else\n  #error \"Dont know how to define htons and friends for this processor\" \n #endif\n#endif\n\n// This is the address that indicates a broadcast\n#define RH_BROADCAST_ADDRESS 0xff\n\n#endif\n"
  },
  {
    "path": "STM32ArduinoCompat/HardwareSPI.cpp",
    "content": "// ArduinoCompat/HardwareSPI.cpp\n//\n// Interface between Arduino-like SPI interface and STM32F4 Discovery and similar\n// using STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\n\n#include <RadioHead.h>\n#if (RH_PLATFORM == RH_PLATFORM_STM32STD)\n\n#include <wirish.h>\n#include <HardwareSPI.h>\n#include \"stm32f4xx.h\"\n#include \"stm32f4xx_spi.h\"\nextern \"C\"\n{\n#include \"gdb_stdio.h\"\n}\n\n// Symbolic definitions for the SPI pins we intend to use\n// Currently we only support SPI1\n#define SPIx                           SPI1\n#define SPIx_CLK                       RCC_APB2Periph_SPI1\n#define SPIx_CLK_INIT                  RCC_APB2PeriphClockCmd\n#define SPIx_IRQn                      SPI2_IRQn\n#define SPIx_IRQHANDLER                SPI2_IRQHandler\n\n#define SPIx_SCK_PIN                   GPIO_Pin_5\n#define SPIx_SCK_GPIO_PORT             GPIOA\n#define SPIx_SCK_GPIO_CLK              RCC_AHB1Periph_GPIOA\n#define SPIx_SCK_SOURCE                GPIO_PinSource5\n#define SPIx_SCK_AF                    GPIO_AF_SPI1\n\n#define SPIx_MISO_PIN                  GPIO_Pin_6\n#define SPIx_MISO_GPIO_PORT            GPIOA\n#define SPIx_MISO_GPIO_CLK             RCC_AHB1Periph_GPIOA\n#define SPIx_MISO_SOURCE               GPIO_PinSource6\n#define SPIx_MISO_AF                   GPIO_AF_SPI1\n\n#define SPIx_MOSI_PIN                  GPIO_Pin_7\n#define SPIx_MOSI_GPIO_PORT            GPIOA\n#define SPIx_MOSI_GPIO_CLK             RCC_AHB1Periph_GPIOA\n#define SPIx_MOSI_SOURCE               GPIO_PinSource7\n#define SPIx_MOSI_AF                   GPIO_AF_SPI1\n\nHardwareSPI::HardwareSPI(uint32_t spiPortNumber) :\n    _spiPortNumber(spiPortNumber)\n{\n}\n\nvoid HardwareSPI::begin(SPIFrequency frequency, uint32_t bitOrder, uint32_t mode)\n{\n  GPIO_InitTypeDef GPIO_InitStructure;\n//  NVIC_InitTypeDef NVIC_InitStructure;\n  SPI_InitTypeDef  SPI_InitStructure;\n\n  /* Peripheral Clock Enable -------------------------------------------------*/\n  /* Enable the SPI clock */\n  RCC_APB2PeriphClockCmd(SPIx_CLK, ENABLE);\n  \n  /* Enable GPIO clocks */\n  RCC_AHB1PeriphClockCmd(SPIx_SCK_GPIO_CLK | SPIx_MISO_GPIO_CLK | SPIx_MOSI_GPIO_CLK, ENABLE);\n\n  /* SPI GPIO Configuration --------------------------------------------------*/\n  /* GPIO Deinitialisation */\n  GPIO_DeInit(SPIx_SCK_GPIO_PORT);\n  GPIO_DeInit(SPIx_MISO_GPIO_PORT);\n  GPIO_DeInit(SPIx_MOSI_GPIO_PORT);\n  \n  /* Connect SPI pins to AF5 */  \n  GPIO_PinAFConfig(SPIx_SCK_GPIO_PORT, SPIx_SCK_SOURCE, SPIx_SCK_AF);\n  GPIO_PinAFConfig(SPIx_MISO_GPIO_PORT, SPIx_MISO_SOURCE, SPIx_MISO_AF);    \n  GPIO_PinAFConfig(SPIx_MOSI_GPIO_PORT, SPIx_MOSI_SOURCE, SPIx_MOSI_AF);\n\n  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;\n  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;\n  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;\n  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;\n\n  /* SPI SCK pin configuration */\n  GPIO_InitStructure.GPIO_Pin = SPIx_SCK_PIN;\n  GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStructure);\n  \n  /* SPI  MISO pin configuration */\n  GPIO_InitStructure.GPIO_Pin =  SPIx_MISO_PIN;\n  GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStructure);  \n\n  /* SPI  MOSI pin configuration */\n  GPIO_InitStructure.GPIO_Pin =  SPIx_MOSI_PIN;\n  GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure);\n \n  /* SPI configuration -------------------------------------------------------*/\n  SPI_I2S_DeInit(SPIx);\n  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;\n  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;\n  if (mode == SPI_MODE0)\n  {\n      SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;\n      SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;\n  }\n  else if (mode == SPI_MODE1)\n  {\n      SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;\n      SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;\n  }\n  else if (mode == SPI_MODE2)\n  {\n      SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;\n      SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;\n  }\n  else if (mode == SPI_MODE3)\n  {\n      SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;\n      SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;\n  }\n\n  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;\n  // Prescaler is divided into PCLK2 (84MHz) to get SPI baud rate/clock speed\n  // 256 => 328.125kHz\n  // 128 => 656.25kHz\n  // 64 => 1.3125MHz\n  // 32 => 2.625MHz\n  // 16 => 5.25MHz\n  // 8  => 10.5MHz\n  // 4  => 21.0MHz\n  switch (frequency)\n  {\n      case SPI_21_0MHZ:\n\t  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;\n\t  break;\n      case SPI_10_5MHZ:\n\t  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;\n\t  break;\n      case SPI_5_25MHZ:\n\t  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;\n\t  break;\n      case SPI_2_625MHZ:\n      default:\n\t  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;\n\t  break;\n      case SPI_1_3125MHZ:\n\t  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;\n\t  break;\n      case SPI_656_25KHZ:\n\t  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;\n\t  break;\n      case SPI_328_125KHZ:\n\t  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;\n\t  break;\n\t  \n  }\n\n  if (bitOrder == LSBFIRST)\n      SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;\n  else\n      SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;\n  SPI_InitStructure.SPI_CRCPolynomial = 7;\n  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;\n\n  /* Initializes the SPI communication */\n  SPI_Init(SPIx, &SPI_InitStructure);\n  /* Enable SPI1  */\n  SPI_Cmd(SPIx, ENABLE);\n}\n\nvoid HardwareSPI::end(void)\n{\n    SPI_DeInit(SPIx);\n}\n\nuint8_t HardwareSPI::transfer(uint8_t data)\n{\n    // Wait for TX empty\n    while (SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET)\n\t;\n    SPI_SendData(SPIx, data);\n    // Wait for RX not empty\n    while (SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET)\n\t;\n    return SPI_ReceiveData(SPIx);\n}\n\n#endif\n"
  },
  {
    "path": "STM32ArduinoCompat/HardwareSPI.h",
    "content": "// ArduinoCompat/HardwareSPI.h\n// STM32 implementattion of Arduino compatible SPI class\n\n#ifndef _HardwareSPI_h\n#define _HardwareSPI_h\n\n#include <stdint.h>\n\ntypedef enum SPIFrequency {\n    SPI_21_0MHZ      = 0, /**< 21 MHz */\n    SPI_10_5MHZ      = 1, /**< 10.5 MHz */\n    SPI_5_25MHZ      = 2, /**< 5.25 MHz */\n    SPI_2_625MHZ     = 3, /**< 2.625 MHz */\n    SPI_1_3125MHZ    = 4, /**< 1.3125 MHz */\n    SPI_656_25KHZ    = 5, /**< 656.25 KHz */\n    SPI_328_125KHZ   = 6, /**< 328.125 KHz */\n} SPIFrequency;\n\n#define SPI_MODE0 0x00\n#define SPI_MODE1 0x04\n#define SPI_MODE2 0x08\n#define SPI_MODE3 0x0C\n\nclass HardwareSPI\n{\npublic:\n    HardwareSPI(uint32_t spiPortNumber); // Only port SPI1 is currently supported\n    void begin(SPIFrequency frequency, uint32_t bitOrder, uint32_t mode);\n    void end(void);\n    uint8_t transfer(uint8_t data);\n\nprivate:\n    uint32_t _spiPortNumber; // Not used yet.\n};\nextern HardwareSPI SPI;\n\n\n#endif\n"
  },
  {
    "path": "STM32ArduinoCompat/HardwareSerial.cpp",
    "content": "// ArduinoCompat/HardwareSerial.cpp\n//\n// Author: mikem@airspayce.com\n\n#include <RadioHead.h>\n#if (RH_PLATFORM == RH_PLATFORM_STM32STD)\n#include <HardwareSerial.h>\n#include <stm32f4xx_usart.h>\n\n// Preinstantiated Serial objects\nHardwareSerial Serial1(USART1);\nHardwareSerial Serial2(USART2);\nHardwareSerial Serial3(USART3);\nHardwareSerial Serial4(UART4);\nHardwareSerial Serial5(UART5);\nHardwareSerial Serial6(USART6);\n\n///////////////////////////////////////////////////////////////\n// RingBuffer\n///////////////////////////////////////////////////////////////\n\nRingBuffer::RingBuffer()\n    : _head(0),\n      _tail(0),\n      _overruns(0),\n      _underruns(0)\n{\n}\n\nbool    RingBuffer::isEmpty()\n{\n    return _head == _tail;\n}\t\n\nbool    RingBuffer::isFull()\n{\n    return ((_head + 1) % ARDUINO_RINGBUFFER_SIZE) == _tail;\n}\n\nbool    RingBuffer::write(uint8_t ch)\n{\n    if (isFull())\n    {\n\t_overruns++;\n\treturn false;\n    }\n    _buffer[_head] = ch;\n    if (++_head >= ARDUINO_RINGBUFFER_SIZE)\n\t_head = 0;\n    return true;\n}\n\nuint8_t RingBuffer::read()\n{\n    if (isEmpty())\n    {\n\t_underruns++;\n\treturn 0; // What else can we do?\n    }\n    uint8_t ret = _buffer[_tail];\n    if (++_tail >= ARDUINO_RINGBUFFER_SIZE)\n\t_tail = 0;\n    return ret;\n}\n\n///////////////////////////////////////////////////////////////\n// HardwareSerial\n///////////////////////////////////////////////////////////////\n\n// On STM32F4 Discovery, USART 1 is not very useful conflicts with the Green lED\nHardwareSerial::HardwareSerial(USART_TypeDef* usart)\n    : _usart(usart)\n{\n}\n\nvoid HardwareSerial::begin(unsigned long baud)\n{    \n    USART_InitTypeDef USART_InitStructure;\n    GPIO_InitTypeDef  GPIO_InitStructure_TX;\n    GPIO_InitTypeDef  GPIO_InitStructure_RX;\n\n    // Common GPIO structure init:\n    GPIO_InitStructure_TX.GPIO_Speed = GPIO_Speed_50MHz;\n    GPIO_InitStructure_TX.GPIO_Mode  = GPIO_Mode_AF;\n    GPIO_InitStructure_TX.GPIO_OType = GPIO_OType_PP;\n    GPIO_InitStructure_TX.GPIO_PuPd  = GPIO_PuPd_UP;\n\n    GPIO_InitStructure_RX.GPIO_Speed = GPIO_Speed_50MHz;\n    GPIO_InitStructure_RX.GPIO_Mode  = GPIO_Mode_AF;\n    GPIO_InitStructure_RX.GPIO_OType = GPIO_OType_PP;\n    GPIO_InitStructure_RX.GPIO_PuPd  = GPIO_PuPd_UP;\n    // CTS or SCLK outputs are not supported.\n\n    USART_InitStructure.USART_BaudRate            = baud * 25/8; // Why?\n    // Only 8N1 is currently supported\n    USART_InitStructure.USART_WordLength          = USART_WordLength_8b;  \n    USART_InitStructure.USART_StopBits            = USART_StopBits_1;   \n    USART_InitStructure.USART_Parity              = USART_Parity_No;\n    USART_InitStructure.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;\n    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;\n\n    // Different for each USART:\n    if (_usart == USART1)\n    {\n\t// Initialise the clocks for this USART and its RX, TX pins port\n\tRCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);\n\tRCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);\n\n\tGPIO_PinAFConfig(GPIOA, GPIO_PinSource9,  GPIO_AF_USART1);\n\tGPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);\n\n\tGPIO_InitStructure_TX.GPIO_Pin = GPIO_Pin_9;\n\tGPIO_InitStructure_RX.GPIO_Pin = GPIO_Pin_10;\n\tGPIO_Init(GPIOA, &GPIO_InitStructure_TX);\n\tGPIO_Init(GPIOA, &GPIO_InitStructure_RX);\n\t// Initialise the USART\n\tUSART_Init(USART1, &USART_InitStructure);\n\t// Enable the RXNE interrupt\n\tUSART_ITConfig(USART1, USART_IT_RXNE, ENABLE);\n\t// Enable global interrupt\n\tNVIC_EnableIRQ(USART1_IRQn);\n    }\n    else if (_usart == USART2)\n    {\n\t// Initialise the clocks for this USART and its RX, TX pins port\n\tRCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);\n\tRCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);\n\n\tGPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);\n\tGPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);\n\n\tGPIO_InitStructure_TX.GPIO_Pin = GPIO_Pin_2;\n\tGPIO_InitStructure_RX.GPIO_Pin = GPIO_Pin_3;\n\tGPIO_Init(GPIOA, &GPIO_InitStructure_TX);\n\tGPIO_Init(GPIOA, &GPIO_InitStructure_RX);\n\t// Initialise the USART\n\tUSART_Init(USART2, &USART_InitStructure);\n\t// Enable the RXNE interrupt\n\tUSART_ITConfig(USART2, USART_IT_RXNE, ENABLE);\n\t// Enable global interrupt\n\tNVIC_EnableIRQ(USART2_IRQn);\n    }\n    else if (_usart == USART3)\n    {\n\t// Initialise the clocks for this USART and its RX, TX pins port\n\tRCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);\n\tRCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);\n\n\tGPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);\n\tGPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);\n\n\tGPIO_InitStructure_TX.GPIO_Pin = GPIO_Pin_8;\n\tGPIO_InitStructure_RX.GPIO_Pin = GPIO_Pin_9;\n\tGPIO_Init(GPIOD, &GPIO_InitStructure_TX);\n\tGPIO_Init(GPIOD, &GPIO_InitStructure_RX);\n\t// Initialise the USART\n\tUSART_Init(USART3, &USART_InitStructure);\n\t// Enable the RXNE interrupt\n\tUSART_ITConfig(USART3, USART_IT_RXNE, ENABLE);\n\t// Enable global interrupt\n\tNVIC_EnableIRQ(USART3_IRQn);\n    }\n    else if (_usart == UART4)\n    {\n\t// Initialise the clocks for this USART and its RX, TX pins port\n\tRCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);\n\tRCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);\n\n\tGPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_UART4);\n\tGPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_UART4);\n\n\tGPIO_InitStructure_TX.GPIO_Pin = GPIO_Pin_0;\n\tGPIO_InitStructure_RX.GPIO_Pin = GPIO_Pin_1;\n\tGPIO_Init(GPIOA, &GPIO_InitStructure_TX);\n\tGPIO_Init(GPIOA, &GPIO_InitStructure_RX);\n\t// Initialise the USART\n\tUSART_Init(UART4, &USART_InitStructure);\n\t// Enable the RXNE interrupt\n\tUSART_ITConfig(UART4, USART_IT_RXNE, ENABLE);\n\t// Enable global interrupt\n\tNVIC_EnableIRQ(UART4_IRQn);\n    }\n    else if (_usart == UART5)\n    {\n\t// Initialise the clocks for this USART and its RX, TX pins port\n\tRCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);\n\tRCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD, ENABLE);\n\n\tGPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5);\n\tGPIO_PinAFConfig(GPIOD, GPIO_PinSource2,  GPIO_AF_UART5);\n\n\tGPIO_InitStructure_TX.GPIO_Pin = GPIO_Pin_12;\n\tGPIO_InitStructure_RX.GPIO_Pin = GPIO_Pin_2;\n\tGPIO_Init(GPIOC, &GPIO_InitStructure_TX);\n\tGPIO_Init(GPIOD, &GPIO_InitStructure_RX);\n\t// Initialise the USART\n\tUSART_Init(UART5, &USART_InitStructure);\n\t// Enable the RXNE interrupt\n\tUSART_ITConfig(UART5, USART_IT_RXNE, ENABLE);\n\t// Enable global interrupt\n\tNVIC_EnableIRQ(UART5_IRQn);\n    }\n    else if (_usart == USART6)\n    {\n\t// Initialise the clocks for this USART and its RX, TX pins port\n\tRCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);\n\tRCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);\n\n\tGPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);\n\tGPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);\n\n\tGPIO_InitStructure_TX.GPIO_Pin = GPIO_Pin_6;\n\tGPIO_InitStructure_RX.GPIO_Pin = GPIO_Pin_7;\n\tGPIO_Init(GPIOC, &GPIO_InitStructure_TX);\n\tGPIO_Init(GPIOC, &GPIO_InitStructure_RX);\n\t// Initialise the USART\n\tUSART_Init(USART6, &USART_InitStructure);\n\t// Enable the RXNE interrupt\n\tUSART_ITConfig(USART6, USART_IT_RXNE, ENABLE);\n\t// Enable global interrupt\n\tNVIC_EnableIRQ(USART6_IRQn);\n    }\n\n    USART_Cmd(_usart, ENABLE);\n}\n\nvoid HardwareSerial::end()\n{\n    USART_Cmd(_usart, DISABLE);\n    USART_DeInit(_usart);\n}\n\nint HardwareSerial::available(void)\n{\n    return !_rxRingBuffer.isEmpty();\n}\n\nint HardwareSerial::read(void)\n{\n    return _rxRingBuffer.read();\n}\n\nsize_t HardwareSerial::write(uint8_t ch)\n{\n    _txRingBuffer.write(ch); // Queue it\n    USART_ITConfig(_usart, USART_IT_TXE, ENABLE); // Enable the TX interrupt\n    return 1;\n}\n\nextern \"C\"\n{\n    void USART1_IRQHandler(void)\n    {\n\tif (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)\n\t{\n\t    Serial1._rxRingBuffer.write(USART_ReceiveData(USART1));\n\t}\n\tif (USART_GetITStatus(USART1, USART_IT_TXE) != RESET)\n\t{\n\t    // Transmitter is empty, maybe send another char?\n\t    if (Serial1._txRingBuffer.isEmpty())\n\t\tUSART_ITConfig(USART1, USART_IT_TXE, DISABLE); // No more to send, disable the TX interrupt\n\t    else\n\t\tUSART_SendData(USART1, Serial1._txRingBuffer.read());\n\t}\n    }\n    void USART2_IRQHandler(void)\n    {\n\tif (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)\n\t{\n\t    // Newly received char, try to put it in our rx buffer\n\t    Serial2._rxRingBuffer.write(USART_ReceiveData(USART2));\n\t}\n\tif (USART_GetITStatus(USART2, USART_IT_TXE) != RESET)\n\t{\n\t    // Transmitter is empty, maybe send another char?\n\t    if (Serial2._txRingBuffer.isEmpty())\n\t\tUSART_ITConfig(USART2, USART_IT_TXE, DISABLE); // No more to send, disable the TX interrupt\n\t    else\n\t\tUSART_SendData(USART2, Serial2._txRingBuffer.read());\n\t}\n    }\n    void USART3_IRQHandler(void)\n    {\n\tif (USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)\n\t{\n\t    // Newly received char, try to put it in our rx buffer\n\t    Serial3._rxRingBuffer.write(USART_ReceiveData(USART3));\n\t}\n\tif (USART_GetITStatus(USART3, USART_IT_TXE) != RESET)\n\t{\n\t    // Transmitter is empty, maybe send another char?\n\t    if (Serial3._txRingBuffer.isEmpty())\n\t\tUSART_ITConfig(USART3, USART_IT_TXE, DISABLE); // No more to send, disable the TX interrupt\n\t    else\n\t\tUSART_SendData(USART3, Serial3._txRingBuffer.read());\n\t}\n    }\n    void UART4_IRQHandler(void)\n    {\n\tif (USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)\n\t{\n\t    // Newly received char, try to put it in our rx buffer\n\t    Serial4._rxRingBuffer.write(USART_ReceiveData(UART4));\n\t}\n\tif (USART_GetITStatus(UART4, USART_IT_TXE) != RESET)\n\t{\n\t    // Transmitter is empty, maybe send another char?\n\t    if (Serial4._txRingBuffer.isEmpty())\n\t\tUSART_ITConfig(UART4, USART_IT_TXE, DISABLE); // No more to send, disable the TX interrupt\n\t    else\n\t\tUSART_SendData(UART4, Serial4._txRingBuffer.read());\n\t}\n    }\n    void UART5_IRQHandler(void)\n    {\n\tif (USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)\n\t{\n\t    // Newly received char, try to put it in our rx buffer\n\t    Serial5._rxRingBuffer.write(USART_ReceiveData(UART5));\n\t}\n\tif (USART_GetITStatus(UART5, USART_IT_TXE) != RESET)\n\t{\n\t    // Transmitter is empty, maybe send another char?\n\t    if (Serial5._txRingBuffer.isEmpty())\n\t\tUSART_ITConfig(UART5, USART_IT_TXE, DISABLE); // No more to send, disable the TX interrupt\n\t    else\n\t\tUSART_SendData(UART5, Serial5._txRingBuffer.read());\n\t}\n    }\n    void USART6_IRQHandler(void)\n    {\n\tif (USART_GetITStatus(USART6, USART_IT_RXNE) != RESET)\n\t{\n\t    // Newly received char, try to put it in our rx buffer\n\t    Serial6._rxRingBuffer.write(USART_ReceiveData(USART6));\n\t}\n\tif (USART_GetITStatus(USART6, USART_IT_TXE) != RESET)\n\t{\n\t    // Transmitter is empty, maybe send another char?\n\t    if (Serial6._txRingBuffer.isEmpty())\n\t\tUSART_ITConfig(USART6, USART_IT_TXE, DISABLE); // No more to send, disable the TX interrupt\n\t    else\n\t\tUSART_SendData(USART6, Serial6._txRingBuffer.read());\n\t}\n    }\n}\n\n#endif\n"
  },
  {
    "path": "STM32ArduinoCompat/HardwareSerial.h",
    "content": "// ArduinoCompat/HardwareSerial.h\n// STM32 implementation of Arduino compatible serial class\n\n#include <RadioHead.h>\n#if (RH_PLATFORM == RH_PLATFORM_STM32STD)\n#ifndef _HardwareSerial_h\n#define _HardwareSerial_h\n\n#include <stdint.h>\n#include <stdio.h>\n#include <stm32f4xx.h>\n\n#ifndef ARDUINO_RINGBUFFER_SIZE\n#define ARDUINO_RINGBUFFER_SIZE 64\n#endif\n\nclass RingBuffer\n{\npublic:\n    RingBuffer();\n    bool    isEmpty();\n    bool    isFull();\n    bool    write(uint8_t ch);\n    uint8_t read();\n\nprivate:\n    uint8_t _buffer[ARDUINO_RINGBUFFER_SIZE]; // In fact we can hold up to ARDUINO_RINGBUFFER_SIZE-1 bytes\n    uint16_t _head;      // Index of next write\n    uint16_t _tail;      // Index of next read\n    uint32_t _overruns;  // Write attempted when buffer full\n    uint32_t _underruns; // Read attempted when buffer empty\n};\n\n// Mostly compatible wuith Arduino HardwareSerial\n// Theres just enough here to support RadioHead RH_Serial\nclass HardwareSerial\n{\npublic:\n    HardwareSerial(USART_TypeDef* usart);\n    void begin(unsigned long baud);\n    void end();\n    virtual int available(void);\n    virtual int read(void);\n    virtual size_t write(uint8_t);\n    inline size_t write(unsigned long n) { return write((uint8_t)n); }\n    inline size_t write(long n) { return write((uint8_t)n); }\n    inline size_t write(unsigned int n) { return write((uint8_t)n); }\n    inline size_t write(int n) { return write((uint8_t)n); }\n\n    // These need to be public so the IRQ handler can read and write to them:\n    RingBuffer     _rxRingBuffer;\n    RingBuffer     _txRingBuffer;\n\nprivate:\n    USART_TypeDef* _usart;\n\n};\n\n// Predefined serial ports are configured so:\n// Serial       STM32 UART   RX pin   Tx Pin   Comments\n// Serial1      USART1       PA10     PA9      TX Conflicts with GREEN LED on Discovery\n// Serial2      USART2       PA3      PA2\n// Serial3      USART3       PD9      PD10     \n// Serial4      UART4        PA1      PA0      TX conflicts with USER button on Discovery\n// Serial5      UART5        PD2      PC12     TX conflicts with CS43L22 SDIN on Discovery\n// Serial6      USART6       PC7      PC6      RX conflicts with CS43L22 MCLK on Discovery\n//\n// All ports are idle HIGH, LSB first, 8 bits, No parity, 1 stop bit\nextern HardwareSerial Serial1;\nextern HardwareSerial Serial2;\nextern HardwareSerial Serial3;\nextern HardwareSerial Serial4;\nextern HardwareSerial Serial5;\nextern HardwareSerial Serial6;\n\n#endif\n\n#endif\n"
  },
  {
    "path": "STM32ArduinoCompat/README",
    "content": "This directory contains some files to allow RadioHead to be built on STM32F4\nDiscovery boards, using the native STM Firmware libraries, in order to support\nCodec2WalkieTalkie and other projects.\n\nThe files provide just enough Arduino compatibility to allow RadioHead to\nbuild in that environment.\n"
  },
  {
    "path": "STM32ArduinoCompat/wirish.cpp",
    "content": "// ArduinoCompat/wirish.cpp\n//\n// Arduino-like API for STM32F4 Discovery and similar\n// using STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\n\n#include <RadioHead.h>\n#if (RH_PLATFORM == RH_PLATFORM_STM32STD)\n#include <wirish.h>\n\nSerialUSBClass SerialUSB;\n\n// Describes all the STM32 things we need to know about a digital IO pin to\n// make it input or output or to configure as an interrupt\ntypedef struct\n{\n    uint32_t         ahbperiph;\n    GPIO_TypeDef*    port;\n    uint16_t         pin;\n    uint8_t          extiportsource;\n    uint8_t          extipinsource;\n} GPIOPin;\n\n// These describe the registers and bits for each digital IO pin to allow us to \n// provide Arduino-like pin addressing, digitalRead etc.\n// Indexed by pin number\nGPIOPin pins[] = \n{\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_0,  EXTI_PortSourceGPIOA, EXTI_PinSource0  }, // 0 = PA0\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_1,  EXTI_PortSourceGPIOA, EXTI_PinSource1  },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_2,  EXTI_PortSourceGPIOA, EXTI_PinSource2  },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_3,  EXTI_PortSourceGPIOA, EXTI_PinSource3  },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_4,  EXTI_PortSourceGPIOA, EXTI_PinSource4  },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_5,  EXTI_PortSourceGPIOA, EXTI_PinSource5  },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_6,  EXTI_PortSourceGPIOA, EXTI_PinSource6  },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_7,  EXTI_PortSourceGPIOA, EXTI_PinSource7  },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_8,  EXTI_PortSourceGPIOA, EXTI_PinSource8  },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_9,  EXTI_PortSourceGPIOA, EXTI_PinSource9  },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_10, EXTI_PortSourceGPIOA, EXTI_PinSource10 },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_11, EXTI_PortSourceGPIOA, EXTI_PinSource11 },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_12, EXTI_PortSourceGPIOA, EXTI_PinSource12 },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_13, EXTI_PortSourceGPIOA, EXTI_PinSource13 },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_14, EXTI_PortSourceGPIOA, EXTI_PinSource14 },\n    { RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_15, EXTI_PortSourceGPIOA, EXTI_PinSource15 }, // 15 = PA15\n\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_0,  EXTI_PortSourceGPIOB, EXTI_PinSource0  }, // 16 = PB0\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_1,  EXTI_PortSourceGPIOB, EXTI_PinSource1  },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_2,  EXTI_PortSourceGPIOB, EXTI_PinSource2  },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_3,  EXTI_PortSourceGPIOB, EXTI_PinSource3  },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_4,  EXTI_PortSourceGPIOB, EXTI_PinSource4  },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_5,  EXTI_PortSourceGPIOB, EXTI_PinSource5  },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_6,  EXTI_PortSourceGPIOB, EXTI_PinSource6  },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_7,  EXTI_PortSourceGPIOB, EXTI_PinSource7  },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_8,  EXTI_PortSourceGPIOB, EXTI_PinSource8  },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_9,  EXTI_PortSourceGPIOB, EXTI_PinSource9  },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_10, EXTI_PortSourceGPIOB, EXTI_PinSource10 },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_11, EXTI_PortSourceGPIOB, EXTI_PinSource11 },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_12, EXTI_PortSourceGPIOB, EXTI_PinSource12 },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_13, EXTI_PortSourceGPIOB, EXTI_PinSource13 },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_14, EXTI_PortSourceGPIOB, EXTI_PinSource14 },\n    { RCC_AHB1Periph_GPIOB, GPIOB, GPIO_Pin_15, EXTI_PortSourceGPIOB, EXTI_PinSource15 }, // 31 = PB15\n\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_0,  EXTI_PortSourceGPIOC, EXTI_PinSource0  }, // 32 = PC0\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_1,  EXTI_PortSourceGPIOC, EXTI_PinSource1  },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_2,  EXTI_PortSourceGPIOC, EXTI_PinSource2  },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_3,  EXTI_PortSourceGPIOC, EXTI_PinSource3  },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_4,  EXTI_PortSourceGPIOC, EXTI_PinSource4  },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_5,  EXTI_PortSourceGPIOC, EXTI_PinSource5  },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_6,  EXTI_PortSourceGPIOC, EXTI_PinSource6  },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_7,  EXTI_PortSourceGPIOC, EXTI_PinSource7  },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_8,  EXTI_PortSourceGPIOC, EXTI_PinSource8  },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_9,  EXTI_PortSourceGPIOC, EXTI_PinSource9  },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_10, EXTI_PortSourceGPIOC, EXTI_PinSource10 },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_11, EXTI_PortSourceGPIOC, EXTI_PinSource11 },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_12, EXTI_PortSourceGPIOC, EXTI_PinSource12 },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_13, EXTI_PortSourceGPIOC, EXTI_PinSource13 },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_14, EXTI_PortSourceGPIOC, EXTI_PinSource14 },\n    { RCC_AHB1Periph_GPIOC, GPIOC, GPIO_Pin_15, EXTI_PortSourceGPIOC, EXTI_PinSource15 }, // 47 = PC15\n\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_0,  EXTI_PortSourceGPIOD, EXTI_PinSource0  }, // 48 = PD0\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_1,  EXTI_PortSourceGPIOD, EXTI_PinSource1  },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_2,  EXTI_PortSourceGPIOD, EXTI_PinSource2  },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_3,  EXTI_PortSourceGPIOD, EXTI_PinSource3  },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_4,  EXTI_PortSourceGPIOD, EXTI_PinSource4  },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_5,  EXTI_PortSourceGPIOD, EXTI_PinSource5  },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_6,  EXTI_PortSourceGPIOD, EXTI_PinSource6  },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_7,  EXTI_PortSourceGPIOD, EXTI_PinSource7  },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_8,  EXTI_PortSourceGPIOD, EXTI_PinSource8  },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_9,  EXTI_PortSourceGPIOD, EXTI_PinSource9  },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_10, EXTI_PortSourceGPIOD, EXTI_PinSource10 },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_11, EXTI_PortSourceGPIOD, EXTI_PinSource11 },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_12, EXTI_PortSourceGPIOD, EXTI_PinSource12 },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_13, EXTI_PortSourceGPIOD, EXTI_PinSource13 },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_14, EXTI_PortSourceGPIOD, EXTI_PinSource14 },\n    { RCC_AHB1Periph_GPIOD, GPIOD, GPIO_Pin_15, EXTI_PortSourceGPIOD, EXTI_PinSource15 }, // 63 = PD15\n\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_0,  EXTI_PortSourceGPIOE, EXTI_PinSource0  }, // 64 = PE0\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_1,  EXTI_PortSourceGPIOE, EXTI_PinSource1  },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_2,  EXTI_PortSourceGPIOE, EXTI_PinSource2  },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_3,  EXTI_PortSourceGPIOE, EXTI_PinSource3  },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_4,  EXTI_PortSourceGPIOE, EXTI_PinSource4  },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_5,  EXTI_PortSourceGPIOE, EXTI_PinSource5  },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_6,  EXTI_PortSourceGPIOE, EXTI_PinSource6  },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_7,  EXTI_PortSourceGPIOE, EXTI_PinSource7  },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_8,  EXTI_PortSourceGPIOE, EXTI_PinSource8  },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_9,  EXTI_PortSourceGPIOE, EXTI_PinSource9  },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_10, EXTI_PortSourceGPIOE, EXTI_PinSource10 },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_11, EXTI_PortSourceGPIOE, EXTI_PinSource11 },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_12, EXTI_PortSourceGPIOE, EXTI_PinSource12 },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_13, EXTI_PortSourceGPIOE, EXTI_PinSource13 },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_14, EXTI_PortSourceGPIOE, EXTI_PinSource14 },\n    { RCC_AHB1Periph_GPIOE, GPIOE, GPIO_Pin_15, EXTI_PortSourceGPIOE, EXTI_PinSource15 }, // 79 = PE15\n\n};\n#define NUM_PINS (sizeof(pins) / sizeof(GPIOPin))\n\ntypedef struct\n{\n    uint32_t  extiline;\n    uint8_t   extiirqn;\n    void      (*handler)(void);\n} IRQLine;\n\n// IRQ line data indexed by pin source number with its port\n// and the programmable handler that will handle interrupts on that line\nIRQLine irqlines[] = \n{\n    { EXTI_Line0,  EXTI0_IRQn,     0 },\n    { EXTI_Line1,  EXTI1_IRQn,     0 },\n    { EXTI_Line2,  EXTI2_IRQn,     0 },\n    { EXTI_Line3,  EXTI3_IRQn,     0 },\n    { EXTI_Line4,  EXTI4_IRQn,     0 },\n    { EXTI_Line5,  EXTI9_5_IRQn,   0 },\n    { EXTI_Line6,  EXTI9_5_IRQn,   0 },\n    { EXTI_Line7,  EXTI9_5_IRQn,   0 },\n    { EXTI_Line8,  EXTI9_5_IRQn,   0 },\n    { EXTI_Line9,  EXTI9_5_IRQn,   0 },\n    { EXTI_Line10, EXTI15_10_IRQn, 0 },\n    { EXTI_Line11, EXTI15_10_IRQn, 0 },\n    { EXTI_Line12, EXTI15_10_IRQn, 0 },\n    { EXTI_Line13, EXTI15_10_IRQn, 0 },\n    { EXTI_Line14, EXTI15_10_IRQn, 0 },\n    { EXTI_Line15, EXTI15_10_IRQn, 0 },\n};\n\n#define NUM_IRQ_LINES (sizeof(irqlines) / sizeof(IRQLine))\n\n// Functions we expect to find in the sketch\nextern void setup();\nextern void loop();\n\nvolatile unsigned long systick_count = 0;\n\nvoid SysTickConfig()\n{\n    /* Setup SysTick Timer for 1ms interrupts  */\n    if (SysTick_Config(SystemCoreClock / 1000))\n    {\n\t/* Capture error */\n\twhile (1);\n    }\n    \n    /* Configure the SysTick handler priority */\n    NVIC_SetPriority(SysTick_IRQn, 0x0);\n    // SysTick_Handler will now be called every 1 ms\n}\n\n// These interrupt handlers have to be extern C else they dont get linked in to the interrupt vectors\nextern \"C\"\n{\n    // Called every 1 ms\n    void SysTick_Handler(void)\n    {\n\tsystick_count++;\n    }\n\n    // Interrupt handlers for optional external GPIO interrupts\n    void EXTI0_IRQHandler(void)\n    {\n\tif (EXTI_GetITStatus(EXTI_Line0) != RESET)\n\t{\n\t    if (irqlines[0].handler)\n\t\tirqlines[0].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line0);\n\t}\n    }\n    void EXTI1_IRQHandler(void)\n    {\n\tif (EXTI_GetITStatus(EXTI_Line1) != RESET)\n\t{\n\t    if (irqlines[1].handler)\n\t\tirqlines[1].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line1);\n\t}\n    }\n    void EXTI2_IRQHandler(void)\n    {\n\tif (EXTI_GetITStatus(EXTI_Line2) != RESET)\n\t{\n\t    if (irqlines[2].handler)\n\t\tirqlines[2].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line2);\n\t}\n    }\n    void EXTI3_IRQHandler(void)\n    {\n\tif (EXTI_GetITStatus(EXTI_Line3) != RESET)\n\t{\n\t    if (irqlines[3].handler)\n\t\tirqlines[3].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line3);\n\t}\n    }\n    void EXTI4_IRQHandler(void)\n    {\n\tif (EXTI_GetITStatus(EXTI_Line4) != RESET)\n\t{\n\t    if (irqlines[4].handler)\n\t\tirqlines[4].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line4);\n\t}\n    }\n    void EXTI9_5_IRQHandler(void)\n    {\n\tif (EXTI_GetITStatus(EXTI_Line5) != RESET)\n\t{\n\t    if (irqlines[5].handler)\n\t\tirqlines[5].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line5);\n\t}\n\tif (EXTI_GetITStatus(EXTI_Line6) != RESET)\n\t{\n\t    if (irqlines[6].handler)\n\t\tirqlines[6].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line6);\n\t}\n\tif (EXTI_GetITStatus(EXTI_Line7) != RESET)\n\t{\n\t    if (irqlines[7].handler)\n\t\tirqlines[7].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line7);\n\t}\n\tif (EXTI_GetITStatus(EXTI_Line8) != RESET)\n\t{\n\t    if (irqlines[8].handler)\n\t\tirqlines[8].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line8);\n\t}\n\tif (EXTI_GetITStatus(EXTI_Line9) != RESET)\n\t{\n\t    if (irqlines[9].handler)\n\t\tirqlines[9].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line9);\n\t}\n    }\n    void EXTI15_10_IRQHandler(void)\n    {\n\tif (EXTI_GetITStatus(EXTI_Line10) != RESET)\n\t{\n\t    if (irqlines[10].handler)\n\t\tirqlines[10].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line10);\n\t}\n\tif (EXTI_GetITStatus(EXTI_Line11) != RESET)\n\t{\n\t    if (irqlines[11].handler)\n\t\tirqlines[11].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line11);\n\t}\n\tif (EXTI_GetITStatus(EXTI_Line12) != RESET)\n\t{\n\t    if (irqlines[12].handler)\n\t\tirqlines[12].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line12);\n\t}\n\tif (EXTI_GetITStatus(EXTI_Line13) != RESET)\n\t{\n\t    if (irqlines[13].handler)\n\t\tirqlines[13].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line13);\n\t}\n\tif (EXTI_GetITStatus(EXTI_Line14) != RESET)\n\t{\n\t    if (irqlines[14].handler)\n\t\tirqlines[14].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line14);\n\t}\n\tif (EXTI_GetITStatus(EXTI_Line15) != RESET)\n\t{\n\t    if (irqlines[15].handler)\n\t\tirqlines[15].handler();\n\t    EXTI_ClearITPendingBit(EXTI_Line15);\n\t}\n    }\n}\n\n// The sketch we want to run\n//#include \"examples/rf22/rf22_client/rf22_client.pde\"\n\n// Run the Arduino standard functions in the main loop\nint main(int argc, char** argv)\n{\n    SysTickConfig();\n    // Seed the random number generator\n//    srand(getpid() ^ (unsigned) time(NULL)/2);\n    setup();\n    while (1)\n\tloop();\n}\n\nvoid pinMode(uint8_t pin, WiringPinMode mode)\n{\n    if (pin > NUM_PINS)\n\treturn;\n    // Enable the GPIO clock\n    RCC_AHB1PeriphClockCmd(pins[pin].ahbperiph, ENABLE);\n    GPIO_InitTypeDef GPIO_InitStructure;\n    GPIO_InitStructure.GPIO_Pin = pins[pin].pin;\n    if (mode == INPUT)\n\tGPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; // REVISIT\n    else if (mode == OUTPUT)\n\tGPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; // REVISIT\n    else\n\treturn; // Unknown so far\n    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;\n    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;\n    GPIO_Init(pins[pin].port, &GPIO_InitStructure);\n}\n\n// This takes about 150ns on STM32F4 Discovery\nvoid digitalWrite(uint8_t pin, uint8_t val)\n{\n    if (pin > NUM_PINS)\n\treturn;\n    if (val)\n\tGPIO_SetBits(pins[pin].port, pins[pin].pin);\n    else\n\tGPIO_ResetBits(pins[pin].port, pins[pin].pin);\n}\n\nuint8_t digitalRead(uint8_t pin)\n{\n    if (pin > NUM_PINS)\n\treturn 0;\n    return GPIO_ReadInputDataBit(pins[pin].port, pins[pin].pin);\n}\n\nvoid attachInterrupt(uint8_t pin, void (*handler)(void), int mode)\n{\n    EXTI_InitTypeDef EXTI_InitStructure;\n    NVIC_InitTypeDef NVIC_InitStructure;\n\n    // Record the handler to call when the interrupt occurs\n    irqlines[pins[pin].extipinsource].handler = handler;\n\n    /* Connect EXTI Line to GPIO Pin */\n    SYSCFG_EXTILineConfig(pins[pin].extiportsource, pins[pin].extipinsource);\n\n    /* Configure EXTI line */\n    EXTI_InitStructure.EXTI_Line = irqlines[pins[pin].extipinsource].extiline;\n\n    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;\n    if (mode == RISING)\n\tEXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  \n    else if (mode == FALLING)\n\tEXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;  \n    else if (mode == CHANGE)\n\tEXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;  \n    EXTI_InitStructure.EXTI_LineCmd = ENABLE;\n    EXTI_Init(&EXTI_InitStructure);\n\n    /* Enable and set EXTI Interrupt to the lowest priority */\n    NVIC_InitStructure.NVIC_IRQChannel = irqlines[pins[pin].extipinsource].extiirqn;\n    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;\n    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;\n    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;\n\n    NVIC_Init(&NVIC_InitStructure); \n\n    // The relevant EXTI?_IRQHandler\n    // will now be called when the pin makes the selected transition\n}\n\nvoid delay(unsigned long ms)\n{\n    unsigned long start = millis();\n\n    while (millis() - start < ms)\n\t;\n}\n\nunsigned long millis()\n{\n    return systick_count;\n}\n\nlong random(long from, long to)\n{\n    return from + (RNG_GetRandomNumber() % (to - from));\n}\n\nlong random(long to)\n{\n    return random(0, to);\n}\n\nextern \"C\"\n{\n    // These need to be in C land for correct linking\n    void _init() {}\n    void _fini() {}\n}\n\n#endif\n"
  },
  {
    "path": "STM32ArduinoCompat/wirish.h",
    "content": "// ArduinoCompat/wirish.h\n\n#ifndef _wirish_h\n#define _wirish_h\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <stm32f4xx_rng.h>\n\n#define PROGMEM\n#define memcpy_P memcpy\n\ntypedef enum WiringPinMode {\n    OUTPUT, /**< Basic digital output: when the pin is HIGH, the\n               voltage is held at +3.3v (Vcc) and when it is LOW, it\n               is pulled down to ground. */\n\n    OUTPUT_OPEN_DRAIN, /**< In open drain mode, the pin indicates\n                          \"low\" by accepting current flow to ground\n                          and \"high\" by providing increased\n                          impedance. An example use would be to\n                          connect a pin to a bus line (which is pulled\n                          up to a positive voltage by a separate\n                          supply through a large resistor). When the\n                          pin is high, not much current flows through\n                          to ground and the line stays at positive\n                          voltage; when the pin is low, the bus\n                          \"drains\" to ground with a small amount of\n                          current constantly flowing through the large\n                          resistor from the external supply. In this\n                          mode, no current is ever actually sourced\n                          from the pin. */\n\n    INPUT, /**< Basic digital input. The pin voltage is sampled; when\n              it is closer to 3.3v (Vcc) the pin status is high, and\n              when it is closer to 0v (ground) it is low. If no\n              external circuit is pulling the pin voltage to high or\n              low, it will tend to randomly oscillate and be very\n              sensitive to noise (e.g., a breath of air across the pin\n              might cause the state to flip). */\n\n    INPUT_ANALOG, /**< This is a special mode for when the pin will be\n                     used for analog (not digital) reads.  Enables ADC\n                     conversion to be performed on the voltage at the\n                     pin. */\n\n    INPUT_PULLUP, /**< The state of the pin in this mode is reported\n                     the same way as with INPUT, but the pin voltage\n                     is gently \"pulled up\" towards +3.3v. This means\n                     the state will be high unless an external device\n                     is specifically pulling the pin down to ground,\n                     in which case the \"gentle\" pull up will not\n                     affect the state of the input. */\n\n    INPUT_PULLDOWN, /**< The state of the pin in this mode is reported\n                       the same way as with INPUT, but the pin voltage\n                       is gently \"pulled down\" towards 0v. This means\n                       the state will be low unless an external device\n                       is specifically pulling the pin up to 3.3v, in\n                       which case the \"gentle\" pull down will not\n                       affect the state of the input. */\n\n    INPUT_FLOATING, /**< Synonym for INPUT. */\n\n    PWM, /**< This is a special mode for when the pin will be used for\n            PWM output (a special case of digital output). */\n\n    PWM_OPEN_DRAIN, /**< Like PWM, except that instead of alternating\n                       cycles of LOW and HIGH, the voltage on the pin\n                       consists of alternating cycles of LOW and\n                       floating (disconnected). */\n} WiringPinMode;\n\nextern void pinMode(uint8_t pin, WiringPinMode mode);\nextern uint32_t millis();\nextern void delay(uint32_t millis);\nextern void attachInterrupt(uint8_t, void (*)(void), int mode);\nextern void digitalWrite(uint8_t pin, uint8_t val);\nextern uint8_t digitalRead(uint8_t pin);\n\n//extern long random(long to);\n//extern long random(long from, long to);\n\n#define HIGH 0x1\n#define LOW  0x0\n\n#define LSBFIRST 0\n#define MSBFIRST 1\n\n#define CHANGE 1\n#define FALLING 2\n#define RISING 3\n\n// Equivalent to HardwareSerial in Arduino\nclass SerialUSBClass\n{\npublic:\n#define DEC 10\n#define HEX 16\n#define OCT 8\n#define BIN 2\n\n    // TODO: move these from being inlined\n    void begin(int baud) {}\n\n    size_t println(const char* s)\n    {\n        print(s);\n        printf(\"\\n\");\n        return 0;\n    }\n    size_t print(const char* s)\n    {\n        printf(s);\n        return 0;\n    }\n    size_t print(unsigned int n, int base = DEC)\n    {\n        if (base == DEC)\n            printf(\"%d\", n);\n        else if (base == HEX)\n            printf(\"%02x\", n);\n        else if (base == OCT)\n\t    printf(\"%o\", n);\n        // TODO: BIN\n\treturn 0;\n    }\n    size_t print(char ch)\n    {\n       printf(\"%c\", ch);\n       return 0;\n    }\n    size_t println(char ch)\n    {\n        printf(\"%c\\n\", ch);\n\treturn 0;\n    }\n    size_t print(unsigned char ch, int base = DEC)\n    {\n        return print((unsigned int)ch, base);\n    }\n    size_t println(unsigned char ch, int base = DEC)\n    {\n        print((unsigned int)ch, base);\n        printf(\"\\n\");\n\treturn 0;\n    }\n\n};\n\n// Global instance of the Serial output\nextern SerialUSBClass SerialUSB;\n\n#endif\n\n"
  },
  {
    "path": "examples/ask/ask_receiver/ask_receiver.pde",
    "content": "// ask_receiver.pde\n// -*- mode: C++ -*-\n// Simple example of how to use RadioHead to receive messages\n// with a simple ASK transmitter in a very simple way.\n// Implements a simplex (one-way) receiver with an Rx-B1 module\n\n#include <RH_ASK.h>\n#include <SPI.h> // Not actualy used but needed to compile\n\nRH_ASK driver;\n// RH_ASK driver(2000, 2, 4, 5); // ESP8266: do not use pin 11\n\nvoid setup()\n{\n    Serial.begin(9600);\t// Debugging only\n    if (!driver.init())\n         Serial.println(\"init failed\");\n}\n\nvoid loop()\n{\n    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];\n    uint8_t buflen = sizeof(buf);\n\n    if (driver.recv(buf, &buflen)) // Non-blocking\n    {\n\tint i;\n\n\t// Message with a good checksum received, dump it.\n\tdriver.printBuffer(\"Got:\", buf, buflen);\n    }\n}\n"
  },
  {
    "path": "examples/ask/ask_reliable_datagram_client/ask_reliable_datagram_client.pde",
    "content": "// ask_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_ASK driver to control a ASK radio.\n// It is designed to work with the other example ask_reliable_datagram_server\n// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy\n\n#include <RHReliableDatagram.h>\n#include <RH_ASK.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_ASK driver;\n// RH_ASK driver(2000, 2, 4, 5); // ESP8266: do not use pin 11\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_ASK_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to ask_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is ask_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/ask/ask_reliable_datagram_server/ask_reliable_datagram_server.pde",
    "content": "// ask_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_ASK driver to control a ASK radio.\n// It is designed to work with the other example ask_reliable_datagram_client\n// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy\n\n#include <RHReliableDatagram.h>\n#include <RH_ASK.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_ASK driver;\n// RH_ASK driver(2000, 2, 4, 5); // ESP8266: do not use pin 11\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_ASK_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  if (manager.available())\n  {\n    // Wait for a message addressed to us from the client\n    uint8_t len = sizeof(buf);\n    uint8_t from;\n    if (manager.recvfromAck(buf, &len, &from))\n    {\n      Serial.print(\"got request from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n\n      // Send a reply back to the originator client\n      if (!manager.sendtoWait(data, sizeof(data), from))\n        Serial.println(\"sendtoWait failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/ask/ask_transmitter/ask_transmitter.pde",
    "content": "// ask_transmitter.pde\n// -*- mode: C++ -*-\n// Simple example of how to use RadioHead to transmit messages\n// with a simple ASK transmitter in a very simple way.\n// Implements a simplex (one-way) transmitter with an TX-C1 module\n\n#include <RH_ASK.h>\n#include <SPI.h> // Not actually used but needed to compile\n\nRH_ASK driver;\n// RH_ASK driver(2000, 2, 4, 5); // ESP8266: do not use pin 11\n\nvoid setup()\n{\n    Serial.begin(9600);\t  // Debugging only\n    if (!driver.init())\n         Serial.println(\"init failed\");\n}\n\nvoid loop()\n{\n    const char *msg = \"hello\";\n\n    driver.send((uint8_t *)msg, strlen(msg));\n    driver.waitPacketSent();\n    delay(200);\n}\n"
  },
  {
    "path": "examples/cc110/cc110_client/cc110_client.pde",
    "content": "// cc110_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing client\n// with the RH_CC110 class. RH_CC110 class does not provide for addressing or\n// reliability, so you should only use RH_CC110 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example cc110_server\n// Tested with Teensy 3.1 and Anaren 430BOOST-CC110L\n\n#include <SPI.h>\n#include <RH_CC110.h>\n\n// Singleton instance of the radio driver\nRH_CC110 cc110;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial)\n    ; // wait for serial port to connect. Needed for native USB\n\n  // CC110L may be equipped with either 26 or 27MHz crystals. You MUST\n  // tell the driver if a 27MHz crystal is installed for the correct configuration to\n  // occur. Failure to correctly set this flag will cause incorrect frequency and modulation\n  // characteristics to be used. You can call this function, or pass it to the constructor\n  cc110.setIs27MHz(true); // Anaren 430BOOST-CC110L Air BoosterPack test boards have 27MHz\n  if (!cc110.init())\n    Serial.println(\"init failed\");\n  // After init(), the following default values apply:\n  // TxPower: TransmitPower5dBm\n  // Frequency: 915.0\n  // Modulation: GFSK_Rb1_2Fd5_2 (GFSK, Data Rate: 1.2kBaud, Dev: 5.2kHz, RX BW 58kHz, optimised for sensitivity)\n  // Sync Words: 0xd3, 0x91\n  // But you can change them:\n//  cc110.setTxPower(RH_CC110::TransmitPowerM30dBm);\n//  cc110.setModemConfig(RH_CC110::GFSK_Rb250Fd127);\n//cc110.setFrequency(928.0);\n}\n\nvoid loop()\n{\n  Serial.println(\"Sending to cc110_server\");\n  // Send a message to cc110_server\n  uint8_t data[] = \"Hello World!\";\n  cc110.send(data, sizeof(data));\n  \n  cc110.waitPacketSent();\n  // Now wait for a reply\n  uint8_t buf[RH_CC110_MAX_MESSAGE_LEN];\n  uint8_t len = sizeof(buf);\n\n  if (cc110.waitAvailableTimeout(3000))\n  { \n    // Should be a reply message for us now   \n    if (cc110.recv(buf, &len))\n   {\n      Serial.print(\"got reply: \");\n      Serial.println((char*)buf);\n//      Serial.print(\"RSSI: \");\n//      Serial.println(cc110.lastRssi(), DEC);    \n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n  else\n  {\n    Serial.println(\"No reply, is cc110_server running?\");\n  }\n\n  delay(400);\n}\n\n\n"
  },
  {
    "path": "examples/cc110/cc110_server/cc110_server.pde",
    "content": "// cc110_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing server\n// with the RH_CC110 class. RH_CC110 class does not provide for addressing or\n// reliability, so you should only use RH_CC110  if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example cc110_client\n// Tested with Teensy 3.1 and Anaren 430BOOST-CC110L\n\n\n#include <SPI.h>\n#include <RH_CC110.h>\n\n// Singleton instance of the radio driver\nRH_CC110 cc110;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial)\n    ; // wait for serial port to connect. Needed for native USB\n\n  // CC110L may be equipped with either 26 or 27MHz crystals. You MUST\n  // tell the driver if a 27MHz crystal is installed for the correct configuration to\n  // occur. Failure to correctly set this flag will cause incorrect frequency and modulation\n  // characteristics to be used. You can call this function, or pass it to the constructor\n  cc110.setIs27MHz(true); // Anaren 430BOOST-CC110L Air BoosterPack test boards have 27MHz\n  if (!cc110.init())\n    Serial.println(\"init failed\");\n  // After init(), the following default values apply:\n  // TxPower: TransmitPower5dBm\n  // Frequency: 915.0\n  // Modulation: GFSK_Rb1_2Fd5_2 (GFSK, Data Rate: 1.2kBaud, Dev: 5.2kHz, RX BW 58kHz, optimised for sensitivity)\n  // Sync Words: 0xd3, 0x91\n  // But you can change them:\n//  cc110.setTxPower(RH_CC110::TransmitPowerM30dBm);\n//  cc110.setModemConfig(RH_CC110::GFSK_Rb250Fd127);\n//cc110.setFrequency(928.0);\n}\n\nvoid loop()\n{\n  if (cc110.available())\n  {\n    // Should be a message for us now   \n    uint8_t buf[RH_CC110_MAX_MESSAGE_LEN];\n    uint8_t len = sizeof(buf);\n    if (cc110.recv(buf, &len))\n    {\n//      RH_CC110::printBuffer(\"request: \", buf, len);\n      Serial.print(\"got request: \");\n      Serial.println((char*)buf);\n//      Serial.print(\"RSSI: \");\n//      Serial.println(cc110.lastRssi(), DEC);\n      \n      // Send a reply\n      uint8_t data[] = \"And hello back to you\";\n      cc110.send(data, sizeof(data));\n      cc110.waitPacketSent();\n      Serial.println(\"Sent a reply\");\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n}\n\n\n"
  },
  {
    "path": "examples/mrf89/mrf89_client/mrf89_client.pde",
    "content": "// mrf89_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing client\n// with the RH_MRF89 class. RH_MRF89 class does not provide for addressing or\n// reliability, so you should only use RH_RF95 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example mrf89_server\n// Tested with Teensy and MRF89XAM9A\n\n#include <SPI.h>\n#include <RH_MRF89.h>\n\n// Singleton instance of the radio driver\nRH_MRF89 mrf89;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial)\n    ; // wait for serial port to connect. Needed for native USB\n\n  if (!mrf89.init())\n    Serial.println(\"init failed\");\n  // Default after init is 1dBm, 915.4MHz, FSK_Rb20Fd40  \n  // But you can change that if you want:\n//  mrf89.setTxPower(RH_MRF89_TXOPVAL_M8DBM); // Min power -8dBm\n//  mrf89.setTxPower(RH_MRF89_TXOPVAL_13DBM); // Max power 13dBm\n//  if (!mrf89.setFrequency(920.0))\n//    Serial.println(\"setFrequency failed\");\n//  if (!mrf89.setModemConfig(RH_MRF89::FSK_Rb200Fd200)) // Fastest\n//    Serial.println(\"setModemConfig failed\");\n}\n\nvoid loop()\n{\n  Serial.println(\"Sending to mrf89_server\");\n  // Send a message to mrf89_server\n  uint8_t data[] = \"Hello World!\";\n  mrf89.send(data, sizeof(data));\n  \n  mrf89.waitPacketSent();\n  // Now wait for a reply\n  uint8_t buf[RH_MRF89_MAX_MESSAGE_LEN];\n  uint8_t len = sizeof(buf);\n\n  if (mrf89.waitAvailableTimeout(3000))\n  { \n    // Should be a reply message for us now   \n    if (mrf89.recv(buf, &len))\n   {\n      Serial.print(\"got reply: \");\n      Serial.println((char*)buf);\n//      Serial.print(\"RSSI: \");\n//      Serial.println(mrf89.lastRssi(), DEC);    \n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n  else\n  {\n    Serial.println(\"No reply, is mrf89_server running?\");\n  }\n  delay(400);\n}\n\n\n"
  },
  {
    "path": "examples/mrf89/mrf89_server/mrf89_server.pde",
    "content": "// mrf89_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing server\n// with the RH_MRF89 class. RH_MRF89 class does not provide for addressing or\n// reliability, so you should only use RH_MRF89 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example mrf89_client\n// Tested with Teensy and MRF89XAM9A\n\n\n#include <SPI.h>\n#include <RH_MRF89.h>\n\n// Singleton instance of the radio driver\nRH_MRF89 mrf89;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial)\n    ; // wait for serial port to connect. Needed for native USB\n\n  if (!mrf89.init())\n    Serial.println(\"init failed\");\n    \n  // Default after init is 1dBm, 915.4MHz, FSK_Rb20Fd40\n  // But you can change that if you want:\n//  mrf89.setTxPower(RH_MRF89_TXOPVAL_M8DBM); // Min power -8dBm\n//  mrf89.setTxPower(RH_MRF89_TXOPVAL_13DBM); // Max power 13dBm\n//  if (!mrf89.setFrequency(920.0))\n//    Serial.println(\"setFrequency failed\");\n//  if (!mrf89.setModemConfig(RH_MRF89::FSK_Rb200Fd200)) // Fastest\n//    Serial.println(\"setModemConfig failed\");\n}\n\nvoid loop()\n{\n  if (mrf89.available())\n  {\n    // Should be a message for us now   \n    uint8_t buf[RH_MRF89_MAX_MESSAGE_LEN];\n    uint8_t len = sizeof(buf);\n    if (mrf89.recv(buf, &len))\n    {\n//      RH_MRF89::printBuffer(\"request: \", buf, len);\n      Serial.print(\"got request: \");\n      Serial.println((char*)buf);\n//      Serial.print(\"RSSI: \");\n//      Serial.println(mrf89.lastRssi(), DEC);\n      \n      // Send a reply\n      uint8_t data[] = \"And hello back to you\";\n      mrf89.send(data, sizeof(data));\n      mrf89.waitPacketSent();\n      Serial.println(\"Sent a reply\");\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n//  delay(10000);\n//  mrf89.printRegisters();\n//  while (1);\n}\n\n\n"
  },
  {
    "path": "examples/nrf24/nrf24_client/nrf24_client.pde",
    "content": "// nrf24_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing client\n// with the RH_NRF24 class. RH_NRF24 class does not provide for addressing or\n// reliability, so you should only use RH_NRF24 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example nrf24_server.\n// Tested on Uno with Sparkfun NRF25L01 module\n// Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module\n// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module\n\n#include <SPI.h>\n#include <RH_NRF24.h>\n\n// Singleton instance of the radio driver\nRH_NRF24 nrf24;\n// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf\n// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin\n// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. Needed for Leonardo only\n  if (!nrf24.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n  if (!nrf24.setChannel(1))\n    Serial.println(\"setChannel failed\");\n  if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))\n    Serial.println(\"setRF failed\");    \n}\n\n\nvoid loop()\n{\n  Serial.println(\"Sending to nrf24_server\");\n  // Send a message to nrf24_server\n  uint8_t data[] = \"Hello World!\";\n  nrf24.send(data, sizeof(data));\n  \n  nrf24.waitPacketSent();\n  // Now wait for a reply\n  uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];\n  uint8_t len = sizeof(buf);\n\n  if (nrf24.waitAvailableTimeout(500))\n  { \n    // Should be a reply message for us now   \n    if (nrf24.recv(buf, &len))\n    {\n      Serial.print(\"got reply: \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n  else\n  {\n    Serial.println(\"No reply, is nrf24_server running?\");\n  }\n  delay(400);\n}\n\n"
  },
  {
    "path": "examples/nrf24/nrf24_reliable_datagram_client/nrf24_reliable_datagram_client.pde",
    "content": "// nrf24_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_NRF24 driver to control a NRF24 radio.\n// It is designed to work with the other example nrf24_reliable_datagram_server\n// Tested on Uno with Sparkfun WRL-00691 NRF24L01 module\n// Tested on Teensy with Sparkfun WRL-00691 NRF24L01 module\n// Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module\n// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module\n\n#include <RHReliableDatagram.h>\n#include <RH_NRF24.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_NRF24 driver;\n// RH_NRF24 driver(8, 7);   // For RFM73 on Anarduino Mini\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to nrf24_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is nrf24_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/nrf24/nrf24_reliable_datagram_server/nrf24_reliable_datagram_server.pde",
    "content": "// nrf24_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_NRF24 driver to control a NRF24 radio.\n// It is designed to work with the other example nrf24_reliable_datagram_client\n// Tested on Uno with Sparkfun WRL-00691 NRF24L01 module\n// Tested on Teensy with Sparkfun WRL-00691 NRF24L01 module\n// Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module\n// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module\n\n#include <RHReliableDatagram.h>\n#include <RH_NRF24.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_NRF24 driver;\n// RH_NRF24 driver(8, 7);   // For RFM73 on Anarduino Mini\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  if (manager.available())\n  {\n    // Wait for a message addressed to us from the client\n    uint8_t len = sizeof(buf);\n    uint8_t from;\n    if (manager.recvfromAck(buf, &len, &from))\n    {\n      Serial.print(\"got request from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n\n      // Send a reply back to the originator client\n      if (!manager.sendtoWait(data, sizeof(data), from))\n        Serial.println(\"sendtoWait failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/nrf24/nrf24_server/nrf24_server.pde",
    "content": "// nrf24_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing server\n// with the RH_NRF24 class. RH_NRF24 class does not provide for addressing or\n// reliability, so you should only use RH_NRF24  if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example nrf24_client\n// Tested on Uno with Sparkfun NRF25L01 module\n// Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module\n// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module\n\n#include <SPI.h>\n#include <RH_NRF24.h>\n\n// Singleton instance of the radio driver\nRH_NRF24 nrf24;\n// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf\n// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin\n// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. Needed for Leonardo only\n  if (!nrf24.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n  if (!nrf24.setChannel(1))\n    Serial.println(\"setChannel failed\");\n  if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))\n    Serial.println(\"setRF failed\");    \n}\n\nvoid loop()\n{\n  if (nrf24.available())\n  {\n    // Should be a message for us now   \n    uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];\n    uint8_t len = sizeof(buf);\n    if (nrf24.recv(buf, &len))\n    {\n//      NRF24::printBuffer(\"request: \", buf, len);\n      Serial.print(\"got request: \");\n      Serial.println((char*)buf);\n      \n      // Send a reply\n      uint8_t data[] = \"And hello back to you\";\n      nrf24.send(data, sizeof(data));\n      nrf24.waitPacketSent();\n      Serial.println(\"Sent a reply\");\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/nrf51/nrf51_audio_rx/nrf51_audio_rx.pde",
    "content": "// nrf51_audio_rx.pde\n// Sample sketch for nRF51822 and RadioHead\n//\n// Plays audio samples received in the radio receiver \n// through a MCP4725 DAC such as on a SparkFun I2C DAC Breakout - MCP4725 (BOB-12918)\n// works with matching transmitter (see nrf51_audio_tx.pde)\n// Works with RedBear nRF51822 board.\n// See examples/nrf51_audiotx/nrf51_audio.pdf for connection details\n\n#include <nrf51.h>\n#include <nrf51_bitfields.h>\n#include <esb/nrf_esb.h>\n#include <RH_NRF51.h>\n#include <Wire.h>\n\n// Number of samples per second to play at.\n// Should match SAMPLE_RATE in nrf51_audio_tx\n// The limiting factor is the time it takes to output a new sample through the DAC\n#define SAMPLE_RATE 5000\n\n// Number of 8 bit samples per packet\n// Should equal or exceed the PACKET_SIZE in nrf51_audio_tx\n#define MAX_PACKET_SIZE 255\n\n// Singleton instance of the radio driver\nRH_NRF51 driver;\n\nvoid setup() \n{\n  delay(1000);\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. \n\n  if (!driver.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n\n  // Set up TIMER\n  // Use TIMER0\n  // Timer freq before prescaling is 16MHz (VARIANT_MCK)\n  // We set up a 32 bit timer that restarts every 100us and outputs a new sample\n  NRF_TIMER0->PRESCALER = 0 << TIMER_PRESCALER_PRESCALER_Pos; \n  NRF_TIMER0->MODE = TIMER_MODE_MODE_Timer << TIMER_BITMODE_BITMODE_Pos;\n  NRF_TIMER0->BITMODE = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;\n  NRF_TIMER0->CC[0] = VARIANT_MCK / SAMPLE_RATE; // Counts per cycle\n  // When timer count expires, its cleared and restarts\n  NRF_TIMER0->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk;\n  NRF_TIMER0->TASKS_START = 1;\n  // Enable an interrupt when timer completes\n  NRF_TIMER0->INTENSET = TIMER_INTENSET_COMPARE0_Msk;\n  \n  // Enable the TIMER0 interrupt, and set the priority \n  // TIMER0_IRQHandler() will be called after each sample is available\n  NVIC_SetPriority(TIMER0_IRQn, 1);\n  NVIC_EnableIRQ(TIMER0_IRQn); \n\n  // Initialise comms with the I2C DAC as fast as we can\n  // Shame the 51822 does not suport the high speed I2C mode that the DAC does\n  Wire.begin(TWI_SCL, TWI_SDA, TWI_FREQUENCY_400K);\n}\n\nvolatile uint32_t count = 0;\n\nuint8_t buffer_length = 0;\nuint8_t buffer[MAX_PACKET_SIZE];\nuint16_t buffer_play_index = 0;\n\n// Write this sample to analog out\nvoid analog_out(uint8_t val)\n{\n  // This takes about 120usecs, which\n  // is the limiting factor for our sample rate of 5kHz\n  // Writes to MCP4725 DAC over I2C using the Wire library\n  Wire.beginTransmission(0x60); // 7 bit addressing\n  Wire.write((val >> 4) & 0x0f); \n  Wire.write((val << 4) & 0xf0);  \n  Wire.endTransmission();\n}\n\n// Called by timer interrupt\n// Output the next available sample\nvoid output_next_sample()\n{\n  if (buffer_play_index < buffer_length)\n  {\n    analog_out(buffer[buffer_play_index++]);\n  }\n}\n\nvoid loop() \n{\n  // Look for a new packet of samples\n  if (driver.available())\n  {\n    // expect one of these every 40ms = 25Hz\n    // This takes about 400us:\n    buffer_length = sizeof(buffer);\n    driver.recv(buffer, &buffer_length);\n    buffer_play_index = 0; // Trigger the interrupt playing of this buffer from the start\n  }\n}\n\n// This interrupt handler called when the timer interrupt fires\n// Time to output the next sample\nvoid TIMER0_IRQHandler(void)\n{\n  // It is vitally important that analog output completes before\n  // the next interrupt becomes due!\n  output_next_sample();\n  NRF_TIMER0->EVENTS_COMPARE[0] = 0; // Clear the COMPARE[0] event and the interrupt\n}\n\n"
  },
  {
    "path": "examples/nrf51/nrf51_audio_tx/nrf51_audio_tx.pde",
    "content": "// nrf51_audio_tx.pde\n// Sample sketch for nRF51822 and RadioHead\n//\n// Reads audio samples from an electret microphone\n// via the built in ADC in the nRF51822\n// Blocks of samples are sent by RadioHEad RH_NRF51 driver\n// to a matching receiver (see nrf51_audio_rx.pde)\n// Works with RedBear nRF51822 board.\n// See examples/nrf51_audiotx/nrf51_audio.pdf for connection details\n\n#include <nrf51.h>\n#include <nrf51_bitfields.h>\n#include <esb/nrf_esb.h>\n#include <RH_NRF51.h>\n\n// Number of audio samples per second\n// Should match SAMPLE_RATE in nrf51_audio_rx\n// Limited by the rate we can output samples in the receiver\n#define SAMPLE_RATE 5000\n\n// Number of 8 bit samples per packet\n#define PACKET_SIZE 200\n\n// Number of ADC data buffers\n#define NUM_BUFFERS 2\n\n// Minimum diff between smallest and largest reading in a given buffer\n// before we will send that buffer. We dont transmit quiet signals or silence\n#define USE_SQUELCH 0\n#define SQUELCH_THRESHOLD 2\n\n// These provide data transfer between the low level ADC interrupt handler and the \n// higher level packet assembly and transmission\nvolatile uint8_t  buffers[NUM_BUFFERS][PACKET_SIZE];\nvolatile uint16_t sample_index = 0;          // Of the next sample to write\nvolatile uint8_t  buffer_index = 0;          // Of the bufferbeing filled\nvolatile bool     buffer_ready[NUM_BUFFERS]; // Set when a buffer is full\n\n// These hold the state of the high level transmitter code\nuint8_t  next_tx_buffer = 0;\n \n// Singleton instance of the radio driver\nRH_NRF51 driver;\n\nvoid setup() \n{\n  delay(1000);\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. \n\n  if (!driver.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n\n  // Set up ADC\n  // Uses the builtin 1.2V bandgap reference and no prescaling\n  // AnalogInput2 is A0 on RedBear nrf51822 board\n  // Input voltage range is 0.0 to 1.2 V\n  NRF_ADC->CONFIG = ADC_CONFIG_RES_8bit << ADC_CONFIG_RES_Pos \n                    | ADC_CONFIG_INPSEL_AnalogInputNoPrescaling << ADC_CONFIG_INPSEL_Pos \n                    | ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos \n                    | ADC_CONFIG_PSEL_AnalogInput2 << ADC_CONFIG_PSEL_Pos;\n  NRF_ADC->ENABLE = 1;\n  NRF_ADC->INTENSET = ADC_INTENSET_END_Msk; // Interrupt at completion of each sample\n    \n  // Set up TIMER to trigger ADC samples\n  // Use TIMER0\n  // Timer freq before prescaling is 16MHz (VARIANT_MCK)\n  // We set up a 32 bit timer that restarts every 100us and trggers a new ADC sample\n  NRF_TIMER0->PRESCALER = 0 << TIMER_PRESCALER_PRESCALER_Pos; \n  NRF_TIMER0->MODE = TIMER_MODE_MODE_Timer << TIMER_BITMODE_BITMODE_Pos;\n  NRF_TIMER0->BITMODE = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;\n  NRF_TIMER0->CC[0] = VARIANT_MCK / SAMPLE_RATE; // Counts per cycle\n  // When timer count expires, its cleared and restarts\n  NRF_TIMER0->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk;\n  NRF_TIMER0->TASKS_START = 1;\n\n  // When the timer expires, trigger an ADC conversion\n  NRF_PPI->CH[0].EEP = (uint32_t)(&NRF_TIMER0->EVENTS_COMPARE[0]);\n  NRF_PPI->CH[0].TEP = (uint32_t)(&NRF_ADC->TASKS_START);\n  NRF_PPI->CHENSET = PPI_CHEN_CH0_Msk;\n\n  // Enable the ADC interrupt, and set the priority\n  // ADC_IRQHandler() will be called after each sample is available\n  NVIC_SetPriority(ADC_IRQn, 1);\n  NVIC_EnableIRQ(ADC_IRQn);   \n}\n\n// Called when a new sample is available from the ADC.\n// Add it to the current buffer.\n// when the buffer is full, signal that and switch to the other buffer.\nvoid handle_sample()\n{\n  buffers[buffer_index][sample_index++] = NRF_ADC->RESULT;\n  if (sample_index >= PACKET_SIZE)\n  {\n    sample_index = 0;\n    buffer_ready[buffer_index] = true;\n    buffer_index = (buffer_index + 1) % NUM_BUFFERS;\n    // If the next buffer is still still full, we have an overrun\n    if (buffer_ready[buffer_index])\n      Serial.println(\"Overrun\");\n  }\n}\n\nvoid loop() {\n  // Wait for the adc to fill the current buffer\n  if (buffer_ready[next_tx_buffer])\n  {\n#if USE_SQUELCH\n    // Honour squelch settings\n    uint8_t min_value = 255;\n    uint8_t max_value = 0;\n    uint16_t i;\n    for (i = 0; i < PACKET_SIZE; i++)\n    {\n      if (buffers[next_tx_buffer][i] > max_value)\n        max_value = buffers[next_tx_buffer][i];\n      if (buffers[next_tx_buffer][i] < min_value)\n        min_value = buffers[next_tx_buffer][i];\n    }\n    if (max_value - min_value > SQUELCH_THRESHOLD)\n#endif\n    {\n      // OK to send this one\n      driver.waitPacketSent(); // Make sure the previous packet has gone\n      driver.send((uint8_t*)buffers[next_tx_buffer], PACKET_SIZE);\n    }\n    \n    // Now get ready to wait for the next buffer\n    buffer_ready[next_tx_buffer] = false;\n    next_tx_buffer = (next_tx_buffer + 1) % NUM_BUFFERS;\n  }\n}\n\n// Called as an interrupt after each new ADC sample is complete.\nvoid ADC_IRQHandler(void)\n{\n  NRF_ADC->EVENTS_END = 0; // Clear the end event\n  handle_sample();\n}\n\n"
  },
  {
    "path": "examples/nrf51/nrf51_client/nrf51_client.pde",
    "content": "// nrf51_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing client\n// with the RH_NRF51 class. RH_NRF51 class does not provide for addressing or\n// reliability, so you should only use RH_NRF51 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example nrf51_server.\n// Tested on RedBearLabs nRF51822 and BLE Nano kit, built with Arduino 1.6.4.\n// See http://redbearlab.com/getting-started-nrf51822/\n// for how to set up your Arduino build environment\n// Also tested with Sparkfun nRF52832 breakout board, witth Arduino 1.6.13 and\n// Sparkfun nRF52 boards manager 0.2.3\n#include <RH_NRF51.h>\n\n// Singleton instance of the radio driver\nRH_NRF51 nrf51;\n\nvoid setup() \n{\n  delay(1000); // Wait for serial port etc to be ready\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. \n  if (!nrf51.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n  if (!nrf51.setChannel(1))\n    Serial.println(\"setChannel failed\");\n  if (!nrf51.setRF(RH_NRF51::DataRate2Mbps, RH_NRF51::TransmitPower0dBm))\n    Serial.println(\"setRF failed\"); \n  \n  // AES encryption can be enabled by setting the same key in the sender and receiver\n//  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,\n//                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};\n//  nrf51.setEncryptionKey(key);\n\n//  nrf51.printRegisters();\n}\n\n\nvoid loop()\n{\n  Serial.println(\"Sending to nrf51_server\");\n  // Send a message to nrf51_server\n  uint8_t data[] = \"Hello World!\";\n  nrf51.send(data, sizeof(data));\n  nrf51.waitPacketSent();\n\n  // Now wait for a reply\n  uint8_t buf[RH_NRF51_MAX_MESSAGE_LEN];\n  uint8_t len = sizeof(buf);\n\n  if (nrf51.waitAvailableTimeout(500))\n  { \n    // Should be a reply message for us now   \n    if (nrf51.recv(buf, &len))\n    {\n      Serial.print(\"got reply: \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n  else\n  {\n    Serial.println(\"No reply, is nrf51_server running?\");\n  }\n\n  delay(400);\n}\n\n"
  },
  {
    "path": "examples/nrf51/nrf51_reliable_datagram_client/nrf51_reliable_datagram_client.pde",
    "content": "// nrf51_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_NRF51 driver to control a NRF51 radio.\n// It is designed to work with the other example nrf51_reliable_datagram_server\n// Tested on RedBearLabs nRF51822 and BLE Nano kit, built with Arduino 1.6.4.\n// See http://redbearlab.com/getting-started-nrf51822/\n// for how to set up your Arduino build environment\n// Also tested with Sparkfun nRF52832 breakout board, witth Arduino 1.6.13 and\n// Sparkfun nRF52 boards manager 0.2.3\n\n#include <RHReliableDatagram.h>\n#include <RH_NRF51.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_NRF51 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{  \n  delay(1000); // Wait for serial port etc to be ready\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. \n\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_NRF51_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to nrf51_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is nrf51_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/nrf51/nrf51_reliable_datagram_server/nrf51_reliable_datagram_server.pde",
    "content": "// nrf51_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_NRF51 driver to control a NRF51 radio.\n// It is designed to work with the other example nrf51_reliable_datagram_client\n// Tested on RedBearLabs nRF51822 and BLE Nano kit, built with Arduino 1.6.4.\n// See http://redbearlab.com/getting-started-nrf51822/\n// for how to set up your Arduino build environment\n// Also tested with Sparkfun nRF52832 breakout board, witth Arduino 1.6.13 and\n// Sparkfun nRF52 boards manager 0.2.3\n\n\n#include <RHReliableDatagram.h>\n#include <RH_NRF51.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_NRF51 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\nvoid setup() \n{\n  delay(1000); // Wait for serial port etc to be ready\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. \n\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_NRF51_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  if (manager.available())\n  {\n    // Wait for a message addressed to us from the client\n    uint8_t len = sizeof(buf);\n    uint8_t from;\n    if (manager.recvfromAck(buf, &len, &from))\n    {\n      Serial.print(\"got request from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n\n      // Send a reply back to the originator client\n      if (!manager.sendtoWait(data, sizeof(data), from))\n        Serial.println(\"sendtoWait failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/nrf51/nrf51_server/nrf51_server.pde",
    "content": "// nrf51_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing server\n// with the RH_NRF51 class. RH_NRF51 class does not provide for addressing or\n// reliability, so you should only use RH_NRF51 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example nrf51_client\n// Tested on RedBearLabs nRF51822 and BLE Nano kit, built with Arduino 1.6.4.\n// See http://redbearlab.com/getting-started-nrf51822/\n// for how to set up your Arduino build environment\n// Also tested with Sparkfun nRF52832 breakout board, witth Arduino 1.6.13 and\n// Sparkfun nRF52 boards manager 0.2.3\n\n#include <RH_NRF51.h>\n\n// Singleton instance of the radio driver\nRH_NRF51 nrf51;\n\nvoid setup() \n{\n  delay(1000); // Wait for serial port etc to be ready\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. Needed for Leonardo only\n  if (!nrf51.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n  if (!nrf51.setChannel(1))\n    Serial.println(\"setChannel failed\");\n  if (!nrf51.setRF(RH_NRF51::DataRate2Mbps, RH_NRF51::TransmitPower0dBm))\n    Serial.println(\"setRF failed\");    \n\n  // AES encryption can be enabled by setting the same key in the sender and receiver\n//  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,\n//                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};\n//  nrf51.setEncryptionKey(key);\n}\n\nvoid loop()\n{\n  if (nrf51.available())\n  {\n    // Should be a message for us now   \n    uint8_t buf[RH_NRF51_MAX_MESSAGE_LEN];\n    uint8_t len = sizeof(buf);\n    if (nrf51.recv(buf, &len))\n    {\n//      NRF51::printBuffer(\"request: \", buf, len);\n      Serial.print(\"got request: \");\n      Serial.println((char*)buf);\n      \n      // Send a reply\n      uint8_t data[] = \"And hello back to you\";\n      nrf51.send(data, sizeof(data));\n      nrf51.waitPacketSent();\n      Serial.println(\"Sent a reply\");\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/nrf905/nrf905_client/nrf905_client.pde",
    "content": "// nrf905_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing client\n// with the RH_NRF905 class. RH_NRF905 class does not provide for addressing or\n// reliability, so you should only use RH_NRF905 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example nrf905_server.\n// Tested on Teensy3.1 with nRF905 module\n// Tested on Arduino Due with nRF905 module (Caution: use the SPI headers for connecting)\n\n#include <SPI.h>\n#include <RH_NRF905.h>\n\n// Singleton instance of the radio driver\nRH_NRF905 nrf905;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. Needed for Leonardo only\n  if (!nrf905.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 433.2 MHz (channel 108), -10dBm\n}\n\n\nvoid loop()\n{\n  Serial.println(\"Sending to nrf905_server\");\n  // Send a message to nrf905_server\n  uint8_t data[] = \"Hello World!\";\n  nrf905.send(data, sizeof(data));\n  \n  nrf905.waitPacketSent();\n  // Now wait for a reply\n  uint8_t buf[RH_NRF905_MAX_MESSAGE_LEN];\n  uint8_t len = sizeof(buf);\n\n  if (nrf905.waitAvailableTimeout(500))\n  { \n    // Should be a reply message for us now   \n    if (nrf905.recv(buf, &len))\n    {\n      Serial.print(\"got reply: \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n  else\n  {\n    Serial.println(\"No reply, is nrf905_server running?\");\n  }\n  delay(400);\n}\n\n"
  },
  {
    "path": "examples/nrf905/nrf905_reliable_datagram_client/nrf905_reliable_datagram_client.pde",
    "content": "// nrf905_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_NRF905 driver to control a NRF905 radio.\n// It is designed to work with the other example nrf905_reliable_datagram_server\n// Tested on Teensy3.1 with nRF905 module\n// Tested on Arduino Due with nRF905 module (Caution: use the SPI headers for connecting)\n\n#include <RHReliableDatagram.h>\n#include <RH_NRF905.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_NRF905 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 433.2 MHz (channel 108), -10dBm\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_NRF905_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to nrf905_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is nrf905_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/nrf905/nrf905_reliable_datagram_server/nrf905_reliable_datagram_server.pde",
    "content": "// nrf905_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_NRF905 driver to control a NRF905 radio.\n// It is designed to work with the other example nrf905_reliable_datagram_client\n// Tested on Teensy3.1 with nRF905 module\n// Tested on Arduino Due with nRF905 module (Caution: use the SPI headers for connecting)\n\n#include <RHReliableDatagram.h>\n#include <RH_NRF905.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_NRF905 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 433.2 MHz (channel 108), -10dBm\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_NRF905_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  if (manager.available())\n  {\n    // Wait for a message addressed to us from the client\n    uint8_t len = sizeof(buf);\n    uint8_t from;\n    if (manager.recvfromAck(buf, &len, &from))\n    {\n      Serial.print(\"got request from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n\n      // Send a reply back to the originator client\n      if (!manager.sendtoWait(data, sizeof(data), from))\n        Serial.println(\"sendtoWait failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/nrf905/nrf905_server/nrf905_server.pde",
    "content": "// nrf905_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing server\n// with the RH_NRF905 class. RH_NRF905 class does not provide for addressing or\n// reliability, so you should only use RH_NRF905  if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example nrf905_client\n// Tested on Teensy3.1 with nRF905 module\n// Tested on Arduino Due with nRF905 module (Caution: use the SPI headers for connecting)\n\n#include <SPI.h>\n#include <RH_NRF905.h>\n\n// Singleton instance of the radio driver\nRH_NRF905 nrf905;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial) \n    ; // wait for serial port to connect. Needed for Leonardo only\n  if (!nrf905.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 433.2 MHz (channel 108), -10dBm\n}\n\nvoid loop()\n{\n  if (nrf905.available())\n  {\n    // Should be a message for us now   \n    uint8_t buf[RH_NRF905_MAX_MESSAGE_LEN];\n    uint8_t len = sizeof(buf);\n    if (nrf905.recv(buf, &len))\n    {\n//      nrf905.printBuffer(\"request: \", buf, len);\n      Serial.print(\"got request: \");\n      Serial.println((char*)buf);\n      \n      // Send a reply\n      uint8_t data[] = \"And hello back to you\";\n      nrf905.send(data, sizeof(data));\n      nrf905.waitPacketSent();\n      Serial.println(\"Sent a reply\");\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/raspi/RasPiBoards.h",
    "content": "// defined pins definition of different hardware boards used\n// Contributed by Charles-Henri Hallard http://hallard.me\n\n// If a pin is not used just define it to NOT_A_PIN\n// or do not define it, both works\n// ie : #define RF_LED_PIN NOT_A_PIN\n\n// LoRasPi board \n//==============\n// see https://github.com/hallard/LoRasPI\n#if defined (BOARD_LORASPI)\n#define RF_LED_PIN RPI_V2_GPIO_P1_16 // Led on GPIO23 so P1 connector pin #16\n#define RF_CS_PIN  RPI_V2_GPIO_P1_24 // Slave Select on CE0 so P1 connector pin #24\n#define RF_IRQ_PIN RPI_V2_GPIO_P1_22 // IRQ on GPIO25 so P1 connector pin #22\n#define RF_RST_PIN RPI_V2_GPIO_P1_15 // IRQ on GPIO22 so P1 connector pin #15\n\n\n// Raspberri PI Lora Gateway Board iC880A and LinkLab Lora Gateway Shield (if RF module plugged into)\n// ==================================================================================================\n// see https://github.com/ch2i/iC880A-Raspberry-PI\n#elif defined (BOARD_IC880A_PLATE)\n#define RF_LED_PIN RPI_V2_GPIO_P1_18 // Led on GPIO24 so P1 connector pin #18\n#define RF_CS_PIN  RPI_V2_GPIO_P1_24 // Slave Select on CE0 so P1 connector pin #24\n#define RF_IRQ_PIN RPI_V2_GPIO_P1_35 // IRQ on GPIO19 so P1 connector pin #35\n\n\n// Raspberri PI Lora Gateway for multiple modules \n// ==============================================\n// see https://github.com/hallard/RPI-Lora-Gateway\n#elif defined (BOARD_PI_LORA_GATEWAY)\n\n// Module 1, 2 and 3 are example of module type soldered on the board\n// change to fit your needs\n\n// Module 1 on board RFM95 868 MHz (example)\n#define MOD1_LED_PIN RPI_V2_GPIO_P1_07 // Led on GPIO4 so P1 connector pin #7\n#define MOD1_CS_PIN  RPI_V2_GPIO_P1_24 // Slave Select on CE0 so P1 connector pin #24\n#define MOD1_IRQ_PIN RPI_V2_GPIO_P1_22 // IRQ on GPIO25 so P1 connector pin #22\n#define MOD1_RST_PIN RPI_V2_GPIO_P1_29 // Reset on GPIO5 so P1 connector pin #29\n\n// Module 2 on board RFM95 433 MHz (example)\n#define MOD2_LED_PIN RPI_V2_GPIO_P1_11 // Led on GPIO17 so P1 connector pin #11\n#define MOD2_CS_PIN  RPI_V2_GPIO_P1_26 // Slave Select on CE1 so P1 connector pin #26\n#define MOD2_IRQ_PIN RPI_V2_GPIO_P1_36 // IRQ on GPIO16 so P1 connector pin #36\n#define MOD2_RST_PIN RPI_V2_GPIO_P1_31 // Reset on GPIO6 so P1 connector pin #31\n\n// Module 3 on board RFM69HW (example)\n#define MOD3_LED_PIN RPI_V2_GPIO_P1_35 // Led on GPIO19 so P1 connector pin #11\n#define MOD3_CS_PIN  RPI_V2_GPIO_P1_37 // Slave Select on GPIO26  so P1 connector pin #37\n#define MOD3_IRQ_PIN RPI_V2_GPIO_P1_16 // IRQ on GPIO23 so P1 connector pin #16\n#define MOD3_RST_PIN RPI_V2_GPIO_P1_33 // reset on GPIO13 so P1 connector pin #33\n\n// Default set to module 1 (in case used just with one module examples)\n#define RF_LED_PIN MOD1_LED_PIN\n#define RF_CS_PIN  MOD1_CS_PIN\n#define RF_IRQ_PIN MOD1_IRQ_PIN\n#define RF_RST_PIN MOD1_RST_PIN\n\n// Dragino Raspberry PI hat (no obboard led)\n// =========================================\n// see https://github.com/dragino/Lora\n#elif defined (BOARD_DRAGINO_PIHAT)\n#define RF_CS_PIN  RPI_V2_GPIO_P1_22 // Slave Select on GPIO25 so P1 connector pin #22\n#define RF_IRQ_PIN RPI_V2_GPIO_P1_07 // IRQ on GPIO4 so P1 connector pin #7\n#define RF_RST_PIN RPI_V2_GPIO_P1_11 // Reset on GPIO17 so P1 connector pin #11\n#define RF_LED_PIN NOT_A_PIN\t\t\t\t // No onboard led to drive\n\n#else\n#error \"RasPiBoards.h => Please define Hardware Board\"\n#endif\n"
  },
  {
    "path": "examples/raspi/irq_test/Makefile",
    "content": "# Makefile\n# Sample for spi irq leve testing for Hope RF modules on Raspberry Pi\n# Caution: requires bcm2835 library to be already installed\n# http://www.airspayce.com/mikem/bcm2835/\n\nCC            = g++\nCFLAGS        = -DRASPBERRY_PI -DBCM2835_NO_DELAY_COMPATIBILITY\nLIBS          = -lbcm2835 \nRADIOHEADBASE = ../../..\nINCLUDE       = -I$(RADIOHEADBASE)\n\nall: irq_test\n\nirq_test.o: irq_test.c\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nirq_test: irq_test.o\n\t\t\t\t$(CC) $^ $(LIBS) -o irq_test\n\nclean:\n\t\t\t\trm -rf *.o irq_test\n"
  },
  {
    "path": "examples/raspi/irq_test/irq_test.c",
    "content": "// irq_test.cpp\n//\n// Example program showing how to use multiple module RH_RF69/RH_RF95 on Raspberry Pi\n// Requires bcm2835 library to be already installed\n// http://www.airspayce.com/mikem/bcm2835/\n// Use the Makefile in this directory:\n// cd example/raspi/irq_test\n// make\n// sudo ./irq_test\n//\n// Will check for rising edge on RF_IRQ_PIN defined below\n//\n// Contributed by Charles-Henri Hallard (hallard.me)\n#include <bcm2835.h>\n#include <stdio.h>\n\n//#define RF_IRQ_PIN RPI_V2_GPIO_P1_22 // IRQ on GPIO25 so P1 connector pin #22\n#define RF_IRQ_PIN RPI_V2_GPIO_P1_37 // IRQ on GPIO26 so P1 connector pin #37\n\nint main(int argc, char **argv)\n{\n  // If you call this, it will not actually access the GPIO\n  if (!bcm2835_init())\n    return 1;\n  \n  // Set RPI pin to be an input\n  bcm2835_gpio_fsel(RF_IRQ_PIN, BCM2835_GPIO_FSEL_INPT);\n  //  with a puldown\n  bcm2835_gpio_set_pud(RF_IRQ_PIN, BCM2835_GPIO_PUD_DOWN);\n  // And a rising edge detect enable\n  bcm2835_gpio_ren(RF_IRQ_PIN);\n  \n  while (1) {\n    // we got it ?\n    if (bcm2835_gpio_eds(RF_IRQ_PIN)) {\n      // Now clear the eds flag by setting it to 1\n      bcm2835_gpio_set_eds(RF_IRQ_PIN);\n      printf(\"Rising event detect for pin GPIO%d\\n\", RF_IRQ_PIN);\n    }\n    // wait a bit\n    bcm2835_delay(5); \n  }\n  \n  bcm2835_close();\n  return 0;\n}\n"
  },
  {
    "path": "examples/raspi/multi_server/Makefile",
    "content": "# Makefile\n# Sample for multi modules server on Raspberry Pi\n# Caution: requires bcm2835 library to be already installed\n# http://www.airspayce.com/mikem/bcm2835/\n\nCC            = g++\nCFLAGS        = -DRASPBERRY_PI -DBCM2835_NO_DELAY_COMPATIBILITY -D__BASEFILE__=\\\"$*\\\"\nLIBS          = -lbcm2835\nRADIOHEADBASE = ../../..\nINCLUDE       = -I$(RADIOHEADBASE)\n\nall: multi_server\n\nRasPi.o: $(RADIOHEADBASE)/RHutil/RasPi.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil/RasPi.cpp $(INCLUDE)\n\nRH_RF69.o: $(RADIOHEADBASE)/RH_RF69.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nmulti_server.o: multi_server.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nmulti_server: multi_server.o RasPi.o RHHardwareSPI.o RH_RF69.o RH_RF95.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o\n\t\t\t\t$(CC) $^ $(LIBS) -o multi_server\n\nclean:\n\t\t\t\trm -rf *.o multi_server\n"
  },
  {
    "path": "examples/raspi/multi_server/multi_server.cpp",
    "content": "// multi_server.cpp\n//\n// Example program showing how to use multiple module RH_RF69/RH_RF95 on Raspberry Pi\n// Requires bcm2835 library to be already installed\n// http://www.airspayce.com/mikem/bcm2835/\n// Use the Makefile in this directory:\n// cd example/raspi/multi_server\n// make\n// sudo ./multi_server\n//\n// Contributed by Charles-Henri Hallard based on sample RH_NRF24 by Mike Poublon\n\n#include <bcm2835.h>\n#include <stdio.h>\n#include <signal.h>\n#include <unistd.h>\n#include <time.h>\n\n#include <RHGenericDriver.h>\n#include <RH_RF69.h>\n#include <RH_RF95.h>\n\n// Raspberri PI Lora Gateway for multiple modules \n// see https://github.com/hallard/RPI-Lora-Gateway\n#define BOARD_PI_LORA_GATEWAY\n\n// Now we include RasPi_Boards.h so this will expose defined \n// constants with CS/IRQ/RESET/on board LED pins definition\n#include \"../RasPiBoards.h\"\n\n// User Led on GPIO18 so P1 connector pin #12\n#define LED_PIN  RPI_V2_GPIO_P1_12     \n\n// Our RF95 module 1 Configuration \n#define RF95_1_NODE_ID    1\n#define RF95_1_FREQUENCY  868.00\n\n// Our RF95 module 3 Configuration \n#define RF95_2_NODE_ID    1\n#define RF95_2_FREQUENCY  433.00\n\n// Our RFM69 module 3 Configuration \n#define RF69_3_NODE_ID    1\n#define RF69_3_GROUP_ID   69\n#define RF69_3_FREQUENCY  433.00\n\n// For module index table\nenum Mod_idx { IDX_MOD1 = 0, IDX_MOD2 = 1, IDX_MOD3 = 2 };\n\n// Modules table index\n#define NB_MODULES 3\nuint8_t IRQ_pins[NB_MODULES] = { MOD1_IRQ_PIN, MOD2_IRQ_PIN, MOD3_IRQ_PIN};\nuint8_t LED_pins[NB_MODULES] = { MOD1_LED_PIN, MOD2_LED_PIN, MOD3_LED_PIN};\nuint8_t RST_pins[NB_MODULES] = { MOD1_RST_PIN, MOD2_RST_PIN, MOD3_RST_PIN};\nuint8_t CSN_pins[NB_MODULES] = { MOD1_CS_PIN , MOD2_CS_PIN , MOD3_CS_PIN };\n\nconst char * MOD_name[]      = { \"1 RF95 868\",     \"2 RF95 433\" ,    \"3 RFM69HW 433\"  };\nfloat MOD_freq[NB_MODULES]   = { RF95_1_FREQUENCY, RF95_2_FREQUENCY, RF69_3_FREQUENCY };\nuint8_t MOD_id[NB_MODULES]   = { RF95_1_NODE_ID,   RF95_2_NODE_ID,   RF69_3_NODE_ID   };\n\n// Pointer table on radio driver\nRHGenericDriver * drivers[NB_MODULES];\n\n// Create an instance of a driver for 3 modules\n// In our case RadioHead code does not use IRQ\n// callback, bcm2835 does provide such function, \n// but keep line state providing function to test\n// Rising/falling/change on GPIO Pin\nRH_RF95 rf95_1(MOD1_CS_PIN, MOD1_IRQ_PIN);\nRH_RF95 rf95_2(MOD2_CS_PIN, MOD2_IRQ_PIN);\nRH_RF69 rf69_3(MOD3_CS_PIN, MOD3_IRQ_PIN);\n\n//Flag for Ctrl-C\nvolatile sig_atomic_t force_exit = 0;\n\n// default led blink on receive for 200 ms\n#define LED_BLINK_MS  200\n\n/* ======================================================================\nFunction: sig_handler\nPurpose : Intercept CTRL-C keyboard to close application\nInput   : signal received\nOutput  : -\nComments: -\n====================================================================== */\nvoid sig_handler(int sig)\n{\n  printf(\"\\nBreak received, exiting!\\n\");\n  force_exit=true;\n}\n\n/* ======================================================================\nFunction: getReceivedData\nPurpose : Get module received data and display it\nInput   : Module Index from modules table\nOutput  : -\nComments: -\n====================================================================== */\nvoid getReceivedData( uint8_t index) \n{\n  RHGenericDriver * driver = drivers[index];\n  if (driver->available()) {\n    // RH_RF95_MAX_MESSAGE_LEN is > RH_RF69_MAX_MESSAGE_LEN, \n    // So we take the maximum size to be able to handle all\n    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];\n    uint8_t len  = sizeof(buf);\n    uint8_t from = driver->headerFrom();\n    uint8_t to   = driver->headerTo();\n    uint8_t id   = driver->headerId();\n    uint8_t flags= driver->headerFlags();;\n    int8_t rssi  = driver->lastRssi();\n\n    if (driver->recv(buf, &len)) {\n      time_t timer;\n      char time_buff[16];\n      struct tm* tm_info;\n\n      time(&timer);\n      tm_info = localtime(&timer);\n\n      strftime(time_buff, sizeof(time_buff), \"%H:%M:%S\", tm_info);\n\n      printf(\"%s Mod%s [%02d] #%d => #%d %ddB: \", \n                time_buff, MOD_name[index], len, from, to, rssi);\n      printbuffer(buf, len);\n    } else {\n      printf(\"receive failed\");\n    }\n    printf(\"\\n\");\n  }\n}\n\n/* ======================================================================\nFunction: initRadioModule\nPurpose : initialize a module\nInput   : Module Index from modules table\nOutput  : -\nComments: -\n====================================================================== */\nbool initRadioModule( uint8_t index) {\n  RHGenericDriver * driver = drivers[index];\n  //RH_RF69 * driver = (RH_RF69 *) drivers[index];\n\n  // Module Information\n  printf( \"%s (CS=GPIO%d, IRQ=GPIO%d, RST=GPIO%d, LED=GPIO%d)\", \n          MOD_name[index], CSN_pins[index], IRQ_pins[index], RST_pins[index], LED_pins[index] );\n\n  // Light Module LED\n  pinMode(LED_pins[index], OUTPUT);\n\n  // IRQ Pin, as input with Pull down (in case no module connected)\n  pinMode(IRQ_pins[index], INPUT);\n  bcm2835_gpio_set_pud(IRQ_pins[index], BCM2835_GPIO_PUD_DOWN);\n\n  // we enable rising edge detection \n  bcm2835_gpio_ren(IRQ_pins[index]);\n\n  // Reset module and blink the module LED \n  digitalWrite(LED_pins[index], HIGH);\n  pinMode(RST_pins[index], OUTPUT);\n  digitalWrite(RST_pins[index], LOW);\n  bcm2835_delay(150);\n  digitalWrite(RST_pins[index], HIGH);\n  bcm2835_delay(100);\n  digitalWrite(LED_pins[index], LOW);\n\n  if (!driver->init()) {\n    fprintf( stderr, \"\\n%s init failed, Please verify wiring/module\\n\", MOD_name[index] );\n  } else {\n    // Since we'll check IRQ line with bcm_2835 Rising edge detection\n    // In case radio already have a packet, IRQ is high and will never\n    // go to low until cleared, so never fire IRQ LOW to HIGH again \n    // Except if we clear IRQ flags and discard packet if any!\n    // ==> This is now done before reset\n    //driver->available();\n    // now we can enable rising edge detection \n    //bcm2835_gpio_ren(IRQ_pins[index]);\n\n    // set Node ID\n    driver->setThisAddress(MOD_id[index]); // filtering address when receiving\n    driver->setHeaderFrom(MOD_id[index]);  // Transmit From Node\n\n    // Get all frame, we're in demo mode\n    driver->setPromiscuous(true);   \n\n    // We need to check module type since generic driver does\n    // not expose driver specific methods\n    switch (index) {\n      // RF95\n      case IDX_MOD1:\n      case IDX_MOD2:\n        // Defaults RF95 after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on\n        // The default transmitter power is 13dBm, using PA_BOOST.\n        // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then\n        // you can set transmitter powers from 5 to 23 dBm:\n        // check your country max power useable, in EU it's +14dB\n        ((RH_RF95 *) driver)->setTxPower(14, false);\n        // If you are using Modtronix inAir4 or inAir9,or any other module which uses the\n        // transmitter RFO pins and not the PA_BOOST pins\n        // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true.\n        // Failure to do that will result in extremely low transmit powers.\n        // rf95.setTxPower(14, true);\n\n        // You can optionally require this module to wait until Channel Activity\n        // Detection shows no activity on the channel before transmitting by setting\n        // the CAD timeout to non-zero:\n        //rf95.setCADTimeout(10000);\n\n        // Adjust Frequency\n        ((RH_RF95 *) driver)->setFrequency( MOD_freq[index] );\n      break;\n\n      // RF69\n      case IDX_MOD3:\n        // Adjust Frequency\n        ((RH_RF69 *) driver)->setFrequency( MOD_freq[index] );\n        \n        // Set TX power to High power RFMH69\n        //((RH_RF69 *) driver)->setTxPower(13);\n        ((RH_RF69 *) driver)->setTxPower(20);\n\n        // Change default radioHead modem configuration to moteino one\n        ((RH_RF69 *) driver)->setModemConfig( RH_RF69::FSK_MOTEINO);\n\n        // set Network ID (by sync words)\n        uint8_t syncwords[2];\n        syncwords[0] = 0x2d;\n        syncwords[1] = RF69_3_GROUP_ID;\n        ((RH_RF69 *) driver)->setSyncWords(syncwords, sizeof(syncwords));\n      break;\n    }\n\n    printf( \" OK!, NodeID=%d @ %3.2fMHz\\n\", MOD_id[index], MOD_freq[index] );\n    return true;\n  }\n  \n  return false;\n}\n\n/* ======================================================================\nFunction: main\nPurpose : not sure ;)\nInput   : command line parameters\nOutput  : -\nComments: -\n====================================================================== */\nint main (int argc, const char* argv[] )\n{\n  // LED blink ms timer saving\n  unsigned long led_blink[NB_MODULES] = {0,0,0};\n  \n  // caught CTRL-C to do clean-up\n  signal(SIGINT, sig_handler);\n  \n  // Display app name\n  printf( \"%s\\n\", __BASEFILE__);\n  for (uint8_t i=0; i<strlen(__BASEFILE__); i++) {\n    printf( \"=\");\n  }\n  printf(\"\\n\");\n\n  // Init GPIO bcm\n  if (!bcm2835_init()) {\n    fprintf( stderr, \"bcm2835_init() Failed\\n\\n\" );\n    return 1;\n  }\n\n  //save driver instances pointer\n  drivers[IDX_MOD1] = &rf95_1;\n  drivers[IDX_MOD2] = &rf95_2;\n  drivers[IDX_MOD3] = &rf69_3;\n\n  // light onboard LEDs \n  pinMode(LED_PIN, OUTPUT);\n  digitalWrite(LED_PIN, HIGH);\n\n  // configure all modules I/O CS pins to 1 before anything else\n  // to avoid any problem with SPI sharing\n  for (uint8_t i=0 ; i<NB_MODULES; i++) {\n    // CS Ping as output and set to 1\n    pinMode(CSN_pins[i], OUTPUT);\n    digitalWrite(CSN_pins[i], HIGH);\n  }\n\n  // configure all modules I/O pins \n  for (uint8_t i=0 ; i<NB_MODULES; i++) {\n    // configure all modules\n    if (!initRadioModule(i)){\n      force_exit = true;\n    }\n  }\n\n  // All init went fine, continue specific init if any\n  if (!force_exit) {\n    // Set all modules in receive mode\n    rf95_1.setModeRx();\n    rf95_2.setModeRx();\n    rf69_3.setModeRx();\n    printf( \"Listening for incoming packets...\\n\" );\n  }\n\n  // Begin the main loop code \n  // ========================\n  while (!force_exit) { \n    // Loop thru modules\n    for (uint8_t idx=0 ; idx<NB_MODULES ; idx++) {\n      // Rising edge fired ?\n      if (bcm2835_gpio_eds(IRQ_pins[idx])) {\n        // Now clear the eds flag by setting it to 1\n        bcm2835_gpio_set_eds(IRQ_pins[idx]);\n        //printf(\"Packet Received, Rising event detect for pin GPIO%d\\n\", IRQ_pins[idx]);\n  \n        // Start associated led blink\n        led_blink[idx] = millis();\n        digitalWrite(LED_pins[idx], HIGH);\n        getReceivedData(idx); \n      } // has IRQ\n\n      // A module led blink timer expired ? Light off\n      if (led_blink[idx] && millis()-led_blink[idx]>LED_BLINK_MS) {\n        led_blink[idx] = 0;\n        digitalWrite(LED_pins[idx], LOW);\n      } // Led timer expired\n\n      getReceivedData(idx); \n\n    } // For Modules\n    \n    // On board led blink (500ms off / 500ms On)\n    digitalWrite(LED_PIN, (millis()%1000)<500?LOW:HIGH);\n\n    // Let OS doing other tasks\n    // For timed critical appliation receiver, you can reduce or delete\n    // this delay, but this will charge CPU usage, take care and monitor\n    bcm2835_delay(5);\n  }\n\n  // We're here because we need to exit, do it clean\n  // Light off on board LED\n  digitalWrite(LED_PIN, LOW);\n  // All module LEDs off, all modules CS line High\n  for (uint8_t i=0 ; i<NB_MODULES; i++) {\n    digitalWrite(LED_pins[i], LOW);\n    digitalWrite(CSN_pins[i], HIGH);\n  }\n  printf( \"\\n%s, done my job!\\n\", __BASEFILE__ );\n  bcm2835_close();\n  return 0;\n}\n"
  },
  {
    "path": "examples/raspi/nrf24/Makefile",
    "content": "# Makefile\n# Sample for RH_NRF24 on Raspberry Pi\n# Caution: requires bcm2835 library to be already installed\n# http://www.airspayce.com/mikem/bcm2835/\n\nCC            = g++\nCFLAGS        = -DRASPBERRY_PI -DBCM2835_NO_DELAY_COMPATIBILITY\nLIBS          = -lbcm2835\nRADIOHEADBASE = ../../..\nINCLUDE       = -I$(RADIOHEADBASE)\n\nall: RasPiRH \n\nRasPi.o: $(RADIOHEADBASE)/RHutil/RasPi.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil/RasPi.cpp $(INCLUDE)\n\nRasPiRH.o: RasPiRH.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRH_NRF24.o: $(RADIOHEADBASE)/RH_NRF24.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHMesh.o: $(RADIOHEADBASE)/RHMesh.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHNRFSPIDriver.o: $(RADIOHEADBASE)/RHNRFSPIDriver.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRasPiRH: RasPiRH.o RH_NRF24.o RHMesh.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHNRFSPIDriver.o RHGenericDriver.o RHGenericSPI.o\n\t\t\t\t$(CC) $^ $(LIBS) -o RasPiRH\n\nclean:\n\t\t\t\trm -rf *.o RasPiRH  \n"
  },
  {
    "path": "examples/raspi/nrf24/RasPiRH.cpp",
    "content": "// RasPiRH.cpp\n//\n// Example program showing how to use RH_NRF24 on Raspberry Pi\n// Uses the bcm2835 library to access the GPIO pins to drive the NRF24L01\n// Requires bcm2835 library to be already installed\n// http://www.airspayce.com/mikem/bcm2835/\n// Use the Makefile in this directory:\n// cd example/raspi\n// make\n// sudo ./RasPiRH\n//\n// Creates a RHReliableDatagram manager and listens and prints for reliable datagrams\n// sent to it on the default Channel 2.\n//\n// Contributed by Mike Poublon\n\n#include <bcm2835.h>\n#include <stdio.h>\n#include <signal.h>\n#include <unistd.h>\n\n#include <RHReliableDatagram.h>\n#include <RH_NRF24.h>\n\n//Function Definitions\nvoid sig_handler(int sig);\nvoid printbuffer(uint8_t buff[], int len);\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Create an instance of a driver\n// Chip enable is pin 22\n// Slave Select is pin 24\nRH_NRF24 nrf24(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_24);\nRHReliableDatagram manager(nrf24, SERVER_ADDRESS);\n\n//Flag for Ctrl-C\nvolatile sig_atomic_t flag = 0;\n\n//Main Function\nint main (int argc, const char* argv[] )\n{\n  signal(SIGINT, sig_handler);\n\n  if (!bcm2835_init())\n  {\n    printf( \"\\n\\nRasPiRH Tester Startup Failed\\n\\n\" );\n    return 1;\n  }\n\n  printf( \"\\nRasPiRH Tester Startup\\n\\n\" );\n\n  /* Begin Driver Only Init Code\n  if (!nrf24.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm\n  if (!nrf24.setChannel(1))\n    Serial.println(\"setChannel failed\");\n  if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))\n    Serial.println(\"setRF failed\");\n  End Driver Only Init Code */\n\n  /* Begin Reliable Datagram Init Code */\n  if (!manager.init())\n  {\n    printf( \"Init failed\\n\" );\n  }\n  /* End Reliable Datagram Init Code */\n\n  uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];\n\n  //Begin the main body of code\n  while (true)\n  {\n    uint8_t len = sizeof(buf);\n    uint8_t from, to, id, flags;\n\n    /* Begin Driver Only code\n    if (nrf24.available())\n    {\n      // Should be a message for us now\n      //uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];\n      uint8_t len = sizeof(buf);\n      if (nrf24.recv(buf, &len))\n      {\n        Serial.print(\"got request: \");\n        Serial.println((char*)buf);\n        Serial.println(\"\");\n      }\n      else\n      {\n        Serial.println(\"recv failed\");\n      }\n    }\n    End Driver Only Code*/\n\n    /* Begin Reliable Datagram Code */\n    if (manager.available())\n    {\n      // Wait for a message addressed to us from the client\n      uint8_t len = sizeof(buf);\n      uint8_t from;\n      if (manager.recvfromAck(buf, &len, &from))\n      {\n        Serial.print(\"got request from : 0x\");\n        Serial.print(from, HEX);\n        Serial.print(\": \");\n        Serial.println((char*)buf);\n      }\n    }\n    /* End Reliable Datagram Code */\n\n    if (flag)\n    {\n      printf(\"\\n---CTRL-C Caught - Exiting---\\n\");\n      break;\n    }\n    //sleep(1);\n    delay(25);\n  }\n  printf( \"\\nRasPiRH Tester Ending\\n\" );\n  bcm2835_close();\n  return 0;\n}\n\nvoid sig_handler(int sig)\n{\n  flag=1;\n}\n\nvoid printbuffer(uint8_t buff[], int len)\n{\n  for (int i = 0; i< len; i++)\n  {\n    printf(\" %2X\", buff[i]);\n  }\n}\n"
  },
  {
    "path": "examples/raspi/rf69/Makefile",
    "content": "# Makefile\n# Sample for RH_RF69 (client and server) on Raspberry Pi\n# Caution: requires bcm2835 library to be already installed\n# http://www.airspayce.com/mikem/bcm2835/\n\nCC            = g++\nCFLAGS        = -DRASPBERRY_PI -DBCM2835_NO_DELAY_COMPATIBILITY -D__BASEFILE__=\\\"$*\\\"\nLIBS          = -lbcm2835\nRADIOHEADBASE = ../../..\nINCLUDE       = -I$(RADIOHEADBASE)\n\nall: rf69_client rf69_server\n\nRasPi.o: $(RADIOHEADBASE)/RHutil/RasPi.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil/RasPi.cpp $(INCLUDE)\n\nrf69_client.o: rf69_client.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nrf69_server.o: rf69_server.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRH_RF69.o: $(RADIOHEADBASE)/RH_RF69.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nrf69_client: rf69_client.o RH_RF69.o RasPi.o RHHardwareSPI.o RHGenericDriver.o RHGenericSPI.o RHSPIDriver.o\n\t\t\t\t$(CC) $^ $(LIBS) -o rf69_client\n\nrf69_server: rf69_server.o RH_RF69.o RasPi.o RHHardwareSPI.o RHGenericDriver.o RHGenericSPI.o RHSPIDriver.o\n\t\t\t\t$(CC) $^ $(LIBS) -o rf69_server\n\nclean:\n\t\t\t\trm -rf *.o rf69_client rf69_server\n"
  },
  {
    "path": "examples/raspi/rf69/rf69_client.cpp",
    "content": "// rf69_client.cpp\n//\n// Example program showing how to use RH_RF69 on Raspberry Pi\n// Uses the bcm2835 library to access the GPIO pins to drive the RFM69 module\n// Requires bcm2835 library to be already installed\n// http://www.airspayce.com/mikem/bcm2835/\n// Use the Makefile in this directory:\n// cd example/raspi/rf69\n// make\n// sudo ./rf69_client\n//\n// Contributed by Charles-Henri Hallard based on sample RH_NRF24 by Mike Poublon\n\n#include <bcm2835.h>\n#include <stdio.h>\n#include <signal.h>\n#include <unistd.h>\n\n#include <RH_RF69.h>\n\n// define hardware used change to fit your need\n// Uncomment the board you have, if not listed \n// uncommment custom board and set wiring tin custom section\n\n// LoRasPi board \n// see https://github.com/hallard/LoRasPI\n#define BOARD_LORASPI\n\n// iC880A and LinkLab Lora Gateway Shield (if RF module plugged into)\n// see https://github.com/ch2i/iC880A-Raspberry-PI\n//#define BOARD_IC880A_PLATE\n\n// Raspberri PI Lora Gateway for multiple modules \n// see https://github.com/hallard/RPI-Lora-Gateway\n//#define BOARD_PI_LORA_GATEWAY\n\n// Dragino Raspberry PI hat\n// see https://github.com/dragino/Lora\n//#define BOARD_DRAGINO_PIHAT\n\n// Now we include RasPi_Boards.h so this will expose defined \n// constants with CS/IRQ/RESET/on board LED pins definition\n#include \"../RasPiBoards.h\"\n\n// Our RFM69 Configuration \n#define RF_FREQUENCY  433.00\n#define RF_GROUP_ID   69 // Moteino default is 100, I'm using 69 on all my house\n#define RF_GATEWAY_ID 1  // Were to send packet\n#define RF_NODE_ID    10 // our own ID\n\n// Create an instance of a driver\nRH_RF69 rf69(RF_CS_PIN, RF_IRQ_PIN);\n//RH_RF69 rf69(RF_CS_PIN);\n\n//Flag for Ctrl-C\nvolatile sig_atomic_t force_exit = false;\n\nvoid sig_handler(int sig)\n{\n  printf(\"\\n%s Break received, exiting!\\n\", __BASEFILE__);\n  force_exit=true;\n}\n\n//Main Function\nint main (int argc, const char* argv[] )\n{\n  static unsigned long last_millis;\n  static unsigned long led_blink = 0;\n  \n  signal(SIGINT, sig_handler);\n  printf( \"%s\\n\", __BASEFILE__);\n\n  if (!bcm2835_init()) {\n    fprintf( stderr, \"%s bcm2835_init() Failed\\n\\n\", __BASEFILE__ );\n    return 1;\n  }\n  \n  printf( \"RF69 CS=GPIO%d\", RF_CS_PIN);\n\n#ifdef RF_LED_PIN\n  pinMode(RF_LED_PIN, OUTPUT);\n  digitalWrite(RF_LED_PIN, HIGH );\n#endif\n\n#ifdef RF_IRQ_PIN\n  printf( \", IRQ=GPIO%d\", RF_IRQ_PIN );\n  // IRQ Pin input/pull down \n  // But it's not used in this client send test\n  pinMode(RF_IRQ_PIN, INPUT);\n  bcm2835_gpio_set_pud(RF_IRQ_PIN, BCM2835_GPIO_PUD_DOWN);\n#endif\n  \n#ifdef RF_RST_PIN\n  printf( \", RST=GPIO%d\", RF_RST_PIN );\n  // Pulse a reset on module\n  pinMode(RF_RST_PIN, OUTPUT);\n  digitalWrite(RF_RST_PIN, LOW );\n  bcm2835_delay(150);\n  digitalWrite(RF_RST_PIN, HIGH );\n  bcm2835_delay(100);\n#endif\n\n#ifdef RF_LED_PIN\n  printf( \", LED=GPIO%d\", RF_LED_PIN );\n  digitalWrite(RF_LED_PIN, LOW );\n#endif\n\n  if (!rf69.init()) {\n    fprintf( stderr, \"\\nRF69 module init failed, Please verify wiring/module\\n\" );\n  } else {\n    printf( \"\\nRF69 module seen OK!\\r\\n\");\n\n#ifdef RF_IRQ_PIN\n    // Since we may check IRQ line with bcm_2835 Rising edge detection\n    // In case radio already have a packet, IRQ is high and will never\n    // go to low so never fire again \n    // Except if we clear IRQ flags and discard one if any by checking\n    rf69.available();\n\n    // Now we can enable Rising edge detection\n    bcm2835_gpio_ren(RF_IRQ_PIN);\n#endif\n\n    \n    // Defaults after init are 434.0MHz, +13dBm, no encryption, GFSK=250kbps, Fdev=250kHz\n\n    // The default transmitter power is 13dBm. If you are using\n    // High power version (RFM69HW or RFM69HCW) you need to set \n    // transmitter power to at least 14 dBm up to 20dBm\n    rf69.setTxPower(20); \n\n    // Now we change back to Moteino setting to be \n    // compatible with RFM69 library from lowpowerlabs \n    rf69.setModemConfig( RH_RF69::FSK_MOTEINO);\n\n    // set Network ID (by sync words)\n    uint8_t syncwords[2];\n    syncwords[0] = 0x2d;\n    syncwords[1] = RF_GROUP_ID;\n    rf69.setSyncWords(syncwords, sizeof(syncwords));\n\n    // Adjust Frequency\n    rf69.setFrequency( RF_FREQUENCY );\n\n    // This is our Node ID\n    rf69.setThisAddress(RF_NODE_ID);\n    rf69.setHeaderFrom(RF_NODE_ID);\n    \n    // Where we're sending packet\n    rf69.setHeaderTo(RF_GATEWAY_ID);  \n\n    printf(\"RF69 GroupID=%d, node #%d init OK @ %3.2fMHz\\n\", RF_GROUP_ID, RF_NODE_ID, RF_FREQUENCY );\n\n    last_millis = millis();\n\n    //Begin the main body of code\n    while (!force_exit) {\n\n      //printf( \"millis()=%ld last=%ld diff=%ld\\n\", millis() , last_millis,  millis() - last_millis );\n\n      // Send every 5 seconds\n      if ( millis() - last_millis > 5000 ) {\n        last_millis = millis();\n\n#ifdef RF_LED_PIN\n        led_blink = millis();\n        digitalWrite(RF_LED_PIN, HIGH);\n#endif\n        \n        // Send a message to rf69_server\n        uint8_t data[] = \"Hi Raspi!\";\n        uint8_t len = sizeof(data);\n        \n        printf(\"Sending %02d bytes to node #%d => \", len, RF_GATEWAY_ID );\n        printbuffer(data, len);\n        printf(\"\\n\" );\n        rf69.send(data, len);\n        rf69.waitPacketSent();\n/*\n        // Now wait for a reply\n        uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];\n        uint8_t len = sizeof(buf);\n\n        if (rf69.waitAvailableTimeout(1000)) { \n          // Should be a reply message for us now   \n          if (rf69.recv(buf, &len)) {\n            printf(\"got reply: \");\n            printbuffer(buf,len);\n            printf(\"\\nRSSI: %d\\n\", rf69.lastRssi());\n          } else {\n            printf(\"recv failed\");\n          }\n        } else {\n          printf(\"No reply, is rf69_server running?\\n\");\n        }\n*/\n        \n      }\n\n#ifdef RF_LED_PIN\n      // Led blink timer expiration ?\n      if (led_blink && millis()-led_blink>200) {\n        led_blink = 0;\n        digitalWrite(RF_LED_PIN, LOW);\n      }\n#endif\n      \n      // Let OS doing other tasks\n      // Since we do nothing until each 5 sec\n      bcm2835_delay(100);\n    }\n  }\n\n#ifdef RF_LED_PIN\n  digitalWrite(RF_LED_PIN, LOW );\n#endif\n  printf( \"\\n%s Ending\\n\", __BASEFILE__ );\n  bcm2835_close();\n  return 0;\n}\n\n"
  },
  {
    "path": "examples/raspi/rf69/rf69_server.cpp",
    "content": "// rf69_server.cpp\n//\n// Example program showing how to use RH_RF69 on Raspberry Pi\n// Uses the bcm2835 library to access the GPIO pins to drive the RFM69 module\n// Requires bcm2835 library to be already installed\n// http://www.airspayce.com/mikem/bcm2835/\n// Use the Makefile in this directory:\n// cd example/raspi/rf69\n// make\n// sudo ./rf69_server\n//\n// Contributed by Charles-Henri Hallard based on sample RH_NRF24 by Mike Poublon\n\n#include <bcm2835.h>\n#include <stdio.h>\n#include <signal.h>\n#include <unistd.h>\n\n#include <RH_RF69.h>\n#include <RH_RF69.h>\n\n// define hardware used change to fit your need\n// Uncomment the board you have, if not listed \n// uncommment custom board and set wiring tin custom section\n\n// LoRasPi board \n// see https://github.com/hallard/LoRasPI\n#define BOARD_LORASPI\n\n// iC880A and LinkLab Lora Gateway Shield (if RF module plugged into)\n// see https://github.com/ch2i/iC880A-Raspberry-PI\n//#define BOARD_IC880A_PLATE\n\n// Raspberri PI Lora Gateway for multiple modules \n// see https://github.com/hallard/RPI-Lora-Gateway\n//#define BOARD_PI_LORA_GATEWAY\n\n// Dragino Raspberry PI hat\n// see https://github.com/dragino/Lora\n//#define BOARD_DRAGINO_PIHAT\n\n// Now we include RasPi_Boards.h so this will expose defined \n// constants with CS/IRQ/RESET/on board LED pins definition\n#include \"../RasPiBoards.h\"\n\n// Our RFM69 Configuration \n#define RF_FREQUENCY  433.00\n#define RF_NODE_ID    1  // We're node ID 1 (Gateway)\n#define RF_GROUP_ID   69 // Moteino default is 100, I'm using 69 on all my house\n\n// Create an instance of a driver\nRH_RF69 rf69(RF_CS_PIN, RF_IRQ_PIN);\n//RH_RF69 rf69(RF_CS_PIN);\n\n//Flag for Ctrl-C\nvolatile sig_atomic_t force_exit = false;\n\nvoid sig_handler(int sig)\n{\n  printf(\"\\n%s Break received, exiting!\\n\", __BASEFILE__);\n  force_exit=true;\n}\n\n//Main Function\nint main (int argc, const char* argv[] )\n{\n  unsigned long led_blink = 0;\n  \n  signal(SIGINT, sig_handler);\n  printf( \"%s\\n\", __BASEFILE__);\n\n  if (!bcm2835_init()) {\n    fprintf( stderr, \"%s bcm2835_init() Failed\\n\\n\", __BASEFILE__ );\n    return 1;\n  }\n  \n  printf( \"RF69 CS=GPIO%d\", RF_CS_PIN);\n\n#ifdef RF_LED_PIN\n  pinMode(RF_LED_PIN, OUTPUT);\n  digitalWrite(RF_LED_PIN, HIGH );\n#endif\n\n#ifdef RF_IRQ_PIN\n  printf( \", IRQ=GPIO%d\", RF_IRQ_PIN );\n  // IRQ Pin input/pull down\n  pinMode(RF_IRQ_PIN, INPUT);\n  bcm2835_gpio_set_pud(RF_IRQ_PIN, BCM2835_GPIO_PUD_DOWN);\n  // Now we can enable Rising edge detection\n  bcm2835_gpio_ren(RF_IRQ_PIN);\n#endif\n  \n#ifdef RF_RST_PIN\n  printf( \", RST=GPIO%d\", RF_RST_PIN );\n  // Pulse a reset on module\n  pinMode(RF_RST_PIN, OUTPUT);\n  digitalWrite(RF_RST_PIN, LOW );\n  bcm2835_delay(150);\n  digitalWrite(RF_RST_PIN, HIGH );\n  bcm2835_delay(100);\n#endif\n\n#ifdef RF_LED_PIN\n  printf( \", LED=GPIO%d\", RF_LED_PIN );\n  digitalWrite(RF_LED_PIN, LOW );\n#endif\n\n  if (!rf69.init()) {\n    fprintf( stderr, \"\\nRF69 module init failed, Please verify wiring/module\\n\" );\n  } else {\n    printf( \"\\nRF69 module seen OK!\\r\\n\");\n\n\n    \n    // Defaults after init are 434.0MHz, +13dBm, no encryption, GFSK=250kbps, Fdev=250kHz\n\n    // The default transmitter power is 13dBm. If you are using\n    // High power version (RFM69HW or RFM69HCW) you need to set \n    // transmitter power to at least 14 dBm up to 20dBm\n    rf69.setTxPower(20); \n\n    // Now we change back to Moteino setting to be \n    // compatible with RFM69 library from lowpowerlabs \n    rf69.setModemConfig( RH_RF69::FSK_MOTEINO);\n\n    // set Network ID (by sync words)\n    uint8_t syncwords[2];\n    syncwords[0] = 0x2d;\n    syncwords[1] = RF_GROUP_ID;\n    rf69.setSyncWords(syncwords, sizeof(syncwords));\n\n    // Adjust Frequency\n    rf69.setFrequency( RF_FREQUENCY );\n\n    // This is our Node ID\n    rf69.setThisAddress(RF_NODE_ID);\n    rf69.setHeaderFrom(RF_NODE_ID);\n    \n    printf(\"RF69 GroupID=%d, node #%d init OK @ %3.2fMHz\\n\", RF_GROUP_ID, RF_NODE_ID, RF_FREQUENCY );\n\n    // Be sure to grab all node packet \n    // we're sniffing to display, it's a demo\n    rf69.setPromiscuous(true);\n\n    // We're ready to listen for incoming message\n    rf69.setModeRx();\n\n    printf( \" OK NodeID=%d @ %3.2fMHz\\n\", RF_NODE_ID, RF_FREQUENCY );\n    printf( \"Listening packet...\\n\" );\n\n    //Begin the main body of code\n    while (!force_exit) {\n      \n#ifdef RF_IRQ_PIN\n      // We have a IRQ pin ,pool it instead reading\n      // Modules IRQ registers from SPI in each loop\n      \n      // Rising edge fired ?\n      if (bcm2835_gpio_eds(RF_IRQ_PIN)) {\n        // Now clear the eds flag by setting it to 1\n        bcm2835_gpio_set_eds(RF_IRQ_PIN);\n        //printf(\"Packet Received, Rising event detect for pin GPIO%d\\n\", RF_IRQ_PIN);\n#endif\n\n        if (rf69.available()) { \n#ifdef RF_LED_PIN\n          led_blink = millis();\n          digitalWrite(RF_LED_PIN, HIGH);\n#endif\n          // Should be a message for us now\n          uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];\n          uint8_t len  = sizeof(buf);\n          uint8_t from = rf69.headerFrom();\n          uint8_t to   = rf69.headerTo();\n          uint8_t id   = rf69.headerId();\n          uint8_t flags= rf69.headerFlags();;\n          int8_t rssi  = rf69.lastRssi();\n          \n          if (rf69.recv(buf, &len)) {\n            printf(\"Packet[%02d] #%d => #%d %ddB: \", len, from, to, rssi);\n            printbuffer(buf, len);\n          } else {\n            Serial.print(\"receive failed\");\n          }\n          printf(\"\\n\");\n        }\n        \n#ifdef RF_IRQ_PIN\n      }\n#endif\n      \n#ifdef RF_LED_PIN\n      // Led blink timer expiration ?\n      if (led_blink && millis()-led_blink>200) {\n        led_blink = 0;\n        digitalWrite(RF_LED_PIN, LOW);\n      }\n#endif\n      // Let OS doing other tasks\n      // For timed critical appliation you can reduce or delete\n      // this delay, but this will charge CPU usage, take care and monitor\n      bcm2835_delay(5);\n    }\n  }\n\n#ifdef RF_LED_PIN\n  digitalWrite(RF_LED_PIN, LOW );\n#endif\n  printf( \"\\n%s Ending\\n\", __BASEFILE__ );\n  bcm2835_close();\n  return 0;\n}\n\n"
  },
  {
    "path": "examples/raspi/rf95/Makefile",
    "content": "# Makefile\n# Sample for RH_RF95 (client and server) on Raspberry Pi\n# Caution: requires bcm2835 library to be already installed\n# http://www.airspayce.com/mikem/bcm2835/\n\nCC            = g++\nCFLAGS        = -DRASPBERRY_PI -DBCM2835_NO_DELAY_COMPATIBILITY -D__BASEFILE__=\\\"$*\\\"\nLIBS          = -lbcm2835\nRADIOHEADBASE = ../../..\nINCLUDE       = -I$(RADIOHEADBASE)\n\nall: rf95_client rf95_server\n\nRasPi.o: $(RADIOHEADBASE)/RHutil/RasPi.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil/RasPi.cpp $(INCLUDE)\n\nrf95_client.o: rf95_client.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nrf95_server.o: rf95_server.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nRHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nrf95_client: rf95_client.o RH_RF95.o RasPi.o RHHardwareSPI.o RHGenericDriver.o RHGenericSPI.o RHSPIDriver.o\n\t\t\t\t$(CC) $^ $(LIBS) -o rf95_client\n\nrf95_server: rf95_server.o RH_RF95.o RasPi.o RHHardwareSPI.o RHGenericDriver.o RHGenericSPI.o RHSPIDriver.o\n\t\t\t\t$(CC) $^ $(LIBS) -o rf95_server\n\nclean:\n\t\t\t\trm -rf *.o rf95_client rf95_server\n"
  },
  {
    "path": "examples/raspi/rf95/rf95_client.cpp",
    "content": "// rf95_client.cpp\n//\n// Example program showing how to use RH_RF95 on Raspberry Pi\n// Uses the bcm2835 library to access the GPIO pins to drive the RFM95 module\n// Requires bcm2835 library to be already installed\n// http://www.airspayce.com/mikem/bcm2835/\n// Use the Makefile in this directory:\n// cd example/raspi/rf95\n// make\n// sudo ./rf95_client\n//\n// Contributed by Charles-Henri Hallard based on sample RH_NRF24 by Mike Poublon\n\n#include <bcm2835.h>\n#include <stdio.h>\n#include <signal.h>\n#include <unistd.h>\n\n#include <RH_RF69.h>\n#include <RH_RF95.h>\n\n// define hardware used change to fit your need\n// Uncomment the board you have, if not listed \n// uncommment custom board and set wiring tin custom section\n\n// LoRasPi board \n// see https://github.com/hallard/LoRasPI\n#define BOARD_LORASPI\n\n// iC880A and LinkLab Lora Gateway Shield (if RF module plugged into)\n// see https://github.com/ch2i/iC880A-Raspberry-PI\n//#define BOARD_IC880A_PLATE\n\n// Raspberri PI Lora Gateway for multiple modules \n// see https://github.com/hallard/RPI-Lora-Gateway\n//#define BOARD_PI_LORA_GATEWAY\n\n// Dragino Raspberry PI hat\n// see https://github.com/dragino/Lora\n//#define BOARD_DRAGINO_PIHAT\n\n// Now we include RasPi_Boards.h so this will expose defined \n// constants with CS/IRQ/RESET/on board LED pins definition\n#include \"../RasPiBoards.h\"\n\n// Our RFM95 Configuration \n#define RF_FREQUENCY  868.00\n#define RF_GATEWAY_ID 1 \n#define RF_NODE_ID    10\n\n// Create an instance of a driver\nRH_RF95 rf95(RF_CS_PIN, RF_IRQ_PIN);\n//RH_RF95 rf95(RF_CS_PIN);\n\n//Flag for Ctrl-C\nvolatile sig_atomic_t force_exit = false;\n\nvoid sig_handler(int sig)\n{\n  printf(\"\\n%s Break received, exiting!\\n\", __BASEFILE__);\n  force_exit=true;\n}\n\n//Main Function\nint main (int argc, const char* argv[] )\n{\n  static unsigned long last_millis;\n  static unsigned long led_blink = 0;\n  \n  signal(SIGINT, sig_handler);\n  printf( \"%s\\n\", __BASEFILE__);\n\n  if (!bcm2835_init()) {\n    fprintf( stderr, \"%s bcm2835_init() Failed\\n\\n\", __BASEFILE__ );\n    return 1;\n  }\n  \n  printf( \"RF95 CS=GPIO%d\", RF_CS_PIN);\n\n#ifdef RF_LED_PIN\n  pinMode(RF_LED_PIN, OUTPUT);\n  digitalWrite(RF_LED_PIN, HIGH );\n#endif\n\n#ifdef RF_IRQ_PIN\n  printf( \", IRQ=GPIO%d\", RF_IRQ_PIN );\n  // IRQ Pin input/pull down \n  pinMode(RF_IRQ_PIN, INPUT);\n  bcm2835_gpio_set_pud(RF_IRQ_PIN, BCM2835_GPIO_PUD_DOWN);\n#endif\n  \n#ifdef RF_RST_PIN\n  printf( \", RST=GPIO%d\", RF_RST_PIN );\n  // Pulse a reset on module\n  pinMode(RF_RST_PIN, OUTPUT);\n  digitalWrite(RF_RST_PIN, LOW );\n  bcm2835_delay(150);\n  digitalWrite(RF_RST_PIN, HIGH );\n  bcm2835_delay(100);\n#endif\n\n#ifdef RF_LED_PIN\n  printf( \", LED=GPIO%d\", RF_LED_PIN );\n  digitalWrite(RF_LED_PIN, LOW );\n#endif\n\n  if (!rf95.init()) {\n    fprintf( stderr, \"\\nRF95 module init failed, Please verify wiring/module\\n\" );\n  } else {\n    printf( \"\\nRF95 module seen OK!\\r\\n\");\n\n#ifdef RF_IRQ_PIN\n    // Since we may check IRQ line with bcm_2835 Rising edge detection\n    // In case radio already have a packet, IRQ is high and will never\n    // go to low so never fire again \n    // Except if we clear IRQ flags and discard one if any by checking\n    rf95.available();\n\n    // Now we can enable Rising edge detection\n    bcm2835_gpio_ren(RF_IRQ_PIN);\n#endif\n\n    // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on\n\n    // The default transmitter power is 13dBm, using PA_BOOST.\n    // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then \n    // you can set transmitter powers from 5 to 23 dBm:\n    //rf95.setTxPower(23, false); \n    // If you are using Modtronix inAir4 or inAir9,or any other module which uses the\n    // transmitter RFO pins and not the PA_BOOST pins\n    // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. \n    // Failure to do that will result in extremely low transmit powers.\n    //rf95.setTxPower(14, true);\n\n    rf95.setTxPower(14, false); \n\n    // You can optionally require this module to wait until Channel Activity\n    // Detection shows no activity on the channel before transmitting by setting\n    // the CAD timeout to non-zero:\n    //rf95.setCADTimeout(10000);\n\n    // Adjust Frequency\n    rf95.setFrequency( RF_FREQUENCY );\n\n    // This is our Node ID\n    rf95.setThisAddress(RF_NODE_ID);\n    rf95.setHeaderFrom(RF_NODE_ID);\n    \n    // Where we're sending packet\n    rf95.setHeaderTo(RF_GATEWAY_ID);  \n\n    printf(\"RF95 node #%d init OK @ %3.2fMHz\\n\", RF_NODE_ID, RF_FREQUENCY );\n\n    last_millis = millis();\n\n    //Begin the main body of code\n    while (!force_exit) {\n\n      //printf( \"millis()=%ld last=%ld diff=%ld\\n\", millis() , last_millis,  millis() - last_millis );\n\n      // Send every 5 seconds\n      if ( millis() - last_millis > 5000 ) {\n        last_millis = millis();\n\n#ifdef RF_LED_PIN\n        led_blink = millis();\n        digitalWrite(RF_LED_PIN, HIGH);\n#endif\n        \n        // Send a message to rf95_server\n        uint8_t data[] = \"Hi Raspi!\";\n        uint8_t len = sizeof(data);\n        \n        printf(\"Sending %02d bytes to node #%d => \", len, RF_GATEWAY_ID );\n        printbuffer(data, len);\n        printf(\"\\n\" );\n        rf95.send(data, len);\n        rf95.waitPacketSent();\n/*\n        // Now wait for a reply\n        uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];\n        uint8_t len = sizeof(buf);\n\n        if (rf95.waitAvailableTimeout(1000)) { \n          // Should be a reply message for us now   \n          if (rf95.recv(buf, &len)) {\n            printf(\"got reply: \");\n            printbuffer(buf,len);\n            printf(\"\\nRSSI: %d\\n\", rf95.lastRssi());\n          } else {\n            printf(\"recv failed\");\n          }\n        } else {\n          printf(\"No reply, is rf95_server running?\\n\");\n        }\n*/\n        \n      }\n\n#ifdef RF_LED_PIN\n      // Led blink timer expiration ?\n      if (led_blink && millis()-led_blink>200) {\n        led_blink = 0;\n        digitalWrite(RF_LED_PIN, LOW);\n      }\n#endif\n      \n      // Let OS doing other tasks\n      // Since we do nothing until each 5 sec\n      bcm2835_delay(100);\n    }\n  }\n\n#ifdef RF_LED_PIN\n  digitalWrite(RF_LED_PIN, LOW );\n#endif\n  printf( \"\\n%s Ending\\n\", __BASEFILE__ );\n  bcm2835_close();\n  return 0;\n}\n\n"
  },
  {
    "path": "examples/raspi/rf95/rf95_server.cpp",
    "content": "// rf95_server.cpp\n//\n// Example program showing how to use RH_RF95 on Raspberry Pi\n// Uses the bcm2835 library to access the GPIO pins to drive the RFM95 module\n// Requires bcm2835 library to be already installed\n// http://www.airspayce.com/mikem/bcm2835/\n// Use the Makefile in this directory:\n// cd example/raspi/rf95\n// make\n// sudo ./rf95_server\n//\n// Contributed by Charles-Henri Hallard based on sample RH_NRF24 by Mike Poublon\n\n#include <bcm2835.h>\n#include <stdio.h>\n#include <signal.h>\n#include <unistd.h>\n\n#include <RH_RF69.h>\n#include <RH_RF95.h>\n\n// define hardware used change to fit your need\n// Uncomment the board you have, if not listed \n// uncommment custom board and set wiring tin custom section\n\n// LoRasPi board \n// see https://github.com/hallard/LoRasPI\n#define BOARD_LORASPI\n\n// iC880A and LinkLab Lora Gateway Shield (if RF module plugged into)\n// see https://github.com/ch2i/iC880A-Raspberry-PI\n//#define BOARD_IC880A_PLATE\n\n// Raspberri PI Lora Gateway for multiple modules \n// see https://github.com/hallard/RPI-Lora-Gateway\n//#define BOARD_PI_LORA_GATEWAY\n\n// Dragino Raspberry PI hat\n// see https://github.com/dragino/Lora\n//#define BOARD_DRAGINO_PIHAT\n\n// Now we include RasPi_Boards.h so this will expose defined \n// constants with CS/IRQ/RESET/on board LED pins definition\n#include \"../RasPiBoards.h\"\n\n// Our RFM95 Configuration \n#define RF_FREQUENCY  868.00\n#define RF_NODE_ID    1\n\n// Create an instance of a driver\nRH_RF95 rf95(RF_CS_PIN, RF_IRQ_PIN);\n//RH_RF95 rf95(RF_CS_PIN);\n\n//Flag for Ctrl-C\nvolatile sig_atomic_t force_exit = false;\n\nvoid sig_handler(int sig)\n{\n  printf(\"\\n%s Break received, exiting!\\n\", __BASEFILE__);\n  force_exit=true;\n}\n\n//Main Function\nint main (int argc, const char* argv[] )\n{\n  unsigned long led_blink = 0;\n  \n  signal(SIGINT, sig_handler);\n  printf( \"%s\\n\", __BASEFILE__);\n\n  if (!bcm2835_init()) {\n    fprintf( stderr, \"%s bcm2835_init() Failed\\n\\n\", __BASEFILE__ );\n    return 1;\n  }\n  \n  printf( \"RF95 CS=GPIO%d\", RF_CS_PIN);\n\n#ifdef RF_LED_PIN\n  pinMode(RF_LED_PIN, OUTPUT);\n  digitalWrite(RF_LED_PIN, HIGH );\n#endif\n\n#ifdef RF_IRQ_PIN\n  printf( \", IRQ=GPIO%d\", RF_IRQ_PIN );\n  // IRQ Pin input/pull down\n  pinMode(RF_IRQ_PIN, INPUT);\n  bcm2835_gpio_set_pud(RF_IRQ_PIN, BCM2835_GPIO_PUD_DOWN);\n  // Now we can enable Rising edge detection\n  bcm2835_gpio_ren(RF_IRQ_PIN);\n#endif\n  \n#ifdef RF_RST_PIN\n  printf( \", RST=GPIO%d\", RF_RST_PIN );\n  // Pulse a reset on module\n  pinMode(RF_RST_PIN, OUTPUT);\n  digitalWrite(RF_RST_PIN, LOW );\n  bcm2835_delay(150);\n  digitalWrite(RF_RST_PIN, HIGH );\n  bcm2835_delay(100);\n#endif\n\n#ifdef RF_LED_PIN\n  printf( \", LED=GPIO%d\", RF_LED_PIN );\n  digitalWrite(RF_LED_PIN, LOW );\n#endif\n\n  if (!rf95.init()) {\n    fprintf( stderr, \"\\nRF95 module init failed, Please verify wiring/module\\n\" );\n  } else {\n    // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on\n\n    // The default transmitter power is 13dBm, using PA_BOOST.\n    // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then \n    // you can set transmitter powers from 5 to 23 dBm:\n    //  driver.setTxPower(23, false);\n    // If you are using Modtronix inAir4 or inAir9,or any other module which uses the\n    // transmitter RFO pins and not the PA_BOOST pins\n    // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. \n    // Failure to do that will result in extremely low transmit powers.\n    // rf95.setTxPower(14, true);\n\n\n    // RF95 Modules don't have RFO pin connected, so just use PA_BOOST\n    // check your country max power useable, in EU it's +14dB\n    rf95.setTxPower(14, false);\n\n    // You can optionally require this module to wait until Channel Activity\n    // Detection shows no activity on the channel before transmitting by setting\n    // the CAD timeout to non-zero:\n    //rf95.setCADTimeout(10000);\n\n    // Adjust Frequency\n    rf95.setFrequency(RF_FREQUENCY);\n    \n    // If we need to send something\n    rf95.setThisAddress(RF_NODE_ID);\n    rf95.setHeaderFrom(RF_NODE_ID);\n    \n    // Be sure to grab all node packet \n    // we're sniffing to display, it's a demo\n    rf95.setPromiscuous(true);\n\n    // We're ready to listen for incoming message\n    rf95.setModeRx();\n\n    printf( \" OK NodeID=%d @ %3.2fMHz\\n\", RF_NODE_ID, RF_FREQUENCY );\n    printf( \"Listening packet...\\n\" );\n\n    //Begin the main body of code\n    while (!force_exit) {\n      \n#ifdef RF_IRQ_PIN\n      // We have a IRQ pin ,pool it instead reading\n      // Modules IRQ registers from SPI in each loop\n      \n      // Rising edge fired ?\n      if (bcm2835_gpio_eds(RF_IRQ_PIN)) {\n        // Now clear the eds flag by setting it to 1\n        bcm2835_gpio_set_eds(RF_IRQ_PIN);\n        //printf(\"Packet Received, Rising event detect for pin GPIO%d\\n\", RF_IRQ_PIN);\n#endif\n\n        if (rf95.available()) { \n#ifdef RF_LED_PIN\n          led_blink = millis();\n          digitalWrite(RF_LED_PIN, HIGH);\n#endif\n          // Should be a message for us now\n          uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];\n          uint8_t len  = sizeof(buf);\n          uint8_t from = rf95.headerFrom();\n          uint8_t to   = rf95.headerTo();\n          uint8_t id   = rf95.headerId();\n          uint8_t flags= rf95.headerFlags();;\n          int8_t rssi  = rf95.lastRssi();\n          \n          if (rf95.recv(buf, &len)) {\n            printf(\"Packet[%02d] #%d => #%d %ddB: \", len, from, to, rssi);\n            printbuffer(buf, len);\n          } else {\n            Serial.print(\"receive failed\");\n          }\n          printf(\"\\n\");\n        }\n        \n#ifdef RF_IRQ_PIN\n      }\n#endif\n      \n#ifdef RF_LED_PIN\n      // Led blink timer expiration ?\n      if (led_blink && millis()-led_blink>200) {\n        led_blink = 0;\n        digitalWrite(RF_LED_PIN, LOW);\n      }\n#endif\n      // Let OS doing other tasks\n      // For timed critical appliation you can reduce or delete\n      // this delay, but this will charge CPU usage, take care and monitor\n      bcm2835_delay(5);\n    }\n  }\n\n#ifdef RF_LED_PIN\n  digitalWrite(RF_LED_PIN, LOW );\n#endif\n  printf( \"\\n%s Ending\\n\", __BASEFILE__ );\n  bcm2835_close();\n  return 0;\n}\n\n"
  },
  {
    "path": "examples/raspi/spi_scan/Makefile",
    "content": "# Makefile\n# Sample for spi scan Hope RF module on Raspberry Pi\n# Caution: requires bcm2835 library to be already installed\n# http://www.airspayce.com/mikem/bcm2835/\n\nCC            = g++\nCFLAGS        = -DRASPBERRY_PI -DBCM2835_NO_DELAY_COMPATIBILITY\nLIBS          = -lbcm2835 \nRADIOHEADBASE = ../../..\nINCLUDE       = -I$(RADIOHEADBASE)\n\nall: spi_scan\n\nspi_scan.o: spi_scan.c\n\t\t\t\t$(CC) $(CFLAGS) -c $(INCLUDE) $<\n\nspi_scan: spi_scan.o\n\t\t\t\t$(CC) $^ $(LIBS) -o spi_scan\n\nclean:\n\t\t\t\trm -rf *.o spi_scan\n"
  },
  {
    "path": "examples/raspi/spi_scan/spi_scan.c",
    "content": "// spi_scan.cpp\n//\n// Example program showing how to detect multiple module RH_RF69/RH_RF95 on Raspberry Pi\n// Requires bcm2835 library to be already installed\n// http://www.airspayce.com/mikem/bcm2835/\n// Use the Makefile in this directory:\n// cd example/raspi/spi_scan\n// make\n// sudo ./spi_scan\n//\n// Will check for RFM92/95/96/98 or RFM69/RFM69HCW/RFM69W modules on SPI BUS\n// scan with CS = GPIO6, CE0, CE1 and GPIO26\n// So it should detect the following boards\n// LoRasPi board => https://github.com/hallard/LoRasPI\n// RasPI Lora Gateway Board iC880A and LinkLab Lora => https://github.com/ch2i/iC880A-Raspberry-PI\n// Raspberri PI Lora Gateway => https://github.com/hallard/RPI-Lora-Gateway\n// Dragino Raspberry PI hat => https://github.com/dragino/Lora\n//\n// Contributed by Charles-Henri Hallard (hallard.me)\n\n#include <bcm2835.h>\n#include <stdio.h>\n\n#include \"RH_RF69.h\"\n#include \"RH_RF95.h\"\n\nuint8_t readRegister(uint8_t cs_pin, uint8_t addr)\n{\n  char spibuf[2];\n  spibuf[0] = addr & 0x7F;\n  spibuf[1] = 0x00;\n\n  bcm2835_gpio_write(cs_pin,0);\n  bcm2835_spi_transfernb( spibuf, spibuf, sizeof(spibuf) );\n  bcm2835_gpio_write(cs_pin,1);\n  return spibuf[1];\n}\n\nvoid getModuleName(uint8_t version)\n{ \n  printf(\" => \");\n  if (version==00 || version==0xFF )\n    printf(\"Nothing!\\n\");\n  else if (version == 0x12)\n    printf(\"SX1276 RF95/96\");\n  else if (version == 0x22)\n    printf(\"SX1272 RF92\");\n  else if (version == 0x24)\n    printf(\"SX1231 RFM69\");\n  else \n    printf(\"Unknown\");\n\n  if (version!=00 && version!=0xFF )\n    printf(\" (V=0x%02X)\\n\", version);\n}\n\nvoid readModuleVersion(uint8_t cs_pin)\n{\n  uint8_t version;\n\n  // RFM9x version is reg 0x42\n  printf(\"Checking register(0x42) with CS=GPIO%02d\", cs_pin);\n  getModuleName( readRegister( cs_pin, 0x42) );\n\n  // RFM69 version is reg 0x10\n  printf(\"Checking register(0x10) with CS=GPIO%02d\", cs_pin);\n  getModuleName ( readRegister( cs_pin, 0x10) ) ;\n}\n\nint main(int argc, char **argv)\n{\n  if (!bcm2835_init()) {\n    printf(\"bcm2835_init failed. Are you running as root??\\n\");\n\n  } else if (!bcm2835_spi_begin()) {\n    printf(\"bcm2835_spi_begin failed\\n\");\n\n  } else {\n    // List of all CS line where module can be connected\n    // GPIO6, GPIO8/CE0, GPIO7/CE1, GPIO26\n    uint8_t CS_pins[] = {6, 7, 8, 26};\n    uint8_t i;\n\n    // Init SPI\n    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      // The default\n    bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);                   // The default\n    bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default\n\n    // We control CS line manually don't assert CEx line!\n    bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE);\n\n    // Drive all CS line as output and set them High to avoid any conflict\n    for ( i=0; i<sizeof(CS_pins); i++) {\n      bcm2835_gpio_fsel (CS_pins[i], BCM2835_GPIO_FSEL_OUTP );\n      bcm2835_gpio_write(CS_pins[i], 1 );\n    }\n\n    // Now try to detect all modules\n    for ( i=0; i<sizeof(CS_pins); i++) {\n      readModuleVersion( CS_pins[i] ); \n    }\n\n    bcm2835_spi_end();\n  }\n\n  bcm2835_close();\n}\n\n\n"
  },
  {
    "path": "examples/rf22/rf22_client/rf22_client.pde",
    "content": "// rf22_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing client\n// with the RH_RF22 class. RH_RF22 class does not provide for addressing or\n// reliability, so you should only use RH_RF22 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example rf22_server\n// Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shield\n// Tested on Flymaple with sparkfun RFM22 wireless shield\n// Tested on ChiKit Uno32 with sparkfun RFM22 wireless shield\n\n#include <SPI.h>\n#include <RH_RF22.h>\n\n// Singleton instance of the radio driver\nRH_RF22 rf22;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!rf22.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n}\n\nvoid loop()\n{\n  Serial.println(\"Sending to rf22_server\");\n  // Send a message to rf22_server\n  uint8_t data[] = \"Hello World!\";\n  rf22.send(data, sizeof(data));\n  \n  rf22.waitPacketSent();\n  // Now wait for a reply\n  uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];\n  uint8_t len = sizeof(buf);\n\n  if (rf22.waitAvailableTimeout(500))\n  { \n    // Should be a reply message for us now   \n    if (rf22.recv(buf, &len))\n    {\n      Serial.print(\"got reply: \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n  else\n  {\n    Serial.println(\"No reply, is rf22_server running?\");\n  }\n  delay(400);\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_mesh_client/rf22_mesh_client.pde",
    "content": "// rf22_mesh_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, routed reliable messaging client\n// with the RHMesh class.\n// It is designed to work with the other examples rf22_mesh_server*\n// Hint: you can simulate other network topologies by setting the \n// RH_TEST_NETWORK define in RHRouter.h\n\n// Mesh has much greater memory requirements, and you may need to limit the\n// max message length to prevent wierd crashes\n#define RH_MESH_MAX_MESSAGE_LEN 50\n\n#include <RHMesh.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n// In this small artifical network of 4 nodes,\n#define CLIENT_ADDRESS 1\n#define SERVER1_ADDRESS 2\n#define SERVER2_ADDRESS 3\n#define SERVER3_ADDRESS 4\n\n// Singleton instance of the radio driver\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHMesh manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_MESH_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to manager_mesh_server3\");\n    \n  // Send a message to a rf22_mesh_server\n  // A route to the destination will be automatically discovered.\n  if (manager.sendtoWait(data, sizeof(data), SERVER3_ADDRESS) == RH_ROUTER_ERROR_NONE)\n  {\n    // It has been reliably delivered to the next node.\n    // Now wait for a reply from the ultimate server\n    uint8_t len = sizeof(buf);\n    uint8_t from;    \n    if (manager.recvfromAckTimeout(buf, &len, 3000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is rf22_mesh_server1, rf22_mesh_server2 and rf22_mesh_server3 running?\");\n    }\n  }\n  else\n     Serial.println(\"sendtoWait failed. Are the intermediate mesh servers running?\");\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_mesh_server1/rf22_mesh_server1.pde",
    "content": "// rf22_mesh_server1.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, routed reliable messaging server\n// with the RHMesh class.\n// It is designed to work with the other examples rf22_mesh_*\n// Hint: you can simulate other network topologies by setting the \n// RH_TEST_NETWORK define in RHRouter.h\n\n// Mesh has much greater memory requirements, and you may need to limit the\n// max message length to prevent wierd crashes\n#define RH_MESH_MAX_MESSAGE_LEN 50\n\n#include <RHMesh.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n// In this small artifical network of 4 nodes,\n#define CLIENT_ADDRESS 1\n#define SERVER1_ADDRESS 2\n#define SERVER2_ADDRESS 3\n#define SERVER3_ADDRESS 4\n\n// Singleton instance of the radio driver\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHMesh manager(driver, SERVER1_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"RF22 init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n}\n\nuint8_t data[] = \"And hello back to you from server1\";\n// Dont put this on the stack:\nuint8_t buf[RH_MESH_MAX_MESSAGE_LEN];\nvoid loop()\n{\n  uint8_t len = sizeof(buf);\n  uint8_t from;\n  if (manager.recvfromAck(buf, &len, &from))\n  {\n    Serial.print(\"got request from : 0x\");\n    Serial.print(from, HEX);\n    Serial.print(\": \");\n    Serial.println((char*)buf);\n\n    // Send a reply back to the originator client\n    if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)\n      Serial.println(\"sendtoWait failed\");\n  }\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_mesh_server2/rf22_mesh_server2.pde",
    "content": "// rf22_mesh_server1.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, routed reliable messaging server\n// with the RHMesh class.\n// It is designed to work with the other examples rf22_mesh_*\n// Hint: you can simulate other network topologies by setting the \n// RH_TEST_NETWORK define in RHRouter.h\n\n// Mesh has much greater memory requirements, and you may need to limit the\n// max message length to prevent wierd crashes\n#define RH_MESH_MAX_MESSAGE_LEN 50\n\n#include <RHMesh.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n// In this small artifical network of 4 nodes,\n#define CLIENT_ADDRESS 1\n#define SERVER1_ADDRESS 2\n#define SERVER2_ADDRESS 3\n#define SERVER3_ADDRESS 4\n\n// Singleton instance of the radio driver\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHMesh manager(driver, SERVER2_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"RF22 init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n}\n\nuint8_t data[] = \"And hello back to you from server2\";\n// Dont put this on the stack:\nuint8_t buf[RH_MESH_MAX_MESSAGE_LEN];\nvoid loop()\n{\n  uint8_t len = sizeof(buf);\n  uint8_t from;\n  if (manager.recvfromAck(buf, &len, &from))\n  {\n    Serial.print(\"got request from : 0x\");\n    Serial.print(from, HEX);\n    Serial.print(\": \");\n    Serial.println((char*)buf);\n\n    // Send a reply back to the originator client\n    if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)\n      Serial.println(\"sendtoWait failed\");\n  }\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_mesh_server3/rf22_mesh_server3.pde",
    "content": "// rf22_mesh_server3.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, routed reliable messaging server\n// with the RHMesh class.\n// It is designed to work with the other examples rf22_mesh_*\n// Hint: you can simulate other network topologies by setting the \n// RH_TEST_NETWORK define in RHRouter.h\n\n// Mesh has much greater memory requirements, and you may need to limit the\n// max message length to prevent wierd crashes\n#define RH_MESH_MAX_MESSAGE_LEN 50\n\n#include <RHMesh.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n// In this small artifical network of 4 nodes,\n#define CLIENT_ADDRESS 1\n#define SERVER1_ADDRESS 2\n#define SERVER2_ADDRESS 3\n#define SERVER3_ADDRESS 4\n\n// Singleton instance of the radio driver\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHMesh manager(driver, SERVER3_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"RF22 init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n}\n\nuint8_t data[] = \"And hello back to you from server3\";\n// Dont put this on the stack:\nuint8_t buf[RH_MESH_MAX_MESSAGE_LEN];\nvoid loop()\n{\n  uint8_t len = sizeof(buf);\n  uint8_t from;\n  if (manager.recvfromAck(buf, &len, &from))\n  {\n    Serial.print(\"got request from : 0x\");\n    Serial.print(from, HEX);\n    Serial.print(\": \");\n    Serial.println((char*)buf);\n\n    // Send a reply back to the originator client\n    if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)\n      Serial.println(\"sendtoWait failed\");\n  }\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_reliable_datagram_client/rf22_reliable_datagram_client.pde",
    "content": "// rf22_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_RF22 driver to control a RF22 radio.\n// It is designed to work with the other example rf22_reliable_datagram_server\n// Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shield\n// Tested on Flymaple with sparkfun RFM22 wireless shield\n// Tested on ChiKit Uno32 with sparkfun RFM22 wireless shield\n\n#include <RHReliableDatagram.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_RF22_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to rf22_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is rf22_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_reliable_datagram_server/rf22_reliable_datagram_server.pde",
    "content": "// rf22_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_RF22 driver to control a RF22 radio.\n// It is designed to work with the other example rf22_reliable_datagram_client\n// Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shield\n// Tested on Flymaple with sparkfun RFM22 wireless shield\n// Tested on ChiKit Uno32 with sparkfun RFM22 wireless shield\n\n#include <RHReliableDatagram.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_RF22_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  if (manager.available())\n  {\n    // Wait for a message addressed to us from the client\n    uint8_t len = sizeof(buf);\n    uint8_t from;\n    if (manager.recvfromAck(buf, &len, &from))\n    {\n      Serial.print(\"got request from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n\n      // Send a reply back to the originator client\n      if (!manager.sendtoWait(data, sizeof(data), from))\n        Serial.println(\"sendtoWait failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_router_client/rf22_router_client.pde",
    "content": "// rf22_router_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, routed reliable messaging client\n// with the RHRouter class.\n// It is designed to work with the other examples rf22_router_server*\n\n#include <RHRouter.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n// In this small artifical network of 4 nodes,\n// messages are routed via intermediate nodes to their destination\n// node. All nodes can act as routers\n// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS\n#define CLIENT_ADDRESS 1\n#define SERVER1_ADDRESS 2\n#define SERVER2_ADDRESS 3\n#define SERVER3_ADDRESS 4\n\n// Singleton instance of the radio driver\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHRouter manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n  \n  // Manually define the routes for this network\n  manager.addRouteTo(SERVER1_ADDRESS, SERVER1_ADDRESS);  \n  manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);\n  manager.addRouteTo(SERVER3_ADDRESS, SERVER3_ADDRESS);\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to rf22_router_server3\");\n    \n  // Send a message to a rf22_router_server\n  // It will be routed by the intermediate\n  // nodes to the destination node, accorinding to the\n  // routing tables in each node\n  if (manager.sendtoWait(data, sizeof(data), SERVER3_ADDRESS) == RH_ROUTER_ERROR_NONE)\n  {\n    // It has been reliably delivered to the next node.\n    // Now wait for a reply from the ultimate server\n    uint8_t len = sizeof(buf);\n    uint8_t from;    \n    if (manager.recvfromAckTimeout(buf, &len, 3000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is rf22_router_server1, rf22_router_server2 and rf22_router_server3 running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed. Are the intermediate router servers running?\");\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_router_server1/rf22_router_server1.pde",
    "content": "// rf22_router_server1.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, routed reliable messaging server\n// with the RHRouter class.\n// It is designed to work with the other example rf22_router_client\n\n#include <RHRouter.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n// In this small artifical network of 4 nodes,\n// messages are routed via intermediate nodes to their destination\n// node. All nodes can act as routers\n// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS\n#define CLIENT_ADDRESS 1\n#define SERVER1_ADDRESS 2\n#define SERVER2_ADDRESS 3\n#define SERVER3_ADDRESS 4\n\n// Singleton instance of the radio\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHRouter manager(driver, SERVER1_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n  \n  // Manually define the routes for this network\n  manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);  \n  manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);\n  manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);\n}\n\nuint8_t data[] = \"And hello back to you from server1\";\n// Dont put this on the stack:\nuint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  uint8_t len = sizeof(buf);\n  uint8_t from;\n  if (manager.recvfromAck(buf, &len, &from))\n  {\n    Serial.print(\"got request from : 0x\");\n    Serial.print(from, HEX);\n    Serial.print(\": \");\n     Serial.println((char*)buf);\n\n    // Send a reply back to the originator client\n    if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)\n      Serial.println(\"sendtoWait failed\");\n  }\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_router_server2/rf22_router_server2.pde",
    "content": "// rf22_router_server2.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, routed reliable messaging server\n// with the RHRouter class.\n// It is designed to work with the other example rf22_router_client\n\n#include <RHRouter.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n// In this small artifical network of 4 nodes,\n// messages are routed via intermediate nodes to their destination\n// node. All nodes can act as routers\n// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS\n#define CLIENT_ADDRESS 1\n#define SERVER1_ADDRESS 2\n#define SERVER2_ADDRESS 3\n#define SERVER3_ADDRESS 4\n\n// Singleton instance of the radio\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHRouter manager(driver, SERVER2_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n  \n  // Manually define the routes for this network\n  manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);  \n  manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);\n  manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);\n}\n\nuint8_t data[] = \"And hello back to you from server2\";\n// Dont put this on the stack:\nuint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  uint8_t len = sizeof(buf);\n  uint8_t from;\n  if (manager.recvfromAck(buf, &len, &from))\n  {\n    Serial.print(\"got request from : 0x\");\n    Serial.print(from, HEX);\n    Serial.print(\": \");\n     Serial.println((char*)buf);\n\n    // Send a reply back to the originator client\n    if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)\n      Serial.println(\"sendtoWait failed\");\n  }\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_router_server3/rf22_router_server3.pde",
    "content": "// rf22_router_server3.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, routed reliable messaging server\n// with the RHRouter class.\n// It is designed to work with the other example rf22_router_client\n\n#include <RHRouter.h>\n#include <RH_RF22.h>\n#include <SPI.h>\n\n// In this small artifical network of 4 nodes,\n// messages are routed via intermediate nodes to their destination\n// node. All nodes can act as routers\n// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS\n#define CLIENT_ADDRESS 1\n#define SERVER1_ADDRESS 2\n#define SERVER2_ADDRESS 3\n#define SERVER3_ADDRESS 4\n\n// Singleton instance of the radio\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHRouter manager(driver, SERVER3_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n  \n  // Manually define the routes for this network\n  manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);  \n  manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);\n  manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);\n}\n\nuint8_t data[] = \"And hello back to you from server3\";\n// Dont put this on the stack:\nuint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  uint8_t len = sizeof(buf);\n  uint8_t from;\n  if (manager.recvfromAck(buf, &len, &from))\n  {\n    Serial.print(\"got request from : 0x\");\n    Serial.print(from, HEX);\n    Serial.print(\": \");\n     Serial.println((char*)buf);\n\n    // Send a reply back to the originator client\n    if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)\n      Serial.println(\"sendtoWait failed\");\n  }\n}\n\n"
  },
  {
    "path": "examples/rf22/rf22_router_test/rf22_router_test.pde",
    "content": "// rf22_router_test.pde\n// -*- mode: C++ -*-\n//\n// Test code used during library development, showing how\n// to do various things, and how to call various functions\n\n#include <SPI.h>\n#include <RHRouter.h>\n#include <RH_RF22.h>\n\n#define CLIENT_ADDRESS 1\n#define ROUTER_ADDRESS 2\n#define SERVER_ADDRESS 3\n\n// Singleton instance of the radio driver\nRH_RF22 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHRouter manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"RF22 init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n}\n\nvoid test_routes()\n{\n  manager.clearRoutingTable();\n//  manager.printRoutingTable();\n  manager.addRouteTo(1, 101);\n  manager.addRouteTo(2, 102);\n  manager.addRouteTo(3, 103);\n  RHRouter::RoutingTableEntry* e;\n  e = manager.getRouteTo(0);\n  if (e) // Should fail\n    Serial.println(\"getRouteTo 0 failed\");\n    \n  e = manager.getRouteTo(1);\n  if (!e)\n    Serial.println(\"getRouteTo 1 failed\");\n  if (e->dest != 1)\n    Serial.println(\"getRouteTo 2 failed\");\n  if (e->next_hop != 101)\n    Serial.println(\"getRouteTo 3 failed\");\n  if (e->state != RHRouter::Valid)\n    Serial.println(\"getRouteTo 4 failed\");\n    \n  e = manager.getRouteTo(2);\n  if (!e)\n    Serial.println(\"getRouteTo 5 failed\");\n  if (e->dest != 2)\n    Serial.println(\"getRouteTo 6 failed\");\n  if (e->next_hop != 102)\n    Serial.println(\"getRouteTo 7 failed\");\n  if (e->state != RHRouter::Valid)\n    Serial.println(\"getRouteTo 8 failed\");\n    \n  if (!manager.deleteRouteTo(1))\n      Serial.println(\"deleteRouteTo 1 failed\");\n  // Route to 1 should now be gone\n  e = manager.getRouteTo(1);\n  if (e)\n    Serial.println(\"deleteRouteTo 2 failed\");\n    \n  Serial.println(\"-------------------\");\n\n//  manager.printRoutingTable();\n  delay(500);\n\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\n//uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];\n\nvoid test_tx()\n{\n  manager.addRouteTo(SERVER_ADDRESS, ROUTER_ADDRESS);\n  uint8_t errorcode;\n  errorcode = manager.sendtoWait(data, sizeof(data), 100); // Should fail with no route\n  if (errorcode != RH_ROUTER_ERROR_NO_ROUTE)\n    Serial.println(\"sendtoWait 1 failed\");\n  errorcode = manager.sendtoWait(data, 255, 10); // Should fail too big\n  if (errorcode != RH_ROUTER_ERROR_INVALID_LENGTH)\n    Serial.println(\"sendtoWait 2 failed\");   \n  errorcode = manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS); // Should fail after timeouts to 110\n  if (errorcode != RH_ROUTER_ERROR_UNABLE_TO_DELIVER)\n    Serial.println(\"sendtoWait 3 failed\");\n  Serial.println(\"-------------------\");\n  delay(500);\n}\n\nvoid loop()\n{\n//  test_routes();\n  test_tx();\n}\n\n\n"
  },
  {
    "path": "examples/rf22/rf22_server/rf22_server.pde",
    "content": "// rf22_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing server\n// with the RH_RF22 class. RH_RF22 class does not provide for addressing or\n// reliability, so you should only use RH_RF22  if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example rf22_client\n// Tested on Duemilanove, Uno with Sparkfun RFM22 wireless shield\n// Tested on Flymaple with sparkfun RFM22 wireless shield\n// Tested on ChiKit Uno32 with sparkfun RFM22 wireless shield\n\n#include <SPI.h>\n#include <RH_RF22.h>\n\n// Singleton instance of the radio driver\nRH_RF22 rf22;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!rf22.init())\n    Serial.println(\"init failed\");  \n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n}\n\nvoid loop()\n{\n  if (rf22.available())\n  {\n    // Should be a message for us now   \n    uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];\n    uint8_t len = sizeof(buf);\n    if (rf22.recv(buf, &len))\n    {\n//      RF22::printBuffer(\"request: \", buf, len);\n      Serial.print(\"got request: \");\n      Serial.println((char*)buf);\n//      Serial.print(\"RSSI: \");\n//      Serial.println(rf22.lastRssi(), DEC);\n      \n      // Send a reply\n      uint8_t data[] = \"And hello back to you\";\n      rf22.send(data, sizeof(data));\n      rf22.waitPacketSent();\n      Serial.println(\"Sent a reply\");\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/rf24/rf24_client/rf24_client.pde",
    "content": "// rf24_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing client\n// with the RH_RF24 class. RH_RF24 class does not provide for addressing or\n// reliability, so you should only use RH_RF24 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example rf24_server.\n// Tested on Anarduino Mini http://www.anarduino.com/mini/ with RFM24W and RFM26W\n\n#include <SPI.h>\n#include <RH_RF24.h>\n\n// Singleton instance of the radio driver\nRH_RF24 rf24;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!rf24.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, modulation GFSK_Rb5Fd10, power 0x10\n//  if (!rf24.setFrequency(433.0))\n//    Serial.println(\"setFrequency failed\");\n}\n\n\nvoid loop()\n{\n  Serial.println(\"Sending to rf24_server\");\n  // Send a message to rf24_server\n  uint8_t data[] = \"Hello World!\";\n  rf24.send(data, sizeof(data));\n  \n  rf24.waitPacketSent();\n  // Now wait for a reply\n  uint8_t buf[RH_RF24_MAX_MESSAGE_LEN];\n  uint8_t len = sizeof(buf);\n\n  if (rf24.waitAvailableTimeout(500))\n  { \n    // Should be a reply message for us now   \n    if (rf24.recv(buf, &len))\n    {\n      Serial.print(\"got reply: \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n  else\n  {\n    Serial.println(\"No reply, is rf24_server running?\");\n  }\n  delay(400);\n}\n\n"
  },
  {
    "path": "examples/rf24/rf24_reliable_datagram_client/rf24_reliable_datagram_client.pde",
    "content": "// rf24_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_RF24 driver to control a RF24 radio.\n// It is designed to work with the other example rf24_reliable_datagram_server\n// Tested on Anarduino Mini http://www.anarduino.com/mini/ with RFM24W and RFM26W\n\n#include <RHReliableDatagram.h>\n#include <RH_RF24.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_RF24 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, modulation GFSK_Rb5Fd10, power 0x10\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_RF24_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to rf24_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is rf24_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/rf24/rf24_reliable_datagram_server/rf24_reliable_datagram_server.pde",
    "content": "// rf24_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_RF24 driver to control a RF24 radio.\n// It is designed to work with the other example rf24_reliable_datagram_client\n// Tested on Anarduino Mini http://www.anarduino.com/mini/ with RFM24W and RFM26W\n\n#include <RHReliableDatagram.h>\n#include <RH_RF24.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_RF24 driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, modulation GFSK_Rb5Fd10, power 0x10\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_RF24_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  if (manager.available())\n  {\n    // Wait for a message addressed to us from the client\n    uint8_t len = sizeof(buf);\n    uint8_t from;\n    if (manager.recvfromAck(buf, &len, &from))\n    {\n      Serial.print(\"got request from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n\n      // Send a reply back to the originator client\n      if (!manager.sendtoWait(data, sizeof(data), from))\n        Serial.println(\"sendtoWait failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/rf24/rf24_server/rf24_server.pde",
    "content": "// rf24_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing server\n// with the RH_RF24 class. RH_RF24 class does not provide for addressing or\n// reliability, so you should only use RH_RF24  if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example rf24_client\n// Tested on Anarduino Mini http://www.anarduino.com/mini/ with RFM24W and RFM26W\n\n#include <SPI.h>\n#include <RH_RF24.h>\n\n// Singleton instance of the radio driver\nRH_RF24 rf24;\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!rf24.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, modulation GFSK_Rb5Fd10, power 0x10\n//  if (!rf24.setFrequency(433.0))\n//    Serial.println(\"setFrequency failed\");\n\n}\n\nvoid loop()\n{\n  if (rf24.available())\n  {\n    // Should be a message for us now   \n    uint8_t buf[RH_RF24_MAX_MESSAGE_LEN];\n    uint8_t len = sizeof(buf);\n    if (rf24.recv(buf, &len))\n    {\n//      RF24::printBuffer(\"request: \", buf, len);\n      Serial.print(\"got request: \");\n      Serial.println((char*)buf);\n//      Serial.print(\"RSSI: \");\n//      Serial.println((uint8_t)rf24.lastRssi(), DEC);\n      \n      // Send a reply\n      uint8_t data[] = \"And hello back to you\";\n      rf24.send(data, sizeof(data));\n      rf24.waitPacketSent();\n      Serial.println(\"Sent a reply\");\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/rf69/rf69_client/rf69_client.pde",
    "content": "// rf69_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing client\n// with the RH_RF69 class. RH_RF69 class does not provide for addressing or\n// reliability, so you should only use RH_RF69  if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example rf69_server.\n// Demonstrates the use of AES encryption, setting the frequency and modem \n// configuration\n// Tested on Moteino with RFM69 http://lowpowerlab.com/moteino/\n// Tested on miniWireless with RFM69 www.anarduino.com/miniwireless\n// Tested on Teensy 3.1 with RF69 on PJRC breakout board\n\n#include <SPI.h>\n#include <RH_RF69.h>\n\n// Singleton instance of the radio driver\nRH_RF69 rf69;\n//RH_RF69 rf69(15, 16); // For RF69 on PJRC breakout board with Teensy 3.1\n//RH_RF69 rf69(4, 2); // For MoteinoMEGA https://lowpowerlab.com/shop/moteinomega\n//RH_RF69 rf69(8, 7); // Adafruit Feather 32u4\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial) \n    ;\n  if (!rf69.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM\n  // No encryption\n  if (!rf69.setFrequency(433.0))\n    Serial.println(\"setFrequency failed\");\n\n  // If you are using a high power RF69, you *must* set a Tx power in the\n  // range 14 to 20 like this:\n  // rf69.setTxPower(14);\n\n  // The encryption key has to be the same as the one in the server\n  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,\n                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};\n  rf69.setEncryptionKey(key);\n}\n\n\nvoid loop()\n{\n  Serial.println(\"Sending to rf69_server\");\n  // Send a message to rf69_server\n  uint8_t data[] = \"Hello World!\";\n  rf69.send(data, sizeof(data));\n  \n  rf69.waitPacketSent();\n  // Now wait for a reply\n  uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];\n  uint8_t len = sizeof(buf);\n\n  if (rf69.waitAvailableTimeout(500))\n  { \n    // Should be a reply message for us now   \n    if (rf69.recv(buf, &len))\n    {\n      Serial.print(\"got reply: \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n  else\n  {\n    Serial.println(\"No reply, is rf69_server running?\");\n  }\n  delay(400);\n}\n\n"
  },
  {
    "path": "examples/rf69/rf69_reliable_datagram_client/rf69_reliable_datagram_client.pde",
    "content": "// rf69_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_RF69 driver to control a RF69 radio.\n// It is designed to work with the other example rf69_reliable_datagram_server\n// Tested on Moteino with RFM69 http://lowpowerlab.com/moteino/\n// Tested on miniWireless with RFM69 www.anarduino.com/miniwireless\n// Tested on Teensy 3.1 with RF69 on PJRC breakout board\n\n#include <RHReliableDatagram.h>\n#include <RH_RF69.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_RF69 driver;\n//RH_RF69 driver(15, 16); // For RF69 on PJRC breakout board with Teensy 3.1\n//RH_RF69 driver(4, 2); // For MoteinoMEGA https://lowpowerlab.com/shop/moteinomega\n//RH_RF69 driver(8, 7); // Adafruit Feather 32u4\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial) \n    ;\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM\n\n  // If you are using a high power RF69, you *must* set a Tx power in the\n  // range 14 to 20 like this:\n  // driver.setTxPower(14);\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_RF69_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to rf69_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is rf69_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/rf69/rf69_reliable_datagram_server/rf69_reliable_datagram_server.pde",
    "content": "// rf69_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_RF69 driver to control a RF69 radio.\n// It is designed to work with the other example rf69_reliable_datagram_client\n// Tested on Moteino with RFM69 http://lowpowerlab.com/moteino/\n// Tested on miniWireless with RFM69 www.anarduino.com/miniwireless\n// Tested on Teensy 3.1 with RF69 on PJRC breakout board\n\n#include <RHReliableDatagram.h>\n#include <RH_RF69.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_RF69 driver;\n//RH_RF69 driver(15, 16); // For RF69 on PJRC breakout board with Teensy 3.1\n//RH_RF69 rf69(4, 2); // For MoteinoMEGA https://lowpowerlab.com/shop/moteinomega\n//RH_RF69 driver(8, 7); // Adafruit Feather 32u4\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial) \n    ;\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM\n\n  // If you are using a high power RF69, you *must* set a Tx power in the\n  // range 14 to 20 like this:\n  // driver.setTxPower(14);\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_RF69_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  if (manager.available())\n  {\n    // Wait for a message addressed to us from the client\n    uint8_t len = sizeof(buf);\n    uint8_t from;\n    if (manager.recvfromAck(buf, &len, &from))\n    {\n      Serial.print(\"got request from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n\n      // Send a reply back to the originator client\n      if (!manager.sendtoWait(data, sizeof(data), from))\n        Serial.println(\"sendtoWait failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/rf69/rf69_server/rf69_server.pde",
    "content": "// rf69_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing server\n// with the RH_RF69 class. RH_RF69 class does not provide for addressing or\n// reliability, so you should only use RH_RF69  if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example rf69_client\n// Demonstrates the use of AES encryption, setting the frequency and modem\n// configuration.\n// Tested on Moteino with RFM69 http://lowpowerlab.com/moteino/\n// Tested on miniWireless with RFM69 www.anarduino.com/miniwireless\n// Tested on Teensy 3.1 with RF69 on PJRC breakout board\n\n#include <SPI.h>\n#include <RH_RF69.h>\n\n// Singleton instance of the radio driver\nRH_RF69 rf69;\n//RH_RF69 rf69(15, 16); // For RF69 on PJRC breakout board with Teensy 3.1\n//RH_RF69 rf69(4, 2); // For MoteinoMEGA https://lowpowerlab.com/shop/moteinomega\n//RH_RF69 rf69(8, 7); // Adafruit Feather 32u4\n\nvoid setup() \n{\n  Serial.begin(9600);\n  while (!Serial) \n    ;\n  if (!rf69.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM\n  // No encryption\n  if (!rf69.setFrequency(433.0))\n    Serial.println(\"setFrequency failed\");\n\n  // If you are using a high power RF69, you *must* set a Tx power in the\n  // range 14 to 20 like this:\n  // rf69.setTxPower(14);\n\n // The encryption key has to be the same as the one in the client\n  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,\n                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};\n  rf69.setEncryptionKey(key);\n  \n#if 0\n  // For compat with RFM69 Struct_send\n  rf69.setModemConfig(RH_RF69::GFSK_Rb250Fd250);\n  rf69.setPreambleLength(3);\n  uint8_t syncwords[] = { 0x2d, 0x64 };\n  rf69.setSyncWords(syncwords, sizeof(syncwords));\n  rf69.setEncryptionKey((uint8_t*)\"thisIsEncryptKey\");\n#endif\n}\n\nvoid loop()\n{\n  if (rf69.available())\n  {\n    // Should be a message for us now   \n    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];\n    uint8_t len = sizeof(buf);\n    if (rf69.recv(buf, &len))\n    {\n//      RH_RF69::printBuffer(\"request: \", buf, len);\n      Serial.print(\"got request: \");\n      Serial.println((char*)buf);\n//      Serial.print(\"RSSI: \");\n//      Serial.println(rf69.lastRssi(), DEC);\n      \n      // Send a reply\n      uint8_t data[] = \"And hello back to you\";\n      rf69.send(data, sizeof(data));\n      rf69.waitPacketSent();\n      Serial.println(\"Sent a reply\");\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/rf95/rf95_client/rf95_client.pde",
    "content": "// rf95_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing client\n// with the RH_RF95 class. RH_RF95 class does not provide for addressing or\n// reliability, so you should only use RH_RF95 if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example rf95_server\n// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with\n// the RFM95W, Adafruit Feather M0 with RFM95\n\n#include <SPI.h>\n#include <RH_RF95.h>\n\n// Singleton instance of the radio driver\nRH_RF95 rf95;\n//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W\n//RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95 \n\n// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)\n//#define Serial SerialUSB\n\nvoid setup() \n{\n  // Rocket Scream Mini Ultra Pro with the RFM95W only:\n  // Ensure serial flash is not interfering with radio communication on SPI bus\n//  pinMode(4, OUTPUT);\n//  digitalWrite(4, HIGH);\n\n  Serial.begin(9600);\n  while (!Serial) ; // Wait for serial port to be available\n  if (!rf95.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on\n\n  // The default transmitter power is 13dBm, using PA_BOOST.\n  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then \n  // you can set transmitter powers from 5 to 23 dBm:\n//  driver.setTxPower(23, false);\n  // If you are using Modtronix inAir4 or inAir9,or any other module which uses the\n  // transmitter RFO pins and not the PA_BOOST pins\n  // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. \n  // Failure to do that will result in extremely low transmit powers.\n//  driver.setTxPower(14, true);\n}\n\nvoid loop()\n{\n  Serial.println(\"Sending to rf95_server\");\n  // Send a message to rf95_server\n  uint8_t data[] = \"Hello World!\";\n  rf95.send(data, sizeof(data));\n  \n  rf95.waitPacketSent();\n  // Now wait for a reply\n  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];\n  uint8_t len = sizeof(buf);\n\n  if (rf95.waitAvailableTimeout(3000))\n  { \n    // Should be a reply message for us now   \n    if (rf95.recv(buf, &len))\n   {\n      Serial.print(\"got reply: \");\n      Serial.println((char*)buf);\n//      Serial.print(\"RSSI: \");\n//      Serial.println(rf95.lastRssi(), DEC);    \n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n  else\n  {\n    Serial.println(\"No reply, is rf95_server running?\");\n  }\n  delay(400);\n}\n\n\n"
  },
  {
    "path": "examples/rf95/rf95_reliable_datagram_client/rf95_reliable_datagram_client.pde",
    "content": "// rf95_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_RF95 driver to control a RF95 radio.\n// It is designed to work with the other example rf95_reliable_datagram_server\n// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with the RFM95W \n\n#include <RHReliableDatagram.h>\n#include <RH_RF95.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_RF95 driver;\n//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\n// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)\n//#define Serial SerialUSB\n\nvoid setup() \n{\n  // Rocket Scream Mini Ultra Pro with the RFM95W only:\n  // Ensure serial flash is not interfering with radio communication on SPI bus\n//  pinMode(4, OUTPUT);\n//  digitalWrite(4, HIGH);\n\n  Serial.begin(9600);\n  while (!Serial) ; // Wait for serial port to be available\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on\n\n  // The default transmitter power is 13dBm, using PA_BOOST.\n  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then \n  // you can set transmitter powers from 5 to 23 dBm:\n//  driver.setTxPower(23, false);\n  // If you are using Modtronix inAir4 or inAir9,or any other module which uses the\n  // transmitter RFO pins and not the PA_BOOST pins\n  // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. \n  // Failure to do that will result in extremely low transmit powers.\n//  driver.setTxPower(14, true);\n  // You can optionally require this module to wait until Channel Activity\n  // Detection shows no activity on the channel before transmitting by setting\n  // the CAD timeout to non-zero:\n//  driver.setCADTimeout(10000);\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_RF95_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to rf95_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is rf95_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/rf95/rf95_reliable_datagram_server/rf95_reliable_datagram_server.pde",
    "content": "// rf95_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_RF95 driver to control a RF95 radio.\n// It is designed to work with the other example rf95_reliable_datagram_client\n// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with the RFM95W \n\n#include <RHReliableDatagram.h>\n#include <RH_RF95.h>\n#include <SPI.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_RF95 driver;\n//RH_RF95 driver(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\n// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)\n//#define Serial SerialUSB\n\nvoid setup() \n{\n  // Rocket Scream Mini Ultra Pro with the RFM95W only:\n  // Ensure serial flash is not interfering with radio communication on SPI bus\n//  pinMode(4, OUTPUT);\n//  digitalWrite(4, HIGH);\n\n  Serial.begin(9600);\n  while (!Serial) ; // Wait for serial port to be available\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on\n\n  // The default transmitter power is 13dBm, using PA_BOOST.\n  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then \n  // you can set transmitter powers from 5 to 23 dBm:\n//  driver.setTxPower(23, false);\n  // If you are using Modtronix inAir4 or inAir9,or any other module which uses the\n  // transmitter RFO pins and not the PA_BOOST pins\n  // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. \n  // Failure to do that will result in extremely low transmit powers.\n//  driver.setTxPower(14, true);\n  // You can optionally require this module to wait until Channel Activity\n  // Detection shows no activity on the channel before transmitting by setting\n  // the CAD timeout to non-zero:\n//  driver.setCADTimeout(10000);\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_RF95_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  if (manager.available())\n  {\n    // Wait for a message addressed to us from the client\n    uint8_t len = sizeof(buf);\n    uint8_t from;\n    if (manager.recvfromAck(buf, &len, &from))\n    {\n      Serial.print(\"got request from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n\n      // Send a reply back to the originator client\n      if (!manager.sendtoWait(data, sizeof(data), from))\n        Serial.println(\"sendtoWait failed\");\n    }\n  }\n}\n\n"
  },
  {
    "path": "examples/rf95/rf95_server/rf95_server.pde",
    "content": "// rf95_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple messageing server\n// with the RH_RF95 class. RH_RF95 class does not provide for addressing or\n// reliability, so you should only use RH_RF95  if you do not need the higher\n// level messaging abilities.\n// It is designed to work with the other example rf95_client\n// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with\n// the RFM95W, Adafruit Feather M0 with RFM95\n\n#include <SPI.h>\n#include <RH_RF95.h>\n\n// Singleton instance of the radio driver\nRH_RF95 rf95;\n//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W\n//RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95 \n\n// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)\n//#define Serial SerialUSB\n\nint led = 9;\n\nvoid setup() \n{\n  // Rocket Scream Mini Ultra Pro with the RFM95W only:\n  // Ensure serial flash is not interfering with radio communication on SPI bus\n//  pinMode(4, OUTPUT);\n//  digitalWrite(4, HIGH);\n\n  pinMode(led, OUTPUT);     \n  Serial.begin(9600);\n  while (!Serial) ; // Wait for serial port to be available\n  if (!rf95.init())\n    Serial.println(\"init failed\");  \n  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on\n\n  // The default transmitter power is 13dBm, using PA_BOOST.\n  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then \n  // you can set transmitter powers from 5 to 23 dBm:\n//  driver.setTxPower(23, false);\n  // If you are using Modtronix inAir4 or inAir9,or any other module which uses the\n  // transmitter RFO pins and not the PA_BOOST pins\n  // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. \n  // Failure to do that will result in extremely low transmit powers.\n//  driver.setTxPower(14, true);\n}\n\nvoid loop()\n{\n  if (rf95.available())\n  {\n    // Should be a message for us now   \n    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];\n    uint8_t len = sizeof(buf);\n    if (rf95.recv(buf, &len))\n    {\n      digitalWrite(led, HIGH);\n//      RH_RF95::printBuffer(\"request: \", buf, len);\n      Serial.print(\"got request: \");\n      Serial.println((char*)buf);\n//      Serial.print(\"RSSI: \");\n//      Serial.println(rf95.lastRssi(), DEC);\n      \n      // Send a reply\n      uint8_t data[] = \"And hello back to you\";\n      rf95.send(data, sizeof(data));\n      rf95.waitPacketSent();\n      Serial.println(\"Sent a reply\");\n       digitalWrite(led, LOW);\n    }\n    else\n    {\n      Serial.println(\"recv failed\");\n    }\n  }\n}\n\n\n"
  },
  {
    "path": "examples/serial/serial_reliable_datagram_client/serial_reliable_datagram_client.pde",
    "content": "// serial_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_Serial driver to\n// communicate using packets over a serial port (or a radio connected to a\n// serial port, such as the 3DR Telemetry radio V1 and others).\n// It is designed to work with the other example serial_reliable_datagram_server\n// Tested on Arduino Mega and ChipKit Uno32 (normal Arduinos only have one\n// serial port and so it not possible to test on them and still have debug\n// output)\n// Tested with Arduino Mega, Teensy 3.1, Moteino, Arduino Due\n// Also works on Linux and OSX. Build and test with:\n//  tools/simBuild examples/serial/serial_reliable_datagram_client/serial_reliable_datagram_client.pde\n//  RH_HARDWARESERIAL_DEVICE_NAME=/dev/ttyUSB1 ./serial_reliable_datagram_client \n\n#include <RHReliableDatagram.h>\n#include <RH_Serial.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n#if (RH_PLATFORM == RH_PLATFORM_UNIX) \n #include <RHutil/HardwareSerial.h>\n // On Unix we connect to a physical serial port\n // You can override this with RH_HARDWARESERIAL_DEVICE_NAME environment variable\n HardwareSerial hardwareserial(\"/dev/ttyUSB0\");\n RH_Serial driver(hardwareserial);\n\n#else\n // On arduino etc, use a predefined local serial port\n // eg Serial1 on a Mega\n #include <SPI.h>\n // Singleton instance of the Serial driver, configured\n // to use the port Serial1. Caution: on Uno32, Serial1 is on pins 39 (Rx) and\n // 40 (Tx)\n RH_Serial driver(Serial1);\n#endif\n\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  // Configure the port RH_Serial will use:\n  driver.serial().begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_SERIAL_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to serial_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is serial_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/serial/serial_reliable_datagram_server/serial_reliable_datagram_server.pde",
    "content": "// serial_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_Serial driver to\n// communicate using packets over a serial port (or a radio connected to a\n// serial port, such as the 3DR Telemetry radio V1 and others).\n// It is designed to work with the other example serial_reliable_datagram_client\n// Tested on Arduino Mega and ChipKit Uno32 (normal Arduinos only have one\n// serial port and so it not possible to test on them and still have debug\n// output)\n// Tested with Arduino Mega, Teensy 3.1, Moteino, Arduino Due\n// Also works on Linux an OSX. Build and test with:\n//  tools/simBuild examples/serial/serial_reliable_datagram_server/serial_reliable_datagram_server.pde\n//  RH_HARDWARESERIAL_DEVICE_NAME=/dev/ttyUSB0 ./serial_reliable_datagram_server \n\n#include <RHReliableDatagram.h>\n#include <RH_Serial.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n#if (RH_PLATFORM == RH_PLATFORM_UNIX)\n #include <RHutil/HardwareSerial.h>\n // On Unix we connect to a physical serial port\n // You can override this with RH_HARDWARESERIAL_DEVICE_NAME environment variable\n HardwareSerial hardwareserial(\"/dev/ttyUSB0\");\n RH_Serial driver(hardwareserial);\n\n#else\n // On arduino etc, use a predefined local serial port\n // eg Serial1 on a Mega\n #include <SPI.h>\n // Singleton instance of the Serial driver, configured\n // to use the port Serial1. Caution: on Uno32, Serial1 is on pins 39 (Rx) and\n // 40 (Tx)\n RH_Serial driver(Serial1);\n#endif\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  // Configure the port RH_Serial will use:\n  driver.serial().begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_SERIAL_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n\n  // Wait for a message addressed to us from the client\n  manager.waitAvailable();\n      \n  uint8_t len = sizeof(buf);\n  uint8_t from;\n  if (manager.recvfromAck(buf, &len, &from))\n  {\n    Serial.print(\"got request from : 0x\");\n    Serial.print(from, HEX);\n    Serial.print(\": \");\n    Serial.println((char*)buf);\n\n    // Send a reply back to the originator client\n    if (!manager.sendtoWait(data, sizeof(data), from))\n      Serial.println(\"sendtoWait failed\");\n  }\n}\n\n"
  },
  {
    "path": "examples/simulator/simulator_reliable_datagram_client/simulator_reliable_datagram_client.pde",
    "content": "// simulator_reliable_datagram_client.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging client\n// with the RHReliableDatagram class, using the RH_SIMULATOR driver to control a SIMULATOR radio.\n// It is designed to work with the other example simulator_reliable_datagram_server\n// Tested on Linux\n// Build with\n// cd whatever/RadioHead \n// tools/simBuild examples/simulator/simulator_reliable_datagram_client/simulator_reliable_datagram_client.pde\n// Run with ./simulator_reliable_datagram_client\n// Make sure you also have the 'Luminiferous Ether' simulator tools/etherSimulator.pl running\n\n#include <RHReliableDatagram.h>\n#include <RH_TCP.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_TCP driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, CLIENT_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n\n  // Maybe set this address from teh command line\n  if (_simulator_argc >= 2)\n     manager.setThisAddress(atoi(_simulator_argv[1]));\n}\n\nuint8_t data[] = \"Hello World!\";\n// Dont put this on the stack:\nuint8_t buf[RH_TCP_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  Serial.println(\"Sending to simulator_reliable_datagram_server\");\n    \n  // Send a message to manager_server\n  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))\n  {\n    // Now wait for a reply from the server\n    uint8_t len = sizeof(buf);\n    uint8_t from;   \n    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))\n    {\n      Serial.print(\"got reply from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n    }\n    else\n    {\n      Serial.println(\"No reply, is simulator_reliable_datagram_server running?\");\n    }\n  }\n  else\n    Serial.println(\"sendtoWait failed\");\n  delay(500);\n}\n\n"
  },
  {
    "path": "examples/simulator/simulator_reliable_datagram_server/simulator_reliable_datagram_server.pde",
    "content": "// simulator_reliable_datagram_server.pde\n// -*- mode: C++ -*-\n// Example sketch showing how to create a simple addressed, reliable messaging server\n// with the RHReliableDatagram class, using the RH_SIMULATOR driver to control a SIMULATOR radio.\n// It is designed to work with the other example simulator_reliable_datagram_client\n// Tested on Linux\n// Build with\n// cd whatever/RadioHead \n// tools/simBuild examples/simulator/simulator_reliable_datagram_server/simulator_reliable_datagram_server.pde\n// Run with ./simulator_reliable_datagram_server\n// Make sure you also have the 'Luminiferous Ether' simulator tools/etherSimulator.pl running\n\n#include <RHReliableDatagram.h>\n#include <RH_TCP.h>\n\n#define CLIENT_ADDRESS 1\n#define SERVER_ADDRESS 2\n\n// Singleton instance of the radio driver\nRH_TCP driver;\n\n// Class to manage message delivery and receipt, using the driver declared above\nRHReliableDatagram manager(driver, SERVER_ADDRESS);\n\nvoid setup() \n{\n  Serial.begin(9600);\n  if (!manager.init())\n    Serial.println(\"init failed\");\n  // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36\n    manager.setRetries(0); // Client will ping us if no ack received\n//  manager.setTimeout(50);\n}\n\nuint8_t data[] = \"And hello back to you\";\n// Dont put this on the stack:\nuint8_t buf[RH_TCP_MAX_MESSAGE_LEN];\n\nvoid loop()\n{\n  // Wait for a message addressed to us from the client\n  manager.waitAvailable();\n\n  // Wait for a message addressed to us from the client\n  uint8_t len = sizeof(buf);\n  uint8_t from;\n  if (manager.recvfromAck(buf, &len, &from))\n  {\n      Serial.print(\"got request from : 0x\");\n      Serial.print(from, HEX);\n      Serial.print(\": \");\n      Serial.println((char*)buf);\n      \n      // Send a reply back to the originator client\n      if (!manager.sendtoWait(data, sizeof(data), from))\n\t  Serial.println(\"sendtoWait failed\");\n  }\n}\n\n"
  },
  {
    "path": "project.cfg",
    "content": "# Doxyfile 1.8.8\n\n# This file describes the settings to be used by the documentation system\n# doxygen (www.doxygen.org) for a project.\n#\n# All text after a double hash (##) is considered a comment and is placed in\n# front of the TAG it is preceding.\n#\n# All text after a single hash (#) is considered a comment and will be ignored.\n# The format is:\n# TAG = value [value, ...]\n# For lists, items can also be appended using:\n# TAG += value [value, ...]\n# Values that contain spaces should be placed between quotes (\\\" \\\").\n\n#---------------------------------------------------------------------------\n# Project related configuration options\n#---------------------------------------------------------------------------\n\n# This tag specifies the encoding used for all characters in the config file\n# that follow. The default is UTF-8 which is also the encoding used for all text\n# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv\n# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv\n# for the list of possible encodings.\n# The default value is: UTF-8.\n\nDOXYFILE_ENCODING      = UTF-8\n\n# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by\n# double-quotes, unless you are using Doxywizard) that should identify the\n# project for which the documentation is generated. This name is used in the\n# title of most generated pages and in a few other places.\n# The default value is: My Project.\n\nPROJECT_NAME           = RadioHead\n\n# The PROJECT_NUMBER tag can be used to enter a project or revision number. This\n# could be handy for archiving the generated documentation or if some version\n# control system is used.\n\nPROJECT_NUMBER         =\n\n# Using the PROJECT_BRIEF tag one can provide an optional one line description\n# for a project that appears at the top of each page and should give viewer a\n# quick idea about the purpose of the project. Keep the description short.\n\nPROJECT_BRIEF          =\n\n# With the PROJECT_LOGO tag one can specify an logo or icon that is included in\n# the documentation. The maximum height of the logo should not exceed 55 pixels\n# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo\n# to the output directory.\n\nPROJECT_LOGO           =\n\n# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path\n# into which the generated documentation will be written. If a relative path is\n# entered, it will be relative to the location where doxygen was started. If\n# left blank the current directory will be used.\n\nOUTPUT_DIRECTORY       =\n\n# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub-\n# directories (in 2 levels) under the output directory of each output format and\n# will distribute the generated files over these directories. Enabling this\n# option can be useful when feeding doxygen a huge amount of source files, where\n# putting all generated files in the same directory would otherwise causes\n# performance problems for the file system.\n# The default value is: NO.\n\nCREATE_SUBDIRS         = NO\n\n# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII\n# characters to appear in the names of generated files. If set to NO, non-ASCII\n# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode\n# U+3044.\n# The default value is: NO.\n\nALLOW_UNICODE_NAMES    = NO\n\n# The OUTPUT_LANGUAGE tag is used to specify the language in which all\n# documentation generated by doxygen is written. Doxygen will use this\n# information to generate all constant output in the proper language.\n# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,\n# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),\n# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,\n# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),\n# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,\n# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,\n# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,\n# Ukrainian and Vietnamese.\n# The default value is: English.\n\nOUTPUT_LANGUAGE        = English\n\n# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member\n# descriptions after the members that are listed in the file and class\n# documentation (similar to Javadoc). Set to NO to disable this.\n# The default value is: YES.\n\nBRIEF_MEMBER_DESC      = YES\n\n# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief\n# description of a member or function before the detailed description\n#\n# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the\n# brief descriptions will be completely suppressed.\n# The default value is: YES.\n\nREPEAT_BRIEF           = YES\n\n# This tag implements a quasi-intelligent brief description abbreviator that is\n# used to form the text in various listings. Each string in this list, if found\n# as the leading text of the brief description, will be stripped from the text\n# and the result, after processing the whole list, is used as the annotated\n# text. Otherwise, the brief description is used as-is. If left blank, the\n# following values are used ($name is automatically replaced with the name of\n# the entity):The $name class, The $name widget, The $name file, is, provides,\n# specifies, contains, represents, a, an and the.\n\nABBREVIATE_BRIEF       =\n\n# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then\n# doxygen will generate a detailed section even if there is only a brief\n# description.\n# The default value is: NO.\n\nALWAYS_DETAILED_SEC    = NO\n\n# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all\n# inherited members of a class in the documentation of that class as if those\n# members were ordinary class members. Constructors, destructors and assignment\n# operators of the base classes will not be shown.\n# The default value is: NO.\n\nINLINE_INHERITED_MEMB  = NO\n\n# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path\n# before files name in the file list and in the header files. If set to NO the\n# shortest path that makes the file name unique will be used\n# The default value is: YES.\n\nFULL_PATH_NAMES        = YES\n\n# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.\n# Stripping is only done if one of the specified strings matches the left-hand\n# part of the path. The tag can be used to show relative paths in the file list.\n# If left blank the directory from which doxygen is run is used as the path to\n# strip.\n#\n# Note that you can specify absolute paths here, but also relative paths, which\n# will be relative from the directory where doxygen is started.\n# This tag requires that the tag FULL_PATH_NAMES is set to YES.\n\nSTRIP_FROM_PATH        =\n\n# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the\n# path mentioned in the documentation of a class, which tells the reader which\n# header file to include in order to use a class. If left blank only the name of\n# the header file containing the class definition is used. Otherwise one should\n# specify the list of include paths that are normally passed to the compiler\n# using the -I flag.\n\nSTRIP_FROM_INC_PATH    =\n\n# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but\n# less readable) file names. This can be useful is your file systems doesn't\n# support long names like on DOS, Mac, or CD-ROM.\n# The default value is: NO.\n\nSHORT_NAMES            = NO\n\n# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the\n# first line (until the first dot) of a Javadoc-style comment as the brief\n# description. If set to NO, the Javadoc-style will behave just like regular Qt-\n# style comments (thus requiring an explicit @brief command for a brief\n# description.)\n# The default value is: NO.\n\nJAVADOC_AUTOBRIEF      = NO\n\n# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first\n# line (until the first dot) of a Qt-style comment as the brief description. If\n# set to NO, the Qt-style will behave just like regular Qt-style comments (thus\n# requiring an explicit \\brief command for a brief description.)\n# The default value is: NO.\n\nQT_AUTOBRIEF           = NO\n\n# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a\n# multi-line C++ special comment block (i.e. a block of //! or /// comments) as\n# a brief description. This used to be the default behavior. The new default is\n# to treat a multi-line C++ comment block as a detailed description. Set this\n# tag to YES if you prefer the old behavior instead.\n#\n# Note that setting this tag to YES also means that rational rose comments are\n# not recognized any more.\n# The default value is: NO.\n\nMULTILINE_CPP_IS_BRIEF = NO\n\n# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the\n# documentation from any documented member that it re-implements.\n# The default value is: YES.\n\nINHERIT_DOCS           = YES\n\n# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a\n# new page for each member. If set to NO, the documentation of a member will be\n# part of the file/class/namespace that contains it.\n# The default value is: NO.\n\nSEPARATE_MEMBER_PAGES  = NO\n\n# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen\n# uses this value to replace tabs by spaces in code fragments.\n# Minimum value: 1, maximum value: 16, default value: 4.\n\nTAB_SIZE               = 8\n\n# This tag can be used to specify a number of aliases that act as commands in\n# the documentation. An alias has the form:\n# name=value\n# For example adding\n# \"sideeffect=@par Side Effects:\\n\"\n# will allow you to put the command \\sideeffect (or @sideeffect) in the\n# documentation, which will result in a user-defined paragraph with heading\n# \"Side Effects:\". You can put \\n's in the value part of an alias to insert\n# newlines.\n\nALIASES                =\n\n# This tag can be used to specify a number of word-keyword mappings (TCL only).\n# A mapping has the form \"name=value\". For example adding \"class=itcl::class\"\n# will allow you to use the command class in the itcl::class meaning.\n\nTCL_SUBST              =\n\n# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources\n# only. Doxygen will then generate output that is more tailored for C. For\n# instance, some of the names that are used will be different. The list of all\n# members will be omitted, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_FOR_C  = NO\n\n# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or\n# Python sources only. Doxygen will then generate output that is more tailored\n# for that language. For instance, namespaces will be presented as packages,\n# qualified scopes will look different, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_JAVA   = NO\n\n# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran\n# sources. Doxygen will then generate output that is tailored for Fortran.\n# The default value is: NO.\n\nOPTIMIZE_FOR_FORTRAN   = NO\n\n# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL\n# sources. Doxygen will then generate output that is tailored for VHDL.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_VHDL   = NO\n\n# Doxygen selects the parser to use depending on the extension of the files it\n# parses. With this tag you can assign which parser to use for a given\n# extension. Doxygen has a built-in mapping, but you can override or extend it\n# using this tag. The format is ext=language, where ext is a file extension, and\n# language is one of the parsers supported by doxygen: IDL, Java, Javascript,\n# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran:\n# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran:\n# Fortran. In the later case the parser tries to guess whether the code is fixed\n# or free formatted code, this is the default for Fortran type files), VHDL. For\n# instance to make doxygen treat .inc files as Fortran files (default is PHP),\n# and .f files as C (default is Fortran), use: inc=Fortran f=C.\n#\n# Note For files without extension you can use no_extension as a placeholder.\n#\n# Note that for custom extensions you also need to set FILE_PATTERNS otherwise\n# the files are not read by doxygen.\n\nEXTENSION_MAPPING      =\n\n# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments\n# according to the Markdown format, which allows for more readable\n# documentation. See http://daringfireball.net/projects/markdown/ for details.\n# The output of markdown processing is further processed by doxygen, so you can\n# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in\n# case of backward compatibilities issues.\n# The default value is: YES.\n\nMARKDOWN_SUPPORT       = YES\n\n# When enabled doxygen tries to link words that correspond to documented\n# classes, or namespaces to their corresponding documentation. Such a link can\n# be prevented in individual cases by by putting a % sign in front of the word\n# or globally by setting AUTOLINK_SUPPORT to NO.\n# The default value is: YES.\n\nAUTOLINK_SUPPORT       = YES\n\n# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want\n# to include (a tag file for) the STL sources as input, then you should set this\n# tag to YES in order to let doxygen match functions declarations and\n# definitions whose arguments contain STL classes (e.g. func(std::string);\n# versus func(std::string) {}). This also make the inheritance and collaboration\n# diagrams that involve STL classes more complete and accurate.\n# The default value is: NO.\n\nBUILTIN_STL_SUPPORT    = NO\n\n# If you use Microsoft's C++/CLI language, you should set this option to YES to\n# enable parsing support.\n# The default value is: NO.\n\nCPP_CLI_SUPPORT        = NO\n\n# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:\n# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen\n# will parse them like normal C++ but will assume all classes use public instead\n# of private inheritance when no explicit protection keyword is present.\n# The default value is: NO.\n\nSIP_SUPPORT            = NO\n\n# For Microsoft's IDL there are propget and propput attributes to indicate\n# getter and setter methods for a property. Setting this option to YES will make\n# doxygen to replace the get and set methods by a property in the documentation.\n# This will only work if the methods are indeed getting or setting a simple\n# type. If this is not the case, or you want to show the methods anyway, you\n# should set this option to NO.\n# The default value is: YES.\n\nIDL_PROPERTY_SUPPORT   = YES\n\n# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC\n# tag is set to YES, then doxygen will reuse the documentation of the first\n# member in the group (if any) for the other members of the group. By default\n# all members of a group must be documented explicitly.\n# The default value is: NO.\n\nDISTRIBUTE_GROUP_DOC   = NO\n\n# Set the SUBGROUPING tag to YES to allow class member groups of the same type\n# (for instance a group of public functions) to be put as a subgroup of that\n# type (e.g. under the Public Functions section). Set it to NO to prevent\n# subgrouping. Alternatively, this can be done per class using the\n# \\nosubgrouping command.\n# The default value is: YES.\n\nSUBGROUPING            = YES\n\n# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions\n# are shown inside the group in which they are included (e.g. using \\ingroup)\n# instead of on a separate page (for HTML and Man pages) or section (for LaTeX\n# and RTF).\n#\n# Note that this feature does not work in combination with\n# SEPARATE_MEMBER_PAGES.\n# The default value is: NO.\n\nINLINE_GROUPED_CLASSES = NO\n\n# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions\n# with only public data fields or simple typedef fields will be shown inline in\n# the documentation of the scope in which they are defined (i.e. file,\n# namespace, or group documentation), provided this scope is documented. If set\n# to NO, structs, classes, and unions are shown on a separate page (for HTML and\n# Man pages) or section (for LaTeX and RTF).\n# The default value is: NO.\n\nINLINE_SIMPLE_STRUCTS  = NO\n\n# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or\n# enum is documented as struct, union, or enum with the name of the typedef. So\n# typedef struct TypeS {} TypeT, will appear in the documentation as a struct\n# with name TypeT. When disabled the typedef will appear as a member of a file,\n# namespace, or class. And the struct will be named TypeS. This can typically be\n# useful for C code in case the coding convention dictates that all compound\n# types are typedef'ed and only the typedef is referenced, never the tag name.\n# The default value is: NO.\n\nTYPEDEF_HIDES_STRUCT   = NO\n\n# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This\n# cache is used to resolve symbols given their name and scope. Since this can be\n# an expensive process and often the same symbol appears multiple times in the\n# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small\n# doxygen will become slower. If the cache is too large, memory is wasted. The\n# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range\n# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536\n# symbols. At the end of a run doxygen will report the cache usage and suggest\n# the optimal cache size from a speed point of view.\n# Minimum value: 0, maximum value: 9, default value: 0.\n\nLOOKUP_CACHE_SIZE      = 0\n\n#---------------------------------------------------------------------------\n# Build related configuration options\n#---------------------------------------------------------------------------\n\n# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in\n# documentation are documented, even if no documentation was available. Private\n# class members and static file members will be hidden unless the\n# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.\n# Note: This will also disable the warnings about undocumented members that are\n# normally produced when WARNINGS is set to YES.\n# The default value is: NO.\n\nEXTRACT_ALL            = NO\n\n# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will\n# be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PRIVATE        = NO\n\n# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal\n# scope will be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PACKAGE        = NO\n\n# If the EXTRACT_STATIC tag is set to YES all static members of a file will be\n# included in the documentation.\n# The default value is: NO.\n\nEXTRACT_STATIC         = NO\n\n# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined\n# locally in source files will be included in the documentation. If set to NO\n# only classes defined in header files are included. Does not have any effect\n# for Java sources.\n# The default value is: YES.\n\nEXTRACT_LOCAL_CLASSES  = YES\n\n# This flag is only useful for Objective-C code. When set to YES local methods,\n# which are defined in the implementation section but not in the interface are\n# included in the documentation. If set to NO only methods in the interface are\n# included.\n# The default value is: NO.\n\nEXTRACT_LOCAL_METHODS  = NO\n\n# If this flag is set to YES, the members of anonymous namespaces will be\n# extracted and appear in the documentation as a namespace called\n# 'anonymous_namespace{file}', where file will be replaced with the base name of\n# the file that contains the anonymous namespace. By default anonymous namespace\n# are hidden.\n# The default value is: NO.\n\nEXTRACT_ANON_NSPACES   = NO\n\n# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all\n# undocumented members inside documented classes or files. If set to NO these\n# members will be included in the various overviews, but no documentation\n# section is generated. This option has no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_MEMBERS     = NO\n\n# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all\n# undocumented classes that are normally visible in the class hierarchy. If set\n# to NO these classes will be included in the various overviews. This option has\n# no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_CLASSES     = NO\n\n# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend\n# (class|struct|union) declarations. If set to NO these declarations will be\n# included in the documentation.\n# The default value is: NO.\n\nHIDE_FRIEND_COMPOUNDS  = NO\n\n# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any\n# documentation blocks found inside the body of a function. If set to NO these\n# blocks will be appended to the function's detailed documentation block.\n# The default value is: NO.\n\nHIDE_IN_BODY_DOCS      = NO\n\n# The INTERNAL_DOCS tag determines if documentation that is typed after a\n# \\internal command is included. If the tag is set to NO then the documentation\n# will be excluded. Set it to YES to include the internal documentation.\n# The default value is: NO.\n\nINTERNAL_DOCS          = NO\n\n# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file\n# names in lower-case letters. If set to YES upper-case letters are also\n# allowed. This is useful if you have classes or files whose names only differ\n# in case and if your file system supports case sensitive file names. Windows\n# and Mac users are advised to set this option to NO.\n# The default value is: system dependent.\n\nCASE_SENSE_NAMES       = YES\n\n# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with\n# their full class and namespace scopes in the documentation. If set to YES the\n# scope will be hidden.\n# The default value is: NO.\n\nHIDE_SCOPE_NAMES       = NO\n\n# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of\n# the files that are included by a file in the documentation of that file.\n# The default value is: YES.\n\nSHOW_INCLUDE_FILES     = YES\n\n# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each\n# grouped member an include statement to the documentation, telling the reader\n# which file to include in order to use the member.\n# The default value is: NO.\n\nSHOW_GROUPED_MEMB_INC  = NO\n\n# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include\n# files with double quotes in the documentation rather than with sharp brackets.\n# The default value is: NO.\n\nFORCE_LOCAL_INCLUDES   = NO\n\n# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the\n# documentation for inline members.\n# The default value is: YES.\n\nINLINE_INFO            = YES\n\n# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the\n# (detailed) documentation of file and class members alphabetically by member\n# name. If set to NO the members will appear in declaration order.\n# The default value is: YES.\n\nSORT_MEMBER_DOCS       = YES\n\n# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief\n# descriptions of file, namespace and class members alphabetically by member\n# name. If set to NO the members will appear in declaration order. Note that\n# this will also influence the order of the classes in the class list.\n# The default value is: NO.\n\nSORT_BRIEF_DOCS        = NO\n\n# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the\n# (brief and detailed) documentation of class members so that constructors and\n# destructors are listed first. If set to NO the constructors will appear in the\n# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.\n# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief\n# member documentation.\n# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting\n# detailed member documentation.\n# The default value is: NO.\n\nSORT_MEMBERS_CTORS_1ST = NO\n\n# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy\n# of group names into alphabetical order. If set to NO the group names will\n# appear in their defined order.\n# The default value is: NO.\n\nSORT_GROUP_NAMES       = NO\n\n# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by\n# fully-qualified names, including namespaces. If set to NO, the class list will\n# be sorted only by class name, not including the namespace part.\n# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.\n# Note: This option applies only to the class list, not to the alphabetical\n# list.\n# The default value is: NO.\n\nSORT_BY_SCOPE_NAME     = NO\n\n# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper\n# type resolution of all parameters of a function it will reject a match between\n# the prototype and the implementation of a member function even if there is\n# only one candidate or it is obvious which candidate to choose by doing a\n# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still\n# accept a match between prototype and implementation in such cases.\n# The default value is: NO.\n\nSTRICT_PROTO_MATCHING  = NO\n\n# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the\n# todo list. This list is created by putting \\todo commands in the\n# documentation.\n# The default value is: YES.\n\nGENERATE_TODOLIST      = YES\n\n# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the\n# test list. This list is created by putting \\test commands in the\n# documentation.\n# The default value is: YES.\n\nGENERATE_TESTLIST      = YES\n\n# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug\n# list. This list is created by putting \\bug commands in the documentation.\n# The default value is: YES.\n\nGENERATE_BUGLIST       = YES\n\n# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO)\n# the deprecated list. This list is created by putting \\deprecated commands in\n# the documentation.\n# The default value is: YES.\n\nGENERATE_DEPRECATEDLIST= YES\n\n# The ENABLED_SECTIONS tag can be used to enable conditional documentation\n# sections, marked by \\if <section_label> ... \\endif and \\cond <section_label>\n# ... \\endcond blocks.\n\nENABLED_SECTIONS       =\n\n# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the\n# initial value of a variable or macro / define can have for it to appear in the\n# documentation. If the initializer consists of more lines than specified here\n# it will be hidden. Use a value of 0 to hide initializers completely. The\n# appearance of the value of individual variables and macros / defines can be\n# controlled using \\showinitializer or \\hideinitializer command in the\n# documentation regardless of this setting.\n# Minimum value: 0, maximum value: 10000, default value: 30.\n\nMAX_INITIALIZER_LINES  = 30\n\n# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at\n# the bottom of the documentation of classes and structs. If set to YES the list\n# will mention the files that were used to generate the documentation.\n# The default value is: YES.\n\nSHOW_USED_FILES        = YES\n\n# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This\n# will remove the Files entry from the Quick Index and from the Folder Tree View\n# (if specified).\n# The default value is: YES.\n\nSHOW_FILES             = YES\n\n# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces\n# page. This will remove the Namespaces entry from the Quick Index and from the\n# Folder Tree View (if specified).\n# The default value is: YES.\n\nSHOW_NAMESPACES        = YES\n\n# The FILE_VERSION_FILTER tag can be used to specify a program or script that\n# doxygen should invoke to get the current version for each file (typically from\n# the version control system). Doxygen will invoke the program by executing (via\n# popen()) the command command input-file, where command is the value of the\n# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided\n# by doxygen. Whatever the program writes to standard output is used as the file\n# version. For an example see the documentation.\n\nFILE_VERSION_FILTER    =\n\n# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed\n# by doxygen. The layout file controls the global structure of the generated\n# output files in an output format independent way. To create the layout file\n# that represents doxygen's defaults, run doxygen with the -l option. You can\n# optionally specify a file name after the option, if omitted DoxygenLayout.xml\n# will be used as the name of the layout file.\n#\n# Note that if you run doxygen from a directory containing a file called\n# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE\n# tag is left empty.\n\nLAYOUT_FILE            =\n\n# The CITE_BIB_FILES tag can be used to specify one or more bib files containing\n# the reference definitions. This must be a list of .bib files. The .bib\n# extension is automatically appended if omitted. This requires the bibtex tool\n# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.\n# For LaTeX the style of the bibliography can be controlled using\n# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the\n# search path. See also \\cite for info how to create references.\n\nCITE_BIB_FILES         =\n\n#---------------------------------------------------------------------------\n# Configuration options related to warning and progress messages\n#---------------------------------------------------------------------------\n\n# The QUIET tag can be used to turn on/off the messages that are generated to\n# standard output by doxygen. If QUIET is set to YES this implies that the\n# messages are off.\n# The default value is: NO.\n\nQUIET                  = NO\n\n# The WARNINGS tag can be used to turn on/off the warning messages that are\n# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES\n# this implies that the warnings are on.\n#\n# Tip: Turn warnings on while writing the documentation.\n# The default value is: YES.\n\nWARNINGS               = YES\n\n# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate\n# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag\n# will automatically be disabled.\n# The default value is: YES.\n\nWARN_IF_UNDOCUMENTED   = YES\n\n# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for\n# potential errors in the documentation, such as not documenting some parameters\n# in a documented function, or documenting parameters that don't exist or using\n# markup commands wrongly.\n# The default value is: YES.\n\nWARN_IF_DOC_ERROR      = YES\n\n# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that\n# are documented, but have no documentation for their parameters or return\n# value. If set to NO doxygen will only warn about wrong or incomplete parameter\n# documentation, but not about the absence of documentation.\n# The default value is: NO.\n\nWARN_NO_PARAMDOC       = NO\n\n# The WARN_FORMAT tag determines the format of the warning messages that doxygen\n# can produce. The string should contain the $file, $line, and $text tags, which\n# will be replaced by the file and line number from which the warning originated\n# and the warning text. Optionally the format may contain $version, which will\n# be replaced by the version of the file (if it could be obtained via\n# FILE_VERSION_FILTER)\n# The default value is: $file:$line: $text.\n\nWARN_FORMAT            = \"$file:$line: $text\"\n\n# The WARN_LOGFILE tag can be used to specify a file to which warning and error\n# messages should be written. If left blank the output is written to standard\n# error (stderr).\n\nWARN_LOGFILE           =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the input files\n#---------------------------------------------------------------------------\n\n# The INPUT tag is used to specify the files and/or directories that contain\n# documented source files. You may enter file names like myfile.cpp or\n# directories like /usr/src/myproject. Separate the files or directories with\n# spaces.\n# Note: If this tag is empty the current directory is searched.\n\nINPUT                  =\n\n# This tag can be used to specify the character encoding of the source files\n# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses\n# libiconv (or the iconv built into libc) for the transcoding. See the libiconv\n# documentation (see: http://www.gnu.org/software/libiconv) for the list of\n# possible encodings.\n# The default value is: UTF-8.\n\nINPUT_ENCODING         = UTF-8\n\n# If the value of the INPUT tag contains directories, you can use the\n# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and\n# *.h) to filter out the source-files in the directories. If left blank the\n# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii,\n# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp,\n# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown,\n# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf,\n# *.qsf, *.as and *.js.\n\nFILE_PATTERNS          =\n\n# The RECURSIVE tag can be used to specify whether or not subdirectories should\n# be searched for input files as well.\n# The default value is: NO.\n\nRECURSIVE              = NO\n\n# The EXCLUDE tag can be used to specify files and/or directories that should be\n# excluded from the INPUT source files. This way you can easily exclude a\n# subdirectory from a directory tree whose root is specified with the INPUT tag.\n#\n# Note that relative paths are relative to the directory from which doxygen is\n# run.\n\nEXCLUDE                =\n\n# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or\n# directories that are symbolic links (a Unix file system feature) are excluded\n# from the input.\n# The default value is: NO.\n\nEXCLUDE_SYMLINKS       = NO\n\n# If the value of the INPUT tag contains directories, you can use the\n# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude\n# certain files from those directories.\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories for example use the pattern */test/*\n\nEXCLUDE_PATTERNS       =\n\n# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names\n# (namespaces, classes, functions, etc.) that should be excluded from the\n# output. The symbol name can be a fully qualified name, a word, or if the\n# wildcard * is used, a substring. Examples: ANamespace, AClass,\n# AClass::ANamespace, ANamespace::*Test\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories use the pattern */test/*\n\nEXCLUDE_SYMBOLS        =\n\n# The EXAMPLE_PATH tag can be used to specify one or more files or directories\n# that contain example code fragments that are included (see the \\include\n# command).\n\nEXAMPLE_PATH           = examples\n\n# If the value of the EXAMPLE_PATH tag contains directories, you can use the\n# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and\n# *.h) to filter out the source-files in the directories. If left blank all\n# files are included.\n\nEXAMPLE_PATTERNS       =\n\n# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be\n# searched for input files to be used with the \\include or \\dontinclude commands\n# irrespective of the value of the RECURSIVE tag.\n# The default value is: NO.\n\nEXAMPLE_RECURSIVE      = YES\n\n# The IMAGE_PATH tag can be used to specify one or more files or directories\n# that contain images that are to be included in the documentation (see the\n# \\image command).\n\nIMAGE_PATH             =\n\n# The INPUT_FILTER tag can be used to specify a program that doxygen should\n# invoke to filter for each input file. Doxygen will invoke the filter program\n# by executing (via popen()) the command:\n#\n# <filter> <input-file>\n#\n# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the\n# name of an input file. Doxygen will then use the output that the filter\n# program writes to standard output. If FILTER_PATTERNS is specified, this tag\n# will be ignored.\n#\n# Note that the filter must not add or remove lines; it is applied before the\n# code is scanned, but not when the output code is generated. If lines are added\n# or removed, the anchors will not be placed correctly.\n\nINPUT_FILTER           =\n\n# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern\n# basis. Doxygen will compare the file name with each pattern and apply the\n# filter if there is a match. The filters are a list of the form: pattern=filter\n# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how\n# filters are used. If the FILTER_PATTERNS tag is empty or if none of the\n# patterns match the file name, INPUT_FILTER is applied.\n\nFILTER_PATTERNS        =\n\n# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using\n# INPUT_FILTER ) will also be used to filter the input files that are used for\n# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).\n# The default value is: NO.\n\nFILTER_SOURCE_FILES    = NO\n\n# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file\n# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and\n# it is also possible to disable source filtering for a specific pattern using\n# *.ext= (so without naming a filter).\n# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.\n\nFILTER_SOURCE_PATTERNS =\n\n# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that\n# is part of the input, its contents will be placed on the main page\n# (index.html). This can be useful if you have a project on for instance GitHub\n# and want to reuse the introduction page also for the doxygen output.\n\nUSE_MDFILE_AS_MAINPAGE =\n\n#---------------------------------------------------------------------------\n# Configuration options related to source browsing\n#---------------------------------------------------------------------------\n\n# If the SOURCE_BROWSER tag is set to YES then a list of source files will be\n# generated. Documented entities will be cross-referenced with these sources.\n#\n# Note: To get rid of all source code in the generated output, make sure that\n# also VERBATIM_HEADERS is set to NO.\n# The default value is: NO.\n\nSOURCE_BROWSER         = NO\n\n# Setting the INLINE_SOURCES tag to YES will include the body of functions,\n# classes and enums directly into the documentation.\n# The default value is: NO.\n\nINLINE_SOURCES         = NO\n\n# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any\n# special comment blocks from generated source code fragments. Normal C, C++ and\n# Fortran comments will always remain visible.\n# The default value is: YES.\n\nSTRIP_CODE_COMMENTS    = NO\n\n# If the REFERENCED_BY_RELATION tag is set to YES then for each documented\n# function all documented functions referencing it will be listed.\n# The default value is: NO.\n\nREFERENCED_BY_RELATION = YES\n\n# If the REFERENCES_RELATION tag is set to YES then for each documented function\n# all documented entities called/used by that function will be listed.\n# The default value is: NO.\n\nREFERENCES_RELATION    = YES\n\n# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set\n# to YES, then the hyperlinks from functions in REFERENCES_RELATION and\n# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will\n# link to the documentation.\n# The default value is: YES.\n\nREFERENCES_LINK_SOURCE = YES\n\n# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the\n# source code will show a tooltip with additional information such as prototype,\n# brief description and links to the definition and documentation. Since this\n# will make the HTML file larger and loading of large files a bit slower, you\n# can opt to disable this feature.\n# The default value is: YES.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nSOURCE_TOOLTIPS        = YES\n\n# If the USE_HTAGS tag is set to YES then the references to source code will\n# point to the HTML generated by the htags(1) tool instead of doxygen built-in\n# source browser. The htags tool is part of GNU's global source tagging system\n# (see http://www.gnu.org/software/global/global.html). You will need version\n# 4.8.6 or higher.\n#\n# To use it do the following:\n# - Install the latest version of global\n# - Enable SOURCE_BROWSER and USE_HTAGS in the config file\n# - Make sure the INPUT points to the root of the source tree\n# - Run doxygen as normal\n#\n# Doxygen will invoke htags (and that will in turn invoke gtags), so these\n# tools must be available from the command line (i.e. in the search path).\n#\n# The result: instead of the source browser generated by doxygen, the links to\n# source code will now point to the output of htags.\n# The default value is: NO.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nUSE_HTAGS              = NO\n\n# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a\n# verbatim copy of the header file for each class for which an include is\n# specified. Set to NO to disable this.\n# See also: Section \\class.\n# The default value is: YES.\n\nVERBATIM_HEADERS       = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to the alphabetical class index\n#---------------------------------------------------------------------------\n\n# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all\n# compounds will be generated. Enable this if the project contains a lot of\n# classes, structs, unions or interfaces.\n# The default value is: YES.\n\nALPHABETICAL_INDEX     = NO\n\n# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in\n# which the alphabetical index list will be split.\n# Minimum value: 1, maximum value: 20, default value: 5.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nCOLS_IN_ALPHA_INDEX    = 5\n\n# In case all classes in a project start with a common prefix, all classes will\n# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag\n# can be used to specify a prefix (or a list of prefixes) that should be ignored\n# while generating the index headers.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nIGNORE_PREFIX          =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the HTML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output\n# The default value is: YES.\n\nGENERATE_HTML          = YES\n\n# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_OUTPUT            = doc\n\n# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each\n# generated HTML page (for example: .htm, .php, .asp).\n# The default value is: .html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FILE_EXTENSION    = .html\n\n# The HTML_HEADER tag can be used to specify a user-defined HTML header file for\n# each generated HTML page. If the tag is left blank doxygen will generate a\n# standard header.\n#\n# To get valid HTML the header file that includes any scripts and style sheets\n# that doxygen needs, which is dependent on the configuration options used (e.g.\n# the setting GENERATE_TREEVIEW). It is highly recommended to start with a\n# default header using\n# doxygen -w html new_header.html new_footer.html new_stylesheet.css\n# YourConfigFile\n# and then modify the file new_header.html. See also section \"Doxygen usage\"\n# for information on how to generate the default header that doxygen normally\n# uses.\n# Note: The header is subject to change so you typically have to regenerate the\n# default header when upgrading to a newer version of doxygen. For a description\n# of the possible markers and block names see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_HEADER            =\n\n# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each\n# generated HTML page. If the tag is left blank doxygen will generate a standard\n# footer. See HTML_HEADER for more information on how to generate a default\n# footer and what special commands can be used inside the footer. See also\n# section \"Doxygen usage\" for information on how to generate the default footer\n# that doxygen normally uses.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FOOTER            =\n\n# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style\n# sheet that is used by each HTML page. It can be used to fine-tune the look of\n# the HTML output. If left blank doxygen will generate a default style sheet.\n# See also section \"Doxygen usage\" for information on how to generate the style\n# sheet that doxygen normally uses.\n# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as\n# it is more robust and this tag (HTML_STYLESHEET) will in the future become\n# obsolete.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_STYLESHEET        =\n\n# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined\n# cascading style sheets that are included after the standard style sheets\n# created by doxygen. Using this option one can overrule certain style aspects.\n# This is preferred over using HTML_STYLESHEET since it does not replace the\n# standard style sheet and is therefor more robust against future updates.\n# Doxygen will copy the style sheet files to the output directory.\n# Note: The order of the extra stylesheet files is of importance (e.g. the last\n# stylesheet in the list overrules the setting of the previous ones in the\n# list). For an example see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_STYLESHEET  =\n\n# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the HTML output directory. Note\n# that these files will be copied to the base HTML output directory. Use the\n# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these\n# files. In the HTML_STYLESHEET file, use the file name only. Also note that the\n# files will be copied as-is; there are no commands or markers available.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_FILES       =\n\n# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen\n# will adjust the colors in the stylesheet and background images according to\n# this color. Hue is specified as an angle on a colorwheel, see\n# http://en.wikipedia.org/wiki/Hue for more information. For instance the value\n# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300\n# purple, and 360 is red again.\n# Minimum value: 0, maximum value: 359, default value: 220.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_HUE    = 220\n\n# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors\n# in the HTML output. For a value of 0 the output will use grayscales only. A\n# value of 255 will produce the most vivid colors.\n# Minimum value: 0, maximum value: 255, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_SAT    = 100\n\n# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the\n# luminance component of the colors in the HTML output. Values below 100\n# gradually make the output lighter, whereas values above 100 make the output\n# darker. The value divided by 100 is the actual gamma applied, so 80 represents\n# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not\n# change the gamma.\n# Minimum value: 40, maximum value: 240, default value: 80.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_GAMMA  = 80\n\n# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML\n# page will contain the date and time when the page was generated. Setting this\n# to NO can help when comparing the output of multiple runs.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_TIMESTAMP         = NO\n\n# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML\n# documentation will contain sections that can be hidden and shown after the\n# page has loaded.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_DYNAMIC_SECTIONS  = NO\n\n# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries\n# shown in the various tree structured indices initially; the user can expand\n# and collapse entries dynamically later on. Doxygen will expand the tree to\n# such a level that at most the specified number of entries are visible (unless\n# a fully collapsed tree already exceeds this amount). So setting the number of\n# entries 1 will produce a full collapsed tree by default. 0 is a special value\n# representing an infinite number of entries and will result in a full expanded\n# tree by default.\n# Minimum value: 0, maximum value: 9999, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_INDEX_NUM_ENTRIES = 100\n\n# If the GENERATE_DOCSET tag is set to YES, additional index files will be\n# generated that can be used as input for Apple's Xcode 3 integrated development\n# environment (see: http://developer.apple.com/tools/xcode/), introduced with\n# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a\n# Makefile in the HTML output directory. Running make will produce the docset in\n# that directory and running make install will install the docset in\n# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at\n# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html\n# for more information.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_DOCSET        = NO\n\n# This tag determines the name of the docset feed. A documentation feed provides\n# an umbrella under which multiple documentation sets from a single provider\n# (such as a company or product suite) can be grouped.\n# The default value is: Doxygen generated docs.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_FEEDNAME        = \"Doxygen generated docs\"\n\n# This tag specifies a string that should uniquely identify the documentation\n# set bundle. This should be a reverse domain-name style string, e.g.\n# com.mycompany.MyDocSet. Doxygen will append .docset to the name.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_BUNDLE_ID       = org.doxygen.Project\n\n# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify\n# the documentation publisher. This should be a reverse domain-name style\n# string, e.g. com.mycompany.MyDocSet.documentation.\n# The default value is: org.doxygen.Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_ID    = org.doxygen.Publisher\n\n# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.\n# The default value is: Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_NAME  = Publisher\n\n# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three\n# additional HTML index files: index.hhp, index.hhc, and index.hhk. The\n# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop\n# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on\n# Windows.\n#\n# The HTML Help Workshop contains a compiler that can convert all HTML output\n# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML\n# files are now used as the Windows 98 help format, and will replace the old\n# Windows help format (.hlp) on all Windows platforms in the future. Compressed\n# HTML files also contain an index, a table of contents, and you can search for\n# words in the documentation. The HTML workshop also contains a viewer for\n# compressed HTML files.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_HTMLHELP      = NO\n\n# The CHM_FILE tag can be used to specify the file name of the resulting .chm\n# file. You can add a path in front of the file if the result should not be\n# written to the html output directory.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_FILE               =\n\n# The HHC_LOCATION tag can be used to specify the location (absolute path\n# including file name) of the HTML help compiler ( hhc.exe). If non-empty\n# doxygen will try to run the HTML help compiler on the generated index.hhp.\n# The file has to be specified with full path.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nHHC_LOCATION           =\n\n# The GENERATE_CHI flag controls if a separate .chi index file is generated (\n# YES) or that it should be included in the master .chm file ( NO).\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nGENERATE_CHI           = NO\n\n# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc)\n# and project file content.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_INDEX_ENCODING     =\n\n# The BINARY_TOC flag controls whether a binary table of contents is generated (\n# YES) or a normal table of contents ( NO) in the .chm file. Furthermore it\n# enables the Previous and Next buttons.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nBINARY_TOC             = NO\n\n# The TOC_EXPAND flag can be set to YES to add extra items for group members to\n# the table of contents of the HTML help documentation and to the tree view.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nTOC_EXPAND             = NO\n\n# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and\n# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that\n# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help\n# (.qch) of the generated HTML documentation.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_QHP           = NO\n\n# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify\n# the file name of the resulting .qch file. The path specified is relative to\n# the HTML output folder.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQCH_FILE               =\n\n# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help\n# Project output. For more information please see Qt Help Project / Namespace\n# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace).\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_NAMESPACE          = org.doxygen.Project\n\n# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt\n# Help Project output. For more information please see Qt Help Project / Virtual\n# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual-\n# folders).\n# The default value is: doc.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_VIRTUAL_FOLDER     = doc\n\n# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom\n# filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_NAME   =\n\n# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the\n# custom filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_ATTRS  =\n\n# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this\n# project's filter section matches. Qt Help Project / Filter Attributes (see:\n# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_SECT_FILTER_ATTRS  =\n\n# The QHG_LOCATION tag can be used to specify the location of Qt's\n# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the\n# generated .qhp file.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHG_LOCATION           =\n\n# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be\n# generated, together with the HTML files, they form an Eclipse help plugin. To\n# install this plugin and make it available under the help contents menu in\n# Eclipse, the contents of the directory containing the HTML and XML files needs\n# to be copied into the plugins directory of eclipse. The name of the directory\n# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.\n# After copying Eclipse needs to be restarted before the help appears.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_ECLIPSEHELP   = NO\n\n# A unique identifier for the Eclipse help plugin. When installing the plugin\n# the directory name containing the HTML and XML files should also have this\n# name. Each documentation set should have its own identifier.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.\n\nECLIPSE_DOC_ID         = org.doxygen.Project\n\n# If you want full control over the layout of the generated HTML pages it might\n# be necessary to disable the index and replace it with your own. The\n# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top\n# of each HTML page. A value of NO enables the index and the value YES disables\n# it. Since the tabs in the index contain the same information as the navigation\n# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nDISABLE_INDEX          = NO\n\n# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index\n# structure should be generated to display hierarchical information. If the tag\n# value is set to YES, a side panel will be generated containing a tree-like\n# index structure (just like the one that is generated for HTML Help). For this\n# to work a browser that supports JavaScript, DHTML, CSS and frames is required\n# (i.e. any modern browser). Windows users are probably better off using the\n# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can\n# further fine-tune the look of the index. As an example, the default style\n# sheet generated by doxygen has an example that shows how to put an image at\n# the root of the tree instead of the PROJECT_NAME. Since the tree basically has\n# the same information as the tab index, you could consider setting\n# DISABLE_INDEX to YES when enabling this option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_TREEVIEW      = NO\n\n# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that\n# doxygen will group on one line in the generated HTML documentation.\n#\n# Note that a value of 0 will completely suppress the enum values from appearing\n# in the overview section.\n# Minimum value: 0, maximum value: 20, default value: 4.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nENUM_VALUES_PER_LINE   = 4\n\n# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used\n# to set the initial width (in pixels) of the frame in which the tree is shown.\n# Minimum value: 0, maximum value: 1500, default value: 250.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nTREEVIEW_WIDTH         = 250\n\n# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to\n# external symbols imported via tag files in a separate window.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nEXT_LINKS_IN_WINDOW    = NO\n\n# Use this tag to change the font size of LaTeX formulas included as images in\n# the HTML documentation. When you change the font size after a successful\n# doxygen run you need to manually remove any form_*.png images from the HTML\n# output directory to force them to be regenerated.\n# Minimum value: 8, maximum value: 50, default value: 10.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_FONTSIZE       = 10\n\n# Use the FORMULA_TRANPARENT tag to determine whether or not the images\n# generated for formulas are transparent PNGs. Transparent PNGs are not\n# supported properly for IE 6.0, but are supported on all modern browsers.\n#\n# Note that when changing this option you need to delete any form_*.png files in\n# the HTML output directory before the changes have effect.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_TRANSPARENT    = YES\n\n# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see\n# http://www.mathjax.org) which uses client side Javascript for the rendering\n# instead of using prerendered bitmaps. Use this if you do not have LaTeX\n# installed or if you want to formulas look prettier in the HTML output. When\n# enabled you may also need to install MathJax separately and configure the path\n# to it using the MATHJAX_RELPATH option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nUSE_MATHJAX            = NO\n\n# When MathJax is enabled you can set the default output format to be used for\n# the MathJax output. See the MathJax site (see:\n# http://docs.mathjax.org/en/latest/output.html) for more details.\n# Possible values are: HTML-CSS (which is slower, but has the best\n# compatibility), NativeMML (i.e. MathML) and SVG.\n# The default value is: HTML-CSS.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_FORMAT         = HTML-CSS\n\n# When MathJax is enabled you need to specify the location relative to the HTML\n# output directory using the MATHJAX_RELPATH option. The destination directory\n# should contain the MathJax.js script. For instance, if the mathjax directory\n# is located at the same level as the HTML output directory, then\n# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax\n# Content Delivery Network so you can quickly see the result without installing\n# MathJax. However, it is strongly recommended to install a local copy of\n# MathJax from http://www.mathjax.org before deployment.\n# The default value is: http://cdn.mathjax.org/mathjax/latest.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_RELPATH        = http://cdn.mathjax.org/mathjax/latest\n\n# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax\n# extension names that should be enabled during MathJax rendering. For example\n# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_EXTENSIONS     =\n\n# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces\n# of code that will be used on startup of the MathJax code. See the MathJax site\n# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an\n# example see the documentation.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_CODEFILE       =\n\n# When the SEARCHENGINE tag is enabled doxygen will generate a search box for\n# the HTML output. The underlying search engine uses javascript and DHTML and\n# should work on any modern browser. Note that when using HTML help\n# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)\n# there is already a search function so this one should typically be disabled.\n# For large projects the javascript based search engine can be slow, then\n# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to\n# search using the keyboard; to jump to the search box use <access key> + S\n# (what the <access key> is depends on the OS and browser, but it is typically\n# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down\n# key> to jump into the search results window, the results can be navigated\n# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel\n# the search. The filter options can be selected when the cursor is inside the\n# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>\n# to select a filter and <Enter> or <escape> to activate or cancel the filter\n# option.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nSEARCHENGINE           = NO\n\n# When the SERVER_BASED_SEARCH tag is enabled the search engine will be\n# implemented using a web server instead of a web client using Javascript. There\n# are two flavors of web server based searching depending on the EXTERNAL_SEARCH\n# setting. When disabled, doxygen will generate a PHP script for searching and\n# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing\n# and searching needs to be provided by external tools. See the section\n# \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSERVER_BASED_SEARCH    = NO\n\n# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP\n# script for searching. Instead the search results are written to an XML file\n# which needs to be processed by an external indexer. Doxygen will invoke an\n# external search engine pointed to by the SEARCHENGINE_URL option to obtain the\n# search results.\n#\n# Doxygen ships with an example indexer ( doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: http://xapian.org/).\n#\n# See the section \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH        = NO\n\n# The SEARCHENGINE_URL should point to a search engine hosted by a web server\n# which will return the search results when EXTERNAL_SEARCH is enabled.\n#\n# Doxygen ships with an example indexer ( doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: http://xapian.org/). See the section \"External Indexing and\n# Searching\" for details.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHENGINE_URL       =\n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed\n# search data is written to a file for indexing by an external tool. With the\n# SEARCHDATA_FILE tag the name of this file can be specified.\n# The default file is: searchdata.xml.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHDATA_FILE        = searchdata.xml\n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the\n# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is\n# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple\n# projects and redirect the results back to the right project.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH_ID     =\n\n# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen\n# projects other than the one defined by this configuration file, but that are\n# all added to the same external search index. Each project needs to have a\n# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of\n# to a relative location where the documentation can be found. The format is:\n# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTRA_SEARCH_MAPPINGS  =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the LaTeX output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_LATEX tag is set to YES doxygen will generate LaTeX output.\n# The default value is: YES.\n\nGENERATE_LATEX         = NO\n\n# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: latex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_OUTPUT           = latex\n\n# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be\n# invoked.\n#\n# Note that when enabling USE_PDFLATEX this option is only used for generating\n# bitmaps for formulas in the HTML output, but not in the Makefile that is\n# written to the output directory.\n# The default file is: latex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_CMD_NAME         = latex\n\n# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate\n# index for LaTeX.\n# The default file is: makeindex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nMAKEINDEX_CMD_NAME     = makeindex\n\n# If the COMPACT_LATEX tag is set to YES doxygen generates more compact LaTeX\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nCOMPACT_LATEX          = NO\n\n# The PAPER_TYPE tag can be used to set the paper type that is used by the\n# printer.\n# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x\n# 14 inches) and executive (7.25 x 10.5 inches).\n# The default value is: a4.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPAPER_TYPE             = a4wide\n\n# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names\n# that should be included in the LaTeX output. To get the times font for\n# instance you can specify\n# EXTRA_PACKAGES=times\n# If left blank no extra packages will be included.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nEXTRA_PACKAGES         =\n\n# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the\n# generated LaTeX document. The header should contain everything until the first\n# chapter. If it is left blank doxygen will generate a standard header. See\n# section \"Doxygen usage\" for information on how to let doxygen write the\n# default header to a separate file.\n#\n# Note: Only use a user-defined header if you know what you are doing! The\n# following commands have a special meaning inside the header: $title,\n# $datetime, $date, $doxygenversion, $projectname, $projectnumber,\n# $projectbrief, $projectlogo. Doxygen will replace $title with the empy string,\n# for the replacement values of the other commands the user is refered to\n# HTML_HEADER.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HEADER           =\n\n# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the\n# generated LaTeX document. The footer should contain everything after the last\n# chapter. If it is left blank doxygen will generate a standard footer. See\n# LATEX_HEADER for more information on how to generate a default footer and what\n# special commands can be used inside the footer.\n#\n# Note: Only use a user-defined footer if you know what you are doing!\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_FOOTER           =\n\n# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the LATEX_OUTPUT output\n# directory. Note that the files will be copied as-is; there are no commands or\n# markers available.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EXTRA_FILES      =\n\n# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is\n# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will\n# contain links (just like the HTML output) instead of page references. This\n# makes the output suitable for online browsing using a PDF viewer.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPDF_HYPERLINKS         = NO\n\n# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate\n# the PDF file directly from the LaTeX files. Set this option to YES to get a\n# higher quality PDF documentation.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nUSE_PDFLATEX           = NO\n\n# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode\n# command to the generated LaTeX files. This will instruct LaTeX to keep running\n# if errors occur, instead of asking the user for help. This option is also used\n# when generating formulas in HTML.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BATCHMODE        = NO\n\n# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the\n# index chapters (such as File Index, Compound Index, etc.) in the output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HIDE_INDICES     = NO\n\n# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source\n# code with syntax highlighting in the LaTeX output.\n#\n# Note that which sources are shown also depends on other settings such as\n# SOURCE_BROWSER.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_SOURCE_CODE      = NO\n\n# The LATEX_BIB_STYLE tag can be used to specify the style to use for the\n# bibliography, e.g. plainnat, or ieeetr. See\n# http://en.wikipedia.org/wiki/BibTeX and \\cite for more info.\n# The default value is: plain.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BIB_STYLE        = plain\n\n#---------------------------------------------------------------------------\n# Configuration options related to the RTF output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_RTF tag is set to YES doxygen will generate RTF output. The\n# RTF output is optimized for Word 97 and may not look too pretty with other RTF\n# readers/editors.\n# The default value is: NO.\n\nGENERATE_RTF           = NO\n\n# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: rtf.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_OUTPUT             = rtf\n\n# If the COMPACT_RTF tag is set to YES doxygen generates more compact RTF\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nCOMPACT_RTF            = NO\n\n# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will\n# contain hyperlink fields. The RTF file will contain links (just like the HTML\n# output) instead of page references. This makes the output suitable for online\n# browsing using Word or some other Word compatible readers that support those\n# fields.\n#\n# Note: WordPad (write) and others do not support links.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_HYPERLINKS         = NO\n\n# Load stylesheet definitions from file. Syntax is similar to doxygen's config\n# file, i.e. a series of assignments. You only have to provide replacements,\n# missing definitions are set to their default value.\n#\n# See also section \"Doxygen usage\" for information on how to generate the\n# default style sheet that doxygen normally uses.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_STYLESHEET_FILE    =\n\n# Set optional variables used in the generation of an RTF document. Syntax is\n# similar to doxygen's config file. A template extensions file can be generated\n# using doxygen -e rtf extensionFile.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_EXTENSIONS_FILE    =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the man page output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_MAN tag is set to YES doxygen will generate man pages for\n# classes and files.\n# The default value is: NO.\n\nGENERATE_MAN           = NO\n\n# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it. A directory man3 will be created inside the directory specified by\n# MAN_OUTPUT.\n# The default directory is: man.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_OUTPUT             = man\n\n# The MAN_EXTENSION tag determines the extension that is added to the generated\n# man pages. In case the manual section does not start with a number, the number\n# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is\n# optional.\n# The default value is: .3.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_EXTENSION          = .3\n\n# The MAN_SUBDIR tag determines the name of the directory created within\n# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by\n# MAN_EXTENSION with the initial . removed.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_SUBDIR             =\n\n# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it\n# will generate one additional man file for each entity documented in the real\n# man page(s). These additional files only source the real man page, but without\n# them the man command would be unable to find the correct page.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_LINKS              = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the XML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_XML tag is set to YES doxygen will generate an XML file that\n# captures the structure of the code including all documentation.\n# The default value is: NO.\n\nGENERATE_XML           = NO\n\n# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: xml.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_OUTPUT             = xml\n\n# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program\n# listings (including syntax highlighting and cross-referencing information) to\n# the XML output. Note that enabling this will significantly increase the size\n# of the XML output.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_PROGRAMLISTING     = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to the DOCBOOK output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_DOCBOOK tag is set to YES doxygen will generate Docbook files\n# that can be used to generate PDF.\n# The default value is: NO.\n\nGENERATE_DOCBOOK       = NO\n\n# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.\n# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in\n# front of it.\n# The default directory is: docbook.\n# This tag requires that the tag GENERATE_DOCBOOK is set to YES.\n\nDOCBOOK_OUTPUT         = docbook\n\n# If the DOCBOOK_PROGRAMLISTING tag is set to YES doxygen will include the\n# program listings (including syntax highlighting and cross-referencing\n# information) to the DOCBOOK output. Note that enabling this will significantly\n# increase the size of the DOCBOOK output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_DOCBOOK is set to YES.\n\nDOCBOOK_PROGRAMLISTING = NO\n\n#---------------------------------------------------------------------------\n# Configuration options for the AutoGen Definitions output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_AUTOGEN_DEF tag is set to YES doxygen will generate an AutoGen\n# Definitions (see http://autogen.sf.net) file that captures the structure of\n# the code including all documentation. Note that this feature is still\n# experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_AUTOGEN_DEF   = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the Perl module output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_PERLMOD tag is set to YES doxygen will generate a Perl module\n# file that captures the structure of the code including all documentation.\n#\n# Note that this feature is still experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_PERLMOD       = NO\n\n# If the PERLMOD_LATEX tag is set to YES doxygen will generate the necessary\n# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI\n# output from the Perl module output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_LATEX          = NO\n\n# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be nicely\n# formatted so it can be parsed by a human reader. This is useful if you want to\n# understand what is going on. On the other hand, if this tag is set to NO the\n# size of the Perl module output will be much smaller and Perl will parse it\n# just the same.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_PRETTY         = YES\n\n# The names of the make variables in the generated doxyrules.make file are\n# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful\n# so different doxyrules.make files included by the same Makefile don't\n# overwrite each other's variables.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_MAKEVAR_PREFIX =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the preprocessor\n#---------------------------------------------------------------------------\n\n# If the ENABLE_PREPROCESSING tag is set to YES doxygen will evaluate all\n# C-preprocessor directives found in the sources and include files.\n# The default value is: YES.\n\nENABLE_PREPROCESSING   = YES\n\n# If the MACRO_EXPANSION tag is set to YES doxygen will expand all macro names\n# in the source code. If set to NO only conditional compilation will be\n# performed. Macro expansion can be done in a controlled way by setting\n# EXPAND_ONLY_PREDEF to YES.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nMACRO_EXPANSION        = NO\n\n# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then\n# the macro expansion is limited to the macros specified with the PREDEFINED and\n# EXPAND_AS_DEFINED tags.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_ONLY_PREDEF     = NO\n\n# If the SEARCH_INCLUDES tag is set to YES the includes files in the\n# INCLUDE_PATH will be searched if a #include is found.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSEARCH_INCLUDES        = YES\n\n# The INCLUDE_PATH tag can be used to specify one or more directories that\n# contain include files that are not input files but should be processed by the\n# preprocessor.\n# This tag requires that the tag SEARCH_INCLUDES is set to YES.\n\nINCLUDE_PATH           =\n\n# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard\n# patterns (like *.h and *.hpp) to filter out the header-files in the\n# directories. If left blank, the patterns specified with FILE_PATTERNS will be\n# used.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nINCLUDE_FILE_PATTERNS  =\n\n# The PREDEFINED tag can be used to specify one or more macro names that are\n# defined before the preprocessor is started (similar to the -D option of e.g.\n# gcc). The argument of the tag is a list of macros of the form: name or\n# name=definition (no spaces). If the definition and the \"=\" are omitted, \"=1\"\n# is assumed. To prevent a macro definition from being undefined via #undef or\n# recursively expanded use the := operator instead of the = operator.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nPREDEFINED             =\n\n# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this\n# tag can be used to specify a list of macro names that should be expanded. The\n# macro definition that is found in the sources will be used. Use the PREDEFINED\n# tag if you want to use a different macro definition that overrules the\n# definition found in the source code.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_AS_DEFINED      =\n\n# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will\n# remove all references to function-like macros that are alone on a line, have\n# an all uppercase name, and do not end with a semicolon. Such function macros\n# are typically used for boiler-plate code, and will confuse the parser if not\n# removed.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSKIP_FUNCTION_MACROS   = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to external references\n#---------------------------------------------------------------------------\n\n# The TAGFILES tag can be used to specify one or more tag files. For each tag\n# file the location of the external documentation should be added. The format of\n# a tag file without this location is as follows:\n# TAGFILES = file1 file2 ...\n# Adding location for the tag files is done as follows:\n# TAGFILES = file1=loc1 \"file2 = loc2\" ...\n# where loc1 and loc2 can be relative or absolute paths or URLs. See the\n# section \"Linking to external documentation\" for more information about the use\n# of tag files.\n# Note: Each tag file must have a unique name (where the name does NOT include\n# the path). If a tag file is not located in the directory in which doxygen is\n# run, you must also specify the path to the tagfile here.\n\nTAGFILES               =\n\n# When a file name is specified after GENERATE_TAGFILE, doxygen will create a\n# tag file that is based on the input files it reads. See section \"Linking to\n# external documentation\" for more information about the usage of tag files.\n\nGENERATE_TAGFILE       =\n\n# If the ALLEXTERNALS tag is set to YES all external class will be listed in the\n# class index. If set to NO only the inherited external classes will be listed.\n# The default value is: NO.\n\nALLEXTERNALS           = NO\n\n# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed in\n# the modules index. If set to NO, only the current project's groups will be\n# listed.\n# The default value is: YES.\n\nEXTERNAL_GROUPS        = YES\n\n# If the EXTERNAL_PAGES tag is set to YES all external pages will be listed in\n# the related pages index. If set to NO, only the current project's pages will\n# be listed.\n# The default value is: YES.\n\nEXTERNAL_PAGES         = YES\n\n# The PERL_PATH should be the absolute path and name of the perl script\n# interpreter (i.e. the result of 'which perl').\n# The default file (with absolute path) is: /usr/bin/perl.\n\nPERL_PATH              = /usr/bin/perl\n\n#---------------------------------------------------------------------------\n# Configuration options related to the dot tool\n#---------------------------------------------------------------------------\n\n# If the CLASS_DIAGRAMS tag is set to YES doxygen will generate a class diagram\n# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to\n# NO turns the diagrams off. Note that this option also works with HAVE_DOT\n# disabled, but it is recommended to install and use dot, since it yields more\n# powerful graphs.\n# The default value is: YES.\n\nCLASS_DIAGRAMS         = YES\n\n# You can define message sequence charts within doxygen comments using the \\msc\n# command. Doxygen will then run the mscgen tool (see:\n# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the\n# documentation. The MSCGEN_PATH tag allows you to specify the directory where\n# the mscgen tool resides. If left empty the tool is assumed to be found in the\n# default search path.\n\nMSCGEN_PATH            =\n\n# You can include diagrams made with dia in doxygen documentation. Doxygen will\n# then run dia to produce the diagram and insert it in the documentation. The\n# DIA_PATH tag allows you to specify the directory where the dia binary resides.\n# If left empty dia is assumed to be found in the default search path.\n\nDIA_PATH               =\n\n# If set to YES, the inheritance and collaboration graphs will hide inheritance\n# and usage relations if the target is undocumented or is not a class.\n# The default value is: YES.\n\nHIDE_UNDOC_RELATIONS   = YES\n\n# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is\n# available from the path. This tool is part of Graphviz (see:\n# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent\n# Bell Labs. The other options in this section have no effect if this option is\n# set to NO\n# The default value is: NO.\n\nHAVE_DOT               = NO\n\n# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed\n# to run in parallel. When set to 0 doxygen will base this on the number of\n# processors available in the system. You can set it explicitly to a value\n# larger than 0 to get control over the balance between CPU load and processing\n# speed.\n# Minimum value: 0, maximum value: 32, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_NUM_THREADS        = 0\n\n# When you want a differently looking font in the dot files that doxygen\n# generates you can specify the font name using DOT_FONTNAME. You need to make\n# sure dot is able to find the font, which can be done by putting it in a\n# standard location or by setting the DOTFONTPATH environment variable or by\n# setting DOT_FONTPATH to the directory containing the font.\n# The default value is: Helvetica.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTNAME           = Helvetica\n\n# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of\n# dot graphs.\n# Minimum value: 4, maximum value: 24, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTSIZE           = 10\n\n# By default doxygen will tell dot to use the default font as specified with\n# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set\n# the path where dot can find it using this tag.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTPATH           =\n\n# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for\n# each documented class showing the direct and indirect inheritance relations.\n# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCLASS_GRAPH            = YES\n\n# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a\n# graph for each documented class showing the direct and indirect implementation\n# dependencies (inheritance, containment, and class references variables) of the\n# class with other documented classes.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCOLLABORATION_GRAPH    = YES\n\n# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for\n# groups, showing the direct groups dependencies.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGROUP_GRAPHS           = YES\n\n# If the UML_LOOK tag is set to YES doxygen will generate inheritance and\n# collaboration diagrams in a style similar to the OMG's Unified Modeling\n# Language.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LOOK               = NO\n\n# If the UML_LOOK tag is enabled, the fields and methods are shown inside the\n# class node. If there are many fields or methods and many nodes the graph may\n# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the\n# number of items for each type to make the size more manageable. Set this to 0\n# for no limit. Note that the threshold may be exceeded by 50% before the limit\n# is enforced. So when you set the threshold to 10, up to 15 fields may appear,\n# but if the number exceeds 15, the total amount of fields shown is limited to\n# 10.\n# Minimum value: 0, maximum value: 100, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LIMIT_NUM_FIELDS   = 10\n\n# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and\n# collaboration graphs will show the relations between templates and their\n# instances.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nTEMPLATE_RELATIONS     = NO\n\n# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to\n# YES then doxygen will generate a graph for each documented file showing the\n# direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDE_GRAPH          = YES\n\n# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are\n# set to YES then doxygen will generate a graph for each documented file showing\n# the direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDED_BY_GRAPH      = YES\n\n# If the CALL_GRAPH tag is set to YES then doxygen will generate a call\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable call graphs for selected\n# functions only using the \\callgraph command.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALL_GRAPH             = NO\n\n# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable caller graphs for selected\n# functions only using the \\callergraph command.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALLER_GRAPH           = NO\n\n# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical\n# hierarchy of all classes instead of a textual one.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGRAPHICAL_HIERARCHY    = YES\n\n# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the\n# dependencies a directory has on other directories in a graphical way. The\n# dependency relations are determined by the #include relations between the\n# files in the directories.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDIRECTORY_GRAPH        = YES\n\n# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images\n# generated by dot.\n# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order\n# to make the SVG files visible in IE 9+ (other browsers do not have this\n# requirement).\n# Possible values are: png, jpg, gif and svg.\n# The default value is: png.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_IMAGE_FORMAT       = png\n\n# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to\n# enable generation of interactive SVG images that allow zooming and panning.\n#\n# Note that this requires a modern browser other than Internet Explorer. Tested\n# and working are Firefox, Chrome, Safari, and Opera.\n# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make\n# the SVG files visible. Older versions of IE do not have SVG support.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINTERACTIVE_SVG        = NO\n\n# The DOT_PATH tag can be used to specify the path where the dot tool can be\n# found. If left blank, it is assumed the dot tool can be found in the path.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_PATH               =\n\n# The DOTFILE_DIRS tag can be used to specify one or more directories that\n# contain dot files that are included in the documentation (see the \\dotfile\n# command).\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOTFILE_DIRS           =\n\n# The MSCFILE_DIRS tag can be used to specify one or more directories that\n# contain msc files that are included in the documentation (see the \\mscfile\n# command).\n\nMSCFILE_DIRS           =\n\n# The DIAFILE_DIRS tag can be used to specify one or more directories that\n# contain dia files that are included in the documentation (see the \\diafile\n# command).\n\nDIAFILE_DIRS           =\n\n# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the\n# path where java can find the plantuml.jar file. If left blank, it is assumed\n# PlantUML is not used or called during a preprocessing step. Doxygen will\n# generate a warning when it encounters a \\startuml command in this case and\n# will not generate output for the diagram.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nPLANTUML_JAR_PATH      =\n\n# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes\n# that will be shown in the graph. If the number of nodes in a graph becomes\n# larger than this value, doxygen will truncate the graph, which is visualized\n# by representing a node as a red box. Note that doxygen if the number of direct\n# children of the root node in a graph is already larger than\n# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that\n# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.\n# Minimum value: 0, maximum value: 10000, default value: 50.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_GRAPH_MAX_NODES    = 50\n\n# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs\n# generated by dot. A depth value of 3 means that only nodes reachable from the\n# root by following a path via at most 3 edges will be shown. Nodes that lay\n# further from the root node will be omitted. Note that setting this option to 1\n# or 2 may greatly reduce the computation time needed for large code bases. Also\n# note that the size of a graph can be further restricted by\n# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.\n# Minimum value: 0, maximum value: 1000, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nMAX_DOT_GRAPH_DEPTH    = 0\n\n# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent\n# background. This is disabled by default, because dot on Windows does not seem\n# to support this out of the box.\n#\n# Warning: Depending on the platform used, enabling this option may lead to\n# badly anti-aliased labels on the edges of a graph (i.e. they become hard to\n# read).\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_TRANSPARENT        = NO\n\n# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output\n# files in one run (i.e. multiple -o and -T options on the command line). This\n# makes dot run faster, but since only newer versions of dot (>1.8.10) support\n# this, this feature is disabled by default.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_MULTI_TARGETS      = NO\n\n# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page\n# explaining the meaning of the various boxes and arrows in the dot generated\n# graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGENERATE_LEGEND        = YES\n\n# If the DOT_CLEANUP tag is set to YES doxygen will remove the intermediate dot\n# files that are used to generate the various graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_CLEANUP            = YES\n"
  },
  {
    "path": "radio_config_Si4460.h",
    "content": "/*! @file radio_config.h\r\n * @brief This file contains the automatically generated\r\n * configurations.\r\n *\r\n * @n WDS GUI Version: 3.2.6.0\r\n * @n Device: Si4460 Rev.: B1                                 \r\n *\r\n * @b COPYRIGHT\r\n * @n Silicon Laboratories Confidential\r\n * @n Copyright 2013 Silicon Laboratories, Inc.\r\n * @n http://www.silabs.com\r\n */\r\n\r\n#ifndef RADIO_CONFIG_H_\r\n#define RADIO_CONFIG_H_\r\n\r\n// USER DEFINED PARAMETERS\r\n// Define your own parameters here\r\n\r\n// INPUT DATA\r\n/*\r\n// Crys_freq(Hz): 30000000    Crys_tol(ppm): 20    IF_mode: 2    High_perf_Ch_Fil: 1    OSRtune: 0    Ch_Fil_Bw_AFC: 0    ANT_DIV: 0    PM_pattern: 0    \r\n// MOD_type: 3    Rsymb(sps): 50000    Fdev(Hz): 100000    RXBW(Hz): 150000    Manchester: 0    AFC_en: 0    Rsymb_error: 0.0    Chip-Version: 2    \r\n// RF Freq.(MHz): 434    API_TC: 31    fhst: 250000    inputBW: 0    BERT: 0    RAW_dout: 0    D_source: 0    Hi_pfm_div: 1    \r\n// \r\n// # WB filter 2 (BW = 274.83 kHz);  NB-filter 2 (BW = 274.83 kHz) \r\r\n// \r\n// Modulation index: 4\r\n*/\r\n\r\n\r\n// CONFIGURATION PARAMETERS\r\n#define RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ                     {30000000L}\r\n#define RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER                    {0x00}\r\n#define RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH               {0x07}\r\n#define RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP        {0x03}\r\n#define RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET       {0xF000}\r\n#define RADIO_CONFIGURATION_DATA_CUSTOM_PAYLOAD\t\t\t\t\t   {0xC5, 0xC5, 0xC5, 0xC5, 0xC5, 0xC5, 0xC5}\r\n\r\n\r\n// CONFIGURATION COMMANDS\r\n\r\n/*\r\n// Command:                  RF_POWER_UP\r\n// Description:              Command to power-up the device and select the operational mode and functionality.\r\n*/\r\n#define RF_POWER_UP 0x02, 0x01, 0x00, 0x01, 0xC9, 0xC3, 0x80\r\n\r\n/*\r\n// Command:                  RF_GPIO_PIN_CFG\r\n// Description:              Configures the GPIO pins.\r\n*/\r\n#define RF_GPIO_PIN_CFG 0x13, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r\n\r\n/*\r\n// Set properties:           RF_GLOBAL_XO_TUNE_1\r\n// Number of properties:     1\r\n// Group ID:                 0x00\r\n// Start ID:                 0x00\r\n// Default values:           0x40, \r\n// Descriptions:\r\n//   GLOBAL_XO_TUNE - Configure the internal capacitor frequency tuning bank for the crystal oscillator.\r\n*/\r\n#define RF_GLOBAL_XO_TUNE_1 0x11, 0x00, 0x01, 0x00, 0x52\r\n\r\n/*\r\n// Set properties:           RF_GLOBAL_CONFIG_1\r\n// Number of properties:     1\r\n// Group ID:                 0x00\r\n// Start ID:                 0x03\r\n// Default values:           0x20, \r\n// Descriptions:\r\n//   GLOBAL_CONFIG - Global configuration settings.\r\n*/\r\n#define RF_GLOBAL_CONFIG_1 0x11, 0x00, 0x01, 0x03, 0x60\r\n\r\n/*\r\n// Set properties:           RF_INT_CTL_ENABLE_2\r\n// Number of properties:     2\r\n// Group ID:                 0x01\r\n// Start ID:                 0x00\r\n// Default values:           0x04, 0x00, \r\n// Descriptions:\r\n//   INT_CTL_ENABLE - This property provides for global enabling of the three interrupt groups (Chip, Modem and Packet Handler) in order to generate HW interrupts at the NIRQ pin.\r\n//   INT_CTL_PH_ENABLE - Enable individual interrupt sources within the Packet Handler Interrupt Group to generate a HW interrupt on the NIRQ output pin.\r\n*/\r\n#define RF_INT_CTL_ENABLE_2 0x11, 0x01, 0x02, 0x00, 0x01, 0x38\r\n\r\n/*\r\n// Set properties:           RF_FRR_CTL_A_MODE_4\r\n// Number of properties:     4\r\n// Group ID:                 0x02\r\n// Start ID:                 0x00\r\n// Default values:           0x01, 0x02, 0x09, 0x00, \r\n// Descriptions:\r\n//   FRR_CTL_A_MODE - Fast Response Register A Configuration.\r\n//   FRR_CTL_B_MODE - Fast Response Register B Configuration.\r\n//   FRR_CTL_C_MODE - Fast Response Register C Configuration.\r\n//   FRR_CTL_D_MODE - Fast Response Register D Configuration.\r\n*/\r\n#define RF_FRR_CTL_A_MODE_4 0x11, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00\r\n\r\n/*\r\n// Set properties:           RF_PREAMBLE_TX_LENGTH_9\r\n// Number of properties:     9\r\n// Group ID:                 0x10\r\n// Start ID:                 0x00\r\n// Default values:           0x08, 0x14, 0x00, 0x0F, 0x21, 0x00, 0x00, 0x00, 0x00, \r\n// Descriptions:\r\n//   PREAMBLE_TX_LENGTH - Configure length of TX Preamble.\r\n//   PREAMBLE_CONFIG_STD_1 - Configuration of reception of a packet with a Standard Preamble pattern.\r\n//   PREAMBLE_CONFIG_NSTD - Configuration of transmission/reception of a packet with a Non-Standard Preamble pattern.\r\n//   PREAMBLE_CONFIG_STD_2 - Configuration of timeout periods during reception of a packet with Standard Preamble pattern.\r\n//   PREAMBLE_CONFIG - General configuration bits for the Preamble field.\r\n//   PREAMBLE_PATTERN_31_24 - Configuration of the bit values describing a Non-Standard Preamble pattern.\r\n//   PREAMBLE_PATTERN_23_16 - Configuration of the bit values describing a Non-Standard Preamble pattern.\r\n//   PREAMBLE_PATTERN_15_8 - Configuration of the bit values describing a Non-Standard Preamble pattern.\r\n//   PREAMBLE_PATTERN_7_0 - Configuration of the bit values describing a Non-Standard Preamble pattern.\r\n*/\r\n#define RF_PREAMBLE_TX_LENGTH_9 0x11, 0x10, 0x09, 0x00, 0x08, 0x14, 0x00, 0x0F, 0x31, 0x00, 0x00, 0x00, 0x00\r\n\r\n/*\r\n// Set properties:           RF_SYNC_CONFIG_5\r\n// Number of properties:     5\r\n// Group ID:                 0x11\r\n// Start ID:                 0x00\r\n// Default values:           0x01, 0x2D, 0xD4, 0x2D, 0xD4, \r\n// Descriptions:\r\n//   SYNC_CONFIG - Sync Word configuration bits.\r\n//   SYNC_BITS_31_24 - Sync word.\r\n//   SYNC_BITS_23_16 - Sync word.\r\n//   SYNC_BITS_15_8 - Sync word.\r\n//   SYNC_BITS_7_0 - Sync word.\r\n*/\r\n#define RF_SYNC_CONFIG_5 0x11, 0x11, 0x05, 0x00, 0x01, 0xB4, 0x2B, 0x00, 0x00\r\n\r\n/*\r\n// Set properties:           RF_PKT_CRC_CONFIG_1\r\n// Number of properties:     1\r\n// Group ID:                 0x12\r\n// Start ID:                 0x00\r\n// Default values:           0x00, \r\n// Descriptions:\r\n//   PKT_CRC_CONFIG - Select a CRC polynomial and seed.\r\n*/\r\n#define RF_PKT_CRC_CONFIG_1 0x11, 0x12, 0x01, 0x00, 0x80\r\n\r\n/*\r\n// Set properties:           RF_PKT_WHT_SEED_15_8_4\r\n// Number of properties:     4\r\n// Group ID:                 0x12\r\n// Start ID:                 0x03\r\n// Default values:           0xFF, 0xFF, 0x00, 0x00, \r\n// Descriptions:\r\n//   PKT_WHT_SEED_15_8 - 16-bit seed value for the PN Generator (e.g., for Data Whitening)\r\n//   PKT_WHT_SEED_7_0 - 16-bit seed value for the PN Generator (e.g., for Data Whitening)\r\n//   PKT_WHT_BIT_NUM - Selects which bit of the LFSR (used to generate the PN / data whitening sequence) is used as the output bit for data scrambling.\r\n//   PKT_CONFIG1 - General configuration bits for transmission or reception of a packet.\r\n*/\r\n#define RF_PKT_WHT_SEED_15_8_4 0x11, 0x12, 0x04, 0x03, 0xFF, 0xFF, 0x00, 0x02\r\n\r\n/*\r\n// Set properties:           RF_PKT_LEN_12\r\n// Number of properties:     12\r\n// Group ID:                 0x12\r\n// Start ID:                 0x08\r\n// Default values:           0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r\n// Descriptions:\r\n//   PKT_LEN - Configuration bits for reception of a variable length packet.\r\n//   PKT_LEN_FIELD_SOURCE - Field number containing the received packet length byte(s).\r\n//   PKT_LEN_ADJUST - Provides for adjustment/offset of the received packet length value (in order to accommodate a variety of methods of defining total packet length).\r\n//   PKT_TX_THRESHOLD - TX FIFO almost empty threshold.\r\n//   PKT_RX_THRESHOLD - RX FIFO Almost Full threshold.\r\n//   PKT_FIELD_1_LENGTH_12_8 - Unsigned 13-bit Field 1 length value.\r\n//   PKT_FIELD_1_LENGTH_7_0 - Unsigned 13-bit Field 1 length value.\r\n//   PKT_FIELD_1_CONFIG - General data processing and packet configuration bits for Field 1.\r\n//   PKT_FIELD_1_CRC_CONFIG - Configuration of CRC control bits across Field 1.\r\n//   PKT_FIELD_2_LENGTH_12_8 - Unsigned 13-bit Field 2 length value.\r\n//   PKT_FIELD_2_LENGTH_7_0 - Unsigned 13-bit Field 2 length value.\r\n//   PKT_FIELD_2_CONFIG - General data processing and packet configuration bits for Field 2.\r\n*/\r\n#define RF_PKT_LEN_12 0x11, 0x12, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00\r\n\r\n/*\r\n// Set properties:           RF_PKT_FIELD_2_CRC_CONFIG_12\r\n// Number of properties:     12\r\n// Group ID:                 0x12\r\n// Start ID:                 0x14\r\n// Default values:           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r\n// Descriptions:\r\n//   PKT_FIELD_2_CRC_CONFIG - Configuration of CRC control bits across Field 2.\r\n//   PKT_FIELD_3_LENGTH_12_8 - Unsigned 13-bit Field 3 length value.\r\n//   PKT_FIELD_3_LENGTH_7_0 - Unsigned 13-bit Field 3 length value.\r\n//   PKT_FIELD_3_CONFIG - General data processing and packet configuration bits for Field 3.\r\n//   PKT_FIELD_3_CRC_CONFIG - Configuration of CRC control bits across Field 3.\r\n//   PKT_FIELD_4_LENGTH_12_8 - Unsigned 13-bit Field 4 length value.\r\n//   PKT_FIELD_4_LENGTH_7_0 - Unsigned 13-bit Field 4 length value.\r\n//   PKT_FIELD_4_CONFIG - General data processing and packet configuration bits for Field 4.\r\n//   PKT_FIELD_4_CRC_CONFIG - Configuration of CRC control bits across Field 4.\r\n//   PKT_FIELD_5_LENGTH_12_8 - Unsigned 13-bit Field 5 length value.\r\n//   PKT_FIELD_5_LENGTH_7_0 - Unsigned 13-bit Field 5 length value.\r\n//   PKT_FIELD_5_CONFIG - General data processing and packet configuration bits for Field 5.\r\n*/\r\n#define RF_PKT_FIELD_2_CRC_CONFIG_12 0x11, 0x12, 0x0C, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r\n\r\n/*\r\n// Set properties:           RF_PKT_FIELD_5_CRC_CONFIG_1\r\n// Number of properties:     1\r\n// Group ID:                 0x12\r\n// Start ID:                 0x20\r\n// Default values:           0x00, \r\n// Descriptions:\r\n//   PKT_FIELD_5_CRC_CONFIG - Configuration of CRC control bits across Field 5.\r\n*/\r\n#define RF_PKT_FIELD_5_CRC_CONFIG_1 0x11, 0x12, 0x01, 0x20, 0x00\r\n\r\n/*\r\n// Set properties:           RF_MODEM_MOD_TYPE_12\r\n// Number of properties:     12\r\n// Group ID:                 0x20\r\n// Start ID:                 0x00\r\n// Default values:           0x02, 0x80, 0x07, 0x0F, 0x42, 0x40, 0x01, 0xC9, 0xC3, 0x80, 0x00, 0x06, \r\n// Descriptions:\r\n//   MODEM_MOD_TYPE - Selects the type of modulation. In TX mode, additionally selects the source of the modulation.\r\n//   MODEM_MAP_CONTROL - Controls polarity and mapping of transmit and receive bits.\r\n//   MODEM_DSM_CTRL - Miscellaneous control bits for the Delta-Sigma Modulator (DSM) in the PLL Synthesizer.\r\n//   MODEM_DATA_RATE_2 - Unsigned 24-bit value used to determine the TX data rate\r\n//   MODEM_DATA_RATE_1 - Unsigned 24-bit value used to determine the TX data rate\r\n//   MODEM_DATA_RATE_0 - Unsigned 24-bit value used to determine the TX data rate\r\n//   MODEM_TX_NCO_MODE_3 - TX Gaussian filter oversampling ratio and Byte 3 of unsigned 26-bit TX Numerically Controlled Oscillator (NCO) modulus.\r\n//   MODEM_TX_NCO_MODE_2 - TX Gaussian filter oversampling ratio and Byte 3 of unsigned 26-bit TX Numerically Controlled Oscillator (NCO) modulus.\r\n//   MODEM_TX_NCO_MODE_1 - TX Gaussian filter oversampling ratio and Byte 3 of unsigned 26-bit TX Numerically Controlled Oscillator (NCO) modulus.\r\n//   MODEM_TX_NCO_MODE_0 - TX Gaussian filter oversampling ratio and Byte 3 of unsigned 26-bit TX Numerically Controlled Oscillator (NCO) modulus.\r\n//   MODEM_FREQ_DEV_2 - 17-bit unsigned TX frequency deviation word.\r\n//   MODEM_FREQ_DEV_1 - 17-bit unsigned TX frequency deviation word.\r\n*/\r\n#define RF_MODEM_MOD_TYPE_12 0x11, 0x20, 0x0C, 0x00, 0x03, 0x00, 0x07, 0x0F, 0x42, 0x40, 0x09, 0xC9, 0xC3, 0x80, 0x00, 0x1B\r\n\r\n/*\r\n// Set properties:           RF_MODEM_FREQ_DEV_0_1\r\n// Number of properties:     1\r\n// Group ID:                 0x20\r\n// Start ID:                 0x0C\r\n// Default values:           0xD3, \r\n// Descriptions:\r\n//   MODEM_FREQ_DEV_0 - 17-bit unsigned TX frequency deviation word.\r\n*/\r\n#define RF_MODEM_FREQ_DEV_0_1 0x11, 0x20, 0x01, 0x0C, 0x4F\r\n\r\n/*\r\n// Set properties:           RF_MODEM_TX_RAMP_DELAY_8\r\n// Number of properties:     8\r\n// Group ID:                 0x20\r\n// Start ID:                 0x18\r\n// Default values:           0x01, 0x00, 0x08, 0x03, 0xC0, 0x00, 0x10, 0x20, \r\n// Descriptions:\r\n//   MODEM_TX_RAMP_DELAY - TX ramp-down delay setting.\r\n//   MODEM_MDM_CTRL - MDM control.\r\n//   MODEM_IF_CONTROL - Selects Fixed-IF, Scaled-IF, or Zero-IF mode of RX Modem operation.\r\n//   MODEM_IF_FREQ_2 - the IF frequency setting (an 18-bit signed number).\r\n//   MODEM_IF_FREQ_1 - the IF frequency setting (an 18-bit signed number).\r\n//   MODEM_IF_FREQ_0 - the IF frequency setting (an 18-bit signed number).\r\n//   MODEM_DECIMATION_CFG1 - Specifies three decimator ratios for the Cascaded Integrator Comb (CIC) filter.\r\n//   MODEM_DECIMATION_CFG0 - Specifies miscellaneous parameters and decimator ratios for the Cascaded Integrator Comb (CIC) filter.\r\n*/\r\n#define RF_MODEM_TX_RAMP_DELAY_8 0x11, 0x20, 0x08, 0x18, 0x01, 0x80, 0x08, 0x03, 0x80, 0x00, 0x00, 0x10\r\n\r\n/*\r\n// Set properties:           RF_MODEM_BCR_OSR_1_9\r\n// Number of properties:     9\r\n// Group ID:                 0x20\r\n// Start ID:                 0x22\r\n// Default values:           0x00, 0x4B, 0x06, 0xD3, 0xA0, 0x06, 0xD3, 0x02, 0xC0, \r\n// Descriptions:\r\n//   MODEM_BCR_OSR_1 - RX BCR/Slicer oversampling rate (12-bit unsigned number).\r\n//   MODEM_BCR_OSR_0 - RX BCR/Slicer oversampling rate (12-bit unsigned number).\r\n//   MODEM_BCR_NCO_OFFSET_2 - RX BCR NCO offset value (an unsigned 22-bit number).\r\n//   MODEM_BCR_NCO_OFFSET_1 - RX BCR NCO offset value (an unsigned 22-bit number).\r\n//   MODEM_BCR_NCO_OFFSET_0 - RX BCR NCO offset value (an unsigned 22-bit number).\r\n//   MODEM_BCR_GAIN_1 - The unsigned 11-bit RX BCR loop gain value.\r\n//   MODEM_BCR_GAIN_0 - The unsigned 11-bit RX BCR loop gain value.\r\n//   MODEM_BCR_GEAR - RX BCR loop gear control.\r\n//   MODEM_BCR_MISC1 - Miscellaneous control bits for the RX BCR loop.\r\n*/\r\n#define RF_MODEM_BCR_OSR_1_9 0x11, 0x20, 0x09, 0x22, 0x00, 0xC8, 0x02, 0x8F, 0x5C, 0x01, 0x48, 0x02, 0xC2\r\n\r\n/*\r\n// Set properties:           RF_MODEM_AFC_GEAR_7\r\n// Number of properties:     7\r\n// Group ID:                 0x20\r\n// Start ID:                 0x2C\r\n// Default values:           0x00, 0x23, 0x83, 0x69, 0x00, 0x40, 0xA0, \r\n// Descriptions:\r\n//   MODEM_AFC_GEAR - RX AFC loop gear control.\r\n//   MODEM_AFC_WAIT - RX AFC loop wait time control.\r\n//   MODEM_AFC_GAIN_1 - Sets the gain of the PLL-based AFC acquisition loop, and provides miscellaneous control bits for AFC functionality.\r\n//   MODEM_AFC_GAIN_0 - Sets the gain of the PLL-based AFC acquisition loop, and provides miscellaneous control bits for AFC functionality.\r\n//   MODEM_AFC_LIMITER_1 - Set the AFC limiter value.\r\n//   MODEM_AFC_LIMITER_0 - Set the AFC limiter value.\r\n//   MODEM_AFC_MISC - Specifies miscellaneous AFC control bits.\r\n*/\r\n#define RF_MODEM_AFC_GEAR_7 0x11, 0x20, 0x07, 0x2C, 0x04, 0x36, 0x80, 0x92, 0x0A, 0x46, 0x80\r\n\r\n/*\r\n// Set properties:           RF_MODEM_AGC_CONTROL_1\r\n// Number of properties:     1\r\n// Group ID:                 0x20\r\n// Start ID:                 0x35\r\n// Default values:           0xE0, \r\n// Descriptions:\r\n//   MODEM_AGC_CONTROL - Miscellaneous control bits for the Automatic Gain Control (AGC) function in the RX Chain.\r\n*/\r\n#define RF_MODEM_AGC_CONTROL_1 0x11, 0x20, 0x01, 0x35, 0xE2\r\n\r\n/*\r\n// Set properties:           RF_MODEM_AGC_WINDOW_SIZE_9\r\n// Number of properties:     9\r\n// Group ID:                 0x20\r\n// Start ID:                 0x38\r\n// Default values:           0x11, 0x10, 0x10, 0x0B, 0x1C, 0x40, 0x00, 0x00, 0x2B, \r\n// Descriptions:\r\n//   MODEM_AGC_WINDOW_SIZE - Specifies the size of the measurement and settling windows for the AGC algorithm.\r\n//   MODEM_AGC_RFPD_DECAY - Sets the decay time of the RF peak detectors.\r\n//   MODEM_AGC_IFPD_DECAY - Sets the decay time of the IF peak detectors.\r\n//   MODEM_FSK4_GAIN1 - Specifies the gain factor of the secondary branch in 4(G)FSK ISI-suppression.\r\n//   MODEM_FSK4_GAIN0 - Specifies the gain factor of the primary branch in 4(G)FSK ISI-suppression.\r\n//   MODEM_FSK4_TH1 - 16 bit 4(G)FSK slicer threshold.\r\n//   MODEM_FSK4_TH0 - 16 bit 4(G)FSK slicer threshold.\r\n//   MODEM_FSK4_MAP - 4(G)FSK symbol mapping code.\r\n//   MODEM_OOK_PDTC - Configures the attack and decay times of the OOK Peak Detector.\r\n*/\r\n#define RF_MODEM_AGC_WINDOW_SIZE_9 0x11, 0x20, 0x09, 0x38, 0x11, 0x2C, 0x2C, 0x00, 0x1A, 0xFF, 0xFF, 0x00, 0x29\r\n\r\n/*\r\n// Set properties:           RF_MODEM_OOK_CNT1_11\r\n// Number of properties:     11\r\n// Group ID:                 0x20\r\n// Start ID:                 0x42\r\n// Default values:           0xA4, 0x03, 0x56, 0x02, 0x00, 0xA3, 0x02, 0x80, 0xFF, 0x0C, 0x01, \r\n// Descriptions:\r\n//   MODEM_OOK_CNT1 - OOK control.\r\n//   MODEM_OOK_MISC - Selects the detector(s) used for demodulation of an OOK signal, or for demodulation of a (G)FSK signal when using the asynchronous demodulator.\r\n//   MODEM_RAW_SEARCH - Defines and controls the search period length for the Moving Average and Min-Max detectors.\r\n//   MODEM_RAW_CONTROL - Defines gain and enable controls for raw / nonstandard mode.\r\n//   MODEM_RAW_EYE_1 - 11 bit eye-open detector threshold.\r\n//   MODEM_RAW_EYE_0 - 11 bit eye-open detector threshold.\r\n//   MODEM_ANT_DIV_MODE - Antenna diversity mode settings.\r\n//   MODEM_ANT_DIV_CONTROL - Specifies controls for the Antenna Diversity algorithm.\r\n//   MODEM_RSSI_THRESH - Configures the RSSI threshold.\r\n//   MODEM_RSSI_JUMP_THRESH - Configures the RSSI Jump Detection threshold.\r\n//   MODEM_RSSI_CONTROL - Control of the averaging modes and latching time for reporting RSSI value(s).\r\n*/\r\n#define RF_MODEM_OOK_CNT1_11 0x11, 0x20, 0x0B, 0x42, 0xA4, 0x02, 0xD6, 0x83, 0x01, 0x7F, 0x01, 0x80, 0xFF, 0x0C, 0x02\r\n\r\n/*\r\n// Set properties:           RF_MODEM_RSSI_COMP_1\r\n// Number of properties:     1\r\n// Group ID:                 0x20\r\n// Start ID:                 0x4E\r\n// Default values:           0x40, \r\n// Descriptions:\r\n//   MODEM_RSSI_COMP - RSSI compensation value.\r\n*/\r\n#define RF_MODEM_RSSI_COMP_1 0x11, 0x20, 0x01, 0x4E, 0x40\r\n\r\n/*\r\n// Set properties:           RF_MODEM_CLKGEN_BAND_1\r\n// Number of properties:     1\r\n// Group ID:                 0x20\r\n// Start ID:                 0x51\r\n// Default values:           0x08, \r\n// Descriptions:\r\n//   MODEM_CLKGEN_BAND - Select PLL Synthesizer output divider ratio as a function of frequency band.\r\n*/\r\n#define RF_MODEM_CLKGEN_BAND_1 0x11, 0x20, 0x01, 0x51, 0x0A\r\n\r\n/*\r\n// Set properties:           RF_MODEM_CHFLT_RX1_CHFLT_COE13_7_0_12\r\n// Number of properties:     12\r\n// Group ID:                 0x21\r\n// Start ID:                 0x00\r\n// Default values:           0xFF, 0xBA, 0x0F, 0x51, 0xCF, 0xA9, 0xC9, 0xFC, 0x1B, 0x1E, 0x0F, 0x01, \r\n// Descriptions:\r\n//   MODEM_CHFLT_RX1_CHFLT_COE13_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE12_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE11_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE10_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE9_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE8_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE7_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE6_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE5_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE4_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE3_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE2_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n*/\r\n#define RF_MODEM_CHFLT_RX1_CHFLT_COE13_7_0_12 0x11, 0x21, 0x0C, 0x00, 0xFF, 0xC4, 0x30, 0x7F, 0xF5, 0xB5, 0xB8, 0xDE, 0x05, 0x17, 0x16, 0x0C\r\n\r\n/*\r\n// Set properties:           RF_MODEM_CHFLT_RX1_CHFLT_COE1_7_0_12\r\n// Number of properties:     12\r\n// Group ID:                 0x21\r\n// Start ID:                 0x0C\r\n// Default values:           0xFC, 0xFD, 0x15, 0xFF, 0x00, 0x0F, 0xFF, 0xC4, 0x30, 0x7F, 0xF5, 0xB5, \r\n// Descriptions:\r\n//   MODEM_CHFLT_RX1_CHFLT_COE1_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COE0_7_0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COEM0 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COEM1 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COEM2 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX1_CHFLT_COEM3 - Filter coefficients for the first set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE13_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE12_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE11_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE10_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE9_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE8_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n*/\r\n#define RF_MODEM_CHFLT_RX1_CHFLT_COE1_7_0_12 0x11, 0x21, 0x0C, 0x0C, 0x03, 0x00, 0x15, 0xFF, 0x00, 0x00, 0xFF, 0xC4, 0x30, 0x7F, 0xF5, 0xB5\r\n\r\n/*\r\n// Set properties:           RF_MODEM_CHFLT_RX2_CHFLT_COE7_7_0_12\r\n// Number of properties:     12\r\n// Group ID:                 0x21\r\n// Start ID:                 0x18\r\n// Default values:           0xB8, 0xDE, 0x05, 0x17, 0x16, 0x0C, 0x03, 0x00, 0x15, 0xFF, 0x00, 0x00, \r\n// Descriptions:\r\n//   MODEM_CHFLT_RX2_CHFLT_COE7_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE6_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE5_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE4_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE3_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE2_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE1_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COE0_7_0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COEM0 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COEM1 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COEM2 - Filter coefficients for the second set of RX filter coefficients.\r\n//   MODEM_CHFLT_RX2_CHFLT_COEM3 - Filter coefficients for the second set of RX filter coefficients.\r\n*/\r\n#define RF_MODEM_CHFLT_RX2_CHFLT_COE7_7_0_12 0x11, 0x21, 0x0C, 0x18, 0xB8, 0xDE, 0x05, 0x17, 0x16, 0x0C, 0x03, 0x00, 0x15, 0xFF, 0x00, 0x00\r\n\r\n/*\r\n// Set properties:           RF_PA_MODE_4\r\n// Number of properties:     4\r\n// Group ID:                 0x22\r\n// Start ID:                 0x00\r\n// Default values:           0x08, 0x7F, 0x00, 0x5D, \r\n// Descriptions:\r\n//   PA_MODE - Selects the PA operating mode, and selects resolution of PA power adjustment (i.e., step size).\r\n//   PA_PWR_LVL - Configuration of PA output power level.\r\n//   PA_BIAS_CLKDUTY - Configuration of the PA Bias and duty cycle of the TX clock source.\r\n//   PA_TC - Configuration of PA ramping parameters.\r\n*/\r\n#define RF_PA_MODE_4 0x11, 0x22, 0x04, 0x00, 0x18, 0x01, 0xC0, 0x3F\r\n\r\n/*\r\n// Set properties:           RF_SYNTH_PFDCP_CPFF_7\r\n// Number of properties:     7\r\n// Group ID:                 0x23\r\n// Start ID:                 0x00\r\n// Default values:           0x2C, 0x0E, 0x0B, 0x04, 0x0C, 0x73, 0x03, \r\n// Descriptions:\r\n//   SYNTH_PFDCP_CPFF - Feed forward charge pump current selection.\r\n//   SYNTH_PFDCP_CPINT - Integration charge pump current selection.\r\n//   SYNTH_VCO_KV - Gain scaling factors (Kv) for the VCO tuning varactors on both the integrated-path and feed forward path.\r\n//   SYNTH_LPFILT3 - Value of resistor R2 in feed-forward path of loop filter.\r\n//   SYNTH_LPFILT2 - Value of capacitor C2 in feed-forward path of loop filter.\r\n//   SYNTH_LPFILT1 - Value of capacitors C1 and C3 in feed-forward path of loop filter.\r\n//   SYNTH_LPFILT0 - Bias current of the active amplifier in the feed-forward loop filter.\r\n*/\r\n#define RF_SYNTH_PFDCP_CPFF_7 0x11, 0x23, 0x07, 0x00, 0x2C, 0x0E, 0x0B, 0x04, 0x0C, 0x73, 0x03\r\n\r\n/*\r\n// Set properties:           RF_MATCH_VALUE_1_12\r\n// Number of properties:     12\r\n// Group ID:                 0x30\r\n// Start ID:                 0x00\r\n// Default values:           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r\n// Descriptions:\r\n//   MATCH_VALUE_1 - Match value to be compared with the result of logically AND-ing (bit-wise) the Mask 1 value with the received Match 1 byte.\r\n//   MATCH_MASK_1 - Mask value to be logically AND-ed (bit-wise) with the Match 1 byte.\r\n//   MATCH_CTRL_1 - Enable for Packet Match functionality, and configuration of Match Byte 1.\r\n//   MATCH_VALUE_2 - Match value to be compared with the result of logically AND-ing (bit-wise) the Mask 2 value with the received Match 2 byte.\r\n//   MATCH_MASK_2 - Mask value to be logically AND-ed (bit-wise) with the Match 2 byte.\r\n//   MATCH_CTRL_2 - Configuration of Match Byte 2.\r\n//   MATCH_VALUE_3 - Match value to be compared with the result of logically AND-ing (bit-wise) the Mask 3 value with the received Match 3 byte.\r\n//   MATCH_MASK_3 - Mask value to be logically AND-ed (bit-wise) with the Match 3 byte.\r\n//   MATCH_CTRL_3 - Configuration of Match Byte 3.\r\n//   MATCH_VALUE_4 - Match value to be compared with the result of logically AND-ing (bit-wise) the Mask 4 value with the received Match 4 byte.\r\n//   MATCH_MASK_4 - Mask value to be logically AND-ed (bit-wise) with the Match 4 byte.\r\n//   MATCH_CTRL_4 - Configuration of Match Byte 4.\r\n*/\r\n#define RF_MATCH_VALUE_1_12 0x11, 0x30, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r\n\r\n/*\r\n// Set properties:           RF_FREQ_CONTROL_INTE_8\r\n// Number of properties:     8\r\n// Group ID:                 0x40\r\n// Start ID:                 0x00\r\n// Default values:           0x3C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, \r\n// Descriptions:\r\n//   FREQ_CONTROL_INTE - Frac-N PLL Synthesizer integer divide number.\r\n//   FREQ_CONTROL_FRAC_2 - Frac-N PLL fraction number.\r\n//   FREQ_CONTROL_FRAC_1 - Frac-N PLL fraction number.\r\n//   FREQ_CONTROL_FRAC_0 - Frac-N PLL fraction number.\r\n//   FREQ_CONTROL_CHANNEL_STEP_SIZE_1 - EZ Frequency Programming channel step size.\r\n//   FREQ_CONTROL_CHANNEL_STEP_SIZE_0 - EZ Frequency Programming channel step size.\r\n//   FREQ_CONTROL_W_SIZE - Set window gating period (in number of crystal reference clock cycles) for counting VCO frequency during calibration.\r\n//   FREQ_CONTROL_VCOCNT_RX_ADJ - Adjust target count for VCO calibration in RX mode.\r\n*/\r\n#define RF_FREQ_CONTROL_INTE_8 0x11, 0x40, 0x08, 0x00, 0x38, 0x0E, 0xEE, 0xEE, 0x44, 0x44, 0x20, 0xFE\r\n\r\n\r\n// AUTOMATICALLY GENERATED CODE! \r\n// DO NOT EDIT/MODIFY BELOW THIS LINE!\r\n// --------------------------------------------\r\n\r\n#ifndef FIRMWARE_LOAD_COMPILE\r\n#define RADIO_CONFIGURATION_DATA_ARRAY { \\\r\n        0x07, RF_POWER_UP, \\\r\n        0x08, RF_GPIO_PIN_CFG, \\\r\n        0x05, RF_GLOBAL_XO_TUNE_1, \\\r\n        0x05, RF_GLOBAL_CONFIG_1, \\\r\n        0x06, RF_INT_CTL_ENABLE_2, \\\r\n        0x08, RF_FRR_CTL_A_MODE_4, \\\r\n        0x0D, RF_PREAMBLE_TX_LENGTH_9, \\\r\n        0x09, RF_SYNC_CONFIG_5, \\\r\n        0x05, RF_PKT_CRC_CONFIG_1, \\\r\n        0x08, RF_PKT_WHT_SEED_15_8_4, \\\r\n        0x10, RF_PKT_LEN_12, \\\r\n        0x10, RF_PKT_FIELD_2_CRC_CONFIG_12, \\\r\n        0x05, RF_PKT_FIELD_5_CRC_CONFIG_1, \\\r\n        0x10, RF_MODEM_MOD_TYPE_12, \\\r\n        0x05, RF_MODEM_FREQ_DEV_0_1, \\\r\n        0x0C, RF_MODEM_TX_RAMP_DELAY_8, \\\r\n        0x0D, RF_MODEM_BCR_OSR_1_9, \\\r\n        0x0B, RF_MODEM_AFC_GEAR_7, \\\r\n        0x05, RF_MODEM_AGC_CONTROL_1, \\\r\n        0x0D, RF_MODEM_AGC_WINDOW_SIZE_9, \\\r\n        0x0F, RF_MODEM_OOK_CNT1_11, \\\r\n        0x05, RF_MODEM_RSSI_COMP_1, \\\r\n        0x05, RF_MODEM_CLKGEN_BAND_1, \\\r\n        0x10, RF_MODEM_CHFLT_RX1_CHFLT_COE13_7_0_12, \\\r\n        0x10, RF_MODEM_CHFLT_RX1_CHFLT_COE1_7_0_12, \\\r\n        0x10, RF_MODEM_CHFLT_RX2_CHFLT_COE7_7_0_12, \\\r\n        0x08, RF_PA_MODE_4, \\\r\n        0x0B, RF_SYNTH_PFDCP_CPFF_7, \\\r\n        0x10, RF_MATCH_VALUE_1_12, \\\r\n        0x0C, RF_FREQ_CONTROL_INTE_8, \\\r\n        0x00 \\\r\n }\r\n#else\r\n#define RADIO_CONFIGURATION_DATA_ARRAY { 0 }\r\n#endif\r\n\r\n// DEFAULT VALUES FOR CONFIGURATION PARAMETERS\r\n#define RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ_DEFAULT                     30000000L\r\n#define RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER_DEFAULT                    0x00\r\n#define RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH_DEFAULT               0x10\r\n#define RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP_DEFAULT        0x01\r\n#define RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET_DEFAULT       0x1000\r\n#define RADIO_CONFIGURATION_DATA_CUSTOM_PAYLOAD_DEFAULT\t\t\t\t\t   0x42, 0x55, 0x54, 0x54, 0x4F, 0x4E, 0x31 // BUTTON1 \r\n\r\n#define RADIO_CONFIGURATION_DATA_RADIO_PATCH_INCLUDED                      0x00\r\n#define RADIO_CONFIGURATION_DATA_RADIO_PATCH_SIZE                          0x00\r\n#define RADIO_CONFIGURATION_DATA_RADIO_PATCH                               {  }\r\n\r\n#ifndef RADIO_CONFIGURATION_DATA_ARRAY\r\n#error \"This property must be defined!\"\r\n#endif\r\n\r\n#ifndef RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ\r\n#define RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ         { RADIO_CONFIGURATION_DATA_RADIO_XO_FREQ_DEFAULT }\r\n#endif\r\n\r\n#ifndef RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER\r\n#define RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER        { RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER_DEFAULT }\r\n#endif\r\n\r\n#ifndef RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH\r\n#define RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH   { RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH_DEFAULT }\r\n#endif\r\n\r\n#ifndef RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP\r\n#define RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP  { RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP_DEFAULT }\r\n#endif\r\n\r\n#ifndef RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET\r\n#define RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET { RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET_DEFAULT }\r\n#endif\r\n\r\n#ifndef RADIO_CONFIGURATION_DATA_CUSTOM_PAYLOAD\r\n#define RADIO_CONFIGURATION_DATA_CUSTOM_PAYLOAD        { RADIO_CONFIGURATION_DATA_CUSTOM_PAYLOAD_DEFAULT }\r\n#endif\r\n\r\n#define RADIO_CONFIGURATION_DATA { \\\r\n                            Radio_Configuration_Data_Array,                            \\\r\n                            RADIO_CONFIGURATION_DATA_CHANNEL_NUMBER,                   \\\r\n                            RADIO_CONFIGURATION_DATA_RADIO_PACKET_LENGTH,              \\\r\n                            RADIO_CONFIGURATION_DATA_RADIO_STATE_AFTER_POWER_UP,       \\\r\n                            RADIO_CONFIGURATION_DATA_RADIO_DELAY_CNT_AFTER_RESET,       \\\r\n                            RADIO_CONFIGURATION_DATA_CUSTOM_PAYLOAD                   \\\r\n                            }\r\n\r\n#endif /* RADIO_CONFIG_H_ */\n"
  },
  {
    "path": "tools/chain.conf",
    "content": "# chain.conf\n# config file for etherSimulator.pl\n# Specify the probability of correct delivery between nodea and nodeb (bidirectional)\n# probability:nodea:nodeb:probability\n# nodea and nodeb are integers 0 to 255\n# probability is a float range 0.0 to 1.0\n\n# In this example, the probability of successful transmission\n# between nodes 10 and 2 (and vice versa) is given as 0.5 (ie 50% chance)\nprobability:10:2:0.5\n"
  },
  {
    "path": "tools/etherSimulator.pl",
    "content": "#!/usr/bin/perl\n#\n# etherSimulator.pl\n# Simulates the luminiferous ether for RH_Simulator.\n# Connects multiple instances of RH_Simulator clients together and passes \n# simulated messages between them.\n\nuse Getopt::Long;\nuse strict;\n\n# Configurable variables\nmy $help;\nmy $config;\nmy $port = 4000;\n$port = $main::opt_p\n    if $main::opt_p;\nmy $bps = 10000;\n$bps = $main::opt_b\n    if $main::opt_b;\n\n# Config that shows probability of successful transmission between nodes\n# Read from config file\nmy %netconfig;\n\nuse warnings;\nuse POE qw(Component::Server::TCP Filter::Block);\nuse strict;\n\nmy @options = \n    (\n     'h'     => \\$help,                # Help, show usage\n     'c=s'   => \\$config,              # Config file\n     'b=n'   => \\$bps,                 # Bits per second simulated baud rate\n     'p=n'   => \\$port,                # port number\n    );\n\n&GetOptions(@options) || &usage;\n&usage if $help;\n\nreadConfig($config) if defined $config;\n\nsub usage\n{\n    print \"usage: $0 [-h] [-c configfile] [-b bitspersec] [-p portnumber]\\n\";\n    exit;\n}\n\n# config file for etherSimulator.pl\n# Specify the probability of correct delivery between nodea and nodeb (bidirectional)\n# probability:nodea:nodeb:probability\n# nodea and nodeb are integers 0 to 255\n# probability is a float range 0.0 to 1.0\n# In this example, the probability of successful transmission\n# between nodes 10 and 2 (and vice versa) is given as 0.5 (ie 50% chance)\n# probability:10:2:0.5\nsub readConfig\n{\n    my ($config) = @_;\n\n    if (open(CONFIG, $config))\n    {\n\twhile (<CONFIG>)\n\t{\n\t    if (/^probability:(\\d{1,3}):(\\d{1,3}):(\\d+(\\.\\d+))/)\n\t    {\n\t\t$netconfig{$1}{$2} = $3;\n\t\t$netconfig{$2}{$1} = $3; # Bidirectional\n\t    }\n\t}\n\tclose(CONFIG);\n    }\n    else\n    {\n\tprint STDERR \"Could not open config file $config: $!\\n\";\n\texit;\n    }\n}\n\n# See RHTcpProtocol.h\n# messages to and from us are preceded by the payload length as uint32_t in network byte order\nsub encoder\n{\n    my $stuff = shift;\n    substr($$stuff, 0, 0) = pack('N', length($$stuff));\n    return;\n}\n\nsub decoder\n{\n    my $stuff = shift;\n    return if (length($$stuff) < 4);\n    my ($length) = unpack('N', $$stuff);\n    return if (length($$stuff) < $length+4);\n    return $length + 4;\n}\n\n# Filter to assemble and disassemble messages accordiong to precending length\nmy $filter = POE::Filter::Block->new( LengthCodec => [ \\&encoder, \\&decoder ] );\n\n# Message types\n# See RH_TcpProtocol.h\nmy $RH_TCP_MESSAGE_TYPE_NOP                = 0; # Not used\nmy $RH_TCP_MESSAGE_TYPE_THISADDRESS        = 1; # Specifies the thisAddress of the connected sketch\nmy $RH_TCP_MESSAGE_TYPE_PACKET             = 2; # Message to/from the connected sketch\n\nmy %clients;\n\n# Look up the source and dest nodes in the netconfig and return the 0.0 to 1.0 probability\n# of successful delivery\nsub probabilityOfSuccessfulDelivery\n{\n    my ($from, $to) = @_;\n\n    return $netconfig{$from}{$to}\n        if exists $netconfig{$from}{$to};\n    # If no explicit probability, use 1.0 (certainty)\n    return 1.0;\n}\n\n# Return true if the message is simulted to have been received successfully\n# taking into account the probability of sucessful delivery\nsub willDeliverFromTo\n{\n    my ($from, $to) = @_;\n\n    my $prob = probabilityOfSuccessfulDelivery($from, $to);\n    return 1 \n\tif rand() < $prob;\n    return 0;\n}\n\nsub deliverMessages\n{\n    my ($key, $value);\n    while (($key, $value) = each(%clients))\n    {\n\tnext unless defined $$value{'packet'}; # No packet waiting for delivery\n\t# Find how long since the message was transmitted and see it its time to \n\t# deliver it to the client.\n\t# We are waiting here for the transmission time of the message to elapse\n\t# given the message length and the bits per second\n\tmy $elapsed = Time::HiRes::tv_interval([$$value{'packetreceived'}], [Time::HiRes::gettimeofday]);\n\tif ($elapsed > length($$value{'packet'}) * 8 / $bps)\n\t{\n\t    $$value{'client'}->put(pack('Ca*', $RH_TCP_MESSAGE_TYPE_PACKET, $$value{'packet'}));\n\t    delete $$value{'packet'}; # Delivered, forget it\n\t}\n    }\n}\n\nPOE::Session->create(\n  inline_states => {\n    _start => sub {\n      $_[KERNEL]->delay(tick => 1);\n    },\n\n    tick => sub {\n      deliverMessages();\n      $_[KERNEL]->delay(tick => 0.001);\n    },\n  },\n);\n\nPOE::Component::Server::TCP->new(\n    Port => $port,\n\n    ClientConnected => sub {\n\tmy $client = $_[HEAP]{client};\n\t# Create a new object to hold data about RH_TCP messages to and from this client\n\t$clients{$client} = {'client' => $client};\n    },\n\n    ClientInput => sub {\n\tmy $client = $_[HEAP]{client};\n\tmy $client_input = $_[ARG0];\n\tmy $client_id =  $_[ARG1];\n\tmy ($length, $type) = unpack('NC', $client_input);\n\tif ($type == $RH_TCP_MESSAGE_TYPE_THISADDRESS)\n\t{\n\t    # Client notifies us of its node ID\n\t    my ($length, $type, $thisaddress) = unpack('NCC', $client_input);\n\t    # Set the client objects thisaddress\n\t    $clients{$client}{'thisaddress'} = $thisaddress;\n\t}\n\telsif ($type == $RH_TCP_MESSAGE_TYPE_PACKET)\n\t{\n\t    # New packet for transmission\n\t    my ($length, $type, $packet) = unpack('NCa*', $client_input);\n\t    # Try to deliver the packet to all the other clients\n\t    my ($key, $value);\n\t    while (($key, $value) = each(%clients))\n\t    {\n\t\tnext if ($key eq $client); # Dont deliver back to the same client\n\n\t\t# Check the network config and see if delivery to this node is possible\n\t\tnext unless willDeliverFromTo($clients{$client}{'thisaddress'}, $$value{thisaddress});\n\n\t\t# The packet reached this destination, see if it collided with \n\t\t# another packet\n\t\tif (defined $$value{'packet'})\n\t\t{\n\t\t    # Collision with waiting packet, delete it\n\t\t    delete $$value{'packet'};\n\t\t}\n\t\telse\n\t\t{\n\t\t    # New packet, queue it for delivery to the client after the\n\t\t    # nominal transmission time is complete\n\t\t    $$value{'packet'} = $packet;\n\t\t    $$value{'packetreceived'} = Time::HiRes::gettimeofday();\n\t\t}\n\t    }\n\t}\n    },\n\n    ClientDisconnected => sub {\n\tmy $client = $_[HEAP]{client};\n\tdelete $clients{$client};\n    },\n    ClientFilter => $filter, # Handles prepended lengths to \n    );\n\nPOE::Kernel->run;\nexit;\n"
  },
  {
    "path": "tools/simBuild",
    "content": "#!/bin/bash\n#\n# simBuild\n# build a RadioHead example sketch for running as a simulated process\n# on Linux.\n#\n# usage: simBuild sketchname.pde\n# The executable will be saved in the current directory\n\nINPUT=$1\nOUTPUT=$(basename $INPUT \".pde\")\n\ng++ -g -I . -I RHutil -x c++ $INPUT tools/simMain.cpp RHGenericDriver.cpp RHMesh.cpp RHRouter.cpp RHReliableDatagram.cpp RHDatagram.cpp RH_TCP.cpp RH_Serial.cpp RHCRC.cpp RHutil/HardwareSerial.cpp -o $OUTPUT\n"
  },
  {
    "path": "tools/simMain.cpp",
    "content": "// main.cpp\n// Lets Arduino RadioHead sketches run within a simulator on Linux as a single process\n// Copyright (C) 2014 Mike McCauley\n// $Id: simMain.cpp,v 1.2 2014/05/09 05:30:03 mikem Exp mikem $\n\n#include <RadioHead.h>\n#if (RH_PLATFORM == RH_PLATFORM_UNIX) \n\n#include <stdio.h>\n#include <RHutil/simulator.h>\n#include <sys/time.h>\n#include <unistd.h>\n#include <time.h>\n\nSerialSimulator Serial;\n\n// Functions we expect to find in the sketch\nextern void setup();\nextern void loop();\n\n// Millis at the start of the process\nunsigned long start_millis;\n\nint    _simulator_argc;\nchar** _simulator_argv;\n\n// Returns milliseconds since beginning of day\nunsigned long time_in_millis()\n{    \n    struct timeval te; \n    gettimeofday(&te, NULL); // get current time\n    unsigned long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // caclulate milliseconds\n    return milliseconds;\n}\n\n// Run the Arduino standard functions in the main loop\nint main(int argc, char** argv)\n{\n    // Let simulated program have access to argc and argv\n    _simulator_argc = argc;\n    _simulator_argv = argv;\n    start_millis = time_in_millis();\n    // Seed the random number generator\n    srand(getpid() ^ (unsigned) time(NULL)/2);\n    setup();\n    while (1)\n\tloop();\n}\n\nvoid delay(unsigned long ms)\n{\n    usleep(ms * 1000);\n}\n\n// Arduino equivalent, milliseconds since process start\nunsigned long millis()\n{\n    return time_in_millis() - start_millis;\n}\n\nlong random(long from, long to)\n{\n    return from + (random() % (to - from));\n}\n\nlong random(long to)\n{\n    return random(0, to);\n}\n\n#endif\n"
  }
]