Skip to content

Commit

Permalink
💥 Too much changes #1 SmartTX + Logger + button
Browse files Browse the repository at this point in the history
  • Loading branch information
valentintintin committed Dec 23, 2019
1 parent 1c873d5 commit 4bda303
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 96 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The `CMakeListsUser.txt` will not be overwritten by PlatformIO.

cmake_minimum_required(VERSION 3.2)
project(arduino-tracker-aprs-dra818)
project("arduino-tracker-aprs-dra818")

include(CMakeListsPrivate.txt)

Expand Down Expand Up @@ -62,6 +62,12 @@ add_custom_target(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_custom_target(
PLATFORMIO_BUILD_DEBUG ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion run --target debug "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_custom_target(
PLATFORMIO_UPDATE_ALL ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion update
Expand All @@ -80,4 +86,4 @@ add_custom_target(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_executable(${PROJECT_NAME} ${SRC_LIST})
add_executable(Z_DUMMY_TARGET ${SRC_LIST})
Binary file added DRA818V.pdf
Binary file not shown.
Binary file added aprs speed time.ods
Binary file not shown.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ platform = atmelavr
board = nanoatmega328
framework = arduino
build_flags = -D DEBUG
#-D TEST -D CONTINUE_TX
lib_deps = ${common.lib_deps}
63 changes: 36 additions & 27 deletions src/APRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "APRS.h"
#include "Utils.h"

APRS::APRS(DRA *dra, GPS *gps, uint8_t txPin) : dra(dra), gps(gps), txPin(txPin), lastTx(UINT64_MAX) {
APRS::APRS(DRA *dra, GPS *gps, uint8_t txPin) : dra(dra), gps(gps), txPin(txPin) {
pinMode(txPin, OUTPUT);
packetBuffer.reserve(255);
}
Expand All @@ -11,7 +11,7 @@ void APRS::init(char *call, uint8_t callId, char *toCall, uint8_t toCallId, char
QAPRS.init(0, 0, call, callId, toCall, toCallId, relays);
}

bool APRS::txToRadio(String packet) {
bool APRS::txToRadio() {
DPRINTLN(F("TX ..."));

digitalWrite(LED_BUILTIN, HIGH);
Expand All @@ -22,15 +22,15 @@ bool APRS::txToRadio(String packet) {
dra->tx();
}

delay(1000);
delay(500);

DPRINTLN(F("Packet sending"));

bool qaprsOk = QAPRS.sendData((char *) packet.c_str()) == QAPRSReturnOK;
bool qaprsOk = QAPRS.sendData((char *) packetBuffer.c_str()) == QAPRSReturnOK;

DPRINTLN(F("Packet sent"));

delay(1000);
delay(500);

digitalWrite(LED_BUILTIN, LOW);
if (!dra->isDraDetected()) {
Expand All @@ -53,31 +53,36 @@ void APRS::setComment(String comment) {
this->comment = comment;
}

bool APRS::loop(bool test) {
DPRINT(F("Next: ")); DPRINTLN(abs(getTimeSecondsForGivenSpeed(gps->gps.speed.kmph()) - ((millis() - lastTx) / 1000)));

DPRINTLN((uint32_t) (millis() - lastTx));
DPRINTLN((uint32_t) 1000 * getTimeSecondsForGivenSpeed(gps->gps.speed.kmph()));

#ifdef DEBUG
delay(1000);
#endif

if (gps->getData() || test) {
if (millis() - lastTx >= (uint32_t) 1000 * getTimeSecondsForGivenSpeed(gps->gps.speed.kmph()) || test) {
bool APRS::sendIfPossible(bool forceGps, bool forceTx) {
if (gps->getData() || forceGps) {
if (millis() - lastTx >= (uint32_t) 1000 * getTimeSecondsForGivenSpeed() || forceTx) {
if (sendPosition()) {
blink(2);
lastTx = millis();
lastSpeed = gps->gps.speed.kmph();
return true;
}
}
blink(1);

DPRINT(F("Next: ")); DPRINT(abs(getTimeSecondsForGivenSpeed() - ((millis() - lastTx) / 1000)));
DPRINT(F("/")); DPRINTLN(getTimeSecondsForGivenSpeed());

#ifdef DEBUG
delay(1000);
#endif

return false;
} else {
lastTx = 0;
lastSpeed = 0;
blink(5);
return false;
}
}

#pragma clang diagnostic push
#pragma ide diagnostic ignored "hicpp-signed-bitwise"
long APRS::readVccAtmega() {
long result; // Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
Expand All @@ -89,12 +94,16 @@ long APRS::readVccAtmega() {
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}
#pragma clang diagnostic pop

uint16_t APRS::getTimeSecondsForGivenSpeed(float speed) {
uint16_t APRS::getTimeSecondsForGivenSpeed() {
float speed = gps->gps.speed.kmph();
if (speed >= 20) {
return -0.1 * speed + 42;
} else if (speed >= 5) {
return -11 * speed + 230;
} else if (lastSpeed >= 20 || lastTx == 0) {
return 0;
} else {
return 300;
}
Expand All @@ -103,10 +112,10 @@ uint16_t APRS::getTimeSecondsForGivenSpeed(float speed) {
float APRS::convertDegMin(float decDeg) {
float DegMin;

int intDeg = decDeg; // partie entière
decDeg -= intDeg; // partie décimale
int intDeg = (int) decDeg; // partie entière
decDeg -= (float) intDeg; // partie décimale
decDeg *= 60; // décimale * 60
DegMin = (intDeg * 100) + decDeg; // entière * 100 + décimale
DegMin = (float) (intDeg * 100) + decDeg; // entière * 100 + décimale

return DegMin;
}
Expand All @@ -125,7 +134,7 @@ void APRS::stringPadding(int number, byte width, String *dest) {

void APRS::stringPaddingf(float number, byte width, String *dest) {
float temp = number;
if (!temp) { // NOLINT(bugprone-narrowing-conversions)
if (temp == 0) {
temp++;
}

Expand All @@ -136,8 +145,8 @@ void APRS::stringPaddingf(float number, byte width, String *dest) {
}

void APRS::buildPacket() {
float lat = gps->gps.location.lat();
float lng = gps->gps.location.lng();
auto lat = (float) gps->gps.location.lat();
auto lng = (float) gps->gps.location.lng();
float latDegMin = convertDegMin(lat);
float lngDegMin = convertDegMin(lng);

Expand Down Expand Up @@ -186,10 +195,10 @@ void APRS::buildPacket() {
stringPadding((int) gps->gps.altitude.feet(), 6, &packetBuffer);
// Voltage
packetBuffer += "/V=";
packetBuffer += readVccAtmega() / 1000.f;
packetBuffer += (float) readVccAtmega() / 1000.f;
// Accuracy
packetBuffer += " HDOP=";
packetBuffer += gps->gps.hdop.hdop();
packetBuffer += (int) gps->gps.hdop.hdop();
// Comment
if (comment.length()) {
packetBuffer += comment;
Expand All @@ -201,5 +210,5 @@ void APRS::buildPacket() {

bool APRS::sendPosition() {
buildPacket();
return txToRadio(packetBuffer);
return txToRadio();
}
15 changes: 7 additions & 8 deletions src/APRS.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,31 @@ class APRS {

void init(char *call, uint8_t callId, char *toCall, uint8_t toCallId, char *relays);

bool loop(bool test = false);
bool sendIfPossible(bool forceGps = false, bool forceTx = false);

void setComment(String comment);

bool txToRadio(String packet);

bool sendPosition();

private:
DRA *dra = nullptr;
GPS *gps = nullptr;

uint8_t lastSpeed = 0;
uint64_t lastTx = 0;
uint8_t txPin = 0;

String packetBuffer;
String comment;

long readVccAtmega();
uint16_t getTimeSecondsForGivenSpeed(float speed);
float convertDegMin(float decDeg);
uint16_t getTimeSecondsForGivenSpeed();

float convertDegMin(float decDeg);
void stringPadding(int number, byte width, String *dest);

void stringPaddingf(float number, byte width, String *dest);

void buildPacket();
bool txToRadio();
bool sendPosition();
};


Expand Down
5 changes: 3 additions & 2 deletions src/DRA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ DRA::~DRA() {
}

bool DRA::init(float freq, bool deactiveAfter, char loop) {
digitalWrite(pttPin, HIGH);
active();
digitalWrite(pttPin, HIGH);

char i = loop;
do {
Expand All @@ -26,7 +26,7 @@ bool DRA::init(float freq, bool deactiveAfter, char loop) {
if (!(dra = DRA818::configure(serial, DRA818_VHF, freq, freq, 0, 0, 0, 0, DRA818_12K5, false, false, false,
&Serial))) {
DPRINTLN(F("DRA failed"));
blink(15);
blink(10);
}
} while (dra == nullptr && i > 0);

Expand Down Expand Up @@ -91,6 +91,7 @@ void DRA::active() {

void DRA::deactive() {
digitalWrite(activePin, LOW);
delay(TIME_TOGGLE_ACTIVE);

activeState = false;
}
Expand Down
65 changes: 11 additions & 54 deletions src/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ GPS::GPS(byte rxPin, int baud, byte txPin) : baud(baud) {
}

bool GPS::getData() {
DPRINTLN(F("GPS init..."));
DPRINTLN(F("GPS update..."));

serial->begin(baud);
uint32_t start = millis();
do {
while (serial->available()) {
char r = serial->read();
// DPRINT(r);
char r = (char) serial->read();
// DPRINT(r);
gps.encode(r);
}
} while (millis() - start < TIME_WAIT_DATA);
serial->flush();
serial->end();

if (!gps.location.isValid()) {
DPRINT(F("GPS no fix, sat: "));
DPRINTLN(gps.satellites.value());
DPRINT(F("GPS no fix, sat: ")); DPRINTLN(gps.satellites.value());
return false;
}
DPRINTLN(F("GPS OK"));
Expand All @@ -34,57 +33,15 @@ bool GPS::getData() {


void GPS::displayInfo() {
DPRINT(F("Location: "));
if (gps.location.isValid()) {
DPRINT(gps.location.lat(), 6);
DPRINT(F(","));
DPRINT(gps.location.lng(), 6);
DPRINT(F(" Alt: "));
DPRINT(gps.altitude.meters(), 2);
DPRINT(F(" V: "));
DPRINT(gps.speed.kmph(), 2);
DPRINT(F(" D: "));
DPRINT(gps.course.deg());
} else {
DPRINT(F("Invalid"));
}

DPRINT(F(" Date/Time: "));
if (gps.date.isValid()) {
DPRINT(gps.date.month());
DPRINT(F("/"));
DPRINT(gps.date.day());
DPRINT(F("/"));
DPRINT(gps.date.year());
} else {
DPRINT(F("Invalid"));
}
DPRINT(F("Sat: ")); DPRINT(gps.satellites.value());
DPRINT(F(" HDOP: ")); DPRINTLN(gps.hdop.hdop(), 0);

DPRINT(F(" "));
if (gps.time.isValid()) {
if (gps.time.hour() < 10) DPRINT(F("0"));
DPRINT(gps.time.hour());
DPRINT(F(":"));
if (gps.time.minute() < 10) DPRINT(F("0"));
DPRINT(gps.time.minute());
DPRINT(F(":"));
if (gps.time.second() < 10) DPRINT(F("0"));
DPRINT(gps.time.second());
DPRINT(F("."));
if (gps.time.centisecond() < 10) DPRINT(F("0"));
DPRINT(gps.time.centisecond());
} else {
DPRINT(F("Invalid"));
}

DPRINT(F(" HDOP:"));
if (gps.hdop.isValid()) {
DPRINT(gps.hdop.hdop());
} else {
DPRINT(F("Invalid"));
}
DPRINT(F("Lat: ")); DPRINTLN(gps.location.lat(), 6);
DPRINT(F("Lng: ")); DPRINTLN(gps.location.lng(), 6);

DPRINTLN();
DPRINT(F("Alt: ")); DPRINT(gps.altitude.meters(), 0);
DPRINT(F(" Spd: ")); DPRINT(gps.speed.kmph(), 0);
DPRINT(F(" Crs: ")); DPRINTLN(gps.course.deg(), 0);

#ifdef DEBUG
delay(2000);
Expand Down
Loading

0 comments on commit 4bda303

Please sign in to comment.