/// <summary> /// convert ASCII character to baudot printable character and replacement character /// </summary> /// <param name="asciiChr"></param> /// <returns></returns> private static string AsciiCharToTelex(char asciiChr, CodeSets codeSet) { AsciiConvItem[] asciiToTelexTab; switch (codeSet) { default: case CodeSets.ITA2: asciiToTelexTab = _asciiIta2Tab; break; //case CodeSets.ITA2EXT: // asciiToTelexTab = _asciiIta2ExtTab; // break; case CodeSets.USTTY: asciiToTelexTab = _asciiUsTtyTab; break; } string asciiData = CodePage437ToPlainAscii(asciiChr); string telexData = ""; for (int i = 0; i < asciiData.Length; i++) { foreach (AsciiConvItem convItem in asciiToTelexTab) { string ascii = convItem.GetCodeInRange(asciiData[i]); if (!string.IsNullOrEmpty(ascii)) { telexData += ascii; } } } return(telexData); }
private async Task <bool> CmdSendFile(string filename) { CodeSets codeSet = ConfigManager.Instance.Config.CodeSet; string[] lines; try { //string text = ConvertText(File.ReadAllText(filename)); lines = File.ReadAllLines(filename); } catch (Exception) { return(false); } foreach (string line in lines) { List <string> wrappedLines = WrapLine(line, CharWidth); foreach (string wrappedLine in wrappedLines) { if (_stopScript) { return(false); } string convLine = ConvertText(wrappedLine, codeSet).Trim(); await SendTextLine(convLine + "\r\n"); Debug.WriteLine($"SendBufferCount={_bufferManager.SendBufferCount}"); } } return(true); }
private void CheckCodeSetCategory(string category) { if (CodeSets.Any(x => x.Category == category)) { throw new Exception("A CodeSet for the Category '" + category + "' already exists in (" + Jurisdiction.Ori + ")"); } }
/// <summary> /// convert ASCII string to printable characters and replacement characters /// </summary> /// <param name="asciiStr"></param> /// <param name="nobrackets">true: do not convert various forms of brackets</param> /// <returns></returns> public static string AsciiStringToTelex(string asciiStr, CodeSets codeSet, bool noBracketConversion = false) { string telexStr = ""; for (int i = 0; i < asciiStr.Length; i++) { telexStr += AsciiCharToTelex(asciiStr[i], codeSet, noBracketConversion); } return(telexStr); }
/// <summary> /// convert ASCII string to printable characters and replacement characters /// </summary> /// <param name="asciiStr"></param> /// <returns></returns> public static string AsciiStringToTelex(string asciiStr, CodeSets codeSet) { string telexStr = ""; for (int i = 0; i < asciiStr.Length; i++) { telexStr += AsciiCharToTelex(asciiStr[i], codeSet); } return(telexStr); }
public string ConvertText(string text, CodeSets codeSet) { string newText = ""; foreach (char chr in text) { newText += ConvertTextChar(chr, codeSet); } return(newText); }
public string ConvertTextChar(char chr, CodeSets codeSet) { string scripChar = @"{}\"; if (scripChar.Contains(chr)) { return(chr.ToString()); } return(CodeManager.AsciiCharToTelex(chr, codeSet, true)); }
/// <summary> /// Change the Category of a CodeSet in this Agency. /// </summary> /// <param name="codeSetId"></param> /// <param name="category"></param> public void ChangeCodeSetCategory(Guid codeSetId, string category) { CheckCodeSetCategory(category); var codeSet = CodeSets.FirstOrDefault(x => x.Id == codeSetId); if (codeSet == null) { throw new Exception("CodeSet does not belong to this Agency."); } codeSet.ChangeCategory(category); }
private static byte?FindBaudot(char asciiChar, ShiftStates shiftState, CodeSets codeSet) { for (int c = 0; c < 32; c++) { char chr = _codeTab[c].GetCode(shiftState, codeSet); if (chr == asciiChar) { return((byte)c); } } return(null); }
public static string CodeSetToString(CodeSets std) { switch (std) { default: case CodeSets.ITA2: return("ITA-2"); //case CodeSets.ITA2EXT: // return "ITA-2 EXT"; case CodeSets.USTTY: return("US-TTY"); } }
private static ICodeTab GetCodeTab(CodeSets codeSet) { switch (codeSet) { case CodeSets.ITA2: default: return(new CodeTabIta2()); case CodeSets.USTTY: return(new CodeTabUstty()); case CodeSets.CYRILL: return(new CodeTabCyrill()); } }
public static string CodeSetToString(CodeSets std) { switch (std) { default: case CodeSets.ITA2: return("ITA-2"); case CodeSets.USTTY: return("US-TTY"); case CodeSets.CYRILL: return("CYRILL"); } }
private static byte?FindBaudot(char asciiChar, ShiftStates shiftState, CodeSets codeSet) { if (codeSet == CodeSets.CYRILL && ConfigManager.Instance.Config.CodeSet != CodeSets.CYRILL) { return(null); } for (byte c = 0; c < 32; c++) { CodeItem codeItem = GetCodeItem(codeSet, c); char chr = codeItem.GetChar(shiftState); if (chr == asciiChar) { return(c); } } return(null); }
public string GetName(ShiftStates shiftState, CodeSets codeSet) { string name; switch (shiftState) { case ShiftStates.Ltr: case ShiftStates.Both: name = NameLtr[(int)codeSet]; break; case ShiftStates.Figs: name = NameFig[(int)codeSet]; break; default: case ShiftStates.Unknown: name = null; break; } if (name == null) { name = CodeManager.ASC_INV.ToString(); /* * if (ext && CharExt != null) * { * name = NameExt; * } * else * { * name = CodeConversion.ASC_INV.ToString(); * } */ } return(name); }
public char GetCode(ShiftStates shiftState, CodeSets codeSet) { char?chr; switch (shiftState) { case ShiftStates.Ltr: case ShiftStates.Both: chr = CharLtr[(int)codeSet]; break; case ShiftStates.Figs: chr = CharFig[(int)codeSet]; break; default: case ShiftStates.Unknown: chr = null; break; } if (chr == null) { chr = CodeManager.ASC_INV; /* * if (ext && CharExt!=null) * { * chr = CharExt.Value; * } * else * { * chr = CodeConversion.ASC_INV; * } */ } return(chr.Value); }
/// <summary> /// convert any ASCII character to a baudot printable ASCII character or replacement character /// </summary> /// <param name="asciiChr"></param> /// <param name="nobracketConversion">true: do not convert various forms of brackets</param> /// <returns></returns> public static string AsciiCharToTelex(char asciiChr, CodeSets codeSet, bool noBracketConversion = false) { if (noBracketConversion && BRACKETS.Contains(asciiChr)) { return(""); } ICodeTab codeTab = GetCodeTab(codeSet); string asciiData = CodePageToPlainAscii(asciiChr, codeSet); string telexData = ""; for (int i = 0; i < asciiData.Length; i++) { foreach (AsciiConvItem convItem in codeTab.AsciiTab) { string ascii = convItem.GetCodeInRange(asciiData[i]); if (!string.IsNullOrEmpty(ascii)) { telexData += ascii; } } } return(telexData); }
public static string BaudotCodeToPuncherText(byte baudotCode, ShiftStates shiftState, CodeSets codeSet) { if (baudotCode > 0x1F) { return(ASC_INV.ToString()); } return(_codeTab[baudotCode].GetName(shiftState, codeSet)); }
public static byte[] TelexStringToBaudot(string telexStr, ref ShiftStates shiftState, CodeSets codeSet) { byte[] buffer = new byte[0]; for (int i = 0; i < telexStr.Length; i++) { byte[] baudotData = TelexCharToBaudotWithShift(telexStr[i], ref shiftState, codeSet); buffer = buffer.Concat(baudotData).ToArray(); } return(buffer); }
public KeyStates(ShiftStates shiftState, CodeSets codeSet) { ShiftState = shiftState; CodeSet = codeSet; }
public KeyStates() { ShiftState = ShiftStates.Unknown; CodeSet = CodeSets.ITA2; }
public static byte[] TelexCharToBaudotWithShift(char telexChr, ref ShiftStates shiftState, CodeSets codeSet) { byte? ltrCode = FindBaudot(telexChr, ShiftStates.Ltr, codeSet); byte? figCode = FindBaudot(telexChr, ShiftStates.Figs, codeSet); byte baudCode; ShiftStates newShiftState; if (ltrCode != null && figCode != null) { baudCode = ltrCode.Value; newShiftState = ShiftStates.Both; } else if (ltrCode != null) { baudCode = ltrCode.Value; newShiftState = ShiftStates.Ltr; } else if (figCode != null) { baudCode = figCode.Value; newShiftState = ShiftStates.Figs; } else { return(new byte[0]); } return(BaudotCodeToBaudotWithShift(baudCode, newShiftState, ref shiftState)); }
public static CodeItem GetCodeItem(CodeSets codeSet, byte code) { return(GetCodeTab(codeSet).CodeTab[code]); }
/* * public static CodeItem FindBaudot(char asciiChar, KeyStates keyStates) * { * for (byte c = 0; c < 32; c++) * { * CodeItem codeItem = GetCodeItem(keyStates.CodeSet, c); * * if (codeItem.GetChar(ShiftStates.Ltr, keyStates.ThirdLevelState) == asciiChar) * { * keyStates.ShiftState = ShiftStates.Ltr; * return codeItem; * } * if (codeItem.GetChar(ShiftStates.Figs, keyStates.ThirdLevelState) == asciiChar) * { * keyStates.ShiftState = ShiftStates.Figs; * return codeItem; * } * } * keyStates.ShiftState = ShiftStates.Unknown; * return null; * } */ private static string CodePageToPlainAscii(char asciiChar, CodeSets codeSet) { switch (asciiChar) { case 'ä': case 'Ä': return("ae"); case 'á': case 'à': case 'â': case 'Á': case 'À': case 'Â': return("a"); case 'ö': case 'Ö': return("oe"); case 'ó': case 'ò': case 'ô': case 'Ó': case 'Ò': case 'Ô': return("o"); case 'ü': case 'Ü': return("ue"); case 'ú': case 'ù': case 'Ú': case 'Ù': case 'û': case 'Û': return("u"); case 'ß': return("ss"); case '°': return("o"); default: if (asciiChar < 128) { return(asciiChar.ToString()); } else if (asciiChar >= 0x0410 && asciiChar <= 0x044F) { return(asciiChar.ToString()); } else { return(""); } } /* * switch (codeSet) * { * case CodeSets.ITA2: * case CodeSets.USTTY: * default: * return CodePage437ToPlainAscii(asciiChar); * case CodeSets.CYRILL: * return CodeCyrillToPlanAscii(asciiChar); * } */ }
public static string BaudotStringToAscii(byte[] baudotData, ref ShiftStates shiftState, CodeSets codeSet, SendRecv sendRecv) { string asciiStr = ""; for (int i = 0; i < baudotData.Length; i++) { byte baudotChr = baudotData[i]; if (baudotChr == BAU_LTRS) { shiftState = ShiftStates.Ltr; } else if (baudotChr == BAU_FIGS) { shiftState = ShiftStates.Figs; } else { char asciiChr = BaudotCharToAscii(baudotData[i], shiftState, codeSet, sendRecv); asciiStr += asciiChr; } } return(asciiStr); }
public static char BaudotCharToAscii(byte baudotCode, ShiftStates shiftState, CodeSets codeSet, SendRecv sendRecv) { if (baudotCode > 0x1F) { return((char)ASC_INV); } char asciiChr = _codeTab[baudotCode].GetCode(shiftState, codeSet); /* * if (asciiChr == ASC_INV && sendRecv==SendRecv.Recv) * { * // received an invalid code: try extended code page * asciiChr = _codeTab[baudotCode].GetCode(shiftState, CodeSets.ITA2EXT); * } */ return(asciiChr); }
public static byte[] AsciiStringToBaudot(string asciiStr, ref ShiftStates shiftState, CodeSets codeSet) { byte[] baudotData = new byte[0]; for (int i = 0; i < asciiStr.Length; i++) { string telexData = AsciiCharToTelex(asciiStr[i], codeSet); byte[] data = TelexStringToBaudot(telexData, ref shiftState, codeSet); baudotData = baudotData.Concat(data).ToArray(); } return(baudotData); }