Modified the structure for use as message standard, also added some more helper functions.

This commit is contained in:
jakeg00dwin 2024-09-25 13:38:40 -07:00
parent 41afd00ca1
commit 1eee1f09bb
1 changed files with 66 additions and 5 deletions

View File

@ -38,22 +38,31 @@ TinyGPSPlus gps; // TinyGPS++ object to process GPS data
#define RF95_FREQ 915.0 #define RF95_FREQ 915.0
#define RF95_MAX_DB 23 #define RF95_MAX_DB 23
#define RF95_MIN_DB 5 #define RF95_MIN_DB 5
#define RF95_TIMEOUT 250
#define RF95_BUF_SZ 32
RH_RF95 rf95(RFM95_CS, RMF95_INT); // Radio instance. RH_RF95 rf95(RFM95_CS, RMF95_INT); // Radio instance.
typedef struct NodeId{ typedef struct Msg{
uint8_t id; uint8_t id;
String name; double latitude;
}NodeId double longitude;
uint8_t crc;
}Msg;
// Variables // Variables
static int prevHeading = -1; // Store previous heading to avoid frequent updates static int prevHeading = -1; // Store previous heading to avoid frequent updates
unsigned long lastUpdate = 0; // Time tracking for updates unsigned long lastUpdate = 0; // Time tracking for updates
const int updateInterval = 500; // Update interval in milliseconds (500ms = 0.5s) const int updateInterval = 500; // Update interval in milliseconds (500ms = 0.5s)
NodeId node = {
id = 0;
name = "name";
};
uint8_t reciver_buffer[RF95_BUF_SZ];
void radio_setup(void) { void Radio_setup(void) {
pinMode(RFM95_RST, OUTPUT); pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH); digitalWrite(RFM95_RST, HIGH);
@ -70,13 +79,59 @@ void radio_setup(void) {
rf95.setTxPower(RF95_MIN_DB, false); rf95.setTxPower(RF95_MIN_DB, false);
} }
void radio_reset(void) { void Radio_reset(void) {
digitalWrite(RFM95_RST, LOW); digitalWrite(RFM95_RST, LOW);
delay(10); delay(10);
digitalWrite(RFM95_RST, HIGH); digitalWrite(RFM95_RST, HIGH);
delay(10); 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();
}
int Radio_ReceiveData() {
//Set radio into RX mode.
rf95.setModeRx();
//Check if radio has traffic
if()
//Set the radio mode to idle.
rf95.setModeIdle();
}
void setup(void) { void setup(void) {
// Initialize Serial Communication for debugging // Initialize Serial Communication for debugging
Serial.begin(115200); Serial.begin(115200);
@ -154,6 +209,9 @@ void updateLEDs(int heading) {
// Placeholder for updating the TFT display with GPS data // Placeholder for updating the TFT display with GPS data
void updateDisplay() { void updateDisplay() {
// Disable interrupts while using the dispaly.
cli();
// Add logic to display the distance between devices on the screen // Add logic to display the distance between devices on the screen
// You can add code here to: // You can add code here to:
// - Display the current distance between devices using the GPS data // - Display the current distance between devices using the GPS data
@ -164,6 +222,9 @@ void updateDisplay() {
// tft.setTextSize(2); // Set text size // tft.setTextSize(2); // Set text size
// tft.print("Distance: "); // tft.print("Distance: ");
// tft.print(calculatedDistance); // tft.print(calculatedDistance);
//Re-Enable interrupts globally.
sei();
} }
// Future function to handle LoRa transmission of GPS data - See adafruit LORA code examples // Future function to handle LoRa transmission of GPS data - See adafruit LORA code examples