/*
 * sfp_helper.h
 *
 */


#include "sfp_types.h"

#ifdef SFP_STATIC_CHECKS

#include <stdlib.h>

static_assert((sizeof(SFP::frag_header_t) & 0x03)==0, "frag_header not multiple of 4");
static_assert((sizeof(SFP::image_header_t) & 0x03)==0, "image_header_t not multiple of 4");
static_assert((sizeof(SFP::image_leader_reply_t) & 0x03)==0, "image_leader_reply_t not multiple of 4");

static_assert((sizeof(SFP::image_leader_packet_t)<1400), "image_leader_reply_t not multiple of 4");

static_assert((offsetof(SFP::frag_header_t, frag_total) & 0x01)==0, "frag_total misaligned");
static_assert((offsetof(SFP::frag_header_t, record_counter) & 0x03)==0, "record_counter misaligned");
static_assert((offsetof(SFP::frag_header_t, payload_total_size) & 0x03)==0, "payload_total_size misaligned");

#endif

#include <string.h>

#define SPF_HELPER_MAYBE_UNUSED	__attribute__((unused))


static uint16_t sfp_data_tag(unsigned char c0, unsigned char c1)
{
	uint16_t t=c0;
	t=t|(char(c1)<<8);
	return t;
}
//static void sfp_frag_header_initialize(SFP::frag_header_t& fh, SFP::frag_tags_t dir, uint8_t src, uint8_t flow_id) SPF_HELPER_MAYBE_UNUSED;
static void sfp_frag_header_initialize(SFP::frag_header_t& fh, SFP::frag_tags_t dir, uint8_t src, uint8_t flow_id)
{
	fh.sync_marker.marker[0]=SFP::frag_sync_marker;
	fh.sync_direction=dir;
	fh.src=src;
	fh.flow_id=flow_id;
}


static int sfp_image_payload_offset(SFP::frag_header_t& fh)
{
	unsigned int offset=fh.payload_offset;
	return offset-sizeof(SFP::image_leader_t);
}
