Exemplo n.º 1
0
/**
*
* \brief Main Thread
*
*/
void TestMgr::Exec(void) {

	bool doExit = false;

	// Print settings
	std::cout << std::endl;
	if (m_TestId.length() > 0) {
		std::cout << "Test Id        : " << m_TestId.toStdString() << std::endl;
	}
	if (m_TestNote.length() > 0) {
		std::cout << "Test Note      : " << m_TestNote.toStdString() << std::endl;
	}

	// Init loop
	while (!doExit) {
		// Open devices and initialize data
		bool success = InitDevicesAndData();
		if (!success) {
			doExit = true;
			std::cout << "Init returned error, waiting for control-c to abort." << std::endl;
			while (!m_AbortFlag) {
				QThread::msleep(200);
			}
			break;
		}
		// Only run once through the loop
		break;
	}

#if 0
	RunPidAutoTuneTest();
	CalibrateTempToPwm();
	ReadAcVoltage();
#endif

	while (!doExit) {

		if (m_AbortFlag) {
			doExit = true;
			break;
		}

		// Do the work of reading temp and voltage
		// Does not return until exit
		// RunWithoutPid();
		// RunWithPid();
		TestTempReading();

		QThread::msleep(10);
	}

	m_Sub20.Close();

	// Signal to any slots listening
	DoneSignal();
}
Exemplo n.º 2
0
DlgLoadRegistry::DlgLoadRegistry(SoaWg *_wg, unsigned int _regId) : QDialog(_wg),
	wg(_wg),
	regId(_regId),
	loading(false) {

	ui.setupUi(this);
	setWindowTitle("Load run-time registry");

	ui.mergeButton->setEnabled(false);

	connect(ui.loadButton, SIGNAL(clicked()), this, SLOT(LoadSlot()));
	connect(&loader, SIGNAL(DoneSignal(QString)), this, SLOT(DoneSlot(QString)));
	connect(&loader, SIGNAL(UpdateSignal(QString)), this, SLOT(UpdateSlot(QString)));
	connect(ui.mergeButton, SIGNAL(clicked()), this, SLOT(MergeSlot()));
}
Exemplo n.º 3
0
void Layer7::LoadSlot(QNetworkReply *reply) {

    switch (op) {

    case lsoStart:

        emit UpdateSignal("Loading started...");
        Logger::ins.Header() << "Loading registry data from " << http.Url() << "data/ started...\r\n";
        http.Propfind(http.Url() + "data/");
        op = lsoListDomains;

        break;

    case lsoListDomains:

        if (reply->error() == QNetworkReply::NoError) {

            QString replyString(reply->readAll());
            sl::log << "lsoListDomains: " << SQ(replyString) << sl::end;

            Propfinds elements = http.ParsePropfindReply(replyString);
            for (Propfinds::iterator e = elements.begin(); e != elements.end(); ++e)
                if (e->href != http.Url()) {
                    domains.push_back(GtDomain(SQ(e->href), SQ(e->name)));
                    Logger::ins.Info() << "Service domain: " << e->name << "\r\n";
                    emit UpdateSignal("Service Domain: " + e->name);
                }

            if (SelectFirstDomain()) {

                loaded = true;

                // check if all domains match domains from the db

                for (unsigned int d = 0; d < domains.size(); ++d)
                    if (!sdoms.contains(QS(domains[d].name))) {
                        loaded = false;
                        Logger::ins.Error() << "Repository does not contain service domain named " << QS(domains[d].name) << "\r\n";
                        emit DoneSignal("Repository does not contain service domain named " + QS(domains[d].name));
                    }

                if (loaded) {
                    op = lsoListServices;
                    http.Propfind(QS(SelectedDomain().href) + "web/");
                }
            }
        }
        else
            emit UpdateSignal(reply->errorString());

        break;

    case lsoListServices:

        if (reply->error() == QNetworkReply::NoError) {

            QString replyString(reply->readAll());
            sl::log << "lsoListServices: " << SQ(replyString) << sl::end;

            Propfinds elements = http.ParsePropfindReply(replyString);
            for (Propfinds::iterator e = elements.begin(); e != elements.end(); ++e)
                if (e->href != http.Url() && e->name != "OLD" && e->name != "REMOVED") {

                    endpoints.push_back(GtEndpoint(item++ * 100 + REPO_TB_IDX, SelectedDomain().name, SQ(e->href), SQ(e->name)));
                    Logger::ins.Info() << "Service: " << e->name << "\r\n";
                    emit UpdateSignal("Service: " + e->name);
                }
        }
        else
            emit UpdateSignal(reply->errorString());

        if (SelectNextDomain())
            http.Propfind(QS(SelectedDomain().href) + "web/");
        else if (SelectFirstEndpoint()) {
            Logger::ins.Info() << "Parsing index files...\r\n";
            emit UpdateSignal("Parsing index files...");
            op = lsoGetIndexXml;
            Logger::ins.Info() << "Parsing " << QS(SelectedEndpoint().urlRegistryFolder) << "index.xml...\r\n";
            http.Get(QS(SelectedEndpoint().urlRegistryFolder) + "index.xml");
        }

        break;

    case lsoGetIndexXml:

        if (reply->error() == QNetworkReply::NoError) {

            QString replyString(reply->readAll());
            sl::log << "lsoGetIndexXml: " << SQ(replyString) << sl::end;

            QDomDocument doc;
            doc.setContent(replyString);

            for (QDomElement r = doc.firstChildElement(); !r.isNull(); r = r.nextSiblingElement()) {

                if (r.nodeName() == "service") {

                    for (QDomElement e = r.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {

                        if (e.nodeName() == "files") {

                            for (QDomElement f = e.firstChildElement(); !f.isNull(); f = f.nextSiblingElement()) {

                                QDomAttr r = f.attributeNode("root"), t = f.attributeNode("type");
                                if (!r.isNull() && r.nodeValue() == "true" && !t.isNull() && t.value() == "WSDL")
                                    SelectedEndpoint().urlWSDL = SQ(f.text());
                            }
                        }
                        else if (e.nodeName() == "name")
                            SelectedEndpoint().intGivenName = SQ(e.text());
                        else if (e.nodeName() == "version")
                            SelectedEndpoint().intGivenVersion = SQ(e.text());
                        else if (e.nodeName() == "policyVersion")
                            SelectedEndpoint().policyVersion = SQ(e.text());
                        else if (e.nodeName() == "enabled")
                            SelectedEndpoint().enabled = SQ(e.text());
                        else if (e.nodeName() == "soap")
                            SelectedEndpoint().soap = SQ(e.text());
                        else if (e.nodeName() == "resolutionPath")
                            SelectedEndpoint().resolutionPath = SQ(e.text());
                        else if (e.nodeName() == "id")
                            SelectedEndpoint().intGivenId = SQ(e.text());
                        else if (e.nodeName() == "protectedEndpoint")
                            SelectedEndpoint().protectedEndpoint = SQ(e.text());
                    }

                    break;
                }
            }

            if (SelectedEndpoint().urlWSDL == "") {
                Logger::ins.Warning() << "WSDL file url not found for endpoint '" << QS(SelectedEndpoint().intGivenName) << "'\r\n";
                emit UpdateSignal("WSDL file url not found for endpoint '" + QS(SelectedEndpoint().intGivenName) + "'");
                SelectedEndpoint().serviceName = SelectedEndpoint().intGivenName;
            }

            if (SelectedEndpoint().protectedEndpoint == "") {
                Logger::ins.Warning() << "Ignoring non-protected endpoint '" << QS(SelectedEndpoint().intGivenName) << "'\r\n";
                emit UpdateSignal("Ignoring non-protected endpoint '" + QS(SelectedEndpoint().intGivenName) + "'");
                RemoveSelectedEndpoint();
            }
        }
        else {
            Logger::ins.Error() << reply->errorString() << "\r\n";
            emit UpdateSignal(reply->errorString());
        }

        if (SelectNextEndpoint()) {
            Logger::ins.Info() << "Parsing " << QS(SelectedEndpoint().urlRegistryFolder) << "index.xml...\r\n";
            http.Get(QS(SelectedEndpoint().urlRegistryFolder) + "index.xml");
        }
        else if (SelectFirstEndpoint()) {
            Logger::ins.Info() << "Parsing WSDL files...\r\n";
            emit UpdateSignal("Parsing WSDL files...");
            op = lsoGetWsdl;
            Logger::ins.Info() << "Parsing " << QS(SelectedEndpoint().urlRegistryFolder + SelectedEndpoint().urlWSDL) << "\r\n";
            http.Get(QS(SelectedEndpoint().urlRegistryFolder + SelectedEndpoint().urlWSDL));
        }

        break;

    case lsoGetWsdl:

        if (reply->error() == QNetworkReply::NoError) {

            QString replyString(reply->readAll());
            sl::log << "lsoGetWsdl: " << SQ(replyString) << sl::end;

            QDomDocument doc;
            doc.setContent(replyString);

            for (QDomElement r = doc.firstChildElement(); !r.isNull(); r = r.nextSiblingElement()) {
                if (r.nodeName() == "definitions" || r.nodeName() == "wsdl:definitions") {

                    QDomAttr n = r.attributeNode("targetNamespace");
                    if (!n.isNull())
                        SelectedEndpoint().targetNamespace = SQ(n.nodeValue());

                    n = r.attributeNode("name");
                    if (!n.isNull())
                        SelectedEndpoint().definitionName = SQ(n.nodeValue());

                    // find all service names

                    std::vector<std::string> serviceNames;
                    for (QDomElement e = r.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {

                        if (e.nodeName() == "service" || e.nodeName() == "wsdl:service") {
                            QDomAttr a = e.attributeNode("name");
                            if (!a.isNull())
                                serviceNames.push_back(SQ(a.nodeValue()));
                        }
                    }

                    // assign service name

                    if (serviceNames.size() == 1)
                        SelectedEndpoint().serviceName = serviceNames[0];
                    else if (serviceNames.size() > 1) {

                        // search service node name with best fit to protected endpoint string

                        std::map<int, std::string> m;
                        for (std::vector<std::string>::iterator s = serviceNames.begin(); s != serviceNames.end(); ++s)
                            m.insert(std::pair<int, std::string>(LevenshteinDistance(SelectedEndpoint().protectedEndpoint, *s, true), *s));

                        SelectedEndpoint().serviceName = m.begin()->second;
                    }
                    else {
                        Logger::ins.Warning() << "Service name not found for endpoint '" << QS(SelectedEndpoint().intGivenName) + "'\r\n";
                        emit UpdateSignal("Service name not found for endpoint '" + QS(SelectedEndpoint().intGivenName) + "'");
                        SelectedEndpoint().serviceName = SelectedEndpoint().intGivenName;
                    }

                    break;
                }
            }
        }
        else {
            Logger::ins.Error() << reply->errorString() << "\r\n";
            emit UpdateSignal(reply->errorString());
        }

        if (SelectNextEndpoint()) {
            Logger::ins.Info() << "Parsing " << QS(SelectedEndpoint().urlRegistryFolder + SelectedEndpoint().urlWSDL) << "\r\n";
            http.Get(QS(SelectedEndpoint().urlRegistryFolder + SelectedEndpoint().urlWSDL));
        }
        else {
            Logger::ins.Info() << "Finished loading registry.\r\n";
            emit DoneSignal("Finished loading.");
        }

        break;

    default:
        ;
    }
}
Exemplo n.º 4
0
void Layer7::Cancel() {

    op = lsoStop;
    http.Abort();
    emit DoneSignal("Canceled.");
}
Exemplo n.º 5
0
void Layer7::ErrorSlot(const QString &text) {
    emit UpdateSignal(text);
    emit DoneSignal("Stopped.");
}
Exemplo n.º 6
0
void TestMgr::CalibrateTempToPwm(void) {

	// int responseBytes;
	// bool outOfOrderFlag = false;
	UtilTimer runTimer;
	UtilTimer startAveragingTimer;
	uint16_t startPwm = 10;
	uint16_t stopPwm = 100;
	uint16_t testPwm = startPwm;
	bool doExit = false;
	std::vector<float> tempVec;

	printf("Temp to PWM Calibrate Thread Start\n");

	// Open file to store calibration data
	std::ofstream tempToPwmStream;
	std::stringstream fileNameSs;
	fileNameSs << "C:/ES/VocPhase1Test/PidData/TempToPwm.cpp";
	std::string fileName = fileNameSs.str();
	tempToPwmStream.open(fileName.c_str(), (std::ios::trunc | std::ios::out));
	if (tempToPwmStream.is_open()) {
		tempToPwmStream << "struct TempToPwm_t {" << std::endl;
		tempToPwmStream << "\tfloat temp;" << std::endl;
		tempToPwmStream << "\tuint8_t pwm;" << std::endl;
		tempToPwmStream << "};" << std::endl;
		tempToPwmStream << std::endl;
		tempToPwmStream << "TempToPwm_t tempToPwm[] = {" << std::endl;
	}

	m_Sub20.TurnOffCooler();

	runTimer.ResetCountdownTimer(20000);
	startAveragingTimer.ResetCountdownTimer(10000);

	while (!doExit) {
		if (m_AbortFlag) {
			doExit = true;
			break;
		}

		if (startAveragingTimer.IsCountdownTimerExpired()) {
			if (ReadTemp()) {
				printf("\n\nTempToPwm: temperature(%d):  %f, mean: %f, stdev: %f\n", testPwm, m_PlateTempDegreesC, m_TempMean, m_TempStdev);
				tempVec.push_back(m_PlateTempDegreesC);
			}

			//if (m_PlateTempDegreesC >= 50.0) {
			//    m_Sub20.TurnOffCooler();
			//}
		}

		if (runTimer.IsCountdownTimerExpired() && (m_TempStdev < 0.15)) {
			float tempSum = std::accumulate(tempVec.begin(), tempVec.end(), 0.0);
			float tempMean = tempSum / tempVec.size();
			unsigned int pwm = testPwm;
			if (tempToPwmStream.is_open()) {
				tempToPwmStream << "\t{ "
					<< std::setprecision(3) << tempMean << ", "
					<< pwm << " },"
					<< std::endl;
			}

			printf("\n\nTempToPwm: Avg temperature for pwm %d is %f, mean: %f, stdev: %f\n", testPwm, tempMean, m_TempMean, m_TempStdev);
			printf("TempToPwm: Process new pwm: %d\n", testPwm);
			QThread::msleep(1000);

			// Set new pwm
			m_Sub20.HeaterPwmUpdate(testPwm);

			// Update for next time
			testPwm++;

			// Check if we are at the end of run
			if (testPwm >= stopPwm) {
				if (tempToPwmStream.is_open()) {
					tempToPwmStream << "};" << std::endl;
					tempToPwmStream.close();
				}
				doExit = true;
				break;
			}

			runTimer.ResetCountdownTimer(20000);
			startAveragingTimer.ResetCountdownTimer(5000);
			tempVec.clear();
		}

		QThread::msleep(1000);
	}

	printf("Calibrate Thread Exit\n");

	QThread::msleep(100);

	// Signal to any slots listening
	DoneSignal();
}