Hi everyone,
I'm working on an Arduino project and am stuck. I've tried lots of things, in last 2-weeks and can't figure it out. Any help would be greatly appreciated!
Basically, our working script (on Arduino Uno) sends AT+ commands to an A7 GSM Board, and reports back the data. Here's the actual output from Serial.write(); :-
//--- Actual ouput is this -----
AT+CGDCONT=?
+CGDCONT: (1..7), (IP,IPV6,PPP),(0..3),(0..4)
OK
AT+CRLP?
+CME ERROR:58
AT+CGMI
Ai Thinker Co.LTD
OK
I need the output to be like this:
|--- Ok ---| [AT+CGDCONT=? ] [+CGDCONT] (1..7), (IP,IPV6,PPP),(0..3),(0..4)
|--- ERROR ---| [AT+CRLP? ] [+CME ] ERROR:58
|--- Ok ---| [AT+CGMI ] [ ] Ai Thinker Co.LTD
From what I have been researching the last week, is that I think this needs to be put into a "multi-dimensial" ARRAY foreach "AT+" result, and then interrogate the ARRAY. So a typical i believe the ARRAY dataset would look like this??:
//--- Assuming this is ARRAY Contents for "AT+CGDCONT" from above -----
GSM_Array[0](i) = 'AT+CGDCONT' //--- AT_COMMAND
GSM_Array[1](i) = '+CGDCONT: (1..7), (IP,IPV6,PPP),(0..3),(0..4)' //--- AT_RESPONSE :1
GSM_Array[2](i) = ' ' //--- AT_RESPONSE :2
GSM_Array[3](i) = OK //--- AT_RESPONSE :3
If the ARRAY worked, then, I assume we could do something like this, to process the ROW_3 of the Raw output...
String AT_CMEError = "+CME ERROR:58";
String AT_MsgError;
String AT_CPlus = "+C";
String AT_MsgCmd;
//---- Check for: '+CME ERROR:' --------
if (strcmp(GSM_Array[1](i),AT_CMEError) == 0) { //--Check if +CME ERROR occurs
AT_MsgError = "|--- ERROR ---|" ;
} else {
AT_MsgError = "|--- Ok ---|";
}
Normally, I would use 'AWK/GREP/SED' in Korne or Bourne for this kinda thing. But this is C+
on Arduino. Nearest best thing I can think of was the following : (i know this is not good but i'm trying to figure it ):
//---- Check for: "+C" MSG detail --------
//---- Exclude : +CME ERROR:58 --------
if (strcmp(GSM_Array[1](i),AT_CPlus) == 0) && (strcmp(GSM_Array[1](i),AT_CMEError) != 0)
{
AT_MsgCmd="+C????"; //--- eg. +CGDCONT, how to "AWK & CUT" the GSM_Array[1](i) ???
//--- Would this be a 'chomp'???
} else {
AT_MsgCmd=""; //-- This is for RESPONSE like "AT+CGMI" it has only 2 rows of data returned.
fi
Then finally I need to print the report. Also need to "RPAD" Column 2 & 3.. I've used this kind of approach before, but do not know how it translates to ARRAY data:
char myBuffer[35] = {0};
sprintf(myBuffer, "%-6s|", "|AT+CGMI"); //-- This prints: |AT+CGMI |
Serial.print(myBuffer);
I guess the Print out would be something along the lines of this? means some kinda rpad technique to be inserted:
Serial.print(AT_MsgError);
Serial.print(" [");
Serial.print(<RPAD>(GSM_Array[0](i),6); //rpad 6x spaces---how to do this?
Serial.print("] [");
Serial.print(<RPAD>(AT_MsgCmd,6); //rpad 6x spaces---how to do this?
Serial.print("] ");
Serial.println(<RPAD>(GSM_Array[1](i),45); //rpad 45x spaces---how to do this?
delay(500);
Thanks again for you help.
Really do appreciate it.
kr.
[ATTACHMENT:] Here's the Working script, RAW output, and the Required Format we need.....
AT_cmds_Test.V.1.1.4_FORMAT_REPORT_.txt.ino (1.15 KB)
AT_cmds_Test.V.1.1.4_RAW_OUTPUT_.txt.ino (555 Bytes)
AT_cmds_Test.V.1.1.5.ino (2.15 KB)