Files
Tools_CPP/devices/Validators/Validator.h
2024-11-01 12:23:13 +05:00

108 lines
6.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//---------------------------------------------------------------------------
#ifndef ValidatorH
#define ValidatorH
//---------------------------------------------------------------------------
#include "../ComPort.h"
#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>
#include "structs.h"
//#include "ValidatorThread.h"
//---------------------------------------------------------------------------
//Ñïèñîê êîìàíä âàëèäàòîðó
#define fcRESET 0x30;// Command for Bill - to - Bill unit to self - reset ALL
#define fcGET_STATUS 0x31;// Request for Bill - to - Bill unit set - up status IDLING, DISABLED
#define fcSET_SECURITY 0x32;//Sets Bill - to - Bill unit Security Mode. Command is followed by set - up data.See command format INITIALIZE, DISABLED
#define fcPOLL 0x33; //Request for Bill - to - Bill unit activity Status ALL
#define fcENABLE_BILL_TYPES 0x34; //Indicates Bill Type enable or disable. Command is followed by set - up data.See command format IDLING, ACCEPTING,REJECTING, ESCROW,HOLDING, STACKING,RETURNING, DISABLED
#define fcSTACK 0x35; //Sent by Controller to stack a bill in escrow to drop cassette or to one of the recycling cassettes ESCROW, HOLDING
#define fcRETURN 0x36; //Sent by Controller to return a bill in escrow ESCROW, HOLDING
#define fcIDENTIFICATION 0x37; //Request for Model, Serial Number, Country ISO code, Asset Number POWER UP, INITIALISE, DISABLED, IDLING
#define fcHOLD 0x38; //Command for holding a bill in Escrow state ESCROW, HOLDING
#define fcSET_BARCODE_PARAMETERS 0x39; // Command for settings the barcode format and number of characters INITIALIZE, DISABLED
#define fcEXTRACT_BARCODE_DATA 0x3A; // Command for retrieving barcode data if barcode coupon is found.If this command is sent when barcode coupon is not found the Bill Validator returns ILLEGAL COMMAND response. ESCROW, PACKED, IDLING, DISABLED
#define fcRECYCLING_CASSETTE_STATUS 0x3B; // Request for Bill - to - Bill unit recycling cassette status IDLING, DISABLED, ESCROW
#define fcDISPENSE 0x3C; // Command to dispense bill(s) DISABLED
#define fcUNLOAD 0x3D; // Command to unload bills from recycling cassette(s) to drop cassette DISABLED
#define fcEXTENDED_IDENTIFICATION 0x3E; // Request for Model, Serial Number, Software Version of Bill - to - Bill unit and its subunits, Country ISO code, Asset Number DISABLED, IDLING
#define fcSET_RECYCLING_CASSETTE_TYPE 0x40; // Assigns recycling cassettes to bill type DISABLED
#define fcGET_BILL_TABLE 0x41; // Request for bill type description IDLING, DISABLED
#define fcDOWNLOAD 0x50; // Command for transition to download mode. Please refer to CCNET Document 2 for details. DISABLED, FAILURE, DROP CASSETTE REMOVED
#define fcGET_CRC32_OF_THE_CODE 0x51; // Request for Bill Validators firmware CRC32. POWER UP, INITIALIZE, DISABLED, FAILURE
#define fcMODULE_DOWNLOAD 0x52; // Command to enter an internal module update mode.Please refer to CCNET Document 2 for details. DISABLED
#define fcMODULE_IDENTIFICATION_REQUEST 0x53; // Request serial numbers of all intelligent modules DISABLED, IDLING
#define fcREQUEST_STATISTICS 0x60; // Command for retrieving full information about acceptance performance.Please refer to CCNET Document 3 for details. DISABLED
#define fcREAL_TIME_CLOCK 0x62; // Read or initialize internal Real - Time Clock.DISABLED
#define fcPOWER_RECOVERY 0x66; // Request whether there was a power cut and perform credit recovery DISABLED
#define fcEMPTY_DISPENSER 0x67; // Dispense all bills remaining in the dispenser after power cut. POWER CUT WHILE DISPENSING
#define fcSET_OPTIONS 0x68; // Set various Bill - To - Bill options INITIALIZE, DISABLED
#define fcGET_OPTIONS 0x69; // Set various Bill - To - Bill options INITIALIZE, DISABLED EXTENDED CASSETTE
#define fcSTATUS 0x70; // Extended recycling cassette status request DISABLED
//---------------------------------------------------------------------------
struct BillType
{
int val; //Íîìèíàë êóïþðû
char country[3]; //Êîä ñòðàíû
};
//---------------------------------------------------------------------------
int addZero(int val,int cnt); //Äîáàâèòü íóëè ê öèôðå
//---------------------------------------------------------------------------
class Validator
{
private:
unsigned char ReadAr[255];
protected:
//int Pay;
bool CheckOnCRC(unsigned char* lpBuffer,unsigned long nSize);
//Íèæý âñ¸ äëÿ îòäåëüíîãî ïîòîêà
bool execute_thread = false; //Ïî óìîë÷àíèþ ïîòîê íå ðàáîòàåò
pthread_t m_threadid;
static void *thread_func(void *d);
pthread_mutex_t m_mutex;
TSimpleList2<int> m_pays; //äëÿ ñáîðà âñåõ îïëàò èç ïîòîêà (â ìþòåêñå)
int m_payState; //Òåêóùåå ñîñòîÿíèå âàëèäàòîðà (â ìþòåêñå)
int getTHPay(int &state); //Âûçûâàåòñÿ â îòäåëüíîì ïîòîêå
void endPay(); //Âûçûâàåòñÿ â îòäåëüíîì ïîòîêå ïðè çàâåðøåíèè îïëàòû
public:
bool m_testmode; //Íå ãåíåðèòü îøèáîê è íå âîçâðàùÿòü ÷òî îïåðàöèÿ ïðîèçîøëà íåóäà÷íî
ComPort* cPort; //Ê êàêîìó ÊÎÌ ïîðòó ïîäêëþ÷¸í
bool bNominals; //Ïîëó÷èëè õîòü 1 ðàç íîìèíàëû êóïþï
BillType bt[24]; //Ñïèñîê íîìèíàëîâ êóïþð
std::string BatchNumber, SerialNumber; //Íîìåð ïàðòèè è ñåðèéíûé
Validator();
virtual ~Validator();
//---------------------------------------------------------------------------
bool OpenCOMPort(std::string ComNumber, int BaudRate);
bool SendCommand(std::string req, std::string &ans);
bool Start(); //ïðîèíèöèàëèçèðîâàòü âàëèäàòîð
bool Reset(); //Ïåðåçàãðóçèòü âàëèäàòîð
bool GetStatus(); //Ïîëó÷èòü ñòàòóñ âàëèäàòîðà
bool SetEnableBillTypes(bool enable); //Óñòàíîâèòü êàêèå êóïþðû ðàçðåøåíû ê ïðè¸ìó
bool getSerialNumber(); //Ïîëó÷èòü íîìåð ïàðòèè è ñåðèéíèê
bool getNominals(); //Ïîëó÷èòü íîìèíàëû ïðîøèòûõ êóïþð
bool startPay(); //Ñòàðòóåì ïîòîê îïëàòû
int getPay(); //Ïîëó÷èòü çíà÷åíèå èç íîêîïèâøåãîñÿ ñïèñêà îïëàò, çíà÷åíèå óäàëÿåòñÿ èç ñïèñêà
int getPayState(); //Ïîëó÷èòü òåêóùåå ñîñòîÿíèå ïëàòåæà 0 - êóïþðà íå ðàñïîçíà¸òñÿ 1 - Êóïþðà â äàííûé ìîìåíò ðàñïîçíà¸òñÿ
bool stopPay(); //Ñòîïèì ïîòîê îïëàòû
int GetState(); //Åñëè 0 òî âñ¸ â ïîðÿäêå
std::string GetStatusDescription(char StatusCode); //Îïèñàíèå ñòàòóñà
};
//---------------------------------------------------------------------------
extern Validator* validator;
//---------------------------------------------------------------------------
#endif