Compare commits
7 Commits
ed037b99c9
...
002d58ba7b
Author | SHA1 | Date | |
---|---|---|---|
002d58ba7b | |||
76f54cdc0c | |||
591fd89cb5 | |||
e7723f669f | |||
d0e1be11b6 | |||
f63798727f | |||
898f0a4af8 |
@ -315,6 +315,9 @@ private slots:
|
|||||||
public:
|
public:
|
||||||
T_datif(QWidget *parent = nullptr);
|
T_datif(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
T_prot *getProt() { return myDCIF; }
|
||||||
|
T_prot const *getProt() const { return myDCIF; }
|
||||||
|
|
||||||
void resetChain(void);
|
void resetChain(void);
|
||||||
char isPortOpen(void);
|
char isPortOpen(void);
|
||||||
void sendWRcommand(uint16_t nxtAsCmd);
|
void sendWRcommand(uint16_t nxtAsCmd);
|
||||||
|
@ -165,12 +165,23 @@ class hwapi : public QObject,
|
|||||||
Q_PLUGIN_METADATA(IID "Atb.Psa2020.software.HWapi/1.0" ) //FILE "HWapi.json")
|
Q_PLUGIN_METADATA(IID "Atb.Psa2020.software.HWapi/1.0" ) //FILE "HWapi.json")
|
||||||
Q_INTERFACES(hwinf)
|
Q_INTERFACES(hwinf)
|
||||||
|
|
||||||
|
DownloadResult sendNextAddress(int bNum) const;
|
||||||
|
DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const;
|
||||||
|
DownloadResult sendStatus(int ret) const;
|
||||||
|
DownloadResult dc_downloadBinary(QByteArray const &binary) const;
|
||||||
|
|
||||||
|
bool startBootloader() const;
|
||||||
|
bool stopBootloader() const;
|
||||||
|
bool openSerial(int br, QString baudrate, QString comPort) const;
|
||||||
|
bool closeSerial(QString comport) const;
|
||||||
|
bool resetDeviceController() const;
|
||||||
|
QByteArray loadBinaryDCFile(QString filename) const;
|
||||||
|
bool downloadBinaryToDC(QString const &bFile) const;
|
||||||
public:
|
public:
|
||||||
explicit hwapi(QWidget *parent = nullptr);
|
explicit hwapi(QWidget *parent = nullptr);
|
||||||
|
|
||||||
T_datif *myDatif;
|
T_datif *myDatif;
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
// Level 0 commands, interface
|
// Level 0 commands, interface
|
||||||
// open, close, change serial interface
|
// open, close, change serial interface
|
||||||
@ -178,13 +189,13 @@ public:
|
|||||||
// start automatic READ requests
|
// start automatic READ requests
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
|
|
||||||
void dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const override;
|
bool dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const override;
|
||||||
// BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
|
// BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
|
||||||
// BaudStr: for exapmle "19200"
|
// BaudStr: for exapmle "19200"
|
||||||
// ComName: for example "COM48"
|
// ComName: for example "COM48"
|
||||||
// connect: 0, 1
|
// connect: 0, 1
|
||||||
|
|
||||||
void dc_closeSerial(void) const override;
|
bool dc_closeSerial(void) const override;
|
||||||
|
|
||||||
bool dc_isPortOpen(void) const override ;
|
bool dc_isPortOpen(void) const override ;
|
||||||
|
|
||||||
@ -192,7 +203,8 @@ public:
|
|||||||
// select if READ-Requests are sent manually one by one or automatically
|
// select if READ-Requests are sent manually one by one or automatically
|
||||||
// automatically request ALL digital and analog sensors, get time/date, get status information
|
// automatically request ALL digital and analog sensors, get time/date, get status information
|
||||||
|
|
||||||
|
bool dc_updateDC(QString binFileName, QString baudrate,
|
||||||
|
QString comPort) const override;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
// Level 1, control device-controller (functions of µC)
|
// Level 1, control device-controller (functions of µC)
|
||||||
@ -246,15 +258,6 @@ public:
|
|||||||
|
|
||||||
QString dc_getState(void) const override;
|
QString dc_getState(void) const override;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// neu, 25.8.21
|
// neu, 25.8.21
|
||||||
QString dc_getTxt4RsDiagWin(void) const override;
|
QString dc_getTxt4RsDiagWin(void) const override;
|
||||||
void dc_clrTxt4RsDiagWin(void) const override;
|
void dc_clrTxt4RsDiagWin(void) const override;
|
||||||
@ -975,7 +978,7 @@ public:
|
|||||||
void bl_rebootDC(void) const override;
|
void bl_rebootDC(void) const override;
|
||||||
|
|
||||||
void bl_startBL(void) const override;
|
void bl_startBL(void) const override;
|
||||||
void bl_checkBL(void) const override;
|
bool bl_checkBL(void) const override;
|
||||||
bool bl_isUp(void) const override;
|
bool bl_isUp(void) const override;
|
||||||
// return true is bl is up and running
|
// return true is bl is up and running
|
||||||
// also initializes "sendFile"
|
// also initializes "sendFile"
|
||||||
|
@ -98,10 +98,10 @@ class hwinf
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum class DownloadResult {OK, ERROR, TIMEOUT, NOP};
|
||||||
|
|
||||||
virtual ~hwinf() {}
|
virtual ~hwinf() {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
||||||
// Use serial interface and protocol stack in Cashagent-Library
|
// Use serial interface and protocol stack in Cashagent-Library
|
||||||
// Sending Output data to DeviceController DC2b
|
// Sending Output data to DeviceController DC2b
|
||||||
@ -110,29 +110,30 @@ public:
|
|||||||
// Furthermore the Cashagent-Library answers with status strings about sending and reading result
|
// Furthermore the Cashagent-Library answers with status strings about sending and reading result
|
||||||
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
|
||||||
|
|
||||||
virtual void dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const =0;
|
virtual bool dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const = 0;
|
||||||
// Command: open serial interface
|
// Command: open serial interface
|
||||||
// BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
|
// BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
|
||||||
// BaudStr: for exapmle "19200"
|
// BaudStr: for exapmle "19200"
|
||||||
// ComName: for example "COM48"
|
// ComName: for example "COM48"
|
||||||
// connect: 0, 1
|
// connect: 0, 1
|
||||||
|
|
||||||
virtual void dc_closeSerial(void) const =0;
|
virtual bool dc_closeSerial(void) const = 0;
|
||||||
// Command: close serial interface in order to save power while power down
|
// Command: close serial interface in order to save power while power down
|
||||||
// or if another port must be used
|
// or if another port must be used
|
||||||
|
|
||||||
virtual bool dc_isPortOpen(void) const =0;
|
virtual bool dc_isPortOpen(void) const =0;
|
||||||
// returns true if port open (don't send unless open. Sending to closed port will crash program)
|
// returns true if port open (don't send unless open. Sending to closed port will crash program)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual uint8_t test_serialState(void) const =0;
|
virtual uint8_t test_serialState(void) const =0;
|
||||||
// test on-board signals for the serials
|
// test on-board signals for the serials
|
||||||
// serial drv on/off, Serial mux1, Serial mux2
|
// serial drv on/off, Serial mux1, Serial mux2
|
||||||
|
|
||||||
virtual bool test_serialIsOn(void) const =0;
|
virtual bool test_serialIsOn(void) const =0;
|
||||||
|
|
||||||
|
virtual bool dc_updateDC(QString binFileName,
|
||||||
|
QString baudrate,
|
||||||
|
QString comPort) const = 0;
|
||||||
|
// download binary file down into device controller
|
||||||
|
|
||||||
virtual void dc_autoRequest(bool on) const =0;
|
virtual void dc_autoRequest(bool on) const =0;
|
||||||
// on = true: select that all READ-Requests are sent automatically
|
// on = true: select that all READ-Requests are sent automatically
|
||||||
@ -1045,7 +1046,7 @@ public:
|
|||||||
virtual void bl_startBL(void) const = 0;
|
virtual void bl_startBL(void) const = 0;
|
||||||
// send command within 4s after DC power-on, otherwise bl is left
|
// send command within 4s after DC power-on, otherwise bl is left
|
||||||
|
|
||||||
virtual void bl_checkBL(void) const =0;
|
virtual bool bl_checkBL(void) const = 0;
|
||||||
// send command to verify if bl is up
|
// send command to verify if bl is up
|
||||||
|
|
||||||
virtual bool bl_isUp(void) const =0;
|
virtual bool bl_isUp(void) const =0;
|
||||||
|
@ -93,6 +93,9 @@ private slots:
|
|||||||
void analyseRecData(void);
|
void analyseRecData(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
T_com *getSerialPort() { return mySerialPort; }
|
||||||
|
T_com const *getSerialPort() const { return mySerialPort; }
|
||||||
|
|
||||||
T_prot();
|
T_prot();
|
||||||
bool isPortOpen(void);
|
bool isPortOpen(void);
|
||||||
bool isSerialFree(void);
|
bool isSerialFree(void);
|
||||||
|
32
src/com.cpp
32
src/com.cpp
@ -93,29 +93,34 @@ T_com::~T_com()
|
|||||||
|
|
||||||
void T_com::ser_ISR100ms()
|
void T_com::ser_ISR100ms()
|
||||||
{
|
{
|
||||||
|
//qDebug() << "~~>LIB" << "ENTER...";
|
||||||
// call every 100ms to check if user(HMI) wants to connect or disconnect
|
// call every 100ms to check if user(HMI) wants to connect or disconnect
|
||||||
|
|
||||||
//qDebug() << "~~>LIB" << "checking connect button... " ;
|
|
||||||
|
|
||||||
uint8_t chkConn = gpi_getSerialConn(); // from global GUI buffer (Sdata)
|
uint8_t chkConn = gpi_getSerialConn(); // from global GUI buffer (Sdata)
|
||||||
|
|
||||||
|
//qDebug() << "~~>LIB" << "checking connect button... " << chkConn;
|
||||||
|
|
||||||
switch (chkConn)
|
switch (chkConn)
|
||||||
{
|
{
|
||||||
case 0: // 0 button "connect" was just released
|
case 0: // 0 button "connect" was just released
|
||||||
|
//qDebug() << "close serial port" << chkConn;
|
||||||
closeSerialPort();
|
closeSerialPort();
|
||||||
gpi_serialChanged(); // set chkConn to 2, thus getting edge
|
gpi_serialChanged(); // set chkConn to 2, thus getting edge
|
||||||
break;
|
break;
|
||||||
case 1: // 1 button "connect" was just pressed
|
case 1: // 1 button "connect" was just pressed
|
||||||
|
//qDebug() << "open serial port" << chkConn;
|
||||||
open_Serial_Port();
|
open_Serial_Port();
|
||||||
gpi_serialChanged(); // set chkConn to 2, thus getting edge
|
gpi_serialChanged(); // set chkConn to 2, thus getting edge
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (CatSerial->isOpen())
|
if (CatSerial->isOpen()) {
|
||||||
gpi_serialIsOpen(true);
|
gpi_serialIsOpen(true);
|
||||||
else
|
} else {
|
||||||
gpi_serialIsOpen(false);
|
gpi_serialIsOpen(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//qDebug() << "LEAVE " << chkConn;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------
|
||||||
@ -124,17 +129,24 @@ void T_com::ser_ISR100ms()
|
|||||||
|
|
||||||
char T_com::open_Serial_Port()
|
char T_com::open_Serial_Port()
|
||||||
{
|
{
|
||||||
|
//qDebug() << "ENTER";
|
||||||
|
|
||||||
bool ret;
|
bool ret;
|
||||||
QString myString=nullptr, myPortName=nullptr, myBaudStr=nullptr;
|
QString myString=nullptr, myPortName=nullptr, myBaudStr=nullptr;
|
||||||
int myBaudNr;
|
int myBaudNr;
|
||||||
|
|
||||||
if (CatSerial->isOpen())
|
if (CatSerial->isOpen()) {
|
||||||
|
qDebug() << "!!!IS OPEN!!!";
|
||||||
return 0; // opening twice is not allowed
|
return 0; // opening twice is not allowed
|
||||||
|
}
|
||||||
|
|
||||||
//qDebug() << "connecting..." << myPortName;
|
//qDebug() << "connecting..." << myPortName;
|
||||||
myPortName=gpi_getComPortName(); // was selected and stored from GUI
|
myPortName=gpi_getComPortName(); // was selected and stored from GUI
|
||||||
CatSerial->setPortName(myPortName);
|
CatSerial->setPortName(myPortName);
|
||||||
myBaudNr=gpi_getBaudNr(); // was selected and stored from GUI
|
myBaudNr=gpi_getBaudNr(); // was selected and stored from GUI
|
||||||
|
|
||||||
|
//qDebug() << "myPortName" << myPortName << ", myBaudNr" << myBaudNr;
|
||||||
|
|
||||||
switch (myBaudNr)
|
switch (myBaudNr)
|
||||||
{
|
{
|
||||||
// 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
|
// 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
|
||||||
@ -167,6 +179,9 @@ char T_com::open_Serial_Port()
|
|||||||
myString.append(CatSerial->errorString());
|
myString.append(CatSerial->errorString());
|
||||||
qDebug() << myString;
|
qDebug() << myString;
|
||||||
gpi_setTxt4comStateLine(myString);
|
gpi_setTxt4comStateLine(myString);
|
||||||
|
|
||||||
|
//qDebug() << "LEAVE";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@ -182,11 +197,14 @@ char T_com::open_Serial_Port()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//qDebug() << "LEAVE";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_com::closeSerialPort()
|
void T_com::closeSerialPort()
|
||||||
{
|
{
|
||||||
|
//qDebug() << "ENTER";
|
||||||
|
|
||||||
if (CatSerial->isOpen())
|
if (CatSerial->isOpen())
|
||||||
{
|
{
|
||||||
qDebug() << "closing connection";
|
qDebug() << "closing connection";
|
||||||
@ -195,6 +213,8 @@ void T_com::closeSerialPort()
|
|||||||
gpi_setTxt4RsDiagWin("closed");
|
gpi_setTxt4RsDiagWin("closed");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//qDebug() << "LEAVE";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,16 +15,20 @@ static uint8_t rs_connect; // 0,1
|
|||||||
|
|
||||||
void epi_setSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect)
|
void epi_setSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect)
|
||||||
{
|
{
|
||||||
|
// qDebug() << "ENTER" << BaudNr << BaudStr << ComName << connect;
|
||||||
|
|
||||||
rs_comportName = ComName;
|
rs_comportName = ComName;
|
||||||
rs_baudStr = BaudStr;
|
rs_baudStr = BaudStr;
|
||||||
rs_baudNr = BaudNr; // 0=1200 1=9600 2=19200 3=38400 4=57600 5=115200 oder -1
|
rs_baudNr = BaudNr; // 0=1200 1=9600 2=19200 3=38400 4=57600 5=115200 oder -1
|
||||||
rs_connect = connect; // 0/1
|
rs_connect = connect; // 0/1
|
||||||
|
|
||||||
|
// qDebug() << "LEAVE" << rs_baudNr << rs_baudStr << rs_comportName << rs_connect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void epi_closeSerial(void)
|
void epi_closeSerial(void)
|
||||||
{
|
{
|
||||||
rs_connect=0;
|
rs_connect=0;
|
||||||
|
// qDebug() << "ENTER/LEAVE rc_connect=0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -32,6 +36,7 @@ void gpi_serialChanged(void)
|
|||||||
{
|
{
|
||||||
// serial confirms that port was closed or opened
|
// serial confirms that port was closed or opened
|
||||||
rs_connect=2; // Flanke, nur 1x öffnen/schließen
|
rs_connect=2; // Flanke, nur 1x öffnen/schließen
|
||||||
|
//qDebug() << "ENTER/LEAVE rc_connect=2";
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t gpi_getSerialConn(void)
|
uint8_t gpi_getSerialConn(void)
|
||||||
@ -54,12 +59,14 @@ static bool rs_portIsOpen;
|
|||||||
|
|
||||||
void gpi_serialIsOpen(bool offen)
|
void gpi_serialIsOpen(bool offen)
|
||||||
{
|
{
|
||||||
|
//qDebug() << "ENTER/LEAVE offen=" << offen;
|
||||||
rs_portIsOpen=offen;
|
rs_portIsOpen=offen;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool epi_isSerialPortOpen()
|
bool epi_isSerialPortOpen()
|
||||||
{
|
{
|
||||||
// true: port is open false: port is closed
|
// true: port is open false: port is closed
|
||||||
|
//qDebug() << "ENTER/LEAVE offen=" << rs_portIsOpen;
|
||||||
return rs_portIsOpen;
|
return rs_portIsOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
290
src/hwapi.cpp
290
src/hwapi.cpp
@ -8,6 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "tslib.h"
|
#include "tslib.h"
|
||||||
#include "hwapi.h"
|
#include "hwapi.h"
|
||||||
@ -20,6 +22,10 @@
|
|||||||
#include <../plugins/interfaces.h>
|
#include <../plugins/interfaces.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const QMap<QString, int> baudrateMap = {
|
||||||
|
{"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3},
|
||||||
|
{"57600" , 4}, {"115200" , 5}
|
||||||
|
};
|
||||||
|
|
||||||
hwapi::hwapi(QWidget *parent) : QObject(parent)
|
hwapi::hwapi(QWidget *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
@ -29,7 +35,6 @@ hwapi::hwapi(QWidget *parent) : QObject(parent)
|
|||||||
sendWRcmd_INI();
|
sendWRcmd_INI();
|
||||||
|
|
||||||
myDatif = new T_datif();
|
myDatif = new T_datif();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -105,25 +110,49 @@ void hwapi::sub_storeSendingText(QByteArray *buf) const
|
|||||||
// start automatic READ requests
|
// start automatic READ requests
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
|
|
||||||
void hwapi::dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const
|
bool hwapi::dc_openSerial(int BaudNr, QString BaudStr,
|
||||||
{
|
QString ComName, uint8_t connect) const {
|
||||||
// BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
|
// BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200
|
||||||
// BaudStr: for exapmle "19200"
|
// BaudStr: for exapmle "19200"
|
||||||
// ComName: for example "COM48"
|
// ComName: for example "COM48"
|
||||||
// connect: 0, 1
|
// connect: 0, 1
|
||||||
//qDebug() << "~~>LIB" << "dc_openSerial called... " ;
|
//qDebug() << "~~>LIB" << "dc_openSerial called... " ;
|
||||||
|
|
||||||
epi_setSerial(BaudNr, BaudStr, ComName, connect);
|
epi_setSerial(BaudNr, BaudStr, ComName, connect);
|
||||||
|
|
||||||
// Actions: open serial port with parameters
|
// Actions: open serial port with parameters
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
if (dc_isPortOpen()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwapi::dc_closeSerial(void) const
|
bool hwapi::dc_closeSerial(void) const {
|
||||||
{
|
|
||||||
epi_closeSerial();
|
epi_closeSerial();
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
if (!dc_isPortOpen()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hwapi::dc_isPortOpen(void) const
|
bool hwapi::dc_isPortOpen(void) const {
|
||||||
{
|
if (myDatif) {
|
||||||
return epi_isSerialPortOpen();
|
T_prot* prot = myDatif->getProt();
|
||||||
|
if (prot) {
|
||||||
|
T_com *com = prot->getSerialPort();
|
||||||
|
if (com) {
|
||||||
|
return com->isPortOpen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
//return epi_isSerialPortOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwapi::dc_autoRequest(bool on) const
|
void hwapi::dc_autoRequest(bool on) const
|
||||||
@ -135,6 +164,247 @@ void hwapi::dc_autoRequest(bool on) const
|
|||||||
epi_startEmmision(0);
|
epi_startEmmision(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
//
|
||||||
|
// LEVEL 2: Help-functions for hwapi::dc_updateDC.
|
||||||
|
//
|
||||||
|
/******************************************************************************/
|
||||||
|
hwapi::DownloadResult hwapi::sendStatus(int ret) const {
|
||||||
|
switch (ret) { // return values of dc are:
|
||||||
|
case 0: // 0: no answer by now
|
||||||
|
return DownloadResult::NOP; // 1: error
|
||||||
|
case 10: // 10: success
|
||||||
|
return DownloadResult::OK;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
return DownloadResult::ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
hwapi::DownloadResult hwapi::sendNextAddress(int bNum) const {
|
||||||
|
// sends address only if blockNumber is one of 0, 1024, 2048, 3072, 4096
|
||||||
|
int noAnswerCount = 0;
|
||||||
|
int errorCount = 0;
|
||||||
|
if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) {
|
||||||
|
qDebug() << "addr-block" << bNum << "...";
|
||||||
|
while (noAnswerCount <= 250) {
|
||||||
|
bl_sendAddress(bNum);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
DownloadResult const res = sendStatus(bl_wasSendingAddOK());
|
||||||
|
if (res != DownloadResult::NOP) {
|
||||||
|
if (res == DownloadResult::ERROR) {
|
||||||
|
if (++errorCount >= 10) {
|
||||||
|
qCritical() << "addr-block" << bNum << "...FAILED";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} else { // res == DownloadResult::OK
|
||||||
|
qInfo() << "addr-block" << bNum << "...OK";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
noAnswerCount += 1; // no answer by now
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// wait max. about 3 seconds
|
||||||
|
return DownloadResult::TIMEOUT;
|
||||||
|
}
|
||||||
|
// blockNumber is not one of 0, 1024, 2048, 3072, 4096 -> do nothing
|
||||||
|
return DownloadResult::NOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
hwinf::DownloadResult hwapi::sendNextDataBlock(QByteArray const &binary,
|
||||||
|
int bNum) const {
|
||||||
|
uint8_t local[66];
|
||||||
|
int const bAddr = bNum * 64;
|
||||||
|
int noAnswerCount = 0;
|
||||||
|
int errorCount = 0;
|
||||||
|
|
||||||
|
memcpy(local, binary.constData() + bAddr, 64);
|
||||||
|
local[64] = local[65] = 0x00;
|
||||||
|
|
||||||
|
qDebug() << "data for addr" << bAddr << "...";
|
||||||
|
|
||||||
|
while (noAnswerCount <= 250) {
|
||||||
|
bl_sendDataBlock(64, local);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
|
DownloadResult const res = sendStatus(bl_wasSendingDataOK());
|
||||||
|
if (res != DownloadResult::NOP) {
|
||||||
|
if (res == DownloadResult::ERROR) {
|
||||||
|
if (++errorCount >= 10) {
|
||||||
|
qCritical() << "data for addr" << bAddr << "...FAILED";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qInfo() << "data for addr" << bAddr << "...OK";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
noAnswerCount += 1; // no answer by now
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// wait max. about 3 seconds
|
||||||
|
return DownloadResult::TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
hwinf::DownloadResult hwapi::dc_downloadBinary(QByteArray const &b) const {
|
||||||
|
|
||||||
|
int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1;
|
||||||
|
|
||||||
|
qInfo() << "total number of bytes to send to dc" << b.size();
|
||||||
|
qInfo() << "total number of blocks to send to dc" << nBlocks;
|
||||||
|
|
||||||
|
for (int blockNumber = 0; blockNumber < nBlocks; ++blockNumber) {
|
||||||
|
DownloadResult res = sendNextAddress(blockNumber);
|
||||||
|
if (res == DownloadResult::NOP) { // no address had to be
|
||||||
|
res = sendNextDataBlock(b, blockNumber); // sent, so send next block
|
||||||
|
} // as data block
|
||||||
|
if (res != DownloadResult::OK) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bl_sendLastBlock();
|
||||||
|
return DownloadResult::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hwapi::startBootloader() const {
|
||||||
|
qDebug() << "starting bootloader...";
|
||||||
|
int nTry = 5;
|
||||||
|
while (--nTry >= 0) {
|
||||||
|
bl_startBL();
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
if (bl_isUp()) {
|
||||||
|
qInfo() << "starting bootloader...OK";
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qCritical() << "starting bootloader...FAILED";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hwapi::stopBootloader() const {
|
||||||
|
qDebug() << "stopping bootloader...";
|
||||||
|
int nTry = 5;
|
||||||
|
while (--nTry >= 0) {
|
||||||
|
bl_stopBL();
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
if (!bl_isUp()) {
|
||||||
|
qInfo() << "stopping bootloader...OK";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qCritical() << "stopping bootloader...FAILED";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// br is a index into a table, used for historical reasons.
|
||||||
|
bool hwapi::openSerial(int br, QString baudrate, QString comPort) const {
|
||||||
|
qDebug() << "opening serial" << br << baudrate << comPort << "...";
|
||||||
|
if (dc_openSerial(br, baudrate, comPort, 1)) { // 1 for connect
|
||||||
|
qInfo() << "opening serial" << br << baudrate << comPort << "...OK";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
qCritical() << "opening serial" << br << baudrate << comPort << "...FAILED";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hwapi::closeSerial(QString comPort) const {
|
||||||
|
qDebug() << "closing serial" << comPort << "...";
|
||||||
|
if (dc_closeSerial()) {
|
||||||
|
qInfo() << "closing serial" << comPort << "...OK";
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
qCritical() << "closing serial" << comPort << "...FAILED";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hwapi::resetDeviceController() const {
|
||||||
|
qDebug() << "resetting device controller...";
|
||||||
|
if (stopBootloader()) { // first stop a (maybe) running bootloader
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
dc_OrderToReset();
|
||||||
|
// wait maximally 3 seconds, before starting bootloader
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||||
|
qInfo() << "resetting device controller...OK";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray hwapi::loadBinaryDCFile(QString filename) const {
|
||||||
|
qDebug() << "loading dc binary" << filename << "...";
|
||||||
|
|
||||||
|
QFile file(filename); // closed in destructor call
|
||||||
|
if (!file.exists()) {
|
||||||
|
qCritical() << file.fileName() << "does not exist";
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
|
qCritical() << "cannot open file" << file.fileName();
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
qInfo() << "loading dc binary" << filename << "...OK";
|
||||||
|
return file.readAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hwapi::downloadBinaryToDC(QString const &bFile) const {
|
||||||
|
qDebug() << "sending" << bFile << "to dc...";
|
||||||
|
QByteArray const dcBinary = loadBinaryDCFile(bFile);
|
||||||
|
if (dcBinary.size() > 0) {
|
||||||
|
if (dc_downloadBinary(dcBinary) != DownloadResult::OK) {
|
||||||
|
qCritical() << "sending" << bFile << "to dc...FAILED";
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
qInfo() << "sending" << bFile << "to dc...OK";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qCritical() << "sending" << bFile << "to dc...FAILED";
|
||||||
|
qCritical() << "loading binary" << bFile << "FAILED";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
//
|
||||||
|
// LEVEL 3: hwapi::dc_updateDC.
|
||||||
|
//
|
||||||
|
/******************************************************************************/
|
||||||
|
bool hwapi::dc_updateDC(QString bFile, QString br, QString serial) const {
|
||||||
|
if (!baudrateMap.contains(br)) { // sanity check
|
||||||
|
qCritical() << "passed wrong baudrate" << br;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "updating dc: " << bFile << br << serial << "...";
|
||||||
|
|
||||||
|
if (!openSerial(baudrateMap.value(br), br, serial)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!resetDeviceController()) {
|
||||||
|
closeSerial(serial);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!startBootloader()) {
|
||||||
|
closeSerial(serial);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!downloadBinaryToDC(bFile)) {
|
||||||
|
stopBootloader();
|
||||||
|
closeSerial(serial);
|
||||||
|
qCritical() << "updating dc: " << bFile << br << serial << "...FAILED";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
qInfo() << "updating dc: " << bFile << br << serial << "...OK";
|
||||||
|
|
||||||
|
stopBootloader();
|
||||||
|
closeSerial(serial);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
// Level 1, control device-controller (functions of µC)
|
// Level 1, control device-controller (functions of µC)
|
||||||
// check serial connection to deviceController
|
// check serial connection to deviceController
|
||||||
@ -2577,13 +2847,15 @@ void hwapi::bl_startBL(void) const
|
|||||||
sendWRcmd_setSendBlock160(len, buf);
|
sendWRcmd_setSendBlock160(len, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwapi::bl_checkBL(void) const
|
bool hwapi::bl_checkBL(void) const
|
||||||
{
|
{
|
||||||
uint8_t len, buf[20];
|
uint8_t len, buf[20];
|
||||||
|
|
||||||
//len=dcBL_readBLversion(buf);
|
//len=dcBL_readBLversion(buf);
|
||||||
len=dcBL_readFWversion(buf);
|
len=dcBL_readFWversion(buf);
|
||||||
sendWRcmd_setSendBlock160(len, buf);
|
sendWRcmd_setSendBlock160(len, buf);
|
||||||
|
|
||||||
|
return (len > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hwapi::bl_isUp(void) const
|
bool hwapi::bl_isUp(void) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user