LoRa Access Point 1.5.2018

Dependencies:   mbed ds3231 SX1276Lib_LoRa_Access_Point

Committer:
lukas_formanek
Date:
Mon Apr 23 10:30:01 2018 +0000
Revision:
2:0499e1d037a5
Parent:
1:7543af31b91f
Child:
3:7a3ddda464bf
23.4.2018

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lukas_formanek 0:ea088908ad26 1 #ifndef RFM95W_H
lukas_formanek 0:ea088908ad26 2 #define RFM95W_H
lukas_formanek 0:ea088908ad26 3
lukas_formanek 0:ea088908ad26 4 #include "mbed.h"
lukas_formanek 0:ea088908ad26 5 #include "sx1276-hal.h"
lukas_formanek 0:ea088908ad26 6 #include "ESP8266.h"
lukas_formanek 1:7543af31b91f 7 #include "Board.h"
lukas_formanek 0:ea088908ad26 8
lukas_formanek 0:ea088908ad26 9 #define GATEWAY_ID 1 // Moja adresa (id)
lukas_formanek 0:ea088908ad26 10
lukas_formanek 0:ea088908ad26 11 ////////////////////////////////////////////////////////////////////////////////
lukas_formanek 0:ea088908ad26 12 ////////////////////////////////////////////////////////////////////////////////
lukas_formanek 0:ea088908ad26 13 /* Set this flag to '1' to display debug messages on the console */
lukas_formanek 0:ea088908ad26 14 #define DEBUG_MESSAGE 0
lukas_formanek 0:ea088908ad26 15
lukas_formanek 0:ea088908ad26 16 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */
lukas_formanek 0:ea088908ad26 17 #define USE_MODEM_LORA 1
lukas_formanek 0:ea088908ad26 18 #define USE_MODEM_FSK !USE_MODEM_LORA
lukas_formanek 0:ea088908ad26 19
lukas_formanek 0:ea088908ad26 20 #define RF_FREQUENCY 869525000 //868000000 // Hz
lukas_formanek 0:ea088908ad26 21 #define TX_OUTPUT_POWER 20 // 20 dBm
lukas_formanek 0:ea088908ad26 22
lukas_formanek 0:ea088908ad26 23 #if USE_MODEM_LORA == 1
lukas_formanek 0:ea088908ad26 24 // Max range, slow data rate = BW=125, CR=4/5, SF=12
lukas_formanek 0:ea088908ad26 25 #define LORA_BANDWIDTH 1 // [0: 125 kHz,
lukas_formanek 0:ea088908ad26 26 // 1: 250 kHz,
lukas_formanek 0:ea088908ad26 27 // 2: 500 kHz,
lukas_formanek 0:ea088908ad26 28 // 3: Reserved]
lukas_formanek 0:ea088908ad26 29 #define LORA_SPREADING_FACTOR 12 // [SF7..SF12]
lukas_formanek 0:ea088908ad26 30 #define LORA_CODINGRATE 1 // [1: 4/5,
lukas_formanek 0:ea088908ad26 31 // 2: 4/6,
lukas_formanek 0:ea088908ad26 32 // 3: 4/7,
lukas_formanek 0:ea088908ad26 33 // 4: 4/8]
lukas_formanek 0:ea088908ad26 34 #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
lukas_formanek 0:ea088908ad26 35 #define LORA_SYMBOL_TIMEOUT 5 // Symbols
lukas_formanek 0:ea088908ad26 36 #define LORA_FIX_LENGTH_PAYLOAD_ON false
lukas_formanek 0:ea088908ad26 37 #define LORA_FHSS_ENABLED false
lukas_formanek 0:ea088908ad26 38 #define LORA_NB_SYMB_HOP 4
lukas_formanek 0:ea088908ad26 39 #define LORA_IQ_INVERSION_ON false
lukas_formanek 0:ea088908ad26 40 #define LORA_CRC_ENABLED true
lukas_formanek 0:ea088908ad26 41
lukas_formanek 0:ea088908ad26 42 #elif USE_MODEM_FSK == 1
lukas_formanek 0:ea088908ad26 43
lukas_formanek 0:ea088908ad26 44 #define FSK_FDEV 25000 // Hz
lukas_formanek 0:ea088908ad26 45 #define FSK_DATARATE 19200 // bps
lukas_formanek 0:ea088908ad26 46 #define FSK_BANDWIDTH 50000 // Hz
lukas_formanek 0:ea088908ad26 47 #define FSK_AFC_BANDWIDTH 83333 // Hz
lukas_formanek 0:ea088908ad26 48 #define FSK_PREAMBLE_LENGTH 5 // Same for Tx and Rx
lukas_formanek 0:ea088908ad26 49 #define FSK_FIX_LENGTH_PAYLOAD_ON false
lukas_formanek 0:ea088908ad26 50 #define FSK_CRC_ENABLED true
lukas_formanek 0:ea088908ad26 51
lukas_formanek 0:ea088908ad26 52 #else
lukas_formanek 0:ea088908ad26 53 #error "Please define a modem in the compiler options."
lukas_formanek 0:ea088908ad26 54 #endif
lukas_formanek 0:ea088908ad26 55
lukas_formanek 0:ea088908ad26 56 #define RX_TIMEOUT_VALUE 2500000 // in us // 3500000
lukas_formanek 0:ea088908ad26 57 #define BUFF_SIZE 255 // Define the payload size here // 32
lukas_formanek 2:0499e1d037a5 58 #define MAX_DEVICES 255
lukas_formanek 0:ea088908ad26 59 //------------------------------------------------------------------------------
lukas_formanek 0:ea088908ad26 60 //------------------------------------------------------------------------------
lukas_formanek 0:ea088908ad26 61
lukas_formanek 0:ea088908ad26 62 class RFM95W
lukas_formanek 0:ea088908ad26 63 {
lukas_formanek 0:ea088908ad26 64 private:
lukas_formanek 0:ea088908ad26 65 RadioEvents_t radioEvents; /**< Radio events function pointer */
lukas_formanek 0:ea088908ad26 66 SX1276MB1xAS radio; /**< Radiovy modul */
lukas_formanek 0:ea088908ad26 67 DigitalOut indicationLed; /**< Indikacna led */
lukas_formanek 0:ea088908ad26 68 Ticker ledTicker;
lukas_formanek 0:ea088908ad26 69 // uint8_t receivedMessage[BUFF_SIZE];
lukas_formanek 1:7543af31b91f 70 uint8_t receivedMessage[BUFF_SIZE];
lukas_formanek 0:ea088908ad26 71 volatile uint8_t messageNumbers[MAX_DEVICES];
lukas_formanek 0:ea088908ad26 72 volatile uint8_t ledState;
lukas_formanek 0:ea088908ad26 73 volatile float timeOnAirSec;
lukas_formanek 0:ea088908ad26 74
lukas_formanek 0:ea088908ad26 75 void OnLedTick();
lukas_formanek 0:ea088908ad26 76 void SendAck(uint8_t addr, uint8_t messageNumber);
lukas_formanek 0:ea088908ad26 77 public:
lukas_formanek 0:ea088908ad26 78 RFM95W();
lukas_formanek 0:ea088908ad26 79 void Init();
lukas_formanek 0:ea088908ad26 80 void OnTxDone( void );
lukas_formanek 0:ea088908ad26 81 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
lukas_formanek 0:ea088908ad26 82 void OnTxTimeout( void );
lukas_formanek 0:ea088908ad26 83 void OnRxTimeout( void );
lukas_formanek 0:ea088908ad26 84 void OnRxError( void );
lukas_formanek 0:ea088908ad26 85 void OnCadDone( bool channelActivityDetected );
lukas_formanek 0:ea088908ad26 86 };
lukas_formanek 0:ea088908ad26 87 extern RFM95W rfm;
lukas_formanek 0:ea088908ad26 88
lukas_formanek 0:ea088908ad26 89 #endif