Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.9 KiB

  1. /*
  2. Radio
  3. RFM69 Radio Manager for ESP8266
  4. Based on sample code by Felix Rusu - http://LowPowerLab.com/contact
  5. Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef RFM69Manager_h
  18. #define RFM69Manager_h
  19. #include <RFM69.h>
  20. #include <RFM69_ATC.h>
  21. #include <SPI.h>
  22. // -----------------------------------------------------------------------------
  23. // Configuration
  24. // -----------------------------------------------------------------------------
  25. #define PING_EVERY 3
  26. #define RETRIES 2
  27. #define REQUESTACK 1
  28. #define RADIO_DEBUG 0
  29. #define SEND_PACKET_ID 1
  30. #define PACKET_SEPARATOR ':'
  31. typedef struct {
  32. unsigned long messageID;
  33. unsigned char packetID;
  34. unsigned char senderID;
  35. unsigned char targetID;
  36. char * name;
  37. char * value;
  38. int16_t rssi;
  39. } packet_t;
  40. typedef void (*TMessageCallback)(packet_t *);
  41. class RFM69Manager: public RFM69_ATC {
  42. public:
  43. RFM69Manager(uint8_t slaveSelectPin=RF69_SPI_CS, uint8_t interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false, uint8_t interruptNum=RF69_IRQ_NUM):
  44. RFM69_ATC(slaveSelectPin, interruptPin, isRFM69HW, interruptNum) {};
  45. bool initialize(uint8_t frequency, uint8_t nodeID, uint8_t networkID, const char* key, uint8_t gatewayID = 0, int16_t targetRSSI = -70);
  46. void onMessage(TMessageCallback fn);
  47. void separator(char sep);
  48. bool send(uint8_t destinationID, char * name, char * value, uint8_t retries = RETRIES, bool requestACK = REQUESTACK);
  49. bool send(char * name, char * value, uint8_t retries = RETRIES) {
  50. return send(_gatewayID, name, value, retries, false);
  51. }
  52. bool send(char * name, char * value, bool requestACK = REQUESTACK) {
  53. return send(_gatewayID, name, value, 0, requestACK);
  54. }
  55. bool loop();
  56. void promiscuous(bool promiscuous);
  57. packet_t * getMessage() {
  58. return &_message;
  59. }
  60. protected:
  61. packet_t _message;
  62. TMessageCallback _callback = NULL;
  63. uint8_t _gatewayID = 0;
  64. unsigned long _receiveCount = 0;
  65. #if SEND_PACKET_ID
  66. unsigned char _sendCount = 0;
  67. #endif
  68. unsigned int _ackCount = 0;
  69. char _separator = PACKET_SEPARATOR;
  70. virtual void select();
  71. };
  72. #endif