/*
 * goose_out.h
 *
 *  Created on: 08-02-2020
 *      Author: Krzysztof Jakubczyk
 */

#ifndef GOOSE_OUT_H_
#define GOOSE_OUT_H_

#include "tdefs.h"
#include "helper.h"
#include "comm.h"
#include "config.h"

//goose_out bits
#define	GOOSE_OUT_VLAN_EN	0x01

#define GOOSE_TIMESTAMP_MS_MULTIPLIER	(u32)((float)0xFFFFFFFF/1000.0f)

struct goose_out_logic
{
	struct binary_io state_in[16];
	struct binary_io ndscom_in;
	struct binary_io test;
	char *goose_id;
	char *goose_dataset;
	char *goose_cbref;
	char *goose_dstaddr;
	char *sv_id;
	char *sv_dstaddr;
	u8 *tstamp_secs;
	u8 *tstamp_frac;

	u8 *ttl;
	u8 *stnum;
	u8 *sqnum;
	u8 *simulation;
	u8 *ndscom;
	u8 *state[16];

	u8 state_prev[16];
	u32 stnum_cur;
	u32 sqnum_cur;
	u8 values;
	u32 len;
	u32 retrans_cnt;
	u32 retrans_cycle;
	u8 first_packet;
	u8 goose_out_frame[GOOSE_MAX_FR_OUT_SIZE] __attribute__((aligned(4)));
};

struct goose_out_io
{
	u32 state_in[16];
	u32 ndscom_in;
	u32 test_in;
}__attribute__((__packed__));


struct goose_out_params
{
	u32 bits;
	u32 appid;
	u32 cfg_rev;
	u32 vlan_no;
	u32 priority;
	u32 ttl;
	u32 strings_start;
}__attribute__((__packed__));

struct goose_out_args
{
	struct goose_out_io io;
	struct goose_out_params params;
//	u16 crc;
}__attribute__((__packed__));

extern void goose_out(void *args, void *logic);
extern int goose_out_initlog(void *arguments, void *logic);

#endif
