/*
 * gc_remote_display.h
 *
 *  Created on: 17/ott/2017
 *      Author: chessaa
 */

#ifndef GC_REMOTE_DISPLAY_H_
#define GC_REMOTE_DISPLAY_H_

#include <stdint.h>


struct gc_remote_display_header_t
{
	typedef uint16_t word_t;
	typedef uint8_t small_word_t;

	enum geometry_t { max_dx=640, max_dy=512, max_rows_per_message=2};

	enum gev_fmt_t
	{
		GEV_LEADER = 0x81,
		GEV_TRAILER = 0x82,
		GEV_PAYLOAD = 0x83
	};

	struct gev_header_t
	{
		uint16_t gev_status;
		uint16_t gev_flags;
		uint8_t fmt;
		uint8_t spare;
		uint16_t spare2;
		//uint64_t blockid;
		uint32_t blockid_h;
		uint32_t blockid_l;
		uint32_t packet_id;
	};

	gev_header_t gev;

	small_word_t type;
		enum { t_leader=0, t_payload=1, t_payload_please_ack=3, t_trailer=4, t_palette=100};
	small_word_t ext_code;	//t_palette -> palett refresh cookie

	word_t frag_number;
	word_t generated_frames;
	word_t sent_frames;
	word_t dx;
	word_t dy;
	word_t pitch;

	word_t row;
	small_word_t number_of_rows;
	small_word_t spare0;
	word_t spare1;

	//uint8_t data[max_dx*max_rows_per_message];
};

struct gc_remote_display_buffer_t
{
	gc_remote_display_header_t header;
	uint8_t data[gc_remote_display_header_t::max_dx*gc_remote_display_header_t::max_rows_per_message];
};
//Constrains: sizeof(gc_remote_display_buffer_t)< Ethernet MTU excluding UDP header

struct gc_remote_display_reply_t {
	gc_remote_display_header_t::gev_header_t gev;

	gc_remote_display_header_t::small_word_t type;
	gc_remote_display_header_t::small_word_t spare;

	gc_remote_display_header_t::word_t frag_number;
	gc_remote_display_header_t::word_t generated_frames;
	gc_remote_display_header_t::word_t sent_frames;
	gc_remote_display_header_t::word_t max_capacity;

	gc_remote_display_header_t::word_t spare2[3];
};

#endif /* GC_REMOTE_DISPLAY_H_ */
