//
//
//
//			POSNET BASE EXAMPLES
//			EXAMPLE 1
//
//

#include <stdlib.h>
#include <string>
#include <iostream>
#include <istream>
#include <limits>
#include <windows.h>
#include "../posnet_lib/posnet.h"
#include "../posnet_lib/hlapi/posnet_hlapi.h"

using namespace std;

/*
template <class charT, class traits>
inline
std::basic_istream<charT,traits>&
ignoreLine(std::basic_istream<charT,traits>& strm)
{
	strm.ignore(std::numeric_limits<int>::max(),strm.widen('\n'));
	return strm;
}*/


string menuLevel0()
{
	do {
	cout << " TESTY - GRUPA " << endl;
	cout << " A - Ustawienia " << endl;
	cout << " B - Raporty " << endl;
	cout << " C - Bazy " << endl;
	cout << " D - Inne " << endl;
	cout << " Q - Koniec " << endl;
	string s;
	cin >> s;
	if (s=="Q" || s=="q") return "";
	if (s!="") return s;
	} while(1);
}

void doLevel1A(POSNET_HANDLE hLocalDevice)
{
	do {
		cout << " TESTY - USTAWIENIA " << endl;
		cout << " A - Pobierz date                     " << " B - Pobierz czas " << endl;
		cout << " C - Pobierz nagłówek                 " << " D - Ustaw serwis na 10.10.2005,POSNET SA" << endl;
		cout << " E - Ustaw nagłówek                   " << " F - Pobierz stopkę " << endl;
		cout << " G - Ustaw stopke                     " << " H - Pobierz param. wyswietlacza " << endl;
		cout << " I - Ustawienia magazynow             " << " J - Pobierz impuls szuflady " << endl;
		cout << " K - Pobierz konf. dzwiekow           " << " L - Pobierz konf. uspienia " << endl;
		cout << " M - Pobierz konf kart rabatowych     " << " N - Pobierz Konf. wysw. tekstow " << endl;
		cout << " O - Pobierz konf. autoryzacji        " << " P - Stan autoryzacji kasy " << endl;
		cout << " R - Pobierz konf. buf.poz.parag.     " << " S - Pobierz konf. druku " << endl;
		cout << " T - Pobierz konf. kasy               " << " U -  Ustaw czasy wylogowania " << endl;
		cout << " V - Pobierz konf. TCP/IP              " << " W - Włacz bufor parag. " << endl;
		cout << " X -                                  " << " Y -  " << endl;
		cout << " Z -                                  " << " 0 -  " << endl;
		cout << " 1 -                                  " << " 2 -  " << endl;
		cout << " 3 -                                  " << " 4 -  " << endl;
		cout << " 5 -                                  " << " 6 -  " << endl;
		cout << " 7 -                                  " << " 8 -  " << endl;
		cout << " 9 -                                  " << " a -  " << endl;
		
		cout << " Q - Koniec " << endl;
		string s;
		cin >> s;
		if (s=="A")
		{
			void *request;
			char date[16];
			POSS_DateGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_DateGet(request,date);
				cout << date << endl;
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="B")
		{
			void *request;
			char date[16];
			POSS_TimeGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_TimeGet(request,date);
				cout << date << endl;
			}
		}
		if (s=="C")
		{
			void *request;
			char flagi[256],linie[256];
			POSS_HeaderGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_HeaderGet(request,flagi,linie);
				cout << "F: " << flagi << " L: " << linie << endl;
			}
		}
		if (s=="D")
		{
			void *request;
			POSS_MaintenanceSet(hLocalDevice,&request,"2005-10-10","POSNET SA");
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
		}
		if (s=="E")
		{
			void *request;
			
			int ile;
			char buf[64];
			cout << "Ile linii:";
			cin  >> ile ;
			cin.ignore(65535,cin.widen('\n'));
			string s,linie;
			string params;
			int k;
			for (int i=0;i<ile;i++)
			{
				if (i) { linie+="\n"; params+="\n"; }
				cout << "Podaj linię : ";
				getline(cin,s);
				linie+=s;
				cout << "Podaj opcje [0-7] : ";
				cin >> k ;cin.ignore(65535,cin.widen('\n'));
				itoa(k,buf,10);
				params+=buf;
			}
			if (ile)
			POSS_HeaderSet(hLocalDevice,&request,(const char*)params.c_str(),(const char*)linie.c_str());
			else
			POSS_HeaderSet(hLocalDevice,&request,NULL,NULL);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="F")
		{
			void *request;
			char flagi[256],linie[256];
			POSS_FooterGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_FooterGet(request,flagi,linie);
				cout << "F: " << flagi << " L: " << linie << endl;
			}
		}
		if (s=="G")
		{
			void *request;
			
			int ile;
			char buf[64];
			cout << "Ile linii:";
			cin  >> ile ;
			cin.ignore(65535,cin.widen('\n'));
			string s,linie;
			string params;
			int k;
			for (int i=0;i<ile;i++)
			{
				if (i) { linie+="\n"; params+="\n"; }
				cout << "Podaj linię : ";
				getline(cin,s);
				linie+=s;
				cout << "Podaj opcje [0-7] : ";
				cin >> k ;cin.ignore(65535,cin.widen('\n'));
				itoa(k,buf,10);
				params+=buf;
			}
			if (ile)
			POSS_FooterSet(hLocalDevice,&request,(const char*)params.c_str(),(const char*)linie.c_str());
			else
			POSS_FooterSet(hLocalDevice,&request,NULL,NULL);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="H")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_DspParamGet(hLocalDevice,&request,(unsigned char)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b,c;
				POSG_DspParamGet(request,&a,&b,&c);
				cout << "Kont: " << (int)a << " Pods: " << (int)b << " Tryb: " << (int)c << endl;
			}
		}
		if (s=="I")
		{
			void *request;

			POSS_StoreCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b,c,d,e,f;
				POSG_StoreCfgGet(request,&a,&b,&c,&d,&e,&f);
				cout << "Magazyn wł: " << (int)a << " Kontrola min: " << (int)b << " Kontrola sprz.: " << (int)c <<" Mag. opak.: " << (int)d <<" Kontrola min.opak.: " << (int)e <<" Kontrola sprz.opak.: " << (int)f << endl;
			}
		}
		if (s=="J")
		{
			void *request;

			POSS_DrawerImpulseGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned short a;
				POSG_DrawerImpulseGet(request,&a);
				cout << "Dlugosc: " << (int)a << endl;
			}
		}
		if (s=="K")
		{
			void *request;

			POSS_SoundCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b,c,d;
				POSG_SoundCfgGet(request,&a,&b,&c,&d);
				cout << "Pozytywne: " << (int)a << " Negatywne: " << (int)b << " Klawiatura: " << (int)c <<" Zrodlo: " << (int)d  << endl;
			}
		}
		if (s=="L")
		{
			void *request;

			POSS_TimeoutsGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b;
				POSG_TimeoutsGet(request,&a,&b);
				cout << "Wylogowanie: " << (int)a << " Wylaczenia: " << (int)b  << endl;
			}
		}
		if (s=="M")
		{
			void *request;

			POSS_DiscntCardCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a;
				unsigned short b,c;
				POSG_DiscntCardCfgGet(request,&a,&b,&c);
				cout << "Wazne: " << (int)a << " Czas: " << (int)b  << " Metoda: " << (int)c<< endl;
			}
		}
		if (s=="N")
		{
			void *request;

			POSS_DspInfoCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b;
				POSG_DspInfoCfgGet(request,&a,&b);
				cout << "Gdy zalogowany: " << (int)a << " Gdy nie zalogowany: " << (int)b  << endl;
			}
		}
		if (s=="O")
		{
			void *request;

			POSS_UserAuthCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b;
				POSG_UserAuthCfgGet(request,&a,&b);
				cout << "Sposob log.: " << (int)a << " Tryb kontroli: " << (int)b  << endl;
			}
		}
		if (s=="P")
		{
			void *request;

			POSS_AuthStatusGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned short a;
				POSG_AuthStatusGet(request,&a);
				cout << "Pozostalo dni: " << (int)a  << endl;
			}
		}
		if (s=="R")
		{
			void *request;

			POSS_BillBufCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b;
				unsigned short c;
				POSG_BillBufCfgGet(request,&a,&b,&c);
				cout << "Aktywny: " << (int)a << " Sygnalizacja: " << (int)b << " Procentowo: " << (int)c  << endl;
			}
		}
		if (s=="S")
		{
			void *request;

			POSS_PrintCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b,c,d;
				POSG_PrintCfgGet(request,&a,&b,&c,&d);
				cout << "Niefiskalne: " << (int)a << " Zmiany PLU: " << (int)b << " Czulosc pap.: " << (int)c << " Obcinacz: " << (int)d  << endl;
			}
		}
		if (s=="T")
		{
			void *request;
			char flagi[256];
			POSS_CashregParGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_CashregParGet(request,flagi);
				cout << "Numer kasy: " << flagi << endl;
			}
		}
		if (s=="U")
		{
			void *request;

			int ile,k;
			
			cout << "Do wylogowania:";
			cin  >> ile ;
			cin.ignore(65535,cin.widen('\n'));
			cout << "Do wylaczenia : ";
			cin >> k ;
			cin.ignore(65535,cin.widen('\n'));
			POSS_TimeoutsSet(hLocalDevice,&request,(unsigned char)ile,(unsigned char)k);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="V")
		{
			void *request;
			POSS_CommCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				//POSG_CashregParGet(request,flagi);
				//cout << "Numer kasy: " << flagi << endl;
			}
		}
		if (s=="W")
		{
			void *request;

			POSS_BillBufCfgSet(hLocalDevice,&request,1,1,7500);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
		}
		
		
		if (s=="Q" || s=="q") return;
	} while(1);
}

void doLevel1C(POSNET_HANDLE hLocalDevice)
{
	do {
		cout << " TESTY - BAZY " << endl;
		cout << " A - Pobierz VAT                          " << " B - Pobierz pozycję paragonową " << endl;
		cout << " C - Stan zapełnienia bufora paragonowego " << " D - Rabat po nazwie " << endl;
		cout << " E - Pobierz nazwe pierwszej grupy        " << " F - Nastepny wolny num. grupy " << endl;
		cout << " G - Pobierz grupe po nazwie              " << " H - Kasowanie statystyk grup " << endl;
		cout << " I - Statystyka grupy                     " << " J - PLU po nazwie" << endl;
		cout << " K - PLU po barkodzie                     " << " L - Statystyka PLU" << endl;
		cout << " M - Czysc statystyki PLU                 " << " N - Usun wszystkie PLU z not." << endl;
		cout << " O - Usun PLU z notat.                    " << " P - Dodaj PLU do notatnika" << endl;
		cout << " R - Nastepny wolny num. PLU              " << " S - Nastepny wolny numer rabatu" << endl;
		cout << " T - Nastepny wolny num. AutoDiscout      " << " U - Czysc statystyki rabatow" << endl;
		cout << " V - Nastepny wolny numer formy plat.     " << " W - Nastepny wolny numer form.kodu." << endl;
		cout << " X - Nastepny wolny numer hotkey          " << " Y - Dodaj sposob platnosci" << endl;
		cout << " Z -                                      " << " 0 - " << endl;
		cout << " 1 -                                      " << " 2 - " << endl;
		cout << " 3 -                                      " << " 4 - " << endl;
		cout << " 5 -                                      " << " 6 - " << endl;
		cout << " 7 -                                      " << " 8 - " << endl;
		cout << " 9 -                                      " << " a - " << endl;
		cout << " b -                                      " << " c - " << endl;
		cout << " Q - Koniec " << endl;
		string s;
		cin >> s;
		if (s=="A")
		{
			void *request;
			
			POSS_VATGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned short A,B,C,D,E,F,G;
				POSG_VATGet(request,&A,&B,&C,&D,&E,&F,&G);
				cout << "A: " << A << " B: " << B << " C: " << C << " D: " << D <<  " E: " << E <<   " F: " << F <<   " G: " << G << endl;
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="B")
		{
			void *request;
			
			POSS_SaleRecGet(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				//
				cout << "Pozycji paragonowych: " << POS_SalesQueueLength(hLocalDevice) << endl;
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="C")
		{
			void *request;
			unsigned char c;
			POSS_SaleSizeGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				char buffer[64];
				POSG_SaleSizeGet(request,&c);
				cout << "SaleSize: " << itoa(c,buffer,10) << endl;
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="D")
		{
			void *request;
			
			string s;
			cout << "Podaj nazwę : ";
			cin >> s;
			POSS_DiscntGetByName(hLocalDevice,&request,(const char*)s.c_str());
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_DiscntGetByName(request,&num);
					cout << "Numer: " << num << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="E")
		{
			void *request;
			
			char buf[64];
			POSS_GroupRead(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num,num1;
					POSG_GroupRead(request,&num,buf,&num1);
					cout << "Numer: " << num << " Nazwa: " << buf << " Nastepny: " << num1 << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="F")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_GroupNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_GroupNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="G")
		{
			void *request;
			
			string s;
			cout << "Podaj nazwę : ";
			cin >> s;
			POSS_GroupGetByName(hLocalDevice,&request,(const char*)s.c_str());
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_GroupGetByName(request,&num);
					cout << "Numer: " << num << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="H")
		{
			void *request;
			POSS_GroupStatClearAll(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="I")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_GroupStatRead(hLocalDevice,&request,(unsigned short)s,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					char og[48],day[256],mon[256];
					POSG_GroupStatRead(request,&num,og,day,mon);
					cout << "Numer: " << num << " Ogolnie: " << og << " Dziennie: " << day << " Miesiecznie: " << mon <<endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="J")
		{
			void *request;
			
			string s;
			cout << "Podaj nazwę : ";
			cin >> s;
			POSS_PLUGetByName(hLocalDevice,&request,(const char*)s.c_str());
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_PLUGetByName(request,&num);
					cout << "Numer: " << num << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="K")
		{
			void *request;
			
			string s;
			cout << "Podaj nazwę : ";
			cin >> s;
			POSS_PLUGetByBarcode(hLocalDevice,&request,(const char*)s.c_str());
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_PLUGetByBarcode(request,&num);
					cout << "Numer: " << num << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="L")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PLUStatRead(hLocalDevice,&request,(unsigned short)s,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					char og[48],day[48],mon[48],data[48];
					POSG_PLUStatRead(request,&num,og,day,mon,data);
					cout << "Numer: " << num << " Wartosc: " << og << " Ilosc: " << day << " Stan: " << mon << " Ostatnio:" << data <<endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="M")
		{
			void *request;
			POSS_PLUStatClearAll(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="N")
		{
			void *request;
			POSS_PLUNotepadDelAll(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="O")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PLUNotepadDel(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="P")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PLUNotepadIns(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="R")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PLUNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_PLUNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="S")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_DiscntNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_DiscntNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="T")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_AutoDiscntNextFreeGet(hLocalDevice,&request,(unsigned char)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_AutoDiscntNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="U")
		{
			void *request;
			
			POSS_DiscntStatClearAll(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="V")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PayformNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_PayformNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="W")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_CodeFmtNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_CodeFmtNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="X")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_HotkeyNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_HotkeyNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="Y")
		{
			void *request;

			int numer,typ,flagi,n,nn;

			cout << "Numer: "; cin  >> numer ; cin.ignore(65535,cin.widen('\n'));
			string nazwa,skrot,kurs;
			cout << "Nazwa: " ;getline(cin,nazwa);
			cout << "Typ: "; cin  >> typ ; cin.ignore(65535,cin.widen('\n'));
			cout << "Flagi: "; cin  >> flagi ; cin.ignore(65535,cin.widen('\n'));
			cout << "Skrot: " ;getline(cin,skrot);
			cout << "kurs (4 zn dzies): " ;getline(cin,kurs);
			cout << "Nadpisac: "; cin  >> n ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nadpisac niezerowe: "; cin  >> nn ; cin.ignore(65535,cin.widen('\n'));

			POSS_PayformIns(hLocalDevice,&request,(unsigned short)numer,(const char*)nazwa.c_str(),(unsigned char)typ,(unsigned short)flagi,(const char*)skrot.c_str(),(const char*)kurs.c_str(),(unsigned char)n,(unsigned char)nn);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		
		if (s=="Q" || s=="q") return;
	} while(1);
}

void doLevel1B(POSNET_HANDLE hLocalDevice)
{
	do {
		cout << " TESTY - RAPORTY " << endl;
		cout << " A - VAT                    " << " B - Kasjerów " << endl;
		cout << " C - Fiskalny miesieczny    " << " D - Kasy" << endl;
		cout << " E - Serwisowy              " << " F - Komunikacji " << endl;
		cout << " G - Konfig. we/wy          " << " H - Braków mag. opakowań" << endl;
		cout << " I - Braków mag. towarów    " << " J - Konfiguracji sprzedaży " << endl;
		cout << " K - Konfig. sprzętu        " << " L - Fiskalny (01-31)-10-2005" << endl;
		cout << " M - Fiskalny za numery 4-5 " << " N - Fiskalny dobowy na 2005-11-01 " << endl;
		cout << " O - Fiskalny dobowy        " << " P - Nieaktywne PLU na 2005-11-01 " << endl;
		cout << " R - PLU wg Rekordów        " << " S - Jednostki wg Rekordów " << endl;
		cout << " T - Klawisze szybkie       " << " U - Zestawy raportów " << endl;
		cout << " V - Opakowan               " << " W - Formaty kodów kresk. " << endl;
		cout << " X - Rabatów                " << " Y - Form płatnosci " << endl;
		cout << " Z - Grup towarowych        " << " 0 - Rabatów czasowych " << endl;
		cout << " 1 - Stat. grup w rozb.     " << " 2 - PLU by VAT (A) " << endl;
		cout << " 3 - PLU by Group (1)       " << " 4 - PLU by Range(1-100) " << endl;
		cout << " 5 - PLU By NAME (A-Z) " << endl;


		cout << " Q - Koniec " << endl;
		string s;
		cin >> s;
		if (s=="A")
		{
			void *request;
			
			POSS_RepPTU(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="B")
		{
			void *request;
			
			POSS_RepUser(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="C")
		{
			void *request;
			POSS_RepFskMonthly(hLocalDevice,&request,"2005-10-01",1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="D")
		{
			void *request;
			POSS_RepCashReg(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="E")
		{
			void *request;
			POSS_RepService(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="F")
		{
			void *request;
			POSS_RepComm(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="G")
		{
			void *request;
			POSS_RepCfgComm(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="H")
		{
			void *request;
			POSS_RepStorePack(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="I")
		{
			void *request;
			POSS_RepStorePLU(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="J")
		{
			void *request;
			POSS_RepCfgSale(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="K")
		{
			void *request;
			POSS_RepCfgHardware(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="L")
		{
			void *request;
			POSS_RepFskPeriodByDate(hLocalDevice,&request,"2005-10-01","2005-10-31",1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="M")
		{
			void *request;
			POSS_RepFskPeriodByNum(hLocalDevice,&request,4,5,1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="N")
		{
			void *request;
			POSS_RepFskDaily(hLocalDevice,&request,1,"2005-11-01 14:44");
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="O")
		{
			void *request;
			POSS_RepFskDaily(hLocalDevice,&request,0,NULL);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="P")
		{
			void *request;
			POSS_RepInactivePLU(hLocalDevice,&request,"2005-11-01");
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="R")
		{
			void *request;
			POSS_RepPLUByRecNo(hLocalDevice,&request,1,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="S")
		{
			void *request;
			POSS_RepMU(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="T")
		{
			void *request;
			POSS_RepHotkey(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="U")
		{
			void *request;
			POSS_RepRepSet(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="V")
		{
			void *request;
			POSS_RepPack(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="W")
		{
			void *request;
			POSS_RepCodeFmt(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="X")
		{
			void *request;
			POSS_RepDiscnt(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="Y")
		{
			void *request;
			POSS_RepPayForm(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="Z")
		{
			void *request;
			POSS_RepGroup(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="0")
		{
			void *request;
			POSS_RepAutoDiscnt(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="1")
		{
			void *request;
			POSS_RepGroupStat(hLocalDevice,&request,0,1,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="2")
		{
			void *request;
			POSS_RepPLUByVAT(hLocalDevice,&request,0,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="3")
		{
			void *request;
			POSS_RepPLUByGroup(hLocalDevice,&request,0,0,0,1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="4")
		{
			void *request;
			POSS_RepPLUByRecNo(hLocalDevice,&request,0,0,0,1,100);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="5")
		{
			void *request;
			POSS_RepPLUByNameRange(hLocalDevice,&request,0,0,0,"A","Z");
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}



		if (s=="Q" || s=="q") return;
	} while(1);
}


void doLevel1D(POSNET_HANDLE hLocalDevice)
{
	do {
		cout << " TESTY - COMPLETE " << endl;
		cout << " A - Test0 Kolejka STD      " << " B - Test1 ErrorAnswer " << endl;
		cout << " C -                        " << " D - " << endl;

		cout << " Q - Koniec " << endl;
		string s;
		cin >> s;
		if (s=="A")
		{
			void *request;
			for (int i=0;i< 10;i++)			
			{
				//POSS_PLUNextFreeGet(hLocalDevice,&request,0,POSNET_REQMODE_AUTOCLEAR);
				POSS_TimeGet(hLocalDevice,&request,POSNET_REQMODE_SPOOL);
				cout << "Sent TOKEN: " << POS_GetRequestCommandSerial(request) << endl;
				//Sleep(100);
			}
			Sleep(500);
			for (int i=0;i< 10;i++)
			{
				if (request=POS_GetNextResponse(hLocalDevice))
				{
					cout << "Answer to: " << POS_GetRequestCommandSerial(request) << endl;
				}
				else
				{
					cout << " No answer waiting ...." << endl;
					Sleep(100);
				}

			}
		}
		if (s=="B")
		{
			void *request;
			POSS_RepMU(hLocalDevice,&request,0);
			POSS_FooterGet(hLocalDevice,&request);
			Sleep(500);
			for (int i=0;i< 10;i++)
			{
				if (request=POS_GetNextResponse(hLocalDevice))
				{
					cout << "Answer to: " << POS_GetRequestCommandSerial(request) << endl;
				}
				else
				{
					cout << " No answer waiting ...." << hex << POS_GetError(hLocalDevice) << dec << endl;

					Sleep(100);
				}

			}
		}

		if (s=="Q" || s=="q") return;
	} while(1);
}


int main(int argc, char *argv[])
{
	void *hDevice=NULL;
	
	if (POS_GetErrorString(1034,"en"))
		cout << "EN: " << POS_GetErrorString(1034,"en") << endl;
	if (POS_GetErrorString(1034,"pl"))
		cout << "PL: " << POS_GetErrorString(1034,"pl") << endl;
	/*
	hDevice=POS_CreateDeviceHandle(POSNET_INTERFACE_USB);
	char buffer[1024];
	POS_GetDeviceParam(hDevice,POSNET_DEV_PARAM_LISTUSBSERIALS,buffer);

	cout << "Devices: " << buffer << endl;

	POS_SetDeviceParam(hDevice,POSNET_DEV_PARAM_USBSERIAL,buffer);
	*/
	hDevice=POS_CreateDeviceHandle(POSNET_INTERFACE_RS232);
	POS_SetDebugLevel(hDevice,POSNET_DEBUG_ALL & 0xFFFFFFFE);
	POS_SetDeviceParam(hDevice,POSNET_DEV_PARAM_COMSETTINGS,"COM1,9600,8,N,1,H");
	//POS_SetDeviceParam(hDevice,POSNET_DEV_PARAM_IP,"10.33.44.6");
	
	void *hLocalDevice=POS_OpenDevice(hDevice);
	POS_SetEventHandlingMode(hLocalDevice,POSNET_EVENT_POLLING);
	while (1)
	{
		string s=menuLevel0();
		if (s=="") break;
		
		if (s=="A")
		{
			doLevel1A((POSNET_HANDLE)hLocalDevice);
		}
		if (s=="B")
		{
			doLevel1B((POSNET_HANDLE)hLocalDevice);
		}
		if (s=="C")
		{
			doLevel1C((POSNET_HANDLE)hLocalDevice);
		}
		if (s=="D")
		{
			doLevel1D((POSNET_HANDLE)hLocalDevice);
		}


	}


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