Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto encoding #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ modem.sms(message, callback)
* text `String` message body. Longs messages will be splitted and
sent in multiple parts transparently.
* receiver `String` receiver number.
* encoding `String`. '16bit' or '7bit'. Use 7bit in case of English messages.
* encoding (optional) `String`. '16bit' or '7bit'. Use 7bit in case of English messages. If `encoding` is not specified, the program will choose the best according to characters in `text`

callback `Fucntion`(err, references) is called when sending is done.
* references `Array` contains reference ids for each part of sent message. (A message may take up to several parts)
Expand Down
20 changes: 20 additions & 0 deletions lib/modem.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ var createModem = function() {

modem.sms = function(message, callback) {
var i = 0;
message.encoding = message.encoding || this.autoEncoding(message.text);
var pdus = pdu.generate(message);
var ids = [];

Expand Down Expand Up @@ -349,6 +350,25 @@ var createModem = function() {
this.execute('AT+CLIP=1');
});

modem.autoEncoding = function(text){
//choose best encoding depending of the text
var sevenBitCharacters = new Array('@', '£', '$', '¥', 'è', 'é', 'ù', 'ì', 'ò', 'Ç', '\n', 'Ø', 'ø', '\r','Å', 'å','\u0394', '_', '\u03a6', '\u0393', '\u039b', '\u03a9', '\u03a0','\u03a8', '\u03a3', '\u0398', '\u039e', 'Æ', 'æ', 'ß', 'É', ' ', '!', '"', '#', '¤', '%', '&', '\'', '(', ')','*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7','8', '9', ':', ';', '<', '=', '>', '?', '¡', 'A', 'B', 'C', 'D', 'E','F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S','T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Ä', 'Ö', 'Ñ', 'Ü', '§', '¿', 'a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o','p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'ä', 'ö', 'ñ','ü', 'à',
'^', '{', '}', '\\', '[', '~', ']', '|', '€');
for (var k in text){
var found = false;
var character = text[k];
for(var i=0;i<sevenBitCharacters.length;i++)
{
if(sevenBitCharacters[i] == character){
found = true;
continue
}
}
if (found == false) {return '16bit';}
}
return '7bit';
}

modem.deleteMessage = function(index, cb) {
modem.execute('AT+CMGD='+index, cb);
}
Expand Down