LoRa_Node_STM32F103C8T6

Dependencies:   mbed mbed-STM32F103C8T6 OneWireCRC_LoRa_Node SX1276Lib_LoRa_Node

Committer:
lukas_formanek
Date:
Mon Apr 30 17:10:02 2018 +0000
Revision:
5:6e899f5db65e
Parent:
4:a8853c148f2a
Child:
6:531b8dccca06
30.4.2018

Who changed what in which revision?

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