-
Notifications
You must be signed in to change notification settings - Fork 9
/
gps.h
99 lines (76 loc) · 6.52 KB
/
gps.h
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
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef H_GPS
#define H_GPS
#include <Arduino.h>
#include "config.h"
#include <EventManager.h>
struct GPSSTATUS {
// Latitude
float lat;
// Longitude
float lng;
// Heading
float hdg;
// Speed
float spd;
// Timestamp of last valid gps data
unsigned long timestamp;
// Current time of day in minutes
unsigned int time;
// Current day of year
unsigned int day;
};
struct SUNINFO {
uint16_t sunrise;
uint16_t sunset;
};
class GPS {
public:
/**
* Register event handlers
* @param EventManager the event manager used for events
*/
static void init(EventManager* em, String* buff) {
eventManager = em;
eventManager->addListener(GPS_MESSAGE_RECEIVED, &GPS::handleMessage);
message = buff;
};
/**
* Handle incoming gps message
*/
static void handleMessage(int eventCode, int eventParam);
/**
* Return the current gps data
*/
static GPSSTATUS* getCurrent() {return &last;}
/**
* Returns true if we're after sunset
* @return boolean true when it's night at the moment
*/
static boolean isNight();
protected:
// Reference to the message buffer
static String* message;
// true, if we have reception
static boolean reception;
// Latest latitude
static GPSSTATUS last;
// Reference to the event manager
static EventManager* eventManager;
/**
* Calculate the checksum of the NMEA sentence
*/
static byte calculateChecksum();
/**
* Parse GPRMC messages
*/
static void parseRMC(String* msg);
/**
* Convert NMEA coordinates to defimal representation
* @param float the coordinate in ddmm.mmmm format
* @param char the N/s/E/W indicator
* @return float the converted value
*/
static float toCoordinates(float coord, char inverse);
};
const SUNINFO sunrisemap[360] PROGMEM = {{390, 904}, {390, 905}, {390, 906}, {390, 907}, {390, 908}, {390, 909}, {390, 910}, {389, 911}, {389, 912}, {389, 913}, {388, 915}, {388, 916}, {387, 917}, {387, 919}, {386, 920}, {385, 921}, {385, 923}, {384, 924}, {383, 925}, {382, 927}, {381, 928}, {380, 930}, {379, 931}, {378, 933}, {377, 934}, {376, 936}, {375, 937}, {374, 939}, {373, 940}, {372, 942}, {369, 945}, {368, 946}, {367, 948}, {365, 950}, {364, 951}, {362, 953}, {361, 954}, {360, 956}, {358, 957}, {356, 959}, {355, 960}, {353, 962}, {352, 964}, {350, 965}, {349, 967}, {347, 968}, {345, 970}, {343, 971}, {342, 973}, {340, 974}, {338, 976}, {336, 977}, {335, 979}, {333, 981}, {331, 982}, {329, 984}, {327, 985}, {326, 987}, {324, 988}, {324, 988}, {322, 990}, {320, 991}, {318, 992}, {316, 994}, {314, 995}, {312, 997}, {310, 998}, {308, 1000}, {306, 1001}, {304, 1003}, {302, 1004}, {300, 1006}, {298, 1007}, {296, 1008}, {294, 1010}, {292, 1011}, {290, 1013}, {288, 1014}, {286, 1016}, {284, 1017}, {282, 1018}, {280, 1020}, {278, 1021}, {276, 1023}, {274, 1024}, {272, 1026}, {270, 1027}, {268, 1028}, {266, 1030}, {264, 1031}, {260, 1034}, {258, 1035}, {256, 1037}, {254, 1038}, {252, 1040}, {250, 1041}, {248, 1042}, {247, 1044}, {245, 1045}, {243, 1046}, {241, 1048}, {239, 1049}, {237, 1051}, {235, 1052}, {233, 1053}, {231, 1055}, {229, 1056}, {228, 1058}, {226, 1059}, {224, 1060}, {222, 1062}, {220, 1063}, {219, 1065}, {217, 1066}, {215, 1067}, {214, 1069}, {212, 1070}, {210, 1072}, {209, 1073}, {207, 1074}, {205, 1076}, {204, 1077}, {202, 1078}, {201, 1080}, {199, 1081}, {198, 1082}, {196, 1084}, {195, 1085}, {193, 1086}, {192, 1088}, {191, 1089}, {189, 1090}, {188, 1092}, {187, 1093}, {186, 1094}, {184, 1095}, {183, 1097}, {182, 1098}, {181, 1099}, {180, 1100}, {179, 1101}, {178, 1102}, {177, 1104}, {176, 1105}, {175, 1106}, {174, 1107}, {174, 1108}, {173, 1109}, {172, 1110}, {172, 1111}, {170, 1113}, {170, 1114}, {169, 1114}, {169, 1115}, {168, 1116}, {168, 1117}, {168, 1118}, {167, 1118}, {167, 1119}, {167, 1120}, {167, 1120}, {166, 1121}, {166, 1121}, {166, 1122}, {166, 1122}, {166, 1123}, {166, 1123}, {167, 1123}, {167, 1123}, {167, 1124}, {167, 1124}, {167, 1124}, {168, 1124}, {168, 1124}, {168, 1124}, {169, 1124}, {169, 1124}, {170, 1124}, {170, 1124}, {171, 1124}, {172, 1123}, {172, 1123}, {173, 1123}, {174, 1123}, {174, 1122}, {175, 1122}, {176, 1121}, {177, 1121}, {178, 1120}, {179, 1119}, {179, 1119}, {180, 1118}, {181, 1117}, {182, 1117}, {183, 1116}, {184, 1115}, {185, 1114}, {187, 1113}, {188, 1112}, {189, 1111}, {190, 1110}, {191, 1109}, {192, 1108}, {193, 1107}, {194, 1106}, {196, 1104}, {197, 1103}, {198, 1102}, {199, 1101}, {201, 1099}, {203, 1096}, {204, 1095}, {206, 1094}, {207, 1092}, {208, 1091}, {209, 1089}, {211, 1088}, {212, 1086}, {213, 1084}, {215, 1083}, {216, 1081}, {217, 1079}, {219, 1078}, {220, 1076}, {221, 1074}, {223, 1073}, {224, 1071}, {225, 1069}, {227, 1067}, {228, 1066}, {229, 1064}, {230, 1062}, {232, 1060}, {233, 1058}, {234, 1056}, {236, 1054}, {237, 1052}, {238, 1051}, {240, 1049}, {241, 1047}, {244, 1043}, {245, 1041}, {246, 1039}, {248, 1037}, {249, 1035}, {250, 1033}, {252, 1031}, {253, 1029}, {254, 1027}, {256, 1025}, {257, 1023}, {258, 1021}, {260, 1019}, {261, 1017}, {262, 1015}, {264, 1013}, {265, 1011}, {266, 1008}, {267, 1006}, {269, 1004}, {270, 1002}, {272, 1000}, {273, 998}, {274, 996}, {276, 994}, {277, 992}, {278, 990}, {280, 988}, {281, 986}, {282, 984}, {284, 982}, {285, 980}, {286, 978}, {288, 976}, {289, 974}, {291, 972}, {292, 970}, {293, 968}, {295, 966}, {296, 964}, {298, 962}, {299, 961}, {300, 959}, {302, 957}, {303, 955}, {305, 953}, {306, 951}, {308, 949}, {309, 948}, {310, 946}, {312, 944}, {313, 942}, {315, 941}, {316, 939}, {318, 937}, {319, 935}, {321, 934}, {322, 932}, {324, 931}, {325, 929}, {328, 926}, {330, 924}, {331, 923}, {333, 921}, {334, 920}, {336, 919}, {337, 917}, {339, 916}, {340, 915}, {342, 913}, {343, 912}, {345, 911}, {346, 910}, {348, 908}, {349, 907}, {351, 906}, {352, 905}, {353, 904}, {355, 903}, {356, 902}, {358, 902}, {359, 901}, {360, 900}, {362, 899}, {363, 898}, {364, 898}, {366, 897}, {367, 897}, {368, 896}, {369, 895}, {371, 895}, {372, 895}, {373, 894}, {374, 894}, {375, 894}, {376, 893}, {377, 893}, {378, 893}, {379, 893}, {380, 893}, {381, 893}, {382, 893}, {383, 893}, {384, 893}, {384, 894}, {385, 894}, {386, 894}, {386, 895}, {387, 895}, {388, 896}, {388, 896}, {388, 897}, {389, 897}, {389, 898}, {390, 898}, {390, 899}, {390, 900}, {390, 901}, {390, 902}, {390, 902}};
#endif