in ch-commons-gsm/src/main/java/com/cloudhopper/commons/gsm/DataCoding.java [343:418]
static public DataCoding parse(byte dcs) {
try {
// if bits 7 thru 4 are all off, this represents a simple character encoding group
if ((dcs & (byte)0xF0) == 0x00) {
// the raw dcs value is exactly our 16 possible languaged
return createCharacterEncodingGroup(dcs);
// if bits 7 thru 4 are all on, this represents a message class group
} else if ((dcs & (byte)0xF0) == (byte)0xF0) {
// bit 2 is the language encoding
byte characterEncoding = CHAR_ENC_DEFAULT;
if ((dcs & (byte)0x04) == (byte)0x04) {
characterEncoding = CHAR_ENC_8BIT;
}
// bits 1 thru 0 is the message class
byte messageClass = (byte)(dcs & (byte)0x03);
return createMessageClassGroup(characterEncoding, messageClass);
// at this point if bits 7 and 6 are off, then general data coding group
} else if ((dcs & (byte)0xC0) == (byte)0x00) {
// bit 5 represents "compression"
boolean compressed = false;
if ((dcs & (byte)0x20) == (byte)0x20) {
compressed = true;
}
// bits 1 thru 0 is the message class
byte tempMessageClass = (byte)(dcs & (byte)0x03);
Byte messageClass = null;
// bit 4 on means the message class becomes used
if ((dcs & (byte)0x10) == (byte)0x10) {
messageClass = new Byte(tempMessageClass);
}
// bits 3 and 2 represent the language encodings (nicely match default, 8-bit, or UCS2)
byte characterEncoding = (byte)(dcs & (byte)0x0C);
return createGeneralGroup(characterEncoding, messageClass, compressed);
// at this point if bits 7 and 6 are on, then bits 5 and 4 determine MWI
} else if ((dcs & (byte)0xC0) == (byte)0xC0) {
// bit 5: 0=default, 1=UCS2
byte characterEncoding = CHAR_ENC_DEFAULT;
if ((byte)(dcs & (byte)0x20) == 0x20) {
characterEncoding = CHAR_ENC_UCS2;
}
// bit 4: 0=discard, 1=store
boolean store = false;
if ((byte)(dcs & (byte)0x10) == 0x10) {
store = true;
}
// bit 3: indicator active
boolean indicatorActive = false;
if ((byte)(dcs & (byte)0x08) == 0x08) {
indicatorActive = true;
}
// bit 2: means nothing
// bit 1 thru 0 is the type of indicator
byte indicatorType = (byte)(dcs & (byte)0x03);
return createMessageWaitingIndicationGroup(characterEncoding, store, indicatorActive, indicatorType);
} else {
return createReservedGroup(dcs);
}
} catch (IllegalArgumentException e) {
return createReservedGroup(dcs);
}
}