
#ifndef SENDWRCMDS_DEFS_H
#define SENDWRCMDS_DEFS_H

#include <stdint.h>
#include "tslib.h"
#include <QString>

// asynch. Commands
// store OUTPUT commands until time to send
// problem: OUT commands are set if a button is pressed or a transaction event happens
// so it's never synchron with sending grid
// but sending must apply the 100ms time grid as we have to wait for the response before sending the next command!!!

// Level 0 (DC direct)
#define SENDDIRCMD_TestSerial           1
#define SENDDIRCMD_MakeReset            2
#define SENDDIRCMD_setTime              3
#define SENDDIRCMD_setWakeFrequ         4

// Level 1 (DC DO's switching connected parts)
#define SENDDIRCMD_MOVEUP_LOCK            5
#define SENDDIRCMD_MOVEDN_LOCK            6
#define SENDDIRCMD_OPENUP_DOOR            7
#define SENDDIRCMD_OPENDN_DOOR            8
#define SENDDIRCMD_LEDILLU              9
#define SENDDIRCMD_LEDCOIN              10
#define SENDDIRCMD_LEDTICKET            11
#define SENDDIRCMD_LEDPAD               12
#define SENDDIRCMD_LEDSTART             13
#define SENDDIRCMD_LEDINSIDE            14
//#define SENDDIRCMD_LED_ALL              15
#define SENDDIRCMD_FAN                  16
#define SENDDIRCMD_LAERM                17
#define SENDDIRCMD_REL1                 18
#define SENDDIRCMD_WAKEPTU              20
#define SENDDIRCMD_AUXPWR               21
#define SENDDIRCMD_AUXDDR               22
#define SENDDIRCMD_AUXOUT               23

#define SENDDIRCMD_UCONTACT_ON          30
#define SENDDIRCMD_PRN2_SWONOFF         31

#define SENDDIRCMD_MIF_SWONOFF          32      // 0x2900
#define SENDDIRCMD_MIF_ATBCREATE        33      // 0x2907

#define SENDDIRCMD_MOD_SWONOFF          40
#define SENDDIRCMD_MOD_WAKE             41
#define SENDDIRCMD_MDB_POWER            42
#define SENDDIRCMD_MDB_WAKE             43
#define SENDDIRCMD_CRED_ON              44
#define SENDDIRCMD_CRED_WAKE            45

#define SENDDIRCMD_SHUT_MOV             50
#define SENDDIRCMD_ESCRO_MOV            51
#define SENDDIR_OPENVAULT               52
#define SENDDIR_REJMOT_ON               53
#define SENDDIR_REJMOT_RUN              54

// Level 2 (serial from DC to devices)
#define SEND_REQU_SERCONF               100
#define SEND_REQU_HWversion             101
#define SEND_REQU_SWversion             102
#define SEND_REQU_CONDITION             103
#define SEND_REQU_UID                   104
#define SEND_REQU_TIME                  105
    // includes wake frequency
#define SEND_REQU_ANALOGS               110
#define SEND_REQU_DIG_INPUTS            111
#define SEND_REQU_DIG_OUTPUTS           112

#define SEND_REQU_PRN_STATE             120
#define SEND_REQU_PRN_FONTS             121
#define SEND_REQU_PRN_ALL               122

#define SEND_REQU_MIFSTATE             123
    // Type and state of reader

#define SEND_REQU_MIFDATA               124
    // Type, UID, Header of card
    // read one card sector
    // sectors must be addressed by RD_ADD

#define SEND_REQU_MIF_ATB_TYPE          125

#define SEND_REQU_MDB_GETSTAT           126
//#define SEND_REQU_MDB_GETWAK            127
#define SEND_REQU_MDB_GETRESP           128
#define SEND_REQU_EMP_GETALL            129
#define SEND_REQU_EMP_GETCOIN           130


#define SENDDIRCMD_DEVICE_PARA          131
#define SENDDIRCMD_MACHINE_ID           132
#define SEND_REQU_DEVICE_PARA           133
#define SEND_REQU_MACINE_ID             134


// further: mdb state, coinchecker state, bill state, modem state, credit_state....

#define SENDDIRCMD_SHUTOPENBYTIME       60
#define SENDDIRCMD_SHUTOPENBYCOIN       61
//#define SENDDIRCMD_SHUT_SENDTIME        62

#define SENDDIRCMD_ESCRO_TAKE           63
#define SENDDIRCMD_ESCRO_GIVE           64

#define SENDDIRCMD_PRN_SYS_CMD          70
#define SENDDIRCMD_PRN_ESC_CMD          71
#define SENDDIRCMD_PRN_SETUP            72
#define SENDDIRCMD_PRN_MOVE             73
#define SENDDIRCMD_PRN_SETFONT          74
#define SENDDIRCMD_PRN_SETLETT          75
#define SENDDIRCMD_PRN_CUT              76
//#define SENDDIRCMD_PRN_TXT              // not needed
#define SENDDIRCMD_PRN_LF               78
#define SENDDIRCMD_PRN_FONTTAB          79
#define SENDDIRCMD_PRN_BC               80
#define SENDDIRCMD_PRN_QR               81
#define SENDDIRCMD_PRN_STOREDQR         82
#define SENDDIRCMD_PRN_LOGO_FL          83
//#define SENDDIRCMD_PRN_LOGO_GRAF        84
//#define SENDDIRCMD_PRN_LOGODAT          85
//#define SENDDIRCMD_PRN_STORBC           86
#define SENDDIRCMD_PRN_STORQR           87
#define SENDDIRCMD_PRN_DOC              88
#define SENDDIRCMD_PRN_CLEARDOC         89

//#define SENDDIRCMD_MDB_POWER            42
//#define SENDDIRCMD_MDB_WAKE             43
#define SENDDIRCMD_MDB_RES              90
#define SENDDIRCMD_MDB_SENDCMD          91
#define SENDDIRCMD_MDB_SNDMSG           92
#define SENDDIRCMD_EMP_SETT             93
#define SENDDIRCMD_EMP_POLL             94
#define SENDDIRCMD_EMP_STARPPAY         95
#define SENDDIRCMD_EMP_STOPPAY          96




// obsolete:
#define SENDDIRCMD_PRN1_SENDTEXT        54
#define SENDDIRCMD_PRN1_SENDCMD         55
#define SENDDIRCMD_PRN1_SERPAR          56
#define SENDDIRCMD_PRN_LEVEL2_4B        58
#define SENDDIRCMD_PRN_LEVEL2_64        59


// highest priority
#define CMDSTACKDEPTH   16
// means: up to 16 cmd can be stored. They are issued one by one every 100ms
void sendWRcmd_clrCmdStack(void);
bool sendWRcmd_setSendCommand0(uint16_t nextCmd);
    // GUI or app sends a command to DC transfered by serial

uint16_t sendWRcmd_getSendCommand0(void);

// lower priority
#define CMD4STACKDEPTH   8
void sendWRcmd_clrCmd4Stack(void);
bool sendWRcmd_setSendCommand4(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint8_t dat3, uint8_t dat4);
uint16_t sendWRcmd_getSendCommand4(uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4);

#define CMD8STACKDEPTH   4
void sendWRcmd_clrCmd8Stack(void);
bool sendWRcmd_setSendCommand8(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint16_t dat3, uint32_t dat4);
uint16_t sendWRcmd_getSendCommand8(uint8_t *dat1, uint8_t *dat2, uint16_t *dat3, uint32_t *dat4);



// lowest priority
// wait for resonse before send next!
bool sendWRcmd_setSendBlock160(uint8_t leng, uint8_t *buf);
uint8_t sendWRcmd_getSendBlock160(uint8_t *leng, uint8_t *buf);
    // retval = *leng

void sendWRcmd_INI(void);



uint8_t epi_store64ByteSendData(uint8_t length, uint8_t *buf);
    // HWapi writes data to be forwarded to DC and further to mdb-device
    // not batched! don't use twice within 100ms

uint8_t gpi_restore64ByteSendData(uint8_t *length, uint8_t *buf);
    // datif reads data to forward to dc



// ONE printer doc consists of 20 x 64 byte
#define MAXNROF_PRNBYTES   64
#define MAXNROF_PRNBLOCKS  20

void epi_resetPrinterStack(void);

uint8_t epi_storePrnText(char *buf, uint8_t leng);
    // store text and binary data from Gui in next higher free memory 0....9

uint8_t gpi_restorePrnText(uint8_t *retbuf);
    // read printer text and send to slave, size of retbuf== 64

uint8_t gpi_chk4remainingText(void);
    // retval: 0: no more textline left (to send)  >0: nr of lines

void epi_storeUserOfSendingTextBuffer(uint8_t user, uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4 );
    // user=1: Text-Print is using this buffer
    //      2: QR-code-Printer is using this buffer

uint8_t gpi_getUserOfSendingTextBuffer(uint8_t *para1, uint8_t *para2, uint8_t *para3, uint8_t *para4);
    // user=1: Text-Print is using this buffer
    //      2: QR-code-Printer is using this buffer

#define     FDCMD_STACKDEPTH    16
void sendFDcmd_clrStack(void);
bool sendFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t dat1, uint8_t dat2, uint8_t dat3, uint8_t dat4);
    // write Command to memory, wait for transport
bool sendFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4);

uint8_t check4FDshortCmd(void);
    // returns number of waiting command, maxFDCMD_STACKDEPTH

uint8_t check4freeFDshortCmd(void);
    // returns number of free places in short-command stack

#define     FDLONG_STACKDEPTH    16
void longFDcmd_clrStack(void);
bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t length, uint8_t *data);
    // write Command to memory, wait for transport
    // data buffer size always 64! data[64], padded with 0
bool longFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *length, uint8_t *data);

uint8_t check4FDlongCmd(void);
    // returns number of waiting command

uint8_t check4freeFDlongCmd(void);
    // returns number of free places in long-command stack



uint8_t epi_store64BdevParameter(uint8_t length, uint8_t *buf);
    // HWapi writes data to be stored

uint8_t epi_restore64BdevParameter(uint8_t *length, uint8_t *buf);



#endif


