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

#ifndef __GW_H__
#define __GW_H__

#include "common.h"
#include "fip.h"
#include "mbus.h"

#define APP_VERSION "1.0.0"

struct gw_measure {
    /* synchro callback measure */
    uint64_t nb_sync_cb;
    uint64_t cumul_sync_cb_duration;
    uint64_t min_sync_cb_duration;
    uint64_t max_sync_cb_duration;
    uint64_t min_sync_cb_last;
    uint64_t max_sync_cb_last;
    /* fip variables stats */
    uint64_t r_var_ok;
    uint64_t w_var_ok;
    uint64_t r_var_warn;
    uint64_t w_var_warn;
};

struct gateway {
    /* gateway modbus part */
    struct gw_modbus mbus;
    /* gateway fip part */
    struct gw_fip fip;
    /* gateway measurement */
    struct gw_measure stats;
};

/****************************************************************************************
 * GATEWAY FUNCTIONS
 ***************************************************************************************/
int gw_cfg_parse(const char *json_path, struct gateway *gw);
extern void gw_display_update(struct gateway *gw);
/****************************************************************************************
 * MODBUS FUNCTIONS
 ***************************************************************************************/
extern int mbus_srv_start(struct gateway *gw);
extern int mbus_srv_stop(struct gateway* gw);
extern void mbus_display_update(struct gateway *gw);
/****************************************************************************************
 * FIP FUNCTIONS
 ***************************************************************************************/
extern int fip_start(struct gateway *gw);
extern int fip_stop(struct gateway *gw);
extern void fip_display_update(struct gateway *gw);
extern int fip_report(struct gateway *gw);

#endif
