libiec61850探究【6】- Windows中qt工程编译goose publisher

11 篇文章 1 订阅
6 篇文章 12 订阅

IEC61850交流QQ群:610793899

其实在windows是是不推荐使用mingw编译libIEC61850库的,主要是Windows底层有些依赖库(如ws2_32.lib等)是默认采用微软自己的visual studio编译链来进行编译的,对于mingw支持不好,很多时候需要你再单独去编译mingw的依赖库,实在是有些繁琐。与其这样,倒不如考虑在windows上使用vs的合适版本进行编译来的更方便。

这儿主要是展示mingw的编译基本流程,供大家参考。

背景条件:

1.libIEC61850的版本是1.5.0

2.mingw版本是mingw49_32

3.操作系统是windows server2012

好了,言归正传。

首先,使用cmake生成VS2013的解决方案以及工程文件:

>Cmake –G “Visual Studio 12 2013”

找到libiec61850.sln解决方案文件:

对于上述的cmake生成的是vs2013的解决方案、工程文件,为了避免头文件、lib库的编译、链接,我们选择用对应的vs2013打开该解决方案文件。

选中iec61850工程,执行生成,如果没有出错,在src/debug目录下会生成iec61850.lib,在hal/debug目录下生成hal.lib,接下来我们就可以使用在qt工程中编写goose publisher代码进行测试了。

注意事项:

1.windows中的qt默认是mingw版本的,因此对于c++代码而言,qt相关SDK库都是不能和vs2013通用的。所以,需要下载vs2013版本的qt安装包,或者自己使用vs2013对qt源码进行编译。

2.在qt creator的套件管理器中,在默认的mingw构建套件之外,要额外添加一个vs2013版本的构建套件。

在新建的qt工程中,增加并修改main.cpp文件内容如下所示:

#include "iec61850_server.h"
#include "hal_thread.h"
#include "static_model.h"
#include "asynciedcallbackwrapper.h"
#include "mms_value.h"
#include "goose_publisher.h"
#include "hal_thread.h"

#include <stdint.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>

#include <QCoreApplication>
#include <QMap>

extern IedModel iedModel;
//extern QMap<QString, DataAttribute*> daMap;

static int running = 0;

void sigint_handler(int signalId)
{
    running = 0;
}

int main(int argc, char *argv[])
{
//    QCoreApplication a(argc, argv);

    char *interface;

    if (argc > 1)
        interface = argv[1];
    else
        interface = "eth0";

    printf("Using interface %s\n", interface);

    LinkedList dataSetValues = LinkedList_create();

    LinkedList_add(dataSetValues, MmsValue_newIntegerFromInt32(1234));
    LinkedList_add(dataSetValues, MmsValue_newBinaryTime(false));
    LinkedList_add(dataSetValues, MmsValue_newIntegerFromInt32(5678));

    CommParameters gooseCommParameters;

    gooseCommParameters.appId = 1000;
    gooseCommParameters.dstAddress[0] = 0x01;
    gooseCommParameters.dstAddress[1] = 0x0c;
    gooseCommParameters.dstAddress[2] = 0xcd;
    gooseCommParameters.dstAddress[3] = 0x01;
    gooseCommParameters.dstAddress[4] = 0x00;
    gooseCommParameters.dstAddress[5] = 0x01;
    gooseCommParameters.vlanId = 0;
    gooseCommParameters.vlanPriority = 4;

    /*
     * Create a new GOOSE publisher instance. As the second parameter the interface
     * name can be provided (e.g. "eth0" on a Linux system). If the second parameter
     * is NULL the interface name as defined with CONFIG_ETHERNET_INTERFACE_ID in
     * stack_config.h is used.
     */
    GoosePublisher publisher = GoosePublisher_create(&gooseCommParameters, interface);

    if (publisher) {
        GoosePublisher_setGoCbRef(publisher, "simpleIOGenericIO/LLN0$GO$gcbAnalogValues");
        GoosePublisher_setConfRev(publisher, 1);
        GoosePublisher_setDataSetRef(publisher, "simpleIOGenericIO/LLN0$AnalogValues");
        GoosePublisher_setTimeAllowedToLive(publisher, 500);

        int i = 0;

        for (i = 0; i < 4; i++) {
            Thread_sleep(1000);

            if (i == 3) {
                /* now change dataset to send an invalid GOOSE message */
                LinkedList_add(dataSetValues, MmsValue_newBoolean(true));
                GoosePublisher_publish(publisher, dataSetValues);
            }
            else {
                if (GoosePublisher_publish(publisher, dataSetValues) == -1) {
                    printf("Error sending message!\n");
                }
            }
        }

        GoosePublisher_destroy(publisher);
    }
    else {
        printf("Failed to create GOOSE publisher. Reason can be that the Ethernet interface doesn't exist or root permission are required.\n");
    }

    LinkedList_destroyDeep(dataSetValues, (LinkedListValueDeleteFunction) MmsValue_delete);

    return 0;

}

Pro工程文件lib依赖库设置部分内容如下:

编译该工程。

在命令行参数中,设置启动网络适配器的索引值,我这儿是4,每个人需要根据自己的情况作出改变。

运行,并与subscriber进行测试。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值