-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathDeclination.cpp
More file actions
86 lines (71 loc) · 3.79 KB
/
Declination.cpp
File metadata and controls
86 lines (71 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "./inc/Globals.hpp"
#include "../Configuration.hpp"
#include "Utility.hpp"
#include "Declination.hpp"
//////////////////////////////////////////////////////////////////////////////////////
//
// Declination
//
// A class to handle degrees, minutes, seconds of a declination
// Parses the RA or DEC from a string that has an optional sign, a two digit degree, a seperator, a two digit minute, a seperator and a two digit second.
// For example: -45*32:11 or 23:44:22
// In the NORTHERN hemisphere, 0 is north pole, 180 and -180 is south pole
//------------------ S---------------------------------------- N ---------------------------------- S
// Celestial -90 -60 -30 0 30 60 90 60 30 0 -30 -60 -90
// Celestial = 90 - abs(Declination)
// Declination -180 -150 -120 -90 -60 -30 0 30 60 90 120 150 180
// In the SOUTHERN hemisphere, 0 is south pole, 180 and -180 is north pole
//------------------ N---------------------------------------- S ---------------------------------- N
// Celestial 90 60 30 0 -30 -60 -90 -60 -30 0 30 60 90
// Celestial = -90 + abs(Declination)
// Declination -180 -150 -120 -90 -60 -30 0 30 60 90 120 150 180
// Pure arithmetic (constructors, set, addDegrees, getTotalDegrees, checkHours)
// is in core::Declination (src/core/types/Declination.hpp/.cpp).
char achBufDeg[32];
// Convert to a standard string (like 14:45:06), specifying separators if needed
const char *Declination::ToDisplayString(char sep1, char sep2) const
{
char achFormat[16];
sprintf(achFormat, "{d}%c{m}%c{s}", sep1, sep2);
return formatString(achBufDeg, achFormat);
}
const char *Declination::ToString() const
{
ToDisplayString('*', ':');
size_t used = strlen(achBufDeg);
size_t remaining = sizeof(achBufDeg) - used;
float displayVal = inNorthernHemisphere ? 90 - fabsf(getTotalHours()) : -90 + fabsf(getTotalHours());
String valStr = String(displayVal, 4);
String hoursStr = String(getTotalHours(), 4);
snprintf(achBufDeg + used, remaining, " (%s, %s)", valStr.c_str(), hoursStr.c_str());
return achBufDeg;
}
Declination Declination::ParseFromMeade(String const &s)
{
Declination result;
LOG(DEBUG_MEADE, "[DECLINATION]: Declination.Parse(%s) for %s Hemi", s.c_str(), inNorthernHemisphere ? "N" : "S");
// Use the DayTime code to parse it...
::DayTime dt = ::DayTime::ParseFromMeade(s);
LOG(DEBUG_MEADE, "[DECLINATION]: Declination DayTime is %l secs", dt.getTotalSeconds());
// ...and then correct for hemisphere
result.totalSeconds = inNorthernHemisphere ? (arcSecondsPerHemisphere / 2) - dt.getTotalSeconds()
: -(arcSecondsPerHemisphere / 2) - dt.getTotalSeconds();
LOG(DEBUG_MEADE, "[DECLINATION]: Adjust for hemisphere. %s -> %s (%l secs)", s.c_str(), result.ToString(), result.totalSeconds);
return result;
}
Declination Declination::FromSeconds(long seconds)
{
const auto secondsFloat = static_cast<float>(seconds);
const auto arcSecondsPerHemisphereFloat = static_cast<float>(arcSecondsPerHemisphere);
if (inNorthernHemisphere)
{
return Declination(((arcSecondsPerHemisphereFloat / 2.0f) - secondsFloat) / 3600.0f);
}
return Declination(((arcSecondsPerHemisphereFloat / 2.0f) + secondsFloat) / 3600.0f);
}
const char *Declination::formatString(char *targetBuffer, const char *format, long *) const
{
long secs
= inNorthernHemisphere ? (arcSecondsPerHemisphere / 2) - labs(totalSeconds) : -(arcSecondsPerHemisphere / 2) + labs(totalSeconds);
return core::DayTime::formatString(targetBuffer, format, &secs);
}