Gas safety management system written in Qt 28- simulation tool

I. Introduction

Simulation tool is particularly useful in a number of programs related to hardware communication, particularly the need to review this decade did the project, 95% of projects are software and hardware interaction, looks like a combination of hardware and software projects more vitality some pure software or pure hardware, and not so good control, if it is a combination of hardware and software, even if the hardware does not make money, you can also earn money by controlling software components and services, and if the software is free, then it would have to buy hardware, must be run on this hardware to software to play the best results, examples of such free software on hardware to make money, but also a lot of these kinds of contact with dozens of companies, is a similar situation, plus the combination of hard and soft services , with these three products, the strongest vitality, you can go further.

Back to Topic, simulation tools, primarily to hardware in not yet fully mature, according to a communication protocol agreed in the beginning, to write their own software simulation data the next crew, then used their main stress tests, determine whether the data protocol analysis is correct, it is estimated most of the companies are so small, after the project started, the software and hardware are generally started at the same time, the hardware will not say wait until the completion of the software to do, the software will not wait until the hardware is ripe do, those are not realistic, both need to keep the FBI can eventually mature and stable, hardware engineers typically use serial debugging assistant, network debugging aids and other tools used to check whether the data in the correct bit machine, and sends a corresponding tool response data look-bit machine is correct, and software engineers need to write a program to simulate the hardware of their own data, in particular the stress tests do, after all, even if the hardware is ready, in most scenarios impossible to add a particularly large number of devices you test, the venue was not so big, so you need to write your own program to do stress tests Simulate hundreds of thousands of devices send and receive data, for the next new software is nothing more than a class or you can control the number of hardware engineers with respect to the simpler still, of course, these simulations owned by simulation test, the real scene or after the need to take equipment for testing, but good software simulation debugging equipment, completed with respect to 80% of the test function, followed by an external real device testing only need to deal with exceptional circumstances.

Skin Open Source: https://gitee.com/feiyangqingyun/QWidgetDemo https://github.com/feiyangqingyun/QWidgetDemo
File name: styledemo

Experience Address: https://gitee.com/feiyangqingyun/QWidgetExe https://github.com/feiyangqingyun/QWidgetExe
File name: bin_sams.zip

Second, the functional characteristics

  1. Collect data port, serial port support + network port, serial port supports baud rate set free + serial number, network support freely set the IP address + communication ports, each port supports acquisition cycle, default 1 second address, set the communication timeout support frequency default 3 times, support the largest reconnection time for the re-read off-line equipment.
  2. Controller information, the controller can be added to the name, address + control model selection controller, the controller is provided below the number of detectors.
  3. Probe information, the bit number can be added, can be freely selected probe type, gas type, gas symbol, the value of the high alarm, low reported values, buffer values, a value is cleared, if enabled, an alarm sound, a background map, the storage period, the value conversion of decimal places, the alarm delay time, alarm type (HH, LL, HL) and the like.
  4. Detector Model Controller Model + + + gas symbol gas species, can be freely arranged.
  5. Map supports importing and delete all the corresponding map position detector can freely drag saved.
  6. Port information + + probe information controller information, import and export support + + print exported to Excel.
  7. + + Alarm log record recording the user, the query condition combination to support multiple, such as + period + Controller detectors, all record print support exported to Excel +.
  8. Export to excel record of support for all forms such as excel + wps file versions, does not rely on software such as excel.
  9. You can delete data within a specified time frame, auto clean up early data, set the maximum number of record-keeping.
  10. Support forwarding alarm messages, the plurality of support receiving phone number, the transmission interval can be set, such as instant or the transmission 6 hours send all the alarm messages, message content is too long, a number of messages automatically split.
  11. Support alarm mail forwarding, support for receiving a plurality of mailboxes, the transmission interval can be set, such as instant transmission or six hours all the alarm information once transmitted, to support attachments.
  12. High + Low message packets Color Color values ​​Color + + + 0 normal color profile curves + background color, etc., can be freely selected.
  13. Software English title Chinese title + + + logo Copyright paths can be freely set.
  14. Provides switch switched on the alarm sound + + + automatic login remember passwords.
  15. Sound the alarm can be set to play frequency interface available in 17 skin file selection.
  16. Support cloud data synchronization, cloud database information can be set, such as database name, username + password.
  17. Support network forwarding and receiving network, the network is open to receive, parse udp software to receive data from. Network forwarding support multiple target IP, thus achieving a local collection of software, free data to the client, at any time to view the detector data.
  18. Automatically remembers the last stop of the user interface + additional information, automatic application restart.
  19. Alarm automatically switches to a map corresponding to the detector button flashes.
  20. Double-click the probe icon, you can back control.
  21. Support user rights management, administrators + operator into two categories, user login + user exits, you can remember the password and automatic login, more than three times error prompt and close the program.
  22. Supports four monitoring mode, the monitoring device panel monitor + Map + table + curve data monitoring data monitoring, are free to switch the four synchronization application.
  23. Support alarm relay linkage, a bit serial number can be linked across a plurality of modules and a relay number, support-many.
  24. Local data storage support sqlite + mysql, supports remote data synchronization to the cloud database. Automatic reconnection.
  25. Real-time local device collected data uploaded to the cloud, so that the phone APP or web and other ways to extract.
  26. Supports two data sources, one serial port and the data acquisition devices through a network protocol, one is the collection database. Acquisition mode database can be used as a general system.
  27. Carrying equipment simulation tools, devices 16 support analog data, but also with the database data simulation, when there is no data to test the device.
  28. Default communication protocol using modbus protocol, later adding support mqtt and other things of the agreement, made common system.
  29. Supports all windows operating system + linux operating system and other operating systems.

Third, renderings

Fourth, the core code

void frmTool::checkData(const QByteArray &data, bool isCom)
{
    int dataLen = data.length();
    if (dataLen <= 0) {
        return;
    }

    QByteArray body;
    QString type = ui->cboxDeviceType->currentText();
    if (type == "FC-1003-1") {
        for (int i = 0; i < 1; i++) {
            body.append(QUIHelper::ushortToByte(spinBox.at(i)->value()));
        }
    } else if (type == "FC-1003-8") {
        for (int i = 0; i < 8; i++) {
            body.append(QUIHelper::ushortToByte(spinBox.at(i)->value()));
        }
    } else if (type == "FC-1003-16") {
        for (int i = 0; i < 16; i++) {
            body.append(QUIHelper::ushortToByte(spinBox.at(i)->value()));
        }
    } else {
        for (int i = 0; i < 4; i++) {
            body.append(QUIHelper::ushortToByte(spinBox.at(i)->value()));
        }
    }

    //模拟回复数据 01 03 08 00 14 03 12 00 00 00 00 79 E6
    QByteArray buffer;
    buffer.append(ui->cboxDeviceAddr->currentText().toInt());
    buffer.append(0x03);
    buffer.append(body.length());
    buffer.append(body);
    buffer.append(QUIHelper::getCRCCode(buffer));

    if (isCom) {
        com->write(buffer);
        append(1, QUIHelper::byteArrayToHexStr(data));
        append(0, QUIHelper::byteArrayToHexStr(buffer));
    } else {
        tcpSocket->write(buffer);
        append(5, QUIHelper::byteArrayToHexStr(data));
        append(4, QUIHelper::byteArrayToHexStr(buffer));
    }
}

void frmTool::append(int type, const QString &data, bool clear)
{
    static int currentCount = 0;
    static int maxCount = 100;

    if (clear) {
        ui->txtMain->clear();
        currentCount = 0;
        return;
    }

    if (currentCount >= maxCount) {
        ui->txtMain->clear();
        currentCount = 0;
    }

    if (ui->btnShowData->text() == "继续显示") {
        return;
    }

    //过滤回车换行符
    QString strData = data;
    strData = strData.replace("\r", "");
    strData = strData.replace("\n", "");

    //不同类型不同颜色显示
    QString strType;
    if (type == 0) {
        strType = "串口发送 >>";
        ui->txtMain->setTextColor(QColor("dodgerblue"));
    } else if (type == 1) {
        strType = "串口接收 <<";
        ui->txtMain->setTextColor(QColor("red"));
    } else if (type == 2) {
        strType = "处理延时 >>";
        ui->txtMain->setTextColor(QColor("gray"));
    } else if (type == 3) {
        strType = "正在校验 >>";
        ui->txtMain->setTextColor(QColor("green"));
    } else if (type == 4) {
        strType = "网络发送 >>";
        ui->txtMain->setTextColor(QColor(24, 189, 155));
    } else if (type == 5) {
        strType = "网络接收 <<";
        ui->txtMain->setTextColor(QColor(255, 107, 107));
    } else if (type == 6) {
        strType = "提示信息 >>";
        ui->txtMain->setTextColor(QColor(100, 184, 255));
    }

    strData = QString("时间[%1] %2 %3").arg(TIMEMS).arg(strType).arg(strData);
    ui->txtMain->append(strData);
    currentCount++;
}

void frmTool::on_btnOpen_clicked()
{
    if (ui->btnOpen->text() == "打开串口") {
        com = new QextSerialPort(ui->cboxPortName->currentText(), QextSerialPort::Polling);
        isComOk = com->open(QIODevice::ReadWrite);
        if (isComOk) {
            com->setBaudRate((BaudRateType)ui->cboxBaudRate->currentText().toInt());
            com->setFlowControl(FLOW_OFF);
            com->setTimeout(10);

            ui->btnOpen->setText("关闭串口");
            timerRead->start();
        }
    } else {
        timerRead->stop();
        com->close();
        com->deleteLater();

        ui->btnOpen->setText("打开串口");
        on_btnClearData_clicked();
        isComOk = false;
    }
}

void frmTool::on_btnListen_clicked()
{
    if (ui->btnListen->text() == "监听服务") {
        int port = ui->txtListenPort->text().toInt();
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
        isTcpOk = tcpServer->listen(QHostAddress::AnyIPv4, port);
#else
        isTcpOk = tcpServer->listen(QHostAddress::Any, port);
#endif

        if (isTcpOk) {
            ui->btnListen->setText("停止服务");
        }
    } else {
        if (tcpSocket != 0) {
            tcpSocket->disconnectFromHost();
        }

        tcpServer->close();
        ui->btnListen->setText("监听服务");
        on_btnClearData_clicked();
        isTcpOk = false;
    }
}

void frmTool::on_btnClearData_clicked()
{
    append(0, "", true);
}

Guess you like

Origin www.cnblogs.com/feiyangqingyun/p/12001459.html