Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 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 + ")");
     }
 }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <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);
        }
Beispiel #6
0
        public string ConvertText(string text, CodeSets codeSet)
        {
            string newText = "";

            foreach (char chr in text)
            {
                newText += ConvertTextChar(chr, codeSet);
            }
            return(newText);
        }
Beispiel #7
0
        public string ConvertTextChar(char chr, CodeSets codeSet)
        {
            string scripChar = @"{}\";

            if (scripChar.Contains(chr))
            {
                return(chr.ToString());
            }

            return(CodeManager.AsciiCharToTelex(chr, codeSet, true));
        }
Beispiel #8
0
        /// <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);
        }
Beispiel #9
0
 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);
 }
Beispiel #10
0
        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");
            }
        }
Beispiel #11
0
        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());
            }
        }
Beispiel #12
0
        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");
            }
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        /// <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);
        }
Beispiel #17
0
 public static string BaudotCodeToPuncherText(byte baudotCode, ShiftStates shiftState, CodeSets codeSet)
 {
     if (baudotCode > 0x1F)
     {
         return(ASC_INV.ToString());
     }
     return(_codeTab[baudotCode].GetName(shiftState, codeSet));
 }
Beispiel #18
0
 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);
 }
Beispiel #19
0
 public KeyStates(ShiftStates shiftState, CodeSets codeSet)
 {
     ShiftState = shiftState;
     CodeSet    = codeSet;
 }
Beispiel #20
0
 public KeyStates()
 {
     ShiftState = ShiftStates.Unknown;
     CodeSet    = CodeSets.ITA2;
 }
Beispiel #21
0
        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));
        }
Beispiel #22
0
 public static CodeItem GetCodeItem(CodeSets codeSet, byte code)
 {
     return(GetCodeTab(codeSet).CodeTab[code]);
 }
Beispiel #23
0
        /*
         * 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);
             * }
             */
        }
Beispiel #24
0
        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);
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
 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);
 }