From: Philippe Nunes <philippe.nunes@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 3/7] qcbsmessage: Extend QCBSMessage class
Date: Mon, 25 Jun 2012 16:37:59 +0200 [thread overview]
Message-ID: <1340635083-5877-4-git-send-email-philippe.nunes@linux.intel.com> (raw)
In-Reply-To: <1340635083-5877-1-git-send-email-philippe.nunes@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 5869 bytes --]
---
src/qcbsmessage.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++-
src/qcbsmessage.h | 7 +++
2 files changed, 146 insertions(+), 1 deletion(-)
diff --git a/src/qcbsmessage.cpp b/src/qcbsmessage.cpp
index fc17ae0..eb360bc 100644
--- a/src/qcbsmessage.cpp
+++ b/src/qcbsmessage.cpp
@@ -51,6 +51,7 @@ public:
uint mUpdateNumber;
uint mChannel;
QCBSMessage::Language mLanguage;
+ uint mDataCodingScheme;
uint mPage;
uint mNumPages;
QString mText;
@@ -268,6 +269,30 @@ void QCBSMessage::setLanguage( QCBSMessage::Language lang )
}
/*!
+ Returns the recommended data coding scheme for encoding CBS text strings.
+ The default value is -1, which indicates that the best scheme should be chosen
+ based on the contents of the CBS text string.
+
+ \sa setDataCodingScheme()
+*/
+int QCBSMessage::dataCodingScheme() const
+{
+ return d->mDataCodingScheme;
+}
+
+/*!
+ Sets the recommended data coding scheme for encoding CBS text strings to \a value.
+ The value -1 indicates that the best scheme should be chosen based on the contents
+ of the CBS text string.
+
+ \sa dataCodingScheme()
+*/
+void QCBSMessage::setDataCodingScheme( int value )
+{
+ d->mDataCodingScheme = value;
+}
+
+/*!
Returns the page number for this cell broadcast message if the
information that it contains is split over multiple pages.
@@ -398,7 +423,14 @@ static QSMSDataCodingScheme bestScheme( const QString& body )
QByteArray QCBSMessage::toPdu() const
{
QCBSDeliverMessage deliver;
- deliver.pack( *this, bestScheme( text() ) );
+ QSMSDataCodingScheme scheme;
+
+ if(dataCodingScheme() == -1)
+ scheme = bestScheme( text() );
+ else
+ scheme = (QSMSDataCodingScheme)dataCodingScheme();
+
+ deliver.pack( *this, scheme );
return deliver.toByteArray();
}
@@ -412,3 +444,109 @@ QCBSMessage QCBSMessage::fromPdu( const QByteArray& pdu )
QCBSDeliverMessage deliver( pdu );
return deliver.unpack();
}
+
+/*!
+ Compute an estimate for the number of pages that will need
+ to be used to send this CBS message (\a numMessages), and the
+ number of spare characters that are left in the last message
+ before it overflows (\a spaceLeftInLast).
+*/
+void QCBSMessage::computeSize( uint& numPages, uint& spaceLeftInLast ) const
+{
+ QString body = text();
+ uint len = body.length();
+ uint scheme= dataCodingScheme();
+
+ if ( scheme == QSMS_DefaultAlphabet ) {
+ // Encode the message using 7-bit GSM.
+ if ( len <= 93 ) { // (82*8)/7 = 93 characters
+ numPages = 1;
+ spaceLeftInLast = 93 - len;
+ } else {
+ numPages = ( len + 92 ) / 93;
+ len %= 93;
+ if ( len != 0 )
+ spaceLeftInLast = 93 - len;
+ else
+ spaceLeftInLast = 0;
+ }
+ } else {
+ // Encode the message with unicode.
+ if ( len <= 40 ) { // 40 = 82/2 - 2 (2 GSM 7-bit ISO 639 characters).
+ numPages = 1;
+ spaceLeftInLast = 40 - len;
+ } else {
+ numPages = ( len + 39 ) / 40;
+ len %= 40;
+ if ( len != 0 )
+ spaceLeftInLast = 40 - len;
+ else
+ spaceLeftInLast = 0;
+ }
+ }
+}
+
+/*!
+ Returns true if this message needs to be split into multiple messages
+ before being transmitted over a GSM network; otherwise returns false.
+
+ \sa split()
+*/
+bool QCBSMessage::shouldSplit() const
+{
+ uint numPages, spaceLeftInLast;
+ this->computeSize( numPages, spaceLeftInLast );
+ return ( numPages <=1 ? false : true );
+}
+
+/*!
+ Split this message into several pages of 88 bytes for
+ transmission over a GSM network.
+
+ \sa shouldSplit()
+*/
+QList<QCBSMessage> QCBSMessage::split() const
+{
+ QList<QCBSMessage> list;
+ uint numPages, spaceLeftInLast;
+
+ computeSize( numPages, spaceLeftInLast );
+ if ( numPages <= 1 ) {
+ // Splitting is not necessary, so return a list with one page.
+ list += *this;
+ return list;
+ }
+
+ // Get the number of characters to transmit in each page.
+ int split;
+ uint scheme= dataCodingScheme();
+
+ switch ( scheme ) {
+ case QSMS_UCS2Alphabet:
+ split = 40; break;
+ case QSMS_DefaultAlphabet:
+ default:
+ split = 93; break;
+ }
+
+ // Split the message to create sub-messages and transmit them.
+ int posn = 0;
+ int len;
+ uint number;
+ QCBSMessage tmp;
+ number = 1;
+ QString txt = text();
+ while ( posn < txt.length() ) {
+ tmp = *this;
+ len = txt.length() - posn;
+ if ( len > split ) {
+ len = split;
+ }
+ tmp.setText( txt.mid( posn, len ) );
+ tmp.setPage( number++ );
+ posn += len;
+ list.append(tmp);
+ }
+
+ return list;
+}
diff --git a/src/qcbsmessage.h b/src/qcbsmessage.h
index 0f86e3e..f6ed364 100644
--- a/src/qcbsmessage.h
+++ b/src/qcbsmessage.h
@@ -76,6 +76,9 @@ public:
QCBSMessage::Language language() const;
void setLanguage( QCBSMessage::Language lang );
+ void setDataCodingScheme(int);
+ int dataCodingScheme() const;
+
uint page() const;
void setPage( uint page );
@@ -93,6 +96,10 @@ public:
QByteArray toPdu() const;
static QCBSMessage fromPdu( const QByteArray& pdu );
+ bool shouldSplit() const;
+ QList<QCBSMessage> split() const;
+ void computeSize( uint& numPages, uint& spaceLeftInLast ) const;
+
private:
QCBSMessagePrivate *d;
};
--
1.7.9.5
next prev parent reply other threads:[~2012-06-25 14:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-25 14:37 [PATCH 0/7] phonesim: Add UCS2 encoding support for CBS/USSD Philippe Nunes
2012-06-25 14:37 ` [PATCH 1/7] control: Fix empty sender checking Philippe Nunes
2012-06-22 8:20 ` Denis Kenzior
2012-06-25 14:37 ` [PATCH 2/7] controbase: Add combobox for CBS scheme selection Philippe Nunes
2012-06-22 8:08 ` Denis Kenzior
2012-06-25 14:37 ` Philippe Nunes [this message]
2012-06-22 14:36 ` [PATCH 3/7] qcbsmessage: Extend QCBSMessage class Denis Kenzior
2012-06-25 14:38 ` [PATCH 4/7] hardwaremanipulator: Add UCS2 encoding support for CBS message Philippe Nunes
2012-06-25 14:38 ` [PATCH 5/7] hardwaremanipulator: Add multi-page " Philippe Nunes
2012-06-22 8:12 ` Denis Kenzior
2012-06-25 14:38 ` [PATCH 6/7] sms: Extend CBS message formating to use UCS2 scheme Philippe Nunes
2012-06-22 14:36 ` Denis Kenzior
2012-06-25 14:38 ` [PATCH 7/7] hardwaremanipulator: Add USC2 encoding support for USSD Philippe Nunes
2012-06-22 14:09 ` Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1340635083-5877-4-git-send-email-philippe.nunes@linux.intel.com \
--to=philippe.nunes@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.