Can anyone explain this code for me

Hello everyone .. i want to work out with sim808 core board
i have found this code and it works correctly
i have a problem to understand this code can someone please explain it to me and thank you very much

what does this fucntion do exactly : String sendData (String command , const int timeout ,boolean debug)

void sendTabData(String command , const int timeout , boolean debug){

  sim808.println(command);
  long int time = millis();
  int i = 0;

  while((time+timeout) > millis()){
    while(sim808.available()){
      char c = sim808.read();
      if (c != ',') {
         data[i] +=c;
         delay(100);
      } else {
        i++;  
      }
      if (i == 5) {
        delay(100);
        goto exitL;
      }
    }
  }exitL:
  if (debug) {
    state = data[1];
    timegps = data[2];
    latitude = data[3];
    longitude =data[4];  
  }
}
and what does this do exactly : void sendTabData(String command , const int timeout , boolean debug){
}
String sendData (String command , const int timeout ,boolean debug){
  String response = "";
  sim808.println(command);
  long int time = millis();
  int i = 0;

  while ( (time+timeout ) > millis()){
    while (sim808.available()){
      char c = sim808.read();
      response +=c;
    }
  }
  if (debug) {
     Serial.print(response);
     }
     return response;
}

i m new and im still struggling with C programming

#include <SoftwareSerial.h>
SoftwareSerial sim808(7,8);

char phone_no[] = "+2XXXXXXXXX"; // replace with your phone no.
String data[5];
#define DEBUG true
String state,timegps,latitude,longitude;

void setup() {
 sim808.begin(9600);
 Serial.begin(9600);
 delay(50);

 sim808.print("AT+CSMP=17,167,0,0");  // set this parameter if empty SMS received
 delay(100);
 sim808.print("AT+CMGF=1\r"); 
 delay(400);

 sendData("AT+CGNSPWR=1",1000,DEBUG);
 delay(50);
 sendData("AT+CGNSSEQ=RMC",1000,DEBUG);
 delay(150);
 
}

void loop() {
  sendTabData("AT+CGNSINF",1000,DEBUG);
  if (state !=0) {
    Serial.println("State  :"+state);
    Serial.println("Time  :"+timegps);
    Serial.println("Latitude  :"+latitude);
    Serial.println("Longitude  :"+longitude);

    sim808.print("AT+CMGS=\"");
    sim808.print(phone_no);
    sim808.println("\"");
    
    delay(300);

    sim808.print("http://maps.google.com/maps?q=loc:");
    sim808.print(latitude);
    sim808.print(",");
    sim808.print (longitude);
    delay(200);
    sim808.println((char)26); // End AT command with a ^Z, ASCII code 26
    delay(200);
    sim808.println();
    delay(20000);
    sim808.flush();
    
  } else {
    Serial.println("GPS Initialising...");
  }
}

void sendTabData(String command , const int timeout , boolean debug){

  sim808.println(command);
  long int time = millis();
  int i = 0;

  while((time+timeout) > millis()){
    while(sim808.available()){
      char c = sim808.read();
      if (c != ',') {
         data[i] +=c;
         delay(100);
      } else {
        i++;  
      }
      if (i == 5) {
        delay(100);
        goto exitL;
      }
    }
  }exitL:
  if (debug) {
    state = data[1];
    timegps = data[2];
    latitude = data[3];
    longitude =data[4];  
  }
}
String sendData (String command , const int timeout ,boolean debug){
  String response = "";
  sim808.println(command);
  long int time = millis();
  int i = 0;

  while ( (time+timeout ) > millis()){
    while (sim808.available()){
      char c = sim808.read();
      response +=c;
    }
  }
  if (debug) {
     Serial.print(response);
     }
     return response;
}

SIM808_Arduino_full_code.ino (2.19 KB)

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

four_nobody:
what does this fucntion do exactly : String sendData (String command , const int timeout ,boolean debug)

It sends out a chunk of data on the sim808 interface.

and what does this do exactly : void sendTabData(String command , const int timeout , boolean debug){

It reads some data from the sim808 interface. The name of the function doesn't seem to match what the function is supposed to do - a sign of crappy code.

i m new

You forgot to add: "and by the way I post my code I'm making it obvious can't be bothered to do my homework which includes reading manuals"...

        goto exitL;

That, by the way, is another sign of crappy code. The copious use of delay() is not helpful either, of course.

TomGeorge:
Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

Thanks TOm now the question clear //
would you try to explain it please

wvmarle:
It sends out a chunk of data on the sim808 interface.

It reads some data from the sim808 interface. The name of the function doesn't seem to match what the function is supposed to do - a sign of crappy code.
You forgot to add: "and by the way I post my code I'm making it obvious can't be bothered to do my homework which includes reading manuals"...

That, by the way, is another sign of crappy code. The copious use of delay() is not helpful either, of course.

BRI it's my first time to ever publish anything here .. i followed to the rules now you can check the question is clear

look can you explain more about this one ..

String sendData (String command , const int timeout ,boolean debug){
  String response = "";
  sim808.println(command);
  long int time = millis();
  int i = 0;

  while ( (time+timeout ) > millis()){
    while (sim808.available()){
      char c = sim808.read();
      response +=c;
    }
  }
  if (debug) {
     Serial.print(response);
     }
     return response;
}

and thank you very much

The variable i is redundant

String sendData (String command , const int timeout ,boolean debug){

sends command to the SIM808, then reads the response. Ignore the function name; read the code.