private static void ISCPSocket_OnPacketRecieved(string str)
        {
            HGJConsole.Regions["recv"].WriteContent("Recieved: " + str);
            ISCPPacket r = ISCPPacket.ParsePacket(str);

            if (r is Power)
            {
                _powerStatus = (r.Command == "!1PWR01");
            }
            else if (r is Input)
            {
                _inputStatus = r.ToString();
            }
            HGJConsole.Regions["recv"].WriteContent(r.ToString(), true);
        }
Beispiel #2
0
        private static async Task DemoOne()
        {
            TcpClient Client        = new TcpClient("192.168.1.120", 60128);
            Stream    NetworkStream = Client.GetStream();

            Task ReadTask = Task.Run(() => Program.ReadLoop(NetworkStream));

            string Command = string.Empty;

            while ((Command = Console.ReadLine()) is not "End" or null)
            {
                if (Command.Length < 3)
                {
                    continue;
                }
                string CommandPart = Command.Substring(0, 3);
                string ParamsPart  = Command.Substring(3);
                byte[] PacketBytes = new ISCPPacket(new ISCPMessage(CommandPart, ParamsPart)).Serialize();

                /*for (int i = 0; i < PacketBytes.Length; i += 4) {
                 *      byte?[] DisplayBytes = PacketBytes.Skip(i).Take(4).Cast<byte?>().ToArray();
                 *      while (DisplayBytes.Length < 4) {
                 *              DisplayBytes = DisplayBytes.Concat(new byte?[] { null }).ToArray();
                 *      }
                 *      string Output = String.Join(
                 *              " ",
                 *              DisplayBytes.Select(x => x == null ? "  " : x.Value.ToString("X2")));
                 *      Output += "\t";
                 *      Output += String.Join(" ", DisplayBytes.Select(t => t == null ? " " : (t > 32 && t < 126 ? ((char)t).ToString() : ".")));
                 *      Console.WriteLine(Output);
                 * }*/
                await NetworkStream.WriteAsync(PacketBytes);

                Program.FlagNext        = CommandPart;
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("Sent!");
                Console.ForegroundColor = ConsoleColor.White;
            }

            Console.WriteLine("End");
        }
Beispiel #3
0
        private static async void ReadLoop(Stream stream)
        {
            ISCPPacket Packet;

            while ((Packet = await ISCPPacket.Read(stream)) != null)
            {
                if (Program.FlagNext == Packet.Message.Command)
                {
                    Program.FlagNext        = string.Empty;
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                }

                string CommandName = CommandId.Commands.ContainsKey(Packet.Message.Command)
                                                             ? CommandId.Commands[Packet.Message.Command].FriendlyName
                                                             : Packet.Message.Command;
                Console.WriteLine("Command: {0}, Params: {1}", CommandName, Packet.Message.Parameters);
                Console.ForegroundColor = ConsoleColor.White;
            }
        }