Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
convert from UTF-8 to UCS-2 before packing the PDU
Browse files Browse the repository at this point in the history
  • Loading branch information
bjyoungblood committed Sep 12, 2011
1 parent 49f937e commit 05851b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
15 changes: 10 additions & 5 deletions lib/models/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ var sms = function(sender, recipient, message, sequence_number) {
self.failureTimeout = null;

self.toPdu = function(command) {
var payload = pack.pack(
'a1cca' + (self.sender.length + 1) + 'cca' + (self.recipient.length + 1) + 'ccca1a1cccccU' + (Buffer.byteLength(self.message, 'utf8')),
var payload, ucs2message, iconv;

iconv = new Iconv('UTF-8', 'UCS-2//TRANSLIT//IGNORE');
ucs2message = iconv.convert(self.message);

payload = pack.pack(
'a1cca' + (self.sender.length + 1) + 'cca' + (self.recipient.length + 1) + 'ccca1a1cccccU' + (ucs2message.length),
"", //service_type
0x00, //source_addr_ton
0x00, //source_addr_npi
Expand All @@ -54,10 +59,10 @@ var sms = function(sender, recipient, message, sequence_number) {
"", //validity_period
0x00, //a couple fields,
0x00,
0x03,
0x08,
0x00,
Buffer.byteLength(self.message), //message length
self.message); //message
ucs2message.length, //message length
ucs2message); //message

return pdu.createPdu(command, self.sequence_number, payload);
};
Expand Down
19 changes: 12 additions & 7 deletions lib/models/utils/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,20 @@ exports.pack = function(format) {
repeater = parseInt(repeater, 10);
}

for (j = 0; j <= repeater; j++) {
chrj = arguments[argi].charAt(j);
if (typeof arguments[argi] == "string") {
for (j = 0; j <= repeater; j++) {
chrj = arguments[argi].charAt(j);

if (j >= arguments[argi].length) {
break;
}

if (j >= arguments[argi].length) {
break;
packed.write(chrj, bufferOffset);
bufferOffset += Buffer.byteLength(chrj);
}

packed.write(chrj, bufferOffset);
bufferOffset += Buffer.byteLength(chrj);
} else {
arguments[argi].copy(packed, bufferOffset, 0, repeater);
bufferOffset += repeater;
}

argi++;
Expand Down

0 comments on commit 05851b3

Please sign in to comment.