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. 通过德鲁伊druid给系统增加监控

    系统在线上运行了一段时间后,比如一年半载的,我们发现系统可能存在某些问题,比如执行系统变慢了,比如某些spring的bean无法监控各种调用情况. 触发到db的各种执行情况,这个时候,我们就需要一个工 ...

  2. keepalived+lvs+nginx高可用

    环境说明: IP地址 部署应用 192.168.10.100 VIP0 192.168.10.101 VIP1 192.168.10.17 keepalived+lvs 192.168.10.16 k ...

  3. Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}

    C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle ...

  4. 012_STM32程序移植之_内部flash开机次数管理lib库建立

    012_STM32程序移植之_内部flash开机次数管理lib库建立 1. 测试环境:STM32C8T6 2. 测试接口: 3. 串口使用串口一,波特率9600 单片机引脚------------CH ...

  5. Flutter布局5---Container

    Container 容器 简介一个常用的widget,它结合了常见的绘画,定位和大小调整·该容器首先让child填充绘制,然后再将其他的约束应用于填充范围.·在绘画过程中,容器先应用给定的转换,再绘制 ...

  6. OSI七层协议模型

    OSI七层模型详解 TCP/IP协议 链接:https://www.nowcoder.com/questionTerminal/b2ccf60bbb13483b94b4bffe200b4f3c 来源: ...

  7. Poj 2165 Milking Grid(kmp)

    Milking Grid Time Limit: 3000MS Memory Limit: 65536K Description Every morning when they are milked, ...

  8. 安装包设计-------打包(MFC)---------知识总结

    目录: 1.选择文件夹 2.判断文件夹或文件是否存在 3.通过cmd命令行向程序中传递参数. 4.路径处理 5.文件夹以及文件的删除 6.复制文件 7.创建目录 8.从当前的应用程序中抽取资源 9.引 ...

  9. elasticsearch shield(5.0以下版本 权限认证)

    elasticsearch 5.0以下的版本要用到权限控制的话需要使用shield.下载地址: https://www.elastic.co/downloads/shield5.0以上的版本则可以使用 ...

  10. 定位ScheduledExecutorService过了一段时间不执行问题

    今天查看生产环境的sentinel控制台,发现某dubbo应用一共5个节点,有3个失联了. 查看失联节点的应用日志,服务没有挂,各dubbo接口的日志正常在打印. 在应用节点ping/telnet s ...