//
//
//
//			POSNET BASE EXAMPLES
//			EXAMPLE LONG COMMAND HANDLING
//
//

#include <stdlib.h>
#include <string>
#include <iostream>
#include <istream>
#include <limits>
#ifdef WIN32
#include <windows.h>
#endif
#include "../../include/posnet.h"
#include "../../include/posnet_hlapi.h"

using namespace std;



int main(int argc, char *argv[])
{

#ifdef WIN32
	WSADATA WSAData;
	if (WSAStartup (MAKEWORD(2,0), &WSAData) != 0) 
	{
		MessageBox (NULL, TEXT("WSAStartup failed!"), TEXT("Error"), MB_OK);
		return FALSE;
	}
#endif

#include "../setup.inc"

	POSNET_HANDLE rq,rq1;
	POSNET_STATUS pstat;
	if (pstat=POSS_RepPTU(hLocalDevice,&rq)==POSNET_STATUS_OK)
	{
		if (pstat=POSS_DateGet(hLocalDevice,&rq1)==POSNET_STATUS_OK)
		{
			int x=30;
			while (POS_WaitForRequestCompleted(rq1,1000)!=POSNET_STATUS_OK && x--);
			if (POS_GetRequestState(rq1)==POSNET_RSTATE_ERRCOMPLETED || POS_GetRequestState(rq1)==POSNET_RSTATE_COMPLETED)
			{
				if (POS_GetRequestState(rq1)==POSNET_RSTATE_COMPLETED)
				{
					char buffer[256];
					POSG_DateGet(rq1,buffer);
					cout << "Date: " << buffer << endl;
				}
				else
				POSG_Default(rq1);
			}
		}
		else
		{
			cout << "CashReg Date get - function error : 0x" << hex << pstat << dec << endl;
		}
		int x=30;
		while (POS_WaitForRequestCompleted(rq,1000)!=POSNET_STATUS_OK && x--);
		if (POS_GetRequestState(rq)==POSNET_RSTATE_ERRCOMPLETED || POS_GetRequestState(rq)==POSNET_RSTATE_COMPLETED) POSG_Default(rq);
	}
	else
	{
		cout << "CashReg report failed - function error : 0x" << hex << pstat << dec << endl;
	}

	POS_CloseDevice(hLocalDevice);
	POS_DestroyDeviceHandle(hDevice);
	return 0;
}
