init
This commit is contained in:
77
DataPRO/RibeyeCommands/CommandBase.cs
Normal file
77
DataPRO/RibeyeCommands/CommandBase.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using DTS.Common.ICommunication;
|
||||
using DTS.DASLib.Utility;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
// Steal it for now
|
||||
using DTS.DASLib.Command;
|
||||
|
||||
namespace DTS.DASLib.Command.Ribeye
|
||||
{
|
||||
public abstract class CommandBase : AbstractCommandBase
|
||||
{
|
||||
protected CommandPacket command { get { return baseCommand as CommandPacket; } set { baseCommand = value; } }
|
||||
protected CommandPacket response { get { return baseResponse as CommandPacket; } set { baseResponse = value; } }
|
||||
|
||||
public CommandBase(DTS.Common.Interface.DASFactory.ICommunication sock) : base(sock)
|
||||
{
|
||||
command = new CommandPacket();
|
||||
}
|
||||
|
||||
public CommandBase(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec) : base(sock, TimeoutMillisec)
|
||||
{
|
||||
command = new CommandPacket();
|
||||
}
|
||||
|
||||
public override void CommandToString(ref List<List<string>> lines)
|
||||
{
|
||||
base.CommandToString(ref lines);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < command.OriginalBytes.Length; i++)
|
||||
{
|
||||
if ((char)command.OriginalBytes[i] != '\n' &&
|
||||
(char)command.OriginalBytes[i] != '\r')
|
||||
{
|
||||
sb.AppendFormat("{0}", (char)command.OriginalBytes[i]);
|
||||
}
|
||||
}
|
||||
lines.Add(new List<string>() { sb.ToString() });
|
||||
}
|
||||
|
||||
public override void ResponseToString(ref List<List<string>> lines)
|
||||
{
|
||||
base.ResponseToString(ref lines);
|
||||
if (null == response || null == response.OriginalBytes)
|
||||
{
|
||||
lines.Add(new List<string>() { "Empty response!" });
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < Math.Min(30, response.OriginalBytes.Length); i++)
|
||||
{
|
||||
if ((char)response.OriginalBytes[i] != '\n' &&
|
||||
(char)response.OriginalBytes[i] != '\r')
|
||||
{
|
||||
sb.AppendFormat("{0}", (char)response.OriginalBytes[i]);
|
||||
}
|
||||
}
|
||||
lines.Add(new List<string>() { sb.ToString() });
|
||||
}
|
||||
|
||||
|
||||
protected override CommandPacketBase GetCommandPacket()
|
||||
{
|
||||
return new CommandPacket();
|
||||
}
|
||||
protected override CommandPacketBase GetCommandPacket(byte[] buffer)
|
||||
{
|
||||
return new CommandPacket(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user