forked from liuning587/QGDW1376_2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d57e03
commit 7501136
Showing
17 changed files
with
678 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,7 @@ | |
/arm | ||
/X86_DLL | ||
/.settings | ||
/gw13762/*.user | ||
/build-gw13762-unknown-Release | ||
/GDW1376_2/.settings | ||
/GDW1376_2/X86_DLL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-----------------------------*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<RCC> | ||
<qresource prefix="/"/> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
{ | ||
//升级 | ||
} |
Oops, something went wrong.