Example #1
0
 public static byte[] TelexStringToBaudot(string telexStr, KeyStates keyStates)
 {
     byte[] buffer = new byte[0];
     for (int i = 0; i < telexStr.Length; i++)
     {
         byte[] baudotData = TelexCharToBaudotWithShift(telexStr[i], keyStates);
         buffer = buffer.Concat(baudotData).ToArray();
     }
     return(buffer);
 }
Example #2
0
        public static char BaudotCharToAscii(byte baudotCode, KeyStates keyStates, SendRecv sendRecv)
        {
            if (baudotCode > 0x1F)
            {
                return(ASC_INVALID);
            }

            CodeItem codeItem = GetCodeItem(keyStates.CodeSet, baudotCode);

            return(codeItem.GetChar(keyStates.ShiftState));
        }
Example #3
0
        public static string BaudotCodeToPuncherText(byte baudotCode, KeyStates keyStates)
        {
            if (baudotCode > 0x1F)
            {
                return(ASC_INVALID.ToString());
            }

            CodeItem codeItem = GetCodeItem(keyStates.CodeSet, baudotCode);
            char     codeChar = codeItem.GetChar(keyStates.ShiftState);
            string   codeName = GetCodeName(codeChar, LanguageManager.Instance.CurrentLanguage.Key);

            if (!string.IsNullOrEmpty(codeName))
            {
                return(codeName);
            }
            return(codeItem.GetName(keyStates.ShiftState));
        }
Example #4
0
        public static string BaudotStringToAscii(byte[] baudotData, KeyStates keyStates, SendRecv sendRecv, bool debug)
        {
            string asciiStr = "";

            for (int i = 0; i < baudotData.Length; i++)
            {
                byte baudotChr = baudotData[i];
                if (baudotChr == BAU_LTRS)
                {
                    keyStates.ShiftState = ShiftStates.Ltr;
                    if (debug)
                    {
                        asciiStr += ASC_LTRS;
                    }
                }
                else if (baudotChr == BAU_FIGS)
                {
                    keyStates.ShiftState = ShiftStates.Figs;
                    if (debug)
                    {
                        asciiStr += ASC_FIGS;
                    }
                }
                else if (baudotChr == BAU_NUL)
                {
                    bool hasThirdLevel = GetCodeTab(keyStates.CodeSet).HasThirdLevel;
                    if (hasThirdLevel)
                    {
                        keyStates.ShiftState = ShiftStates.Third;
                    }
                    if (debug)
                    {
                        asciiStr += ASC_NUL;
                    }
                }
                else
                {
                    char asciiChr = BaudotCharToAscii(baudotData[i], keyStates, sendRecv);
                    asciiStr += asciiChr;
                }
            }
            return(asciiStr);
        }
Example #5
0
 public static byte[] AsciiStringToBaudot(string asciiStr, KeyStates keyStates)
 {
     byte[] baudotData = new byte[0];
     for (int i = 0; i < asciiStr.Length; i++)
     {
         char   chr = asciiStr[i];
         byte[] data;
         if (chr >= 128 && chr <= 255)
         {
             data = new byte[] { (byte)(chr - 128) };
         }
         else
         {
             string telexData = AsciiCharToTelex(asciiStr[i], keyStates.CodeSet);
             data = TelexStringToBaudot(telexData, keyStates);
         }
         baudotData = baudotData.Concat(data).ToArray();
     }
     return(baudotData);
 }
Example #6
0
        public static byte[] TelexCharToBaudotWithShift(char telexChr, KeyStates keyStates)
        {
            byte?       ltrCode    = FindBaudot(telexChr, ShiftStates.Ltr, keyStates.CodeSet);
            byte?       figCode    = FindBaudot(telexChr, ShiftStates.Figs, keyStates.CodeSet);
            byte?       thirdLevel = FindBaudot(telexChr, ShiftStates.Third, keyStates.CodeSet);
            byte        baudCode;
            ShiftStates newShiftState;

            if (ltrCode != null && figCode != null)
            {
                baudCode      = ltrCode.Value;
                newShiftState = ShiftStates.Both;
            }
            //else if (keyStates.ShiftState == ShiftStates.Third && ltrCode != null)
            //{
            //	baudCode = ltrCode.Value;
            //	newShiftState = ShiftStates.Third;
            //}
            else if (ltrCode != null)
            {
                baudCode      = ltrCode.Value;
                newShiftState = ShiftStates.Ltr;
            }
            else if (figCode != null)
            {
                baudCode      = figCode.Value;
                newShiftState = ShiftStates.Figs;
            }
            else if (thirdLevel != null)
            {
                baudCode      = thirdLevel.Value;
                newShiftState = ShiftStates.Third;
            }
            else
            {
                return(new byte[0]);
            }

            return(BaudotCodeToBaudotWithShift(baudCode, newShiftState, keyStates));
        }
Example #7
0
        public static byte[] BaudotCodeToBaudotWithShift(byte baudCode, ShiftStates newShiftState, KeyStates keyStates)
        {
            byte[] buffer = new byte[0];

            if (baudCode == BAU_LTRS)
            {
                buffer = Helper.AddByte(buffer, BAU_LTRS);
                keyStates.ShiftState = ShiftStates.Ltr;
                return(buffer);
            }
            if (baudCode == BAU_FIGS)
            {
                buffer = Helper.AddByte(buffer, BAU_FIGS);
                keyStates.ShiftState = ShiftStates.Figs;
                return(buffer);
            }
            if (baudCode == BAU_NUL)
            {
                bool hasThirdLevel = GetCodeTab(keyStates.CodeSet).HasThirdLevel;
                if (hasThirdLevel)
                {
                    keyStates.ShiftState = ShiftStates.Third;
                }
                buffer = Helper.AddByte(buffer, BAU_NUL);
                return(buffer);
            }

            if (keyStates.ShiftState == ShiftStates.Unknown && newShiftState == ShiftStates.Unknown)
            {
                buffer        = Helper.AddByte(buffer, BAU_LTRS);
                newShiftState = ShiftStates.Ltr;
            }

            if (newShiftState == ShiftStates.Ltr && keyStates.ShiftState != ShiftStates.Ltr)
            {
                buffer = Helper.AddByte(buffer, BAU_LTRS);
                buffer = Helper.AddByte(buffer, baudCode);
                keyStates.ShiftState = ShiftStates.Ltr;
                return(buffer);
            }

            if (newShiftState == ShiftStates.Figs && keyStates.ShiftState != ShiftStates.Figs)
            {
                buffer = Helper.AddByte(buffer, BAU_FIGS);
                buffer = Helper.AddByte(buffer, baudCode);
                keyStates.ShiftState = ShiftStates.Figs;
                return(buffer);
            }

            if (newShiftState == ShiftStates.Third && keyStates.ShiftState != ShiftStates.Third)
            {
                buffer = Helper.AddByte(buffer, BAU_NUL);
                buffer = Helper.AddByte(buffer, baudCode);
                keyStates.ShiftState = ShiftStates.Third;
                return(buffer);
            }

            if (keyStates.ShiftState == newShiftState || newShiftState == ShiftStates.Both)
            {
                buffer = Helper.AddByte(buffer, baudCode);
                return(buffer);
            }

            // should not happen
            return(new byte[0]);
        }
Example #8
0
        public static string AsciiWithBaudotEscCodeToAscii(string asciiStrWithEscCodes, KeyStates keyStates)
        {
            string asciiStr = "";

            foreach (char chr in asciiStrWithEscCodes)
            {
                if (chr >= 128 && chr <= 255)
                {
                    byte code = (byte)(chr - 128);
                    asciiStr += BaudotStringToAscii(new byte[] { code }, keyStates, SendRecv.Send, false);
                }
                else
                {
                    asciiStr += chr;
                }
            }
            return(asciiStr);
        }