APservice/win13_json.cpp

385 lines
9.1 KiB
C++
Executable File

#include "win13_json.h"
// load Json file from HDD and send it to DC:
//virtual bool sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8_t *content ) const =0;
// kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer
// nrOfTemplate=1...32 if kindOfFile==6
// content = content of the Json file, max 800byte ascii signs
// file is 0-terminated!
// return false if sending is not possible, wait a second
static bool win13_nowPrinting;
T_win13::T_win13(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
{
this->HWaccess = HWaccess;
//myLayout = new QGridLayout;
myVmainlayer= new QVBoxLayout;
myH0layer = new QHBoxLayout;
myH1layer = new QHBoxLayout;
myVlayer_left = new QVBoxLayout;
myVlayer_midd = new QVBoxLayout;
myVlayer_right = new QVBoxLayout;
myVmainlayer->addLayout(myH0layer);
myVmainlayer->addLayout(myH1layer);
QFont myTabFont;
myTabFont.setPixelSize(22);
lab1 =new QLabel(tr("send Jsonfiles from ../smd to DC"));
lab1->setFont(myTabFont);
myH0layer->addWidget(lab1);
lab2 =new QLabel(tr(" "));
lab2->setFont(myTabFont);
myH0layer->addWidget(lab2);
myH1layer->addLayout(myVlayer_left);
myH1layer->addLayout(myVlayer_midd);
myH1layer->addLayout(myVlayer_right);
// linke Spalte: laden
/*
pB1 = new QPushButton("load settings");
myVlayer_left->addWidget(pB1);
pB1->setFont(myTabFont);
connect(pB1, SIGNAL(clicked()), this, SLOT(slot_pb1()));
pB2 = new QPushButton("load devices");
myVlayer_left->addWidget(pB2);
pB2->setFont(myTabFont);
connect(pB2, SIGNAL(clicked()), this, SLOT(slot_pb2()));
pB3 = new QPushButton("load cash");
myVlayer_left->addWidget(pB3);
pB3->setFont(myTabFont);
connect(pB3, SIGNAL(clicked()), this, SLOT(slot_pb3()));
pB4 = new QPushButton("load print32");
myVlayer_left->addWidget(pB4);
pB4->setFont(myTabFont);
connect(pB4, SIGNAL(clicked()), this, SLOT(slot_pb4()));
*/
// Mitte: anzeigen
showFile = new QTextEdit();
myVlayer_midd->addWidget(showFile);
myTabFont.setPixelSize(14);
showFile->setFont(myTabFont);
showFile->setStyleSheet("background-color: white");
showFile->append("content of the loaded file:");
showFile->append(" ");
showFile->append(" ");
myTabFont.setPixelSize(22);
// rechte Spalte:
// Laden mit Dialogbox:
pB1 = new QPushButton("L O A D");
myVlayer_right->addWidget(pB1);
pB1->setFont(myTabFont);
connect(pB1, SIGNAL(clicked()), this, SLOT(slot_pb1()));
myTabFont.setPixelSize(22);
pB5 = new QPushButton("S E N D");
myVlayer_right->addWidget(pB5);
pB5->setFont(myTabFont);
connect(pB5, SIGNAL(clicked()), this, SLOT(slot_pb5()));
// Untrscheidung nicht noetig
/*
pB6 = new QPushButton("send devices");
myVlayer_right->addWidget(pB6);
pB6->setFont(myTabFont);
connect(pB6, SIGNAL(clicked()), this, SLOT(slot_pb6()));
pB7 = new QPushButton("send cash");
myVlayer_right->addWidget(pB7);
pB7->setFont(myTabFont);
connect(pB7, SIGNAL(clicked()), this, SLOT(slot_pb7()));
pB8 = new QPushButton("send print32");
myVlayer_right->addWidget(pB8);
pB8->setFont(myTabFont);
connect(pB8, SIGNAL(clicked()), this, SLOT(slot_pb8()));
*/
// neu, 23.5.2024
pB9 = new QPushButton("print directly");
myVlayer_right->addWidget(pB9);
pB9->setFont(myTabFont);
connect(pB9, SIGNAL(clicked()), this, SLOT(slot_pb9()));
setLayout(myVmainlayer);
myNextStep=0;
myStep=0;
myTO = new QTimer();
myTO->setSingleShot(true);
myTO->start(2000);
win13_nowPrinting=false;
}
T_win13::~T_win13()
{
close();
}
void T_win13::Nav_back(void)
{
myNextStep=WCS_WIN13BAK;
}
void T_win13::Nav_home(void)
{
myNextStep=WCS_WIN13MID;
}
void T_win13::Nav_next(void)
{
myNextStep=WCS_WIN13FWD;
}
void T_win13::slot_pb1(void)
{
QString fileName;
showFile->clear();
/*
if (datei_ifFileExists(FILENAME_CONFIG))
{
loadedFile=datei_readFromFile(FILENAME_CONFIG);
showFile->append(loadedFile);
} else
{
showFile->append("file not found");
} */
fileName.clear();
fileName = QFileDialog::getOpenFileName(this, ("Select JSON file:"),
"/etc/psa_config",
("binary file(*.json)"));
loadedFile=datei_readFromFile(fileName);
showFile->append(loadedFile);
// neu, 23.5.2024
HWaccess->prn_translateLocalPrinterJson(loadedFile);
}
/*
void T_win13::slot_pb2(void)
{
showFile->clear();
if (datei_ifFileExists(FILENAME_DEVICE))
{
loadedFile=datei_readFromFile(FILENAME_DEVICE);
showFile->append(loadedFile);
} else
{
showFile->append("file not found");
}
}
void T_win13::slot_pb3(void)
{
showFile->clear();
if (datei_ifFileExists(FILENAME_CASH))
{
loadedFile=datei_readFromFile(FILENAME_CASH);
showFile->append(loadedFile);
} else
{
showFile->append("file not found");
}
}
void T_win13::slot_pb4(void)
{
showFile->clear();
if (datei_ifFileExists(FILENAME_PRINT))
{
loadedFile=datei_readFromFile(FILENAME_PRINT);
showFile->append(loadedFile);
} else
{
showFile->append("file not found");
}
}
*/
// send selected file:
void T_win13::slot_pb5(void)
{
uint8_t buf800[800];
uint16_t ii, len;
len=loadedFile.size();
memset(buf800,0,800);
for (ii=0; ii<len; ii++)
buf800[ii]=loadedFile.at(ii);
//virtual bool sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8_t *content ) const =0;
// kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer
// nrOfTemplate=1...32 if kindOfFile==6
// content = content of the Json file, max 800byte ascii signs
// file is 0-terminated!
// return false if sending is not possible, wait a second
HWaccess->sys_sendJsonFileToDc(1, 0, buf800);
}
/*
void T_win13::slot_pb6(void)
{
uint8_t buf800[800];
uint16_t ii, len;
len=loadedFile.size();
memset(buf800,0,800);
for (ii=0; ii<len; ii++)
buf800[ii]=loadedFile.at(ii);
HWaccess->sys_sendJsonFileToDc(2, 0, buf800);
}
void T_win13::slot_pb7(void)
{
uint8_t buf800[800];
uint16_t ii, len;
len=loadedFile.size();
memset(buf800,0,800);
for (ii=0; ii<len; ii++)
buf800[ii]=loadedFile.at(ii);
HWaccess->sys_sendJsonFileToDc(3, 0, buf800);
}
void T_win13::slot_pb8(void)
{
uint8_t buf800[800];
uint16_t ii, len;
len=loadedFile.size();
memset(buf800,0,800);
for (ii=0; ii<len; ii++)
buf800[ii]=loadedFile.at(ii);
HWaccess->sys_sendJsonFileToDc(4, 32, buf800);
}
*/
void T_win13::slot_pb9(void)
{
pB9->setStyleSheet("background-color: white");
HWaccess->prn_printTranslatedTicket();
win13_nowPrinting=true;
}
bool T_win13::work_ini(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called ONE time after selecting this state (initialization)
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
*nextScreen=0; // needed 0=no change
*useNavi=SWITCH_BACK_ON | SWITCH_HOME_ON | SWITCH_NEXT_ON;
myNextStep=0;
return false;
}
bool T_win13::working(uint16_t *nextScreen, uint8_t *useNavi)
{
// one state of the vending/operating FSM
// called cyclic until this state changes intentionally to another state
// display informations for human operator, react on operators inputs or wait for payment media
// useNavi=0: no change
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
uint8_t result;
*nextScreen=0; // 0=no change
*useNavi=0;
if (win13_nowPrinting)
{
result=HWaccess->prn_waitForDirectTicket();
if (result==1)
pB9->setStyleSheet("background-color: rgb(150,230,150)"); // hell grün
else
if (result>1)
pB9->setStyleSheet("background-color: rgb(250,150,150)"); // hell rot
if (result>0)
win13_nowPrinting=0;
}
if (myStep==0)
{
myTO->start(); // restart
} else
if (myStep==1)
{
if (!myTO->isActive())
{
// time out
}
} else
if (myStep==2)
{
} else
if (myStep==3)
{
} else
if (myStep==4)
{
} else
if (myStep==5)
{
} else
if (myStep==6)
{
} else
if (myStep==7)
{
} else
{
}
if (myNextStep)
{
*nextScreen=myNextStep;
myNextStep=0;
}
return false;
}