Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Array itself is the one index of an 2d array ie, strings[i][so_far[i]]

Status
Not open for further replies.

saramah

Member level 3
Member level 3
Joined
Apr 25, 2018
Messages
64
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
689
hI,

When I was terying to understand the tutorials from
HTML:
https://circuitdigest.com/microcontroller-projects/gsm-interfacing-with-pic16f877a
, the below 2d array is found.

Code:
if (strings[i][so_far[i]] == received)
.

what i understand, it is a 2-D array, and 'so_far[]' array itself is one of the another index of 'string' array. But my qestion is how this operate in the code below as mentioned in the aricle:
Code:
/*
#define SIM900_OK 1
#define SIM900_READY 2
#define SIM900_FAIL 3
#define SIM900_RING 4
#define SIM900_NC 5
#define SIM900_UNLINK 6
*/
inline unsigned char _SIM900_waitResponse(void) 
{
    unsigned char so_far[6] = {0,0,0,0,0,0};
    unsigned const char lengths[6] = {2,12,5,4,6,6};
    unsigned const char* strings[6] = {"OK", "+CPIN: READY", "ERROR", "RING", "NO CARRIER", "Unlink"};
    unsigned const char responses[6] = {SIM900_OK, SIM900_READY, SIM900_FAIL, SIM900_RING, SIM900_NC, SIM900_UNLINK};
    unsigned char received;
    unsigned char response;
    char continue_loop = 1;
    while (continue_loop) 
    {
        received = _SIM900_getch();
        for (unsigned char i = 0; i < 6; i++) 
        {
            if (strings[i][so_far[i]] == received) 
            {
                so_far[i]++;
                if (so_far[i] == lengths[i]) 
                {
                    response = responses[i];
                    continue_loop = 0;
                }
            } 
            
            else
            {
                so_far[i] = 0;
            }
        }
    }
    return response;
}

how //if (strings[so_far] == received) this line being implemented. if i had been recived "O" for "OK" at 'received' variable from calling fun //_SIM900_getch();
I REQUEST TO MAKE ME UNDERSTAND IF POSSIBLE..
TNX
 

The code is receiving input from the GSM modem and staying in the loop until one of the six expected responses in strings[] is detected.

so_far[] keeps track of the already matched characters in each compare string.

For the details, you should review the string processing chapter in a C programming text book.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top