void CJavaScript_Protocol::slot_TagChange(CPointI *pPoint_, QVariant /*VarSet_*/)
{
    CJavaScript_DataChange_Point *pPoint = (CJavaScript_DataChange_Point *)pPoint_;

    qDebug()<<"222222222222222"<<__func__<<__LINE__<<pPoint->m_strLink;
    for (int nJavaScriptCount = 0; nJavaScriptCount < pPoint->m_JavaScriptList.count(); ++nJavaScriptCount)
    {
        JavaScript *pJavaScript = pPoint->m_JavaScriptList.at(nJavaScriptCount);
        qDebug()<<__func__<<__LINE__<<pPoint->m_strLink<<pJavaScript->m_strScript;
        QScriptEngine engine;
        QMap<QString,PointStruct*>::iterator iterator;
        for (iterator = pJavaScript->m_PointStructMap.begin(); iterator != pJavaScript->m_PointStructMap.end(); ++iterator)
        {
            QString strName = iterator.value()->m_strName;
            qDebug()<<__func__<<__LINE__<<pPoint->m_strLink<<pJavaScript->m_strScript<<strName;
            CTagI *pTag = iterator.value()->m_pPoint->m_pTag;
            if (pTag)
            {
                iterator.value()->m_pPoint->m_SrcValue = pTag->GetProjectValue()->GetVarValue();
                engine.globalObject().setProperty(strName,pTag->GetProjectValue()->GetVarValue().toFloat());
                qDebug()<<__func__<<__LINE__<<pPoint->m_strLink<<pJavaScript->m_strScript<<strName<<pTag->GetProjectValue()->GetVarValue().toFloat();
            }else
            {
                qDebug()<<__func__<<__LINE__<<pPoint->m_strLink<<pJavaScript->m_strScript<<strName<<"return;";
//                return;
            }
        }
        engine.evaluate(pJavaScript->m_strScript);
        for (iterator = pJavaScript->m_PointStructMap.begin(); iterator != pJavaScript->m_PointStructMap.end(); ++iterator)
        {
            QString strName = iterator.value()->m_strName;
            qDebug()<<__func__<<__LINE__<<pPoint->m_strLink<<pJavaScript->m_strScript<<strName;
            CTagI *pTag = iterator.value()->m_pPoint->m_pTag;
            if (pTag)
            {
                qDebug()<<__func__<<__LINE__<<pTag->GetName();
                QVariant value = engine.globalObject().property(strName).toVariant();
                if (value != iterator.value()->m_pPoint->m_SrcValue)
                {
                    engine.globalObject().setProperty(strName,pTag->GetProjectValue()->GetVarValue().toFloat());
                    pTag->SetValue(iterator.value()->m_pPoint,value,value);
                    qDebug()<<__func__<<__LINE__<<pTag->GetName()<<"setvalue1"<<value;
                }else
                {
                    qDebug()<<__func__<<__LINE__<<pTag->GetName()<<"setvalue2"<<value;
                }
            }else
            {
//                return;
            }
        }
    }

}
Пример #2
0
void CProtocolDemo::GetRand(CPointDemoBase *pPoint_)
{
//    qDebug()<<"xxxxxxxxxxxxxxxxxxxxxxx"<<pPoint_->m_nFunction<<pPoint_->m_strRTDBName;
    QVariant Value;
    int nType = pPoint_->m_nFunction;
    int nMax = pPoint_->m_nPara1;
    int nMin = pPoint_->m_nPara2;
    int nStep = pPoint_->m_nPara3;
    CTagI *pTempTagI = pPoint_->m_pTag;
//    qDebug()<<__func__<<"pTempTagI ="<<pTempTagI;
//    qDebug()<<"pPoint_->m_pTag"<<pPoint_->m_pTag->GetName();
    if (pTempTagI)
    {
        QString strValue;
        if (pTempTagI->GetPointCollection())
        {
            strValue = pTempTagI->GetProjectValue()->GetVarValue().toString();
        }
        int m_nLastValue = strValue.toInt();
        //功能:生成各种随机数据
        //参数:nType生成数据的方式
        //返回值:
        double fValue=0.0;
        //	srand(time(NULL));
        switch(nType)
        {
        case 70://常量   参数为:70 常量值
            fValue = nMax;
            break;
        case 72://一定范围内的随机量 参数为:72 最大值 最小值
            fValue=  rand()%(nMax-nMin)+nMin;
            break;
        case 74://单调增加 参数为:74 初值  终值 步长(<0 为单调递减)
            {
                int nStartValue = nMax;
                int nEndValue = nMin;
                Q_ASSERT(nStartValue <= nEndValue);

                m_nLastValue += nStep;
                if(m_nLastValue>nEndValue) //不在有效值范围内)
                {
                    m_nLastValue = nStartValue;
                }
                else if(m_nLastValue<nStartValue)
                {
                    m_nLastValue = nEndValue;
                }
            }
            fValue=  m_nLastValue;
            break;
        case 76://正弦变量 参数为:76 基值 幅值 步长(角度)
            {
                int nBaseValue = nMax;
                int nK = nMin;
                fValue = nBaseValue + nK * sin(m_nLastValue*3.14/180.0);
                m_nLastValue += nStep;
                if(m_nLastValue>360)
                {
                    m_nLastValue -= 360;
                }
            }
            break;
        case 78://方波  参数为:78 高值,低值(扫描周期就是方波长度)
            if(m_nLastValue>0)
            {
                fValue = nMax;
            }
            else
            {
                fValue = nMin;
            }
            m_nLastValue = 1 - m_nLastValue;
            break;
        case 80://遥信量 参数为:80 (扫描周期就是变位周期)
//            qDebug()<<"AAAAAAAAAAAAAAAAAAAAAAAAAAAAA"<<pPoint_->m_nFunction<<pPoint_->m_strRTDBName;
            m_nLastValue = 1 - m_nLastValue;
            fValue=m_nLastValue;
            break;
        case 82://遥信量  参数为:82 每次变位的可能性(0-100)
            {
                int nRand= rand()%101;//0--100
//                qDebug()<<"ZZZZZZZZz"<<m_nLastValue<<nRand;
                if(nRand<nMax)
                {
                    m_nLastValue = 1 - m_nLastValue;
                }
                fValue=m_nLastValue;
            }
            break;
        default:
            Q_ASSERT(false);//("IO变量定义无效:未定义的随机变量取值方式 funcno=100 param1=%d\n",nType);
            break;
        }
        Value.setValue(fValue);
//        qDebug()<<"Value_.setValue(fValue);"<<Value;
        pTempTagI->SetValue(pPoint_,Value,Value);
    }

//    return true;
}
Пример #3
0
void CProtocolDemo::GetMemoryInfo(CPointDemoBase *pPoint_)
{
    CTagI *pTempTagI = pPoint_->m_pTag;
    if (pTempTagI)
    {
        double fValue=0.0;
        switch(pPoint_->m_nFunction)
        {
        case 20://物理内存总数
        {
            QString strTitle_("MemTotal");
            QFile file(PROC_MEMINFO);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        fValue = m.total;
                        break;
                    }
                }
                file.close();
            }
        }
            break;
        case 22://物理内存空闲
        {
            QString strTitle_("MemFree");
            QFile file(PROC_MEMINFO);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        fValue = m.total;
                        break;
                    }
                }
                file.close();
            }
        }
            break;
        case 24://物理内存使用
        {
            QString strTitle_1("MemTotal");
            QString strTitle_2("MemFree");
            double value1 = 0.0;
            double value2 = 0.0;
            QFile file(PROC_MEMINFO);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_1))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        value1 = m.total;
                        break;
                    }else if (lineList.at(i).contains(strTitle_2))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        value2 = m.total;
                        break;
                    }
                }
                file.close();
                fValue = value1 - value2;
            }
        }
            break;
        case 26://虚内存总数
        {
            QString strTitle_("VmallocTotal");
            QFile file(PROC_MEMINFO);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        fValue = m.total;
                        break;
                    }
                }
                file.close();
            }
        }
            break;
        case 28://虚内存空闲
        {
            QString strTitle_1("VmallocTotal");
            QString strTitle_2("VmallocUsed");
            double value1 = 0.0;
            double value2 = 0.0;
            QFile file(PROC_MEMINFO);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_1))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        value1 = m.total;
                        break;
                    }else if (lineList.at(i).contains(strTitle_2))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        value2 = m.total;
                        break;
                    }
                }
                file.close();
                fValue = value1 - value2;
            }
        }
            break;
        case 30://虚内存占用
        {
            QString strTitle_("VmallocUsed");
            QFile file(PROC_MEMINFO);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        fValue = m.total;
                        break;
                    }
                }
                file.close();
            }
        }

            break;
        case 32://文件页总数
            break;
        case 34://文件页空闲
            break;
        case 36://文件页占用
            break;
        case 38://内存占用率
            break;
        case 40://当前程序占用空间
        {
            uid_t current_pid = getpid();   //获取进程ID
            QString strTitle_("VmallocUsed");
            QString filename = QString("/proc/%1/stat").arg(QString::number(current_pid));
            qDebug()<<"current pid="<<current_pid;
            QFile file(filename);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        fValue = m.total;
                        break;
                    }
                }
                file.close();
            }


        }
            break;
        case 42://内存使用峰值
        {
            QString strValue;
            if (pTempTagI->GetPointCollection())
            {
                strValue = pTempTagI->GetProjectValue()->GetVarValue().toString();
            }
            int m_nLastValue = strValue.toInt();
            QString strTitle_1("MemTotal");
            QString strTitle_2("MemFree");
            double value1 = 0.0;
            double value2 = 0.0;
            QFile file(PROC_MEMINFO);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_1))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        value1 = m.total;
                        break;
                    }else if (lineList.at(i).contains(strTitle_2))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        value2 = m.total;
                        break;
                    }
                }
                file.close();
                if (m_nLastValue < value1-value2)
                {
                    fValue = value1 - value2;
                }
            }
        }
            break;
        case 44://占用的虚拟内存大小
        {
            QString strTitle_("VmallocUsed");
            QFile file(PROC_MEMINFO);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        fValue = m.total;
                        break;
                    }
                }
                file.close();
            }
        }
            break;
        case 46://占用的虚拟内存峰值
        {
            QString strValue;
            if (pTempTagI->GetPointCollection())
            {
                strValue = pTempTagI->GetProjectValue()->GetVarValue().toString();
            }
            int m_nLastValue = strValue.toInt();
            QString strTitle_("VmallocUsed");
            QFile file(PROC_MEMINFO);
            MEM_OCCUPY m;
            if (file.open(QIODevice::ReadOnly| QIODevice::Text))
            {
                QTextStream in(&file);
                QString data = in.readAll();
                QStringList lineList = data.split('\n');
                for (int i = 0; i < lineList.count(); ++i)
                {
                    if (lineList.at(i).contains(strTitle_))
                    {
                        sscanf (lineList.at(i).toStdString().data(), "%s %lu %s", m.name, &m.total, m.name2);
                        if (m_nLastValue < (int)m.total)
                        {
                            fValue = m.total;
                        }
                        break;
                    }
                }
                file.close();
            }
        }
            break;
        default:
            Q_ASSERT(false);//("IO变量定义无效:未定义的随机变量取值方式 funcno=100 param1=%d\n",nType);
            break;
        }
        QVariant Value(fValue);
//        qDebug()<<"Value_.setValue(fValue);"<<Value;
        pTempTagI->SetValue(pPoint_,Value,Value);
    }
}