LoRa_Node_STM32F103C8T6
Dependencies: mbed mbed-STM32F103C8T6 OneWireCRC_LoRa_Node SX1276Lib_LoRa_Node
RFM95W.h@1:a54ff5e2c2f3, 2018-04-22 (annotated)
- Committer:
- lukas_formanek
- Date:
- Sun Apr 22 12:39:13 2018 +0000
- Revision:
- 1:a54ff5e2c2f3
- Parent:
- 0:cc04364f049a
- Child:
- 2:8bd9ce0ae2df
22.4.2018
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:cc04364f049a | 9 | #define NODE_ID 4 // 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 | 0:cc04364f049a | 59 | //------------------------------------------------------------------------------ |
lukas_formanek | 0:cc04364f049a | 60 | //------------------------------------------------------------------------------ |
lukas_formanek | 0:cc04364f049a | 61 | |
lukas_formanek | 0:cc04364f049a | 62 | class RFM95W |
lukas_formanek | 0:cc04364f049a | 63 | { |
lukas_formanek | 0:cc04364f049a | 64 | private: |
lukas_formanek | 0:cc04364f049a | 65 | RadioEvents_t radioEvents; /**< Radio events function pointer */ |
lukas_formanek | 0:cc04364f049a | 66 | SX1276MB1xAS radio; /**< Radiovy modul */ |
lukas_formanek | 0:cc04364f049a | 67 | DigitalOut indicationLed; /**< Indikacna led */ |
lukas_formanek | 0:cc04364f049a | 68 | AnalogIn noise; |
lukas_formanek | 0:cc04364f049a | 69 | Ticker ledTicker; |
lukas_formanek | 1:a54ff5e2c2f3 | 70 | Ticker sendTicker; |
lukas_formanek | 1:a54ff5e2c2f3 | 71 | Ticker ackTicker; |
lukas_formanek | 1:a54ff5e2c2f3 | 72 | |
lukas_formanek | 0:cc04364f049a | 73 | uint8_t receivedMessage[BUFF_SIZE]; |
lukas_formanek | 0:cc04364f049a | 74 | uint8_t sendBuffer[BUFF_SIZE]; |
lukas_formanek | 1:a54ff5e2c2f3 | 75 | uint8_t ack[3]; |
lukas_formanek | 0:cc04364f049a | 76 | volatile uint8_t messageNumbers[MAX_DEVICES]; |
lukas_formanek | 0:cc04364f049a | 77 | volatile uint8_t messageNumber; /**< My message number */ |
lukas_formanek | 0:cc04364f049a | 78 | volatile uint8_t ledState; |
lukas_formanek | 0:cc04364f049a | 79 | volatile float timeOnAirSec; |
lukas_formanek | 1:a54ff5e2c2f3 | 80 | volatile bool receivedAck; |
lukas_formanek | 0:cc04364f049a | 81 | |
lukas_formanek | 0:cc04364f049a | 82 | float CalculateRandomTime(); |
lukas_formanek | 0:cc04364f049a | 83 | void InitRandom(); |
lukas_formanek | 0:cc04364f049a | 84 | void OnLedTick(); |
lukas_formanek | 1:a54ff5e2c2f3 | 85 | void SendMessage(); |
lukas_formanek | 0:cc04364f049a | 86 | void SendAck(uint8_t addr, uint8_t messageNumber); |
lukas_formanek | 0:cc04364f049a | 87 | public: |
lukas_formanek | 0:cc04364f049a | 88 | RFM95W(); |
lukas_formanek | 0:cc04364f049a | 89 | void Init(); |
lukas_formanek | 0:cc04364f049a | 90 | void OnTxDone( void ); |
lukas_formanek | 0:cc04364f049a | 91 | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); |
lukas_formanek | 0:cc04364f049a | 92 | void OnTxTimeout( void ); |
lukas_formanek | 0:cc04364f049a | 93 | void OnRxTimeout( void ); |
lukas_formanek | 0:cc04364f049a | 94 | void OnRxError( void ); |
lukas_formanek | 1:a54ff5e2c2f3 | 95 | void OnCadDone( bool channelActivityDetected ); |
lukas_formanek | 0:cc04364f049a | 96 | void SendValue(uint8_t addr, float value); |
lukas_formanek | 0:cc04364f049a | 97 | }; |
lukas_formanek | 0:cc04364f049a | 98 | extern RFM95W rfm; |
lukas_formanek | 0:cc04364f049a | 99 | |
lukas_formanek | 0:cc04364f049a | 100 | #endif |