
ping pong with modifiable parameters
Revision 6:e155f7cceb5b, committed 2019-06-21
- Comitter:
- nimita23
- Date:
- Fri Jun 21 19:08:11 2019 +0000
- Parent:
- 5:dc53029f4c02
- Child:
- 7:df2f595fda33
- Commit message:
- all values changeable;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jun 20 22:53:28 2019 +0000 +++ b/main.cpp Fri Jun 21 19:08:11 2019 +0000 @@ -4,30 +4,12 @@ #define buffer_size 256 // incoming buffer size #define buffer_fill buffer_size+1 // number, when buffer is ready - - -long unsigned RF_FREQUENCY = 350000000; // Hz -unsigned int spreading_factor = LORA_SF7; -unsigned int bandwidth = LORA_BW_500; - -Serial s( USBTX, USBRX ); -// additional variables for incoming data -char serial_buffer[buffer_size]; // buffer to save incoming data -int serial_buffer_index = 0; // index array for buffer -bool serial_end_line = false; // searching for end line +#define BUFFER_SIZE 16 // payload size +#define PINGPONGSIZE 4 // size of token defining message type in the payload +#define TX_TIMEOUT_VALUE 0xFFFF // ms +#define RX_TIMEOUT_VALUE 0xFFFF // ms - -/*! - * \brief Defines the output power in dBm - * - * \remark The range of the output power is [-18..+13] dBm - */ -#define TX_OUTPUT_POWER 10 - -/*! - * \brief Defines the states of the application - */ -typedef enum +typedef enum //states of the application { APP_LOWPOWER, APP_RX, @@ -37,48 +19,42 @@ APP_TX_TIMEOUT, }AppStates_t; -/*! - * \brief Defines the buffer size, i.e. the payload size - */ -#define BUFFER_SIZE 16 - -/*! - * \brief Define the possible message type for this application - */ const uint8_t PingMsg[] = "PING"; const uint8_t PongMsg[] = "PONG"; -/*! - * \brief Defines the size of the token defining message type in the payload - */ -#define PINGPONGSIZE 4 +long unsigned RF_FREQUENCY = 350000000; // Hz +RadioLoRaSpreadingFactors_t spreading_factor = LORA_SF7; +RadioLoRaBandwidths_t bandwidth = LORA_BW_500; +int TX_OUTPUT_POWER = 10; //The range of the output power is [-18..+13] dBm +bool isMaster = true; + +Serial s( USBTX, USBRX ); // serial object for AT commands +char serial_buffer[buffer_size]; // buffer to save incoming data +int serial_buffer_index = 0; // index array for buffer +bool serial_end_line = false; // searching for end line -/*! - * \brief The size of the buffer - */ uint8_t BufferSize = BUFFER_SIZE; +uint8_t Buffer[BUFFER_SIZE]; -/*! - * \brief The buffer - */ -uint8_t Buffer[BUFFER_SIZE]; +uint16_t RxIrqMask = IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT; +uint16_t TxIrqMask = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT; + +PacketParams_t PacketParams; +PacketStatus_t PacketStatus; + +ModulationParams_t modulationParams; /*! * \brief The State of the application */ AppStates_t AppState = APP_LOWPOWER; - -int8_t RssiValue = 0; -int8_t SnrValue = 0; -ModulationParams_t modulationParams; - void OnTxDone( void ); void OnRxDone( void ); void OnTxTimeout( void ); void OnRxTimeout( void ); void OnRxError( IrqErrorCode_t ); void parser(); -void LoRa_init(ModulationParams_t modulationParams); +void LoRa_init(); RadioCallbacks_t callbacks = { @@ -107,32 +83,6 @@ DigitalOut F_CS( D6 ); // MBED description of pin DigitalOut SD_CS( D8 ); // MBED description of pin -/*! - * \brief Number of tick size steps for tx timeout - */ -#define TX_TIMEOUT_VALUE 0xFFFF // ms - -/*! - * \brief Number of tick size steps for rx timeout - */ -#define RX_TIMEOUT_VALUE 0xFFFF // ms - -/*! - * \brief Mask of IRQs to listen to in rx mode - */ -uint16_t RxIrqMask = IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT; - -/*! - * \brief Mask of IRQs to listen to in tx mode - */ -uint16_t TxIrqMask = IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT; - -/*! - * \brief Locals parameters and status for radio API - */ -PacketParams_t PacketParams; -PacketStatus_t PacketStatus; - void serialRx() { @@ -212,14 +162,13 @@ Radio.SetDioIrqParams( RxIrqMask, RxIrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE ); Radio.SetRx( RX_TIMEOUT_VALUE ); AppState = APP_LOWPOWER; + isMaster = true; Radio.ProcessIrqs( ); } int main( ) { - bool isMaster = true; - baud( 115200 ); F_CS = 1; @@ -371,6 +320,7 @@ } void OnRxDone( void ) { + int RssiValue, SnrValue; AppState = APP_RX; PacketStatus_t packetStatus; Radio.GetPacketStatus(&packetStatus); @@ -400,7 +350,7 @@ void parser() { printf("%s\n\r", serial_buffer); char command[10]; - unsigned long val; + long val; if(sscanf(serial_buffer, "%10s %lu", command, &val) != 2){ printf("Invalid Input\n\r"); return; @@ -409,7 +359,14 @@ if((125000000<=val) && (val<=960000000)) { RF_FREQUENCY = val; printf("Frequency set to: %lu\n\r", val); - LoRa_init(); + LoRa_init(); + } + } + else if(strcmp(command, "TX") == 0) { + if((-22<=val) && (val<=13)) { + TX_OUTPUT_POWER = val; + printf("TX output power set to: %lu\n\r", val); + LoRa_init(); } } else if(strcmp(command, "S_F") == 0) { @@ -443,7 +400,7 @@ return; } printf("Spreading factor changed to %lu\n\r", val); - LoRa.init(); + LoRa_init(); } else if(strcmp(command, "BW") == 0) { switch(val) { @@ -483,7 +440,7 @@ return; } printf("LoRa bandwidth changed to %lu\n\r", val); - LoRa.init(); + LoRa_init(); } else printf("Invalid command\n\r");