title: GxDlms编译

date: 2019/12/5 13:36:37

toc: true

GxDlms编译

  1. C++版本如果要编译动态库,项目>属性需要在GXDLMSIp4Setup.h加入

    #pragma comment(lib, "ws2_32.lib")//这是链接API相关连的Ws2_32.lib静态库

  2. 刚开始QT使用静态库的时候,提示一堆找不到,要注意默认qt这里使用的是x64,然后我们将vs编译的改成x64,再加入静态库就好了

  3. qt加入库

  4. qt编译的时候如果提示少inet..,加入步骤1中的头文件

  5. 打包 windeployqt 工具命令:windeployqt hello.exe

  6. 一个小demo测试

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "./development/include/GXDLMSSecureClient.h"
    #include <iostream>
    using namespace std;
    #include <QApplication>
    #pragma comment(lib, "ws2_32.lib")
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    } MainWindow::~MainWindow()
    {
    delete ui;
    } void MainWindow::on_pushButton_clicked()
    { CGXCipher cipher("4D4D4D0000BC614E"); CGXByteBuffer SYS_TITLE;
    SYS_TITLE.SetHexString("4D4D4D0000BC614E");
    cipher.SetSystemTitle(SYS_TITLE); cipher.SetSecurity(DLMS_SECURITY_AUTHENTICATION_ENCRYPTION);
    CGXByteBuffer EK;
    EK.SetHexString("11111111111111111111111111111111");
    cipher.SetBlockCipherKey(EK);
    CGXByteBuffer AK;
    AK.SetHexString("33333333333333333333333333333333");
    cipher.SetAuthenticationKey(AK); cipher.SetFrameCounter(0); CGXByteBuffer plainText;
    plainText.SetHexString("01000000065f1f040000181dffff"); CGXByteBuffer cryptedText; int cmd = 0x21;//DLMS_COMMAND_GENERAL_GLO_CIPHERING;
    cryptedText.Clear();
    cipher.Encrypt(cipher.GetSecurity(),
    DLMS_COUNT_TYPE_TAG,
    cipher.GetFrameCounter(),
    cmd,
    cipher.GetSystemTitle(),
    cipher.GetBlockCipherKey(),
    plainText,
    cryptedText);
    std::cout << "DLMS_COUNT_TYPE_TAG" << std::endl;
    std::cout << cryptedText.ToHexString() << std::endl; cryptedText.Clear();
    cipher.Encrypt(cipher.GetSecurity(),
    DLMS_COUNT_TYPE_DATA,
    cipher.GetFrameCounter(),
    cmd,
    cipher.GetSystemTitle(),
    cipher.GetBlockCipherKey(),
    plainText,
    cryptedText);
    cout << "DLMS_COUNT_TYPE_DATA" << endl;
    cout << cryptedText.ToHexString() << endl; cryptedText.Clear();
    cipher.Encrypt(cipher.GetSecurity(),
    DLMS_COUNT_TYPE_PACKET,
    cipher.GetFrameCounter(),
    cmd,
    cipher.GetSystemTitle(),
    cipher.GetBlockCipherKey(),
    plainText,
    cryptedText);
    cout << "DLMS_COUNT_TYPE_PACKET" << endl;
    cout << cryptedText.ToHexString() << endl; ui->textEdit->setText(QString::fromStdString(cryptedText.ToHexString()));
    }
    1. qt程序
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "./development/include/GXDLMSSecureClient.h"
    #include <iostream>
    using namespace std;
    #include <QApplication>
    #include <QDebug>
    #include <QDataStream> #include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm> // 大写转换
    #include <regex>
    #pragma comment(lib, "ws2_32.lib")
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    } MainWindow::~MainWindow()
    {
    delete ui;
    } class string_help
    {
    public:
    string_help(); static bool IsHexNum(char c);
    static void deleteAllMark(string &s, const string &mark); // 假定完美 hex形式的字符串形如 010203040506...FF 全是大写的并且
    // 中间无任何分隔符
    const static string demo_srting;
    // 替换一次
    static string replace_all(string& str, const string& old_value, const string& new_value);
    // 迭代替换
    static string replace_all_distinct(string& str, const string& old_value, const string& new_value); // hex数组转换为string
    static string HexArrayToString(const vector<unsigned char >& data);
    //转换一个string到完美string
    static string HexStringFormat(const std::string& data=demo_srting);
    // string转换为一个数组
    static vector<unsigned char> StringToHexArray(const std::string& data=demo_srting);
    }; const string string_help::demo_srting="500010203040506073031323334ff"; string string_help:: replace_all_distinct(string& str, const string& old_value, const string& new_value)
    {
    string::size_type pos=0;
    while((pos=str.find(old_value,pos))!= string::npos)
    {
    str=str.replace(pos,old_value.length(),new_value);
    if(new_value.length()>0)
    {
    pos+=new_value.length();
    }
    }
    return str; } //替换2 循环替换,替换后的值也检查并替换 12212 替换12为21----->22211
    string string_help::replace_all(string& str, const string& old_value, const string& new_value)
    {
    string::size_type pos=0;
    while((pos=str.find(old_value))!= string::npos)
    {
    str=str.replace(str.find(old_value),old_value.length(),new_value);
    }
    return str;
    } void string_help:: deleteAllMark(string &s, const string &mark)
    {
    size_t nSize = mark.size();
    while(1)
    {
    size_t pos = s.find(mark); // 尤其是这里
    if(pos == string::npos)
    {
    return;
    } s.erase(pos, nSize);
    }
    } bool string_help::IsHexNum(char c)
    {
    if(c>='0' && c<='9') return true;
    if(c>='a' && c<='f') return true;
    if(c>='A' && c<='F') return true;
    return false; } string string_help::HexStringFormat(const std::string& data)
    {
    vector<unsigned char >hex_array;
    //1. 转换为大写
    string format_string=data;
    transform(data.begin(),data.end(),format_string.begin(),::toupper); //2. 去除0X
    replace_all_distinct(format_string,"0X"," ");
    replace(format_string.begin(),format_string.end(),',',' ');
    replace(format_string.begin(),format_string.end(),',',' '); regex e("\\s+");
    regex_token_iterator<string::iterator> i(format_string.begin(), format_string.end(), e, -1);
    regex_token_iterator<string::iterator> end;
    while (i != end)
    {
    //字串处理
    string tmp_get=*i;
    for(size_t i = 0; i < tmp_get.length(); )
    {
    if(IsHexNum(tmp_get[i]))
    {
    if(i+1<tmp_get.length() && IsHexNum(tmp_get[i+1]) )
    {
    string one=tmp_get.substr(i,2);
    unsigned char value = static_cast<unsigned char>(std::stoi(one,0,16));
    hex_array.push_back(value);
    i++;
    }
    else
    {
    string one=tmp_get.substr(i,1);
    unsigned char value = static_cast<unsigned char>(std::stoi(one,0,16));
    hex_array.push_back(value);
    }
    //break;
    }
    i++;
    }
    i++;
    }
    return HexArrayToString(hex_array);
    } vector<unsigned char> string_help::StringToHexArray(const std::string& src)
    {
    vector<unsigned char> ret;
    if(src.size()<1)
    {
    ret.push_back(0x00);
    return ret;
    }
    for (string::size_type i = 0; i < src.size()-1; i+=2)
    {
    string one=src.substr(i,2);
    unsigned char value = static_cast<unsigned char>(std::stoi(one,0,16));
    ret.push_back(value);
    }
    return ret;
    } string string_help::HexArrayToString(const vector<unsigned char >& data)
    {
    const string hexme = "0123456789ABCDEF";
    string ret="";
    for(auto it:data)
    {
    ret.push_back(hexme[(it&0xF0) >>4]);
    ret.push_back(hexme[it&0x0F]);
    }
    return ret;
    } string format(QTextEdit * me,QString default_txt )
    {
    QString tmp=me->toPlainText(); if(tmp.size()<1)
    tmp=default_txt; string good_string=string_help::HexStringFormat(tmp.toStdString());
    QString good_qstring = QString::fromStdString(good_string);
    me->setText(good_qstring);
    return good_string;
    } void MainWindow::on_pushButton_clicked()
    { //ui->sysText->setText(QString::fromStdString("123")); string s_systitle =format(ui->sysText,"4D4D4D0000BC614E");
    string s_Ak =format(ui->AkText,"33333333333333333333333333333333");
    string s_Ek =format(ui->EkText,"11111111111111111111111111111111");
    string s_Ic =format(ui->IcEdit_8,"00");
    string s_text =format(ui->plainText,"01000000065f1f040000181dffff");
    string cmdme =format(ui->cmdme,"21"); CGXCipher cipher(s_systitle.c_str());
    CGXByteBuffer SYS_TITLE;
    SYS_TITLE.SetHexString(s_systitle.c_str());
    CGXByteBuffer EK;
    EK.SetHexString(s_Ek.c_str());
    CGXByteBuffer AK;
    AK.SetHexString(s_Ak.c_str());
    CGXByteBuffer plainText;
    plainText.SetHexString(s_text.c_str()); // SYS_TITLE.Clear();
    // EK.Clear();
    // AK.Clear();
    // plainText.Clear();
    // SYS_TITLE.SetHexString("4D4D4D0000BC614E");
    // EK.SetHexString("11111111111111111111111111111111");
    // AK.SetHexString("33333333333333333333333333333333");
    // plainText.SetHexString("01000000065f1f040000181dffff"); int value_IC = QString::fromStdString(s_Ic).toInt(NULL, 16);
    int value_cmd = QString::fromStdString(cmdme).toInt(NULL, 16); cipher.SetBlockCipherKey(EK);
    cipher.SetAuthenticationKey(AK);
    //cipher.SetFrameCounter(std::stol(s_Ic));
    cipher.SetSystemTitle(SYS_TITLE);
    cipher.SetFrameCounter(value_IC); std::cout << plainText.ToHexString() << std::endl;
    cout << cipher.GetFrameCounter() <<endl;
    std::cout << cipher.GetSystemTitle().ToHexString() << std::endl;
    std::cout << cipher.GetBlockCipherKey().ToHexString() << std::endl;
    std::cout << cipher.GetAuthenticationKey().ToHexString() << std::endl; CGXByteBuffer cryptedText; int cmd=value_cmd;
    cipher.SetSecurity(DLMS_SECURITY_AUTHENTICATION_ENCRYPTION);
    cryptedText.Clear();
    cipher.Encrypt(cipher.GetSecurity(),
    DLMS_COUNT_TYPE_PACKET,
    cipher.GetFrameCounter(),
    cmd,
    cipher.GetSystemTitle(),
    cipher.GetBlockCipherKey(),
    plainText,
    cryptedText);
    std::cout << "DLMS_COUNT_TYPE_TAG" << std::endl;
    std::cout << cryptedText.ToHexString() << std::endl; ui->enTextAll->setText(QString::fromStdString(cryptedText.ToHexString())); cryptedText.Clear();
    cipher.SetSecurity(DLMS_SECURITY_ENCRYPTION);
    cipher.Encrypt(cipher.GetSecurity(),
    DLMS_COUNT_TYPE_DATA,
    cipher.GetFrameCounter(),
    cmd,
    cipher.GetSystemTitle(),
    cipher.GetBlockCipherKey(),
    plainText,
    cryptedText);
    cout << "DLMS_COUNT_TYPE_DATA" << endl;
    cout << cryptedText.ToHexString() << endl; ui->enTextData->setText(QString::fromStdString(cryptedText.ToHexString())); }
    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>1080</width>
    <height>605</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>MainWindow</string>
    </property>
    <widget class="QWidget" name="centralwidget">
    <widget class="QTextEdit" name="plainText">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>40</y>
    <width>631</width>
    <height>91</height>
    </rect>
    </property>
    </widget>
    <widget class="QPushButton" name="pushButton">
    <property name="geometry">
    <rect>
    <x>690</x>
    <y>370</y>
    <width>75</width>
    <height>23</height>
    </rect>
    </property>
    <property name="text">
    <string>加密</string>
    </property>
    </widget>
    <widget class="QLabel" name="label">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>20</y>
    <width>54</width>
    <height>12</height>
    </rect>
    </property>
    <property name="text">
    <string>原文</string>
    </property>
    </widget>
    <widget class="QLabel" name="label_2">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>140</y>
    <width>121</width>
    <height>16</height>
    </rect>
    </property>
    <property name="text">
    <string>密文(包含tag)</string>
    </property>
    </widget>
    <widget class="QTextEdit" name="enTextAll">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>160</y>
    <width>631</width>
    <height>91</height>
    </rect>
    </property>
    </widget>
    <widget class="QTextEdit" name="enTextData">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>280</y>
    <width>631</width>
    <height>91</height>
    </rect>
    </property>
    </widget>
    <widget class="QLabel" name="label_3">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>260</y>
    <width>121</width>
    <height>16</height>
    </rect>
    </property>
    <property name="text">
    <string>密文 数据域</string>
    </property>
    </widget>
    <widget class="QTextEdit" name="enTextDataTag">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>410</y>
    <width>631</width>
    <height>91</height>
    </rect>
    </property>
    </widget>
    <widget class="QLabel" name="label_5">
    <property name="geometry">
    <rect>
    <x>670</x>
    <y>10</y>
    <width>71</width>
    <height>16</height>
    </rect>
    </property>
    <property name="text">
    <string>sys-title</string>
    </property>
    </widget>
    <widget class="QTextEdit" name="sysText">
    <property name="geometry">
    <rect>
    <x>670</x>
    <y>40</y>
    <width>371</width>
    <height>31</height>
    </rect>
    </property>
    </widget>
    <widget class="QLabel" name="label_6">
    <property name="geometry">
    <rect>
    <x>690</x>
    <y>80</y>
    <width>71</width>
    <height>16</height>
    </rect>
    </property>
    <property name="text">
    <string>Ak</string>
    </property>
    </widget>
    <widget class="QTextEdit" name="AkText">
    <property name="geometry">
    <rect>
    <x>670</x>
    <y>100</y>
    <width>371</width>
    <height>31</height>
    </rect>
    </property>
    </widget>
    <widget class="QLabel" name="label_7">
    <property name="geometry">
    <rect>
    <x>690</x>
    <y>140</y>
    <width>71</width>
    <height>16</height>
    </rect>
    </property>
    <property name="text">
    <string>Ek</string>
    </property>
    </widget>
    <widget class="QTextEdit" name="EkText">
    <property name="geometry">
    <rect>
    <x>670</x>
    <y>160</y>
    <width>371</width>
    <height>31</height>
    </rect>
    </property>
    </widget>
    <widget class="QLabel" name="label_8">
    <property name="geometry">
    <rect>
    <x>680</x>
    <y>210</y>
    <width>71</width>
    <height>16</height>
    </rect>
    </property>
    <property name="text">
    <string>IC 帧序号</string>
    </property>
    </widget>
    <widget class="QTextEdit" name="IcEdit_8">
    <property name="geometry">
    <rect>
    <x>670</x>
    <y>230</y>
    <width>371</width>
    <height>31</height>
    </rect>
    </property>
    </widget>
    <widget class="QLabel" name="label_9">
    <property name="geometry">
    <rect>
    <x>670</x>
    <y>270</y>
    <width>71</width>
    <height>16</height>
    </rect>
    </property>
    <property name="text">
    <string>cmd</string>
    </property>
    </widget>
    <widget class="QTextEdit" name="cmdme">
    <property name="geometry">
    <rect>
    <x>670</x>
    <y>290</y>
    <width>371</width>
    <height>31</height>
    </rect>
    </property>
    </widget>
    <widget class="QPushButton" name="pushButton_2">
    <property name="geometry">
    <rect>
    <x>790</x>
    <y>370</y>
    <width>151</width>
    <height>23</height>
    </rect>
    </property>
    <property name="text">
    <string>解密包含tag</string>
    </property>
    </widget>
    <widget class="QPushButton" name="pushButton_3">
    <property name="geometry">
    <rect>
    <x>790</x>
    <y>410</y>
    <width>151</width>
    <height>23</height>
    </rect>
    </property>
    <property name="text">
    <string>解密单纯数据,需要填写IC</string>
    </property>
    </widget>
    </widget>
    <widget class="QMenuBar" name="menubar">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>1080</width>
    <height>23</height>
    </rect>
    </property>
    </widget>
    <widget class="QStatusBar" name="statusbar"/>
    </widget>
    <resources/>
    <connections/>
    </ui>

GxDlms编译的更多相关文章

  1. TODO:macOS编译PHP7.1

    TODO:macOS编译PHP7.1 本文主要介绍在macOS上编译PHP7.1,有兴趣的朋友可以去尝试一下. 1.下载PHP7.1源码,建议到PHP官网下载纯净到源码包php-7.1.0.tar.g ...

  2. Centos6.5下编译安装mysql 5.6

    一:卸载旧版本 使用下面的命令检查是否安装有MySQL Server rpm -qa | grep mysql 有的话通过下面的命令来卸载掉 rpm -e mysql //普通删除模式 rpm -e ...

  3. CENTOS 6.5 平台离线编译安装 PHP5.6.6

    一.下载php源码包 http://cn2.php.net/get/php-5.6.6.tar.gz/from/this/mirror 二.编译 编译之前可能会缺少一些必要的依赖包,加载一个本地yum ...

  4. CENTOS 6.5 平台离线编译安装 Mysql5.6.22

    一.下载源码包 http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.22.tar.gz 二.准备工作 卸载之前本机自带的MYSQL 安装 cmake,编 ...

  5. Android注解使用之注解编译android-apt如何切换到annotationProcessor

    前言: 自从EventBus 3.x发布之后其通过注解预编译的方式解决了之前通过反射机制所引起的性能效率问题,其中注解预编译所采用的的就是android-apt的方式,不过最近Apt工具的作者宣布了不 ...

  6. Hawk 6. 编译和扩展开发

    Hawk是开源项目,因此任何人都可以为其贡献代码.作者也非常欢迎使用者能够扩展出更有用的插件. 编译 编译需要Visual Stuido,版本建议使用2015, 2010及以上没有经过测试,但应该可以 ...

  7. android studio 使用 jni 编译 opencv 完整实例 之 图像边缘检测!从此在andrid中自由使用 图像匹配、识别、检测

    目录: 1,过程感慨: 2,运行环境: 3,准备工作: 4,编译 .so 5,遇到的关键问题及其解决方法 6,实现效果截图. (原创:转载声明出处:http://www.cnblogs.com/lin ...

  8. 在Windows上编译和调试CoreCLR

    生成CoreCLR - Windows篇 本文的唯一目的就是让你运行Hello World 运行环境 Window 7+ Visual studio 2015 确保C++ 工具已经被安装,默认是不安装 ...

  9. 【踩坑速记】二次依赖?android studio编译运行各种踩坑解决方案,杜绝弯路,总有你想要的~

    这篇博客,只是把自己在开发中经常遇到的打包编译问题以及解决方案给大家稍微分享一下,不求吸睛,但求有用. 1.大家都知道我们常常会遇到dex超出方法数的问题,所以很多人都会采用android.suppo ...

随机推荐

  1. ES6-21.class基本语法

    1.简介(详情参考) class是构造函数的语法糖. class的constructor方法内的实现,就是原来构造函数的实现. class内的所有方法都是在prototype上的,就是原来构造函数的p ...

  2. 使用zabbix-proxy

    事情背景: vt上两个vps,只提供ipv6.(因为便宜嘛).而我的zabbix服务器在腾讯云.它丫的没有ipv6. 那么我没法监控它们了呀... 这咋个行呢? 想办法... 我还有另外的vps 可以 ...

  3. [2]windows内核情景分析--系统调用

    Windows的地址空间分用户模式与内核模式,低2GB的部分叫用户模式,高2G的部分叫内核模式,位于用户空间的代码不能访问内核空间,位于内核空间的代码却可以访问用户空间 一个线程的运行状态分内核态与用 ...

  4. maven-jetty插件配置时,webdefault.xml的取得和修改

    取得 没必要去下载一个jetty客户端去找webdefault.xml了. 可以去maven的本地仓库找到 \org\eclipse\jetty\jetty-webapp\版本号\ 里面的jar文件, ...

  5. Android studio 导入项目报 Error:Cause: peer not authenticated 异常

    修改build.gradle文件(project级的) 一.dependencies { classpath 'com.android.tools.build:gradle:1.0.1'}将class ...

  6. ie8 ajax 跨域问题

    最近做了个客服端要通过ocx获得初始化数据就是一个html页面镶嵌在一个c++做的程序里面通过c++做的程序的一个按钮来打开我的这个html页面但是页面中的ajax就是用不了又不报错 后来加入了cro ...

  7. C语言指针方法对字符串进行去重

    自己编写了3种方法,都是使用指针的.(在LR中编写的) 1.先在原字符串进行比较,然后再放入目标字符串 Action() { char *srt="aadfeedeewwffggecccew ...

  8. Redis使用Docker镜像安装

    详细见本人以下文档: https://www.cnblogs.com/zyc-blogs/p/9621727.html

  9. JMeter压力测试及并发量计算-1

    一.JMeter的安装(Linux) 1. 下载JMeter:这个就不细说了,直接去(http://jmeter.apache.org/download_jmeter.cgi)下载. 2. 解压:ta ...

  10. arcpy 获得是否为布局mxd.activeView

    arcpy 获得是否为布局mxd.activeView print mxd.activeView PAGE_LAYOUT mxd.pageSizePageSize(width=21.590043180 ...