Skip to content

Commit

Permalink
Merge pull request #15 from telit/feature/code-cleanup
Browse files Browse the repository at this point in the history
code cleanup
  • Loading branch information
fabiopi-tlt authored Jan 11, 2022
2 parents 59fe77c + 3a3d081 commit e374e14
Show file tree
Hide file tree
Showing 17 changed files with 700 additions and 445 deletions.
33 changes: 22 additions & 11 deletions examples/AGNSS_example/AGNSS_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ void setup() {
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)
{
#if NMEA_DEBUG

/////////////////////////////////////
// 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
Expand All @@ -158,15 +159,20 @@ void setup() {
/////////////////////////////////////
rc = myME310.gnss_nmea_data_configuration(2,1,0,1,1,1,0);
int i = 0;
while(strcmp(myME310.buffer_cstr(i), "OK") != 0)
char* buff = (char*) myME310.buffer_cstr(0);
if(buff != NULL)
{
Serial.println(myME310.buffer_cstr(i));
i++;
while(strcmp(buff, "OK") != 0)
{
buff = (char*) myME310.buffer_cstr(i);
Serial.println(buff);
i++;
}
}
}
#endif
}

}
#endif
/////////////////////////////////////
// Set the real-time clock of the module.
// AT+CCLK="05/07/21,12:40:00+00"
Expand Down Expand Up @@ -208,12 +214,16 @@ void loop() {
/*When the position is fixed, the led blinks*/
if (rc == ME310::RETURN_VALID)
{
Serial.println(myME310.buffer_cstr(1));
char* buff = (char*)myME310.buffer_cstr(1);
Serial.println(buff);
std::string tmp_pos;
tmp_pos = myME310.buffer_cstr(1);
std::size_t len_pos = tmp_pos.find(":");
if(len_pos != std::string::npos)

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)
Expand All @@ -227,6 +237,7 @@ void loop() {
delay(1000);
}
}
}
}
}
delay(5000);
Expand All @@ -244,7 +255,7 @@ void loop() {
rc = myME310.gnss_nmea_extended_data_configuration(0);
if(rc == ME310::RETURN_VALID)
{
Serial.println("De-activate unsolicited NMEA sentences flow");
Serial.println("De-activate unsolicited NMEA sentences flow");
}
#endif
/////////////////////////////////////
Expand Down
83 changes: 51 additions & 32 deletions examples/CLIP_example/CLIP_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -70,50 +70,69 @@ void setup() {
Serial.println("AT Command");
myME310.report_mobile_equipment_error(2); //issue command AT+CMEE=2 and wait for answer or timeout
rc = myME310.read_enter_pin(); //issue command AT+cpin? in read mode, check that the SIM is inserted and the module is not waiting for the PIN
if(strcmp(myME310.buffer_cstr(2), "OK") == 0) // read response in 2 array position
char *resp = (char*)myME310.buffer_cstr(2);
if(resp != NULL)
{
delay(2000);
Serial.println("Define PDP Context");
rc = myME310.define_pdp_context(cID, ipProt, APN); //issue command AT+CGDCONT=cid,PDP_type,APN
if(rc == ME310::RETURN_VALID)
if(strcmp(resp, "OK") == 0) // read response in 2 array position
{
myME310.read_define_pdp_context(); //issue command AT+CGDCONT=? (read mode)
Serial.print("pdp context read :");
Serial.println(myME310.buffer_cstr(1)); //print second line of modem answer

Serial.print("gprs network registration status :");
rc = myME310.read_gprs_network_registration_status(); //issue command AT+CGREG? (read mode)
Serial.println(myME310.buffer_cstr(1));
delay(2000);
Serial.println("Define PDP Context");
rc = myME310.define_pdp_context(cID, ipProt, APN); //issue command AT+CGDCONT=cid,PDP_type,APN
if(rc == ME310::RETURN_VALID)
{
while ((strcmp(myME310.buffer_cstr(1), "+CGREG: 0,1") != 0) && (strcmp(myME310.buffer_cstr(1), "+CGREG: 0,5") != 0))
myME310.read_define_pdp_context(); //issue command AT+CGDCONT=? (read mode)
Serial.print("pdp context read :");
Serial.println(myME310.buffer_cstr(1)); //print second line of modem answer

Serial.print("gprs network registration status :");
rc = myME310.read_gprs_network_registration_status(); //issue command AT+CGREG? (read mode)
Serial.println(myME310.buffer_cstr(1));
if(rc == ME310::RETURN_VALID)
{
resp = (char*)myME310.buffer_cstr(1);
while(resp != NULL)
{
if((strcmp(resp, "+CGREG: 0,1") != 0) && (strcmp(resp, "+CGREG: 0,5") != 0))
{
delay(3000);
myME310.read_gprs_network_registration_status();
rc = myME310.read_gprs_network_registration_status();
if(rc != ME310::RETURN_VALID)
{
Serial.println("ERROR");
Serial.println(myME310.return_string(rc));
break;
}
Serial.println(myME310.buffer_cstr(1));
resp = (char*) myME310.buffer_cstr(1);
}
else
{
break;
}
}
}
Serial.println("Activate context");
myME310.context_activation(cID, 1); //issue command AT#SGACT=cid,state and wait for answer or timeout

rc = myME310.calling_line_identification_presentation(1); //issue command AT+CLIP=enable and wait for answer or timeout
Serial.println(myME310.return_string(rc));
if(rc == ME310::RETURN_VALID)
{
Serial.println("Calling Line Identity is enable");
flag = true;
}
else
{
Serial.println((String)"Error: " + rc + " Error string: " + myME310.buffer_cstr(2));
flag = false;
}
}
Serial.println("Activate context");
myME310.context_activation(cID, 1); //issue command AT#SGACT=cid,state and wait for answer or timeout

rc = myME310.calling_line_identification_presentation(1); //issue command AT+CLIP=enable and wait for answer or timeout
Serial.println(rc);
if(rc == ME310::RETURN_VALID)
{
Serial.println("Calling Line Identity is enable");
flag = true;
}
else
{
}
else
{
Serial.println((String)"Error: " + rc + " Error string: " + myME310.buffer_cstr(2));
flag = false;
}
}
}
else
{
Serial.println((String)"Error: " + rc + " Error string: " + myME310.buffer_cstr(2));
}
}

void loop() {
Expand Down
83 changes: 53 additions & 30 deletions examples/FTP_example/FTP_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
#include <ME310.h>
#include <string.h>

#define APN "apn"
#define APN "APN"

#define FTP_ADDR_PORT "ftp.telit.com"
#define FTP_USER "Username"
#define FTP_PASS "Password"
#define FTP_ADDR_PORT "PORT"
#define FTP_USER "CLIENTUSER"
#define FTP_PASS "PASSWORD"

#ifndef ARDUINO_TELIT_SAMD_CHARLIE
#define ON_OFF 6 /*Select the GPIO to control ON_OFF*/
Expand Down Expand Up @@ -72,41 +72,64 @@ void setup() {
Serial.println("AT Command");
myME310.report_mobile_equipment_error(2); //issue command AT+CMEE=2 and wait for answer or timeout
rc = myME310.read_enter_pin(); //issue command AT+cpin? in read mode, check that the SIM is inserted and the module is not waiting for the PIN
if(strcmp(myME310.buffer_cstr(2), "OK") == 0) // read response in 2 array position
if(rc == ME310::RETURN_VALID)
{
Serial.println("Define PDP Context");
rc = myME310.define_pdp_context(cID, ipProt, APN); //issue command AT+CGDCONT=cid,PDP_type,APN
if(rc == ME310::RETURN_VALID)
char *resp = (char*)myME310.buffer_cstr(2);
if(resp != NULL)
{
myME310.read_define_pdp_context(); //issue command AT+CGDCONT=? (read mode)
Serial.print("pdp context read :");
Serial.println(myME310.buffer_cstr(1)); //print second line of modem answer

Serial.print("gprs network registration status :");
rc = myME310.read_gprs_network_registration_status(); //issue command AT+CGREG? (read mode)
Serial.println(myME310.buffer_cstr(1));
if(rc == ME310::RETURN_VALID)
{
while ((strcmp(myME310.buffer_cstr(1), "+CGREG: 0,1") != 0) && (strcmp(myME310.buffer_cstr(1), "+CGREG: 0,5") != 0))
if(strcmp(resp, "OK") == 0) // read response in 2 array position
{
Serial.println("Define PDP Context");
rc = myME310.define_pdp_context(cID, ipProt, APN); //issue command AT+CGDCONT=cid,PDP_type,APN
if(rc == ME310::RETURN_VALID)
{
delay(3000);
myME310.read_gprs_network_registration_status();
Serial.println(myME310.buffer_cstr(1));
myME310.read_define_pdp_context(); //issue command AT+CGDCONT=? (read mode)
Serial.print("pdp context read :");
Serial.println(myME310.buffer_cstr(1)); //print second line of modem answer

Serial.print("gprs network registration status :");
rc = myME310.read_gprs_network_registration_status(); //issue command AT+CGREG? (read mode)
Serial.println(myME310.buffer_cstr(1));
if(rc == ME310::RETURN_VALID)
{
resp = (char*)myME310.buffer_cstr(1);
while(resp != NULL)
{
if ((strcmp(resp, "+CGREG: 0,1") != 0) && (strcmp(resp, "+CGREG: 0,5") != 0))
{
delay(3000);
rc = myME310.read_gprs_network_registration_status();
if(rc != ME310::RETURN_VALID)
{
Serial.println("ERROR");
Serial.println(myME310.return_string(rc));
break;
}
Serial.println(myME310.buffer_cstr(1));
resp = (char*)myME310.buffer_cstr(1);
}
else
{
break;
}
}
}
Serial.println("Activate context");
myME310.context_activation(cID, 1); //issue command AT#SGACT=cid,state and wait for answer or timeout
}
}
Serial.println("Activate context");
myME310.context_activation(cID, 1); //issue command AT#SGACT=cid,state and wait for answer or timeout
}
else
{
Serial.println((String)"Error: " + rc + " Error string: " + myME310.buffer_cstr(2));
}
}
}
else
{
Serial.println((String)"Error: " + rc + " Error string: " + myME310.buffer_cstr(2));
}

}

void loop() {

char data[] = "We are appending some FTP data\nAnother data";
const char data[] = "We are appending some FTP data\nAnother data";

rc = myME310.ftp_close();
if(rc == ME310::RETURN_VALID)
Expand Down Expand Up @@ -140,7 +163,7 @@ void loop() {
Serial.println((String)"Ftp put result: " +myME310.return_string(rc));
if(rc == ME310::RETURN_VALID)
{
rc = myME310.ftp_append_extended((int)sizeof(data), data, 1); //issue command AT#FTPAPPEXT=dataSize, data and wait for answer or timeout
rc = myME310.ftp_append_extended((int)sizeof(data), (char*)data, 1); //issue command AT#FTPAPPEXT=dataSize, data and wait for answer or timeout
Serial.println((String)"Ftp append extended result: " +myME310.return_string(rc));
if(rc == ME310::RETURN_VALID)
{
Expand Down
46 changes: 25 additions & 21 deletions examples/GNSS_example/GNSS_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,30 @@ void setup() {
// 1 : GNSS controller is powered up
/////////////////////////////////////
rc = myME310.gnss_controller_power_management(1);
if (rc == ME310::RETURN_VALID)
{
#if NMEA_DEBUG
/////////////////////////////////////
// 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)
#if NMEA_DEBUG
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
// 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_data_configuration(2,1,0,1,1,1,0);
int i = 0;
while(strcmp(myME310.buffer_cstr(i), "OK") != 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)
{
Serial.println(myME310.buffer_cstr(i));
i++;
/////////////////////////////////////
// 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;
while(strcmp(myME310.buffer_cstr(i), "OK") != 0)
{
Serial.println(myME310.buffer_cstr(i));
i++;
}
}
}
#endif
}
#endif
}

void loop() {
Expand All @@ -170,11 +170,14 @@ void loop() {
if (rc == ME310::RETURN_VALID)
{
Serial.println(myME310.buffer_cstr(1));
char* buff = (char*)myME310.buffer_cstr(1);
std::string tmp_pos;
tmp_pos = myME310.buffer_cstr(1);
std::size_t len_pos = tmp_pos.find(":");
if(len_pos != std::string::npos)
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)
Expand All @@ -188,6 +191,7 @@ void loop() {
delay(1000);
}
}
}
}
}
delay(5000);
Expand Down
Loading

0 comments on commit e374e14

Please sign in to comment.