-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAGNSS_example.ino
271 lines (243 loc) · 8.46 KB
/
AGNSS_example.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*Copyright (C) 2020 Telit Communications S.p.A. Italy - All Rights Reserved.*/
/* See LICENSE file in the project root for full license information. */
/**
@file
ME310.cpp
string.h
stdio.h
@brief
Sample test of the use of AT commands via ME310 library
@details
In this example sketch, it is shown how to use AGNSS management, using ME310 library.\n
AGNSS is enable, GNSS configuration, GNSS controller power management, GNSS nmea configuration functions are shown.\n
GPS positions are acquired and response is printed.
NOTE:\n
For the sketch to work correctly, GNSS should be tested in open sky conditions to allow a fix. The fix may take a few minutes.
@version
1.0.0
@note
@author
Cristina Desogus
@date
05/07/2021
*/
#include <ME310.h>
#include <string>
/*When NMEA_DEBUG is 0 Unsolicited NMEA is disable*/
#define NMEA_DEBUG 0
#ifndef ARDUINO_TELIT_SAMD_CHARLIE
#define ON_OFF 6 /*Select the GPIO to control ON_OFF*/
#endif
using namespace me310;
/*
* If a Telit-Board Charlie is not in use, the ME310 class needs the Uart Serial instance in the constructor, that will be used to communicate with the modem.\n
* Please refer to your board configuration in variant.h file.
* Example:
* Uart Serial1(&sercom4, PIN_MODULE_RX, PIN_MODULE_TX, PAD_MODULE_RX, PAD_MODULE_TX, PIN_MODULE_RTS, PIN_MODULE_CTS);
* ME310 myME310 (Serial1);
*/
ME310 myME310;
ME310::return_t rc;
int count = 0;
void setup() {
pinMode(ON_OFF, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
myME310.begin(115200);
delay(1000);
myME310.powerOn(ON_OFF);
delay(5000);
Serial.println("Telit Test AT GNSS command");
Serial.println("ME310 ON");
Serial.println("AT Command");
ME310::return_t rc = myME310.attention(); // issue command and wait for answer or timeout
Serial.println(myME310.buffer_cstr(0)); // print first line of modem answer
////////////////////////////////////
// Report Mobile Equipment Error CMEE
// (0 -> disable, 1-> enable numeric
// values, 2 -> enable verbose mode)
///////////////////////////////////
myME310.report_mobile_equipment_error(2); //issue command AT+CMEE=2 and wait for answer or timeout
/////////////////////////////////////
// Read GNSS configuration
// $GPSCFG:<startup priority>,<TBF>,<costellation>,<runtime priority>
// e.g. $GPSCFG: 0,4321,2,0
/////////////////////////////////////
Serial.println("Read GNSS configuration");
myME310.read_gnss_configuration(); //issue command AT$GPSCFG?
Serial.println(myME310.buffer_cstr(1));
/////////////////////////////////////
// Set GNSS priority
// AT$GPSCFG=0,0
// 0 : priority GNSS
// 1 : priority WWAN
/////////////////////////////////////
Serial.println("Set GNSS priority");
rc = myME310.gnss_configuration(0,0);
Serial.println(ME310::return_string(rc)); // print return value
if (rc == ME310::RETURN_VALID)
{
myME310.module_reboot(); //issue command AT#REBOOT
Serial.println(myME310.buffer_cstr(1));
}
delay(5000);
/////////////////////////////////////
// Set constellations
// AT$GPSCFG=2,X
// 0 : the constellation is selected automatically based on Mobile Country Code (MCC) of camped network
// 1 : GPS+GLO
// 2 : GPS+GAL
// 3 : GPS+BDS
// 4 : GPS+QZSS
/////////////////////////////////////
Serial.println("Set constellations");
rc = myME310.gnss_configuration(2,1);
Serial.println(ME310::return_string(rc));
if (rc == ME310::RETURN_VALID)
{
myME310.module_reboot(); //issue command AT#REBOOT
Serial.println(myME310.buffer_cstr(1));
}
delay(5000);
/////////////////////////////////////
// Set priority to GNSS priority in runtime
// AT$GPSCFG=3,0
// 0 : priority GNSS
// 1 : priority WWAN
/////////////////////////////////////
Serial.println("Set priority to GNSS priority in runtime");
rc = myME310.gnss_configuration(3,0);
Serial.println(ME310::return_string(rc));
if (rc == ME310::RETURN_VALID)
{
myME310.module_reboot(); //issue command AT#REBOOT
Serial.println(myME310.buffer_cstr(1));
}
delay(5000);
/////////////////////////////////////
// Set on/off GNSS controller
// AT$GPSP=<status>
// 0 : GNSS controller is powered down
// 1 : GNSS controller is powered up
/////////////////////////////////////
Serial.println("Set on/off GNSS controller");
rc = myME310.gnss_controller_power_management(1);
Serial.println(ME310::return_string(rc));
#if NMEA_DEBUG
if (rc == ME310::RETURN_VALID)
{
/////////////////////////////////////
// Set GNGSA, GLGSV and GNRMC as available sentence in the unsolicited NMEA sentences.
// AT$GPSNMUNEX=0,1,1,0,0,0,0,0,0,0,0,1,0
/////////////////////////////////////
rc = myME310.gnss_nmea_extended_data_configuration(0,1,1,0,0,0,0,0,0,0,0,1,0);
if(rc == ME310::RETURN_VALID)
{
/////////////////////////////////////
// Activate unsolicited NMEA sentences flow in the AT port and GPGGA,GPRMC, GPGSA and GPGSV sentences.
// AT$GPSNMUN=2,1,0,1,1,1,0
/////////////////////////////////////
rc = myME310.gnss_nmea_data_configuration(2,1,0,1,1,1,0);
int i = 0;
char* buff = (char*) myME310.buffer_cstr(0);
if(buff != NULL)
{
while(strcmp(buff, "OK") != 0)
{
buff = (char*) myME310.buffer_cstr(i);
Serial.println(buff);
i++;
}
}
}
}
#endif
/////////////////////////////////////
// Set the real-time clock of the module.
// AT+CCLK="05/07/21,12:40:00+00"
/////////////////////////////////////
Serial.println("Set the real-time clock of the module.");
rc = myME310.clock_management("05/07/21,12:40:00+00");
Serial.println(ME310::return_string(rc));
/////////////////////////////////////
// Set the AGNSS providers enable or disable.
// AT$AGNSS=provider,status
// <status>:0 to disable
// 1 to enable
/////////////////////////////////////
Serial.println("Set the AGNSS providers enable.");
myME310.gnss_set_agnss_enable(0,1);
myME310.module_reboot();
delay(10000);
/////////////////////////////////////
// Read command returns the requested and the active status for each agnss provider.
// $AGNSS: <provider>,<active>,<requested>
// Request value is 0 to disable or 1 to enable
/////////////////////////////////////
myME310.read_gnss_set_agnss_enable();
Serial.println(myME310.buffer_cstr(1));
}
void loop() {
delay(1000);
/////////////////////////////////////
// Get Acquired Position
// AT$GPSACP
/////////////////////////////////////
rc = myME310.gps_get_acquired_position();
/*When the position is fixed, the led blinks*/
if (rc == ME310::RETURN_VALID)
{
char* buff = (char*)myME310.buffer_cstr(1);
Serial.println(buff);
std::string tmp_pos;
if(buff != NULL)
{
tmp_pos = buff;
std::size_t len_pos = tmp_pos.find(":");
if(len_pos != std::string::npos)
{
std::size_t len_pos2 = tmp_pos.find(",");
char valid_pos[64];
if(len_pos2 != std::string::npos)
{
int len = tmp_pos.copy(valid_pos, ((len_pos2-1)-len_pos), len_pos+1);
if(len > 2)
{
digitalWrite(LED_BUILTIN, HIGH);
delay(6000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
}
}
}
}
delay(5000);
if(count > 20)
{
#if NMEA_DEBUG
//////////////////////////////////
//Stop NMEA Flow and Stop GNSS Session
//////////////////////////////////
Serial.println("Stop NMEA Flow and GNSS Session");
/////////////////////////////////////
// De-activate unsolicited NMEA sentences flow.
// AT$GPSNMUN=0
/////////////////////////////////////
rc = myME310.gnss_nmea_extended_data_configuration(0);
if(rc == ME310::RETURN_VALID)
{
Serial.println("De-activate unsolicited NMEA sentences flow");
}
#endif
/////////////////////////////////////
// GNSS controller is powered down
// AT$GPSP=0
/////////////////////////////////////
Serial.println("Stop GNSS Session");
myME310.gnss_controller_power_management(0);
delay(5000);
exit(0);
}
count++;
}