Beispiel #1
0
        public ExpanderCommandHandle EnqueueCommand(ExpanderCommand expcmd)
        {
            ExpanderCommandHandle cmdhdl = new ExpanderCommandHandle(new AutoResetEvent(false), expcmd);

            Task.Run(() =>
            {
                var sw = new Stopwatch();
                sw.Start();
                var t       = new System.Timers.Timer(1000);
                t.AutoReset = true;
                t.Elapsed  += (a, b) => { FileTextLogger.logger.AppendLog("LEC - Waiting for simplex-command execution to complete. " + TimeSpan.FromTicks(sw.ElapsedTicks).ToString()); };
                t.Start();

                FileTextLogger.logger.AppendLog("LEC - connecting to = " + connprop.IPAddress + " " + connprop.TCPPort);
                FileTextLogger.logger.AppendLog("LEC - executing command");

                lock (pending_command_queue_lock)
                    pending_command_queue.Enqueue(cmdhdl);

                sw.Stop();
                t.Stop();

                FileTextLogger.logger.AppendLog("LEC, SCE - Command Enqueued");
            });

            return(cmdhdl);
        }
Beispiel #2
0
        public ExpanderCommandHandle EnqueueCommand(ExpanderCommand expcmd)
        {
            ExpanderCommandHandle cmdhdl = new ExpanderCommandHandle(new AutoResetEvent(false), expcmd);

            Task.Run(() =>
            {
                var sw = new Stopwatch();
                sw.Start();

                var t       = new System.Timers.Timer(1000);
                t.AutoReset = true;
                t.Elapsed  += (a, b) => { FileTextLogger.logger.AppendLog("REC, SCE - Waiting for simplex-command execution to complete. " + TimeSpan.FromTicks(sw.ElapsedTicks).ToString()); };
                t.Start();

                var ctc = new CommandTransactionContainer(device_id, new ExpanderCommand[] { expcmd });

                try
                {
                    FileTextLogger.logger.AppendLog("REC, SCE - connecting to = " + hi.TCPConnectionProperties.AddressString + " " + hi.TCPConnectionProperties.Port);

                    using (var client = new TcpClient())
                    {
                        client.NoDelay        = true;
                        client.ReceiveTimeout = 5000;
                        client.SendTimeout    = 5000;
                        client.Connect(hi.TCPConnectionProperties.AddressString, hi.TCPConnectionProperties.Port);

                        FileTextLogger.logger.AppendLog("REC, SCE - executing command");

                        try
                        {
                            XMLSerdes.SendPacket(client, ctc);
                        }
                        catch (Exception ex)
                        {
                            FileTextLogger.logger.AppendLog("REC, SCE - An error occured while serializing expander command");
                            FileTextLogger.logger.AppendLog(ex.Message);
                            throw;
                        }

                        try
                        {
                            ctc = (CommandTransactionContainer)XMLSerdes.Decode(XMLSerdes.ReceivePacket(client, typeof(CommandTransactionContainer)), typeof(CommandTransactionContainer));
                        }
                        catch (Exception ex)
                        {
                            FileTextLogger.logger.AppendLog("REC, SCE - An error occured while deserializing expander command");
                            FileTextLogger.logger.AppendLog(ex.Message);
                            throw;
                        }

                        FileTextLogger.logger.AppendLog("REC, SCE - Command Executed");
                    }
                }
                catch (Exception ex)
                {
                    FileTextLogger.logger.AppendLog("REC, SCE - Simplex-command execution failed to complete. The operation has been aborted.");
                    FileTextLogger.logger.AppendLog(ex.Message);
                }

                sw.Stop();
                t.Stop();

                cmdhdl.Command = ctc.ExpanderCommands[0];

                cmdhdl.Handle.Set();
            });

            return(cmdhdl);
        }
Beispiel #3
0
 public ExpanderCommandHandle(AutoResetEvent handle, ExpanderCommand command)
 {
     this.handle  = handle;
     this.command = command;
 }
        private void Refresh()
        {
            FileTextLogger.logger.AppendLog("REM, GEN - Begin Refresh");

            ExpanderCommandHandle[] cmdhdls;
            ExpanderCommand[]       expcmds = new ExpanderCommand[5];
            expcmds[0] = new ExpanderCommand(ExpanderCommand.READ_EXPANDERS_COMMAND);
            expcmds[1] = new ExpanderCommand(ExpanderCommand.READ_FAN_SPEED_COMMAND);
            expcmds[2] = new ExpanderCommand(ExpanderCommand.READ_POWER_MONITOR_COMMAND);
            expcmds[3] = new ExpanderCommand(ExpanderCommand.READ_TEMPERATURES_COMMAND);
            expcmds[4] = new ExpanderCommand(ExpanderCommand.READ_UPTIME_COMMAND);

            lock (expander_connection_lock)
                cmdhdls = expconn.EnqueueCommands(expcmds);

            FileTextLogger.logger.AppendLog("REM, GEN - Enqueued Commands");

            ExpanderState new_state = new ExpanderState();

            //fill expander state
            cmdhdls[0].Handle.WaitOne();
            byte[] buffer = new byte[4];
            Array.Copy(cmdhdls[0].Command.RxPacket, 1, buffer, 0, 4);

            bool[] converted = buffer.SelectMany(Utilities.GetBits).ToArray(); //resulting order 0: 1, 0 1: 1, 0
            Array.Copy(converted, 8, new_state.Expander0State, 0, 8);
            Array.Copy(converted, 0, new_state.Expander0State, 8, 8);
            Array.Copy(converted, 24, new_state.Expander1State, 0, 8);
            Array.Copy(converted, 16, new_state.Expander1State, 8, 8);

            //apply hardware configuration
            lock (hwconfig_lock)
                for (int index_counter = 0; index_counter < 16; index_counter++)
                {
                    new_state.Expander0State[index_counter] ^= exphwconfig.Expander0Configuration[index_counter];
                    new_state.Expander1State[index_counter] ^= exphwconfig.Expander1Configuration[index_counter];
                }
            FileTextLogger.logger.AppendLog("REM, GEN - Command 1 of 5 completed execution.");

            cmdhdls[1].Handle.WaitOne();
            buffer = new byte[2];
            Array.Copy(cmdhdls[1].Command.RxPacket, 1, buffer, 0, 2);
            new_state.FanSpeed = BitConverter.ToUInt16(buffer, 0);
            FileTextLogger.logger.AppendLog("REM, GEN - Command 2 of 5 completed execution.");

            cmdhdls[2].Handle.WaitOne();
            buffer = new byte[8];
            Array.Copy(cmdhdls[2].Command.RxPacket, 1, buffer, 0, 8);
            new_state.BusVoltage = BitConverter.ToSingle(buffer, 0);
            new_state.BusPower   = BitConverter.ToSingle(buffer, 4);
            FileTextLogger.logger.AppendLog("REM, GEN - Command 3 of 5 completed execution.");

            cmdhdls[3].Handle.WaitOne();
            buffer = new byte[12];
            Array.Copy(cmdhdls[3].Command.RxPacket, 1, buffer, 0, 12);
            new_state.FanTemperature    = BitConverter.ToSingle(buffer, 0);
            new_state.Board0Temperature = BitConverter.ToSingle(buffer, 4);
            new_state.Board1Temperature = BitConverter.ToSingle(buffer, 8);
            FileTextLogger.logger.AppendLog("REM, GEN - Command 4 of 5 completed execution.");

            cmdhdls[4].Handle.WaitOne();
            buffer = new byte[8];
            Array.Copy(cmdhdls[4].Command.RxPacket, 1, buffer, 0, 4);
            new_state.Uptime = BitConverter.ToUInt64(buffer, 0);
            FileTextLogger.logger.AppendLog("REM, GEN - Command 5 of 5 completed execution.");

            lock (expander_state_lock)
                expst = new ExpanderState(new_state);

            FileTextLogger.logger.AppendLog("REM, GEN - State Updated");

            if (freshstateevent != null)
            {
                freshstateevent(this, new ExpanderEventArgs(new_state));
            }

            FileTextLogger.logger.AppendLog("REM, GEN - Event Generated");

            FileTextLogger.logger.AppendLog("REM, GEN - End Refresh");
        }