IEC104规约服务器端源代码

更新时间:2023-07-30 13:53:36 阅读: 评论:0

#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include "cs104_slave.h"
#include "hal_thread.h"
#include "hal_time.h"
static bool running = true;
void
sigint_handler(int signalId)
{
    running = fal;
}
void
printCP56Time2a(CP56Time2a time)
{
    printf("%02i:%02i:%02i %02i/%02i/%04i", CP56Time2a_getHour(time),
                            CP56Time2a_getMinute(time),
                            CP56Time2a_getSecond(time),
水浒传作者是谁                            CP56Time2a_getDayOfMonth(time),
                            CP56Time2a_getMonth(time),履职情况怎么写
                            CP56Time2a_getYear(time) + 2000);
}
static bool
clockSyncHandler (void* parameter, IMasterConnection connection, CS101_ASDU asdu, CP56Time2a newTime)
{
    printf("Process time sync command with time "); printCP56Time2a(newTime); printf("\n");
    return true;
}
static bool
interrogationHandler(void* parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qoi)
{
    printf("Received interrogation for group %i\n", qoi);
    if (qoi == 20) { /* only handle station interrogation */
        CS101_AppLayerParameters alParams = IMasterConnection_getApplicationLayerParameters(connection);
        IMasterConnection_ndACT_CON(connection, asdu, fal);
        /* The CS101 specification only allows information objects without timestamp in GI respons */
        CS101_ASDU newAsdu = CS101_ASDU_create(alParams, fal, CS101_COT_INTERROGATED_BY_STATION,
                0, 1, fal, fal);
        InformationObject io = (InformationObject) MeasuredValueScaled_create(NULL, 100, -1, IEC60870_QUALITY_GOOD);
        CS101_ASDU_addInformationObject(newAsdu, io);
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject)
            MeasuredValueScaled_create((MeasuredValueScaled) io, 101, 23, IEC60870_QUALITY_GOOD));
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject)
            MeasuredValueScaled_create((MeasuredValueScaled) io, 102, 2300, IEC60870_QUALITY_GOOD));
        InformationObject_destroy(io);
        IMasterConnection_ndASDU(connection, newAsdu);
        CS101_ASDU_destroy(newAsdu);
        newAsdu = CS101_ASDU_create(alParams, fal, CS101_COT_INTERROGATED_BY_STATION,
丰收的田野                    0, 1, fal, fal);
        io = (InformationObject) SinglePointInformation_create(NULL, 104, true, IEC60870_QUALITY_GOOD);
        CS101_ASDU_addInformationObject(newAsdu, io);
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject)
            SinglePointInformation_create((SinglePointInformation) io, 105, fal, IEC60870_QUALITY_GOOD));
        InformationObject_destroy(io);
        IMasterConnection_ndASDU(connection, newAsdu);
        CS101_ASDU_destroy(newAsdu);
        newAsdu = CS101_ASDU_create(alParams, true, CS101_COT_INTERROGATED_BY_STATION,
                0, 1, fal, fal);
        CS101_ASDU_addInformationObject(newAsdu, io = (InformationObject) Si
nglePointInformation_create(NULL, 300, true, IEC60870_QUALITY_GOOD));
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject) SinglePointInformation_create((SinglePointInformation) io, 301, fal, IEC60870_QUALITY_GOOD));
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject) SinglePointInformation_create((SinglePointInformation) io, 302, true, IEC60870_QUALITY_GOOD));
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject) SinglePointInformation_create((SinglePointInformation) io, 303, fal, IEC60870_QUALITY_GOOD));
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject) SinglePointInformation_create((SinglePointInformation) io, 304, true, IEC60870_QUALITY_GOOD));
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject) SinglePointInformation_create((SinglePointInformation) io, 305, fal, IEC60870_QUALITY_GOOD));
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject) SinglePointInformation_create((SinglePointInformation) io, 306, true, IEC60870_QUALITY_GOOD));
        CS101_ASDU_addInformationObject(newAsdu, (InformationObject) SinglePointInformation_create((SinglePointInformation) io, 307, fal, IEC60870_QUALITY_GOOD));
        InformationObject_destroy(io);
        IMasterConnection_ndASDU(connection, newAsdu);
        CS101_ASDU_destroy(newAsdu);
        IMasterConnection_ndACT_TERM(connection, asdu);
    }
    el {
        IMasterConnection_ndACT_CON(connection, asdu, true);
    }
    return true;
}
static bool
asduHandler(void* parameter, IMasterConnection connection, CS101_ASDU asdu)
{
    if (CS101_ASDU_getTypeID(asdu) == C_SC_NA_1) {
        printf("received single command\n");
        if  (CS101_ASDU_getCOT(asdu) == CS101_COT_ACTIVATION) {
            InformationObject io = CS101_ASDU_getElement(asdu, 0);
            if (InformationObject_getObjectAddress(io) == 5000) {
                SingleCommand sc = (SingleCommand) io;
                printf("IOA: %i switch to %i\n", InformationObject_getObjectAddress(io),
                        SingleCommand_getState(sc));
                CS101_ASDU_tCOT(asdu, CS101_COT_ACTIVATION_CON);
            }
            el
                CS101_ASDU_tCOT(asdu, CS101_COT_UNKNOWN_IOA);
            InformationObject_destroy(io);
        }
        el
            CS101_ASDU_tCOT(asdu, CS101_COT_UNKNOWN_COT);
        IMasterConnection_ndASDU(connection, asdu);
        return true;
    }
    return fal;
}
static bool
connectionRequestHandler(void* parameter, const char* ipAddress)
{
    printf("New connection from %s\n", ipAddress);
#if 0
    if (strcmp(ipAddress, "127.0.0.1") == 0) {
        printf("Accept connection\n");
        return true;
    }
    el {思想政治品德考核
        printf("Deny connection\n");
方天戟        return fal;
    }
#el
    return true;
#endif
}
int
main(int argc, char** argv)
{
    /* Add Ctrl-C handler */
    signal(SIGINT, sigint_handler);
    /* create a new slave/rver instan
ce with default connection parameters and
    * default message queue size */
    CS104_Slave slave = CS104_Slave_create(100, 100);
    CS104_Slave_tLocalAddress(slave, "0.0.0.0");
    CS104_Slave_tServerMode(slave, CS104_MODE_SINGLE_REDUNDANCY_GROUP);
    /* get the connection parameters - we need them to create correct ASDUs */
    CS101_AppLayerParameters alParams = CS104_Slave_getAppLayerParameters(slave);
    /* t the callback handler for the clock synchronization command */
    CS104_Slave_tClockSyncHandler(slave, clockSyncHandler, NULL);父子情深
    /* t the callback handler for the interrogation command */
    CS104_Slave_tInterrogationHandler(slave, interrogationHandler, NULL);
    /* t handler for other message types */
    CS104_Slave_tASDUHandler(slave, asduHandler, NULL);
    CS104_Slave_tConnectionRequestHandler(slave, connectionRequestHandler, NULL);
    CS104_Slave_start(slave);
    if (CS104_Slave_isRunning(slave) == fal) {
        printf("Starting rver failed!\n");
        goto exit_program;
    }
    int16_t scaledValue = 0;
曹操有几个儿子    while (running) {
        Thread_sleep(1000);
        CS101_ASDU newAsdu = CS101_ASDU_create(alParams, fal, CS101_COT_PERIODIC, 0, 1, fal, fal);
        InformationObject io = (InformationObject) MeasuredValueScaled_create(NULL, 110, scaledValue, IEC60870_QUALITY_GOOD);
献血活动新闻稿        scaledValue++;
        CS101_ASDU_addInformationObject(newAsdu, io);
        InformationObject_destroy(io);
        /* Add ASDU to slave event queue - don't relea the ASDU afterwards!
        * The ASDU will be relead by the Slave instance when the ASDU
        * has been nt.
        */
        CS104_Slave_enqueueASDU(slave, newAsdu);
        CS101_ASDU_destroy(newAsdu);
    }
    CS104_Slave_stop(slave);
exit_program:
    CS104_Slave_destroy(slave);
    Thread_sleep(500);
}

本文发布于:2023-07-30 13:53:36,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1102018.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:考核   献血   情况   政治   活动   思想   履职   新闻稿
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图