Пример #1
0
        private void buttonTestFTP_Click(object sender, EventArgs e)
        {
            this.doLog("Test FTP: (1) ");

            this.textBoxTestFTP.Text = "Setting radiostate ...";
            Application.DoEvents();

            WirelessManager.SetWLANState(this.checkBoxTestWLAN.Checked);

            WirelessManager.SetWWANState(this.checkBoxTestWWAN.Checked);

            if (this.checkBoxTestWWAN.Checked)
            {
                this.textBoxTestFTP.Text = "Attaching to GPRS ...";
                Application.DoEvents();
                if (!this.cmr.Connected)
                {
                    this.cmr.Connect(this.textBoxGPRSEntry.Text,
                        ConnMgr.ConnectionMode.Asynchronous,
                        this.textBoxGPRSBenutzer.Text,
                        this.textBoxGPRSKennwort.Text,
                        this.textBoxGPRSAPN.Text);

                    int maxWait = 30;
                    while (!cmr.Connected && maxWait-- > 0)
                    {
                        Thread.Sleep(1000);
                    }
                }
            }

            try
            {
                this.textBoxTestFTP.Text = "Testing ...";
                Application.DoEvents();
                OpenNETCF.Net.Ftp.FTP client = new OpenNETCF.Net.Ftp.FTP(this.textBoxDataServer.Text);
                if (client != null)
                {
                    client.BeginConnect(this.textBoxDataBenutzer.Text, this.textBoxDataKennwort.Text);
                    int numWait = 50;
                    while (!client.IsConnected && numWait-- > 0)
                    {
                        Thread.Sleep(100);
                    }
                    if (client.IsConnected)
                    {
                        client.TransferType = OpenNETCF.Net.Ftp.FTPTransferType.Binary;
                        if (client.SendBytes((int)1) == 1)
                        {
                            this.textBoxTestFTP.Text = "FTP test succesful";
                        }
                        else
                        {
                            this.textBoxTestFTP.Text = "FTP test failed";
                        }
                        client.Disconnect();
                    }
                    else
                    {
                        this.textBoxTestFTP.Text = "FTP connect failed";
                    }
                    client = null;
                }
                else
                {
                    this.textBoxTestFTP.Text = "FTP nicht geöffnet";
                }
            }
            catch (Exception ee)
            {
                this.textBoxTestFTP.Text = ee.Message;
                this.doLog(this.textBoxDataBenutzer.Text + ":" + this.textBoxDataKennwort.Text + "@" + this.textBoxDataServer.Text + " -> " + ee.Message);
            }
        }
Пример #2
0
        // This is the main State Machine Loop
        // It will activate, based up certain sequence and mutual exclusion rules, any Task which was set to from IDLE to PLAN by the timers
        // It will also initiate certain cleanup when a Task is DONE and revert it back to IDLE
        private void timerSecond_Tick(object sender, EventArgs e)
        {
            this.timeSpan = DateTime.Now.Subtract(this.startTime);

            this.doRefreshOutputStatusDisplay();

            if (this.stopTest) // V1.3.0 interrupt any plans is we are supposed to stop
            {
                if (this.stateFTPSession == TaskTestState.PLAN)
                {
                    this.stateFTPSession = TaskTestState.IDLE;
                }
                if (this.stateScanBarcode == TaskTestState.PLAN)
                {
                    this.stateScanBarcode = TaskTestState.IDLE;
                }
                if (this.stateSnapPhoto == TaskTestState.PLAN)
                {
                    this.stateSnapPhoto = TaskTestState.IDLE;
                }
                if (this.stateTourCycle == TaskTestState.PLAN)
                {
                    this.stateTourCycle = TaskTestState.IDLE;
                }
                if (this.stateGPSPosition != TaskTestState.IDLE)
                {
                    this.stateGPSPosition = TaskTestState.DONE;
                }
                // V1.5.2
                bool result = (PowerPolicyNotify(PowerMode.UnattendedMode, UNATTENDED_OFF) != 0);

            }

            switch (this.testPlanType)
            {
                case TestPlanType.BELADE_PLAN:
                    if (this.checkBoxIncludeBeladePhase.Checked)
                    {
                        this.timerStateMachine.Enabled = false;
                        this.timerStateMachine.Interval = 5000; // V1.5.2 go in relax mode
                        this.doStartBelade();
                        this.timerStateMachine.Enabled = true;

                    }
                    else
                    {
                        this.doLog("Test: skip Belade ...");
                        this.testPlanType = TestPlanType.TOUR_PLAN;
                    }
                    break;

                case TestPlanType.TOUR_PLAN:
                    if (this.checkBoxIncludeTourPhase.Checked)
                    {
                        this.timerStateMachine.Enabled = false;
                        this.timerStateMachine.Interval = 5000; // V1.5.2 go in relax mode
                        this.doStartTour();
                        this.timerStateMachine.Enabled = true;
                    }
                    else
                    {
                        this.doLog("Test: skip Tour ...");
                        this.testPlanType = TestPlanType.RUHE_PLAN;
                    }
                    break;

                case TestPlanType.RUHE_PLAN:
                    if (this.checkBoxIncludeRuhePhase.Checked)
                    {
                        this.timerStateMachine.Enabled = false;
                        this.timerStateMachine.Interval = 20000; // V1.5.2 go in relax mode
                        this.doStartRuhe();
                        this.timerStateMachine.Enabled = true;

                    }
                    else
                    {
                        this.doLog("Test: skip Ruhe ...");
                        this.testPlanType = TestPlanType.DONE;
                    }
                    break;

                case TestPlanType.RUHE_EXEC:

                    if (!stopTest && !skipPhase)
                    {
                        // this.doLog("Ruhephase ping");
                        if (this.radioButtonRuheSuspend.Checked)
                        {
                            this.timerStateMachine.Enabled = false; // temp disable the looper because we get dual entry after resume

                            // V1.5.2
                            // long fileStartTime = DateTime.Now.AddHours((double)this.numericUpDownRuheLaufzeitStunden.Value).AddMinutes((double)this.numericUpDownRuheLaufzeitMinuten.Value).ToFileTime();
                            long fileStartTime = this.startTime.AddHours((double)this.numericUpDownRuheLaufzeitStunden.Value).AddMinutes((double)this.numericUpDownRuheLaufzeitMinuten.Value).ToFileTime();

                            // V1.5.2 wakeup every hour to log battery , so let's see which interval is shorter
                            long fileStartTime2 = DateTime.Now.AddHours((double)1.0).ToFileTime();
                            // long fileStartTime2 = DateTime.Now.AddMinutes((double)2.0).ToFileTime();
                            if (fileStartTime2 < fileStartTime)
                            {
                                fileStartTime = fileStartTime2;
                            }

                            long localFileStartTime = 0;
                            FileTimeToLocalFileTime(ref fileStartTime, ref localFileStartTime);

                            SystemTime systemStartTime = new SystemTime();
                            FileTimeToSystemTime(ref localFileStartTime, systemStartTime);
                            // we plan to be woken up after a few hours
                            string myappname = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
                            CeRunAppAtTime(myappname, systemStartTime);

                            this.doLog("Suspend für " + this.numericUpDownRuheLaufzeitStunden.Value.ToString() + "h" + this.numericUpDownRuheLaufzeitMinuten.Value.ToString() + "m");

                            // V1.5.2
                            UtilMethods.SuspendDevice();
                            // PowerPolicyNotify(PowerMode.SuspendKeyOrPwrButtonPressed, 0);

                            this.timeSpan = DateTime.Now.Subtract(this.startTime); // V1.5.0
                            this.doLog("Wakeup nach: " + this.timeSpan.ToString().Split('.')[0]);

                            // V2.5.2
                            this.lastLevel = SystemNotification.GetBatteryLife();
                            this.doLog("Akku " + this.lastLevel.ToString() + "%");

                            this.timerStateMachine.Enabled = true;
                        }
                        else if (!this.deviceInUnattended)
                        {
                            // V1.5.2
                            this.timerManageUnattended.Interval = 1000;
                            this.timerManageUnattended.Enabled = true;
                        }
                        this.timeSpan = DateTime.Now.Subtract(this.startTime); // V1.5.0

                        // if (timeSpan.Hours >= this.testHours) // V1.3.0 use global var
                        if (timeSpan.CompareTo(this.testSpan)>0) // V1.5.2
                        {
                            this.doLog("Ruhephase ending");
                            Form1.SystemIdleTimerReset();
                            Form1.SetSystemPowerState(IntPtr.Zero, Form1.POWER_STATE_ON, 0);

                            this.timerManageUnattended.Enabled = false;
                            this.deviceInUnattended = false;

                            this.testPlanType = TestPlanType.DONE;

                            this.doLog("Test beendet nach: " + this.timeSpan.ToString().Split('.')[0]);
                            this.testPlanType = TestPlanType.DONE;
                        } // if we were woken up earlier, then we look back into this

                    }
                    else
                    {
                        this.testPlanType = TestPlanType.DONE;
                    }
                    break;

                case TestPlanType.BELADE_EXEC:
                case TestPlanType.TOUR_EXEC:
                case TestPlanType.DONE:

                    if (this.stateGPSPosition == TaskTestState.DONE)
                    {
                        this.timerExecGPS.Enabled = false;
                        this.stateGPSPosition = TaskTestState.IDLE;
                        Thread t = new Thread(new ThreadStart(this.threadedCloseGPS));
                        t.Start();
                    }

                    // GPS .. this may need to be reviewed
                    // Currently the GPS is opened every time on test demand and closed after Fix or Timeout
                    // The event handler waits for a Fix-position or else the Close timer will end
                    // Not sure there is time enough for fix, although Windows should also have the GPS open
                    // Alternatively, the GPS needs to be opened at the start of the Test and closed at the End and at test interval we simply take the current status immediately

                    if (this.stateGPSPosition == TaskTestState.PLAN)
                    {
                        try
                        {
                            this.doLog("GPS: obtain location ...");
                            if (this.gps.OpenComPort() == 0)
                            { // V1.3.0
                            this.stateGPSPosition = TaskTestState.EXEC;
                            this.timerExecGPS.Enabled = true;
                            }
                            else
                            {
                                this.stateGPSPosition = TaskTestState.IDLE;
                                this.doLog("GPS: fail to open GPS");
                            }
                        }
                        catch
                        {
                            this.stateGPSPosition = TaskTestState.IDLE;
                        }
                    }

                    if (this.stateTourCycle == TaskTestState.PLAN && (this.stateSnapPhoto == TaskTestState.IDLE || this.stateSnapPhoto == TaskTestState.PLAN))
                    {
                        this.numTourCycles++;
                        this.stateTourCycle = TaskTestState.EXEC;
                        this.numTourCycleScanBarcodes = (int)(this.numericUpDownTourCycleScanBarcodes.Value);
                    }
                    if (this.stateTourCycle == TaskTestState.EXEC && this.numTourCycleScanBarcodes > 0 && this.stateScanBarcode == TaskTestState.IDLE)
                    {
                        this.numTourCycleScanBarcodes--;
                        this.stateScanBarcode = TaskTestState.PLAN;
                    }
                    if (this.stateTourCycle == TaskTestState.EXEC && this.numTourCycleScanBarcodes == 0)
                    {
                        if (this.textBoxDataServer.Text != string.Empty && (int)(this.numericUpDownTourCycleFTPSessionSize.Value) > 0)
                        {
                            this.numFTPSessions++;
                            this.doLog("Interval Data #" + this.numTourCycles.ToString() + ": (" + this.numericUpDownTourCycleFTPSessionSize.Value.ToString() + ")");
                            try
                            {
                                OpenNETCF.Net.Ftp.FTP client = new OpenNETCF.Net.Ftp.FTP(this.textBoxDataServer.Text);
                                if (client != null)
                                {
                                    client.BeginConnect(this.textBoxDataBenutzer.Text, this.textBoxDataKennwort.Text);
                                    int numWait = 50;
                                    while (!client.IsConnected && numWait-- > 0)
                                    {
                                        Thread.Sleep(100);
                                    }
                                    if (client.IsConnected)
                                    {
                                        client.TransferType = OpenNETCF.Net.Ftp.FTPTransferType.Binary;
                                        this.numTotalDataBytes += (int)(this.numericUpDownTourCycleFTPSessionSize.Value);
                                        client.SendBytes((int)this.numericUpDownTourCycleFTPSessionSize.Value);
                                        client.Disconnect();
                                        client = null;
                                        this.numFTPSuccess++;
                                    }
                                    else
                                    {
                                        this.doLog("FTP nicht geöffnet");
                                    }
                                }
                                else
                                {
                                    this.doLog("FTP nicht geöffnet");
                                }
                            }
                            catch (Exception ee)
                            {
                                this.doLog(this.textBoxDataBenutzer.Text + ":" + this.textBoxDataKennwort.Text + "@" + this.textBoxDataServer.Text + " -> " + ee.Message);
                            }
                        }
                        this.stateTourCycle = TaskTestState.DONE;
                    }

                    if (this.stateTourCycle == TaskTestState.DONE)
                    {
                        this.stateTourCycle = TaskTestState.IDLE;
                    }

                    if (this.stateScanBarcode == TaskTestState.PLAN && (this.stateSnapPhoto == TaskTestState.IDLE || this.stateSnapPhoto == TaskTestState.PLAN))
                    {
                        this.numScanBarcodes++;
                        this.doLog("Scan #" + this.numScanBarcodes.ToString());
                        this.stateScanBarcode = TaskTestState.EXEC;
                        this.da.Connect();
                        this.da.ScanTimeout = this.timeoutScanBarcode;
                        this.da.ScanBarcode();
                    }

                    if (this.stateScanBarcode == TaskTestState.DONE)
                    {
                        this.da.Disconnect();
                        this.stateScanBarcode = TaskTestState.IDLE;
                    }

                    if (this.stateSnapPhoto == TaskTestState.PLAN && this.stateScanBarcode == TaskTestState.IDLE && this.stateTourCycle == TaskTestState.IDLE)
                    {
                        this.numSnapPhotos++;
                        this.doLog("Photo #" + this.numSnapPhotos.ToString());
                        this.stateSnapPhoto = TaskTestState.EXEC;
                        try
                        {
            #if HSM
                            this.ca.Connect(this.pictureBox1.Handle, null, null);
            #else
                            this.ca.Connect(ref this.pictureBox1, null, null);
            #endif
                            long resolutionSetting;
                            this.ca.GetResolutionCount(out resolutionSetting);
                            this.ca.SetResolution((uint)(resolutionSetting - 1));
                            this.ca.SetProperty(CameraProperty.Illumination, 1, PropertyMode.Manual);
                            this.ca.SetProperty(CameraProperty.ColorEnable, 1, PropertyMode.Manual);
                            this.ca.StartPreview();
                            this.timerExecPhoto.Enabled = true;
                        }
                        catch (Exception ee)
                        {
                            this.doLog("Exception in exec photo"+ee.Message);
                        }
                    }

                    if (this.stateSnapPhoto == TaskTestState.DONE)
                    {
                        try
                        {
                            this.ca.StopPreview();
                            this.ca.Disconnect();
                        }
                        catch
                        {
                        }
                        this.stateSnapPhoto = TaskTestState.IDLE;
                    }

                    if (this.stateFTPSession == TaskTestState.PLAN)
                    {
                        this.numFTPSessions++;
                        this.doLog("Data #" + this.numFTPSessions.ToString() + ": (" + this.numSendDataBytes.ToString() + ") ");
                        this.stateFTPSession = TaskTestState.EXEC;
                        if (this.textBoxDataServer.Text != string.Empty)
                        {
                            try
                            {
                                OpenNETCF.Net.Ftp.FTP client = new OpenNETCF.Net.Ftp.FTP(this.textBoxDataServer.Text);
                                if (client != null)
                                {
                                    client.BeginConnect(this.textBoxDataBenutzer.Text, this.textBoxDataKennwort.Text);
                                    int numWait = 50;
                                    while (!client.IsConnected && numWait-- > 0)
                                    {
                                        Thread.Sleep(100);
                                    }
                                    if (client.IsConnected)
                                    {
                                        client.TransferType = OpenNETCF.Net.Ftp.FTPTransferType.Binary;
                                        this.numTotalDataBytes += this.numSendDataBytes;
                                        client.SendBytes(this.numSendDataBytes);
                                        client.Disconnect();
                                        client = null;
                                        this.numFTPSuccess++;
                                    }
                                    else
                                    {
                                        this.doLog("FTP nicht geöffnet");
                                    }
                                }
                                else
                                {
                                    this.doLog("FTP nicht geöffnet");
                                }
                            }
                            catch (Exception ee)
                            {
                                this.doLog(this.textBoxDataBenutzer.Text + ":" + this.textBoxDataKennwort.Text + "@" + this.textBoxDataServer.Text + " -> " + ee.Message);
                            }
                        }
                        this.stateFTPSession = TaskTestState.DONE;
                    }

                    if (this.stateFTPSession == TaskTestState.DONE)
                    {
                        this.stateFTPSession = TaskTestState.IDLE;
                    }

                    if ((this.stopTest || this.skipPhase || timeSpan.CompareTo(this.testSpan) > 0) &&
                        (this.stateFTPSession != TaskTestState.IDLE || this.stateSnapPhoto != TaskTestState.IDLE || this.stateScanBarcode != TaskTestState.IDLE || this.stateGPSPosition != TaskTestState.IDLE))
                    {
                        // do nothing yet, wait until substates are finised
                        if (!complained)
                        {
                            // V1.5.3
                            this.timerPlanScan.Enabled = false;
                            this.timerPlanPhoto.Enabled = false;
                            this.timerPlanData.Enabled = false;
                            this.timerPlanTourCycle.Enabled = false;
                            this.timerPlanGPS.Enabled = false;

                            complained = true;
                            this.doLog("waiting for sub test to complete");
                        }
                    } else

                    // V1.5.2
                    // if (!this.stopTest && (this.skipPhase || timeSpan.Hours >= this.testHours || this.testPlanType == TestPlanType.DONE)) // V1.3.0 use global var
                    if (!this.stopTest && (this.skipPhase || timeSpan.CompareTo(this.testSpan)>0 || this.testPlanType == TestPlanType.DONE)) // V1.3.0 use global var
                        {
                        // V1.3.0
                        this.timerPlanScan.Enabled = false;
                        this.timerPlanPhoto.Enabled = false;
                        this.timerPlanData.Enabled = false;
                        this.timerPlanTourCycle.Enabled = false;
                        this.timerPlanGPS.Enabled = false;
                        // V1.5.3
                        // this.timerExecGPS.Enabled = false;
                        this.doLog("Test beenden ...");

                        // V1.3.2 test for TestType
                        if (!this.skipPhase && this.testPlanType == TestPlanType.BELADE_EXEC && (int)(this.numericUpDownBeladeFTPBulkSize.Value) > 0)
                        {
                            this.numFTPSessions++;
                            this.doLog("Bulk #" + this.numFTPSessions.ToString() + ": (" + this.numericUpDownBeladeFTPBulkSize.Value.ToString() + ") ");
                            if (this.textBoxDataServer.Text != string.Empty)
                            {
                                try
                                {
                                    OpenNETCF.Net.Ftp.FTP client = new OpenNETCF.Net.Ftp.FTP(this.textBoxDataServer.Text);
                                    if (client != null)
                                    {
                                        client.BeginConnect(this.textBoxDataBenutzer.Text, this.textBoxDataKennwort.Text);
                                        int numWait = 50;
                                        while (!client.IsConnected && numWait-- > 0)
                                        {
                                            Thread.Sleep(100);
                                        }
                                        if (client.IsConnected)
                                        {
                                            client.TransferType = OpenNETCF.Net.Ftp.FTPTransferType.Binary;
                                            this.numTotalDataBytes += (int)(this.numericUpDownBeladeFTPBulkSize.Value) * 1024 * 1024;
                                            client.SendBytes((int)this.numericUpDownBeladeFTPBulkSize.Value * 1024 * 1024);
                                            client.Disconnect();
                                            client = null;
                                            this.numFTPSuccess++;
                                        }
                                        else
                                        {
                                            this.doLog("FTP nicht geöffnet");
                                        }
                                    }
                                    else
                                    {
                                        this.doLog("FTP nicht geöffnet");
                                    }
                                }
                                catch (Exception ee)
                                {
                                    this.doLog(this.textBoxDataBenutzer.Text + ":" + this.textBoxDataKennwort.Text + "@" + this.textBoxDataServer.Text + " -> " + ee.Message);
                                }
                            }
                            // V1.5.2
                            bool result = (PowerPolicyNotify(PowerMode.UnattendedMode, UNATTENDED_OFF) != 0);

                        }

                        this.doLog("Akku " + SystemNotification.GetBatteryLife().ToString() + "%");

                        // this.timerSecond.Enabled = false; // V1.3.0
                        // V1.5.0 jump to next major test
                        switch (this.testPlanType)
                        {
                            case TestPlanType.BELADE_EXEC:
                                this.timeSpan = DateTime.Now.Subtract(this.startTime); //V1.5.0
                                this.doLog("Test beendet nach: " + this.timeSpan.ToString().Split('.')[0]);
                                this.testPlanType = TestPlanType.TOUR_PLAN;
                                break;
                            case TestPlanType.TOUR_EXEC:
                                this.timeSpan = DateTime.Now.Subtract(this.startTime); //V1.5.0
                                this.doLog("Test beendet nach: " + this.timeSpan.ToString().Split('.')[0]);
                                this.testPlanType = TestPlanType.RUHE_PLAN;
                                //Thread t = new Thread(new ThreadStart(this.threadedCloseGPS));
                                //t.Start();
                                break;
                            case TestPlanType.DONE:
                                this.stopTest = true; // V1.3.0
                                this.buttonSkipPhase.Enabled = false;
                                this.buttonStop.Enabled = false; // V1.3.2
                                // this.testPlanType = TestPlanType.NONE;
                                break;
                            default: // can't be here ...
                                break;
                        }
                        this.skipPhase = false;
                    }

                    if (this.stopTest && this.stateFTPSession == TaskTestState.IDLE && this.stateSnapPhoto == TaskTestState.IDLE && this.stateScanBarcode == TaskTestState.IDLE && this.stateGPSPosition == TaskTestState.IDLE)
                    {
                        Form1.SystemIdleTimerReset();
                        Form1.SetSystemPowerState(IntPtr.Zero, Form1.POWER_STATE_ON, 0);

                        // V1.5.3
                        this.timerPlanScan.Enabled = false; // V1.3.0
                        this.timerPlanPhoto.Enabled = false; // V1.3.0
                        this.timerPlanData.Enabled = false; // V1.3.0
                        this.timerPlanTourCycle.Enabled = false; // V1.3.0
                        this.timerPlanGPS.Enabled = false; // V1.3.0

                        this.timerManageUnattended.Enabled = false;
                        this.timerStateMachine.Enabled = false;
                        this.timerStateMachine.Interval = 1000; // V1.5.2 go back in speed mode next time
                        this.menuItemExit.Enabled = true;
                        this.menuItemStart.Enabled = true;
                        this.testPlanType = TestPlanType.NONE;

                        this.gps = null;

                        // V1.5.2
                        this.doSetTimeouts(3 * 60, 0, 0, 0, 5 * 60, 0);
                    }

                    this.doRefreshOutputStatusDisplay();
                    break;

                default: // IDLE, DONE
                    this.doLog("Default? : " + this.testPlanType.ToString());
                    this.timerStateMachine.Enabled = false;
                    break;
            }
        }