/*
#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;
}