コード例 #1
0
        /* Non-Command functions */

        // This function calls the open com port function of the SSP library.
        public bool OpenComPort(TextBox log = null)
        {
            if (log != null)
            {
                log.AppendText("Opening com port\r\n");
            }
            return(LibraryHandler.OpenPort(ref cmd));
        }
コード例 #2
0
ファイル: Form1Events.cs プロジェクト: kalkansa/stserver
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     hopperRunning     = false;
     payoutRunning     = false;
     CHelpers.Shutdown = true;
     LibraryHandler.ClosePort();
     Properties.Settings.Default.Comms       = logTickBox.Checked;
     Properties.Settings.Default.ComPortVal1 = Global.ValidatorComPort;
     Properties.Settings.Default.SSP1        = Global.Validator1SSPAddress;
     Properties.Settings.Default.SSP2        = Global.Validator2SSPAddress;
     Properties.Settings.Default.Save();
 }
コード例 #3
0
 // This is used to send a command via SSP to the validator
 public bool SendCommand(TextBox log)
 {
     if (!LibraryHandler.SendCommand(ref m_cmd, ref m_info))
     {
         m_Comms.UpdateLog(m_info, true);
         if (log != null)
         {
             log.AppendText("Sending command failed\r\nPort status: " + m_cmd.ResponseStatus.ToString() + "\r\n");
         }
         return(false);
     }
     // update the log after every command
     m_Comms.UpdateLog(m_info);
     return(true);
 }
コード例 #4
0
        public bool SendCommand(TextBox log)
        {
            // Backup data and length in case we need to retry
            byte[] backup = new byte[255];
            cmd.CommandData.CopyTo(backup, 0);
            byte length = cmd.CommandDataLength;

            // attempt to send the command
            if (!LibraryHandler.SendCommand(ref cmd, ref info))
            {
                m_Comms.UpdateLog(info, true); // Update on fail
                if (log != null)
                {
                    log.AppendText("Sending command failed\r\nPort status: " + cmd.ResponseStatus.ToString() + "\r\n");
                }
                return(false);
            }

            // update the log after every command
            m_Comms.UpdateLog(info);
            return(true);
        }
コード例 #5
0
        // This function performs a number of commands in order to setup the encryption between the host and the validator.
        public bool NegotiateKeys(TextBox log = null)
        {
            byte i;

            // make sure encryption is off
            m_cmd.EncryptionStatus = false;

            // send sync
            if (log != null)
            {
                log.AppendText("Syncing... ");
            }
            if (!SendSync())
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            LibraryHandler.InitiateKeys(ref m_keys, ref m_cmd);

            // send generator
            m_cmd.CommandData[0]    = CCommands.Generic.SSP_CMD_SET_GENERATOR;
            m_cmd.CommandDataLength = 9;
            if (log != null)
            {
                log.AppendText("Setting generator... ");
            }
            for (i = 0; i < 8; i++)
            {
                m_cmd.CommandData[i + 1] = (byte)(m_keys.Generator >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            // send modulus
            m_cmd.CommandData[0]    = CCommands.Generic.SSP_CMD_SET_MODULUS;
            m_cmd.CommandDataLength = 9;
            if (log != null)
            {
                log.AppendText("Sending modulus... ");
            }
            for (i = 0; i < 8; i++)
            {
                m_cmd.CommandData[i + 1] = (byte)(m_keys.Modulus >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            // send key exchange
            m_cmd.CommandData[0]    = CCommands.Generic.SSP_CMD_REQUEST_KEY_EXCHANGE;
            m_cmd.CommandDataLength = 9;
            if (log != null)
            {
                log.AppendText("Exchanging keys... ");
            }
            for (i = 0; i < 8; i++)
            {
                m_cmd.CommandData[i + 1] = (byte)(m_keys.HostInter >> (8 * i));
            }

            if (!SendCommand(log))
            {
                return(false);
            }
            if (log != null)
            {
                log.AppendText("Success\r\n");
            }

            m_keys.SlaveInterKey = 0;
            for (i = 0; i < 8; i++)
            {
                m_keys.SlaveInterKey += (UInt64)m_cmd.ResponseData[1 + i] << (8 * i);
            }

            LibraryHandler.CreateFullKey(ref m_keys);

            // get full encryption key
            m_cmd.Key.FixedKey    = 0x0123456701234567;
            m_cmd.Key.VariableKey = m_keys.KeyHost;

            if (log != null)
            {
                log.AppendText("Keys successfully negotiated\r\n");
            }

            return(true);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: kalkansa/stserver
        // The main program loop, this is to control the validator, it polls at
        // a value set in this class (pollTimer).
        public void MainLoop()
        {
            btnRun.Enabled  = false;
            btnHalt.Enabled = true;
            Thread tNV11Rec = null, tHopRec = null;

            // Connect to the validators
            ConnectToNV11(textBox1);
            ConnectToHopper(textBox1);

            NV11.EnableValidator();
            Hopper.EnableValidator();

            // While application is still active
            while (!CHelpers.Shutdown)
            {
                // Setup form layout on first run
                if (!FormSetup)
                {
                    SetupFormLayout();
                    FormSetup = true;
                }

                // If the hopper is supposed to be running but the poll fails
                if (hopperRunning && !Hopper.DoPoll(textBox1))
                {
                    textBox1.AppendText("Lost connection to SMART Hopper\r\n");
                    // If the other unit isn't running, refresh the port by closing it
                    if (!NV11Running)
                    {
                        LibraryHandler.ClosePort();
                    }
                    hopperRunning = false;
                    tHopRec       = new Thread(() => ReconnectHopper());
                    tHopRec.Start();
                }

                // If the NV11 is supposed to be running but the poll fails
                if (NV11Running && !NV11.DoPoll(textBox1))
                {
                    textBox1.AppendText("Lost connection to NV11\r\n");
                    // If the other unit isn't running, refresh the port by closing it
                    if (!hopperRunning)
                    {
                        LibraryHandler.ClosePort();
                    }
                    NV11Running = false;
                    tNV11Rec    = new Thread(() => ReconnectNV11());
                    tNV11Rec.Start();
                }

                UpdateUI();
                timer1.Enabled = true;

                while (timer1.Enabled)
                {
                    Application.DoEvents();
                    Thread.Sleep(1); // Yield so windows can schedule other threads to run
                }
            }

            //close com port
            LibraryHandler.ClosePort();

            btnRun.Enabled  = true;
            btnHalt.Enabled = false;
        }
コード例 #7
0
ファイル: CPayout.cs プロジェクト: kalkansa/stserver
        /* Non-Command functions */

        // Use the library handler to open the port
        public bool OpenPort()
        {
            return(LibraryHandler.OpenPort(ref cmd));
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: kalkansa/stserver
        // The main program loop, this is to control the validator, it polls at
        // a value set in this class (pollTimer).
        public void MainLoop()
        {
            this.Enabled    = true;
            btnRun.Enabled  = false;
            btnHalt.Enabled = true;

            // Connect to the validators (non-threaded for initial connect)
            ConnectToSMARTPayout(textBox1);
            ConnectToHopper(textBox1);

            // Enable validators
            Payout.EnableValidator();
            Hopper.EnableValidator();

            // While app active
            while (!CHelpers.Shutdown)
            {
                // Setup form layout on first run
                if (!FormSetup)
                {
                    SetupFormLayout();
                    FormSetup = true;
                }

                // If the Hopper is supposed to be running but the poll fails
                if (hopperRunning && !hopperConnecting && !Hopper.DoPoll(textBox1))
                {
                    textBox1.AppendText("Lost connection to SMART Hopper\r\n");
                    // If the other unit isn't running, refresh the port by closing it
                    if (!payoutRunning)
                    {
                        LibraryHandler.ClosePort();
                    }
                    hopperRunning = false;
                    // Create and start a reconnection thread, this allows this loop to continue executing
                    // and polling the other validator
                    tHopRec = new Thread(() => ReconnectHopper());
                    tHopRec.Start();
                }
                // Same as above but for the Payout
                if (payoutRunning && !payoutConnecting && !Payout.DoPoll(textBox1))
                {
                    textBox1.AppendText("Lost connection to SMART Payout\r\n");
                    // If the other unit isn't running, refresh the port by closing it
                    if (!hopperRunning)
                    {
                        LibraryHandler.ClosePort();
                    }
                    payoutRunning = false;
                    // Create and start a reconnection thread, this allows this loop to continue executing
                    // and polling the other validator
                    tSPRec = new Thread(() => ReconnectPayout());
                    tSPRec.Start();
                }
                UpdateUI();
                timer1.Enabled = true;
                while (timer1.Enabled)
                {
                    Application.DoEvents();
                }
            }

            btnRun.Enabled  = true;
            btnHalt.Enabled = false;
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: kalkansa/stserver
        // The main program loop, this is to control the validator, it polls at
        // a value set in this class (pollTimer).
        public void MainLoop()
        {
            Enabled = true;

            // Connect to the validators
            ConnectToNoteValidator(textBox1);
            ConnectToHopper(textBox1);

            // Enable the validators
            Validator.EnableValidator(textBox1);
            Hopper.EnableValidator(textBox1);

            // While either one is still running
            while (!CHelpers.Shutdown)
            {
                // Setup form layout on first run
                if (!FormSetup)
                {
                    SetupFormLayout();
                    FormSetup = true;
                }

                // If the hopper is supposed to be running but the poll fails
                if (hopperRunning && !Hopper.DoPoll(textBox1))
                {
                    textBox1.AppendText("Lost connection to SMART Hopper\r\n");
                    hopperRunning = false;
                    // If the other device has also stopped, close the port
                    if (!validatorRunning)
                    {
                        LibraryHandler.ClosePort();
                    }
                    // Create a reconnection thread, this allows this loop to continue executing
                    // and polling the other validator
                    Thread t = new Thread(ReconnectHopper);
                    t.Start();
                }
                // If the validator is supposed to be running but the poll fails
                if (validatorRunning && !Validator.DoPoll(textBox1))
                {
                    textBox1.AppendText("Lost connection to note validator\r\n");
                    validatorRunning = false;
                    // If the other device has also stopped, close the port
                    if (!hopperRunning)
                    {
                        LibraryHandler.ClosePort();
                    }
                    // Create a reconnection thread, this allows this loop to continue executing
                    // and polling the other validator
                    Thread t = new Thread(ReconnectValidator);
                    t.Start();
                }
                UpdateUI();
                timer1.Enabled = true;
                while (timer1.Enabled)
                {
                    Application.DoEvents();
                }
            }

            LibraryHandler.ClosePort();

            btnRun.Enabled  = true;
            btnHalt.Enabled = false;
        }