> 1.5.2 | UCS2 and GSM data coding and conversion for SMS text mode and Remote SAT

> This section provides basic information on how to handle input and output character conversion for SMS text mode and Remote SAT if internal (TA) and external (TE) character representation differ, i.e. if the Data Coding Scheme and the TE character use different coding.

> 1.5.2.1 | Implementing output of SIM data to Terminal (direction TA to TE)

> Used character set | DCS = 7 bit GSM | DCS = 8 bit Data | DCS = 16 bit UCS2
> GSM | Case 1 GSM (1:1) | Case 2 8 bit to IRA (1:2) | Case 3 UCS2 to IRA (2:4)
> UCS2 | Case 4 GSM to IRA (1:4) | Case 5 8 bit to IRA (1:4) | Case 6 UCS2 to IRA (2:4)

> Note: The ratio of SIM bytes to output bytes is given in parentheses.
> Case 1
> Every GSM character is sent to the TE as it is (8-bit value with highest bit set to zero).
> Example: 47'H, 53'H, 4D'H → 47'H, 53'H, 4D'H, displayed as "GSM"
> Case 2
> Every data byte is sent to the TE as 2 IRA characters each representing a halfbyte.
> Example: B8'H (184 decimal) → 42'H, 38'H, displayed as "B8"
> Case 3
> Every 16-bit UCS2 value is sent to the TE as 4 IRA characters.
> Example: C4xA7'H (50343 decimal) → 43'H, 34'H, 41'H, 37'H, displayed as "C4A7"
> Problem: An odd number of bytes leads to an error because there are always two bytes needed for each USC2 character
> Case 4
> Every GSM character is sent to the TE as 4 IRA characters to show UCS2 in text mode.
> Example: 41'H ("A") → 30'H, 30'H, 34'H, 31'H, displayed as "0041"
> Case 5
> Every data byte is sent to the TE as IRA representation of UCS2 (similar to case 4).
> Example: B2'H → 30'H, 30'H, 42'H, 32'H, displayed as "00B2"
> Case 6
> Every 16-bit value is sent to the TE as IRA representation of it. It is assumed that number of bytes is even.
> Example: C3x46'H → 43'H, 33'H, 34'H, 36'H, displayed as "C346"

> 1.5.2.2 | Implementing input of Terminal data to SIM (direction TE to TA)

> Used character set | DCS = 7 bit GSM | DCS = 8 bit Data | DCS = 16 bit UCS2
> GSM | Case 1 GSM (1:1) | Case 2 IRA to 8 bit (2:1) | Case 3 IRA to 16 bit (4:2)
> UCS2 | Case 4 UCS2 to GSM (4:1) | Case 5 UCS2 to 8 bit (4:1) | Case 6 UCS2 to 16 bit (4:2)

> Note: The ratio between the number of input characters and bytes stored on the SIM is given in parentheses.
> Case 1
> Every character is sent from TE to TA as GSM character (or ASCII with standard terminal emulation, e.g. Hyperterminal).
> Character value must be in range from 0 to 127 because of 7-bit GSM alphabet.
> To reach maximum SMS text length of 160 characters in 140 bytes space characters will be compressed on SIM. This must be set using the parameter <dcs> of AT+CSMP (add 64).
> Example: "ABCDEFGH" typed is sent and stored uncompressed as → 4142434445464748'H (stored compressed as 41E19058341E91'H)
> Case 2
> Every data byte is sent as 2 IRA characters.
> Maximum text length is 280 IRA characters which will be converted into 140 bytes SMS binary user data
> Example: "C8" typed is sent as 43'H, 38'H → stored as C8'H
> Case 3
> Every 16-bit value is sent as 4 IRA characters.
> Maximum text length is 280 IRA characters which will be converted into 70 UCS2 characters (16-bit each)
> Number of IRA characters must be a multiple of four because always 4 half bytes are needed for a 16-bit value
> Example: "D2C8" typed is sent as 44'H, 32'H, 43'H, 38'H → stored as D2C8'H
> Case 4
> Every GSM character is sent as 4 IRA characters representing one UCS2 character.
> Example: To store text "ABC" using UCS2 character set you have to type "004100420043".
> This is sent as 30'H,30'H,34'H,31'H, 30'H,30'H,34'H,32'H, 30'H,30'H,34'H,33'H → detected as IRA representation of 3 UCS2 characters, converted to GSM character set and stored as 41'H, 42'H, 43'H.
> Maximum input is 640 IRA characters repesenting 160 UCS2 characters when compression is active. These are converted to 160 GSM 7-bit characters.
> Without compression only 140 GSM characters can be stored which are put in as 560 IRA characters.
> Values of UCS2 characters must be smaller than 80'H (128 decimal) to be valid GSM characters.
> Number of IRA characters must be a multiple of four. Problems:
> • "41" → Error, there are four IRA characters (two bytes) needed
> • "0000" → Error, not an UCS2 character
> • "4142" → Error, value of UCS2 character > 7F'H
> • "008B" → Error, value of UCS2 character > 7F'H
> This affects the maximum input length of a string)
> Case 5
> Every UCS2 character is sent as 4 IRA characters and is converted into two 8-bit values. This means that the first two characters have to be '00'.
> Example: UCS2 character 009F'H typed as "009F" is sent as 30'H,30'H,39'H,46'H → converted into 8-bit value 9F'H.
> Maximum number of UCS2 characters is 140 which are represented by 560 IRA characters. Number of IRA characters must be a multiple of four.
> Case 6
> Every UCS2 character is sent as 4 IRA characters each and is converted into a 16-bit value again.
> Example: UCS2 character 9F3A'H typed as "9F3A" is sent as 39'H,46'H,33'H,41'H → converted into 9F3A'H.
> Maximum number of UCS2 characters is 70 which are represented by 280 IRA characters. Number of IRA characters must be a multiple of four.
> Invalid UCS2 values must be prevented.