2022-11-01 05:06:23 +08:00
|
|
|
#ifndef DEVICEUSBLOG_H
|
|
|
|
#define DEVICEUSBLOG_H
|
|
|
|
|
|
|
|
#include "../../VNA_embedded/Application/Communication/Protocol.hpp"
|
|
|
|
|
|
|
|
#include "savable.h"
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QObject>
|
2022-11-01 08:12:04 +08:00
|
|
|
#include <mutex>
|
2022-11-01 05:06:23 +08:00
|
|
|
|
|
|
|
class DeviceUSBLog : public QObject, public Savable
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static DeviceUSBLog& getInstance() {
|
|
|
|
static DeviceUSBLog instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
DeviceUSBLog(const DeviceUSBLog&) = delete;
|
|
|
|
virtual ~DeviceUSBLog();
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
void addPacket(Protocol::PacketInfo &p, QString serial = "");
|
|
|
|
void addInvalidBytes(const uint8_t *bytes, uint16_t len, QString serial = "");
|
|
|
|
|
|
|
|
virtual nlohmann::json toJSON() override;
|
|
|
|
virtual void fromJSON(nlohmann::json j) override;
|
|
|
|
|
|
|
|
|
|
|
|
class LogEntry : public Savable {
|
|
|
|
public:
|
|
|
|
LogEntry()
|
|
|
|
: type(Type::InvalidBytes), timestamp(QDateTime()), serial(""), p(nullptr) {}
|
2022-11-01 08:12:04 +08:00
|
|
|
~LogEntry() {
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogEntry(const LogEntry &e);
|
2022-11-01 05:06:23 +08:00
|
|
|
|
|
|
|
enum class Type {
|
|
|
|
Packet,
|
|
|
|
InvalidBytes,
|
|
|
|
};
|
|
|
|
Type type;
|
|
|
|
QDateTime timestamp;
|
|
|
|
QString serial;
|
|
|
|
std::vector<uint8_t> bytes;
|
|
|
|
Protocol::PacketInfo *p;
|
|
|
|
unsigned int storageSize() const {
|
|
|
|
unsigned long size = sizeof(type) + sizeof(timestamp) + serial.size();
|
|
|
|
switch(type) {
|
|
|
|
case Type::InvalidBytes: size += bytes.size(); break;
|
|
|
|
case Type::Packet: size += sizeof(Protocol::PacketInfo); break;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nlohmann::json toJSON() override;
|
|
|
|
virtual void fromJSON(nlohmann::json j) override;
|
|
|
|
};
|
|
|
|
|
2022-11-01 08:12:04 +08:00
|
|
|
LogEntry getEntry(unsigned int index);
|
|
|
|
|
|
|
|
unsigned long getUsedStorageSize() const;
|
|
|
|
unsigned long getMaxStorageSize() const;
|
2022-11-01 05:06:23 +08:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void entryAdded(const LogEntry &e);
|
|
|
|
|
|
|
|
private:
|
|
|
|
DeviceUSBLog();
|
|
|
|
|
|
|
|
void addEntry(const LogEntry &e);
|
|
|
|
|
|
|
|
unsigned long maxStorageSize;
|
|
|
|
unsigned long usedStorageSize;
|
|
|
|
std::deque<LogEntry> entries;
|
2022-11-01 08:12:04 +08:00
|
|
|
|
|
|
|
std::mutex access;
|
2022-11-01 05:06:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DEVICEUSBLOG_H
|