implement function for SMS reading
This commit is contained in:
parent
85f8da54a5
commit
796be414fc
@ -109,3 +109,64 @@ bool gammu_send_sms(const char* message)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool gammu_read_sms()
|
||||||
|
{
|
||||||
|
GSM_MultiSMSMessage sms;
|
||||||
|
|
||||||
|
// Variable for SMS sender number
|
||||||
|
char sender_number[20];
|
||||||
|
memset(&sender_number, 0, sizeof(sender_number));
|
||||||
|
|
||||||
|
/* Connect to phone */
|
||||||
|
/* 1 means number of replies you want to wait for */
|
||||||
|
error = GSM_InitConnection(state_machine, 1);
|
||||||
|
if (!check_gammu_error(error))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* Prepare for reading message */
|
||||||
|
error = ERR_NONE;
|
||||||
|
sms.Number = 0;
|
||||||
|
sms.SMS[0].Location = 0;
|
||||||
|
sms.SMS[0].Folder = 0;
|
||||||
|
|
||||||
|
log_debug("Trying to read SMS...",DEBUG_ALL);
|
||||||
|
|
||||||
|
error = GSM_GetNextSMS(state_machine, &sms, TRUE);
|
||||||
|
if (error == ERR_EMPTY) return true;
|
||||||
|
if (!check_gammu_error(error))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Now we can do something with the message
|
||||||
|
for (int i = 0; i < sms.Number; i++)
|
||||||
|
{
|
||||||
|
strncpy(sender_number,DecodeUnicodeConsole(sms.SMS[i].Number),19);
|
||||||
|
char dbg_tmp[100];
|
||||||
|
sprintf(dbg_tmp,"Number: '%s'", sender_number);
|
||||||
|
log_debug(dbg_tmp,DEBUG_ALL);
|
||||||
|
|
||||||
|
// special hack for Motorola L7
|
||||||
|
sms.SMS[i].Location-=100000;
|
||||||
|
|
||||||
|
if (sms.SMS[i].Coding == SMS_Coding_8bit) {
|
||||||
|
log_event("gammu sms error: 8-bit message, can not read");
|
||||||
|
// remove SMS
|
||||||
|
GSM_DeleteSMS(state_machine,&sms.SMS[i]);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
sprintf(dbg_tmp,"Text: \"%s\"\n", DecodeUnicodeConsole(sms.SMS[i].Text));
|
||||||
|
log_debug(dbg_tmp,DEBUG_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove SMS after reading
|
||||||
|
error = GSM_DeleteSMS(state_machine,&sms.SMS[i]);
|
||||||
|
if (!check_gammu_error(error))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Terminate connection */
|
||||||
|
error = GSM_TerminateConnection(state_machine);
|
||||||
|
if (!check_gammu_error(error))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user