-
Notifications
You must be signed in to change notification settings - Fork 0
/
tleFunction.cpp
92 lines (90 loc) · 2.25 KB
/
tleFunction.cpp
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
#include "TLEFunction.h"
void updateTleData(String& payload, String serverName)
{
uint8_t httpResponseCode = 0;
HTTPClient http;
http.begin(serverName);
httpResponseCode = http.GET();
if(httpResponseCode > 0){
payload = http.getString();
}
else{
Serial.println(httpResponseCode);
Serial.println("Fail to get TLE!!!");
}
http.end();
}
bool checkNameSat(String nameSat, String tle, uint16_t& posStartTLEsLine1){
String tempName;
uint16_t i, j;
uint16_t lengthOfPayload = tle.length();
for(i = 0; i < lengthOfPayload; ++i){
for(j = i; j < i + LENGTH_SAT_NAME; ++j){
if(tle[j] == '\n'){
tempName = tle.substring(i,j);
if(strcmp(tempName.c_str(), nameSat.c_str()) == 0){
posStartTLEsLine1 = j + 1;
return true;
}
else{
break;
}
}
}
i = j + STEP_JUMP_TLE;
if(tle[i] != '\n'){
while(tle[++i] != '\n');
}
}
return false;
}
bool getTLE(String nameSat, char* tle_line1, char* tle_line2, String payload){
uint16_t posStartTLEsLine1 = 0;
uint8_t count = 0;
uint16_t i;
if(checkNameSat(nameSat, payload, posStartTLEsLine1)){
for(i = posStartTLEsLine1; i < posStartTLEsLine1 + MAX_CHAR_ONE_LINE_TLE; ++i){
if(payload[i] != '\n'){
tle_line1[count] = payload[i];
tle_line2[count] = payload[i + 70];
++count;
}
else{
break;
}
}
tle_line1[i] = '\0';
tle_line2[i] = '\0';
return true;
}
else{
Serial.println("fail --");
return false;
}
}
uint8_t getAmountOfSat(String payload)
{
uint8_t amountOfSat = 0;
uint16_t lengthOfPayload = payload.length();
for(uint16_t index = 0; index < lengthOfPayload; ++index){
if(payload[index] == '\n'){
index = index + STEP_JUMP_TLE;
amountOfSat++;
}
}
return amountOfSat;
}
void getAllSatName(String* arraySatNames, String payload)
{
uint8_t element = 0;
uint16_t indexStart, indexStop;
uint8_t n = getAmountOfSat(payload);
for(indexStart = 0; element < n; ++indexStart){
indexStop = indexStart;
while(payload[indexStop] != '\n'){
++indexStop;
}
arraySatNames[element++] = payload.substring(indexStart,indexStop);
indexStart = indexStop + STEP_JUMP_TLE;
}
}