RX

Dependencies:   mbed BufferedSerial SX1276GenericLib X_NUCLEO_IKS01A2

Committer:
TMRL123
Date:
Thu Apr 18 13:56:50 2019 +0000
Revision:
0:a73914f20498
Child:
1:bd8b9ad01400
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMRL123 0:a73914f20498 1 /* Includes */
TMRL123 0:a73914f20498 2 #include "mbed.h" /* Mbed include */
TMRL123 0:a73914f20498 3
TMRL123 0:a73914f20498 4 #include "XNucleoIKS01A2.h" /* Sensors include*/
TMRL123 0:a73914f20498 5
TMRL123 0:a73914f20498 6 /* LoRa includes */
TMRL123 0:a73914f20498 7 #include "PinMap.h"
TMRL123 0:a73914f20498 8 #include "sx1276-mbed-hal.h"
TMRL123 0:a73914f20498 9
TMRL123 0:a73914f20498 10 /* LoRa definitions */
TMRL123 0:a73914f20498 11
TMRL123 0:a73914f20498 12 /* Set this flag to '1' to display debug messages on the console */
TMRL123 0:a73914f20498 13 #define DEBUG_MESSAGE 1
TMRL123 0:a73914f20498 14
TMRL123 0:a73914f20498 15 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */
TMRL123 0:a73914f20498 16 #define USE_MODEM_LORA 1
TMRL123 0:a73914f20498 17 #define USE_MODEM_FSK !USE_MODEM_LORA
TMRL123 0:a73914f20498 18 #define RF_FREQUENCY RF_FREQUENCY_915_0 // Hz
TMRL123 0:a73914f20498 19 #define TX_OUTPUT_POWER 14 // 14 dBm
TMRL123 0:a73914f20498 20
TMRL123 0:a73914f20498 21 #if USE_MODEM_LORA == 1
TMRL123 0:a73914f20498 22
TMRL123 0:a73914f20498 23 #define LORA_BANDWIDTH 125000 // LoRa default, details in SX1276::BandwidthMap
TMRL123 0:a73914f20498 24 #define LORA_SPREADING_FACTOR LORA_SF7
TMRL123 0:a73914f20498 25 #define LORA_CODINGRATE LORA_ERROR_CODING_RATE_4_5
TMRL123 0:a73914f20498 26
TMRL123 0:a73914f20498 27 #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
TMRL123 0:a73914f20498 28 #define LORA_SYMBOL_TIMEOUT 5 // Symbols
TMRL123 0:a73914f20498 29 #define LORA_FIX_LENGTH_PAYLOAD_ON false
TMRL123 0:a73914f20498 30 #define LORA_FHSS_ENABLED false
TMRL123 0:a73914f20498 31 #define LORA_NB_SYMB_HOP 4
TMRL123 0:a73914f20498 32 #define LORA_IQ_INVERSION_ON false
TMRL123 0:a73914f20498 33 #define LORA_CRC_ENABLED true
TMRL123 0:a73914f20498 34
TMRL123 0:a73914f20498 35 #endif
TMRL123 0:a73914f20498 36
TMRL123 0:a73914f20498 37
TMRL123 0:a73914f20498 38 #define RX_TIMEOUT_VALUE 3500 // in ms
TMRL123 0:a73914f20498 39
TMRL123 0:a73914f20498 40 //#define BUFFER_SIZE 32 // Define the payload size here
TMRL123 0:a73914f20498 41 #define BUFFER_SIZE 512 // Define the payload size here
TMRL123 0:a73914f20498 42
TMRL123 0:a73914f20498 43 /* Sensors instances */
TMRL123 0:a73914f20498 44
TMRL123 0:a73914f20498 45 /* Instantiate the expansion board */
TMRL123 0:a73914f20498 46 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
TMRL123 0:a73914f20498 47
TMRL123 0:a73914f20498 48 /* Retrieve the composing elements of the expansion board */
TMRL123 0:a73914f20498 49 static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
TMRL123 0:a73914f20498 50 static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
TMRL123 0:a73914f20498 51 static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
TMRL123 0:a73914f20498 52 static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
TMRL123 0:a73914f20498 53 static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
TMRL123 0:a73914f20498 54
TMRL123 0:a73914f20498 55 char buffer1[32], buffer2[32]; // buffers to help theprinting of doubles
TMRL123 0:a73914f20498 56
TMRL123 0:a73914f20498 57 uint32_t dados[16]; //data vector
TMRL123 0:a73914f20498 58
TMRL123 0:a73914f20498 59 /* LoRa modem instances and configurations */
TMRL123 0:a73914f20498 60
TMRL123 0:a73914f20498 61 static RadioEvents_t RadioEvents; // Calback functions struct
TMRL123 0:a73914f20498 62
TMRL123 0:a73914f20498 63 SX1276Generic *Radio; //Defenition of a Radio object
TMRL123 0:a73914f20498 64
TMRL123 0:a73914f20498 65 /*Configuration function*/
TMRL123 0:a73914f20498 66 void SystemClock_Config(void);
TMRL123 0:a73914f20498 67
TMRL123 0:a73914f20498 68 bool transmited = true;
TMRL123 0:a73914f20498 69
TMRL123 0:a73914f20498 70 /* Callback functions prototypes */
TMRL123 0:a73914f20498 71 void OnTxDone(void *radio, void *userThisPtr, void *userData);
TMRL123 0:a73914f20498 72
TMRL123 0:a73914f20498 73 void OnRxDone(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
TMRL123 0:a73914f20498 74
TMRL123 0:a73914f20498 75 void OnTxTimeout(void *radio, void *userThisPtr, void *userData);
TMRL123 0:a73914f20498 76
TMRL123 0:a73914f20498 77 void OnRxTimeout(void *radio, void *userThisPtr, void *userData);
TMRL123 0:a73914f20498 78
TMRL123 0:a73914f20498 79 void OnRxError(void *radio, void *userThisPtr, void *userData);
TMRL123 0:a73914f20498 80
TMRL123 0:a73914f20498 81 void OnFhssChangeChannel(void *radio, void *userThisPtr, void *userData, uint8_t channelIndex);
TMRL123 0:a73914f20498 82
TMRL123 0:a73914f20498 83 void OnCadDone(void *radio, void *userThisPtr, void *userData);
TMRL123 0:a73914f20498 84
TMRL123 0:a73914f20498 85 /* Serial communication to debug program */
TMRL123 0:a73914f20498 86
TMRL123 0:a73914f20498 87 Serial pc(USBTX,USBRX);
TMRL123 0:a73914f20498 88
TMRL123 0:a73914f20498 89 int main() {
TMRL123 0:a73914f20498 90 /* General Header*/
TMRL123 0:a73914f20498 91
TMRL123 0:a73914f20498 92 pc.printf("Telemetry Tx inicial version program\r\n\r\n");
TMRL123 0:a73914f20498 93
TMRL123 0:a73914f20498 94 uint8_t id; //Sensor id parameter for debug purpose
TMRL123 0:a73914f20498 95
TMRL123 0:a73914f20498 96 /* Enable all sensors */
TMRL123 0:a73914f20498 97 hum_temp->enable();
TMRL123 0:a73914f20498 98 press_temp->enable();
TMRL123 0:a73914f20498 99 magnetometer->enable();
TMRL123 0:a73914f20498 100 accelerometer->enable();
TMRL123 0:a73914f20498 101 acc_gyro->enable_x();
TMRL123 0:a73914f20498 102 acc_gyro->enable_g();
TMRL123 0:a73914f20498 103
TMRL123 0:a73914f20498 104 pc.printf("\r\n--- Starting the sensors ---\r\n");
TMRL123 0:a73914f20498 105
TMRL123 0:a73914f20498 106 hum_temp->read_id(&id);
TMRL123 0:a73914f20498 107 pc.printf("HTS221 humidity & temperature = 0x%X\r\n", id);
TMRL123 0:a73914f20498 108 press_temp->read_id(&id);
TMRL123 0:a73914f20498 109 pc.printf("LPS22HB pressure & temperature = 0x%X\r\n", id);
TMRL123 0:a73914f20498 110 magnetometer->read_id(&id);
TMRL123 0:a73914f20498 111 pc.printf("LSM303AGR magnetometer = 0x%X\r\n", id);
TMRL123 0:a73914f20498 112 accelerometer->read_id(&id);
TMRL123 0:a73914f20498 113 pc.printf("LSM303AGR accelerometer = 0x%X\r\n", id);
TMRL123 0:a73914f20498 114 acc_gyro->read_id(&id);
TMRL123 0:a73914f20498 115 pc.printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id);
TMRL123 0:a73914f20498 116
TMRL123 0:a73914f20498 117 pc.printf("\r\n");
TMRL123 0:a73914f20498 118
TMRL123 0:a73914f20498 119 /* Radio setup */
TMRL123 0:a73914f20498 120 pc.printf("\r\n--- Starting the modem LoRa ---\r\n");
TMRL123 0:a73914f20498 121
TMRL123 0:a73914f20498 122 Radio = new SX1276Generic(NULL, MURATA_SX1276,
TMRL123 0:a73914f20498 123 LORA_SPI_MOSI, LORA_SPI_MISO, LORA_SPI_SCLK, LORA_CS, LORA_RESET,
TMRL123 0:a73914f20498 124 LORA_DIO0, LORA_DIO1, LORA_DIO2, LORA_DIO3, LORA_DIO4, LORA_DIO5,
TMRL123 0:a73914f20498 125 LORA_ANT_RX, LORA_ANT_TX, LORA_ANT_BOOST, LORA_TCXO);
TMRL123 0:a73914f20498 126 pc.printf("SX1276 Simple transmission aplication\r\n" );
TMRL123 0:a73914f20498 127 pc.printf("Frequency: %.1f\r\n", (double)RF_FREQUENCY/1000000.0);
TMRL123 0:a73914f20498 128 pc.printf("TXPower: %d dBm\r\n", TX_OUTPUT_POWER);
TMRL123 0:a73914f20498 129 pc.printf("Bandwidth: %d Hz\r\n", LORA_BANDWIDTH);
TMRL123 0:a73914f20498 130 pc.printf("Spreading factor: SF%d\r\n", LORA_SPREADING_FACTOR);
TMRL123 0:a73914f20498 131
TMRL123 0:a73914f20498 132 // Initialize Radio driver
TMRL123 0:a73914f20498 133 RadioEvents.TxDone = OnTxDone;
TMRL123 0:a73914f20498 134 RadioEvents.RxDone = OnRxDone;
TMRL123 0:a73914f20498 135 RadioEvents.RxError = OnRxError;
TMRL123 0:a73914f20498 136 RadioEvents.TxTimeout = OnTxTimeout;
TMRL123 0:a73914f20498 137 RadioEvents.RxTimeout = OnRxTimeout;
TMRL123 0:a73914f20498 138 while (Radio->Init( &RadioEvents ) == false) {
TMRL123 0:a73914f20498 139 pc.printf("Radio could not be detected!\r\n");
TMRL123 0:a73914f20498 140 wait( 1 );
TMRL123 0:a73914f20498 141 }
TMRL123 0:a73914f20498 142
TMRL123 0:a73914f20498 143 switch(Radio->DetectBoardType()) {
TMRL123 0:a73914f20498 144 case SX1276MB1LAS:
TMRL123 0:a73914f20498 145 if (DEBUG_MESSAGE)
TMRL123 0:a73914f20498 146 pc.printf(" > Board Type: SX1276MB1LAS <\r\n");
TMRL123 0:a73914f20498 147 break;
TMRL123 0:a73914f20498 148 case SX1276MB1MAS:
TMRL123 0:a73914f20498 149 if (DEBUG_MESSAGE)
TMRL123 0:a73914f20498 150 pc.printf(" > Board Type: SX1276MB1LAS <\r\n");
TMRL123 0:a73914f20498 151 case MURATA_SX1276:
TMRL123 0:a73914f20498 152 if (DEBUG_MESSAGE)
TMRL123 0:a73914f20498 153 pc.printf(" > Board Type: MURATA_SX1276_STM32L0 <\r\n");
TMRL123 0:a73914f20498 154 break;
TMRL123 0:a73914f20498 155 case RFM95_SX1276:
TMRL123 0:a73914f20498 156 if (DEBUG_MESSAGE)
TMRL123 0:a73914f20498 157 pc.printf(" > HopeRF RFM95xx <\r\n");
TMRL123 0:a73914f20498 158 break;
TMRL123 0:a73914f20498 159 default:
TMRL123 0:a73914f20498 160 pc.printf(" > Board Type: unknown <\r\n");
TMRL123 0:a73914f20498 161 }
TMRL123 0:a73914f20498 162
TMRL123 0:a73914f20498 163 Radio->SetChannel(RF_FREQUENCY );
TMRL123 0:a73914f20498 164
TMRL123 0:a73914f20498 165 if (LORA_FHSS_ENABLED)
TMRL123 0:a73914f20498 166 pc.printf(" > LORA FHSS Mode <\r\n");
TMRL123 0:a73914f20498 167 if (!LORA_FHSS_ENABLED)
TMRL123 0:a73914f20498 168 pc.printf(" > LORA Mode <\r\n");
TMRL123 0:a73914f20498 169
TMRL123 0:a73914f20498 170 pc.printf("\r\n");
TMRL123 0:a73914f20498 171
TMRL123 0:a73914f20498 172 Radio->SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
TMRL123 0:a73914f20498 173 LORA_SPREADING_FACTOR, LORA_CODINGRATE,
TMRL123 0:a73914f20498 174 LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
TMRL123 0:a73914f20498 175 LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
TMRL123 0:a73914f20498 176 LORA_IQ_INVERSION_ON, 2000 );
TMRL123 0:a73914f20498 177
TMRL123 0:a73914f20498 178 Radio->SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
TMRL123 0:a73914f20498 179 LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
TMRL123 0:a73914f20498 180 LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON, 0,
TMRL123 0:a73914f20498 181 LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP,
TMRL123 0:a73914f20498 182 LORA_IQ_INVERSION_ON, true );
TMRL123 0:a73914f20498 183
TMRL123 0:a73914f20498 184 Radio->Tx(1000000);
TMRL123 0:a73914f20498 185
TMRL123 0:a73914f20498 186 while(1) {
TMRL123 0:a73914f20498 187 float p; //pressure
TMRL123 0:a73914f20498 188 float temperatureHTS221; //temperature from HTS221
TMRL123 0:a73914f20498 189 float humidity; //humidity
TMRL123 0:a73914f20498 190 float temperatureLPS22HB; //temperature from LPS22HB
TMRL123 0:a73914f20498 191 int32_t w[3]; //angular velocity
TMRL123 0:a73914f20498 192 int32_t a[3]; //acceleration of the accelerometer LSM303AGR
TMRL123 0:a73914f20498 193 int32_t ag[3]; //acceleration of the accelerometer and gyroscope LSM6DSL
TMRL123 0:a73914f20498 194 int32_t m [3]; //heading
TMRL123 0:a73914f20498 195
TMRL123 0:a73914f20498 196 press_temp->get_pressure(&p); //get the pressure
TMRL123 0:a73914f20498 197 press_temp->get_temperature(&temperatureLPS22HB); //get temperature from LPS22HB
TMRL123 0:a73914f20498 198 accelerometer->get_x_axes(a);//get the acceleration
TMRL123 0:a73914f20498 199 acc_gyro->get_x_axes(ag);//get the acceleration
TMRL123 0:a73914f20498 200 acc_gyro->get_g_axes(w);//get the angular velocity
TMRL123 0:a73914f20498 201 magnetometer->get_m_axes(m); //get the magnetometer heading
TMRL123 0:a73914f20498 202 hum_temp->get_temperature(&temperatureHTS221); //get temperature from HTS221
TMRL123 0:a73914f20498 203 hum_temp->get_humidity(&humidity); //get humidity
TMRL123 0:a73914f20498 204
TMRL123 0:a73914f20498 205
TMRL123 0:a73914f20498 206 //sensors data
TMRL123 0:a73914f20498 207
TMRL123 0:a73914f20498 208 dados[0] = a[0];
TMRL123 0:a73914f20498 209 dados[1] = a[1];
TMRL123 0:a73914f20498 210 dados[2] = a[2];
TMRL123 0:a73914f20498 211 dados[3] = ag[0];
TMRL123 0:a73914f20498 212 dados[4] = ag[1];
TMRL123 0:a73914f20498 213 dados[5] = ag[2];
TMRL123 0:a73914f20498 214 dados[6] = w[0];
TMRL123 0:a73914f20498 215 dados[7] = w[1];
TMRL123 0:a73914f20498 216 dados[8] = w[2];
TMRL123 0:a73914f20498 217 dados[9] = m[0];
TMRL123 0:a73914f20498 218 dados[10] = m[1];
TMRL123 0:a73914f20498 219 dados[11] = m[2];
TMRL123 0:a73914f20498 220 dados[12] = humidity;
TMRL123 0:a73914f20498 221 dados[13] = temperatureHTS221;
TMRL123 0:a73914f20498 222 dados[14] = temperatureLPS22HB;
TMRL123 0:a73914f20498 223 dados[15] = p;
TMRL123 0:a73914f20498 224
TMRL123 0:a73914f20498 225 if (transmited==true) {
TMRL123 0:a73914f20498 226 transmited = false;
TMRL123 0:a73914f20498 227 wait_ms(10);
TMRL123 0:a73914f20498 228 Radio->Send( dados, sizeof(dados) );
TMRL123 0:a73914f20498 229 }
TMRL123 0:a73914f20498 230 }
TMRL123 0:a73914f20498 231 }
TMRL123 0:a73914f20498 232
TMRL123 0:a73914f20498 233 void SystemClock_Config(void)
TMRL123 0:a73914f20498 234 {
TMRL123 0:a73914f20498 235 #ifdef B_L072Z_LRWAN1_LORA
TMRL123 0:a73914f20498 236 /*
TMRL123 0:a73914f20498 237 * The L072Z_LRWAN1_LORA clock setup is somewhat differnt from the Nucleo board.
TMRL123 0:a73914f20498 238 * It has no LSE.
TMRL123 0:a73914f20498 239 */
TMRL123 0:a73914f20498 240 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
TMRL123 0:a73914f20498 241 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
TMRL123 0:a73914f20498 242
TMRL123 0:a73914f20498 243 /* Enable HSE Oscillator and Activate PLL with HSE as source */
TMRL123 0:a73914f20498 244 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
TMRL123 0:a73914f20498 245 RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
TMRL123 0:a73914f20498 246 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
TMRL123 0:a73914f20498 247 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
TMRL123 0:a73914f20498 248 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
TMRL123 0:a73914f20498 249 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
TMRL123 0:a73914f20498 250 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_6;
TMRL123 0:a73914f20498 251 RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3;
TMRL123 0:a73914f20498 252
TMRL123 0:a73914f20498 253 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
TMRL123 0:a73914f20498 254 // Error_Handler();
TMRL123 0:a73914f20498 255 }
TMRL123 0:a73914f20498 256
TMRL123 0:a73914f20498 257 /* Set Voltage scale1 as MCU will run at 32MHz */
TMRL123 0:a73914f20498 258 __HAL_RCC_PWR_CLK_ENABLE();
TMRL123 0:a73914f20498 259 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
TMRL123 0:a73914f20498 260
TMRL123 0:a73914f20498 261 /* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */
TMRL123 0:a73914f20498 262 while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {};
TMRL123 0:a73914f20498 263
TMRL123 0:a73914f20498 264 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
TMRL123 0:a73914f20498 265 clocks dividers */
TMRL123 0:a73914f20498 266 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
TMRL123 0:a73914f20498 267 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
TMRL123 0:a73914f20498 268 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
TMRL123 0:a73914f20498 269 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
TMRL123 0:a73914f20498 270 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
TMRL123 0:a73914f20498 271 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) {
TMRL123 0:a73914f20498 272 // Error_Handler();
TMRL123 0:a73914f20498 273 }
TMRL123 0:a73914f20498 274 #endif
TMRL123 0:a73914f20498 275 }
TMRL123 0:a73914f20498 276
TMRL123 0:a73914f20498 277 /* Helper function for printing floats & doubles */
TMRL123 0:a73914f20498 278 static char *print_double(char* str, double v, int decimalDigits=2)
TMRL123 0:a73914f20498 279 {
TMRL123 0:a73914f20498 280 int i = 1;
TMRL123 0:a73914f20498 281 int intPart, fractPart;
TMRL123 0:a73914f20498 282 int len;
TMRL123 0:a73914f20498 283 char *ptr;
TMRL123 0:a73914f20498 284
TMRL123 0:a73914f20498 285 /* prepare decimal digits multiplicator */
TMRL123 0:a73914f20498 286 for (;decimalDigits!=0; i*=10, decimalDigits--);
TMRL123 0:a73914f20498 287
TMRL123 0:a73914f20498 288 /* calculate integer & fractinal parts */
TMRL123 0:a73914f20498 289 intPart = (int)v;
TMRL123 0:a73914f20498 290 fractPart = (int)((v-(double)(int)v)*i);
TMRL123 0:a73914f20498 291
TMRL123 0:a73914f20498 292 /* fill in integer part */
TMRL123 0:a73914f20498 293 sprintf(str, "%i.", intPart);
TMRL123 0:a73914f20498 294
TMRL123 0:a73914f20498 295 /* prepare fill in of fractional part */
TMRL123 0:a73914f20498 296 len = strlen(str);
TMRL123 0:a73914f20498 297 ptr = &str[len];
TMRL123 0:a73914f20498 298
TMRL123 0:a73914f20498 299 /* fill in leading fractional zeros */
TMRL123 0:a73914f20498 300 for (i/=10;i>1; i/=10, ptr++) {
TMRL123 0:a73914f20498 301 if (fractPart >= i) {
TMRL123 0:a73914f20498 302 break;
TMRL123 0:a73914f20498 303 }
TMRL123 0:a73914f20498 304 *ptr = '0';
TMRL123 0:a73914f20498 305 }
TMRL123 0:a73914f20498 306
TMRL123 0:a73914f20498 307 /* fill in (rest of) fractional part */
TMRL123 0:a73914f20498 308 sprintf(ptr, "%i", fractPart);
TMRL123 0:a73914f20498 309
TMRL123 0:a73914f20498 310 return str;
TMRL123 0:a73914f20498 311 }
TMRL123 0:a73914f20498 312
TMRL123 0:a73914f20498 313 void OnTxDone(void *radio, void *userThisPtr, void *userData)
TMRL123 0:a73914f20498 314 {
TMRL123 0:a73914f20498 315 Radio->Sleep( );
TMRL123 0:a73914f20498 316 transmited = true;
TMRL123 0:a73914f20498 317 if (DEBUG_MESSAGE) {
TMRL123 0:a73914f20498 318 pc.printf("> OnTxDone\r\n");
TMRL123 0:a73914f20498 319 pc.printf("I transmited %6ld, %6ld, %6ld, %6ld, %6ld, %6ld, %6ld, %6ld, %6ld\r\n", dados[0], dados[1], dados[2], dados[3], dados[4], dados[5], dados[6], dados[7], dados[8]);
TMRL123 0:a73914f20498 320 pc.printf("and %6ld, %6ld, %6ld, %s, %7s, %7s %s\r\n", dados[9], dados[10], dados[11], print_double(buffer2, dados[12]), print_double(buffer1, dados[13]), print_double(buffer1, dados[14]), print_double(buffer2, dados[15]));
TMRL123 0:a73914f20498 321 }
TMRL123 0:a73914f20498 322 }
TMRL123 0:a73914f20498 323
TMRL123 0:a73914f20498 324 void OnRxDone(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
TMRL123 0:a73914f20498 325 {
TMRL123 0:a73914f20498 326 Radio->Sleep( );
TMRL123 0:a73914f20498 327 if (DEBUG_MESSAGE)
TMRL123 0:a73914f20498 328 pc.printf("> OnRxDone: RssiValue=%d dBm, SnrValue=%d\r\n", rssi, snr);
TMRL123 0:a73914f20498 329 }
TMRL123 0:a73914f20498 330
TMRL123 0:a73914f20498 331 void OnTxTimeout(void *radio, void *userThisPtr, void *userData)
TMRL123 0:a73914f20498 332 {
TMRL123 0:a73914f20498 333 Radio->Sleep( );
TMRL123 0:a73914f20498 334 if(DEBUG_MESSAGE)
TMRL123 0:a73914f20498 335 pc.printf("> OnTxTimeout\r\n");
TMRL123 0:a73914f20498 336 }
TMRL123 0:a73914f20498 337
TMRL123 0:a73914f20498 338 void OnRxTimeout(void *radio, void *userThisPtr, void *userData)
TMRL123 0:a73914f20498 339 {
TMRL123 0:a73914f20498 340 Radio->Sleep( );
TMRL123 0:a73914f20498 341 if (DEBUG_MESSAGE)
TMRL123 0:a73914f20498 342 pc.printf("> OnRxTimeout\r\n");
TMRL123 0:a73914f20498 343 }
TMRL123 0:a73914f20498 344
TMRL123 0:a73914f20498 345 void OnRxError(void *radio, void *userThisPtr, void *userData)
TMRL123 0:a73914f20498 346 {
TMRL123 0:a73914f20498 347 Radio->Sleep( );
TMRL123 0:a73914f20498 348 if (DEBUG_MESSAGE)
TMRL123 0:a73914f20498 349 pc.printf("> OnRxError\r\n");
TMRL123 0:a73914f20498 350 }