//
//
//
//			POSNET BASE EXAMPLES
//			EXAMPLE QUEUE MODE
//
//

#include <stdlib.h>
#include <string>
#include <iostream>
#include <istream>
#include <limits>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#define Sleep(a) {struct timespec tc,tc1;\
                 tc.tv_sec=0; \
		                  tc.tv_nsec=a*1000*1000; \
				                   nanosleep(&tc,&tc1);   \
						                    }
								    
#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 rq1;

	cout << "Scheduling 32 DateGet Queries" << endl;
	for (int i=0;i<32;i++)
		POSS_DateGet(hLocalDevice,&rq1);
	Sleep(800);
	for (int i=0;i<64;i++)
	{
		if (rq1=POS_GetNextResponse(hLocalDevice))
		{
			unsigned long z=POS_GetRequestCommandSerial(rq1);
			char buffer[256];
			POSG_DateGet(rq1,buffer);
			cout << "Date ("<< z << "): " << buffer << endl;
			Sleep(500);
		}
		
	}

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