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