Prueba LoRa

Dependencies:   BLE_API SX1276Lib mbed nRF51822

Fork of BLE_Observer by Bluetooth Low Energy

Committer:
Javier117
Date:
Wed Nov 02 20:53:30 2016 +0000
Revision:
8:3b30027c7e8f
Parent:
7:88f50499af9a
no change

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 0:332983584a9c 1 /* mbed Microcontroller Library
rgrover1 0:332983584a9c 2 * Copyright (c) 2006-2015 ARM Limited
rgrover1 0:332983584a9c 3 *
rgrover1 0:332983584a9c 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 0:332983584a9c 5 * you may not use this file except in compliance with the License.
rgrover1 0:332983584a9c 6 * You may obtain a copy of the License at
rgrover1 0:332983584a9c 7 *
rgrover1 0:332983584a9c 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 0:332983584a9c 9 *
rgrover1 0:332983584a9c 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 0:332983584a9c 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 0:332983584a9c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 0:332983584a9c 13 * See the License for the specific language governing permissions and
rgrover1 0:332983584a9c 14 * limitations under the License.
rgrover1 0:332983584a9c 15 */
rgrover1 0:332983584a9c 16
rgrover1 0:332983584a9c 17 #include "mbed.h"
andresag 7:88f50499af9a 18 #include "ble/BLE.h"
Javier117 8:3b30027c7e8f 19 #include "sx1276-hal.h"
Javier117 8:3b30027c7e8f 20 #include "main.h"
Javier117 8:3b30027c7e8f 21
Javier117 8:3b30027c7e8f 22 //Configuración del radio LoRa
Javier117 8:3b30027c7e8f 23 #define USE_MODEM_LORA 1
Javier117 8:3b30027c7e8f 24
Javier117 8:3b30027c7e8f 25 #define RF_FREQUENCY 915000000 //
Javier117 8:3b30027c7e8f 26 #define TX_OUTPUT_POWER 14 //14 dBm
Javier117 8:3b30027c7e8f 27
Javier117 8:3b30027c7e8f 28 #define LORA_BANDWIDTH 1 // [0: 125 kHz,
Javier117 8:3b30027c7e8f 29 // 1: 250 kHz,
Javier117 8:3b30027c7e8f 30 // 2: 500 kHz,
Javier117 8:3b30027c7e8f 31 // 3: Reserved]
Javier117 8:3b30027c7e8f 32 #define LORA_SPREADING_FACTOR 10 // [SF7..SF12]
Javier117 8:3b30027c7e8f 33 #define LORA_CODINGRATE 1 // [1: 4/5,
Javier117 8:3b30027c7e8f 34 // 2: 4/6,
Javier117 8:3b30027c7e8f 35 // 3: 4/7,
Javier117 8:3b30027c7e8f 36 // 4: 4/8]
Javier117 8:3b30027c7e8f 37 #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
Javier117 8:3b30027c7e8f 38 #define LORA_SYMBOL_TIMEOUT 5 // Symbols
Javier117 8:3b30027c7e8f 39 #define LORA_FIX_LENGTH_PAYLOAD_ON false
Javier117 8:3b30027c7e8f 40 #define LORA_FHSS_ENABLED true
Javier117 8:3b30027c7e8f 41 #define LORA_NB_SYMB_HOP 4
Javier117 8:3b30027c7e8f 42 #define LORA_IQ_INVERSION_ON false
Javier117 8:3b30027c7e8f 43 #define LORA_CRC_ENABLED true
Javier117 8:3b30027c7e8f 44
Javier117 8:3b30027c7e8f 45 #define RX_TIMEOUT_VALUE 3500000 // in us
Javier117 8:3b30027c7e8f 46 #define BUFFER_SIZE 40 // Define the payload size here [min:1 max:255]
Javier117 8:3b30027c7e8f 47
Javier117 8:3b30027c7e8f 48 /*
Javier117 8:3b30027c7e8f 49 * Global variables declarations
Javier117 8:3b30027c7e8f 50 */
Javier117 8:3b30027c7e8f 51 typedef enum
Javier117 8:3b30027c7e8f 52 {
Javier117 8:3b30027c7e8f 53 LOWPOWER = 0,
Javier117 8:3b30027c7e8f 54 IDLE,
Javier117 8:3b30027c7e8f 55
Javier117 8:3b30027c7e8f 56 RX,
Javier117 8:3b30027c7e8f 57 RX_TIMEOUT,
Javier117 8:3b30027c7e8f 58 RX_ERROR,
Javier117 8:3b30027c7e8f 59
Javier117 8:3b30027c7e8f 60 TX,
Javier117 8:3b30027c7e8f 61 TX_TIMEOUT,
Javier117 8:3b30027c7e8f 62
Javier117 8:3b30027c7e8f 63 CAD,
Javier117 8:3b30027c7e8f 64 CAD_DONE
Javier117 8:3b30027c7e8f 65 }AppStates_t;
Javier117 8:3b30027c7e8f 66
Javier117 8:3b30027c7e8f 67 volatile AppStates_t State = LOWPOWER;
Javier117 8:3b30027c7e8f 68
Javier117 8:3b30027c7e8f 69 /*!
Javier117 8:3b30027c7e8f 70 * Radio events function pointer
Javier117 8:3b30027c7e8f 71 */
Javier117 8:3b30027c7e8f 72 static RadioEvents_t RadioEvents;
Javier117 8:3b30027c7e8f 73
Javier117 8:3b30027c7e8f 74 /*
Javier117 8:3b30027c7e8f 75 * Global variables declarations
Javier117 8:3b30027c7e8f 76 */
Javier117 8:3b30027c7e8f 77 SX1276MB1xAS Radio( NULL );
Javier117 8:3b30027c7e8f 78
Javier117 8:3b30027c7e8f 79 uint16_t BufferSize = BUFFER_SIZE;
Javier117 8:3b30027c7e8f 80 uint8_t Buffer[BUFFER_SIZE];
Javier117 8:3b30027c7e8f 81
Javier117 8:3b30027c7e8f 82 int16_t RssiValue = 0.0;
Javier117 8:3b30027c7e8f 83 int8_t SnrValue = 0.0;
rgrover1 0:332983584a9c 84
andresag 7:88f50499af9a 85 DigitalOut led1(LED1, 1);
Javier117 8:3b30027c7e8f 86 DigitalOut led(LED2, 1);
andresag 7:88f50499af9a 87 Ticker ticker;
Javier117 8:3b30027c7e8f 88 Serial pc(USBTX, USBRX);
Javier117 8:3b30027c7e8f 89
Javier117 8:3b30027c7e8f 90 const unsigned int nMax = 10;
Javier117 8:3b30027c7e8f 91 const float dZero = 0.65; //Distancia de la señal de referencia
Javier117 8:3b30027c7e8f 92 const float pdBZero = -55.0665; //Potencia de la señal de referencia
Javier117 8:3b30027c7e8f 93 //const int coord[4][2] = {{0, 6}, {6, 6}, {0, 0}, {6, 0}}; //Coordenadas de dos beacons
Javier117 8:3b30027c7e8f 94 const float coord[4][2] = {{0.55, 5}, {7.95, 5}, {7.95, 0.68}, {0.65, 0.68}}; //Coordenadas de dos beacons
Javier117 8:3b30027c7e8f 95 //const int coord[2][2] = {{0, 6}, {6, 6}}; //Coordenadas de dos beacons
Javier117 8:3b30027c7e8f 96 const int k = 1; //Grado de estimación
Javier117 8:3b30027c7e8f 97 const int n = 4; //Índice de pérdidas por trayectoria
Javier117 8:3b30027c7e8f 98 const int nBeacons = 4; //Número de beacons
Javier117 8:3b30027c7e8f 99 float d[nMax];
Javier117 8:3b30027c7e8f 100 float w[nMax];
Javier117 8:3b30027c7e8f 101
Javier117 8:3b30027c7e8f 102 int8_t rssi[nMax];
Javier117 8:3b30027c7e8f 103 int8_t dir[nMax];
Javier117 8:3b30027c7e8f 104 int8_t addr[nMax];
Javier117 8:3b30027c7e8f 105 int8_t dirAux[nMax];
Javier117 8:3b30027c7e8f 106 int8_t rssiRcv[4] = {0};
Javier117 8:3b30027c7e8f 107 uint8_t i = 0;
Javier117 8:3b30027c7e8f 108 uint16_t cPqt = 1;
Javier117 8:3b30027c7e8f 109
Javier117 8:3b30027c7e8f 110 //Declaración de funciones
Javier117 8:3b30027c7e8f 111 void printData();
Javier117 8:3b30027c7e8f 112 void getCoord (float weigth[], int c);
rgrover1 0:332983584a9c 113
rgrover1 0:332983584a9c 114 void periodicCallback(void)
rgrover1 0:332983584a9c 115 {
rgrover1 0:332983584a9c 116 led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
rgrover1 0:332983584a9c 117 }
rgrover1 0:332983584a9c 118
Javier117 8:3b30027c7e8f 119 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
Javier117 8:3b30027c7e8f 120 {
Javier117 8:3b30027c7e8f 121 if ((params->peerAddr[0] == 0x82 && params->peerAddr[5] == 0x68 && i<=nMax) || (params->peerAddr[0] == 0x02 && params->peerAddr[5] == 0xb0 && i<=nMax) || (params->peerAddr[0] == 0x01 && params->peerAddr[5] == 0xc4 && i<=nMax) || (params->peerAddr[0] == 0x82 && params->peerAddr[5] == 0xb0 && i<=nMax)) {
Javier117 8:3b30027c7e8f 122 dir[i] = params->peerAddr[0];
Javier117 8:3b30027c7e8f 123 dirAux[i] = params->peerAddr[5];
Javier117 8:3b30027c7e8f 124 rssi[i] = params->rssi;
Javier117 8:3b30027c7e8f 125 //printf("Dir: [%d][%d], Iter: %d\r\n", dir[i], dirAux, i);
Javier117 8:3b30027c7e8f 126 i++;
Javier117 8:3b30027c7e8f 127
Javier117 8:3b30027c7e8f 128 if (i==nMax) {
Javier117 8:3b30027c7e8f 129 for (int j = 0; j < nMax; j++) {
Javier117 8:3b30027c7e8f 130 if (dir[j] == -126 && dirAux[j] == -80) {
Javier117 8:3b30027c7e8f 131 addr[j] = 4;
Javier117 8:3b30027c7e8f 132 rssiRcv[3] = rssi[j];
Javier117 8:3b30027c7e8f 133 } else if (dir[j] == 0x01) {
Javier117 8:3b30027c7e8f 134 addr[j] = 1;
Javier117 8:3b30027c7e8f 135 rssiRcv[0] = rssi[j];
Javier117 8:3b30027c7e8f 136 } else if (dir[j] == 0x02) {
Javier117 8:3b30027c7e8f 137 addr[j] = 3;
Javier117 8:3b30027c7e8f 138 rssiRcv[2] = rssi[j];
Javier117 8:3b30027c7e8f 139 } else if (dir[j] == -126 && dirAux[j] == 104) {
Javier117 8:3b30027c7e8f 140 addr[j] = 2;
Javier117 8:3b30027c7e8f 141 rssiRcv[1] = rssi[j];
Javier117 8:3b30027c7e8f 142 }
Javier117 8:3b30027c7e8f 143 //printf("Dir: %02x RSSI: %d\r\n", addr[j], rssi[j]);
Javier117 8:3b30027c7e8f 144 }
rgrover1 3:50a7d47912b2 145
Javier117 8:3b30027c7e8f 146 i=0;
Javier117 8:3b30027c7e8f 147 for (int u = 0; u < nBeacons; u++) {
Javier117 8:3b30027c7e8f 148 //printf("RSSI: %d\r\n", rssiRcv[u]);
Javier117 8:3b30027c7e8f 149 w[u] = 0;
Javier117 8:3b30027c7e8f 150 if (rssiRcv[u] != 0) {
Javier117 8:3b30027c7e8f 151 //c++;
Javier117 8:3b30027c7e8f 152 switch (u) {
Javier117 8:3b30027c7e8f 153 case 0: // 82
Javier117 8:3b30027c7e8f 154 d[0] = dZero*pow((float)10, ((pdBZero-rssiRcv[0])/(10*n)));
Javier117 8:3b30027c7e8f 155 w[0] = pow(d[0], (float)(k*-1));
Javier117 8:3b30027c7e8f 156 //printf("BLE 1, RSSI: %d, d: %f, w: %f\r\n", rssiRcv[0], d[0], w[0]);
Javier117 8:3b30027c7e8f 157 break;
Javier117 8:3b30027c7e8f 158 case 1: // 1
Javier117 8:3b30027c7e8f 159 d[1] = dZero*pow((float)10, ((pdBZero-rssiRcv[1])/(10*n)));
Javier117 8:3b30027c7e8f 160 w[1] = pow(d[1], (float)(k*-1));
Javier117 8:3b30027c7e8f 161 //printf("BLE 2, RSSI: %d, d: %f, w: %f\r\n", rssiRcv[1], d[1], w[1]);
Javier117 8:3b30027c7e8f 162 break;
Javier117 8:3b30027c7e8f 163 case 2: //2
Javier117 8:3b30027c7e8f 164 d[2] = dZero*pow((float)10, ((pdBZero-rssiRcv[2])/(10*n)));
Javier117 8:3b30027c7e8f 165 w[2] = pow(d[2], (float)(k*-1));
Javier117 8:3b30027c7e8f 166 //printf("BLE 3, RSSI: %d, d: %f, w: %f\r\n", rssiRcv[2], d[2], w[2]);
Javier117 8:3b30027c7e8f 167 break;
Javier117 8:3b30027c7e8f 168 case 3: //68
Javier117 8:3b30027c7e8f 169 d[3] = dZero*pow((float)10, ((pdBZero-rssiRcv[3])/(10*n)));
Javier117 8:3b30027c7e8f 170 w[3] = pow(d[3], (float)(k*-1));
Javier117 8:3b30027c7e8f 171 //printf("BLE 4, RSSI: %d, d: %f, w: %f\r\n", rssiRcv[3], d[3], w[3]);
Javier117 8:3b30027c7e8f 172 break;
Javier117 8:3b30027c7e8f 173 }
Javier117 8:3b30027c7e8f 174 }
Javier117 8:3b30027c7e8f 175
Javier117 8:3b30027c7e8f 176 rssiRcv[u] = 0;
Javier117 8:3b30027c7e8f 177 }
Javier117 8:3b30027c7e8f 178
Javier117 8:3b30027c7e8f 179 getCoord(w, 4);
Javier117 8:3b30027c7e8f 180 }
rgrover1 0:332983584a9c 181 }
rgrover1 0:332983584a9c 182 }
rgrover1 0:332983584a9c 183
Javier117 8:3b30027c7e8f 184 /*
Javier117 8:3b30027c7e8f 185
Javier117 8:3b30027c7e8f 186 #if DUMP_ADV_DATA
Javier117 8:3b30027c7e8f 187 for (unsigned index = 0; index < params->advertisingDataLen; index++) {
Javier117 8:3b30027c7e8f 188 printf("%02x ", params->advertisingData[index]);
Javier117 8:3b30027c7e8f 189 }
Javier117 8:3b30027c7e8f 190 printf("\r\n");
Javier117 8:3b30027c7e8f 191 #endif */ /* DUMP_ADV_DATA */
Javier117 8:3b30027c7e8f 192
Javier117 8:3b30027c7e8f 193 /*
Javier117 8:3b30027c7e8f 194 Weighted Centroid Localization (WCL) Algorithm
Javier117 8:3b30027c7e8f 195 */
Javier117 8:3b30027c7e8f 196 void getCoord (float weigth[], int d)
Javier117 8:3b30027c7e8f 197 {
Javier117 8:3b30027c7e8f 198 int i, j;
Javier117 8:3b30027c7e8f 199 float nCoord[4][2] = {0};
Javier117 8:3b30027c7e8f 200 float c[2] = {0};
Javier117 8:3b30027c7e8f 201 float wAuxSum = 0;
Javier117 8:3b30027c7e8f 202 State = TX;
Javier117 8:3b30027c7e8f 203 for (i=0; i<4; i++)
Javier117 8:3b30027c7e8f 204 {
Javier117 8:3b30027c7e8f 205 wAuxSum += weigth[i];
Javier117 8:3b30027c7e8f 206 for (j=0; j<2; j++) {
Javier117 8:3b30027c7e8f 207 nCoord[i][j] = weigth[i]*coord[i][j];
Javier117 8:3b30027c7e8f 208 }
Javier117 8:3b30027c7e8f 209 }
Javier117 8:3b30027c7e8f 210
Javier117 8:3b30027c7e8f 211 for (i=0; i<2; i++) {
Javier117 8:3b30027c7e8f 212 for (j=0; j<4; j++)
Javier117 8:3b30027c7e8f 213 c[i] += nCoord[j][i]/wAuxSum;
Javier117 8:3b30027c7e8f 214 }
Javier117 8:3b30027c7e8f 215
Javier117 8:3b30027c7e8f 216 printf("Coordenadas: (%f, %f)\r\n", c[0], c[1]);
Javier117 8:3b30027c7e8f 217 sprintf((char*) Buffer, "Coordenadas: (%f, %f) No.%d", c[0], c[1], cPqt);
Javier117 8:3b30027c7e8f 218 cPqt++;
Javier117 8:3b30027c7e8f 219 Radio.Send( Buffer, BufferSize );
Javier117 8:3b30027c7e8f 220 State = LOWPOWER;
Javier117 8:3b30027c7e8f 221 }
Javier117 8:3b30027c7e8f 222
Javier117 8:3b30027c7e8f 223
Javier117 8:3b30027c7e8f 224
andresag 7:88f50499af9a 225 /**
andresag 7:88f50499af9a 226 * This function is called when the ble initialization process has failed
andresag 7:88f50499af9a 227 */
andresag 7:88f50499af9a 228 void onBleInitError(BLE &ble, ble_error_t error)
andresag 7:88f50499af9a 229 {
andresag 7:88f50499af9a 230 /* Initialization error handling should go here */
andresag 7:88f50499af9a 231 }
andresag 7:88f50499af9a 232
andresag 7:88f50499af9a 233 /**
andresag 7:88f50499af9a 234 * Callback triggered when the ble initialization process has finished
andresag 7:88f50499af9a 235 */
andresag 7:88f50499af9a 236 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
andresag 7:88f50499af9a 237 {
andresag 7:88f50499af9a 238 BLE& ble = params->ble;
andresag 7:88f50499af9a 239 ble_error_t error = params->error;
andresag 7:88f50499af9a 240
andresag 7:88f50499af9a 241 if (error != BLE_ERROR_NONE) {
andresag 7:88f50499af9a 242 /* In case of error, forward the error handling to onBleInitError */
andresag 7:88f50499af9a 243 onBleInitError(ble, error);
andresag 7:88f50499af9a 244 return;
andresag 7:88f50499af9a 245 }
andresag 7:88f50499af9a 246
andresag 7:88f50499af9a 247 /* Ensure that it is the default instance of BLE */
andresag 7:88f50499af9a 248 if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
andresag 7:88f50499af9a 249 return;
andresag 7:88f50499af9a 250 }
Javier117 8:3b30027c7e8f 251
Javier117 8:3b30027c7e8f 252 ble.gap().setScanParams(200 /* scan interval */, 200 /* scan window */);
andresag 7:88f50499af9a 253 ble.gap().startScan(advertisementCallback);
andresag 7:88f50499af9a 254 }
andresag 7:88f50499af9a 255
rgrover1 0:332983584a9c 256 int main(void)
rgrover1 0:332983584a9c 257 {
Javier117 8:3b30027c7e8f 258 // Configuración del radio LoRa
Javier117 8:3b30027c7e8f 259 bool isMaster = true;
Javier117 8:3b30027c7e8f 260 // Initialize Radio driver
Javier117 8:3b30027c7e8f 261 RadioEvents.TxDone = OnTxDone;
Javier117 8:3b30027c7e8f 262 RadioEvents.RxDone = OnRxDone;
Javier117 8:3b30027c7e8f 263 RadioEvents.RxError = OnRxError;
Javier117 8:3b30027c7e8f 264 RadioEvents.TxTimeout = OnTxTimeout;
Javier117 8:3b30027c7e8f 265 RadioEvents.RxTimeout = OnRxTimeout;
Javier117 8:3b30027c7e8f 266 RadioEvents.FhssChangeChannel = OnFhssChangeChannel;
Javier117 8:3b30027c7e8f 267 Radio.Init( &RadioEvents );
rgrover1 0:332983584a9c 268 ticker.attach(periodicCallback, 1);
rgrover1 0:332983584a9c 269
Javier117 8:3b30027c7e8f 270 Radio.SetChannel( HoppingFrequencies[0] );
Javier117 8:3b30027c7e8f 271
Javier117 8:3b30027c7e8f 272 Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
Javier117 8:3b30027c7e8f 273 LORA_SPREADING_FACTOR, LORA_CODINGRATE,
Javier117 8:3b30027c7e8f 274 LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
Javier117 8:3b30027c7e8f 275 LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
Javier117 8:3b30027c7e8f 276 LORA_IQ_INVERSION_ON, 4000000 );
Javier117 8:3b30027c7e8f 277
Javier117 8:3b30027c7e8f 278 Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
Javier117 8:3b30027c7e8f 279 LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
Javier117 8:3b30027c7e8f 280 LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
Javier117 8:3b30027c7e8f 281 LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
Javier117 8:3b30027c7e8f 282 LORA_IQ_INVERSION_ON, true );
Javier117 8:3b30027c7e8f 283
andresag 7:88f50499af9a 284 BLE &ble = BLE::Instance();
andresag 7:88f50499af9a 285 ble.init(bleInitComplete);
rgrover1 0:332983584a9c 286
Javier117 8:3b30027c7e8f 287 pc.baud(9600);
Javier117 8:3b30027c7e8f 288 printf("Iniciando BLE Observer\r\n");
Javier117 8:3b30027c7e8f 289
Javier117 8:3b30027c7e8f 290 //Transmisión de prueba LOL
Javier117 8:3b30027c7e8f 291 const uint8_t PingMsg[] = "TxRx";
Javier117 8:3b30027c7e8f 292 strcpy( ( char* )Buffer, ( char* )PingMsg );
Javier117 8:3b30027c7e8f 293 Radio.Send( Buffer, BufferSize );
Javier117 8:3b30027c7e8f 294
Javier117 8:3b30027c7e8f 295 wait(15);
Javier117 8:3b30027c7e8f 296
rgrover1 0:332983584a9c 297 while (true) {
rgrover1 0:332983584a9c 298 ble.waitForEvent();
rgrover1 0:332983584a9c 299 }
rgrover1 0:332983584a9c 300 }
Javier117 8:3b30027c7e8f 301
Javier117 8:3b30027c7e8f 302
Javier117 8:3b30027c7e8f 303 void OnTxDone( void )
Javier117 8:3b30027c7e8f 304 {
Javier117 8:3b30027c7e8f 305 Radio.SetChannel( HoppingFrequencies[0] );
Javier117 8:3b30027c7e8f 306 Radio.Sleep( );
Javier117 8:3b30027c7e8f 307 State = TX;
Javier117 8:3b30027c7e8f 308 //debug_if( DEBUG_MESSAGE, "> OnTxDone\n\r" );
Javier117 8:3b30027c7e8f 309 }
Javier117 8:3b30027c7e8f 310
Javier117 8:3b30027c7e8f 311 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
Javier117 8:3b30027c7e8f 312 {
Javier117 8:3b30027c7e8f 313 Radio.SetChannel( HoppingFrequencies[0] );
Javier117 8:3b30027c7e8f 314 Radio.Sleep( );
Javier117 8:3b30027c7e8f 315 BufferSize = size;
Javier117 8:3b30027c7e8f 316 memcpy( Buffer, payload, BufferSize );
Javier117 8:3b30027c7e8f 317 RssiValue = rssi;
Javier117 8:3b30027c7e8f 318 SnrValue = snr;
Javier117 8:3b30027c7e8f 319 State = RX;
Javier117 8:3b30027c7e8f 320 //debug_if( DEBUG_MESSAGE, "> OnRxDone\n\r" );
Javier117 8:3b30027c7e8f 321 }
Javier117 8:3b30027c7e8f 322
Javier117 8:3b30027c7e8f 323 void OnTxTimeout( void )
Javier117 8:3b30027c7e8f 324 {
Javier117 8:3b30027c7e8f 325 Radio.SetChannel( HoppingFrequencies[0] );
Javier117 8:3b30027c7e8f 326 Radio.Sleep( );
Javier117 8:3b30027c7e8f 327 State = TX_TIMEOUT;
Javier117 8:3b30027c7e8f 328 //debug_if( DEBUG_MESSAGE, "> OnTxTimeout\n\r" );
Javier117 8:3b30027c7e8f 329 }
Javier117 8:3b30027c7e8f 330
Javier117 8:3b30027c7e8f 331 void OnRxTimeout( void )
Javier117 8:3b30027c7e8f 332 {
Javier117 8:3b30027c7e8f 333 Radio.SetChannel( HoppingFrequencies[0] );
Javier117 8:3b30027c7e8f 334 Radio.Sleep( );
Javier117 8:3b30027c7e8f 335 Buffer[ BufferSize ] = 0;
Javier117 8:3b30027c7e8f 336 State = RX_TIMEOUT;
Javier117 8:3b30027c7e8f 337 //debug_if( DEBUG_MESSAGE, "> OnRxTimeout\n\r" );
Javier117 8:3b30027c7e8f 338 }
Javier117 8:3b30027c7e8f 339
Javier117 8:3b30027c7e8f 340 void OnRxError( void )
Javier117 8:3b30027c7e8f 341 {
Javier117 8:3b30027c7e8f 342 Radio.SetChannel( HoppingFrequencies[0] );
Javier117 8:3b30027c7e8f 343 Radio.Sleep( );
Javier117 8:3b30027c7e8f 344 State = RX_ERROR;
Javier117 8:3b30027c7e8f 345 //debug_if( DEBUG_MESSAGE, "> OnRxError\n\r" );
Javier117 8:3b30027c7e8f 346 }
Javier117 8:3b30027c7e8f 347
Javier117 8:3b30027c7e8f 348 void OnFhssChangeChannel( uint8_t channelIndex )
Javier117 8:3b30027c7e8f 349 {
Javier117 8:3b30027c7e8f 350 Radio.SetChannel( HoppingFrequencies[channelIndex] );
Javier117 8:3b30027c7e8f 351 //debug_if( DEBUG_MESSAGE, "F%d-", channelIndex);
Javier117 8:3b30027c7e8f 352 }