APservice/win12_BL.cpp

383 lines
10 KiB
C++
Executable File

#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);
myVlayer_right->addWidget(lab7);
but9 = new QPushButton("Starting \nBootloader");
myVlayer_right->addWidget(but9);
connect(but9, SIGNAL(clicked()), this, SLOT(slot_startCompleteBL()));
but9->setStyleSheet(BUTTONCOLOR0);
but9->setFont(myTabFont);
QLabel *lab3 = new QLabel(" ");
lab3->setFont(myTabFont);
myH0layer->addWidget(lab3);
but4 = new QPushButton("load Bin-File");
myVlayer_right->addWidget(but4);
connect(but4, SIGNAL(clicked()), this, SLOT(slot_loadBin()));
but4->setStyleSheet(BUTTONCOLOR0);
but4->setFont(myTabFont);
QLabel *lab4 = new QLabel(" ");
lab4->setFont(myTabFont);
myH0layer->addWidget(lab4);
but5 = new QPushButton(" send file to DC");
myVlayer_right->addWidget(but5);
connect(but5, SIGNAL(clicked()), this, SLOT(slot_sendBin()));
but5->setStyleSheet(BUTTONCOLOR0);
but5->setFont(myTabFont);
QLabel *lab5 = new QLabel(" ");
lab5->setFont(myTabFont);
myH0layer->addWidget(lab5);
myTabFont.setPixelSize(14);
but1 = new QPushButton("restart DC: \n");
myVlayer_right->addWidget(but1);
connect(but1, SIGNAL(clicked()), this, SLOT(slot_restart()));
but1->setStyleSheet(BUTTONCOLOR0);
but1->setFont(myTabFont);
but2 = new QPushButton("Start BL: \n");
myVlayer_right->addWidget(but2);
connect(but2, SIGNAL(clicked()), this, SLOT(slot_startBl()));
but2->setStyleSheet(BUTTONCOLOR0);
but2->setFont(myTabFont);
but3 = new QPushButton("check BL: \n");
myVlayer_right->addWidget(but3);
connect(but3, SIGNAL(clicked()), this, SLOT(slot_checkBl()));
but3->setStyleSheet(BUTTONCOLOR0);
but3->setFont(myTabFont);
QLabel *lab6 = new QLabel(" ");
lab6->setFont(myTabFont);
myH0layer->addWidget(lab6);
myTabFont.setPixelSize(22);
but10 = new QPushButton("stop BL: ");
myVlayer_right->addWidget(but10);
connect(but10, SIGNAL(clicked()), this, SLOT(slot_stopBL()));
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;
win12_startProgramming=false;
win12_nrOfFWblocks=0;
win12_currentBlkNr=0;
APservBLisUp=false;
}
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;
}
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)
{
showProgress->append(" rebooting");
HWaccess->dc_autoRequest(false);
HWaccess->bl_rebootDC();
}
void T_win12::slot_startBl(void)
{
HWaccess->dc_autoRequest(false);
HWaccess->bl_startBL();
}
void T_win12::slot_checkBl(void)
{
HWaccess->dc_autoRequest(false);
showState->setText(" ");
HWaccess->bl_checkBL();
myTO->stop();
myTO->start(200);
myStep=20;
}
void T_win12::slot_loadBin(void)
{
QString myStr;
QString fileName;
win12_nrOfFWblocks=0;
fileName.clear();
// bin file im selben folder wie in PTU5: /etc/dc/
fileName = QFileDialog::getOpenFileName(this, ("Select DC firmware file:"),
"/etc/dc",
("binary file(*.bin)"));
// Jsons im selben folder wie in PTU5: /etc/psa_config
//fileName = QFileDialog::getOpenFileName(this, ("Select JSON file:"),
// "/etc/psa_config",
// ("binary file(*.json)"));
//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 :-( ");
}
void T_win12::slot_sendBin(void)
{
win12_startProgramming=true;
showProgress->clear();
myStep=5;
}
void T_win12::slot_stopBL(void)
{
showState->setText(" Bootloader is off ");
showFile->setText(" ");
HWaccess->bl_stopBL();
HWaccess->dc_autoRequest(true);
APservBLisUp=false;
}
bool T_win12::isBLup()
{
return APservBLisUp;
}
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;
int8_t iresult;
if (HWaccess->bl_isUp()==1)
APservBLisUp=true;
if (APservBLisUp)
showState->setText(" Bootloader is running");
else
showState->setText(" - - - ");
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)
{
// -------------------------------------------------------------------
HWaccess->bl_blockAutoLoad(win12_currentBlkNr);
// -------------------------------------------------------------------
//if (win12_currentBlkNr%10==0) // nur jeden 10. Block anzeigen
// geht auch nicht schneller
showProgress->append(swl_int2str(win12_currentBlkNr));
myStep++;
//qDebug()<<"win12 chain step 6->7";
} else
if (myStep==7)
{
// -------------------------------------------------------------------
iresult=HWaccess->bl_blockAutoResponse();
// 0: wait 1: OK, blk was sent 2: OK, transfer complete 3: error
// -------------------------------------------------------------------
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
{
}
/*
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;
}
}
*/
if (myNextStep)
{
*nextScreen=myNextStep;
myNextStep=0;
}
return false;
}