js/sms_message_analyser.js
/** 
 * Encode message according to the "GSM default" alphabet.
 * The function is being initialized with the "message" input by the user.
 * The function returns:
 * - the message in its "encoded" (hex) "PDU" representation,
 * - the charset used,
 * - the number of "encoded" message characters,
 * - the number of "hex" characters that represent the "encoded" message text.
 */
Encode message according to the "GSM default" alphabet.
The function is being initialized with the "message" input by the user.
Encode message according to the " GSM default " alphabet . The function is being initialized with the " message " input by the user .
function encode_GSM(msg) {
  if (msg === null) {
    return null;
  }
  var pdu = [];
  try {
    var len = msg.length;
    for (i = 0; i < len; i++) {	
      var search = 0;
      var c = msg.charAt(i);
      for (; search < CHAR_TABLE.length; search++) {
        if (search == EXTENDED_ESCAPE) {
          continue;
        }
        if (c === CHAR_TABLE[search]) {		
          pdu.push(intToHex(search));
          break;
        }
        if (c === EXT_CHAR_TABLE[search]) {
          pdu.push(intToHex(EXTENDED_ESCAPE));
          pdu.push(intToHex(search));
          break;
        }
      }
      if (search == CHAR_TABLE.length) {
        pdu.push(ToHex(0x3f));
      }
    }
  } catch (e) {
    document.getElementById('pdu_error_id').innerHTML = "Impossible error with byte array: " + e;
	return null;
  }
  return {
    pdu: pdu.join(''),
    pdu_characters: pdu.length,
    pdu_hex_characters: pdu.length * 2,
    pdu_encoding: "GSM"
  };
}
function encode_GSM ( msg ) { if ( msg === null ) { return null ; } var pdu = [ ] ; try { var len = msg . length ; for ( i = 0 ; i < len ; i ++ ) { var search = 0 ; var c = msg . charAt ( i ) ; for ( ; search < CHAR_TABLE . length ; search ++ ) { if ( search == EXTENDED_ESCAPE ) { continue ; } if ( c === CHAR_TABLE [ search ] ) { pdu . push ( intToHex ( search ) ) ; break ; } if ( c === EXT_CHAR_TABLE [ search ] ) { pdu . push ( intToHex ( EXTENDED_ESCAPE ) ) ; pdu . push ( intToHex ( search ) ) ; break ; } } if ( search == CHAR_TABLE . length ) { pdu . push ( ToHex ( 0x3f ) ) ; } } } catch ( e ) { document . getElementById ( 'pdu_error_id' ) . innerHTML = "Impossible error with byte array: " + e ; return null ; } return { pdu : pdu . join ( '' ) , pdu_characters : pdu . length , pdu_hex_characters : pdu . length * 2 , pdu_encoding : "GSM" } ; }
Encode message according to the "GSM default" alphabet.
Encode message according to the " GSM default " alphabet .
/** Input message null; exit immediately. */ /** 
   * Initialize "PDU" array. Each array position will hold a character, in "hex" format, encoded according to the "GSM default" alphabet. 
   * So in practice, each position will hold either a single character or the "escape" character followed by another character, in both cases
   * in the proper "hex" encoded form.
   */ /** Store message length. */ /** Loop through all message characters encoding each one of those according to the "GSM default" alphabet. */ /**Initialize a character table index. */ /** Get the char at the current index in this string. */ /** 
	   * Loop through the "GSM" character tables ("default" and "extended") and "convert" the current character 
	   * to its (hex) encoded form. 
	   */ /** Check whether the current message character can be found at the current "index" in the "GSM default" character table. */ /** 
		   * "Encode" current message character by converting the decimal value of the current table "index" into its "hex" form and 
		   * push it into the "PDU" array. 
		   */ /** No reason to go-on with the table look-up; exit loop immediately. */ /** "Else" check whether the current message character can be found at the current "index" in the "GSM extended" character table. */ /** 
		   * "Encode" current message character by converting the decimal value of the "escape" character into its "hex" form and 
		   * push it into the "PDU" array. 
		   */ /** 
		   * "Encode" current message character by converting the decimal value of the current table "index" into its "hex" form and 
		   * push it into the "PDU" array. 		   
		   */ /** No reason to go-on with the table look-up; exit loop immediately. */ /** Search has been completed without finding a "match" for the current message character; push a "?" into the "PDU" array. */ /** Exception thrown; print error message and exit immediately. */ /** Return an "object" consisting of: */ /** the message in its "encoded" (hex) "PDU" representation. */ /** 
	 * the number of "encoded" message characters; keep in mind that in case where a character of the input
	 * "message" is part of the "Extended" character table, then this specific character will be 
	 * "encoded" into the "escape" character followed by another character; so in practice the "total" length
	 * of the "encoded" message (PDU) will be greater than the length of the input "message" if there is 
	 * at least one "extended" character.
	 */ /** 
	 * the number of "hex" characters that represent the "encoded" message text; one "encoded" char is 
	 * represented by one "hex" number (two "hex" chars).
	 */ /** the charset used; "GSM" by default of course. */