CaryCoders
/
demo_SX1276_standalone
standalone sx1276 demo program
Fork of SX1276_GPS by
main.h@33:319cbac3b6eb, 2015-09-03 (annotated)
- Committer:
- ftagius
- Date:
- Thu Sep 03 14:33:55 2015 +0000
- Revision:
- 33:319cbac3b6eb
- Parent:
- 32:a2472bbe7c92
sx1276 demo program requiring only the freedom board and a semtech shield
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ftagius | 29:0ea07cc7124b | 1 | /* |
ftagius | 29:0ea07cc7124b | 2 | / _____) _ | | |
ftagius | 29:0ea07cc7124b | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
ftagius | 29:0ea07cc7124b | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
ftagius | 29:0ea07cc7124b | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
ftagius | 29:0ea07cc7124b | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
ftagius | 29:0ea07cc7124b | 7 | ( C )2014 Semtech |
ftagius | 29:0ea07cc7124b | 8 | |
ftagius | 29:0ea07cc7124b | 9 | Description: Contains the callbacks for the IRQs and any application related details |
ftagius | 29:0ea07cc7124b | 10 | |
ftagius | 29:0ea07cc7124b | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
ftagius | 29:0ea07cc7124b | 12 | |
ftagius | 29:0ea07cc7124b | 13 | Maintainer: Miguel Luis and Gregory Cristian |
ftagius | 29:0ea07cc7124b | 14 | */ |
ftagius | 29:0ea07cc7124b | 15 | #ifndef __MAIN_H__ |
ftagius | 29:0ea07cc7124b | 16 | #define __MAIN_H__ |
ftagius | 33:319cbac3b6eb | 17 | #define STANDALONE 1 |
ftagius | 33:319cbac3b6eb | 18 | #ifndef STANDALONE |
ftagius | 29:0ea07cc7124b | 19 | #include "lcdadafruit.h" |
ftagius | 29:0ea07cc7124b | 20 | #include "GPS.h" |
ftagius | 33:319cbac3b6eb | 21 | #endif |
ftagius | 31:2c813f321db7 | 22 | #include "enums.h" |
ftagius | 31:2c813f321db7 | 23 | #include "typedefs.h" |
ftagius | 31:2c813f321db7 | 24 | |
ftagius | 29:0ea07cc7124b | 25 | /* |
ftagius | 29:0ea07cc7124b | 26 | * Callback functions prototypes |
ftagius | 29:0ea07cc7124b | 27 | */ |
ftagius | 29:0ea07cc7124b | 28 | /*! |
ftagius | 29:0ea07cc7124b | 29 | * @brief Function to be executed on Radio Tx Done event |
ftagius | 29:0ea07cc7124b | 30 | */ |
ftagius | 29:0ea07cc7124b | 31 | void OnTxDone( void ); |
ftagius | 29:0ea07cc7124b | 32 | |
ftagius | 29:0ea07cc7124b | 33 | /*! |
ftagius | 29:0ea07cc7124b | 34 | * @brief Function to be executed on Radio Rx Done event |
ftagius | 29:0ea07cc7124b | 35 | */ |
ftagius | 29:0ea07cc7124b | 36 | void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); |
ftagius | 29:0ea07cc7124b | 37 | |
ftagius | 29:0ea07cc7124b | 38 | /*! |
ftagius | 29:0ea07cc7124b | 39 | * @brief Function executed on Radio Tx Timeout event |
ftagius | 29:0ea07cc7124b | 40 | */ |
ftagius | 29:0ea07cc7124b | 41 | void OnTxTimeout( void ); |
ftagius | 29:0ea07cc7124b | 42 | |
ftagius | 29:0ea07cc7124b | 43 | /*! |
ftagius | 29:0ea07cc7124b | 44 | * @brief Function executed on Radio Rx Timeout event |
ftagius | 29:0ea07cc7124b | 45 | */ |
ftagius | 29:0ea07cc7124b | 46 | void OnRxTimeout( void ); |
ftagius | 29:0ea07cc7124b | 47 | |
ftagius | 29:0ea07cc7124b | 48 | /*! |
ftagius | 29:0ea07cc7124b | 49 | * @brief Function executed on Radio Rx Error event |
ftagius | 29:0ea07cc7124b | 50 | */ |
ftagius | 29:0ea07cc7124b | 51 | void OnRxError( void ); |
ftagius | 29:0ea07cc7124b | 52 | |
ftagius | 29:0ea07cc7124b | 53 | /*! |
ftagius | 29:0ea07cc7124b | 54 | * @brief Function executed on Radio Fhss Change Channel event |
ftagius | 29:0ea07cc7124b | 55 | */ |
ftagius | 29:0ea07cc7124b | 56 | void OnFhssChangeChannel( uint8_t channelIndex ); |
ftagius | 29:0ea07cc7124b | 57 | |
ftagius | 29:0ea07cc7124b | 58 | /*! |
ftagius | 29:0ea07cc7124b | 59 | * @brief Function executed on CAD Done event |
ftagius | 29:0ea07cc7124b | 60 | */ |
ftagius | 33:319cbac3b6eb | 61 | void OnCadDone( bool activity ); |
ftagius | 29:0ea07cc7124b | 62 | |
ftagius | 29:0ea07cc7124b | 63 | char* itoa(int val, int base); |
ftagius | 29:0ea07cc7124b | 64 | unsigned int randomSeed(void); |
ftagius | 29:0ea07cc7124b | 65 | void start_ping_pong(void); |
ftagius | 29:0ea07cc7124b | 66 | void ping_pong(void); |
ftagius | 29:0ea07cc7124b | 67 | void start_hello(void); |
ftagius | 29:0ea07cc7124b | 68 | void hello(void); |
ftagius | 29:0ea07cc7124b | 69 | int get_kbd_str(char* buf, int size); |
ftagius | 29:0ea07cc7124b | 70 | void console_chat(); |
ftagius | 29:0ea07cc7124b | 71 | void console(); |
ftagius | 29:0ea07cc7124b | 72 | void check_rx_chat(); |
ftagius | 29:0ea07cc7124b | 73 | void configRxTx(); |
ftagius | 29:0ea07cc7124b | 74 | void print_status(); |
ftagius | 29:0ea07cc7124b | 75 | void print_help(); |
ftagius | 29:0ea07cc7124b | 76 | void print_bandwidth(); |
ftagius | 29:0ea07cc7124b | 77 | void print_cr(); |
ftagius | 29:0ea07cc7124b | 78 | void print_power(); |
ftagius | 32:a2472bbe7c92 | 79 | void gps_setup(void); |
ftagius | 32:a2472bbe7c92 | 80 | int check_gps(void); |
ftagius | 29:0ea07cc7124b | 81 | |
ftagius | 29:0ea07cc7124b | 82 | /* |
ftagius | 29:0ea07cc7124b | 83 | * Global variables declarations |
ftagius | 29:0ea07cc7124b | 84 | */ |
ftagius | 29:0ea07cc7124b | 85 | extern Serial pc; |
ftagius | 29:0ea07cc7124b | 86 | //extern char pcbuf[]; |
ftagius | 29:0ea07cc7124b | 87 | |
ftagius | 29:0ea07cc7124b | 88 | #define RX_TIMEOUT_VALUE 5000000 // in us |
ftagius | 29:0ea07cc7124b | 89 | #define TX_TIMEOUT_VALUE 4000000 // in us |
ftagius | 29:0ea07cc7124b | 90 | #define BUFFER_SIZE 256 // Define the payload size here |
ftagius | 29:0ea07cc7124b | 91 | #define RADIO_INSTALLED true |
ftagius | 32:a2472bbe7c92 | 92 | /* Set this flag to '1' to display debug messages on the console */ |
ftagius | 32:a2472bbe7c92 | 93 | #define DEBUG_MESSAGE 1 |
ftagius | 32:a2472bbe7c92 | 94 | #define TX_OUTPUT_POWER 20 // 14 dBm |
ftagius | 33:319cbac3b6eb | 95 | #define LORA_BANDWIDTH 0 // [0: 125 kHz, |
ftagius | 32:a2472bbe7c92 | 96 | // 1: 250 kHz, |
ftagius | 32:a2472bbe7c92 | 97 | // 2: 500 kHz, |
ftagius | 32:a2472bbe7c92 | 98 | // 3: Reserved] |
ftagius | 32:a2472bbe7c92 | 99 | // #define LORA_SPREADING_FACTOR 7 // [SF7..SF12] |
ftagius | 32:a2472bbe7c92 | 100 | #define LORA_SPREADING_FACTOR 12 // [SF7..SF12] |
ftagius | 32:a2472bbe7c92 | 101 | // #define LORA_CODINGRATE 1 // [1: 4/5, |
ftagius | 32:a2472bbe7c92 | 102 | #define LORA_CODINGRATE 2 // [1: 4/5, |
ftagius | 32:a2472bbe7c92 | 103 | // 2: 4/6, |
ftagius | 32:a2472bbe7c92 | 104 | // 3: 4/7, |
ftagius | 32:a2472bbe7c92 | 105 | // 4: 4/8] |
ftagius | 32:a2472bbe7c92 | 106 | #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx |
ftagius | 32:a2472bbe7c92 | 107 | #define LORA_SYMBOL_TIMEOUT 5 // Symbols |
ftagius | 32:a2472bbe7c92 | 108 | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
ftagius | 32:a2472bbe7c92 | 109 | #define LORA_FHSS_ENABLED false |
ftagius | 32:a2472bbe7c92 | 110 | #define LORA_NB_SYMB_HOP 4 |
ftagius | 32:a2472bbe7c92 | 111 | #define LORA_IQ_INVERSION_ON false |
ftagius | 32:a2472bbe7c92 | 112 | #define LORA_CRC_ENABLED true |
ftagius | 29:0ea07cc7124b | 113 | |
ftagius | 29:0ea07cc7124b | 114 | #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) |
ftagius | 29:0ea07cc7124b | 115 | extern DigitalOut led; |
ftagius | 29:0ea07cc7124b | 116 | #else |
ftagius | 29:0ea07cc7124b | 117 | extern DigitalOut led; |
ftagius | 29:0ea07cc7124b | 118 | #endif |
ftagius | 29:0ea07cc7124b | 119 | |
ftagius | 29:0ea07cc7124b | 120 | typedef RadioState States_t; |
ftagius | 33:319cbac3b6eb | 121 | #ifndef STANDALONE |
ftagius | 29:0ea07cc7124b | 122 | extern LCDadafruit cLCD; |
ftagius | 33:319cbac3b6eb | 123 | extern GPS gpsd; |
ftagius | 33:319cbac3b6eb | 124 | #endif |
ftagius | 29:0ea07cc7124b | 125 | extern volatile States_t State; |
ftagius | 29:0ea07cc7124b | 126 | extern SX1276MB1xAS Radio; |
ftagius | 29:0ea07cc7124b | 127 | extern uint8_t PingMsg[]; |
ftagius | 29:0ea07cc7124b | 128 | extern uint8_t PongMsg[]; |
ftagius | 29:0ea07cc7124b | 129 | extern uint8_t HelloMsg[]; |
ftagius | 29:0ea07cc7124b | 130 | extern uint16_t BufferSize; |
ftagius | 29:0ea07cc7124b | 131 | extern uint8_t BufferTx[]; |
ftagius | 29:0ea07cc7124b | 132 | extern uint8_t BufferRx[]; |
ftagius | 31:2c813f321db7 | 133 | // radfta extern vt100 ctrl; |
ftagius | 29:0ea07cc7124b | 134 | extern float Frequency; |
ftagius | 32:a2472bbe7c92 | 135 | extern float distance; |
ftagius | 32:a2472bbe7c92 | 136 | extern float r_latitude; |
ftagius | 33:319cbac3b6eb | 137 | extern float r_latitude_last; |
ftagius | 33:319cbac3b6eb | 138 | extern float r_longitude_last; |
ftagius | 32:a2472bbe7c92 | 139 | extern float r_longitude; |
ftagius | 29:0ea07cc7124b | 140 | extern int TxPower; |
ftagius | 29:0ea07cc7124b | 141 | extern int Bandwidth; |
ftagius | 29:0ea07cc7124b | 142 | extern int SpreadingFactor; |
ftagius | 29:0ea07cc7124b | 143 | extern int CodingRate; |
ftagius | 29:0ea07cc7124b | 144 | extern int pkt_count; |
ftagius | 29:0ea07cc7124b | 145 | extern int pkt_data[]; |
ftagius | 29:0ea07cc7124b | 146 | extern int max_pkts; |
ftagius | 29:0ea07cc7124b | 147 | extern int per; |
ftagius | 29:0ea07cc7124b | 148 | extern bool isMaster; |
ftagius | 29:0ea07cc7124b | 149 | extern bool AlwaysMaster; |
ftagius | 29:0ea07cc7124b | 150 | extern bool AlwaysSlave; |
ftagius | 29:0ea07cc7124b | 151 | extern bool rxTimeout; |
ftagius | 29:0ea07cc7124b | 152 | extern char pcbuf[]; |
ftagius | 29:0ea07cc7124b | 153 | extern bool ackRcvd; |
ftagius | 29:0ea07cc7124b | 154 | extern bool gpsEnabled; |
ftagius | 29:0ea07cc7124b | 155 | extern int txLen; |
ftagius | 29:0ea07cc7124b | 156 | extern int16_t RssiValue; |
ftagius | 29:0ea07cc7124b | 157 | extern int8_t SnrValue; |
ftagius | 33:319cbac3b6eb | 158 | extern DigitalOut RXin; |
ftagius | 29:0ea07cc7124b | 159 | #define PCBUF_SIZE 64 |
ftagius | 32:a2472bbe7c92 | 160 | #define PI 3.14159265 |
ftagius | 29:0ea07cc7124b | 161 | |
ftagius | 29:0ea07cc7124b | 162 | typedef enum { |
ftagius | 29:0ea07cc7124b | 163 | APP_NONE = 0, |
ftagius | 29:0ea07cc7124b | 164 | APP_PING, |
ftagius | 29:0ea07cc7124b | 165 | APP_CHAT, |
ftagius | 29:0ea07cc7124b | 166 | APP_HELLO, |
ftagius | 29:0ea07cc7124b | 167 | APP_CONSOLE, |
ftagius | 29:0ea07cc7124b | 168 | APP_GPS |
ftagius | 29:0ea07cc7124b | 169 | } app_e; |
ftagius | 29:0ea07cc7124b | 170 | |
ftagius | 29:0ea07cc7124b | 171 | extern app_e app; |
ftagius | 29:0ea07cc7124b | 172 | |
ftagius | 29:0ea07cc7124b | 173 | #endif // __MAIN_H__ |