When I was terying to understand the tutorials from, https://circuitdigest.com/microcontroller-projects/gsm-interfacing-with…, the below 2d array is found.
if (strings[i][so_far[i]] == received)
but how this line being implemented in the code.
could anybody explain plaese??
tnx
unsigned char so_far[6] = {0
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,
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;
}
}
}
To understand the code you should not just look into the line, but rather the complete code block shown below. As you can see so_far, lengths, strings, responses these all are variable types that have been declared already.
The purpose of the code is to check what character is being received from the GSM module. The received information should be any one form the 6 string variable thats is "OK", "+CPIN: READY", "ERROR", "RING", "NO CARRIER" or "Unlink".
The length of these information is also defined with the variable lengths and the output that should be given to each of these information is also defined in the variable responces. Now coming to your line
strings[i][so_far[i]]
As you might have already noticed the information from the GSM module is read charector by charector, so to check if we have received any particular string we have to breakdown the string to that particular charector and compare it to the received charector. So when i=0
strings[0][so_far[0]] = "O"
Bradyen
Permalink- Log in or register to post comments
Joined August 14, 2018 44Tuesday at 03:25 PM