LoRa_Node_STM32F103C8T6

Dependencies:   mbed mbed-STM32F103C8T6 OneWireCRC_LoRa_Node SX1276Lib_LoRa_Node

Committer:
lukas_formanek
Date:
Mon Apr 23 21:28:49 2018 +0000
Revision:
4:a8853c148f2a
Parent:
3:369546c57dc7
Child:
5:6e899f5db65e
23.4.2018 ver 2

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