Version FC

Dependencies:   DmTftLibrary eeprom SX1280Lib filesystem mbed

Fork of MSNV2-Terminal_V1-5 by Francis CHATAIN

Committer:
FCH_31
Date:
Tue Aug 15 17:01:32 2017 +0000
Revision:
6:784bb5247f0b
Parent:
5:aa8a8d1a5aa7
Child:
7:1d890cab51bd
<<Version 1.0>>     IOT-1  :  Temp + Hum    IOT-2 : Temp + Press; Trame ASCII ; 1C : IdTerminal; 1C : IdGateway ; 5c : Value Float ; 5c : Value Float ; ; Emet si changement d'?tat.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregCr 1:22e02d1cfbca 1 #include "mbed.h"
GregCr 1:22e02d1cfbca 2 #include "radio.h"
GregCr 1:22e02d1cfbca 3 #include "sx1280-hal.h"
FCH_31 3:3adb454ba1d2 4 #include "stdio.h"
FCH_31 4:41a92fbf702a 5 #include "XNucleoIKS01A2.h"
GregCr 1:22e02d1cfbca 6
FCH_31 4:41a92fbf702a 7 #define FIRMWARE_VERSION ( ( char* )"Firmware Version: 0.1" ) // display firmware version on RS232
FCH_31 2:57f098de07c7 8 #define MODE_LORA // Lora modulation
FCH_31 2:57f098de07c7 9 #define RF_FREQUENCY 2400000000UL // HzNominal frequency
FCH_31 4:41a92fbf702a 10 #define TX_OUTPUT_POWER -18 // Output power in dBm [-18..+13] dBm
GregCr 1:22e02d1cfbca 11
FCH_31 2:57f098de07c7 12 typedef enum // States of the application
GregCr 1:22e02d1cfbca 13 {
GregCr 1:22e02d1cfbca 14 APP_LOWPOWER,
GregCr 1:22e02d1cfbca 15 APP_RX,
GregCr 1:22e02d1cfbca 16 APP_RX_TIMEOUT,
GregCr 1:22e02d1cfbca 17 APP_RX_ERROR,
GregCr 1:22e02d1cfbca 18 APP_TX,
GregCr 1:22e02d1cfbca 19 APP_TX_TIMEOUT,
GregCr 1:22e02d1cfbca 20 }AppStates_t;
GregCr 1:22e02d1cfbca 21
FCH_31 6:784bb5247f0b 22 #define ID_TERMINAL1 '1'
FCH_31 5:aa8a8d1a5aa7 23 #define ID_TERMINAL2 '2'
FCH_31 5:aa8a8d1a5aa7 24 #define ID_GATEWAY '1'
FCH_31 3:3adb454ba1d2 25
FCH_31 3:3adb454ba1d2 26 float temperature = 0.0 ;
FCH_31 3:3adb454ba1d2 27 float humidite = 0.0 ;
FCH_31 3:3adb454ba1d2 28
GregCr 1:22e02d1cfbca 29
FCH_31 3:3adb454ba1d2 30 #define MESSAGESIZE 34 // Defines the size of the token defining message type in the payload
FCH_31 3:3adb454ba1d2 31 char Message[MESSAGESIZE] = "MSG DATA IOT TERMINAL";
GregCr 1:22e02d1cfbca 32
FCH_31 3:3adb454ba1d2 33 int cptr = 0 ;
GregCr 1:22e02d1cfbca 34
FCH_31 3:3adb454ba1d2 35 #define BUFFER_SIZE 34 // Payload size
FCH_31 3:3adb454ba1d2 36 uint8_t BufferSize = BUFFER_SIZE; // Size of the buffer
FCH_31 2:57f098de07c7 37 uint8_t Buffer[BUFFER_SIZE]; // Buffer
GregCr 1:22e02d1cfbca 38
FCH_31 2:57f098de07c7 39 AppStates_t AppState = APP_LOWPOWER; // State of the application
GregCr 1:22e02d1cfbca 40
FCH_31 3:3adb454ba1d2 41 int8_t RssiValue = 0;
FCH_31 3:3adb454ba1d2 42 int8_t SnrValue = 0;
GregCr 1:22e02d1cfbca 43
FCH_31 2:57f098de07c7 44 void OnTxDone ( void ); // Function to be executed on Radio Tx Done event
FCH_31 2:57f098de07c7 45 void OnRxDone ( void ); // Function to be executed on Radio Rx Done event
FCH_31 2:57f098de07c7 46 void OnTxTimeout ( void ); // Function executed on Radio Tx Timeout event
FCH_31 2:57f098de07c7 47 void OnRxTimeout ( void ); // Function executed on Radio Rx Timeout event
FCH_31 2:57f098de07c7 48 void OnRxError ( IrqErrorCode_t ); // Function executed on Radio Rx Error event
GregCr 1:22e02d1cfbca 49
FCH_31 2:57f098de07c7 50 RadioCallbacks_t callbacks = // All the callbacks are stored in a structure
GregCr 1:22e02d1cfbca 51 {
GregCr 1:22e02d1cfbca 52 &OnTxDone, // txDone
GregCr 1:22e02d1cfbca 53 &OnRxDone, // rxDone
GregCr 1:22e02d1cfbca 54 NULL, // syncWordDone
GregCr 1:22e02d1cfbca 55 NULL, // headerDone
GregCr 1:22e02d1cfbca 56 &OnTxTimeout, // txTimeout
GregCr 1:22e02d1cfbca 57 &OnRxTimeout, // rxTimeout
GregCr 1:22e02d1cfbca 58 &OnRxError, // rxError
GregCr 1:22e02d1cfbca 59 NULL, // rangingDone
GregCr 1:22e02d1cfbca 60 NULL, // cadDone
GregCr 1:22e02d1cfbca 61 };
GregCr 1:22e02d1cfbca 62
FCH_31 2:57f098de07c7 63 // mosi, miso, sclk, nss, busy, dio1, dio2, dio3, rst, callbacks...
FCH_31 2:57f098de07c7 64 SX1280Hal Radio ( D11 , D12 , D13 , D7 , D3 , D5 , NC , NC , A0 , &callbacks );
GregCr 1:22e02d1cfbca 65
FCH_31 3:3adb454ba1d2 66 DigitalOut ANT_SW ( A3 ) ;
FCH_31 3:3adb454ba1d2 67 DigitalOut TxLed ( A4 ) ;
FCH_31 3:3adb454ba1d2 68 DigitalOut RxLed ( A5 ) ;
FCH_31 3:3adb454ba1d2 69 DigitalOut F_CS ( D6 ) ; // MBED description of pin
FCH_31 3:3adb454ba1d2 70 DigitalOut SD_CS ( D8 ) ; // MBED description of pin
GregCr 1:22e02d1cfbca 71
FCH_31 2:57f098de07c7 72 #define TX_TIMEOUT_VALUE 100 // ms Number of tick size steps for tx timeout
FCH_31 3:3adb454ba1d2 73 #define RX_TIMEOUT_VALUE 100 // ms Number of tick size steps for rx timeout
FCH_31 2:57f098de07c7 74 #define RX_TIMEOUT_TICK_SIZE RADIO_TICK_SIZE_1000_US // Size of ticks (used for Tx and Rx timeout)
FCH_31 2:57f098de07c7 75
FCH_31 2:57f098de07c7 76 uint16_t RxIrqMask = IRQ_RX_DONE | IRQ_RX_TX_TIMEOUT; // Mask of IRQs to listen to in rx mode
FCH_31 2:57f098de07c7 77 uint16_t TxIrqMask = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT; // Mask of IRQs to listen to in tx mode
FCH_31 2:57f098de07c7 78
FCH_31 2:57f098de07c7 79 PacketParams_t PacketParams; // Locals parameters and status for radio API
FCH_31 2:57f098de07c7 80 PacketStatus_t PacketStatus; // NEED TO BE OPTIMIZED, COPY OF STUCTURE ALREADY EXISTING
GregCr 1:22e02d1cfbca 81
FCH_31 2:57f098de07c7 82 ModulationParams_t modulationParams;
FCH_31 2:57f098de07c7 83
FCH_31 2:57f098de07c7 84
FCH_31 4:41a92fbf702a 85 /* Instantiate the expansion board */
FCH_31 4:41a92fbf702a 86 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
FCH_31 4:41a92fbf702a 87
FCH_31 4:41a92fbf702a 88 /* Retrieve the composing elements of the expansion board */
FCH_31 4:41a92fbf702a 89 static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
FCH_31 4:41a92fbf702a 90 static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
FCH_31 4:41a92fbf702a 91 static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
FCH_31 4:41a92fbf702a 92 static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
FCH_31 4:41a92fbf702a 93 static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
FCH_31 4:41a92fbf702a 94
FCH_31 4:41a92fbf702a 95 uint8_t id1, id2, id3, id4, id5, id6, id7;
FCH_31 4:41a92fbf702a 96 float valueTH1, valueTH2, valueTP1, valueTP2;
FCH_31 5:aa8a8d1a5aa7 97 float OldvalueTH1, OldvalueTH2, OldvalueTP1, OldvalueTP2;
FCH_31 4:41a92fbf702a 98 char buffer1[32], buffer2[32], buffer3[32], buffer4[32];
FCH_31 4:41a92fbf702a 99 int32_t axesA[3], axesM[3], axesG1[3], axesG2[3];
FCH_31 5:aa8a8d1a5aa7 100 int32_t OldaxesA[3], OldaxesM[3], OldaxesG1[3], OldaxesG2[3];
FCH_31 4:41a92fbf702a 101
FCH_31 5:aa8a8d1a5aa7 102 static char *print_double ( char* str, double v, int decimalDigits=2) ;
FCH_31 5:aa8a8d1a5aa7 103 void baud ( int baudrate ) ;
FCH_31 5:aa8a8d1a5aa7 104 void sendRadio ( char TERMINAL, char GATEWAY, float value1, float value2) ;
FCH_31 5:aa8a8d1a5aa7 105
FCH_31 5:aa8a8d1a5aa7 106
FCH_31 2:57f098de07c7 107 void setup () {
FCH_31 3:3adb454ba1d2 108 baud (115200);
FCH_31 2:57f098de07c7 109 printf( "\n\n\r SX1280 Terminal IoT LORA MODULATION 2.4GHz (%s)\n\n\r", FIRMWARE_VERSION );
GregCr 1:22e02d1cfbca 110
FCH_31 2:57f098de07c7 111 F_CS = 1 ;
FCH_31 2:57f098de07c7 112 SD_CS = 1 ;
FCH_31 2:57f098de07c7 113 ANT_SW = 1 ;
GregCr 1:22e02d1cfbca 114
GregCr 1:22e02d1cfbca 115 wait_ms( 500 ); // wait for on board DC/DC start-up time
GregCr 1:22e02d1cfbca 116
FCH_31 2:57f098de07c7 117 Radio.Init ( );
FCH_31 2:57f098de07c7 118 Radio.SetRegulatorMode ( USE_DCDC ); // Can also be set in LDO mode but consume more power
GregCr 1:22e02d1cfbca 119
FCH_31 2:57f098de07c7 120 memset ( &Buffer, 0x00, BufferSize );
FCH_31 2:57f098de07c7 121
FCH_31 2:57f098de07c7 122 RxLed = 0;
FCH_31 2:57f098de07c7 123 TxLed = 0;
FCH_31 2:57f098de07c7 124
FCH_31 2:57f098de07c7 125 modulationParams.PacketType = PACKET_TYPE_LORA ;
FCH_31 2:57f098de07c7 126 modulationParams.Params.LoRa.SpreadingFactor = LORA_SF7 ;
FCH_31 2:57f098de07c7 127 modulationParams.Params.LoRa.Bandwidth = LORA_BW_0400 ;
FCH_31 2:57f098de07c7 128 modulationParams.Params.LoRa.CodingRate = LORA_CR_4_5 ;
GregCr 1:22e02d1cfbca 129
FCH_31 2:57f098de07c7 130 PacketParams.PacketType = PACKET_TYPE_LORA ;
FCH_31 2:57f098de07c7 131 PacketParams.Params.LoRa.PreambleLength = 0x08 ;
FCH_31 2:57f098de07c7 132 PacketParams.Params.LoRa.HeaderType = LORA_PACKET_VARIABLE_LENGTH;
FCH_31 3:3adb454ba1d2 133 PacketParams.Params.LoRa.PayloadLength = 34 ;
FCH_31 3:3adb454ba1d2 134 PacketParams.Params.LoRa.CrcMode = LORA_CRC_ON ;
FCH_31 3:3adb454ba1d2 135 PacketParams.Params.LoRa.InvertIQ = LORA_IQ_INVERTED ;
GregCr 1:22e02d1cfbca 136
FCH_31 2:57f098de07c7 137 Radio.SetStandby ( STDBY_RC );
FCH_31 2:57f098de07c7 138 Radio.SetPacketType ( modulationParams.PacketType );
FCH_31 2:57f098de07c7 139 Radio.SetModulationParams ( &modulationParams );
FCH_31 2:57f098de07c7 140 Radio.SetPacketParams ( &PacketParams );
FCH_31 2:57f098de07c7 141 Radio.SetRfFrequency ( RF_FREQUENCY );
FCH_31 2:57f098de07c7 142 Radio.SetBufferBaseAddresses ( 0x00, 0x00 );
FCH_31 2:57f098de07c7 143 Radio.SetTxParams ( TX_OUTPUT_POWER, RADIO_RAMP_20_US );
FCH_31 2:57f098de07c7 144 Radio.SetDioIrqParams ( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
FCH_31 2:57f098de07c7 145 Radio.SetRx ( ( TickTime_t ) { RX_TIMEOUT_TICK_SIZE, RX_TIMEOUT_VALUE } );
GregCr 1:22e02d1cfbca 146
FCH_31 4:41a92fbf702a 147 AppState = APP_LOWPOWER;
FCH_31 2:57f098de07c7 148
FCH_31 4:41a92fbf702a 149 /* Enable all sensors */
FCH_31 4:41a92fbf702a 150 hum_temp->enable ();
FCH_31 4:41a92fbf702a 151 press_temp->enable ();
FCH_31 4:41a92fbf702a 152 magnetometer->enable ();
FCH_31 4:41a92fbf702a 153 accelerometer->enable ();
FCH_31 4:41a92fbf702a 154 acc_gyro->enable_x ();
FCH_31 4:41a92fbf702a 155 acc_gyro->enable_g ();
FCH_31 4:41a92fbf702a 156
FCH_31 4:41a92fbf702a 157 printf("\r\n--- Starting new run ---\r\n");
FCH_31 4:41a92fbf702a 158
FCH_31 4:41a92fbf702a 159 hum_temp->read_id (&id1);
FCH_31 4:41a92fbf702a 160 printf("HTS221 humidity & temperature = 0x%X\r\n", id1);
FCH_31 4:41a92fbf702a 161 press_temp->read_id (&id2);
FCH_31 4:41a92fbf702a 162 printf("LPS22HB pressure & temperature = 0x%X\r\n", id2);
FCH_31 4:41a92fbf702a 163 magnetometer->read_id (&id3);
FCH_31 4:41a92fbf702a 164 printf("LSM303AGR magnetometer = 0x%X\r\n", id3);
FCH_31 4:41a92fbf702a 165 accelerometer->read_id (&id4);
FCH_31 4:41a92fbf702a 166 printf("LSM303AGR accelerometer = 0x%X\r\n", id4);
FCH_31 4:41a92fbf702a 167 acc_gyro->read_id (&id5);
FCH_31 4:41a92fbf702a 168 printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id5);
FCH_31 4:41a92fbf702a 169
FCH_31 4:41a92fbf702a 170 }
GregCr 1:22e02d1cfbca 171
FCH_31 2:57f098de07c7 172 void loop () {
FCH_31 5:aa8a8d1a5aa7 173
FCH_31 5:aa8a8d1a5aa7 174 TxLed = 0 ;
FCH_31 5:aa8a8d1a5aa7 175 RxLed = 0 ;
FCH_31 5:aa8a8d1a5aa7 176 wait (1) ;
FCH_31 5:aa8a8d1a5aa7 177 F_CS = 1 ;
FCH_31 5:aa8a8d1a5aa7 178 SD_CS = 1 ;
FCH_31 5:aa8a8d1a5aa7 179 ANT_SW = 1 ;
FCH_31 5:aa8a8d1a5aa7 180 wait( 0.5 ); // wait for on board DC/DC start-up time
FCH_31 4:41a92fbf702a 181
FCH_31 4:41a92fbf702a 182 /* Enable all sensors */
FCH_31 4:41a92fbf702a 183 hum_temp->enable ();
FCH_31 4:41a92fbf702a 184 press_temp->enable ();
FCH_31 4:41a92fbf702a 185 magnetometer->enable ();
FCH_31 4:41a92fbf702a 186 accelerometer->enable ();
FCH_31 4:41a92fbf702a 187 acc_gyro->enable_x ();
FCH_31 4:41a92fbf702a 188 acc_gyro->enable_g ();
FCH_31 5:aa8a8d1a5aa7 189 wait(0.5);
FCH_31 4:41a92fbf702a 190
FCH_31 4:41a92fbf702a 191 printf("============================================================== \r\n");
FCH_31 5:aa8a8d1a5aa7 192 hum_temp->get_temperature (&valueTH1) ;
FCH_31 5:aa8a8d1a5aa7 193 hum_temp->get_humidity (&valueTH2) ;
FCH_31 4:41a92fbf702a 194 printf("HTS221 : [temp] %7s C, [hum] %s%%\r\n" , print_double(buffer1, valueTH1), print_double(buffer2, valueTH2));
FCH_31 5:aa8a8d1a5aa7 195 press_temp->get_temperature (&valueTP1) ;
FCH_31 5:aa8a8d1a5aa7 196 press_temp->get_pressure (&valueTP2) ;
FCH_31 4:41a92fbf702a 197 printf("LPS22HB : [temp] %7s C, [press] %s mbar\r\n" , print_double(buffer3, valueTP1), print_double(buffer4, valueTP2));
FCH_31 5:aa8a8d1a5aa7 198 magnetometer->get_m_axes (axesM) ;
FCH_31 4:41a92fbf702a 199 printf("LSM303AGR : [mag/mgauss] %6ld, %6ld, %6ld\r\n", axesM[0], axesM[1], axesM[2]);
FCH_31 5:aa8a8d1a5aa7 200 accelerometer->get_x_axes (axesA) ;
FCH_31 4:41a92fbf702a 201 printf("LSM303AGR : [acc/mg] %6ld, %6ld, %6ld\r\n", axesA[0], axesA[1], axesA[2]);
FCH_31 5:aa8a8d1a5aa7 202 acc_gyro->get_x_axes (axesG1) ;
FCH_31 4:41a92fbf702a 203 printf("LSM6DSL : [acc/mg] %6ld, %6ld, %6ld\r\n", axesG1[0], axesG1[1], axesG1[2]);
FCH_31 5:aa8a8d1a5aa7 204 acc_gyro->get_g_axes (axesG2) ;
FCH_31 4:41a92fbf702a 205 printf("LSM6DSL : [gyro/mdps] %6ld, %6ld, %6ld\r\n", axesG2[0], axesG2[1], axesG2[2]);
FCH_31 4:41a92fbf702a 206 printf("============================================================== \r\n");
FCH_31 4:41a92fbf702a 207
FCH_31 4:41a92fbf702a 208 /* Disable all sensors */
FCH_31 4:41a92fbf702a 209 hum_temp->disable ();
FCH_31 4:41a92fbf702a 210 press_temp->disable ();
FCH_31 4:41a92fbf702a 211 magnetometer->disable ();
FCH_31 4:41a92fbf702a 212 accelerometer->disable ();
FCH_31 4:41a92fbf702a 213 acc_gyro->disable_x ();
FCH_31 4:41a92fbf702a 214 acc_gyro->disable_g ();
FCH_31 4:41a92fbf702a 215
FCH_31 5:aa8a8d1a5aa7 216 if ( abs(OldvalueTH1 - valueTH1) > 0.25F ||
FCH_31 5:aa8a8d1a5aa7 217 abs(OldvalueTH2 - valueTH2) > 0.25F ||
FCH_31 5:aa8a8d1a5aa7 218 abs(OldaxesA[0] - axesA[0]) > 20 ) {
FCH_31 5:aa8a8d1a5aa7 219 OldvalueTH1 = valueTH1 ;
FCH_31 5:aa8a8d1a5aa7 220 OldvalueTH2 = valueTH2 ;
FCH_31 5:aa8a8d1a5aa7 221 OldaxesA[0] = axesA[0] ;
FCH_31 5:aa8a8d1a5aa7 222 sendRadio (ID_TERMINAL1, ID_GATEWAY, valueTH1, valueTH2) ;
FCH_31 5:aa8a8d1a5aa7 223 }
FCH_31 5:aa8a8d1a5aa7 224 if ( abs(OldvalueTP1 - valueTP1) > 0.25F ||
FCH_31 5:aa8a8d1a5aa7 225 abs(OldvalueTP2 - valueTP2) > 0.25F ) {
FCH_31 5:aa8a8d1a5aa7 226 OldvalueTP1 = valueTP1 ;
FCH_31 5:aa8a8d1a5aa7 227 OldvalueTP2 = valueTP2 ;
FCH_31 5:aa8a8d1a5aa7 228 sendRadio (ID_TERMINAL2, ID_GATEWAY, valueTP1, valueTP2) ;
FCH_31 5:aa8a8d1a5aa7 229 }
FCH_31 5:aa8a8d1a5aa7 230
GregCr 1:22e02d1cfbca 231 }
FCH_31 5:aa8a8d1a5aa7 232
GregCr 1:22e02d1cfbca 233
FCH_31 2:57f098de07c7 234 int main( ) { setup () ; while (1) loop () ; }
GregCr 1:22e02d1cfbca 235
FCH_31 3:3adb454ba1d2 236 void OnTxDone ( void ) { /*printf( "*** TERM *** OnTxDone \r\n" ); */ AppState = APP_TX ; }
FCH_31 2:57f098de07c7 237 void OnRxDone ( void ) { printf( "*** TERM *** OnRxDone \r\n" ); AppState = APP_RX ; }
FCH_31 2:57f098de07c7 238 void OnTxTimeout ( void ) { printf( "*** TERM *** OnTxTimeout \r\n" ); AppState = APP_TX_TIMEOUT ; }
FCH_31 2:57f098de07c7 239 void OnRxTimeout ( void ) { printf( "*** TERM *** OnRxTimeout \r\n" ); AppState = APP_RX_TIMEOUT ; }
FCH_31 2:57f098de07c7 240 void OnRxError ( IrqErrorCode_t errorCode ) { printf( "*** TERM *** OnRxError \r\n" ); AppState = APP_RX_ERROR ; }
FCH_31 2:57f098de07c7 241 void OnRangingDone ( IrqRangingCode_t val ) { printf( "*** TERM *** OnRangingDone \r\n" ); }
FCH_31 2:57f098de07c7 242 void OnCadDone ( bool channelActivityDetected ) { printf( "*** TERM *** OnCadDone \r\n" ); }
FCH_31 2:57f098de07c7 243
FCH_31 2:57f098de07c7 244 /*
GregCr 1:22e02d1cfbca 245 Radio.GetPacketStatus(&packetStatus);
GregCr 1:22e02d1cfbca 246 RssiValue = packetStatus.Lr24.RssiPkt;
GregCr 1:22e02d1cfbca 247 SnrValue = packetStatus.Lr24.SnrPkt;
GregCr 1:22e02d1cfbca 248 printf("rssi: %d; snr: %d\n\r", RssiValue, SnrValue );
FCH_31 2:57f098de07c7 249 */
FCH_31 4:41a92fbf702a 250
FCH_31 5:aa8a8d1a5aa7 251 void sendRadio (char TERMINAL, char GATEWAY, float value1, float value2) {
FCH_31 5:aa8a8d1a5aa7 252 TxLed = 1 ;
FCH_31 5:aa8a8d1a5aa7 253 memset ( &Buffer , 0x00, BufferSize );
FCH_31 5:aa8a8d1a5aa7 254 memset ( &Message, 0x00, BufferSize );
FCH_31 5:aa8a8d1a5aa7 255 int n = sprintf ( Message, "%c%c%5s%5s",
FCH_31 5:aa8a8d1a5aa7 256 TERMINAL,
FCH_31 5:aa8a8d1a5aa7 257 GATEWAY,
FCH_31 5:aa8a8d1a5aa7 258 print_double(buffer1, value1),
FCH_31 5:aa8a8d1a5aa7 259 print_double(buffer2, value2) );
FCH_31 5:aa8a8d1a5aa7 260 memcpy ( Buffer , Message , MESSAGESIZE );
FCH_31 5:aa8a8d1a5aa7 261 printf ( "*** TERM *** Message = %s \r\n", Buffer );
FCH_31 5:aa8a8d1a5aa7 262 Radio.SetDioIrqParams ( TxIrqMask , TxIrqMask , IRQ_RADIO_NONE, IRQ_RADIO_NONE );
FCH_31 5:aa8a8d1a5aa7 263 Radio.SendPayload ( Buffer , BufferSize,( TickTime_t ){ RX_TIMEOUT_TICK_SIZE, TX_TIMEOUT_VALUE } );
FCH_31 5:aa8a8d1a5aa7 264 TxLed = 0 ;
FCH_31 5:aa8a8d1a5aa7 265 }
FCH_31 5:aa8a8d1a5aa7 266
FCH_31 4:41a92fbf702a 267
FCH_31 4:41a92fbf702a 268
FCH_31 4:41a92fbf702a 269 /* Helper function for printing floats & doubles */
FCH_31 4:41a92fbf702a 270 static char *print_double(char* str, double v, int decimalDigits)
FCH_31 4:41a92fbf702a 271 {
FCH_31 4:41a92fbf702a 272 int i = 1;
FCH_31 4:41a92fbf702a 273 int intPart, fractPart;
FCH_31 4:41a92fbf702a 274 int len;
FCH_31 4:41a92fbf702a 275 char *ptr;
FCH_31 4:41a92fbf702a 276
FCH_31 4:41a92fbf702a 277 /* prepare decimal digits multiplicator */
FCH_31 4:41a92fbf702a 278 for (;decimalDigits!=0; i*=10, decimalDigits--);
FCH_31 4:41a92fbf702a 279
FCH_31 4:41a92fbf702a 280 /* calculate integer & fractinal parts */
FCH_31 4:41a92fbf702a 281 intPart = (int)v;
FCH_31 4:41a92fbf702a 282 fractPart = (int)((v-(double)(int)v)*i);
FCH_31 4:41a92fbf702a 283
FCH_31 4:41a92fbf702a 284 /* fill in integer part */
FCH_31 4:41a92fbf702a 285 sprintf(str, "%i.", intPart);
FCH_31 4:41a92fbf702a 286
FCH_31 4:41a92fbf702a 287 /* prepare fill in of fractional part */
FCH_31 4:41a92fbf702a 288 len = strlen(str);
FCH_31 4:41a92fbf702a 289 ptr = &str[len];
FCH_31 4:41a92fbf702a 290
FCH_31 4:41a92fbf702a 291 /* fill in leading fractional zeros */
FCH_31 4:41a92fbf702a 292 for (i/=10;i>1; i/=10, ptr++) {
FCH_31 4:41a92fbf702a 293 if (fractPart >= i) {
FCH_31 4:41a92fbf702a 294 break;
FCH_31 4:41a92fbf702a 295 }
FCH_31 4:41a92fbf702a 296 *ptr = '0';
FCH_31 4:41a92fbf702a 297 }
FCH_31 4:41a92fbf702a 298
FCH_31 4:41a92fbf702a 299 /* fill in (rest of) fractional part */
FCH_31 4:41a92fbf702a 300 sprintf(ptr, "%i", fractPart);
FCH_31 4:41a92fbf702a 301
FCH_31 4:41a92fbf702a 302 return str;
FCH_31 4:41a92fbf702a 303 }
FCH_31 4:41a92fbf702a 304
FCH_31 4:41a92fbf702a 305
FCH_31 4:41a92fbf702a 306
FCH_31 4:41a92fbf702a 307 /* Specify serial datarate for UART debug output */
FCH_31 4:41a92fbf702a 308 void baud ( int baudrate ) { Serial s( USBTX, USBRX ); s.baud( baudrate );}