I can’t say for certain which arrays I will use, but I wanted to try something very basic, specifically, obtaining the message number, its status, and length. To do this, I need to find all phrases of the “+CMGL: 15,1,155” type and trim the alphabetic part. It seems like I’ve gone through all the necessary steps: found all occurrences of such phrases, created an array of these occurrences, found the length of each phrase, and created an array with their values. However, when I try to trim them, only the first phrase gets trimmed for some reason, even though there’s an array of occurrence positions created next to it and some other unclear chunk. Could you please take a look and let me know where my mistake might be?
#The variable where all the unprocessed SMS messages go
:local modemOutput ( [ /interface lte at-chat lte1 wait=yes input="AT+CMGL=4" as-value ]->"output" );
#Four variables for the counter.
:local matchPosition -1;
:local matchCount 0;
:local previous 0
:local continue true;
#The array where all occurrences of the found line endings are collected.
:local whereEnd ([:toarray ""]);
#The array where all the values of the phrase length, such as "+CMGL: 15,1,,155", are collected
:local arrayLen ({})
#An array where all positions of the occurrence of the phrase go
:local arrayHead ({})
#An array where all trimmed data from a phrase like "15,1,,155" should go
:local arrayStat ({})
#The loop for finding all the identified line ending characters.
while ( $continue ) do={
:set matchPosition [ :find $modemOutput $search $matchPosition ];
:if ( [ :typeof $matchPosition ] != "nil" ) do={
:set matchCount ( $matchCount + 1 );
# :put ( "Find position #" . [ :tostr $matchCount ] . " at: " . $matchPosition );
:set $whereEnd ($whereEnd, $matchPosition)
} else={ :set continue false; };
};
#The loop for creating an array where all the calculated lengths of phrases like "+CMGL: 15,1,,155" are stored.
:foreach key,num in=$whereEnd do={
if (($key % 2) = 0) do={
:put "$($num - $previous)"
:set $arrayLen ($arrayLen, $num - $previous)
} else={
:set previous $num
#:put "Find position #$key at:$num"
}
}
#Checking the result
:put $whereEnd
:put $arrayLen
#The loop for searching and creating an array from the results of trimming the phrase "+CMGL: 15,1,,155".
:local continue true;
while ( $continue ) do={
:set matchPosition [ :find $modemOutput $searchHead $matchPosition ];
:put $arrayLen
:if ( [ :typeof $matchPosition ] != "nil" ) do={
:set matchCount ( $matchCount + 1 );
:put ( "Find position #" . [ :tostr $matchCount ] . " at: " . $matchPosition );
:set $arrayHead ($arrayHead, $matchPosition)
:set $arrayStat ($arrayStat, [:pick $modemOutput ($matchPosition+7) ($arrayLen->$matchCount) ] )
} else={ :set continue false; };
};
#Checking the result
:put $arrayHead
:put $arrayStat
Perhaps I have chosen not the most optimal approach, but I am just starting to learn scripts, and I am trying to go from simple to complex in order to develop a solid understanding.
I want to add that all the screen outputs are done for result verification purposes, to make it easier to understand where and at which stage the data exists.