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)); }
/// <summary> /// Punch a baudot code character /// </summary> /// <param name="baudotCode"></param> /// <param name="shiftState"></param> public void PunchCode(byte baudotCode, ShiftStates shiftState) { if (PuncherOn) { InternPunchCode(baudotCode, shiftState); } }
public string GetName(ShiftStates shiftState) { string name; switch (shiftState) { case ShiftStates.Ltr: case ShiftStates.Both: name = NameLtr; break; case ShiftStates.Figs: name = NameFig; break; default: case ShiftStates.Unknown: name = null; break; } if (name == null) { name = CodeManager.ASC_INVALID.ToString(); } return(name); }
private void ConnectInit() { Debug.WriteLine($"{nameof(ConnectInit)} start"); _n_recv = 0; _n_trans = 0; _n_ack = 0; _sendBuffer = new ConcurrentQueue <byte>(); _ackRecvFlag = false; _ackTimerActive = false; _ackTimer.Stop(); _ackTimer.Interval = 2000; _ackTimer.Start(); _sendTimerActive = false; _sendTimer.Stop(); _sendTimer.Interval = 100; _sendTimer.Start(); EyeballCharActive = false; _shiftState = ShiftStates.Unknown; _lastSendRecvIdleMs = Helper.GetTicksMs(); Local = false; _connStartTime = DateTime.Now; ConnectionState = ConnectionStates.Connected; Update?.Invoke(); Connected?.Invoke(); Debug.WriteLine($"{nameof(ConnectInit)} end"); }
public char GetChar(ShiftStates shiftState) { char?chr; switch (shiftState) { case ShiftStates.Ltr: case ShiftStates.Both: case ShiftStates.Unknown: chr = CharLtr; break; case ShiftStates.Figs: chr = CharFig; break; case ShiftStates.Third: chr = Char3rd; break; default: chr = null; break; } if (chr == null) { chr = CodeManager.ASC_INVALID; } return(chr.Value); }
private string PunchDataToText(byte[] punchData) { string text = ""; ShiftStates shiftState = ShiftStates.Ltr; foreach (byte code in punchData) { if (code == CodeManager.BAU_LTRS) { shiftState = ShiftStates.Ltr; } else if (code == CodeManager.BAU_FIGS) { shiftState = ShiftStates.Figs; } else { char ascii = CodeManager.BaudotCharToAscii(code, shiftState, ConfigManager.Instance.Config.CodeSet, CodeManager.SendRecv.Send); if (ascii != '\r') { text += ascii; } } } return(text); }
/// <summary> /// Get readable punchcodes for one baudot character /// </summary> /// <param name="baudotCode">0..31</param> /// <param name="shift">0=letters, 1=figures</param> /// <returns></returns> public byte[] GetPunchCodes(int baudotCode, ShiftStates shift) { if (baudotCode == 0x00) { // code32 return(new byte[] { 0x00 }); } int code = baudotCode; if (shift == ShiftStates.Figs) { code += 32; } byte[] pattern = (from p in _punchCodes where p.BaudotCode == code select p.Pattern).FirstOrDefault(); if (pattern == null) { return(null); } return(pattern); /* * // add one space row * byte[] pattern2 = new byte[pattern.Length + 1]; * Buffer.BlockCopy(pattern, 0, pattern2, 0, pattern.Length); * pattern2[pattern2.Length - 1] = 0; * return pattern2; * * //return (from p in _punchCodes where p.BaudotCode == code select p.Pattern).FirstOrDefault(); */ }
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 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); }
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 byte[] BaudotCodeToBaudotWithShift(byte baudCode, ShiftStates newShiftState, ref ShiftStates shiftState) { byte[] buffer = new byte[0]; if (baudCode == BAU_LTRS) { buffer = Helper.AddByte(buffer, BAU_LTRS); shiftState = ShiftStates.Ltr; return(buffer); } if (baudCode == BAU_FIGS) { buffer = Helper.AddByte(buffer, BAU_FIGS); shiftState = ShiftStates.Figs; return(buffer); } if (shiftState == ShiftStates.Unknown && newShiftState == ShiftStates.Unknown) { buffer = Helper.AddByte(buffer, BAU_LTRS); newShiftState = ShiftStates.Ltr; } if (shiftState == ShiftStates.Unknown && newShiftState == ShiftStates.Ltr || shiftState == ShiftStates.Figs && newShiftState == ShiftStates.Ltr) { buffer = Helper.AddByte(buffer, BAU_LTRS); buffer = Helper.AddByte(buffer, baudCode); shiftState = ShiftStates.Ltr; return(buffer); } if (shiftState == ShiftStates.Unknown && newShiftState == ShiftStates.Figs || shiftState == ShiftStates.Ltr && newShiftState == ShiftStates.Figs) { buffer = Helper.AddByte(buffer, BAU_FIGS); buffer = Helper.AddByte(buffer, baudCode); shiftState = ShiftStates.Figs; return(buffer); } if (shiftState == newShiftState || newShiftState == ShiftStates.Both) { buffer = Helper.AddByte(buffer, baudCode); return(buffer); } // should not happen return(new byte[0]); }
public static HotKey TextToHotKey(string text) { ShiftStates shift = new ShiftStates(); while (true) { bool res = CompareFront(ref text, KeyCaps[mkcShift].Sign); if (res) { shift.Include(ShiftStates.SsShift); } else { res = CompareFront(ref text, KeyCaps[mkcCtrl].Sign); if (res) { shift.Include(ShiftStates.SsCtrl); } else { res = !CompareFront(ref text, KeyCaps[mkcAlt].Sign); if (res) { break; } shift.Include(ShiftStates.SsAlt); } } } HotKey result = new HotKey(); if (text != "") { for (int key = 0; key < KeyCaps.Length; key++) { if ((text == KeyCaps[key].Sign)) { result.Key = KeyCaps[key].Key; result.Shift = shift; } } } return(result); }
/// <summary> /// Get readable punchcodes for one baudot character /// </summary> /// <param name="baudotCode">0..31</param> /// <param name="shift">0=letters, 1=figures</param> /// <returns></returns> public byte[] GetPunchCodes(int baudotCode, ShiftStates shift) { if (baudotCode == 0x00) { // code32 return(new byte[] { 0x00 }); } int code = baudotCode; if (shift == ShiftStates.Figs) { code += 32; } return((from p in _punchCodes where p.BaudotCode == code select p.Pattern).FirstOrDefault()); }
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(""); } }
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); }
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); }
private void SendCode(byte baudotCode, ref ShiftStates shiftState) { byte[] codes = CodeManager.BaudotCodeToBaudotWithShift(baudotCode, shiftState, ref shiftState); if (EyeballCharActive) { byte[] buffer = new byte[0]; for (int i = 0; i < codes.Length; i++) { byte[] newCodes = _eyeballChar.GetPunchCodes(codes[i], shiftState); buffer = Helper.AddBytes(buffer, newCodes); } codes = buffer; } BaudotSendRecv?.Invoke(codes); if (Local) { Update?.Invoke(); return; } if (!IsConnected) { return; } if (IdleTimerMs >= 25000) { // wake up remote machine with LTRS EnqueueSend(new byte[] { CodeManager.BAU_LTRS }); EnqueueSend(new byte[] { CodeManager.BAU_LTRS }); EnqueueSend(new byte[] { CodeManager.BAU_LTRS }); if (shiftState == ShiftStates.Figs) { EnqueueSend(new byte[] { CodeManager.BAU_FIGS }); } } EnqueueSend(codes); Update?.Invoke(); }
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]); } }
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); }
public void SetBuffer(byte[] buffer) { ShiftStates shiftState = ShiftStates.Ltr; _updateActive = false; Clear(); for (int i = 0; i < buffer.Length; i++) { InternPunchCode(buffer[i], shiftState); switch (buffer[i]) { case CodeManager.BAU_LTRS: shiftState = ShiftStates.Ltr; break; case CodeManager.BAU_FIGS: shiftState = ShiftStates.Figs; break; } } _updateActive = true; InvokeChanged(); }
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 KeyStates(ShiftStates shiftState, CodeSets codeSet) { ShiftState = shiftState; CodeSet = codeSet; }
private void InternPunchCode(byte baudotCode, ShiftStates shiftState) { string text = CodeManager.BaudotCodeToPuncherText(baudotCode, shiftState, _config.CodeSet); switch (text) { case "CR": text = LngText(LngKeys.TapePunch_CodeCarriageReturn); break; case "NL": text = LngText(LngKeys.TapePunch_CodeLinefeed); break; case "LTR": text = LngText(LngKeys.TapePunch_CodeLetters); break; case "FIG": text = LngText(LngKeys.TapePunch_CodeFigures); break; } PunchLine newLine = new PunchLine(baudotCode, text); if (!EditOn) { _buffer.Add(newLine); DisplayPos = _buffer.Count; } else { if (EditInsert) { if (DisplayPos >= _buffer.Count) { _buffer.Add(newLine); } else { _buffer.Insert(DisplayPos, newLine); } DisplayPos++; } else { if (DisplayPos >= _buffer.Count) { _buffer.Add(newLine); } else { _buffer[DisplayPos] = newLine; } DisplayPos++; } if (DisplayPos > _buffer.Count) { DisplayPos = _buffer.Count; } } InvokeChanged(); }
public KeyCapInfo(string sign, Keys key, ShiftStates shift) { Sign = sign; Key = key; Shift = shift; }
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]); }