generated from TDD-Templates/cmake_cpputest_template
Changed C radio source to CPP
This commit is contained in:
parent
2f9fb1202d
commit
cfa740209f
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* Author: username
|
||||
* Date: 2024
|
||||
* filename: Radio.c
|
||||
* description: module_purpose
|
||||
*/
|
||||
|
||||
#include "Radio.h"
|
||||
|
||||
// dumb test function
|
||||
int add_two(int a)
|
||||
{
|
||||
int b = a;
|
||||
b += 2;
|
||||
return b;
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Author: username
|
||||
* Date: 2024
|
||||
* filename: Radio.c
|
||||
* description: module_purpose
|
||||
*/
|
||||
|
||||
#include "Radio.h"
|
||||
|
||||
void Radio_setup(void) {
|
||||
pinMode(RFM95_RST, OUTPUT);
|
||||
digitalWrite(RFM95_RST, HIGH);
|
||||
|
||||
while(!rf95.init()){}
|
||||
Serial.println("radio: Initialized");
|
||||
|
||||
if(rf95.setFrequency(RF95_FREQ)) {
|
||||
Serial.println("radio: Error could not set frequency");
|
||||
while(true){} //Loop forever
|
||||
}
|
||||
Serial.print("radio: Frequency = ");
|
||||
Serial.println(RF95_FREQ);
|
||||
|
||||
rf95.setTxPower(RF95_MIN_DB, false);
|
||||
}
|
||||
|
||||
|
||||
void Radio_reset(void) {
|
||||
digitalWrite(RFM95_RST, LOW);
|
||||
delay(10);
|
||||
digitalWrite(RFM95_RST, HIGH);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
int Radio_SendData() {
|
||||
int8_t tx_power = RF95_MIN_DB;
|
||||
uint8_t received_id = 0;
|
||||
|
||||
//Set the radio output to lowest power.
|
||||
rf95.setTxPower(tx_power, false);
|
||||
|
||||
//Set the radio into TX mode.
|
||||
rf95.setModeTx();
|
||||
|
||||
//Try transmitting data
|
||||
rf95.send(node.id, 1);
|
||||
rf95.waitPacketSent();
|
||||
|
||||
//Wait for ACK or Radio Msg. (Timeout Should be included).
|
||||
//On timeout increase the transmit power and re-attempt.
|
||||
if(!rf95.waitAvailbleTimeout(RF95_TIMEOUT)) {
|
||||
if(rf95.recv(reciver_buffer, RF95_BUF_SZ)) {
|
||||
|
||||
}
|
||||
else {
|
||||
//Failed to receive the message.
|
||||
}
|
||||
}
|
||||
else {
|
||||
//No reply of any kind.
|
||||
}
|
||||
|
||||
//Set the radio mode to idle.
|
||||
rf95.setModeIdle();
|
||||
}
|
||||
|
||||
|
|
@ -9,6 +9,22 @@
|
|||
#define RADIO
|
||||
|
||||
|
||||
int add_two(int a);
|
||||
/**
|
||||
* @brief Preforms radio setup using defined values.
|
||||
*/
|
||||
void Radio_setup(void);
|
||||
|
||||
/**
|
||||
* @brief Resets the radio module.
|
||||
*/
|
||||
void Radio_reset(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sends data to any receiving radios.
|
||||
*/
|
||||
int Radio_SendData();
|
||||
|
||||
|
||||
|
||||
#endif //RADIO
|
||||
|
|
Loading…
Reference in New Issue