/*
 * Copyright (C) 2022 EXOLIGENT (www.exoligent.com)
 * Author: Maxime Coroyer <maxime.coroyer@exoligent.com>
 */

#ifndef __TEST_H__
#define __TEST_H__

#include "common.h"
#include "opc.h"

#define APP_VERSION "1.0.0"

//#define PC_ROOT
#define PC_UNO2372G
//#define PC_UNO1483G

#ifdef PC_ROOT
#  define OPC_PUB_NET_INTERFACE       "eno1"
#  define OPC_PUB_URL                 "opc.eth://40-b0-76-de-7a-06:8.3"
#  define OPC_SUB_NET_INTERFACE       "eno1"
#  define OPC_SUB_URL                 "opc.eth://40-b0-76-de-7a-06:8.3"
#endif

#ifdef PC_UNO2372G
#  define OPC_PUB_NET_INTERFACE       "enp2s0"
#  define OPC_PUB_URL                 "opc.eth://74-fe-48-30-39-eb:8.3"
#  define OPC_SUB_NET_INTERFACE       "enp2s0"
#  define OPC_SUB_URL                 "opc.eth://74-fe-48-42-c2-e4:8.3"
#endif

#ifdef PC_UNO1483G
#  define OPC_PUB_NET_INTERFACE       "enp7s0"
#  define OPC_PUB_URL                 "opc.eth://74-fe-48-42-c2-e4:8.3"
#  define OPC_SUB_NET_INTERFACE       "enp7s0"
#  define OPC_SUB_URL                 "opc.eth://74-fe-48-30-39-eb:8.3"
#endif

//#define OPC_RX_BLOCKING_SOCKET
#define OPC_RX_XDP_ENABLE

// publisher
#define OPC_PUB_PUB_ID              5670
#define OPC_PUB_DATASET_WRITE_ID    62541
#define OPC_PUB_WRITER_GROUP_ID     100
#define OPC_PUB_PUBLISH_PERDIOD_US  250
#define OPC_PUB_FIP_DATA_NAME       "ID[0x3801] - Pong"
#define OPC_PUB_FIP_DATA_ID         0x3801
#define OPC_PUB_FIP_DATA_BSZ        8
// subscriber
#define OPC_SUB_PUB_ID              5671
#define OPC_SUB_DATASET_WRITE_ID    62541
#define OPC_SUB_WRITER_GROUP_ID     101
#define OPC_SUB_FIP_DATA_NAME       "ID[0x3800] - Ping"
#define OPC_SUB_FIP_DATA_ID         0x3800
#define OPC_SUB_FIP_DATA_BSZ        8

struct tst_measure {
    /* => opc pub operation */
    uint64_t nb_pub_op;
    uint64_t min_pub_op_per;
    uint64_t max_pub_op_per;
    /* => opc sub operation */
    uint64_t nb_sub_op;
    uint64_t min_sub_op_per;
    uint64_t max_sub_op_per;
    /* => opc app operation */
    uint64_t nb_app_op;
    uint64_t min_app_op_per;
    uint64_t max_app_op_per;
};

struct tst_session {
    /* opc-ua part */
    struct opc opc;
    /* measurement */
    struct tst_measure stats;
};

extern struct tst_session sess;

/****************************************************************************************
 * OPCUA FUNCTIONS
 ***************************************************************************************/
extern int opc_init(struct tst_session *sess);
extern int opc_pub_start(struct tst_session *sess);
extern int opc_pub_stop(struct tst_session* sess);
extern void opc_display_update(struct tst_session *sess);

#endif