Modified: freeswitch/branches/gmaruzz/mod_gsmopen/gsmopen_protocol.cpp (16125 => 16126)
--- freeswitch/branches/gmaruzz/mod_gsmopen/gsmopen_protocol.cpp 2010-01-03 05:15:23 UTC (rev 16125)
+++ freeswitch/branches/gmaruzz/mod_gsmopen/gsmopen_protocol.cpp 2010-01-03 14:18:37 UTC (rev 16126)
@@ -346,7 +346,7 @@
if (res) {
DEBUGA_GSMOPEN("AT+CMGF? failed, continue\n", GSMOPEN_P_LOG);
}
- res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CMGF=0"); //TODO: support phones that only accept pdu mode
+ res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CMGF=1"); //TODO: support phones that only accept pdu mode
if (res) {
ERRORA("Error setting SMS sending mode to PDU on the cellphone\n", GSMOPEN_P_LOG);
return RESULT_FAILURE;
@@ -496,6 +496,7 @@
{
usleep(10000); /* 10msec */
time(&tech_pvt->gsmopen_serial_synced_timestamp);
+ WARNINGA("CUCU = %ld \n", GSMOPEN_P_LOG, tech_pvt->gsmopen_serial_synced_timestamp);
return 0;
}
int gsmopen_serial_read_AT(private_t * tech_pvt, int look_for_ack, int timeout_usec, int timeout_sec, const char *expected_string, int expect_crlf)
@@ -1478,7 +1479,18 @@
else {
DEBUGA_GSMOPEN("body=%s\n", GSMOPEN_P_LOG, sms_body);
DEBUGA_GSMOPEN("tech_pvt->line_array.result[i]=%s\n", GSMOPEN_P_LOG, tech_pvt->line_array.result[i]);
+ strncpy(tech_pvt->sms_body, tech_pvt->line_array.result[i], sizeof(tech_pvt->sms_body));
+ strncpy(tech_pvt->sms_message, tech_pvt->line_array.result[i], sizeof(tech_pvt->sms_message));
+ char content3[1000];
+ //int howmanyleft;
+
+
+ WARNINGA("sms_message=%s\n", GSMOPEN_P_LOG, tech_pvt->sms_message);
+ ucs2_to_utf8(tech_pvt, tech_pvt->sms_message, content3, sizeof(content3));
+ WARNINGA("content3=%s\n", GSMOPEN_P_LOG, content3);
+ //sleep(10);
+ //cicopet
SMSMessageRef sms;
char content2[1000];
//MessageType messagetype;
@@ -1486,7 +1498,7 @@
//Timestamp servicecentretimestamp;
//Address sender_recipient_address;
-
+#ifdef NOTDEF_GSMLIB
sms = SMSMessage::decode(tech_pvt->line_array.result[i]); // dataCodingScheme = 8 , text=ciao 123 belè новости לק ראת ﺎﻠﺠﻤﻋﺓ 人大
NOTICA("SMS=\n%s\n", GSMOPEN_P_LOG, sms->toString().c_str());
@@ -1524,7 +1536,9 @@
//servicecentretimestamp = sms->serviceCentreTimestamp();
//sender_recipient_address = sms->address();
+#endif //NOTDEF_GSMLIB
+
#if 0
//strncat(tech_pvt->sms_message, "---", ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
//strncat(tech_pvt->sms_message, tech_pvt->line_array.result[i], ((sizeof(tech_pvt->sms_message) - strlen(tech_pvt->sms_message)) - 1));
@@ -1997,11 +2011,15 @@
}
inbytesleft = i;
+ DEBUGA_GSMOPEN("1 ciao in=%s, inleft=%d, out=%s, outleft=%d, converted=%s, utf8_out=%s\n",
+ GSMOPEN_P_LOG, inbuf, (int) inbytesleft, outbuf, (int) outbytesleft, converted, utf8_out);
+
iconv_res = iconv(iconv_format, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
if (iconv_res == (size_t) -1) {
- DEBUGA_GSMOPEN("ciao in=%s, inleft=%d, out=%s, outleft=%d, converted=%s, utf8_out=%s\n",
+ DEBUGA_GSMOPEN("2 ciao in=%s, inleft=%d, out=%s, outleft=%d, converted=%s, utf8_out=%s\n",
GSMOPEN_P_LOG, inbuf, (int) inbytesleft, outbuf, (int) outbytesleft, converted, utf8_out);
- DEBUGA_GSMOPEN("error: %s %d\n", GSMOPEN_P_LOG, strerror(errno), errno);
+ DEBUGA_GSMOPEN("3 error: %s %d\n", GSMOPEN_P_LOG, strerror(errno), errno);
+ iconv_close(iconv_format);
return -1;
}
DEBUGA_GSMOPEN
@@ -3215,3 +3233,163 @@
}
return 0;
}
+
+
+int gsmopen_serial_getstatus_AT(private_t * tech_pvt)
+{
+ int res;
+ private_t *p = tech_pvt;
+
+#if 0
+ if (p->owner) {
+ if (p->owner->_state != AST_STATE_UP && p->owner->_state != AST_STATE_DOWN) {
+ DEBUGA_AT("No getstatus, we're neither UP nor DOWN\n", GSMOPEN_P_LOG);
+ return 0;
+ }
+ }
+#endif
+
+
+ PUSHA_UNLOCKA(p->controldev_lock);
+ LOKKA(p->controldev_lock);
+ res = gsmopen_serial_write_AT_ack(p, "AT");
+ if (res) {
+ ERRORA("AT was not acknowledged, continuing but maybe there is a problem\n",
+ GSMOPEN_P_LOG);
+ }
+ usleep(1000);
+
+ if (strlen(p->at_query_battchg)) {
+ res =
+ gsmopen_serial_write_AT_expect(p, p->at_query_battchg, p->at_query_battchg_expect);
+ if (res) {
+ WARNINGA("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG,
+ p->at_query_battchg, p->at_query_battchg_expect);
+ }
+ usleep(1000);
+ }
+
+ if (strlen(p->at_query_signal)) {
+ res =
+ gsmopen_serial_write_AT_expect(p, p->at_query_signal, p->at_query_signal_expect);
+ if (res) {
+ WARNINGA("%s does not get %s from the phone. Continuing.\n", GSMOPEN_P_LOG,
+ p->at_query_signal, p->at_query_signal_expect);
+ }
+ usleep(1000);
+ }
+ //FIXME all the following commands in config!
+
+ if (p->sms_cnmi_not_supported) {
+ res = gsmopen_serial_write_AT_ack(p, "AT+MMGL=\"HEADER ONLY\"");
+ if (res) {
+ WARNINGA
+ ("%s does not get %s from the phone, probably a long msg is incoming. If it does not go away, and you cannot correctly receive SMSs from this interface, please manually clean all messages from the cellphone/SIM. Continuing.\n",
+ GSMOPEN_P_LOG, "AT+MMGL=\"HEADER ONLY\"", "OK");
+ } else {
+ usleep(1000);
+ if (p->unread_sms_msg_id) {
+ char at_command[256];
+
+ res = gsmopen_serial_write_AT_ack(p, "AT+CSCS=\"UCS2\"");
+ if (res) {
+ ERRORA
+ ("AT+CSCS=\"UCS2\" (set TE messages to ucs2) do not got OK from the phone\n",
+ GSMOPEN_P_LOG);
+ memset(p->sms_message, 0, sizeof(p->sms_message));
+ }
+
+ memset(at_command, 0, sizeof(at_command));
+ sprintf(at_command, "AT+CMGR=%d", p->unread_sms_msg_id);
+ memset(p->sms_message, 0, sizeof(p->sms_message));
+
+ p->reading_sms_msg = 1;
+ res = gsmopen_serial_write_AT_ack(p, at_command);
+ p->reading_sms_msg = 0;
+ if (res) {
+ ERRORA
+ ("AT+CMGR (read SMS) do not got OK from the phone, message sent was:|||%s|||\n",
+ GSMOPEN_P_LOG, at_command);
+ }
+ res = gsmopen_serial_write_AT_ack(p, "AT+CSCS=\"GSM\"");
+ if (res) {
+ ERRORA
+ ("AT+CSCS=\"GSM\" (set TE messages to GSM) do not got OK from the phone\n",
+ GSMOPEN_P_LOG);
+ }
+ memset(at_command, 0, sizeof(at_command));
+ sprintf(at_command, "AT+CMGD=%d", p->unread_sms_msg_id); /* delete the message */
+ p->unread_sms_msg_id = 0;
+ res = gsmopen_serial_write_AT_ack(p, at_command);
+ if (res) {
+ ERRORA
+ ("AT+CMGD (Delete SMS) do not got OK from the phone, message sent was:|||%s|||\n",
+ GSMOPEN_P_LOG, at_command);
+ }
+
+ if (strlen(p->sms_message)) {
+#if 0
+
+ manager_event(EVENT_FLAG_SYSTEM, "GSMOPENincomingsms", "Interface: %s\r\nSMS_Message: %s\r\n", p->name, p->sms_message);
+
+ if (strlen(p->sms_receiving_program)) {
+ int fd1[2];
+ pid_t pid1;
+ char *arg1[] = { p->sms_receiving_program, (char *) NULL };
+ int i;
+
+ DEBUGA_AT("incoming SMS message:---%s---\n", GSMOPEN_P_LOG, p->sms_message);
+ pipe(fd1);
+ pid1 = fork();
+
+ if (pid1 == 0) { //child
+ int err;
+
+ dup2(fd1[0], 0); // Connect stdin to pipe output
+ close(fd1[1]); // close input pipe side
+ setsid(); //session id
+ err = execvp(arg1[0], arg1); //exec our program, with stdin connected to pipe output
+ if (err) {
+ ERRORA
+ ("'sms_receiving_program' is set in config file to '%s', and it gave us back this error: %d, (%s). SMS received was:---%s---\n",
+ GSMOPEN_P_LOG, p->sms_receiving_program, err, strerror(errno),
+ p->sms_message);
+ }
+ close(fd1[0]); // close output pipe side
+ } //starting here continue the parent
+ close(fd1[0]); // close output pipe side
+ // write the msg on the pipe input
+ for (i = 0; i < strlen(p->sms_message); i++) {
+ write(fd1[1], &p->sms_message[i], 1);
+ }
+ close(fd1[1]); // close pipe input, let our program know we've finished
+ } else {
+ ERRORA
+ ("got SMS incoming message, but 'sms_receiving_program' is not set in config file. SMS received was:---%s---\n",
+ GSMOPEN_P_LOG, p->sms_message);
+ }
+#endif //0
+ WARNINGA ("got SMS incoming message. SMS received was:---%s---\n", GSMOPEN_P_LOG, p->sms_message);
+ }
+#if 0 //is this one needed? maybe it can interrupt an incoming call that is just to announce itself
+ if (p->phone_callflow == CALLFLOW_CALL_IDLE
+ && p->interface_state == AST_STATE_DOWN && p->owner == NULL) {
+ /* we're not in a call, neither calling */
+ res = gsmopen_serial_write_AT_ack(p, "AT+CKPD=\"EEE\"");
+ if (res) {
+ ERRORA
+ ("AT+CKPD=\"EEE\" (cellphone screen back to user) do not got OK from the phone\n",
+ GSMOPEN_P_LOG);
+ }
+ }
+#endif
+ }
+ }
+ }
+
+ UNLOCKA(p->controldev_lock);
+ POPPA_UNLOCKA(p->controldev_lock);
+ return 0;
+}
+
+