Skip to content

Commit

Permalink
add qt demo
Browse files Browse the repository at this point in the history
  • Loading branch information
liuning587 committed Dec 2, 2019
1 parent 8d57e03 commit 7501136
Show file tree
Hide file tree
Showing 17 changed files with 678 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
/arm
/X86_DLL
/.settings
/gw13762/*.user
/build-gw13762-unknown-Release
/GDW1376_2/.settings
/GDW1376_2/X86_DLL
4 changes: 2 additions & 2 deletions GDW1376_2/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.mingw.exe.debug.option.optimization.level.1065527565" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.c.optimization.level.size" valueType="enumerated"/>
<option id="gnu.c.compiler.mingw.exe.debug.option.debugging.level.2146786113" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<option id="gnu.c.compiler.option.dialect.std.756262085" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.default" valueType="enumerated"/>
<option id="gnu.c.compiler.option.warnings.extrawarn.1319491683" name="Extra warnings (-Wextra)" superClass="gnu.c.compiler.option.warnings.extrawarn" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="gnu.c.compiler.option.warnings.toerrors.1958510430" name="Warnings as errors (-Werror)" superClass="gnu.c.compiler.option.warnings.toerrors" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="gnu.c.compiler.option.warnings.extrawarn.1319491683" name="Extra warnings (-Wextra)" superClass="gnu.c.compiler.option.warnings.extrawarn" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="gnu.c.compiler.option.warnings.toerrors.1958510430" name="Warnings as errors (-Werror)" superClass="gnu.c.compiler.option.warnings.toerrors" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1116566454" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug.539569013" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug">
Expand Down
2 changes: 1 addition & 1 deletion GDW1376_2/src/AFN15.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ AFN15_FN01(unsigned char dir,
pcb(pline_end);
if (dir == 0) //下行
{
if (len < sizeof(file_tran_req_t))
if (len < (int)sizeof(file_tran_req_t))
{
sprintf(buf, "%s输入报文长度不足解析失败!%s", pline_head, pline_end);
pcb(buf);
Expand Down
68 changes: 68 additions & 0 deletions gw13762/GDW1376_2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
******************************************************************************
* @file GDW1376_2.h
* @brief API include file of GDW1376_2.h.
* @details This file including all API functions's declare of GDW1376_2.h.
* @copyright
******************************************************************************
*/
#ifndef GDW1376_2_H_
#define GDW1376_2_H_

#ifdef __cplusplus
extern "C"
{
#endif

/*-----------------------------------------------------------------------------
Section: Includes
----------------------------------------------------------------------------*/
/* NONE */

/*-----------------------------------------------------------------------------
Section: Macro Definitions
----------------------------------------------------------------------------*/
#define ERR_NONE (0) /**< 无错误 */
#define ERR_INPUT (1) /**< 输入参数错误 */
#define ERR_CHKFRM_0x68 (2) /**< 报文头0x68 */
#define ERR_CHKFRM_LEN (3) /**< 输入报文长度无效 */
#define ERR_CHKFRM_0x16 (4) /**< 报文尾0x16 */
#define ERR_CHKFRM_cs (5) /**< 报文cs错误 */
#define ERR_AFN_FN (6) /**< 不支持的FN*/
#define ERR_APP_LEN (7) /**< 应用数据LEN有误 */

/*-----------------------------------------------------------------------------
Section: Type Definitions
----------------------------------------------------------------------------*/
typedef void (*pcallback)(const char*);

/*-----------------------------------------------------------------------------
Section: Globals
----------------------------------------------------------------------------*/
/* NONE */

/*-----------------------------------------------------------------------------
Section: Function Prototypes
----------------------------------------------------------------------------*/
extern int
GDW1376_2_parse(const unsigned char *pin,
unsigned int len,
pcallback pcb,
const char *pline_head,
const char *pline_end);

extern const char *
GDW1376_2_error(int errid);

extern const char *
GDW1376_2_ver_str(void);

extern const char *
GDW1376_2_changelog(void);

#ifdef __cplusplus
}
#endif

#endif /* GDW1376_2_H_ */
/*--------------------------End of GDW1376_2.h-----------------------------*/
3 changes: 3 additions & 0 deletions gw13762/db.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<RCC>
<qresource prefix="/"/>
</RCC>
31 changes: 31 additions & 0 deletions gw13762/gw13762.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#-------------------------------------------------
#
# Project created by QtCreator 2013-09-08T11:06:45
#
#-------------------------------------------------

QT += core gui sql

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = gw13762
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h \
GDW1376_2.h

FORMS += mainwindow.ui

RC_FILE += myico.rc

LIBS += ../build/GDW1376_2.dll

OTHER_FILES += \
myico.rc

RESOURCES += \
zk.qrc
Binary file added gw13762/img/Penguin.ico
Binary file not shown.
Binary file added gw13762/img/nwbmp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gw13762/img/nwico.ico
Binary file not shown.
23 changes: 23 additions & 0 deletions gw13762/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <QApplication>
#include <QTextCodec>
#include <QTranslator>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// 设置编码
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("gbk"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf8"));
MainWindow w;


//加载中文字符
QTranslator translator;
translator.load(":/qt_zh_CN.qm");
a.installTranslator(&translator);

w.show();
return a.exec();
}
202 changes: 202 additions & 0 deletions gw13762/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#include <stdlib.h>
#include <string.h>
#include <QtDebug>
#include <qmessagebox.h>
#include <QKeyEvent>
#include <QTextCodec>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "GDW1376_2.h"

QTextBrowser *ptextBrowser = NULL;
static char the_text[1024*512]; //512k
static int the_pos = 0;

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle(tr("国网1376.2规约报文解析(%1)").arg(QString::fromLocal8Bit(GDW1376_2_ver_str())));
ui->textBrowser->clear();
ui->textBrowser->setText(QString::fromLocal8Bit(GDW1376_2_changelog()));
ptextBrowser = ui->textBrowser;
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::keyPressEvent(QKeyEvent *e)
{
switch (e->key())
{
case Qt::Key_F1:
on_action_F1_triggered();
break;
case Qt::Key_F2:
on_action_F2_triggered();
break;
case Qt::Key_F3:
on_action_C_triggered();
break;
case Qt::Key_F4:
on_action_S_triggered();
break;
default:
break;
}
}


void printCallBack(const char *pstr)
{
int len;

if (ptextBrowser)
{
len = strlen(pstr);
if ((unsigned)(the_pos + len) < sizeof(the_text))
{
memcpy(the_text + the_pos, pstr, len);
the_pos += len;
}
}
}

void MainWindow::deBlank(QString &strs)
{
int len = strs.length();
int newlen = 0;

for (int i = 0; i < len; i++)
{
if (!strs.at(i).isSpace())
{
strs[newlen++] = strs[i];
}
}
strs.truncate(newlen);
}

void MainWindow::on_action_Q_triggered()
{
this->close();
}

void MainWindow::on_action_F1_triggered()
{
qDebug("打开报文");
}

void MainWindow::on_action_F2_triggered()
{
//解析报文
bool ok;
int inLen;
QString inData = ui->textEdit->toPlainText();

deBlank(inData); //去除空格
inLen = inData.length();

if (inLen & 0x01)
{
QMessageBox::warning(this, "提示", tr("输入数据非偶数个!"));
return;
}

inLen /= 2;
if (inLen <= 0)
{
return;
}

if (inLen > MAX_FRAME_LEN)
{
QMessageBox::warning(this, "提示", tr("输入数据不能大于%1字节!").arg(MAX_FRAME_LEN));
return;
}

ok = true;
for (int i = 0; i < inLen; i++)
{
inpbuf[i] = inData.left(2).toUInt(&ok, 16);
if (ok != true)
{
break;
}
inData.remove(0, 2);
}
if (ok != true)
{
QMessageBox::warning(this, "提示", "输入数据含有非十六进制,请仔细检查!");
return;
}

ui->textBrowser->clear();

the_pos = 0;
memset(the_text, 0x00, sizeof(the_text));

QString my3762;
for (int i = 0; i < inLen; i++)
{
if (inpbuf[i] < 0x10)
my3762 += QString(tr("0"));
my3762 += QString::number(inpbuf[i], 16).toUpper() + QString(tr(" "));
}
my3762.truncate(my3762.length() - 1);
ui->textEdit->setText(my3762);

int err = GDW1376_2_parse((const unsigned char *)inpbuf, inLen,
printCallBack, "", "\n");

ptextBrowser->append(QString::fromLocal8Bit(the_text));
if (err)
{
QMessageBox::warning(this, "提示", QString::fromLocal8Bit(GDW1376_2_error(err)));
}
}

void MainWindow::on_action_C_triggered()
{
//清屏
if (ui->textBrowser->toPlainText().size() > 0)
{
ui->textBrowser->clear();
}
else
{
ui->textEdit->clear();
}
}

void MainWindow::on_action_2013_triggered()
{
//选择规约
}

void MainWindow::on_action_S_triggered()
{
//保存结果
}

void MainWindow::on_action_triggered()
{
//版本说明
ui->textBrowser->clear();
ui->textBrowser->setText(QString::fromLocal8Bit(GDW1376_2_changelog()));
}

void MainWindow::on_action_H_triggered()
{
//帮助
ui->textBrowser->clear();
ui->textBrowser->setText(tr("F2:解析\nF3:清除"));
}

void MainWindow::on_action_D_triggered()
{
//升级
}
Loading

0 comments on commit 7501136

Please sign in to comment.