-
Notifications
You must be signed in to change notification settings - Fork 3
/
S7xG.ino
209 lines (171 loc) · 4.7 KB
/
S7xG.ino
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*------------------------------------------------------------------------------------------------------*\
| |
| S7xG Firmware for TTGO Watch |
| |
| IMPORANT - USE FOLLOWING ARDUINO SETTINGS |
| |
| BOARD - Nucleo-64 |
| BOARD PART NUMBER - Nucleo L073RZ |
| U(S)ART SUPPORT - Enabled (no generic serial) |
| USB SUPPORT - None |
| C RUNTIME LIBRARY - Newlib Nano + Float printf |
| UPLOAD METHOD - STM32CubeProgrammer(SWD) |
| |
\*------------------------------------------------------------------------------------------------------*/
#define VERSION "V1.00"
//------------------------------------------------------------------------------------------------------
#define GNSS_RST PB2
#define GNSS_LS PC6
#define LORA_RST PB10
#define LORA_DIO0 PB11
#define LORA_MOSI PB15
#define LORA_MISO PB14
#define LORA_SCK PB13
#define LORA_NSS PB12
//------------------------------------------------------------------------------------------------------
#define COMMAND_BUFFER_LENGTH 70
//------------------------------------------------------------------------------------------------------
struct TSettings
{
// LoRa
float Frequency;
unsigned char ImplicitOrExplicit; // 1=Implicit, 0=Explicit
unsigned char ErrorCoding;
unsigned char Bandwidth;
unsigned char SpreadingFactor;
unsigned char LowDataRateOptimize;
} Settings;
struct TGPS
{
int Hours, Minutes, Seconds;
unsigned long SecondsInDay; // Time in seconds since midnight
float Longitude, Latitude;
long Altitude;
int Speed;
int Direction;
unsigned int Satellites;
byte FixType;
byte psm_status;
byte Lock;
byte GotTime;
} GPS;
int ShowGPS=1;
int ShowLoRa=1;
unsigned char SSDVBuffer[256];
unsigned int SSDVBufferLength=0;
HardwareSerial Serial4(PC11, PC10); // GPS
HardwareSerial Serial2(PA10, PA9); // Host
#define GPSPort Serial4
#define HostPort Serial2
//------------------------------------------------------------------------------------------------------
void setup()
{
// Serial ports
HostPort.begin(115200);
delay(100);
HostPort.print("\r\n\nTTGO S7xG HAB Firmware ");
HostPort.println(VERSION);
SetupGPS();
SetupLoRa();
}
void loop()
{
CheckHost();
CheckGPS();
CheckLoRa();
}
void ReplyOK(void)
{
HostPort.println('*');
}
void ReplyBad(void)
{
HostPort.println('?');
}
void ShowVersion(void)
{
ReplyOK();
HostPort.print("VER=");
HostPort.println(VERSION);
}
void CheckHost(void)
{
static char Line[COMMAND_BUFFER_LENGTH];
static unsigned int Length=0;
char Character;
while (HostPort.available())
{
Character = HostPort.read();
if (Character == '~')
{
Line[0] = Character;
Length = 1;
}
else if (Character == '\r')
{
Line[Length] = '\0';
ProcessCommand(Line+1);
Length = 0;
}
else if (Length >= sizeof(Line))
{
Length = 0;
}
else if (Length > 0)
{
Line[Length++] = Character;
}
}
}
void ProcessCommand(char *Line)
{
char Command;
Command = Line[0];
Line++;
if (Command == 'F')
{
SetFrequency(Line);
}
else if (Command == 'M')
{
SetLoRaMode(Line);
}
else if (Command == 'B')
{
SetBandwidth(Line);
}
else if (Command == 'E')
{
SetErrorCoding(Line);
}
else if (Command == 'S')
{
SetSpreadingFactor(Line);
}
else if (Command == 'I')
{
SetImplicit(Line);
}
else if (Command == 'L')
{
SetLowOpt(Line);
}
else if (Command == 'V')
{
ShowVersion();
}
else if (Command == 'G')
{
SetShowGPS(Line);
}
else
{
ReplyBad();
}
}
void SetShowGPS(char *Line)
{
int Coding;
ShowGPS = atoi(Line);
ReplyOK();
}