diff --git a/README.md b/README.md index 732d54b..f3bc53c 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lib/modem.js b/lib/modem.js index 55322cb..abbcb75 100644 --- a/lib/modem.js +++ b/lib/modem.js @@ -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 = []; @@ -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