Beispiel #1
0
        /// <summary>
        /// Process input data
        /// </summary>
        /// <param name="input">Input string</param>
        /// <returns>Packet bytes</returns>
        private byte[] processInput(string input)
        {
            var arguments = input.Split(new string[] { ";" }, StringSplitOptions.None);

            if (arguments.Length >= 2)
            {
                return(newPacket(Conv.ToInt(arguments[0], 0), ProtocolFormat.Format(arguments[1], Encoding.UTF8)));
            }
            else if (arguments.Length >= 1)
            {
                return(newPacket(0, ProtocolFormat.Format(arguments[0], Encoding.UTF8)));
            }
            else
            {
                return(new byte[0]);
            }
        }
Beispiel #2
0
        Dictionary <string, string> LoadReplyFile(string fileName)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            string[] lines = Files.ReadLines(fileName, true);
            string[] item;
            for (int i = 0; i < lines.Length; i++)
            {
                item = lines[i].Split(new string[] { @"\->" }, StringSplitOptions.RemoveEmptyEntries);
                if (item.Length == 2)
                {
                    dict.Add(BitConverter.ToString(ProtocolFormat.Format(item[0], Settings.Connection.UsedEncoding)), item[1]);
                }
            }

            return(dict);
        }
Beispiel #3
0
        public byte[] AcknowledgeReception(byte[] message)
        {
            if (message.Length > 2)
            {
                int frameNum = 0;
                try
                {
                    int frame  = Conv.SwapBytes(BitConverter.ToUInt16(message, 0));
                    int length = (frame & 2047) - 6; // dala length
                    frameNum = (frame & 12288) + 6 + (128 << 8) + +(1 << 8);
                }
                catch (Exception) { }

                return(ProtocolFormat.Format(@"\s" + frameNum.ToString(), Encoding.UTF8));
            }
            return(new byte[0]);
        }
Beispiel #4
0
        private void SendMsg(string message)
        {
            var byteMsg = ProtocolFormat.Format(message, Settings.Connection.UsedEncoding);

            SendMsg(byteMsg);
        }
Beispiel #5
0
        private string ProcessData(byte[] message, bool input)
        {
            string description = "";

            if (Settings.Messages.PacketView == Fx.Logging.ePacketView.Custom)
            {
                var protocol = (IPluginProtocol)Global.PL.GetPlugin(Settings.Messages.PacketViewPlugin);
                Send(protocol.AcknowledgeReception(message));
            }

            var endChar = Settings.Connection.UsedEncoding.GetString(ProtocolFormat.Format(Settings.Messages.LineSeparatingChar, Settings.Connection.UsedEncoding));

            if (Settings.Messages.UseLineSeparatingChar && endChar != "")
            {
                Global.LogPacket.LineSeparatingChar = endChar;
            }
            else
            {
                Global.LogPacket.LineSeparatingChar = "";
            }


            if (Settings.Messages.ShowBaudRate)
            {
                description = Settings.Connection.BaudRate + "[Bd]";
            }

            string text = "";

            if (input)
            {
                // ----- Reply statistics -----
                Statistic.ReplyCounter.All++;
                var diff = DateTime.Now - SendTime;
                if (diff.TotalMilliseconds > 2000)
                {
                    Statistic.ReplyCounter.Over2s++;
                }
                else if (diff.TotalMilliseconds > 1000)
                {
                    Statistic.ReplyCounter.Over1s++;
                }
                else if (diff.TotalMilliseconds > 500)
                {
                    Statistic.ReplyCounter.Over500ms++;
                }
                else if (diff.TotalMilliseconds > 250)
                {
                    Statistic.ReplyCounter.Over250ms++;
                }
                else if (diff.TotalMilliseconds > 100)
                {
                    Statistic.ReplyCounter.Over100ms++;
                }

                // ----- Log message -----
                text = Global.LogPacket.Add(description, message, Color.Blue, Settings.Messages.ShowTime, input);

                // ----- Send auto-reply -----
                if (Settings.Messages.EnableReplyFile)
                {
                    string key = BitConverter.ToString(message);
                    if (ReplyData.ContainsKey(key))
                    {
                        string value = ReplyData[key];
                        Send(value);
                    }
                }
            }
            else
            {
                SendTime = DateTime.Now;
                text     = Global.LogPacket.Add(description, message, Color.Black, Settings.Messages.ShowTime, input);
            }


            return(text);
        }