#ifndef MSEIAL_H #define MSEIAL_H #include #include #include #include #include #include #include #include #include #include #include #include #include class SerialThread: public QThread { Q_OBJECT public: // 数据缓存区 QByteArray dataBuf; explicit SerialThread(QObject *parent = nullptr); ~SerialThread(); void setSerialPortSettings(const QString &portName, QSerialPort::BaudRate baudRate, QSerialPort::DataBits dataBits, QSerialPort::Parity parity, QSerialPort::StopBits stopBits, QSerialPort::FlowControl flowControl); void run() override; void stop(); void SetLedState(bool sw){ sendData(m_json.setLedState(sw)); } Q_INVOKABLE void reboot(){ sendData(m_json.CmdReboot()); } QSerialPort& getSerialPort() { return m_serialPort; } Q_INVOKABLE void readBoardData(); Q_INVOKABLE void update_dat_f_main(QString freq); //更新数据上传间隔 Q_INVOKABLE void sendCmd(QString cmd_type,bool sw,QString setup,QString speed); Q_INVOKABLE QStringList pathinfo(){ QStringList pf_pic; pf_pic.append(qst_dirPath); pf_pic.append(QString::number(int_fileCount)); pf_pic.append(QString::number(int_totalSize/1048576)); return pf_pic; } Q_INVOKABLE void readPathinfo(){ getDirectoryStats(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); } Q_INVOKABLE void removepic(){ deleteAllFilesInDirectory(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); } Q_INVOKABLE void setCollt(int sh1 ,int eh1,int sh2,int eh2,int sh3,int eh3){ sendData(m_json.CmdParamconf(sh1,eh1,sh2,eh2,sh3,eh3)); } Q_INVOKABLE void setLightness(int val){ auto qtContext = QJniObject(QNativeInterface::QAndroidApplication::context()); //activity if (qtContext.isValid()) { QJniObject jClass("com/yfkj/cb/Q6iot/Backlight"); jClass.callMethod("setScreenLight","(Landroid/content/Context;I)V",qtContext.object(),val); } } signals: void dataReceived(const QByteArray &data); void dataUpload(const QByteArray &data); void updatestart(QString filename); void auto_takephoto(bool sw); void takephotodone(); void disconnect_485(); void autotestdone(); void translatedone(); void netMessage(const QByteArray &data); void autoFocusDone(); void autoFocusStart(); void signal_movy(); void timeout_mov_stop(); public slots: void sendData(const QByteArray &data); void mqtttoserial(const QByteArray &data); void getmodemresult(int res); void doWork(QVideoFrame dframe); private slots: //void readBoardData(); private: void processJsonData(QByteArray &jsonData); QTimer m_dat_f; QTimer* timeout_mov = nullptr; QSerialPort m_serialPort; SqliteOperator *sqlConfig; bool m_running; bool data_upload; int connect_board; //主板串口连接状态 JsonFunc m_json; QString qst_dirPath; int int_fileCount; qint64 int_totalSize; void deleteAllFilesInDirectory(const QString &directoryPath) { QDir directory(directoryPath); if (!directory.exists()) { qDebug() << "Directory does not exist."; return; } QFileInfoList fileInfoList = directory.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); foreach (const QFileInfo &fileInfo, fileInfoList) { if (fileInfo.isDir()) { // 递归删除子目录中的文件 deleteAllFilesInDirectory(fileInfo.filePath()); } else { // 删除文件 QFile::remove(fileInfo.filePath()); } } getDirectoryStats(directoryPath); } void getDirectoryStats(const QString &directoryPath) { QDir directory(directoryPath); if (!directory.exists()) { qDebug() << "Directory does not exist."; } qint64 totalSize = 0; int fileCount = 0; QFileInfoList fileInfoList = directory.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); foreach (const QFileInfo &fileInfo, fileInfoList) { if (fileInfo.isDir()) { // 递归获取子目录的统计信息 getDirectoryStats(fileInfo.filePath()); } else { totalSize += fileInfo.size(); fileCount++; } } qst_dirPath = directoryPath; int_fileCount = fileCount; int_totalSize = totalSize; qDebug() << "Directory: " << directoryPath; qDebug() << "File count: " << fileCount; qDebug() << "Total size: " << totalSize << " bytes"; } }; class Serial_AT : public QSerialPort { Q_OBJECT public: explicit Serial_AT(QObject *parent = 0); QTimer *m_5s; // 发送字节数 int txByte = 0; // 接收字节数 int rxByte = 0; // 数据缓存区 QByteArray dataBuf; // 串口描述内容 QStringList serialDescription; // 串口扫描函数 QStringList serialScan(void); bool serialOpen(QString serialName, int baudRate); void sendData(QByteArray sendData); void serialClose(); private slots: void ReadData(); private: QTextCodec *tc; QString at_str; QTimer* timeout_recv = nullptr; signals: void readSignal(int recByte); void sendSuccess(int sendByte); void imeiDone(); void iccidDone(); }; #endif // MSEIAL_H