Skip to content

Commit

Permalink
Merge pull request #3 from telit/feature/better-parsing
Browse files Browse the repository at this point in the history
improve AT commands management and responses parsing
  • Loading branch information
fabiopi-tlt authored May 6, 2021
2 parents 08e14b3 + ed76ae3 commit 06c632a
Show file tree
Hide file tree
Showing 15 changed files with 1,070 additions and 287 deletions.
8 changes: 4 additions & 4 deletions examples/FTP_example/FTP_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#include <ME310.h>
#include <string.h>

#define APN "nbiot.tids.tim.it"
#define APN "apn"

#define FTP_ADDR_PORT "ftp.telit.com"
#define FTP_USER "guest0181"
#define FTP_PASS "g2hs3tx6"
#define FTP_USER "Username"
#define FTP_PASS "Password"

using namespace me310;

Expand Down Expand Up @@ -148,7 +148,7 @@ void loop() {
if(rc == ME310::RETURN_VALID)
{
delay(3000);
myME310.ftp_size("test.txt", ME310::TOUT_10SEC);
myME310.ftp_get_file_size("test.txt", ME310::TOUT_10SEC);
Serial.print("File size: ");
Serial.println(myME310.buffer_cstr(0));
Serial.println(myME310.buffer_cstr(1));
Expand Down
264 changes: 264 additions & 0 deletions examples/ME310_AT_Test/ME310_AT_Test.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
/*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
Driver Library for ME310 Telit Modem
@details
The library contains a single class that implements a C++ interface to all ME310 AT Commands.
It makes it easy to build Arduino applications that use the full power of ME310 module
@version
1.0.0
@note
@author
BlackIoT Sagl
@date
28/10/2020
*/

#include <ME310.h>

/*
//sercom2
#define PIN_MODULE_RX 29
#define PIN_MODULE_TX 28
#define PAD_MODULE_TX UART_TX_PAD_0
#define PAD_MODULE_RX SERCOM_RX_PAD_1
#define PIN_MODULE_RTS 30
#define PIN_MODULE_CTS 31
#define ON_OFF 27
Uart SerialModule(&sercom4, PIN_MODULE_RX, PIN_MODULE_TX, PAD_MODULE_RX, PAD_MODULE_TX, PIN_MODULE_RTS, PIN_MODULE_CTS);
ME310 myME310 (SerialModule);
*/

using namespace me310;

ME310 myME310;

void print_buffer(ME310 &aME310, const char *term = "OK");

void turnOnModule (){
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
digitalWrite(LED_BUILTIN, LOW);
delay(500);

while(myME310.attention() == ME310::RETURN_TOUT)
{
digitalWrite(ON_OFF, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
delay(6000);
digitalWrite(ON_OFF, LOW);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
}

void setup() {
pinMode(ON_OFF, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(ON_OFF, LOW);

Serial.begin(115200);
myME310.begin(115200);
delay(1000);

Serial.println("SERCOMM Telit Test AT");

turnOnModule();

Serial.println("ME310 ON");

Serial.println();
Serial.println("AT Command");
ME310::return_t rc = myME310.attention(); // issue command and wait for answer or timeout
Serial.println(myME310.buffer_cstr()); // print first line of modem answer
Serial.print(ME310::return_string(rc)); // print return value
Serial.println(" answer from ME310 MODULE");
if(rc != ME310::RETURN_VALID) // exit on error
return;


Serial.println();
Serial.print("Soft Reset Command : ");
rc = myME310.soft_reset (); // issue command and wait for answer or timeout
Serial.println(ME310::return_string(rc)); // print return value
if(rc != ME310::RETURN_VALID) // exit on error
return;

Serial.println();
Serial.println("Display Config Profile : ");
rc = myME310.display_config_profile(); // issue command and wait for answer or timeout
if(rc == ME310::RETURN_VALID) // print all rows returned from ME310 except command echo (index = 0)
print_buffer(myME310);
else return; // exit on error

Serial.println();
Serial.print("Query SIM Status : ");
myME310.query_sim_status();
Serial.println(myME310.buffer_cstr(1));

Serial.println();
Serial.println("Read Query SIM Status : ");
rc = myME310.read_query_sim_status();
if(rc == ME310::RETURN_VALID) // print all rows returned from ME310 except command echo (index = 0)
{
Serial.println(myME310.buffer_cstr(1));
if(strstr(myME310.buffer_cstr(1),"#QSS: 0,1"))
{
Serial.println("SIM is inserted");

rc = myME310.read_enter_pin();
if(rc == ME310::RETURN_VALID) // print all rows returned from ME310 except command echo (index = 0)
{
if(strstr(myME310.buffer_cstr(1),"READY"))
Serial.println("PIN not required");
else
Serial.println("PIN required");
}
else return;

Serial.println();
Serial.print("Print ICCID : ");
rc = myME310.read_iccid();
if(rc == ME310::RETURN_VALID)
{
const char *pLabel = strstr(myME310.buffer_cstr(1),"+CCID: ");
if(pLabel)
{
Serial.print("[");
Serial.write(pLabel+7,19);
Serial.println("]");
}
}
else return;

Serial.print("Print IMSI : ");
rc = myME310.imsi(); // no command echo
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.println();
Serial.println("List Capabilities : ");
rc = myME310.capabilities_list();
if(rc == ME310::RETURN_VALID) // print all rows returned from ME310 except command echo (index = 0)
Serial.println(myME310.buffer_cstr(1));
else return;

}
else
Serial.println("SIM not inserted");
}
else return; // exit on error


Serial.println();
Serial.print("Manufacturer Identification : ");
rc = myME310.manufacturer_identification();
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.print("Model Identification : ");
rc = myME310.model_identification();
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.print("Revision Identification : ");
rc = myME310.revision_identification();
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.print("Serial Number : ");
rc = myME310.serial_number();
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.print("Request Manufacturer Ident. : ");
rc = myME310.request_manufacturer_identification();
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.print("Request Model Ident. : ");
rc = myME310.request_model_identification();
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.print("Request Revision Ident. : ");
rc = myME310.request_revision_identification();
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.print("Product Serial Number : ");
rc = myME310.request_psn_identification();
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.print("Product Code : ");
rc = myME310.request_product_code();
if(rc == ME310::RETURN_VALID)
Serial.println(myME310.buffer_cstr(1));
else return;

Serial.println();
Serial.println("Software Package Version : ");
rc = myME310.request_software_package_version();
if(rc == ME310::RETURN_VALID)
print_buffer(myME310);
else return;

}

void loop() {
Serial.println();
Serial.println("Transparent Bridge Started");
while(1){
while (SerialModule.available()) {
Serial.write(SerialModule.read());
}
while (Serial.available()) {
SerialModule.write(Serial.read());
}
}
}

void print_buffer(ME310 &aME310, const char *term)
{
for(int index = 1;;index++)
{
const char * tmp = aME310.buffer_cstr(index);
if(tmp)
{
if(term)
{
if(strcmp(tmp,term))
Serial.println(tmp); // print if not null
else
break;
}
}
else break; // exit loop if null
}
}
2 changes: 1 addition & 1 deletion examples/Ping_example/Ping_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

using namespace me310;

#define APN "nbiot.tids.tim.it"
#define APN "apn"

char server[] = "8.8.8.8";

Expand Down
4 changes: 2 additions & 2 deletions examples/Socket_example/Socket_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
#include <ME310.h>
//#include <string.h>

#define APN "nbiot.tids.tim.it"
#define APN "apn"
using namespace me310;
int cID = 1; //PDP Context Identifier
int connID = 1; //Socket connection identifier.
char ipProt[] = "IP"; //Packet Data Protocol type

char server[] = "185.86.42.218"; //echo server
char server[] = "modules.telit.com"; //echo server
int port = 10510;

ME310 myME310;
Expand Down
2 changes: 1 addition & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ME310 KEYWORD2
ME310G1 AT-INTERFACE

2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ME310G1
version=1.1.0
version=2.0.0
author=Telit
maintainer=Telit <[email protected]>
sentence=Allows communication with ME310G1 Telit module.
Expand Down
17 changes: 13 additions & 4 deletions src/ATCommandDataParsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using namespace telitAT;
*/
ATCommandDataParsing::ATCommandDataParsing(char* aCommand, char* str, int flag)
{
_str = str;
_str = str;
char* cmd;
cmd = findCommand(aCommand);
if(cmd == NULL && flag == -1)
Expand Down Expand Up @@ -77,7 +77,7 @@ ATCommandDataParsing::ATCommandDataParsing(char* aCommand, char* str, int flag)
}
}
_parser->parse(_str);
}
}
}

//! \brief Implements the extraction of the payload from the string
Expand All @@ -88,7 +88,9 @@ ATCommandDataParsing::ATCommandDataParsing(char* aCommand, char* str, int flag)
uint8_t * ATCommandDataParsing::extractedPayload()
{
if(_parser == nullptr)
{
return NULL;
}
return _parser->getPayload();
}

Expand All @@ -100,9 +102,13 @@ uint8_t * ATCommandDataParsing::extractedPayload()
bool ATCommandDataParsing::parserIs()
{
if(_parser == nullptr)
{
return false;
}
else
{
return true;
}
}
//! \brief Implements the extraction of the received bytes from the string
/*! \details
Expand All @@ -112,7 +118,9 @@ bool ATCommandDataParsing::parserIs()
int ATCommandDataParsing::receivedBytes()
{
if(_parser == nullptr)
{
return -1;
}
return _parser->getReceivedBytes();
}
//! \brief Implements the extraction of the command response from the string
Expand Down Expand Up @@ -179,12 +187,13 @@ char* ATCommandDataParsing::findCommand(char* aCommand)
{
len = tmp_str.copy(_command, posColon, 0);
_command[len] = '\0';
return _command;
}
else
{
return NULL;
tmp_str.copy(_command, tmp_str.length(), 0);
_command[len] = '\0';
}
return _command;
}

//!\brief Class Destructor
Expand Down
Loading

0 comments on commit 06c632a

Please sign in to comment.