Compare commits

..

9 commits

Author SHA1 Message Date
jakeg00dwin
88c22ee457 moved the gps baud rate magic number into header as a define. 2024-09-26 16:51:51 -07:00
jakeg00dwin
3f45a4f789 Moved magic numbers into header 2024-09-26 16:48:39 -07:00
jakeg00dwin
07c2ee4b6d Moved the defines and board specific data into the header 2024-09-26 16:45:08 -07:00
jakeg00dwin
cfa740209f Changed C radio source to CPP 2024-09-26 16:37:58 -07:00
jakeg00dwin
2f9fb1202d Changed project to make use of symlinks for the INO file. 2024-09-26 16:37:36 -07:00
jakeg00dwin
ec1e504edf Added header guards to board_config.h file. 2024-09-26 16:37:14 -07:00
jakeg00dwin
bbc4e4597d Added empty test for the Radio module. 2024-09-26 16:22:25 -07:00
jakeg00dwin
d534b1bd56 Added module Radio to the repo. 2024-09-26 16:22:14 -07:00
jakeg00dwin
5564f1178e changed source into --> src/multi-tracker.ino 2024-09-26 16:20:11 -07:00
11 changed files with 211 additions and 37 deletions

41
inc/board_config.h Normal file
View file

@ -0,0 +1,41 @@
#ifndef BOARD_CONFIG_H
#define BOARD_CONFIG_H
//Un-comment a line below for the target board/uC.
#define FEATHER_RFM95
//#define FEATHER_RFM96
//Only applied if defined
#ifdef FEATHER_RFM9X
//Define Serial params for debuging
#define SERIAL_BUADRATE 115200
// DISPLAY CONFIGURATION (ST7789)
#define TFT_CS 5 // Chip select pin for the display
#define TFT_RST 9 // Reset pin for the display
#define TFT_DC 6 // Data/Command pin for the display
#define TFT_X 240 // Number of pixes in X axis.
#define TFT_Y 280 // Number of pixes in Y axis.
// LED RING CONFIGURATION (WS2812)
#define NUM_LEDS 24 // Number of LEDs in the ring
#define DATA_PIN 12 // Pin for LED data
// GPS CONFIGURATION (BN-220)
#define GPS_TX_PIN 10 // GPS TX pin connected to Arduino RX
#define GPS_RX_PIN 11 // GPS RX pin connected to Arduino TX
#define GPS_BUADRATE 9600 // GPS serial baud rate.
// Radio defines
#define RFM95_CS 8
#define RFM95_INT 7
#define RFM95_RST 4
#define RF95_FREQ 915.0
#define RF95_MAX_DB 23
#define RF95_MIN_DB 5
#define RF95_TIMEOUT 250
#define RF95_BUF_SZ 32
#endif //FEATHER_RFM9X
#endif //BOARD_CONFIG_H

1
multi-tracker.ino Symbolic link
View file

@ -0,0 +1 @@
./src/main.cpp

View file

@ -1,3 +1,4 @@
add_executable(main add_executable(main
main.c main.c
) )
add_subdirectory(Radio)

7
src/Radio/CMakeLists.txt Normal file
View file

@ -0,0 +1,7 @@
add_library(Radio STATIC
Radio.c
)
target_include_directories(Radio PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)

68
src/Radio/Radio.cpp Normal file
View file

@ -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();
}

30
src/Radio/Radio.h Normal file
View file

@ -0,0 +1,30 @@
/*
* Author: username
* Date: 2024
* filename: RADIO.h
* description: module_purpose
*/
#ifndef RADIO
#define RADIO
/**
* @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

View file

@ -1,7 +0,0 @@
#include "stdio.h"
int main(int argc, char **argv)
{
printf("Hello!\n");
return 0;
}

View file

@ -9,37 +9,18 @@
#include <TinyGPS++.h> // Library to handle GPS data #include <TinyGPS++.h> // Library to handle GPS data
#include <SoftwareSerial.h> // Software serial for GPS communication #include <SoftwareSerial.h> // Software serial for GPS communication
#include <RH_RF95.h> // #include <RH_RF95.h> //
//#include "Radio/Radio.h"
#include "inc/board_config.h"
//GLOBAL VARS/OBJS
// MAGNETOMETER (LIS2MDL) CONFIGURATION // MAGNETOMETER (LIS2MDL) CONFIGURATION
Adafruit_LIS2MDL lis2mdl = Adafruit_LIS2MDL(12345); // Create magnetometer object Adafruit_LIS2MDL lis2mdl = Adafruit_LIS2MDL(12345); // Create magnetometer object
// DISPLAY CONFIGURATION (ST7789)
#define TFT_CS 5 // Chip select pin for the display
#define TFT_RST 9 // Reset pin for the display
#define TFT_DC 6 // Data/Command pin for the display
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); // Initialize display Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); // Initialize display
// LED RING CONFIGURATION (WS2812)
#define NUM_LEDS 24 // Number of LEDs in the ring
#define DATA_PIN 12 // Pin for LED data
CRGB leds[NUM_LEDS]; // Array to hold LED colors CRGB leds[NUM_LEDS]; // Array to hold LED colors
// GPS CONFIGURATION (BN-220)
#define GPS_TX_PIN 10 // GPS TX pin connected to Arduino RX
#define GPS_RX_PIN 11 // GPS RX pin connected to Arduino TX
SoftwareSerial gpsSerial(GPS_RX_PIN, GPS_TX_PIN); // Software serial for GPS SoftwareSerial gpsSerial(GPS_RX_PIN, GPS_TX_PIN); // Software serial for GPS
TinyGPSPlus gps; // TinyGPS++ object to process GPS data TinyGPSPlus gps; // TinyGPS++ object to process GPS data
// Radio defines
#define RFM95_CS 8
#define RFM95_INT 7
#define RFM95_RST 4
#define RF95_FREQ 915.0
#define RF95_MAX_DB 23
#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.
@ -61,7 +42,6 @@ NodeId node = {
}; };
uint8_t reciver_buffer[RF95_BUF_SZ]; 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);
@ -79,6 +59,7 @@ 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);
@ -119,6 +100,8 @@ int Radio_SendData() {
rf95.setModeIdle(); rf95.setModeIdle();
} }
int Radio_ReceiveData() { int Radio_ReceiveData() {
//Set radio into RX mode. //Set radio into RX mode.
rf95.setModeRx(); rf95.setModeRx();
@ -134,10 +117,10 @@ int Radio_ReceiveData() {
void setup(void) { void setup(void) {
// Initialize Serial Communication for debugging // Initialize Serial Communication for debugging
Serial.begin(115200); Serial.begin(SERIAL_BUADRATE);
// Display Setup // Display Setup
tft.init(240, 280); // Initialize the display with a resolution of 240x280 pixels tft.init(TFT_X, TFT_Y); // Initialize the display with a resolution of 240x280 pixels
tft.fillScreen(ST77XX_BLACK); // Set the screen background to black tft.fillScreen(ST77XX_BLACK); // Set the screen background to black
// Magnetometer Setup // Magnetometer Setup
@ -147,10 +130,10 @@ void setup(void) {
} }
// LED Ring Setup // LED Ring Setup
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // Initialize the LED ring FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
// GPS Setup // GPS Setup
gpsSerial.begin(9600); // Start GPS communication at 9600 baud rate gpsSerial.begin(GPS_BUADRATE);
} }
void loop() { void loop() {

View file

@ -1,6 +1,7 @@
project(Tests) project(Tests)
# TEST_DIRS # TEST_DIRS
add_subdirectory(Radio)
add_subdirectory(simple_test) add_subdirectory(simple_test)
# TEST_RUNNER # TEST_RUNNER
@ -11,6 +12,7 @@ add_executable(AllTests
target_link_libraries(AllTests target_link_libraries(AllTests
${CPPUTEST_LIBRARIES}/libCppUTest.a ${CPPUTEST_LIBRARIES}/libCppUTest.a
${CPPUTEST_LIBRARIES}/libCppUTestExt.a ${CPPUTEST_LIBRARIES}/libCppUTestExt.a
# TEST_LINKS # TEST_LINKS
Radio
simple_test simple_test
) )

View file

@ -0,0 +1,10 @@
# TEST_RUNNER
add_library(test_Radio
test_Radio.cpp
)
target_link_libraries(test_Radio
${CPPUTEST_LIBRARIES}/libCppUTest.a
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
Radio
)

View file

@ -0,0 +1,38 @@
/*
* Author: username
* Date: todays_date
* filename: test_Radio.c
* description: module_purpose
*/
#include "CppUTest/CommandLineTestRunner.h"
extern "C"
{
#include "Radio.h"
}
TEST_GROUP(FirstTestGroup)
{
void setup()
{
}
void teardown()
{
}
};
TEST(FirstTestGroup, FirstTest)
{
FAIL("Fail me!");
}
TEST(FirstTestGroup, SecondTest)
{
STRCMP_EQUAL("hello", "world");
LONGS_EQUAL(1, 2);
CHECK(false);
}