SmartLockerTools/Analyser/Application.h

129 lines
5.1 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
2024-08-31 11:37:20 +08:00
QML_NAMED_ELEMENT(App)
QML_SINGLETON
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)
2024-10-25 17:18:09 +08:00
Q_PROPERTY(ModuleCommunication::MessageId persistenceCommand READ persistenceCommand WRITE setPersistenceCommand NOTIFY persistenceCommandChanged)
2024-06-13 15:41:40 +08:00
Q_PROPERTY(int persistenceVerifyInterval READ persistenceVerifyInterval WRITE setPersistenceVerifyInterval NOTIFY
persistenceVerifyIntervalChanged)
2024-10-25 17:18:09 +08:00
Q_PROPERTY(ModuleCommunication::MessageId currentMessageId READ currentMessageId NOTIFY currentMessageIdChanged)
2024-06-13 15:41:40 +08:00
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,
2024-09-05 16:36:54 +08:00
Warnging,
2024-06-13 15:41:40 +08:00
};
Q_ENUM(TipType)
void initializeLogger();
int exec();
2024-08-31 11:37:20 +08:00
static Application *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine);
2024-06-13 15:41:40 +08:00
Q_INVOKABLE QStringList availableSerialPorts() const;
2024-11-21 19:34:13 +08:00
Q_INVOKABLE QVariantList availableUsbVideoCameras() const;
2024-06-13 15:41:40 +08:00
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);
2024-09-11 15:45:19 +08:00
Q_INVOKABLE void enroll(const QString &username, bool strictMode, uint8_t excludeMode, bool persistence,
uint8_t timeout);
Q_INVOKABLE void enrollExtended(const QString &username, bool strictMode, uint8_t excludeMode, 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;
2024-10-25 17:18:09 +08:00
Q_INVOKABLE void resetModule();
2024-06-13 15:41:40 +08:00
bool connected() const;
bool uvcOpened() const;
2024-10-25 17:18:09 +08:00
ModuleCommunication::MessageId persistenceCommand() const;
void setPersistenceCommand(ModuleCommunication::MessageId command);
ModuleCommunication::MessageId currentMessageId() const;
2024-06-13 15:41:40 +08:00
int persistenceVerifyInterval() const;
void setPersistenceVerifyInterval(int interval);
signals:
void connectedChanged();
2024-10-25 17:18:09 +08:00
void persistenceCommandChanged();
2024-06-13 15:41:40 +08:00
void persistenceVerifyIntervalChanged();
2024-10-25 17:18:09 +08:00
void currentMessageIdChanged();
2024-06-13 15:41:40 +08:00
void uvcOpenedChanged();
void newVideoFrame();
void newLog(const QString &log);
2024-09-05 16:36:54 +08:00
void newStatusTip(TipType type, const QString &tip, const QString &detailMessage = "");
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);
2024-09-05 16:36:54 +08:00
void onErrorOccurred(ModuleCommunication::NoteId note, const QString &error, const QString &detailMessage);
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;
2024-10-25 17:18:09 +08:00
ModuleCommunication::MessageId m_persistenceCommand = ModuleCommunication::Idle; // 模组持续识别
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-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__