Exemple #1
0
        public void setLED(int myDevice) // command to set LED color
        {
            byte[] color = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
            switch (device[myDevice].activeCoil) // based on which coil is currently active - determine which color the LED should be.
            {
            case 0:
            {
                color[0] = 0xff;
                color[1] = 0xff;
                device[myDevice].ledColor = "red";
                break;
            }

            case 1:
            {
                color[2] = 0xff;
                color[3] = 0xff;
                device[myDevice].ledColor = "green";
                break;
            }

            case 2:
            {
                color[4] = 0xff;
                color[5] = 0xff;
                device[myDevice].ledColor = "blue";
                break;
            }
            }
            GeneralCommand writeColor = new GeneralCommand(device[myDevice].m_si, 0x01, 0x0C, new byte[] { color[0], color[1], color[2], color[3], color[5], color[5] }, "set led color");

            writeColor.RegisterListener(this); device[myDevice].target.Queue(writeColor);
        }
        public async Task generate_multiple_new_clients_send_message_expect_proper_response()
        {
            var message = new GeneralCommand {
                CorrellationId = 1, Id = Guid.NewGuid()
            };
            var observer = Container.GetService <IQueueObserverClient>();

            observer.RegisterForNotificationOf <GeneralMessage>(m =>
            {
                if (m is GeneralMessage gm)
                {
                    gm.CorrellationId += 1;
                }
                return(Task.FromResult(true));
            });

            observer.RegisterForNotificationOf <GeneralCommand>(m =>
            {
                if (m is GeneralCommand gm)
                {
                    gm.CorrellationId += 1;
                }
                return(Task.FromResult(true));
            });

            var messenger = Container.GetService <IQueueMessengerClient>();
            await messenger.Send(message);

            // this asserts that only one of the handlers above were executed due //
            // to the type of the message //
            Assert.AreEqual(1, message.CorrellationId);
        }
Exemple #3
0
 public Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken)
 {
     return(SendMessage(new WebSocketMessage <GeneralCommand>
     {
         MessageType = "GeneralCommand",
         Data = command
     }, cancellationToken));
 }
Exemple #4
0
        private void GetApplicationVersionSync()
        {
            GeneralCommand app_vers = new GeneralCommand(m_interface, 0x01, 0x1E, null, "get application version");

            app_vers.RegisterListener(this);
            m_target.Queue(app_vers);
            m_target.Wait();
        }
    public void UserLogin()
    {
        GeneralCommand <string> msg = Command.NetCommand.Login(UserName.text, "123").ToObject <GeneralCommand <string> >();

        print(msg.Datas[1]);
        Info.AllPlayerInfo.Player1Info = msg.Datas[1].ToObject <PlayerInfo>();
        print(msg.Datas[0] == "1" ? "登录成功" : msg.Datas[1] == "-1" ? "密码错误" : "无此账号");
        Info.AllPlayerInfo.Player1Info = msg.Datas[1].ToObject <PlayerInfo>();
        SceneManager.LoadSceneAsync(1);
    }
Exemple #6
0
        public Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken)
        {
            var socket = GetActiveSocket();

            return(socket.SendAsync(new WebSocketMessage <GeneralCommand>
            {
                MessageType = "GeneralCommand",
                Data = command
            }, cancellationToken));
        }
Exemple #7
0
        public void ShouldFailWhenSameReadyCommand()
        {
            lobby = new Lobby(new GameArena(0));

            GeneralCommand command = new GeneralCommand();

            command.Author = new Player(new User());

            lobby.PlayerReady(command);

            Assert.IsFalse(lobby.PlayerReady(command));
        }
Exemple #8
0
        public Task Post(SendGeneralCommand request)
        {
            var currentSession = GetSession(_sessionContext);

            var command = new GeneralCommand
            {
                Name = request.Command,
                ControllingUserId = currentSession.UserId
            };

            return(_sessionManager.SendGeneralCommand(currentSession.Id, request.Id, command, CancellationToken.None));
        }
Exemple #9
0
        public void Run(string com_port, string full_file_name)
        {
            bool abort = false;

            m_full_file_name = full_file_name;
            m_interface      = new WcaInterfaceLibrary.SerialInterface(com_port, globals.baud, Parity.None, 8);
            m_target         = new Target();
            m_interface.RegisterListener(this);

            Console.WriteLine("Wait until charger is ready.");

            if (m_interface.Open() && File.Exists(m_full_file_name))
            {
                while (!abort)
                {
                    if (Console.KeyAvailable)
                    {
                        ConsoleKey key = Console.ReadKey().Key;

                        switch (key)
                        {
                        case ConsoleKey.Escape:
                            abort = true;
                            break;
                        }
                    }

                    if (m_start_indication_received.WaitOne(2000))
                    {
                        m_start_indication_received.Reset();
                        Thread.Sleep(400);
                        GeneralCommand set_bl = new GeneralCommand(m_interface, 0x01, 0x24, new byte[] { 0x01, 0x03, 0x7D }, "keep bootloader running");
                        set_bl.RegisterListener(this);
                        m_target.Queue(set_bl);
                        m_target.Wait();
                        Thread.Sleep(500);
                        GetApplicationVersionSync();
                        Upload();
                        Thread.Sleep(200);
                        GetApplicationVersionSync();
                        Console.WriteLine("Flashing done.");
                        abort = true;
                    }
                }
            }
            else
            {
                Console.WriteLine("COM port cannot be opened or file does not exists. Pls. check both of them.");
            }

            m_interface.Close();
        }
    public void UserRegister()
    {
        GeneralCommand <int> msg = Command.NetCommand.Register(UserName.text, Password.text).ToObject <GeneralCommand <int> >();

        if (msg.Datas[0] == 1)
        {
            print("注册成功");
        }
        if (msg.Datas[0] == -1)
        {
            print("账号已存在");
        }
    }
Exemple #11
0
        public Task SendBrowseCommand(string controllingSessionId, string sessionId, BrowseRequest command, CancellationToken cancellationToken)
        {
            var generalCommand = new GeneralCommand
            {
                Name = GeneralCommandType.DisplayContent.ToString()
            };

            generalCommand.Arguments["Context"]  = command.Context;
            generalCommand.Arguments["ItemId"]   = command.ItemId;
            generalCommand.Arguments["ItemName"] = command.ItemName;
            generalCommand.Arguments["ItemType"] = command.ItemType;

            return(SendGeneralCommand(controllingSessionId, sessionId, generalCommand, cancellationToken));
        }
Exemple #12
0
        public void Post(SendGeneralCommand request)
        {
            var currentSession = GetSession(_sessionContext).Result;

            var command = new GeneralCommand
            {
                Name = request.Command,
                ControllingUserId = currentSession.UserId.HasValue ? currentSession.UserId.Value.ToString("N") : null
            };

            var task = _sessionManager.SendGeneralCommand(currentSession.Id, request.Id, command, CancellationToken.None);

            Task.WaitAll(task);
        }
Exemple #13
0
        public Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken)
        {
            GeneralCommandType commandType;

            if (Enum.TryParse(command.Name, true, out commandType))
            {
                switch (commandType)
                {
                case GeneralCommandType.VolumeDown:
                    return(_device.VolumeDown());

                case GeneralCommandType.VolumeUp:
                    return(_device.VolumeUp());

                case GeneralCommandType.Mute:
                    return(_device.Mute());

                case GeneralCommandType.Unmute:
                    return(_device.Unmute());

                case GeneralCommandType.ToggleMute:
                    return(_device.ToggleMute());

                case GeneralCommandType.SetVolume:
                {
                    string volumeArg;

                    if (command.Arguments.TryGetValue("Volume", out volumeArg))
                    {
                        int volume;

                        if (int.TryParse(volumeArg, NumberStyles.Any, _usCulture, out volume))
                        {
                            return(_device.SetVolume(volume));
                        }

                        throw new ArgumentException("Unsupported volume value supplied.");
                    }

                    throw new ArgumentException("Volume argument cannot be null");
                }

                default:
                    return(Task.FromResult(true));
                }
            }

            return(Task.FromResult(true));
        }
Exemple #14
0
        public ActionResult SendSystemCommand(
            [FromRoute, Required] string sessionId,
            [FromRoute, Required] GeneralCommandType command)
        {
            var currentSession = RequestHelpers.GetSession(_sessionManager, _authContext, Request);
            var generalCommand = new GeneralCommand
            {
                Name = command,
                ControllingUserId = currentSession.UserId
            };

            _sessionManager.SendGeneralCommand(currentSession.Id, sessionId, generalCommand, CancellationToken.None);

            return(NoContent());
        }
Exemple #15
0
        public async Task <ActionResult> SendGeneralCommand(
            [FromRoute, Required] string sessionId,
            [FromRoute, Required] GeneralCommandType command)
        {
            var currentSession = await RequestHelpers.GetSession(_sessionManager, _authContext, Request).ConfigureAwait(false);

            var generalCommand = new GeneralCommand
            {
                Name = command,
                ControllingUserId = currentSession.UserId
            };

            await _sessionManager.SendGeneralCommand(currentSession.Id, sessionId, generalCommand, CancellationToken.None)
            .ConfigureAwait(false);

            return(NoContent());
        }
Exemple #16
0
 public virtual bool PlayerReady(GeneralCommand command)
 {
     if (!this.readyCommands.Contains(command) && this.readyCommands.Count < _maxPlayerCount)
     {
         command.Author.Ready = true;
         this.readyCommands.Add(command);
         if (this.readyCommands.Count >= 2)
         {
             this.source = new CancellationTokenSource();
             StartCountdown();
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public void Post(SendGeneralCommand request)
        {
            var    config          = Plugin.Instance.Configuration;
            var    ClientSessionID = GetClientID();
            var    SessionID       = config.SelectedDeviceId;
            string UserID          = GetUserIDNew();

            var command = new GeneralCommand
            {
                Name = request.Command,
                ControllingUserId = UserID ?? ""
            };

            _logger.Debug("--- FrontView+ General Command: Command Sent: " + request.Command + " Session Id: " + SessionID + " Client Requesting ID: " + ClientSessionID);
            var task2 = _sessionManager.SendGeneralCommand(SessionID, ClientSessionID, command, CancellationToken.None);

            Task.WaitAll(task2);
        }
Exemple #18
0
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public Task Post(SendSystemCommand request)
        {
            var name = request.Command;

            if (Enum.TryParse(name, true, out GeneralCommandType commandType))
            {
                name = commandType.ToString();
            }

            var currentSession = GetSession(_sessionContext);
            var command        = new GeneralCommand
            {
                Name = name,
                ControllingUserId = currentSession.UserId
            };

            return(_sessionManager.SendGeneralCommand(currentSession.Id, request.Id, command, CancellationToken.None));
        }
Exemple #19
0
        public void AddCommand_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var logicFacade    = this.CreateLogicFacade();
            var generalCommand = new GeneralCommand();
            var arenaCommand   = new ArenaCommand();

            // Act
            logicFacade.AddCommand(
                generalCommand);
            logicFacade.AddCommand(
                arenaCommand);


            // Assert
            Assert.IsNotNull(generalCommand.Receiver);
            Assert.IsNotNull(arenaCommand.Receiver);
        }
Exemple #20
0
        public IMessage GenerateMessage()
        {
            IMessage message = null;

            switch (JobType)
            {
            case "projectData":
            {
                message = new GeneralCommand
                {
                    Id      = SessionIdentifier,
                    Command = JobType,
                    CommandDataCollection = new List <ICommandData>
                    {
                        new CommandData {
                            Data = FileName, DataType = "filename"
                        }
                    }
                };
                break;
            }

            case "generateTiles":
            {
                message = new GeneralCommand
                {
                    Id      = SessionIdentifier,
                    Command = JobType,
                    CommandDataCollection = new List <ICommandData>
                    {
                        new CommandData {
                            Data = FileName, DataType = "filename"
                        }
                    }
                };
                break;
            }

            default:
                break;
            }
            return(message);
        }
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Post(SendSystemCommand request)
        {
            GeneralCommandType commandType;

            if (Enum.TryParse(request.Command, true, out commandType))
            {
                var currentSession = GetSession();

                var command = new GeneralCommand
                {
                    Name = commandType.ToString(),
                    ControllingUserId = currentSession.UserId.HasValue ? currentSession.UserId.Value.ToString("N") : null
                };

                var task = _sessionManager.SendGeneralCommand(currentSession.Id, request.Id, command, CancellationToken.None);

                Task.WaitAll(task);
            }
        }
Exemple #22
0
        public void Action_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var generalLogic   = this.CreateGeneralLogic();
            var generalCommand = new GeneralCommand();

            generalCommand.Author = new Player(User);


            mockLobby.Setup(x => x.AddPlayer(generalCommand.Author)).Returns(true);
            mockLobby.Setup(x => x.RemovePlayer(generalCommand.Author));
            mockLobby.Setup(x => x.PlayerReady(generalCommand)).Returns(true);
            mockLobby.Setup(x => x.GetReadyCommand(generalCommand.Author)).Returns(generalCommand);

            // Act
            generalCommand.Cmds.Add(GeneralCommandEnum.JoinLobby);
            generalLogic.Action(
                generalCommand);
            generalCommand.Cmds.Remove(GeneralCommandEnum.JoinLobby);

            generalCommand.Cmds.Add(GeneralCommandEnum.LeaveLobby);
            generalLogic.Action(
                generalCommand);
            generalCommand.Cmds.Remove(GeneralCommandEnum.LeaveLobby);

            generalCommand.Cmds.Add(GeneralCommandEnum.NotReady);
            generalLogic.Action(
                generalCommand);
            generalCommand.Cmds.Remove(GeneralCommandEnum.NotReady);

            generalCommand.Cmds.Add(GeneralCommandEnum.Ready);
            generalLogic.Action(
                generalCommand);
            generalCommand.Cmds.Remove(GeneralCommandEnum.Ready);

            // Assert
            mockLobby.Verify(x => x.AddPlayer(generalCommand.Author), Times.Once);
            mockLobby.Verify(x => x.RemovePlayer(generalCommand.Author), Times.Once);
            mockLobby.Verify(x => x.PlayerReady(generalCommand), Times.Once);
            mockLobby.Verify(x => x.GetReadyCommand(generalCommand.Author), Times.Once);
        }
        public void with_general_command_serialize_expect_proper_deserial()
        {
            var command = new GeneralCommand
            {
                Command = "",
                CommandDataCollection = new List <MockCommandData>
                {
                    new MockCommandData {
                        Data = true, DataType = typeof(bool).AssemblyQualifiedName
                    }
                },
                Id = Guid.NewGuid()
            };

            var serial    = command.SerializeToJson();
            var deserial  = serial.DeserializeJson <IMessage>(command.Type);
            var deserial1 = serial.DeserializeJson <GeneralCommand>();

            Assert.AreEqual(command.Id, deserial.Id);
            Assert.AreEqual(command.CommandDataCollection.Count(), deserial1.CommandDataCollection.Count());
        }
Exemple #24
0
        public ActionResult SendFullGeneralCommand(
            [FromRoute, Required] string?sessionId,
            [FromBody, Required] GeneralCommand command)
        {
            var currentSession = RequestHelpers.GetSession(_sessionManager, _authContext, Request);

            if (command == null)
            {
                throw new ArgumentException("Request body may not be null");
            }

            command.ControllingUserId = currentSession.UserId;

            _sessionManager.SendGeneralCommand(
                currentSession.Id,
                sessionId,
                command,
                CancellationToken.None);

            return(NoContent());
        }
Exemple #25
0
        public ActionResult SendSystemCommand(
            [FromRoute, Required] string?sessionId,
            [FromRoute, Required] string?command)
        {
            var name = command;

            if (Enum.TryParse(name, true, out GeneralCommandType commandType))
            {
                name = commandType.ToString();
            }

            var currentSession = RequestHelpers.GetSession(_sessionManager, _authContext, Request);
            var generalCommand = new GeneralCommand
            {
                Name = name,
                ControllingUserId = currentSession.UserId
            };

            _sessionManager.SendGeneralCommand(currentSession.Id, sessionId, generalCommand, CancellationToken.None);

            return(NoContent());
        }
Exemple #26
0
        public void resendCommand() // command called by the check funciton if there is a failed command. it repackages the command info and resends it.
        {

            for (int a = 0; a < rerunIndex; a++) //runs through all failed commands regardless if there is only 1 failed command
            {
                int currentIndex = 0;
                for (int b = 0; b < deviceNum; b++) // runs through all devices refardless if there is only 1 device
                {
                    if (device[b].comport.Equals(myRerun[a].comport)) currentIndex = b; // need to know what device index needs a command to be resent - so i compare comports
                }
                if (device[currentIndex].count < 58) // we don't want any repetitive commands from this coil loop to enter into the next coil loop to we stop sending commands for the last second of the loop.
                {
                    GeneralCommand rerunCommand = new GeneralCommand(device[currentIndex].m_si, 0x01, myRerun[a].command, myRerun[a].data, "resent command");
                    rerunCommand.RegisterListener(this); device[currentIndex].target.Queue(rerunCommand);
                    device[currentIndex].ackFailures = myRerun[a].name;
                    writeToLog(currentIndex, true);
                    device[currentIndex].ackFailures = "";
                }
            }
            rerunIndex = 0; // after all failed commands are resent, set this value back to 0
            myRerun = new rerun[20]; // also creat a new stuct array
        }
Exemple #27
0
        private void Upload()
        {
            StreamReader   sr = new StreamReader(m_full_file_name, Encoding.ASCII);
            GeneralCommand upload_cmd;
            string         line;

            byte[] sdata;
            ushort seg_cnt = 0;

            byte[] seg_cnt_ba;

            m_telegram_acknowledged.Reset();

            while ((line = sr.ReadLine()) != null && !m_aborted)
            {
                line = "00" + line + "\r\n";
                //Console.Write(".");

                sdata      = Encoding.Default.GetBytes(line.ToCharArray());
                seg_cnt_ba = BitConverter.GetBytes(seg_cnt);
                sdata[0]   = seg_cnt_ba[0];
                sdata[1]   = seg_cnt_ba[1];
                seg_cnt++;

                upload_cmd = new GeneralCommand(m_interface, 0x01, 0x2E, sdata, "");
                m_target.Queue(upload_cmd);
                m_target.Wait();

                if (!m_telegram_acknowledged.WaitOne(1000))
                {
                    break;
                }
            }

            sr.Close();
        }
 public Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken)
 {
     return(SendMessage(command.Name, command.Arguments, cancellationToken));
 }
Exemple #29
0
        private Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken)
        {
            switch (command.Name)
            {
            case GeneralCommandType.VolumeDown:
                return(_device.VolumeDown(cancellationToken));

            case GeneralCommandType.VolumeUp:
                return(_device.VolumeUp(cancellationToken));

            case GeneralCommandType.Mute:
                return(_device.Mute(cancellationToken));

            case GeneralCommandType.Unmute:
                return(_device.Unmute(cancellationToken));

            case GeneralCommandType.ToggleMute:
                return(_device.ToggleMute(cancellationToken));

            case GeneralCommandType.SetAudioStreamIndex:
                if (command.Arguments.TryGetValue("Index", out string index))
                {
                    if (int.TryParse(index, NumberStyles.Integer, _usCulture, out var val))
                    {
                        return(SetAudioStreamIndex(val));
                    }

                    throw new ArgumentException("Unsupported SetAudioStreamIndex value supplied.");
                }

                throw new ArgumentException("SetAudioStreamIndex argument cannot be null");

            case GeneralCommandType.SetSubtitleStreamIndex:
                if (command.Arguments.TryGetValue("Index", out index))
                {
                    if (int.TryParse(index, NumberStyles.Integer, _usCulture, out var val))
                    {
                        return(SetSubtitleStreamIndex(val));
                    }

                    throw new ArgumentException("Unsupported SetSubtitleStreamIndex value supplied.");
                }

                throw new ArgumentException("SetSubtitleStreamIndex argument cannot be null");

            case GeneralCommandType.SetVolume:
                if (command.Arguments.TryGetValue("Volume", out string vol))
                {
                    if (int.TryParse(vol, NumberStyles.Integer, _usCulture, out var volume))
                    {
                        return(_device.SetVolume(volume, cancellationToken));
                    }

                    throw new ArgumentException("Unsupported volume value supplied.");
                }

                throw new ArgumentException("Volume argument cannot be null");

            default:
                return(Task.CompletedTask);
            }
        }
Exemple #30
0
        public void readESN_HW(int myDevice)                                                                                                 // read the esn and hw version
        {
            GeneralCommand readParaLE = new GeneralCommand(device[myDevice].m_si, 0x01, 0x03, new byte[] { 0x03, 0x01 }, "read ESN and HW"); //"read general device parameters for ESN (little endian)");

            readParaLE.RegisterListener(this); device[myDevice].target.Queue(readParaLE);
        }