Dear All,
I am very new with Arduino and I am trying hard to understand a code wich read the serial port.
Could you help me on it?
My goal is read this:
if(cell.available() > 0){
incoming_char=cell.read(); //Get the character from the cellular serial port.
Serial.println(incoming_char); //Print the incoming character to the terminal.
if (incoming_char == '\n') {
Serial.println("[n]");
}
if (incoming_char == '\r') {
Serial.println("[r]");
}
if (incoming_char == '\O') {
Serial.println("[00]");
}
}
and to collect all data, in a array or varibale, such
+SIND: 1
+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
+SIND: 11
+SIND: 3
+SIND: 4
(and other)
I also would like to Serial.print() the message matching to those code
0 SIM card removed
1 SIM card inserted
2 Ring melody
3 AT module is partially ready
4 AT module is totally ready
5 ID of released calls
6 Released call whose ID=
7 The network service is available for an emergency call
8 The network is lost
9 Audio ON
10 Show the status of each phonebook after init phrase
11 Registered to network
I also, I would like to run the GSM/GPS communication when +SIND: 4.
For now I found that code that I can not understand, or, let's say translate and explain to a human:
static void readATString(boolean watchTimeout = false) {
char buffidx = 0;
int time = millis();
while (1) {
int newTime = millis();
if (watchTimeout) {
// Time out if we never receive a response
if (newTime - time > 30000) error(ERROR_GSM_FAIL);
}
if (cell.available() > 0) {
incoming_char = cell.read();
if (incoming_char == -1) {
at_buffer[buffidx] = '\0';
return;
}
if (incoming_char == '\n') {
continue;
}
if ((buffidx == BUFFSIZE - 1) || incoming_char == '\r') {
at_buffer[buffidx] = '\0';
return;
}
at_buffer[buffidx++] = incoming_char;
}
}
}
How is printed and stored the value of at_buffer[buffidx]?
In other word, I would like to have somethink like this.
if (something == "+SIND:0") Serial.print("SIM card remove");
if (something =="+SIND:1") Serial.print("SIM card inserted");
if (something == "+SIND:3") Serial.print("AT module is partially ready");
if (something == "+SIND:4") Serial.print("AT module is totaly ready");
if (something == "+SIND:10") Serial.print("message");
if (something == "+SIND:11") Serial.print("Registered to network");
Someone can explain me or provide me an exemple?
Many thank for your great help, I loat all my afternoon on this.... :o|
Cheers and happy new year!!