public void WriteCmd(ItelexPacket itxPkt, Modes mode, Acknowledge ack) { if (_debugForm == null) { return; } if (itxPkt.CommandType == ItelexCommands.Heartbeat && !_debugForm.ShowHeartbeat) { return; } if (itxPkt.CommandType == ItelexCommands.Ack && !_debugForm.ShowAck) { return; } string debugStr = CmdToString(itxPkt, mode, ack); Write(debugStr + "\r\n", mode); }
private string CmdToString(ItelexPacket itxPkt, Modes mode, Acknowledge ack) { string cmdStr; switch (itxPkt.CommandType) { case ItelexCommands.Heartbeat: return($"Heartbeat {itxPkt.GetDebugData()}"); case ItelexCommands.DirectDial: cmdStr = "DirectDial"; if (itxPkt.Data.Length == 0) { return($"{cmdStr} no data"); } else { return($"{cmdStr} {itxPkt.Data[0]} [{itxPkt.GetDebugPacket()}]"); } case ItelexCommands.BaudotData: cmdStr = "BaudotData"; if (itxPkt.Data.Length == 0) { return($"{cmdStr} no data"); } else { string asciiStr = CodeManager.BaudotStringToAscii(itxPkt.Data, _keyStates, CodeManager.SendRecv.Recv, true); asciiStr = ConvDebugText(asciiStr); return($"{cmdStr} {asciiStr} [{itxPkt.GetDebugPacket()}] {ack.LocalBufferCount}"); } case ItelexCommands.End: return($"End {itxPkt.GetDebugData()}"); case ItelexCommands.Reject: cmdStr = "Reject"; if (itxPkt.Data.Length == 0) { return($"{cmdStr} no data"); } else { string rejectReason = Encoding.ASCII.GetString(itxPkt.Data, 0, itxPkt.Data.Length); rejectReason = rejectReason.TrimEnd('\x00'); return($"{cmdStr} '{rejectReason}' [{itxPkt.GetDebugPacket()}]"); } case ItelexCommands.Ack: cmdStr = $"Ack"; if (itxPkt.Data.Length == 0) { return($"{cmdStr} no data"); } else { if (ack == null) { return($"{cmdStr} [{itxPkt.GetDebugPacket()}]"); } else { int ackCnt = itxPkt.Data[0]; if (mode == Modes.Recv) { return($"{cmdStr} ack={ackCnt} sent={ack.SendCnt}/{ack.SendAckCnt} buf={ack.RemoteBufferCount} [{itxPkt.GetDebugPacket()}]"); } else { return($"{cmdStr} ack={ackCnt} recv={ack.ReceivedCnt}/{ack.ReceivedAckCnt} buf={ack.LocalBufferCount} [{itxPkt.GetDebugPacket()}]"); } } } case ItelexCommands.ProtocolVersion: cmdStr = "ProtocolVersion"; if (itxPkt.Data.Length == 0) { return($"{cmdStr} no data"); } else { string versionStr = Encoding.ASCII.GetString(itxPkt.Data, 1, itxPkt.Data.Length - 1); versionStr = versionStr.TrimEnd('\x00'); // remove 00-byte suffix versionStr = ConvDebugText(versionStr); return($"{cmdStr} {itxPkt.Data[0]} '{versionStr}' [{itxPkt.GetDebugPacket()}]"); } case ItelexCommands.SelfTest: return($"SelfTest {itxPkt.GetDebugData()}"); case ItelexCommands.RemoteConfig: return($"RemoteConfig {itxPkt.GetDebugData()}"); case ItelexCommands.ConnectRemote: return($"ConnectRemote {itxPkt.GetDebugData()}"); case ItelexCommands.RemoteConfirm: return($"RemoteConfirm {itxPkt.GetDebugData()}"); case ItelexCommands.RemoteCall: return($"RemoteCall {itxPkt.GetDebugData()}"); case ItelexCommands.AcceptCallRemote: return($"AcceptCallRemote {itxPkt.GetDebugData()}"); default: return($"Unknown cmd {itxPkt.GetDebugData()}"); } }
public void WriteCmd(ItelexPacket itxPkt, Modes mode) { WriteCmd(itxPkt, mode, null); }