/**
 * @file ps_sample_app.h
 *
 * @brief This file contains function prototypes and data definitions that helps
 * to create a PS application
 */

#ifndef PS_SAMP_APP_H_
#define PS_SAMP_APP_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ipcc_common.h>
#include <ipcc_lib_common.h>
#include <comms_al.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/select.h>
#include "ps_intf_ctrl_msg.h"

#ifdef __cplusplus
extern "C" {
#endif
/**@}*/
/**\name C standard macros */
#ifndef NULL
#ifdef __cplusplus
#define NULL                                      0
#else
#define NULL                            ((void *) 0)
#endif
#endif

#define PS_SOCK_RX_PORT_ADDR   5003
#define PS_SOCK_RX_IP_ADDR     "192.168.10.2"

#define PS_SOCK_TX_PORT_ADDR   5004
#define PS_SOCK_TX_IP_ADDR     "192.168.10.2"


/******** Automation Framework Start *********/

#define PS_AUTOM_MAX_INPUT (100)

typedef struct _ps_autom_user_input
{
	int ps_autom_arg_cnt;
	int *ps_autom_argv[PS_AUTOM_MAX_INPUT];
	char ps_autom_argv_valid[PS_AUTOM_MAX_INPUT];
}s_ps_autom_user_input;

/******** Automation Framework End *********/

//socket details
typedef struct sock_info
{
    char ip_addr[16];
    char port_num[5];
}s_sock_info;

typedef struct
{
    uint32 addr;
    uint32 port;
    s_ipcc_frame *ipcc_frame;
} ps_server_param;
FILE *fptr;

/**
 * @brief structure that holds the interface message header
 *
 * Bit Name    Value Description
 * 31  Notification Indicator  0 – Not a notification; 1 – Notification
 * 30  Command / Response Indicator    This bit is don’t care / invalid when notification bit 31 is set
 *     0 – Command; 1 – Response
 * 29:28   Reserved    Don’t care
 * 27:16   Command / Response / Notification Identity Number   0 to 4095
 * 15:10   Reserved    Don’t care
 * 9:0 Data Length Indicator   Specifies the data length in number of bytes (excluding header length)
 *     0 – 1023; 0 – Specifies data / payload is not present
 */
typedef struct _obc_ps_intf_msg_header
{
    int ni;
    int cr;
    int cmd_resp_ntf_id;
    int data_len_ind;
}obc_ps_intf_msghdr;

typedef enum _obc_ps_ntf_type
{
    NO_NOTIFY_TYPE = 0,
    NOTIFY_TYPE
}obc_ps_ntf_type;

typedef enum _obc_ps_cmd_rsp_type
{
    CMD_TYPE = 0,
    RESP_TYPE
}obc_ps_cmd_rsp_type;

typedef enum _obc_ps_cmd_rsp_id
{
    OBC_PS_PWR_OFF = 100,
}obc_ps_cmd_rsp_id;

void *ps_rcv_socket_server_thread (void * params);
void *ps_get_icd_cmd_id_thread(void *params);
void *ps_evnt_trig_thread(void *params);
void ps_encode_icd_cmd(uint16 cmd_id);
void *ps_rsp_enc_socket_server_thread(void *params);
int ps_print_data( s_ipcc_frame * ipcc_frame);
void ps_app_socket_server_init(uint32 addr, uint32 port, s_ipcc_frame *ipcc_orig);
void validate_seq_num(uint16 actual_seq_no);
int ps_socket_send(uint8 *data, uint16 data_len);

void ft_ps_set_enc_id(void);



#ifdef __cplusplus
}
#endif
#endif /*PS_SAMP_APP_H_*/
