SmartLockerTools/Analyser/Application.h

129 lines
4.8 KiB
C
Raw Normal View History

2024-06-13 15:41:40 +08:00
#ifndef __APPLICATION_H__
#define __APPLICATION_H__
#include "DataStructure.h"
#include "ModuleCommunication.h"
#include "Singleton.h"
#include <QObject>
#include <QQmlEngine>
#include <memory>
class QGuiApplication;
class Database;
class VideoPlayer;
class VideoFrameProvider;
class QTimer;
2024-08-05 17:42:27 +08:00
class CdcUpdater;
2024-06-13 15:41:40 +08:00
class Application : public QObject {
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(ModuleCommunication *module READ module NOTIFY connectedChanged)
2024-06-13 15:41:40 +08:00
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
Q_PROPERTY(bool uvcOpened READ uvcOpened NOTIFY uvcOpenedChanged)
Q_PROPERTY(bool persistenceMode READ persistenceMode WRITE setPersistenceMode NOTIFY persistenceModeChanged)
2024-08-16 19:05:50 +08:00
Q_PROPERTY(bool imageUploadPersistenceMode READ imageUploadPersistenceMode WRITE setImageUploadPersistenceMode
NOTIFY imageUploadPersistenceModeChanged)
2024-06-13 15:41:40 +08:00
Q_PROPERTY(int persistenceVerifyInterval READ persistenceVerifyInterval WRITE setPersistenceVerifyInterval NOTIFY
persistenceVerifyIntervalChanged)
Q_PROPERTY(bool isVerifying READ isVerifying NOTIFY isVerifyingChanged)
friend class Amass::Singleton<Application>;
static constexpr auto JpgPath = "jpg";
static constexpr auto YuvPath = "yuv";
2024-06-13 15:41:40 +08:00
public:
enum TipType {
Tip,
Error,
Info,
};
Q_ENUM(TipType)
void initializeLogger();
int exec();
Q_INVOKABLE QStringList availableSerialPorts() const;
Q_INVOKABLE QStringList availableUsbVideoCameras() const;
Q_INVOKABLE bool open(const QString &portName, int baudRate);
Q_INVOKABLE bool openUVC(const QString &deviceName);
Q_INVOKABLE void close();
Q_INVOKABLE void closeUVC();
2024-08-08 17:05:32 +08:00
Q_INVOKABLE bool startOta(const QString &path);
2024-07-31 16:08:38 +08:00
Q_INVOKABLE void verify(bool captureImage, uint8_t timeout);
Q_INVOKABLE void enroll(const QString &username, bool persistence, uint8_t timeout);
Q_INVOKABLE void enrollExtended(const QString &username, bool persistence, uint8_t timeout);
2024-06-13 15:41:40 +08:00
Q_INVOKABLE void deleteUser(uint16_t userid);
Q_INVOKABLE void deleteAll();
2024-08-16 19:05:50 +08:00
Q_INVOKABLE void uploadImage(const QString &path, const QString &username, int operation);
2024-06-13 15:41:40 +08:00
ModuleCommunication *module() const;
bool connected() const;
bool uvcOpened() const;
bool persistenceMode() const;
void setPersistenceMode(bool enabled);
2024-08-16 19:05:50 +08:00
bool imageUploadPersistenceMode() const;
void setImageUploadPersistenceMode(bool enabled);
2024-06-13 15:41:40 +08:00
int persistenceVerifyInterval() const;
void setPersistenceVerifyInterval(int interval);
bool isVerifying() const;
signals:
void connectedChanged();
void persistenceModeChanged();
void persistenceVerifyIntervalChanged();
2024-08-16 19:05:50 +08:00
void imageUploadPersistenceModeChanged();
2024-06-13 15:41:40 +08:00
void isVerifyingChanged();
void uvcOpenedChanged();
void newVideoFrame();
void newLog(const QString &log);
void newStatusTip(TipType type, const QString &tip);
2024-08-05 17:42:27 +08:00
void updateFinished();
void otaMessage(const QString &text);
void otaProgressChanged(int32_t progress);
2024-06-13 15:41:40 +08:00
protected:
Application(int &argc, char **argv);
2024-08-07 11:45:13 +08:00
void onNewEnrollResult(uint16_t userid);
2024-07-01 15:07:13 +08:00
void onNewVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed);
2024-06-13 15:41:40 +08:00
void onNewPalmFeature(const PalmFeature &feature);
void onErrorOccurred(const QString &error);
2024-07-31 16:08:38 +08:00
void onNewImageInfo(ModuleCommunication::MessageId messageId, uint32_t size, const uint8_t *md5);
2024-06-13 15:41:40 +08:00
void onNewImageSliceData(const std::vector<uint8_t> &data);
void onCommandStarted(ModuleCommunication::MessageId messageId);
void onCommandFinished(ModuleCommunication::MessageId messageId, ModuleCommunication::MessageStatus status);
void onVerifyTimeout();
2024-08-05 17:42:27 +08:00
void onCdcDeviceDiscovered(const QSerialPortInfo &info);
void onUpdateFinished();
2024-06-13 15:41:40 +08:00
private:
std::shared_ptr<QGuiApplication> m_app;
std::shared_ptr<ModuleCommunication> m_communication;
2024-08-05 17:42:27 +08:00
std::shared_ptr<CdcUpdater> m_updater;
2024-06-13 15:41:40 +08:00
std::shared_ptr<Database> m_database;
bool m_persistenceMode = true; // 模组持续识别
2024-07-31 16:08:38 +08:00
bool m_verifyExtendedMode = false;
2024-06-13 15:41:40 +08:00
bool m_persistenceModeStarted = false;
int m_persistenceVerifyInterval = 1;
QTimer *m_verifyTimer = nullptr;
2024-07-31 16:08:38 +08:00
ModuleCommunication::MessageId m_palmImageId; // 通过哪个指令获取的图片
uint32_t m_palmImageSize = 0;
QString m_palmUsername;
2024-08-07 11:45:13 +08:00
uint16_t m_palmId = ModuleCommunication::InvalidUserId;
2024-07-31 16:08:38 +08:00
QByteArray m_palmYImageBuffer;
2024-06-13 15:41:40 +08:00
std::chrono::system_clock::time_point m_startUploadTime;
2024-06-20 21:28:30 +08:00
uint32_t m_uploadImageSendedSize;
std::vector<uint8_t> m_uploadBuffer;
2024-08-16 19:05:50 +08:00
int m_currentUploadOperation = 0;
QString m_uploadPath;
QString m_uploadUsername;
bool m_imageUploadling = false;
2024-08-16 19:05:50 +08:00
bool m_imageUploadPersistenceMode = false;
2024-06-20 21:28:30 +08:00
2024-06-13 15:41:40 +08:00
std::shared_ptr<VideoPlayer> m_videoPlayer;
VideoFrameProvider *m_videoFrameProvider;
};
#endif // __APPLICATION_H__