public void SetCallSign(String stationID) { StationIDInfo tmpID = Validate(stationID); stationIDString = tmpID.staString; stationSSID = tmpID.staSSID; tmpID.staBuf.CopyTo(stationBytes, 0); stationBytes[6] = (Byte)((stationSSID << 1) | 0x60); }
StationIDInfo Validate(String stationID) { // // Validate the format and characters in the incoming callsign. Throws an exception if any illegal // characters are found or the format is invalid // Char[] s1 = { '-' }; String validChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"; Int32 i; Exception ex = new Exception("Bad callsign supplied:" + stationID); StationIDInfo retID = new StationIDInfo(); stationID = stationID.ToUpper().Trim(); foreach (Char c in stationID) { if (!validChar.Contains(c.ToString())) { throw ex; } } String[] a = stationID.Split(s1); if ((a.Length > 2) || (a[0].Length > 6)) { throw ex; } if (a.Length == 2) { retID.staSSID = Convert.ToInt32(a[1]); if (retID.staSSID > 15) { throw ex; } } retID.staString = a[0] + "-" + retID.staSSID.ToString(); stationID = a[0].PadRight(6, ' '); Byte[] tmpB = Encoding.ASCII.GetBytes(stationID); for (i = 0; i < 6; i++) { retID.staBuf[i] = (Byte)(tmpB[i] << 1); } return(retID); }