/*
 * All Rights Reserved (C) 2021-2025
 * Exoligent SARL (Colombes, France)
 * Website: www.exoligent.com
 * Author : Maxime Coroyer <maxime.coroyer@exoligent.com>
 */

#ifndef __STA_H__
#define __STA_H__

#include "common.h"
#include "libpowerfip.h"

#define PWRFIP_BITRATE_RANGE (_PWRFIP_BITRATE_MAX - _PWRFIP_BITRATE_MIN)

/* turn around time (default) in us, according to the bitrate */
static const uint32_t tr_ustime[PWRFIP_BITRATE_RANGE] = {
    424, /* 424us@31.25Kbps */
    30, /* 30us@1Mbps */
    30, /* 30us@2.5Mbps */
    32, /* 32us@5Mbps */
    32, /* 32us@12.5Mbps */
    32, /* 32us@25Mbps */
};

/* silence time (default) in us, according to the bitrate */
static const uint32_t ts_ustime[PWRFIP_BITRATE_RANGE] = {
    4096, /* 4096us@31.25Kbps */
    150, /* 150us@1Mbps */
    96, /* 96us@2.5Mbps */
    92, /* 92us@5Mbps */
    92, /* 92us@12.5Mbps */
    92, /* 92us@25Mbps */
};

static const char *pwrfip_node_state_str[_PWRFIP_NODE_STATE_MAX] = {
    /* PWRFIP_NODE_STATE_INITIAL */
    "initial",
    /* PWRFIP_NODE_STATE_LOADED */
    "loaded",
    /* PWRFIP_NODE_STATE_READY */
    "ready",
    /* PWRFIP_NODE_STATE_RUNNING */
    "running",
};

static const char *pwrfip_ba_state_str[_PWRFIP_BA_STATE_MAX] = {
    /* PWRFIP_BA_STATE_INITIAL */
    "initial",
    /* PWRFIP_BA_STATE_READY */
    "ready",
    /* PWRFIP_BA_STATE_STARTING */
    "starting",
    /* PWRFIP_BA_STATE_IDLE */
    "idle",
    /* PWRFIP_BA_STATE_RUNNING */
    "running",
};

static const char *pwrfip_node_op_str[_PWRFIP_NODE_OP_MAX] = {
    /* _PWRFIP_NODE_OP_UNKNOWN */
    "unknown",
    /* PWRFIP_NODE_OP_WAIT_RX_RP_FRM */
    "rx rp frame",
    /* PWRFIP_NODE_OP_WAIT_TX_RP_FRM */
    "tx rp frame",
    /* PWRFIP_NODE_OP_WAIT_RX_ID_FRM */
    "rx id frame",
    /* PWRFIP_NODE_OP_WAIT_TX_ID_FRM */
    "tx id frame",
};

static const char *pwrfip_ba_wind_str[_PWRFIP_BA_WIND_TYPE_MAX] = {
    /* _PWRFIP_BA_WIND_TYPE_NONE */
    "none",
    /* PWRFIP_BA_WIND_PER */
    "periodic",
    /* PWRFIP_BA_WIND_APER_VAR */
    "aper. var",
    /* PWRFIP_BA_WIND_APER_MSG */
    "aper. msg",
    /* PWRFIP_BA_WIND_WAIT */
    "wait",
};

static const char *pwrfip_var_err_str[_PWRFIP_VAR_ERR_MAX] = {
    /* _PWRFIP_VAR_OK */
    "no error",
    /* PWRFIP_VAR_ID_UNKNOWN */
    "unknown var id",
    /* PWRFIP_VAR_NOT_PRODUCING */
    "not a producing var",
    /* PWRFIP_VAR_NOT_CONSUMING */
    "not a consuming var",
    /* PWRFIP_VAR_TX_APER_CH_UNKNOWN */
    "unknown tx aper channel",
    /* PWRFIP_VAR_PDU_INCONSISTENT */
    "inconsistent var pdu",
    /* PWRFIP_VAR_LEN_TOO_LONG */
    "var length too long",
    /* PWRFIP_VAR_LEN_TOO_SHORT */
    "var length too short",
    /* PWRFIP_VAR_NEVER_RECEIVED */
    "var never received",
    /* PWRFIP_VAR_TX_APER_FIFO_EMPTY */
    "tx aper queue is empty",
    /* PWRFIP_VAR_TX_APER_FIFO_FULL */
    "tx aper queue is full",
    /* PWRFIP_VAR_NOT_MEANING */
    "payload not significant",
    /* PWRFIP_VAR_NOT_REFRESH */
    "payload not refreshed",
    /* PWRFIP_VAR_NOT_PROMPT */
    "payload not prompt",
    /* PWRFIP_VAR_BAD_PROMPT_PER */
    "bad reading frequency (promptness)",
    /* PWRFIP_VAR_BAD_REFRESH_PER */
    "bad writing frequency (refreshment)"
};

void tst_pwrfip_ba_state_handler(struct pwrfip_node *node,
                struct pwrfip_event *evt);
void tst_pwrfip_error_handler(struct pwrfip_node *node,
                enum pwrfip_error_code code);
void tst_pwrfip_reset_handler(struct pwrfip_node *node);
void tst_pwrfip_sync_rw_op_handler(struct pwrfip_node *node,
        struct pwrfip_var *var, struct pwrfip_event *event);
void print_node_infos(struct pwrfip_node *node);

#endif
