Læser og kalder API som det skal. OTA virker Opsætning af wifi via ESP32's eget hotspot virker Mangler at få lavet skrivning, men det bliver v2.
121 lines
2.5 KiB
C++
121 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
#include <PN5180ISO15693.h>
|
|
|
|
#include "FilamentGuardApiClient.h"
|
|
#include "FilamentGuardDeviceInfo.h"
|
|
#include "FilamentGuardLogger.h"
|
|
#include "FilamentGuardTagRead.h"
|
|
#include "FilamentGuardTagReadSerializer.h"
|
|
#include "OpenPrintTagData.h"
|
|
#include "OpenPrintTagParser.h"
|
|
|
|
#ifndef FILAMENT_GUARD_NFC_DIAGNOSTICS
|
|
#define FILAMENT_GUARD_NFC_DIAGNOSTICS 0
|
|
#endif
|
|
|
|
class Pn5180Reader
|
|
{
|
|
public:
|
|
Pn5180Reader(
|
|
FilamentGuardLogger& logger,
|
|
uint8_t nssPin,
|
|
uint8_t busyPin,
|
|
uint8_t resetPin);
|
|
|
|
void begin();
|
|
|
|
void setDeviceInfo(
|
|
const FilamentGuardDeviceInfo& deviceInfo);
|
|
|
|
void printVersionInformation();
|
|
|
|
const String& getReaderId() const;
|
|
|
|
bool scanForTag(
|
|
uint8_t* uid,
|
|
uint16_t& signalStrength);
|
|
|
|
bool registerTag(
|
|
const uint8_t* uid,
|
|
uint8_t uidLength);
|
|
|
|
bool isActiveTag(
|
|
const uint8_t* uid,
|
|
uint8_t uidLength) const;
|
|
|
|
bool hasActiveTag() const;
|
|
|
|
void markTagPresent();
|
|
|
|
bool markTagMissing();
|
|
|
|
private:
|
|
enum class TagProtocol : uint8_t
|
|
{
|
|
None,
|
|
Iso15693
|
|
};
|
|
|
|
static constexpr uint8_t RequiredMissingScans = 3;
|
|
|
|
PN5180ISO15693 iso15693Reader;
|
|
|
|
OpenPrintTagParser openPrintTagParser;
|
|
FilamentGuardTagReadSerializer tagReadSerializer;
|
|
FilamentGuardApiClient apiClient;
|
|
FilamentGuardLogger& logger;
|
|
|
|
FilamentGuardDeviceInfo deviceInfo;
|
|
String readerId;
|
|
|
|
uint8_t lastUid[10] = {};
|
|
uint8_t lastUidLength = 0;
|
|
|
|
TagProtocol activeProtocol = TagProtocol::None;
|
|
uint8_t missingScanCount = 0;
|
|
|
|
#if FILAMENT_GUARD_NFC_DIAGNOSTICS
|
|
unsigned long nextDiagnosticAt = 0;
|
|
#endif
|
|
|
|
void handleTagMissing();
|
|
|
|
bool performInventory(
|
|
uint8_t* uid);
|
|
|
|
bool readIso15693BlockRange(
|
|
const uint8_t* uid,
|
|
uint8_t firstBlock,
|
|
uint8_t blockCount,
|
|
uint8_t* blockData,
|
|
uint8_t blockSize);
|
|
|
|
bool isSameUid(
|
|
const uint8_t* uid,
|
|
uint8_t uidLength) const;
|
|
|
|
void rememberUid(
|
|
const uint8_t* uid,
|
|
uint8_t uidLength,
|
|
TagProtocol protocol);
|
|
|
|
void clearLastUid();
|
|
|
|
String formatUid(
|
|
const uint8_t* uid,
|
|
uint8_t uidLength,
|
|
bool reverseOrder) const;
|
|
|
|
bool dumpIso15693Tag(
|
|
const uint8_t* uid,
|
|
uint8_t uidLength);
|
|
|
|
void logTagRead(
|
|
const FilamentGuardTagRead& tagRead) const;
|
|
|
|
void sendTagRead(
|
|
const FilamentGuardTagRead& tagRead) const;
|
|
};
|