Network and serial port debugging assistant

Contents Chapter
1 Introduction1
1.1 Project background1
1.2 Research status at home and abroad1
1.3 Main research content2
1.4 Paper organization structure2
Chapter 2 Software requirements analysis3
2.1 Feasibility analysis3
2.1.1 Economic feasibility3
2.1.2 Technical feasibility Performance 3
2.1.3 Operation feasibility 3
2.2 Requirements overview 3
2.3 Functional requirements analysis 6
2.3.1 Equipment module 6
2.3.2 Equipment information module 8
2.3.3 Sending data module 9
2.3.4 Data receiving module 12
2.3.5 System settings Module 13
2.3.5 Other functional modules 14
2.4 Non-functional requirements analysis 21
2.4.1 Performance requirements analysis 21
2.4.2 Reliability analysis 21
2.5 Summary of this chapter 21
Chapter 3 Software system design 21
3.1 Overall design 21
3.1.1 Basic framework design 21
3.1.2 Functional structure design 22
3.1.3 Introduction to key technologies 23
3.2 Detailed design 24
3.2.1 Equipment module 24
3.2.2 Equipment information module 26
3.2.3 Send data module 27
3.2.4 Data receiving module 30
3.2.5 System setting module 31
3.2.6 Other functional modules 32
3.3 Summary of this chapter 36
Chapter 4 Software implementation 36
4.1 Overall interface 37
4.1.1 Interface design 37
4.1.2 Software architecture design 37
4.2 Equipment Module 38
4.2.1 Design of MyObject class 38
4.2.2 Device creation 40
4.2.3 Device deletion 42
4.3 Device information module 44
4.4 Sending data module 46
4.4.1 Single sending 46
4.4.2 Scheduled sending 47
4.4.3 Set sending Mode 48
4.5 Data receiving module 49
4.6 System setting module 49
4.7 Other functional modules 50
4.7.1 Clear the data receiving box 51
4.7.2 Clear the data sending box 51
4.7.3 Load file 51
4.7.4 Export data 52
4.7.5 Display words Number of sections and reset count 52
4.7.6 Detailed explanation of functions 53
4.8 Summary of this chapter 54
Chapter 5 Software testing 54
5.1 Testing principles 54
5.2 Test environment 55
5.3 Equipment module testing 55
5.3.1 Create device 55
5.3.2 Delete device 56
5.4 Device information module test 56
5.5 Send data module test 57
5.5.1 Single send function test 57
5.6.2 Scheduled send function test 58
5.6.3 Set send mode function test 58
5.6 Data receiving module test 60
5.7 System setting module 60
5.8 Other functional module tests 61
5.8.1 Clear data receiving box function test 61
5.8.2 Clear data sending box function test 62
5.8.3 Load file function test 63
5.8.4 Export data Functional test 63
5.8.5 Display byte number function test 64
5.8.6 Count clear function test 64
5.8.7 Display device number function test 65
Chapter 6 Summary and Outlook 66
6.1 Summary 66
6.2 Outlook 66
References 67
Acknowledgments 68
2.3 Functional requirements analysis
Requirements analysis is a very important process in the software life cycle. It determines the quality of the entire software project and is also the success or failure of the entire software project. It is required that all functions of the software can be used normally and the interface is beautiful.
2.3.1 Equipment module
The device module of the debugging assistant mainly allows users to create and delete devices. For creating devices, users can choose to create TCP type clients and servers or UDP type clients and servers. Serial device is automatically detected and created. For deleting a device, the created device is deleted. The activity diagram for creating the device is shown in Figure 2-2.
Insert image description here

#include "common.h"
#include <QDebug>
common::common(QWidget *parent) : QTextEdit(parent)
{
    
    
    connect(this,&QTextEdit::cursorPositionChanged,this,&common::changePosSLOT);
}

QString common::getCurrTime()
{
    
    
    return QTime::currentTime().toString();
}

QByteArray common::hexStrToByteArray(const QString &str)
{
    
    
    /*qDebug()<<"hexStrToByteArray::str="<<str;
    QByteArray senddata;
    int hexdata, lowhexdata;
    int hexdatalen = 0;
    int len = str.length();
    senddata.resize(len / 2);
    char lstr, hstr;

    for (int i = 0; i < len;) {
        hstr = str.at(i).toLatin1();

        if (hstr == ' ') {
            i++;
            continue;
        }
        i++;
        if (i >= len) {
            break;
        }

        lstr = str.at(i).toLatin1();
        hexdata = convertHexChar(hstr);
        lowhexdata = convertHexChar(lstr);
        qDebug()<<"hexStrToByteArray::hexdata="<<str;
        qDebug()<<"hexStrToByteArray::lowhexdata="<<str;
        if ((hexdata == 16) || (lowhexdata == 16)) {
            break;
        } else {
            hexdata = hexdata * 16 + lowhexdata;
        }

        i++;
        qDebug()<<"hexStrToByteArray::data="<<(char)hexdata;
        senddata[hexdatalen] = (char)hexdata;
        hexdatalen++;
    }

    senddata.resize(hexdatalen);
    */
        bool ok;
        QByteArray ret;
        QString str1;
        QStringList sl;
        QString str2;
        qDebug()<<"str.length="<<str.length();
        for(int i=1;i<=str.length();i++)
        {
    
    
            qDebug()<<"i="<<i;
            str2.append(str.at(i-1));
            qDebug()<<"str2="<<str2;
            if(i%2==0)//每两个字符放一起
            {
    
    
                sl.append(str2);
                str2.clear();
            }
        }

        foreach (QString s, sl) {
    
    
            if(!s.isEmpty())
            {
    
    
                //byte类型的数字要&0xff再赋值给int类型,其本质原因就是想保持二进制补码的一致性。
                char c = s.toInt(&ok,16)&0xFF;//任何一个数&0xFF都是它本身,这里为了保持补码的一致性(由byte(8位)-》int(32位))
                char d= 10;
                qDebug()<<"d="<<d;
                if(ok){
    
    
                    ret.append(c);
                }else{
    
    
                    qDebug()<<"非法的16进制字符:"<<s;
                }
            }
        }
    return ret;
}

/*char common::convertHexChar(char ch)
{
    if ((ch >= '0') && (ch <= '9')) {
        return ch - 0x30;
    } else if ((ch >= 'A') && (ch <= 'F')) {
        return ch - 'A' + 10;
    }else {
        return (-1);
    }
}*/

//只能输入16进制数和回退符
void common::keyPressEvent(QKeyEvent *event)
{
    
    
    if(event->key()==Qt::Key_0||event->key()==Qt::Key_1||event->key()==Qt::Key_2||event->key()==Qt::Key_3||event->key()==Qt::Key_4||event->key()==Qt::Key_5||event->key()==Qt::Key_6||event->key()==Qt::Key_7||event->key()==Qt::Key_8||event->key()==Qt::Key_9||event->key()==Qt::Key_A||event->key()==Qt::Key_B||event->key()==Qt::Key_C||event->key()==Qt::Key_D||event->key()==Qt::Key_E||event->key()==Qt::Key_F)
    {
    
    
        QString str=this->toPlainText();//保存已经有的
        str.append(event->text().toUpper());//添加新传来的
        this->clear();
        this->append(str);
    }
    else if(event->key()==Qt::Key_Backspace) {
    
    
        QString str=this->toPlainText();
        QString str1=str.remove(str.length()-1,1);
        this->clear();
        this->append(str1);
    }
}

//限制中文输入
void common::changePosSLOT()
{
    
    
    QString str=this->toPlainText();
    if(str=="")
        return;
    QString ch=str.at(str.length()-1);
    QChar ch1=str.at(str.length()-1);
    char ch2=ch1.toLatin1();
    qDebug()<<"str="<<str<<"  ch="<<ch;
    if((ch2>='A')&&(ch2<='F'))
    {
    
    
        //ch正常AF";
    }
    else if ((ch2>='0')&&(ch2<='9')) {
    
    
        //正常09";
    }
    else {
    
    
        //ch错误";
        if(!isFile)
        {
    
    
            str.remove(str.length()-1,1);
            this->clear();
            this->append(str);
        }
    }
}

Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/newlw/article/details/133064664