예제 #1
0
        /// <summary>
        /// convert ASCII string to printable characters and replacement characters
        /// </summary>
        /// <param name="asciiStr"></param>
        /// <returns></returns>
        public static string AsciiStringToTelex(string asciiStr, CodeStandards codeStd)
        {
            string telexStr = "";

            for (int i = 0; i < asciiStr.Length; i++)
            {
                telexStr += AsciiCharToTelex(asciiStr[i], codeStd);
            }
            return(telexStr);
        }
예제 #2
0
 private static byte?FindBaudot(int shift, char telexChar, CodeStandards codeStd)
 {
     // search ascii chars to find baudot code
     char[,] _codeTab = codeStd == CodeStandards.Ita2 ? _codeTabEu : _codeTabUs;
     for (int c = 0; c < 32; c++)
     {
         if (_codeTab[shift, c] == telexChar)
         {
             return((byte)c);
         }
     }
     return(null);
 }
예제 #3
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, CodeStandards codeStd)
        {
            Dictionary <byte, string> asciiToTelexTab =
                codeStd == CodeStandards.Ita2 ? _asciiToTelexTabEu : _asciiToTelexTabUs;

            string asciiData = _codePage437ToAsciiTab(asciiChr);
            string telexData = "";

            for (int i = 0; i < asciiData.Length; i++)
            {
                //telexData += _asciiToTelexTab[(int)asciiData[i]];
                byte data = (byte)asciiData[i];
                if (asciiToTelexTab.ContainsKey(data))
                {
                    telexData += asciiToTelexTab[data];
                }
            }
            return(telexData);
        }
예제 #4
0
 public static byte[] AsciiStringToBaudot(string asciiStr, ref ShiftStates shiftState, CodeStandards codeStd)
 {
     byte[] baudotData = new byte[0];
     for (int i = 0; i < asciiStr.Length; i++)
     {
         string telexData = AsciiCharToTelex(asciiStr[i], codeStd);
         byte[] data      = TelexStringToBaudot(telexData, ref shiftState, codeStd);
         baudotData = baudotData.Concat(data).ToArray();
     }
     return(baudotData);
 }
예제 #5
0
        public static string BaudotCodeToPuncherText(byte baudotCode, ShiftStates shiftState, CodeStandards codeStd)
        {
            string[,] codeTab = codeStd == CodeStandards.Ita2 ? _codeTabPuncherEu : _codeTabPuncherUs;

            switch (shiftState)
            {
            case ShiftStates.Ltr:
                return(codeTab[LTRS, baudotCode]);

            case ShiftStates.Figs:
                return(codeTab[FIGS, baudotCode]);

            default:
                return("");
            }
        }
예제 #6
0
        public static char BaudotCharToAscii(byte baudotCode, ShiftStates shiftState, CodeStandards codeStd)
        {
            if (baudotCode > 0x1F)
            {
                return((char)ASC_INV);
            }

            char[,] codeTab = codeStd == CodeStandards.Ita2 ? _codeTabEu : _codeTabUs;

            switch (shiftState)
            {
            case ShiftStates.Unknown:
            default:
                return(ASC_INV);

            case ShiftStates.Ltr:
                return(codeTab[LTRS, baudotCode]);

            case ShiftStates.Figs:
                return(codeTab[FIGS, baudotCode]);
            }
        }
예제 #7
0
        public static string BaudotStringToAscii(byte[] baudotData, ref ShiftStates shiftState, CodeStandards codeStd)
        {
            string asciiStr = "";

            for (int i = 0; i < baudotData.Length; i++)
            {
                byte baudotChr = baudotData[i];
                if (baudotChr == BAU_LTR)
                {
                    shiftState = ShiftStates.Ltr;
                }
                else if (baudotChr == BAU_FIG)
                {
                    shiftState = ShiftStates.Figs;
                }
                else
                {
                    char asciiChr = BaudotCharToAscii(baudotData[i], shiftState, codeStd);
                    asciiStr += asciiChr;
                }
            }
            return(asciiStr);
        }
예제 #8
0
        public static byte[] TelexCharToBaudotWithShift(char telexChr, ref ShiftStates shiftState, CodeStandards codeStd)
        {
            byte?       ltrCode = FindBaudot(LTRS, telexChr, codeStd);
            byte?       figCode = FindBaudot(FIGS, telexChr, codeStd);
            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));
        }
예제 #9
0
 public static byte[] TelexStringToBaudot(string telexStr, ref ShiftStates shiftState, CodeStandards codeStd)
 {
     byte[] buffer = new byte[0];
     for (int i = 0; i < telexStr.Length; i++)
     {
         byte[] baudotData = TelexCharToBaudotWithShift(telexStr[i], ref shiftState, codeStd);
         buffer = buffer.Concat(baudotData).ToArray();
     }
     return(buffer);
 }