/// <summary> Initializes this object. </summary> /// <param name="transport"> The transport layer. </param> /// <param name="fieldSeparator"> The field separator. </param> /// <param name="commandSeparator"> The command separator. </param> /// <param name="escapeCharacter"> The escape character. </param> /// <param name="sendBufferMaxLength"> The maximum size of the send buffer</param> private void Init(ITransport transport, char fieldSeparator, char commandSeparator, char escapeCharacter, int sendBufferMaxLength) { _controlToInvokeOn = null; _receiveCommandQueue = new ReceiveCommandQueue(DisposeStack, this); _communicationManager = new CommunicationManager(DisposeStack, transport, _receiveCommandQueue, commandSeparator, fieldSeparator, escapeCharacter); _sender = new Sender(_communicationManager, _receiveCommandQueue); _sendCommandQueue = new SendCommandQueue(DisposeStack, this, _sender, sendBufferMaxLength); _receiveCommandQueue.NewLineReceived += (o, e) => InvokeNewLineEvent(NewLineReceived, e); _sendCommandQueue.NewLineSent += (o, e) => InvokeNewLineEvent(NewLineSent, e); _fieldSeparator = fieldSeparator; _commandSeparator = commandSeparator; PrintLfCr = false; Command.FieldSeparator = _fieldSeparator; Command.CommandSeparator = _commandSeparator; Command.PrintLfCr = PrintLfCr; Escaping.EscapeChars(_fieldSeparator, _commandSeparator, escapeCharacter); _callbackList = new Dictionary <int, MessengerCallbackFunction>(); //CurrentSentLine = ""; CurrentReceivedLine = ""; }
/// <summary> Clean line. </summary> /// <param name="line"> The line. </param> /// <returns> . </returns> private string CleanLine(string line) { var cleanedLine = line.Trim('\r', '\n'); cleanedLine = Escaping.Remove(cleanedLine, _commandSeparator, _escapeCharacter); return(cleanedLine); }
/// <summary> Parse message. </summary> /// <param name="line"> The received command line. </param> /// <returns> The received command. </returns> private ReceivedCommand ParseMessage(string line) { // Split line in command and arguments //var splitLine = Escaping.Split(line, _fieldSeparator, _escapeCharacter, StringSplitOptions.RemoveEmptyEntries); //var command = new ReceivedCommand(splitLine); return (new ReceivedCommand(Escaping.Split(line, _fieldSeparator, _escapeCharacter, StringSplitOptions.RemoveEmptyEntries))); }
/// <summary> Parse message. </summary> /// <param name="line"> The received command line. </param> /// <returns> The received command. </returns> private ReceivedCommand ParseMessage(string line) { // Trim and clean line var cleanedLine = line.Trim('\r', '\n'); cleanedLine = Escaping.Remove(cleanedLine, _commandSeparator, _escapeCharacter); return (new ReceivedCommand(Escaping.Split(cleanedLine, _fieldSeparator, _escapeCharacter, StringSplitOptions.RemoveEmptyEntries))); }
/// <summary> Converts an escaped string to a bytes array. </summary> /// <param name="value"> The value to be converted. </param> /// <returns> input value as an escaped string. </returns> public static byte[] EscapedStringToBytes(String value) { try { string unEscapedValue = Escaping.Unescape(value); return(_stringEncoder.GetBytes(unEscapedValue)); } catch (Exception) { return(null); } }
/***** conversion functions ****/ /// <summary> Converts a byte array to escaped string. </summary> /// <param name="byteArray"> Array of bytes. </param> /// <returns> input value as an escaped string. </returns> private static string BytesToEscapedString(byte[] byteArray) { try { string stringValue = _stringEncoder.GetString(byteArray); return(Escaping.Escape(stringValue)); } catch (Exception) { return(null); } }
/// <summary> Reads the current binary argument as a string value. </summary> /// <returns> The string value. </returns> public String ReadBinStringArg() { if (Next()) { if (CmdArgs[_parameter] != null) { _dumped = true; return(Escaping.Unescape(CmdArgs[_parameter])); } } return(string.Empty); }
/// <summary> Reads the current binary argument as a string value. </summary> /// <returns> The string value. </returns> public String ReadBinStringArg() { if (Next()) { if (_arguments[_parameter] != null) { _dumped = true; return(Escaping.Unescape(_arguments[_parameter])); } } return(""); }
/// <summary> Initialises this object. </summary> /// <param name="transport"> The transport layer. </param> /// <param name="fieldSeparator"> The field separator. </param> /// <param name="commandSeparator"> The command separator. </param> /// <param name="escapeCharacter"> The escape character. </param> private void Init(ITransport transport, char fieldSeparator, char commandSeparator, char escapeCharacter) { _controlToInvokeOn = null; _sendCommandQueue = new SendCommandQueue(DisposeStack, this); _receiveCommandQueue = new ReceiveCommandQueue(DisposeStack, this); _communicationManager = new CommunicationManager(DisposeStack, transport, _receiveCommandQueue, commandSeparator, fieldSeparator, escapeCharacter); _fieldSeparator = fieldSeparator; _commandSeparator = commandSeparator; Escaping.EscapeChars(fieldSeparator, commandSeparator, escapeCharacter); _callbackList = new Dictionary <int, MessengerCallbackFunction>(); PrintLfCr = false; }
/// <summary> Initialises this object. </summary> /// <param name="communications"> The Serial port object. </param> /// <param name="fieldSeparator"> The field separator. </param> /// <param name="commandSeparator"> The command separator. </param> /// <param name="escapeCharacter"> The escape character. </param> private void Init(SerialPortManager communications, char fieldSeparator, char commandSeparator, char escapeCharacter) { _controlToInvokeOn = null; _communications = communications; _communications = communications; _fieldSeparator = fieldSeparator; _commandSeparator = commandSeparator; _escapeCharacter = escapeCharacter; communications.EolDelimiter = _commandSeparator; Escaping.EscapeChars(fieldSeparator, commandSeparator, escapeCharacter); _callbackList = new Dictionary <int, MessengerCallbackFunction>(); PrintLfCr = false; _communications.NewLineReceived += NewSerialDataReceived; }
/// <summary> Initializes this object. </summary> /// <param name="transport"> The transport layer. </param> /// <param name="boardType"> Embedded Processor type. Needed to translate variables between sides. </param> /// <param name="fieldSeparator"> The field separator. </param> /// <param name="commandSeparator"> The command separator. </param> /// <param name="escapeCharacter"> The escape character. </param> /// <param name="sendBufferMaxLength"> The maximum size of the send buffer</param> private void Init(ITransport transport, BoardType boardType, char fieldSeparator, char commandSeparator, char escapeCharacter, int sendBufferMaxLength) { //Logger.Open(@"sendCommands.txt"); Logger.DirectFlush = true; _receiveCommandQueue = new ReceiveCommandQueue(HandleMessage); _communicationManager = new CommunicationManager(transport, _receiveCommandQueue, boardType, commandSeparator, fieldSeparator, escapeCharacter); _sendCommandQueue = new SendCommandQueue(_communicationManager, sendBufferMaxLength); PrintLfCr = false; _receiveCommandQueue.NewLineReceived += (o, e) => InvokeNewLineEvent(NewLineReceived, e); _sendCommandQueue.NewLineSent += (o, e) => InvokeNewLineEvent(NewLineSent, e); Escaping.EscapeChars(fieldSeparator, commandSeparator, escapeCharacter); _callbackList = new Dictionary <int, MessengerCallbackFunction>(); _sendCommandQueue.Start(); _receiveCommandQueue.Start(); }
// ***** Binary **** / /// <summary> Adds a binary command argument. </summary> /// <param name="argument"> The argument. </param> public void AddBinArgument(string argument) { _arguments.Add(Escaping.Escape(argument)); }
// ***** Binary **** / /// <summary> Adds a binary command argument. </summary> /// <param name="argument"> The argument. </param> public void AddBinArgument(string argument) { _lazyArguments.Add(() => CmdArgs.Add(Escaping.Escape(argument))); }