gsmopen: added gsmlib support to outbound smss (eg: PDU mode). Must implement a mechanism to fall back sending in UCS2 when characters cannot be represented in iso-8859-1 (gsmlib does not support utf)
This commit is contained in:
parent
a621cdee99
commit
a4df4fa1f4
|
@ -593,7 +593,7 @@ read:
|
|||
msecs_passed += 20;
|
||||
|
||||
if (timeout_in_msec != 100){
|
||||
ERRORA("TIMEOUT=%d, PASSED=%d\n", GSMOPEN_P_LOG, timeout_in_msec, msecs_passed);
|
||||
//ERRORA("TIMEOUT=%d, PASSED=%d\n", GSMOPEN_P_LOG, timeout_in_msec, msecs_passed);
|
||||
}
|
||||
//read_count = tech_pvt->serialPort_serial_control->Readv(tmp_answer_ptr, AT_BUFSIZ - (tmp_answer_ptr - tmp_answer), (timeout_sec * 1000) + (timeout_usec ? (timeout_usec / 1000) : 0));
|
||||
read_count = tech_pvt->serialPort_serial_control->Read(tmp_answer_ptr, AT_BUFSIZ - (tmp_answer_ptr - tmp_answer));
|
||||
|
@ -1687,24 +1687,6 @@ read:
|
|||
|
||||
|
||||
|
||||
#ifdef NOTDEF_SENDING_EXAMPLE
|
||||
SMSMessageRef smsMessage;
|
||||
// message text has probably to be in 8859-1
|
||||
smsMessage = new SMSSubmitMessage("submit me ", "3472665618");
|
||||
cout << smsMessage->toString() << endl;
|
||||
string pdu = smsMessage->encode();
|
||||
cout << pdu << endl;
|
||||
//cout << intToStr(pdu.length() / 2 - getSCAddressLen()) << endl;
|
||||
cout << intToStr(pdu.length() / 2 - 1) << endl;
|
||||
|
||||
/*
|
||||
string pdu = encode();
|
||||
Parser p(_at->sendPdu("+CMGS=" +
|
||||
intToStr(pdu.length() / 2 - getSCAddressLen()),
|
||||
"+CMGS:", pdu));
|
||||
*/
|
||||
#endif// NOTDEF_SENDING_EXAMPLE
|
||||
|
||||
#endif// WANT_GSMLIB
|
||||
|
||||
|
||||
|
@ -2353,10 +2335,55 @@ int ucs2_to_utf8(private_t *tech_pvt, char *ucs2_in, char *utf8_out, size_t outb
|
|||
#endif //WIN32
|
||||
return 0;
|
||||
}
|
||||
int utf8_to_iso_8859_1(private_t *tech_pvt, char *utf8_in, size_t inbytesleft, char *iso_8859_1_out, size_t outbytesleft)
|
||||
{
|
||||
/* cicopet */
|
||||
#ifndef WIN32
|
||||
iconv_t iconv_format;
|
||||
int iconv_res;
|
||||
char *outbuf;
|
||||
char *inbuf;
|
||||
|
||||
outbuf = iso_8859_1_out;
|
||||
inbuf = utf8_in;
|
||||
|
||||
iconv_format = iconv_open("ISO_8859-1", "UTF8");
|
||||
if (iconv_format == (iconv_t) -1) {
|
||||
ERRORA("error: %s\n", GSMOPEN_P_LOG, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
outbytesleft = strlen(utf8_in) * 2;
|
||||
|
||||
DEBUGA_GSMOPEN("in=%s, inleft=%d, out=%s, outleft=%d, utf8_in=%s, iso_8859_1_out=%s\n",
|
||||
GSMOPEN_P_LOG, inbuf, (int) inbytesleft, outbuf, (int) outbytesleft, utf8_in, iso_8859_1_out);
|
||||
iconv_res = iconv(iconv_format, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
|
||||
if (iconv_res == (size_t) -1) {
|
||||
ERRORA("error: %s %d\n", GSMOPEN_P_LOG, strerror(errno), errno);
|
||||
return -1;
|
||||
}
|
||||
DEBUGA_GSMOPEN
|
||||
("iconv_res=%d, in=%s, inleft=%d, out=%s, outleft=%d, utf8_in=%s, iso_8859_1_out=%s\n",
|
||||
GSMOPEN_P_LOG, iconv_res, inbuf, (int) inbytesleft, outbuf, (int) outbytesleft, utf8_in, iso_8859_1_out);
|
||||
iconv_close(iconv_format);
|
||||
#if 0
|
||||
for (i = 0; i < 16000 - outbytesleft; i++) {
|
||||
memset(stringa, '\0', sizeof(stringa));
|
||||
memset(stringa2, '\0', sizeof(stringa2));
|
||||
sprintf(stringa, "%02X", converted[i]);
|
||||
DEBUGA_GSMOPEN("character is |%02X|\n", GSMOPEN_P_LOG, converted[i]);
|
||||
stringa2[0] = stringa[strlen(stringa) - 2];
|
||||
stringa2[1] = stringa[strlen(stringa) - 1];
|
||||
strncat(iso_8859_1_out, stringa2, ((outbytesleft - strlen(iso_8859_1_out)) - 1)); //add the received line to the buffer
|
||||
DEBUGA_GSMOPEN("stringa=%s, stringa2=%s, iso_8859_1_out=%s\n", GSMOPEN_P_LOG, stringa, stringa2, iso_8859_1_out);
|
||||
}
|
||||
#endif //0
|
||||
#endif //WIN32
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int iso_8859_1_to_utf8(private_t *tech_pvt, char *iso_8859_1_in, char *utf8_out, size_t outbytesleft)
|
||||
{
|
||||
char converted[16000];
|
||||
#ifndef WIN32
|
||||
iconv_t iconv_format;
|
||||
int iconv_res;
|
||||
|
@ -2368,8 +2395,6 @@ int iso_8859_1_to_utf8(private_t *tech_pvt, char *iso_8859_1_in, char *utf8_out,
|
|||
//double hexnum;
|
||||
//int i = 0;
|
||||
|
||||
memset(converted, '\0', sizeof(converted));
|
||||
|
||||
DEBUGA_GSMOPEN("iso_8859_1_in=%s\n", GSMOPEN_P_LOG, iso_8859_1_in);
|
||||
|
||||
outbuf = utf8_out;
|
||||
|
@ -2656,17 +2681,94 @@ int gsmopen_sendsms(private_t *tech_pvt, char *dest, char *text)
|
|||
if (tech_pvt->controldevprotocol == PROTOCOL_AT) {
|
||||
char smscommand[16000];
|
||||
memset(smscommand, '\0', sizeof(smscommand));
|
||||
char pdu2[16000];
|
||||
memset(pdu2, '\0', sizeof(pdu2));
|
||||
int pdulenght = 0;
|
||||
|
||||
PUSHA_UNLOCKA(&tech_pvt->controldev_lock);
|
||||
LOKKA(tech_pvt->controldev_lock);
|
||||
|
||||
#ifndef WANT_GSMLIB
|
||||
err = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CMGF=1");
|
||||
if (err) {
|
||||
ERRORA("AT+CMGF=1 (set message sending to TEXT (as opposed to PDU) do not got OK from the phone\n", GSMOPEN_P_LOG);
|
||||
}
|
||||
#else// WANT_GSMLIB
|
||||
err = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CMGF=0");
|
||||
if (err) {
|
||||
ERRORA("AT+CMGF=0 (set message sending to TEXT (as opposed to PDU) do not got OK from the phone\n", GSMOPEN_P_LOG);
|
||||
}
|
||||
#endif// WANT_GSMLIB
|
||||
|
||||
|
||||
if (tech_pvt->no_ucs2 || tech_pvt->sms_pdu_not_supported == 0) {
|
||||
#ifdef WANT_GSMLIB
|
||||
SMSMessageRef smsMessage;
|
||||
|
||||
memset(mesg_test, '\0', sizeof(mesg_test));
|
||||
sprintf(mesg_test,":) ciao belè новости לק ראת ﺎﻠﺠﻤﻋﺓ 人大aèéàòçù"); //let's test the beauty of utf8
|
||||
//text=mesg_test;
|
||||
|
||||
utf8_to_iso_8859_1(tech_pvt, text, strlen(text), smscommand, sizeof(smscommand));
|
||||
smsMessage = new SMSSubmitMessage(smscommand, dest);
|
||||
string pdu = smsMessage->encode();
|
||||
strncpy(pdu2, pdu.c_str(), sizeof(pdu2)-1);
|
||||
memset(smscommand, '\0', sizeof(smscommand));
|
||||
pdulenght = pdu.length() / 2 - 1;
|
||||
sprintf(smscommand, "AT+CMGS=%d", pdulenght);
|
||||
|
||||
#ifdef NOTDEF
|
||||
char content2[1000];
|
||||
SMSMessageRef sms;
|
||||
//MessageType messagetype;
|
||||
//Address servicecentreaddress;
|
||||
//Timestamp servicecentretimestamp;
|
||||
//Address sender_recipient_address;
|
||||
|
||||
sms = SMSMessage::decode(tech_pvt->line_array.result[i]); // dataCodingScheme = 8 , text=ciao 123 belè новости לק ראת ﺎﻠﺠﻤﻋﺓ 人大
|
||||
|
||||
DEBUGA_GSMOPEN("SMS=\n%s\n", GSMOPEN_P_LOG, sms->toString().c_str());
|
||||
|
||||
memset(content2, '\0', sizeof(content2));
|
||||
if (sms->dataCodingScheme().getAlphabet() == DCS_DEFAULT_ALPHABET) {
|
||||
iso_8859_1_to_utf8(tech_pvt, (char *) sms->userData().c_str(), content2, sizeof(content2));
|
||||
} else if (sms->dataCodingScheme().getAlphabet() == DCS_SIXTEEN_BIT_ALPHABET) {
|
||||
ucs2_to_utf8(tech_pvt, (char *) bufToHex((unsigned char *) sms->userData().data(), sms->userData().length()).c_str(), content2,
|
||||
sizeof(content2));
|
||||
} else {
|
||||
ERRORA("dataCodingScheme not supported=%d\n", GSMOPEN_P_LOG, sms->dataCodingScheme().getAlphabet());
|
||||
|
||||
}
|
||||
DEBUGA_GSMOPEN("dataCodingScheme=%d\n", GSMOPEN_P_LOG, sms->dataCodingScheme().getAlphabet());
|
||||
DEBUGA_GSMOPEN("dataCodingScheme=%s\n", GSMOPEN_P_LOG, sms->dataCodingScheme().toString().c_str());
|
||||
DEBUGA_GSMOPEN("address=%s\n", GSMOPEN_P_LOG, sms->address().toString().c_str());
|
||||
DEBUGA_GSMOPEN("serviceCentreAddress=%s\n", GSMOPEN_P_LOG, sms->serviceCentreAddress().toString().c_str());
|
||||
DEBUGA_GSMOPEN("serviceCentreTimestamp=%s\n", GSMOPEN_P_LOG, sms->serviceCentreTimestamp().toString().c_str());
|
||||
DEBUGA_GSMOPEN("messageType=%d\n", GSMOPEN_P_LOG, sms->messageType());
|
||||
DEBUGA_GSMOPEN("userData= |||%s|||\n", GSMOPEN_P_LOG, content2);
|
||||
|
||||
|
||||
memset(sms_body, '\0', sizeof(sms_body));
|
||||
strncpy(sms_body, content2, sizeof(sms_body));
|
||||
DEBUGA_GSMOPEN("body=%s\n", GSMOPEN_P_LOG, sms_body);
|
||||
strncpy(tech_pvt->sms_body, sms_body, sizeof(tech_pvt->sms_body));
|
||||
strncpy(tech_pvt->sms_sender, sms->address().toString().c_str(), sizeof(tech_pvt->sms_sender));
|
||||
strncpy(tech_pvt->sms_date, sms->serviceCentreTimestamp().toString().c_str(), sizeof(tech_pvt->sms_date));
|
||||
strncpy(tech_pvt->sms_datacodingscheme, sms->dataCodingScheme().toString().c_str(), sizeof(tech_pvt->sms_datacodingscheme));
|
||||
strncpy(tech_pvt->sms_servicecentreaddress, sms->serviceCentreAddress().toString().c_str(),
|
||||
sizeof(tech_pvt->sms_servicecentreaddress));
|
||||
tech_pvt->sms_messagetype = sms->messageType();
|
||||
//messagetype = sms->messageType();
|
||||
//servicecentreaddress = sms->serviceCentreAddress();
|
||||
//servicecentretimestamp = sms->serviceCentreTimestamp();
|
||||
//sender_recipient_address = sms->address();
|
||||
#endif// NOTDEF
|
||||
|
||||
#else// WANT_GSMLIB
|
||||
ERRORA("tech_pvt->no_ucs2 || tech_pvt->sms_pdu_not_supported == 0 && no WANT_GSMLIB\n", GSMOPEN_P_LOG);
|
||||
return RESULT_FAILURE;
|
||||
#endif// WANT_GSMLIB
|
||||
|
||||
if (tech_pvt->no_ucs2) {
|
||||
sprintf(smscommand, "AT+CMGS=\"%s\"", dest); //TODO: support phones that only accept pdu mode
|
||||
} else {
|
||||
char dest2[1048];
|
||||
|
||||
|
@ -2677,11 +2779,8 @@ int gsmopen_sendsms(private_t *tech_pvt, char *dest, char *text)
|
|||
|
||||
memset(dest2, '\0', sizeof(dest2));
|
||||
utf8_to_ucs2(tech_pvt, dest, strlen(dest), dest2, sizeof(dest2));
|
||||
sprintf(smscommand, "AT+CMGS=\"%s\"", dest2); //TODO: support phones that only accept pdu mode
|
||||
sprintf(smscommand, "AT+CMGS=\"%s\"", dest2);
|
||||
}
|
||||
//TODO: support phones that only accept pdu mode
|
||||
//TODO would be better to lock controldev here
|
||||
//sprintf(smscommand, "AT+CMGS=\"%s\"", dest); //FIXME: nokia e63 want this
|
||||
err = gsmopen_serial_write_AT_noack(tech_pvt, smscommand);
|
||||
if (err) {
|
||||
ERRORA("Error sending SMS\n", GSMOPEN_P_LOG);
|
||||
|
@ -2716,6 +2815,7 @@ int gsmopen_sendsms(private_t *tech_pvt, char *dest, char *text)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef WANT_GSMLIB
|
||||
memset(mesg_test, '\0', sizeof(mesg_test));
|
||||
sprintf(mesg_test,":) ciao belè новости לק ראת ﺎﻠﺠﻤﻋﺓ 人大aèéàòçù"); //let's test the beauty of utf8
|
||||
//text=mesg_test;
|
||||
|
@ -2726,7 +2826,11 @@ int gsmopen_sendsms(private_t *tech_pvt, char *dest, char *text)
|
|||
} else {
|
||||
utf8_to_ucs2(tech_pvt, text, strlen(text), smscommand, sizeof(smscommand));
|
||||
}
|
||||
#else // WANT_GSMLIB
|
||||
|
||||
memset(smscommand, '\0', sizeof(smscommand));
|
||||
sprintf(smscommand, "%s", pdu2);
|
||||
#endif // WANT_GSMLIB
|
||||
smscommand[strlen(smscommand)] = 0x1A;
|
||||
DEBUGA_GSMOPEN("smscommand len is: %d, text is:|||%s|||\n", GSMOPEN_P_LOG, (int) strlen(smscommand), smscommand);
|
||||
|
||||
|
|
Loading…
Reference in New Issue