Skip to content

Commit

Permalink
Merge pull request #4 from Halibut-Engineering/master
Browse files Browse the repository at this point in the history
Cleaned up some compiler warnings. Copy observer and satellite name Strings. Added `dopplerOffset()`.
Many thanks to SmittyHalibut, great stuff!
  • Loading branch information
dl9sec authored Dec 23, 2021
2 parents b40dab6 + 65463cd commit eaa203f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/PredictISS/PredictISS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int iySAT = 0; // Map pixel coordinate y of satellite
int ixSUN = 0; // Map pixel coordinate x of sun
int iySUN = 0; // Map pixel coordinate y of sun

char acBuffer[20]; // Buffer for ASCII time
char acBuffer[P13DateTime::ascii_str_len + 1]; // Buffer for ASCII time

int aiSatFP[32][2]; // Array for storing the satellite footprint map coordinates
int aiSunFP[32][2]; // Array for storing the sunlight footprint map coordinates
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version=1.0.1
author=Thorsten Godau (dl9sec)
license=BSD-3-Clause
maintainer=Thorsten Godau <https://github.com/dl9sec>
sentence=Another implementation of G3RUH's PLAN-13 for satellite and sun prediction.
sentence=Another implementation of G3RUHs PLAN-13 for satellite and sun prediction.
paragraph=Compact and modular port to smaller processors including the Atmel AVR chips and reworked for flawless library use in the Arduino ecosystem. Originally authored by Mark VandeWettering K6HX (https://github.com/brainwagon/angst/tree/master/P13)
category=Data Processing
url=https://github.com/dl9sec/AioP13
Expand Down
54 changes: 39 additions & 15 deletions src/AioP13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
//
// - Implementation of P13Sun:elaz()
//
// Mark Smith @SmittyHalibut (12/2021)
//
// - Added some helper constants, cleaned up compiler warnings.
// - Copy Observer and Satellite name strings instead of assuming
// the source is always there.
// - Added `dopplerOffset()`
//
//----------------------------------------------------------------------

#include "AioP13.h"
Expand Down Expand Up @@ -265,7 +272,14 @@ P13Observer::P13Observer(const char *p_ccnm, double p_dlat, double p_dlon, doubl
double l_dRx;
double l_dRz;

this->c_ccObsName = p_ccnm;
uint8_t len = strlen(p_ccnm)%256;
if (c_ccObsName) {
delete c_ccObsName;
}
c_ccObsName = new char[len+1];
strncpy(c_ccObsName, p_ccnm, len);
c_ccObsName[len] = '\0';

c_dLA = radians(p_dlat);
c_dLO = radians(p_dlon);
c_dHT = p_dasl / 1000.0;
Expand Down Expand Up @@ -303,7 +317,9 @@ P13Observer::P13Observer(const char *p_ccnm, double p_dlat, double p_dlon, doubl


P13Observer::~P13Observer() {

if (c_ccObsName) {
delete c_ccObsName;
}
}

//----------------------------------------------------------------------
Expand All @@ -320,7 +336,9 @@ P13Satellite::P13Satellite(const char *p_ccnm, const char *p_ccl1, const char *p
}

P13Satellite::~P13Satellite() {

if (c_ccSatName) {
delete c_ccSatName;
}
}

// Get satellite data from the TLE
Expand All @@ -329,7 +347,14 @@ void P13Satellite::tle(const char *p_ccnm, const char *p_ccl1, const char *p_ccl

double l_dCI;

this->c_ccSatName = p_ccnm;
uint8_t len = strlen(p_ccnm)%256;
if (c_ccSatName) {
delete c_ccSatName;
}
c_ccSatName = new char[len+1];
strncpy(c_ccSatName, p_ccnm, len);
c_ccSatName[len] = '\0';


// Direct quantities from the orbital elements

Expand Down Expand Up @@ -380,7 +405,7 @@ void P13Satellite::predict(const P13DateTime &p_dt) {
double l_dTN;
double l_dGHAE, l_dGHAA;
double l_dT, l_dDT, l_dKD, l_dKDP;
double l_dM, l_dDR, l_dRN, l_dEA;
double l_dM, l_dDR, l_dEA;
double l_dDNOM, l_dC_EA, l_dS_EA;
double l_dA, l_dB, l_dD;
double l_dAP, l_dCW, l_dSW;
Expand All @@ -405,9 +430,6 @@ void P13Satellite::predict(const P13DateTime &p_dt) {
l_dDR = (long)(l_dM / (2.0 * PI)); // Strip out whole no of revs
l_dM -= l_dDR * 2.0 * PI; // M now in range 0..2PI

//??
l_dRN = cp_dRV + l_dDR; // Current Orbit number

// Solve M = EA - EC*SIN(EA) for EA given M, by Newton's Method
l_dEA = l_dM; // Initial solution

Expand Down Expand Up @@ -578,13 +600,10 @@ void P13Satellite::footprint(int p_aipoints[][2], int p_inumberofpoints, const i

}


// Returns the RX (dir = 0 or P13_FRX) or TX (dir = 1 or P13_FTX) frequency with doppler shift.
double P13Satellite::doppler(double p_dfreqMHz, bool p_bodir) {

double l_ddopplershift; // Dopplershift in MHz

l_ddopplershift = -p_dfreqMHz * cp_dRR / 299792.0; // Speed of light is 299792.0 km/s
double l_ddopplershift = dopplerOffset(p_dfreqMHz);

if (p_bodir) // TX
{
Expand All @@ -599,12 +618,17 @@ double P13Satellite::doppler(double p_dfreqMHz, bool p_bodir) {

}

// Returns just the change in frequency, relative to the observer, due to doppler shift.
double P13Satellite::dopplerOffset(double p_dfreqMHz) {
return -p_dfreqMHz * cp_dRR / 299792.0; // Speed of light is 299792.0 km/s
}


//----------------------------------------------------------------------
// _ ___ _ _______
// __| |__ _ ______ | _ \/ |__ / __|_ _ _ _
// / _| / _` (_-<_-< | _/| ||_ \__ \ || | ' \
// \__|_\__,_/__/__/ |_| |_|___/___/\_,_|_||_|
// __| |__ _ ______ | _ \/ |__ / __|_ _ _ _
// / _| / _` (_-<_-< | _/| ||_ \__ \ || | \| |
// \__|_\__,_/__/__/ |_| |_|___/___/\_,_|_|\_|
//
//----------------------------------------------------------------------

Expand Down
12 changes: 5 additions & 7 deletions src/AioP13.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@
#define P13_FRX 0
#define P13_FTX 1


static long fnday(int p_iy, int p_im, int p_id);
static void fndate(int &p_iy, int &p_im, int &p_id, long p_idt);
static double getdouble(const char *p_ccc, int p_ii0, int p_ii1);
static long getlong(const char *p_ccc, int p_ii0, int p_ii1);
void latlon2xy(int &p_ix, int &l_iy, double p_dlat, double p_dlon, const int p_ciMapMaxX, const int p_ciMapMaxY);

//----------------------------------------------------------------------
Expand Down Expand Up @@ -131,6 +126,8 @@ typedef double Vec3[3];
class P13DateTime {

public:
const static uint8_t ascii_str_len = 19;

long c_lDN;
double c_dTN;

Expand All @@ -152,7 +149,7 @@ class P13DateTime {
class P13Observer {

public:
const char *c_ccObsName;
char *c_ccObsName;
double c_dLA;
double c_dLO;
double c_dHT;
Expand All @@ -169,7 +166,7 @@ class P13Observer {
class P13Satellite {

public:
const char *c_ccSatName;
char *c_ccSatName;

Vec3 c_vecSAT, c_vecVEL; // Celestial coordinates
Vec3 c_vecS, c_vecV; // Geocentric coordinates
Expand All @@ -183,6 +180,7 @@ class P13Satellite {
void elaz(const P13Observer &p_obs, double &p_del, double &p_daz);
void footprint(int p_aipoints[][2], int p_inumberofpoints, const int p_ciMapMaxX, const int p_ciMapMaxY, double &p_dsatlat, double &p_dsatlon);
double doppler(double p_dfreqMHz, bool p_bodir);
double dopplerOffset(double p_dfreqMHz);

private:
long cp_lN; // Satellite calaog number
Expand Down

0 comments on commit eaa203f

Please sign in to comment.