take over some code from mainwindow
This commit is contained in:
		@@ -24,6 +24,8 @@
 | 
			
		||||
#include <QMap>
 | 
			
		||||
#include <QStringList>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QSerialPort>
 | 
			
		||||
#include <QSerialPortInfo>
 | 
			
		||||
 | 
			
		||||
#define UPDATE_OPKG                 (1)
 | 
			
		||||
#define UPDATE_DC                   (0)
 | 
			
		||||
@@ -147,6 +149,35 @@ Update::~Update() {
 | 
			
		||||
    unloadDCPlugin();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Update::openSerialPort() {
 | 
			
		||||
   // const SettingsDialog::Settings p = m_settings->settings();
 | 
			
		||||
   m_serial->setPortName(SERIAL_PORT);
 | 
			
		||||
   m_serial->setBaudRate(QSerialPort::Baud115200);
 | 
			
		||||
   m_serial->setDataBits(QSerialPort::DataBits::Data8);
 | 
			
		||||
   m_serial->setParity(QSerialPort::Parity::NoParity);
 | 
			
		||||
   m_serial->setStopBits(QSerialPort::StopBits::OneStop);
 | 
			
		||||
   m_serial->setFlowControl(QSerialPort::FlowControl::NoFlowControl);
 | 
			
		||||
   if (m_serial->open(QIODevice::ReadWrite)) {
 | 
			
		||||
       //showStatusMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
 | 
			
		||||
       //                  .arg(p.name, p.stringBaudRate, p.stringDataBits,
 | 
			
		||||
       //                       p.stringParity, p.stringStopBits, p.stringFlowControl));
 | 
			
		||||
       return true;
 | 
			
		||||
   } else {
 | 
			
		||||
       //QMessageBox::critical(this, tr("Error"), m_serial->errorString());
 | 
			
		||||
       //showStatusMessage(tr("Open error"));
 | 
			
		||||
   }
 | 
			
		||||
   return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Update::closeSerialPort() {
 | 
			
		||||
    if (m_serial->isOpen()) {
 | 
			
		||||
        m_serial->close();
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
    //showStatusMessage(tr("Disconnected"));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Update::DownloadResult Update::sendStatus(int ret) const {
 | 
			
		||||
    switch (ret) {                  // return values of dc are:
 | 
			
		||||
    case 0:                         // 0: no answer by now
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@
 | 
			
		||||
#define SERIAL_PORT "ttyUSB0"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class QSerialPort;
 | 
			
		||||
class Update : public QObject {
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
@@ -46,6 +47,12 @@ class Update : public QObject {
 | 
			
		||||
        return QStringLiteral("+%1s").arg(secs, 7, 'f', 2, QChar('0'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    bool openSerialPort();
 | 
			
		||||
    bool closeSerialPort();
 | 
			
		||||
 | 
			
		||||
    QSerialPort *m_serial;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    enum class DownloadResult {OK, ERROR, TIMEOUT, NOP};
 | 
			
		||||
    enum class FileTypeJson {CONFIG=1, DEVICE=2, CASH=3, SERIAL=4, TIME=5, PRINTER=6};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user