/************************************************************************/
/* Copyright 2003-2016 MBARI											*/
/************************************************************************/
/* Summary	: Definitions for Utility library for OASIS5				*/
/* Filename : utils.h													*/
/* Author	: Robert Herlien (rah)										*/
/* Project	: OASIS Mooring Replacement (OASIS5)						*/
/* Revision: 0.1														*/
/* Created	: 06/28/2016												*/
/*																			*/
/* MBARI provides this documentation and code "as is", with no warranty,	*/
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium	*/
/* Research Institute to assist in its use, correction, modification, or	*/
/* enhancement. This information should not be published or distributed to	*/
/* third parties without specific written permission from MBARI.			*/
/*																			*/
/************************************************************************/
/* Modification History:												*/
/* 07jan2003 rah - created for OASIS3									*/
/* 28jun2016 rah - created for OASIS5 from OASIS3						*/
/************************************************************************/

#ifndef INCutilsh
#define INCutilsh		1

#include <mbariTypes.h>
#include <oasis.h>
#include <otask.h>
#include <istdio.h>

#define find_str(src, tgt)		strstr(src, tgt)


/****************************************/
/*		Macros							*/
/****************************************/

//#include <sys/endian.h>
//#define swapWord(w)	__swap16md(w)
//#define swapLong(l)	__swap32md(l)

#define swapWord(w)		(w)
#define swapLong(l)		(l)

#define newline()		newlinep(pvTaskGetThreadLocalStoragePointer(NULL, ConsoleP))

#define xprintf			iprintf
#define kbhit()			xRxAvail()


/****************************************/
/* Function Declarations				*/
/****************************************/

void	doputc(Int32 c, SerDesc *sdp);
void	xputcp(Int32 c, SerDesc *sdp);
void	xputc(Int32 c);
void	newlinep(SerDesc *sdp);
Int32	xgetc_tmout(Nat32 tmout);
Int32	xgetc(void);
void	xputs(const char *s);
void	xputn(const char *s, Int32 len);
Int32	xgetn_tmout(char *s, Int32 len, Nat32 tmout);
Int32	xgets_tmout_flg(char *s, Int32 len, Nat32 tmout, Word flags);
Int32	xgets_tmout(char *s, Int32 len, Nat32 tmout);
Int32	xgets(char *s, Int32 len);
void	xflush_ser(Nat32 timeout);
void	xdrain_ser(Nat32 tmout);
void	xser_break(Int32 breakTicks);
int		xTxStatus(void);
int		xRxAvail(void);
MBool	delimit(Reg char c);
Int16	getByte(char *p, Nat16 radix);
char	*cmp_ulc(const char *s, const char *cs);
Nat16	bitsOn(Nat16 num);

Nat16	getSwapWord(Nat16 *p);
Nat32	getSwapLong(Nat32 *p);

#endif	/* INCutilsh */
