//----------------------------------------------------
/**
	\file		ctk/inc/ucnp1c.h
	\ingroup	serial
	\ingroup	all

	\brief		Funkce pro seriovou komunikaci protokol Modbus
				<<< ALL >>>

	\author		ConTeK s.r.o., Ing. Vladimir Kastner
	\version	01.01
	\date		10.10.2009
*/
//----------------------------------------------------

#ifndef _UCNP1C_H_
#define _UCNP1C_H_		//!< Definice pritomnosti knihovny

#include <ctktypes.h>
#include <comm.h>

//----------------------------------------------------
/**
	\brief	Definice CNP1C protokolu
			DNode,*data*
			  1  , xxx  Bytes
*/
//----------------------------------------------------

typedef uint8_t			dnode_t;			//!< typ adresy site <1..255>, 0 = all = broadcast, Device Node

#ifdef MSVC
//#pragma pack(show)
#pragma pack(push,1)
//#pragma pack(show)
#endif // MSVC

typedef struct
{
	dnode_t		DAddr;					//!< adresa zarizeni, Device Address
//	uint8_t		Data[0];				// data zpravy

#ifndef MSVC
} __attribute__((packed)) CNP1CMESS;
#else
} CNP1CMESS;
#endif // MSVC

#ifdef MSVC
#pragma pack(pop)
//#pragma pack(show)
#endif // MSVC

typedef struct
{
	dnode_t		DAddr;					//!< adresa zarizeni, Device Address
//	uint8_t		Data[0];				// data zpravy

} CNP1CMESSu;


//----------------------------------------------------
//! Struktura kontextu automatu vysilace a prijimace

typedef struct
{
	COMMDESC 			* Cmm;			//!< ukazatel na ovladac seriove komunikace

	dnode_t				DAddr;			//!< Device Address, master = broadcast = 0

	cmSend_t			Send;			//!< ukazatel na Send linkove vrstvy
	cmRecv_t			Recv;			//!< ukazetel na Recv linkove vrstvy

} CNP1CDESC;


//----------------------------------------------------
/**
	\brief	Funkce pro inicializaci komunikacniho automatu

	\param	cnp1c		Struktura kontextu automatu
	\param	cmm			Adresa knihovny fyzicke vrstvy
	\param	Node		Adresa komunikacniho uzlu, Master = 0
*/
//----------------------------------------------------

bool_t Cnp1CInitialize(CNP1CDESC * const _cnp1a, COMMDESC * const _cmm, const dnode_t _dAddr);


//----------------------------------------------------
/**
	\brief	Funkce pro ukonceni komunikacniho automatu

*/
//----------------------------------------------------

void Cnp1CFinalize(const CNP1CDESC * const _cnp1c);

#endif // _UCNP1C_H_
