Add printer update
This commit is contained in:
		
							
								
								
									
										51
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								main.cpp
									
									
									
									
									
								
							@@ -2,9 +2,10 @@
 | 
				
			|||||||
#include <QApplication>
 | 
					#include <QApplication>
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
#include <QTimer>
 | 
					#include <QTimer>
 | 
				
			||||||
 | 
					#include <QFileInfo>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "message_handler.h"
 | 
					#include "message_handler.h"
 | 
				
			||||||
#include "plugins/interfaces.h"
 | 
					#include "interfaces.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "DCPlugin/include/hwapi.h"
 | 
					#include "DCPlugin/include/hwapi.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -12,11 +13,21 @@
 | 
				
			|||||||
#include <thread>
 | 
					#include <thread>
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//static void updateDC(hwinf const *hw) {
 | 
					static void updateBinary(std::unique_ptr<hwinf> hw,     // update d2dc*.bin
 | 
				
			||||||
static void updateDC(std::unique_ptr<hwinf> hw,
 | 
					                         char const *fileToSendToDC,
 | 
				
			||||||
                     char const *fileToSendToDC,
 | 
					                         char const *baudrate,
 | 
				
			||||||
                     char const *baudrate,
 | 
					                         char const *serialInterface) {
 | 
				
			||||||
                     char const *serialInterface) {
 | 
					    for (int i=0; i < 1;++i) {
 | 
				
			||||||
 | 
					        hw->dc_updateDC(fileToSendToDC, baudrate, serialInterface);
 | 
				
			||||||
 | 
					        std::this_thread::sleep_for(std::chrono::milliseconds(3000));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    QCoreApplication::quit();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void updatePrinterConf(std::unique_ptr<hwinf> hw, // update printer-file
 | 
				
			||||||
 | 
					                              char const *fileToSendToDC,
 | 
				
			||||||
 | 
					                              char const *baudrate,
 | 
				
			||||||
 | 
					                              char const *serialInterface) {
 | 
				
			||||||
    for (int i=0; i < 1;++i) {
 | 
					    for (int i=0; i < 1;++i) {
 | 
				
			||||||
        hw->dc_updateDC(fileToSendToDC, baudrate, serialInterface);
 | 
					        hw->dc_updateDC(fileToSendToDC, baudrate, serialInterface);
 | 
				
			||||||
        std::this_thread::sleep_for(std::chrono::milliseconds(3000));
 | 
					        std::this_thread::sleep_for(std::chrono::milliseconds(3000));
 | 
				
			||||||
@@ -39,12 +50,32 @@ int main(int argc, char *argv[]) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::unique_ptr<hwinf> hw(new hwapi());
 | 
					    std::unique_ptr<hwinf> hw(new hwapi());
 | 
				
			||||||
 | 
					    QFileInfo fileInfo(argv[1]);
 | 
				
			||||||
 | 
					    QString fname(fileInfo.fileName());
 | 
				
			||||||
 | 
					    int ret = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (fname.startsWith("dc") && fname.endsWith(".bin")) {
 | 
				
			||||||
#ifdef PTU5
 | 
					#ifdef PTU5
 | 
				
			||||||
    std::thread t(updateDC, std::move(hw), argv[1], "115200", "ttymxc2");
 | 
					        std::thread t(updateBinary, std::move(hw),
 | 
				
			||||||
 | 
					                      fname.toStdString().c_str(), "115200", "ttymxc2");
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    std::thread t(updateDC, std::move(hw), "dc2c4.bin", "115200", "ttyUSB0");
 | 
					        std::thread t(updateBinary, std::move(hw),
 | 
				
			||||||
 | 
					                      fname.toStdString().c_str(), "115200", "ttyUSB0");
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    int ret = a.exec();
 | 
					        ret = a.exec();
 | 
				
			||||||
    t.join();
 | 
					        t.join();
 | 
				
			||||||
 | 
					    } else
 | 
				
			||||||
 | 
					    if (fname.startsWith("DC") && fname.endsWith(".json")) {
 | 
				
			||||||
 | 
					#ifdef PTU5
 | 
				
			||||||
 | 
					        std::thread t(updatePrinterConf, std::move(hw),
 | 
				
			||||||
 | 
					                      fname.toStdString().c_str(), "115200", "ttymxc2");
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					        std::thread t(updatePrinterConf, std::move(hw),
 | 
				
			||||||
 | 
					                      fname.toStdString().c_str(), "115200", "ttyUSB0");
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					        ret = a.exec();
 | 
				
			||||||
 | 
					        t.join();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user