2023-11-14 09:32:56 +01:00
|
|
|
#include "win12_BL.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define BUTTONCOLOR0 "background-color: white"
|
|
|
|
#define BUTTONCOLORWAIT "background-color: yellow"
|
|
|
|
#define BUTTONCOLORGOT "background-color: green"
|
|
|
|
#define BUTTONCOLORBAD "background-color: red"
|
|
|
|
#define BUTTONCOLORGOOD "background-color: green"
|
|
|
|
|
|
|
|
static bool win12_startProgramming;
|
|
|
|
static uint16_t win12_nrOfFWblocks, win12_currentBlkNr;
|
|
|
|
|
|
|
|
|
|
|
|
T_win12::T_win12(hwinf *HWaccess, QWidget *parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
this->HWaccess = HWaccess;
|
|
|
|
|
|
|
|
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("program DC-firmware"));
|
|
|
|
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: controls
|
|
|
|
QLabel *lab7 = new QLabel(" ");
|
|
|
|
lab7->setFont(myTabFont);
|
2024-11-08 12:57:26 +01:00
|
|
|
myVlayer_right->addWidget(lab7);
|
2023-11-14 09:32:56 +01:00
|
|
|
|
|
|
|
but9 = new QPushButton("Starting \nBootloader");
|
2024-11-08 12:57:26 +01:00
|
|
|
myVlayer_right->addWidget(but9);
|
|
|
|
connect(but9, SIGNAL(clicked()), this, SLOT(slot_startCompleteBL()));
|
2023-11-14 09:32:56 +01:00
|
|
|
but9->setStyleSheet(BUTTONCOLOR0);
|
|
|
|
but9->setFont(myTabFont);
|
|
|
|
|
|
|
|
QLabel *lab3 = new QLabel(" ");
|
|
|
|
lab3->setFont(myTabFont);
|
|
|
|
myH0layer->addWidget(lab3);
|
|
|
|
|
|
|
|
but4 = new QPushButton("load Bin-File");
|
2024-11-08 12:57:26 +01:00
|
|
|
myVlayer_right->addWidget(but4);
|
|
|
|
connect(but4, SIGNAL(clicked()), this, SLOT(slot_loadBin()));
|
2023-11-14 09:32:56 +01:00
|
|
|
but4->setStyleSheet(BUTTONCOLOR0);
|
|
|
|
but4->setFont(myTabFont);
|
|
|
|
|
|
|
|
QLabel *lab4 = new QLabel(" ");
|
|
|
|
lab4->setFont(myTabFont);
|
|
|
|
myH0layer->addWidget(lab4);
|
|
|
|
|
|
|
|
but5 = new QPushButton(" send file to DC");
|
2024-11-08 12:57:26 +01:00
|
|
|
myVlayer_right->addWidget(but5);
|
|
|
|
connect(but5, SIGNAL(clicked()), this, SLOT(slot_sendBin()));
|
2023-11-14 09:32:56 +01:00
|
|
|
but5->setStyleSheet(BUTTONCOLOR0);
|
|
|
|
but5->setFont(myTabFont);
|
|
|
|
|
|
|
|
QLabel *lab5 = new QLabel(" ");
|
|
|
|
lab5->setFont(myTabFont);
|
|
|
|
myH0layer->addWidget(lab5);
|
|
|
|
|
|
|
|
myTabFont.setPixelSize(14);
|
2024-11-08 12:57:26 +01:00
|
|
|
but1 = new QPushButton("restart DC: \n");
|
|
|
|
myVlayer_right->addWidget(but1);
|
|
|
|
connect(but1, SIGNAL(clicked()), this, SLOT(slot_restart()));
|
2023-11-14 09:32:56 +01:00
|
|
|
but1->setStyleSheet(BUTTONCOLOR0);
|
|
|
|
but1->setFont(myTabFont);
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
but2 = new QPushButton("Start BL: \n");
|
|
|
|
myVlayer_right->addWidget(but2);
|
|
|
|
connect(but2, SIGNAL(clicked()), this, SLOT(slot_startBl()));
|
2023-11-14 09:32:56 +01:00
|
|
|
but2->setStyleSheet(BUTTONCOLOR0);
|
|
|
|
but2->setFont(myTabFont);
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
but3 = new QPushButton("check BL: \n");
|
|
|
|
myVlayer_right->addWidget(but3);
|
|
|
|
connect(but3, SIGNAL(clicked()), this, SLOT(slot_checkBl()));
|
2023-11-14 09:32:56 +01:00
|
|
|
but3->setStyleSheet(BUTTONCOLOR0);
|
|
|
|
but3->setFont(myTabFont);
|
|
|
|
|
|
|
|
QLabel *lab6 = new QLabel(" ");
|
|
|
|
lab6->setFont(myTabFont);
|
|
|
|
myH0layer->addWidget(lab6);
|
|
|
|
|
|
|
|
myTabFont.setPixelSize(22);
|
|
|
|
but10 = new QPushButton("stop BL: ");
|
2024-11-08 12:57:26 +01:00
|
|
|
myVlayer_right->addWidget(but10);
|
|
|
|
connect(but10, SIGNAL(clicked()), this, SLOT(slot_stopBL()));
|
2023-11-14 09:32:56 +01:00
|
|
|
but10->setStyleSheet(BUTTONCOLOR0);
|
|
|
|
but10->setFont(myTabFont);
|
|
|
|
|
|
|
|
// Mitte: anzeigen
|
|
|
|
showState =new QLabel("BL is off");
|
|
|
|
showState->setFont(myTabFont);
|
|
|
|
myVlayer_midd->addWidget(showState);
|
|
|
|
|
|
|
|
myTabFont.setPixelSize(14);
|
|
|
|
showFile =new QLabel(" --- no file loaded ---");
|
|
|
|
showFile->setFont(myTabFont);
|
|
|
|
myVlayer_midd->addWidget(showFile);
|
|
|
|
|
|
|
|
showProgress = new QTextEdit();
|
|
|
|
myVlayer_midd->addWidget(showProgress);
|
|
|
|
myTabFont.setPixelSize(14);
|
|
|
|
showProgress->setFont(myTabFont);
|
|
|
|
showProgress->setStyleSheet("background-color: white");
|
|
|
|
showProgress->append(" ");
|
|
|
|
|
|
|
|
setLayout(myVmainlayer);
|
|
|
|
|
|
|
|
myTO = new QTimer();
|
|
|
|
myTO->setSingleShot(true);
|
|
|
|
myTO->start(2);
|
|
|
|
trigger_BLstartup=false;
|
2024-11-08 12:57:26 +01:00
|
|
|
win12_startProgramming=false;
|
2023-11-14 09:32:56 +01:00
|
|
|
win12_nrOfFWblocks=0;
|
|
|
|
win12_currentBlkNr=0;
|
2024-11-08 12:57:26 +01:00
|
|
|
APservBLisUp=false;
|
2023-11-14 09:32:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
T_win12::~T_win12()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_win12::Nav_back(void)
|
|
|
|
{
|
|
|
|
myNextStep=WCS_WIN12BAK;
|
|
|
|
}
|
|
|
|
void T_win12::Nav_home(void)
|
|
|
|
{
|
|
|
|
myNextStep=WCS_WIN12MID;
|
|
|
|
}
|
|
|
|
void T_win12::Nav_next(void)
|
|
|
|
{
|
|
|
|
myNextStep=WCS_WIN12FWD;
|
|
|
|
}
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
void T_win12::slot_startCompleteBL(void)
|
|
|
|
{
|
|
|
|
// replaces the next three single steps restart_DC, start_BL and check_BL
|
|
|
|
showState->setText(" starting bootloader... ");
|
|
|
|
showFile->setText(" ");
|
|
|
|
HWaccess->bl_completeStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
// single steps from former version:
|
|
|
|
void T_win12::slot_restart(void)
|
2023-11-14 09:32:56 +01:00
|
|
|
{
|
|
|
|
showProgress->append(" rebooting");
|
|
|
|
HWaccess->dc_autoRequest(false);
|
|
|
|
HWaccess->bl_rebootDC();
|
|
|
|
}
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
void T_win12::slot_startBl(void)
|
2023-11-14 09:32:56 +01:00
|
|
|
{
|
|
|
|
HWaccess->dc_autoRequest(false);
|
|
|
|
HWaccess->bl_startBL();
|
|
|
|
}
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
void T_win12::slot_checkBl(void)
|
2023-11-14 09:32:56 +01:00
|
|
|
{
|
|
|
|
HWaccess->dc_autoRequest(false);
|
|
|
|
showState->setText(" ");
|
|
|
|
HWaccess->bl_checkBL();
|
|
|
|
myTO->stop();
|
|
|
|
myTO->start(200);
|
|
|
|
myStep=20;
|
|
|
|
}
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
void T_win12::slot_loadBin(void)
|
2023-11-14 09:32:56 +01:00
|
|
|
{
|
|
|
|
QString myStr;
|
|
|
|
QString fileName;
|
|
|
|
|
|
|
|
win12_nrOfFWblocks=0;
|
|
|
|
fileName.clear();
|
2024-11-08 12:57:26 +01:00
|
|
|
|
|
|
|
// bin file im selben folder wie in PTU5: /etc/dc/
|
2023-11-14 09:32:56 +01:00
|
|
|
fileName = QFileDialog::getOpenFileName(this, ("Select DC firmware file:"),
|
2024-11-08 12:57:26 +01:00
|
|
|
"/etc/dc",
|
2023-11-14 09:32:56 +01:00
|
|
|
("binary file(*.bin)"));
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
// Jsons im selben folder wie in PTU5: /etc/psa_config
|
|
|
|
//fileName = QFileDialog::getOpenFileName(this, ("Select JSON file:"),
|
|
|
|
// "/etc/psa_config",
|
|
|
|
// ("binary file(*.json)"));
|
|
|
|
|
2023-11-14 09:32:56 +01:00
|
|
|
//qDebug()<<"T_win12: selected file: "<<fileName;
|
|
|
|
bool ret=HWaccess->bl_storeFirmware(fileName);
|
|
|
|
win12_nrOfFWblocks = HWaccess->bl_getNrOfFirmwareBlocks();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
myStr.clear();
|
|
|
|
myStr=" file ";
|
|
|
|
myStr.append(fileName);
|
|
|
|
myStr.append(" \n loaded with ");
|
|
|
|
myStr.append(swl_ulong2str(win12_nrOfFWblocks));
|
|
|
|
myStr.append(" blocks");
|
|
|
|
showFile->setText(myStr);
|
|
|
|
} else
|
|
|
|
showFile->setText(" cannot load file :-( ");
|
|
|
|
}
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
|
|
|
|
void T_win12::slot_sendBin(void)
|
2023-11-14 09:32:56 +01:00
|
|
|
{
|
|
|
|
win12_startProgramming=true;
|
2024-11-08 12:57:26 +01:00
|
|
|
showProgress->clear();
|
2023-11-14 09:32:56 +01:00
|
|
|
myStep=5;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
void T_win12::slot_stopBL(void)
|
2023-11-14 09:32:56 +01:00
|
|
|
{
|
|
|
|
showState->setText(" Bootloader is off ");
|
|
|
|
showFile->setText(" ");
|
2024-11-08 12:57:26 +01:00
|
|
|
HWaccess->bl_stopBL();
|
|
|
|
HWaccess->dc_autoRequest(true);
|
|
|
|
APservBLisUp=false;
|
2023-11-14 09:32:56 +01:00
|
|
|
}
|
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
bool T_win12::isBLup()
|
2023-11-14 09:32:56 +01:00
|
|
|
{
|
2024-11-08 12:57:26 +01:00
|
|
|
return APservBLisUp;
|
2023-11-14 09:32:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool T_win12::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_win12::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"
|
|
|
|
|
|
|
|
*nextScreen=0; // 0=no change
|
|
|
|
*useNavi=0;
|
2024-11-08 12:57:26 +01:00
|
|
|
int8_t iresult;
|
2023-11-14 09:32:56 +01:00
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
if (HWaccess->bl_isUp()==1)
|
|
|
|
APservBLisUp=true;
|
2023-11-14 09:32:56 +01:00
|
|
|
|
2024-11-08 12:57:26 +01:00
|
|
|
if (APservBLisUp)
|
|
|
|
showState->setText(" Bootloader is running");
|
|
|
|
else
|
|
|
|
showState->setText(" - - - ");
|
2023-11-14 09:32:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (myStep==5)
|
|
|
|
{
|
|
|
|
if (win12_startProgramming)
|
|
|
|
{
|
|
|
|
win12_nrOfFWblocks = HWaccess->bl_getNrOfFirmwareBlocks();
|
|
|
|
if (win12_nrOfFWblocks>10)
|
|
|
|
{
|
|
|
|
// qDebug()<<"win12 chain step 6";
|
|
|
|
myStep++;
|
|
|
|
}
|
|
|
|
win12_currentBlkNr=0;
|
|
|
|
showProgress->append("transfering file:");
|
|
|
|
win12_startProgramming=0;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (myStep==6)
|
|
|
|
{
|
2024-11-08 12:57:26 +01:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2023-11-14 09:32:56 +01:00
|
|
|
HWaccess->bl_blockAutoLoad(win12_currentBlkNr);
|
2024-11-08 12:57:26 +01:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
//if (win12_currentBlkNr%10==0) // nur jeden 10. Block anzeigen
|
|
|
|
// geht auch nicht schneller
|
|
|
|
showProgress->append(swl_int2str(win12_currentBlkNr));
|
2023-11-14 09:32:56 +01:00
|
|
|
myStep++;
|
|
|
|
//qDebug()<<"win12 chain step 6->7";
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (myStep==7)
|
|
|
|
{
|
2024-11-08 12:57:26 +01:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2023-11-14 09:32:56 +01:00
|
|
|
iresult=HWaccess->bl_blockAutoResponse();
|
|
|
|
// 0: wait 1: OK, blk was sent 2: OK, transfer complete 3: error
|
2024-11-08 12:57:26 +01:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2023-11-14 09:32:56 +01:00
|
|
|
if (iresult==1)
|
|
|
|
{
|
|
|
|
win12_currentBlkNr++;
|
|
|
|
if (win12_currentBlkNr <= win12_nrOfFWblocks)
|
|
|
|
{
|
|
|
|
myStep=6;
|
|
|
|
//qDebug()<<"win12 chain step 7->6";
|
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
showProgress->append("finished");
|
|
|
|
//qDebug()<<"win12 chain step 99";
|
|
|
|
myStep=99;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (iresult==2)
|
|
|
|
{
|
|
|
|
// fertisch
|
|
|
|
showProgress->append("finished");
|
|
|
|
myStep=99;
|
|
|
|
} else
|
|
|
|
if (iresult==3)
|
|
|
|
{
|
|
|
|
// fehler
|
|
|
|
showProgress->append("cancel due to error");
|
|
|
|
myStep=99;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (myStep==8)
|
|
|
|
{
|
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2024-11-08 12:57:26 +01:00
|
|
|
/*
|
2023-11-14 09:32:56 +01:00
|
|
|
if (myStep==20)
|
|
|
|
{
|
|
|
|
if (!myTO->isActive())
|
|
|
|
{
|
|
|
|
//qDebug()<<"win12 step0";
|
|
|
|
if (HWaccess->bl_isUp())
|
|
|
|
showState->setText(" Bootloader is running");
|
|
|
|
//else
|
|
|
|
// lab7->setText(" Bootloader is off ");
|
|
|
|
myTO->stop();
|
|
|
|
myStep=99;
|
|
|
|
}
|
|
|
|
}
|
2024-07-08 10:34:47 +02:00
|
|
|
*/
|
2023-11-14 09:32:56 +01:00
|
|
|
|
|
|
|
if (myNextStep)
|
|
|
|
{
|
|
|
|
*nextScreen=myNextStep;
|
|
|
|
myNextStep=0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|