APservice/win12_BL.cpp

480 lines
12 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_left->addWidget(lab7);
but9 = new QPushButton("Starting \nBootloader");
myVlayer_left->addWidget(but9);
connect(but9, SIGNAL(clicked()), this, SLOT(slot_b9()));
but9->setStyleSheet(BUTTONCOLOR0);
but9->setFont(myTabFont);
QLabel *lab3 = new QLabel(" ");
lab3->setFont(myTabFont);
myH0layer->addWidget(lab3);
but4 = new QPushButton("load Bin-File");
myVlayer_left->addWidget(but4);
connect(but4, SIGNAL(clicked()), this, SLOT(slot_b4()));
but4->setStyleSheet(BUTTONCOLOR0);
but4->setFont(myTabFont);
QLabel *lab4 = new QLabel(" ");
lab4->setFont(myTabFont);
myH0layer->addWidget(lab4);
but5 = new QPushButton(" send file to DC");
myVlayer_left->addWidget(but5);
connect(but5, SIGNAL(clicked()), this, SLOT(slot_b5()));
but5->setStyleSheet(BUTTONCOLOR0);
but5->setFont(myTabFont);
QLabel *lab5 = new QLabel(" ");
lab5->setFont(myTabFont);
myH0layer->addWidget(lab5);
/*
but6 = new QPushButton(" ");
myVlayer_left->addWidget(but6);
connect(but6, SIGNAL(clicked()), this, SLOT(slot_b6()));
but6->setStyleSheet(BUTTONCOLOR0);
but6->setFont(myTabFont);
but7 = new QPushButton(" ");
myVlayer_left->addWidget(but7);
connect(but7, SIGNAL(clicked()), this, SLOT(slot_b7()));
but7->setStyleSheet(BUTTONCOLOR0);
but7->setFont(myTabFont);
but8 = new QPushButton(" ");
myVlayer_left->addWidget(but8);
connect(but8, SIGNAL(clicked()), this, SLOT(slot_b8()));
but8->setStyleSheet(BUTTONCOLOR0);
but8->setFont(myTabFont);
*/
/*
but9 = new QPushButton("complete start");
myVlayer_left->addWidget(but9);
connect(but9, SIGNAL(clicked()), this, SLOT(slot_b9()));
but9->setStyleSheet(BUTTONCOLOR0);
but9->setFont(myTabFont);
*/
myTabFont.setPixelSize(14);
but1 = new QPushButton("restart DC: ");
myVlayer_left->addWidget(but1);
connect(but1, SIGNAL(clicked()), this, SLOT(slot_b1()));
but1->setStyleSheet(BUTTONCOLOR0);
but1->setFont(myTabFont);
but2 = new QPushButton("Start BL: ");
myVlayer_left->addWidget(but2);
connect(but2, SIGNAL(clicked()), this, SLOT(slot_b2()));
but2->setStyleSheet(BUTTONCOLOR0);
but2->setFont(myTabFont);
but3 = new QPushButton("check BL: ");
myVlayer_left->addWidget(but3);
connect(but3, SIGNAL(clicked()), this, SLOT(slot_b3()));
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_left->addWidget(but10);
connect(but10, SIGNAL(clicked()), this, SLOT(slot_b10()));
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=0;
win12_nrOfFWblocks=0;
win12_currentBlkNr=0;
}
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_b1(void)
{
showProgress->append(" rebooting");
HWaccess->dc_autoRequest(false);
HWaccess->bl_rebootDC();
}
void T_win12::slot_b2(void)
{
HWaccess->dc_autoRequest(false);
HWaccess->bl_startBL();
}
void T_win12::slot_b3(void)
{
HWaccess->dc_autoRequest(false);
showState->setText(" ");
HWaccess->bl_checkBL();
myTO->stop();
myTO->start(200);
myStep=20;
}
void T_win12::slot_b4(void)
{
QString myStr;
QString fileName;
win12_nrOfFWblocks=0;
fileName.clear();
fileName = QFileDialog::getOpenFileName(this, ("Select DC firmware file:"),
"C:/own/work2023/PSA1256ptu5/PTU SW",
("binary file(*.bin)"));
//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_b5(void)
{
win12_startProgramming=true;
myStep=5;
}
void T_win12::slot_b6(void)
{
}
void T_win12::slot_b7(void)
{
}
void T_win12::slot_b8(void)
{
}
void T_win12::slot_b9(void)
{
showState->setText(" Bootloader is off ");
showFile->setText(" ");
//trigger_BLstartup=true;
//myStep=0;
// neu, 29.9: Start-Schrittkette jetzt in HWapi:
HWaccess->bl_completeStart();
}
void T_win12::slot_b10(void)
{
showState->setText(" Bootloader is off ");
showFile->setText(" ");
HWaccess->bl_stopBL();
HWaccess->dc_autoRequest(true);
}
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())
showState->setText(" Bootloader is running");
/*
if (myStep==0)
{
if (trigger_BLstartup)
{
HWaccess->dc_autoRequest(false);
myStep++;
}
} else
if (myStep==1)
{
//qDebug()<<"win12 chain step 1";
if (trigger_BLstartup)
{
//qDebug()<<"starting up BL step1";
trigger_BLstartup=false;
HWaccess->bl_rebootDC();
myTO->stop();
myTO->start(1000); // restart
retryCtr=0;
myStep++;
//qDebug()<<"win12 chain step 2";
}
} else
if (myStep==2)
{
if (!myTO->isActive())
{
qDebug()<<"starting BL";
HWaccess->bl_startBL();
myTO->stop();
myTO->start(100);
myStep++;
//qDebug()<<"win12 chain step 3";
}
} else
if (myStep==3)
{
if (!myTO->isActive())
{
HWaccess->bl_checkBL();
myTO->stop();
myTO->start(100);
myStep++;
//qDebug()<<"win12 chain step 4";
}
} else
if (myStep==4)
{
if (!myTO->isActive())
{
//qDebug()<<"starting up BL step4";
myTO->stop();
if (HWaccess->bl_isUp())
{
myStep++;
//qDebug()<<"win12 chain step 5";
showState->setText(" --- BL is up and running ---");
//qDebug()<<"BL laeuft!!!";
} else
{
retryCtr++; // start again
if (retryCtr>=15)
{
myStep=99;
//qDebug()<<"win12 chain step 99";
showState->setText(" --- BL error! ---");
//qDebug()<<"BL error!!!";
} else
{
myStep=3;
//qDebug()<<"BL retry...";
//qDebug()<<"win12 chain step 3";
}
}
}
} else
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)
{
//qDebug()<<"starting transfer";
HWaccess->bl_blockAutoLoad(win12_currentBlkNr);
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;
}