Lora Transport Abstraction Layer for sx1272

Dependents:   lora-transceiver

Committer:
trusch
Date:
Thu Oct 13 09:40:21 2016 +0000
Revision:
0:518c8dac75f3
initial commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trusch 0:518c8dac75f3 1 #ifndef __LORA_TRANSPORT__
trusch 0:518c8dac75f3 2 #define __LORA_TRANSPORT__
trusch 0:518c8dac75f3 3
trusch 0:518c8dac75f3 4 #include "sx1272-hal.h"
trusch 0:518c8dac75f3 5
trusch 0:518c8dac75f3 6 #define RF_FREQUENCY 868300000 // Hz
trusch 0:518c8dac75f3 7 #define TX_OUTPUT_POWER 20 // 14 dBm
trusch 0:518c8dac75f3 8 #define RX_TIMEOUT_VALUE 5000000 // in us
trusch 0:518c8dac75f3 9 #define TX_TIMEOUT_VALUE 5000000 // in us
trusch 0:518c8dac75f3 10 #define LORA_BANDWIDTH 0 // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved]
trusch 0:518c8dac75f3 11 #define LORA_SPREADING_FACTOR 9 // [SF7..SF12]
trusch 0:518c8dac75f3 12 #define LORA_CODINGRATE 1 // [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
trusch 0:518c8dac75f3 13 #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
trusch 0:518c8dac75f3 14 #define LORA_SYMBOL_TIMEOUT 5 // Symbols
trusch 0:518c8dac75f3 15 #define LORA_FIX_LENGTH_PAYLOAD_ON false
trusch 0:518c8dac75f3 16 #define LORA_FHSS_ENABLED false
trusch 0:518c8dac75f3 17 #define LORA_NB_SYMB_HOP 4
trusch 0:518c8dac75f3 18 #define LORA_IQ_INVERSION_ON false
trusch 0:518c8dac75f3 19 #define LORA_CRC_ENABLED true
trusch 0:518c8dac75f3 20
trusch 0:518c8dac75f3 21 #define MAX_PAYLOAD_SIZE 251
trusch 0:518c8dac75f3 22
trusch 0:518c8dac75f3 23 namespace LoraTransport {
trusch 0:518c8dac75f3 24
trusch 0:518c8dac75f3 25 struct Packet {
trusch 0:518c8dac75f3 26 uint16_t from_addr;
trusch 0:518c8dac75f3 27 uint16_t to_addr;
trusch 0:518c8dac75f3 28 uint8_t packet_number;
trusch 0:518c8dac75f3 29 uint8_t payload[MAX_PAYLOAD_SIZE];
trusch 0:518c8dac75f3 30 uint8_t payload_size;
trusch 0:518c8dac75f3 31 };
trusch 0:518c8dac75f3 32
trusch 0:518c8dac75f3 33 struct Ack {
trusch 0:518c8dac75f3 34 uint16_t from_addr;
trusch 0:518c8dac75f3 35 uint16_t to_addr;
trusch 0:518c8dac75f3 36 uint8_t packet_number;
trusch 0:518c8dac75f3 37 uint8_t success;
trusch 0:518c8dac75f3 38 };
trusch 0:518c8dac75f3 39
trusch 0:518c8dac75f3 40 enum State {
trusch 0:518c8dac75f3 41 IDLE, //0
trusch 0:518c8dac75f3 42 // TX cycle
trusch 0:518c8dac75f3 43 CAD_RUNNING, //1
trusch 0:518c8dac75f3 44 CAD_POSITIVE, //2
trusch 0:518c8dac75f3 45 CAD_NEGATIVE, //3
trusch 0:518c8dac75f3 46 TX_MSG, //4
trusch 0:518c8dac75f3 47 TX_MSG_TIMEOUT, //5
trusch 0:518c8dac75f3 48 TX_MSG_DONE, //6
trusch 0:518c8dac75f3 49 RX_ACK, //7
trusch 0:518c8dac75f3 50 RX_ACK_TIMEOUT, //8
trusch 0:518c8dac75f3 51 RX_ACK_ERROR, //9
trusch 0:518c8dac75f3 52 RX_ACK_DONE, //10
trusch 0:518c8dac75f3 53 TX_ERROR, //11
trusch 0:518c8dac75f3 54 TX_SUCCESS, //12
trusch 0:518c8dac75f3 55 // RX cycle
trusch 0:518c8dac75f3 56 RX_MSG, //13
trusch 0:518c8dac75f3 57 RX_MSG_TIMEOUT, //14
trusch 0:518c8dac75f3 58 RX_MSG_ERROR, //15
trusch 0:518c8dac75f3 59 RX_MSG_DONE, //16
trusch 0:518c8dac75f3 60 TX_ERROR_ACK, //17
trusch 0:518c8dac75f3 61 TX_ERROR_ACK_TIMEOUT, //18
trusch 0:518c8dac75f3 62 TX_ERROR_ACK_DONE, //19
trusch 0:518c8dac75f3 63 TX_SUCCESS_ACK, //20
trusch 0:518c8dac75f3 64 TX_SUCCESS_ACK_TIMEOUT, //21
trusch 0:518c8dac75f3 65 TX_SUCCESS_ACK_DONE, //22
trusch 0:518c8dac75f3 66 RX_ERROR, //23
trusch 0:518c8dac75f3 67 RX_SUCCESS //24
trusch 0:518c8dac75f3 68
trusch 0:518c8dac75f3 69 };
trusch 0:518c8dac75f3 70
trusch 0:518c8dac75f3 71 void init();
trusch 0:518c8dac75f3 72 void send(uint16_t addr, uint8_t *ptr, uint8_t len, uint32_t timeout = 20000000 /*µs -> 20s*/);
trusch 0:518c8dac75f3 73 void recv(uint32_t timeout = 20000000 /*µs -> 20s*/);
trusch 0:518c8dac75f3 74 bool done();
trusch 0:518c8dac75f3 75 bool success();
trusch 0:518c8dac75f3 76
trusch 0:518c8dac75f3 77 void setAddress(uint16_t addr);
trusch 0:518c8dac75f3 78 State getState();
trusch 0:518c8dac75f3 79 State getLastErrorState();
trusch 0:518c8dac75f3 80 Packet& getPacket();
trusch 0:518c8dac75f3 81 int16_t getRSSI();
trusch 0:518c8dac75f3 82 int8_t getSNR();
trusch 0:518c8dac75f3 83
trusch 0:518c8dac75f3 84 };
trusch 0:518c8dac75f3 85
trusch 0:518c8dac75f3 86 #endif // __LORA_TRANSPORT__