text: #pragma once
  
  #include <freertos/queue.h>
  
  #ifndef __LORA_H__
  #define __LORA_H__
  
  typedef struct {
      char *buf;
      int len;
  
      int rssi;
      int snr;
  
      int band;
  
      // Lora specific - modulation
      int sf;
      int cr;
  
      int cnt;
  } lora_packet;
  
  typedef void (*onMessageFunc)(char *data, int len, int interfaceId);
  
  typedef struct {
      int pinInterupt;
      int pinMiso;
      int pinMosi;
      int pinClk;
      int pinCs;
      int pinRst;
  
      // Active ( receive ) mode.
      bool dataReceive;
  
      // Receive band
      int band;
  
      int sf;
      int cr;
  
      // if time has synced, the band can be determined from time.
      // Else: listen on 0
      bool beaconReceive;
      // -1 if beacon sync not enabled.
      int beaconBand;
  
      int loraBeacons;
      int loraReceived;
  
      onMessageFunc onMessage;
      int interfaceId;
  
      lora_packet last;
  } lora_driver;
  
  extern lora_driver lora;
  
  int lora_init(xQueueHandle rcv);
  
  void lora_reset(void);
  void lora_explicit_header_mode(void);
  void lora_implicit_header_mode(int size);
  void lora_idle(void);
  void lora_sleep(void); 
  void lora_receive(void);
  void lora_set_tx_power(int level);
  void lora_set_frequency(long frequency);
  void lora_set_spreading_factor(int sf);
  void lora_set_bandwidth(long sbw);
  void lora_set_coding_rate(int denominator);
  void lora_set_preamble_length(long length);
  void lora_set_sync_word(int sw);
  void lora_enable_crc(void);
  void lora_disable_crc(void);
  void lora_send_packet(uint8_t *buf, int size);
  int lora_receive_packet(uint8_t *buf, int size);
  int lora_received(void);
  int lora_packet_rssi(void);
  float lora_packet_snr(void);
  void lora_close(void);
  int lora_initialized(void);
  void lora_dump_registers(void);
  void lora_invert_iq(bool inv);
  
  // Beacon period: 128s
  // Freq: 8 channels in round robin, (time/period)mod8
  //
  void lora_receive_beacon(int size);
  
  void lora_receive_upstream();
  #endif
  