private static string DecodeAddress(byte[] pduData, int start, out int elementLength) { int length = pduData[start]; int coding = pduData[start + 1]; int digitStart = start + 2; StringBuilder builder = new StringBuilder(); /* 1 byte digit count, 1 byte numbering scheme plus the number of nibbles/2 */ elementLength = 1 + 1 + (length + 1) / 2; switch (coding & 0x7F) { case 0x50: /* alphanumeric */ string message = GSM7Bit.Decode(pduData, digitStart, ((length * 4) / 7), 0); builder.Append(message); break; default: char[] characters = new[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '#', 'a', 'b', 'c', ' ', }; for (int digit = 0; digit < length; digit++) { long bcd = (pduData[digitStart + digit / 2] >> (4 * (digit % 2))) & 0x0F; builder.Append(characters[bcd]); } break; } return(builder.ToString()); }
private static string DecodeGSM7Bit(byte[] pduData, int start, int skipBytes, int charCount) { try { return(GSM7Bit.Decode(pduData, start, charCount, (skipBytes * 8 + 6) / 7)); } catch (Exception e) { return("(DecodeGSM7Bit failed)"); } }
public bool Handle(byte[] data) { int lpd = (data[0] >> 5) & 3; int seq = data[0] & 0x0f; if (lpd != 1 || data.Length < 23) { return(false); } if (Sequence != seq) { Sequence = 0; return(false); } Array.Copy(data, 1, CBCBuffer, seq * 22, 22); Sequence++; /* final packet */ if (Sequence >= 4) { bool emergency = ((CBCBuffer[0] >> 5) & 0x01) == 1; bool popup = ((CBCBuffer[0] >> 4) & 0x01) == 1; int messageCode = (((CBCBuffer[0] << 8) | CBCBuffer[1]) >> 4) & 0xFF; int updateNr = CBCBuffer[1] & 0xF; int messageIdent = (CBCBuffer[2] << 8) | CBCBuffer[3]; int dataCoding = CBCBuffer[4]; int pageParam = CBCBuffer[5]; Array.Copy(CBCBuffer, 6, CBMessage, 0, CBMessage.Length); if (ShowCBMessages) { StatusMessage = "Cell Broadcast: "; if (emergency) { StatusMessage += "[Emergency] "; } if (popup) { StatusMessage += "[Popup] "; } StatusMessage += "[Channel " + messageIdent + "] "; StatusMessage += "[Update " + updateNr + "] "; StatusMessage += "[Code " + messageCode + "] "; StatusMessage += "[Coding 0x" + String.Format("{0:X2}", dataCoding) + "] "; StatusMessage += "[Page 0x" + String.Format("{0:X2}", pageParam) + "] "; StatusMessage += Environment.NewLine; StatusMessage += " '" + GSM7Bit.Decode(CBMessage) + "'" + Environment.NewLine; } else { StatusMessage = null; } Sequence = 0; } return(true); }