Tighten PN532 framing and NFC access locking so scan, read, write, and raw operations behave reliably on hardware, and correct Classic versus Type 2 tag classification so common cards hit the right code paths. Refresh the embedded web assets and launcher files to match the corrected firmware behavior. Made-with: Cursor
156 lines
2.9 KiB
C
156 lines
2.9 KiB
C
#include "nfc_engine/session_capture.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/semphr.h"
|
|
#include <string.h>
|
|
|
|
#define SESSION_CAPTURE_BYTES (48 * 1024)
|
|
|
|
static char s_buf[SESSION_CAPTURE_BYTES];
|
|
static size_t s_len;
|
|
static uint32_t s_lines;
|
|
static bool s_full;
|
|
static bool s_deep;
|
|
static SemaphoreHandle_t s_mu;
|
|
|
|
void session_capture_init(void)
|
|
{
|
|
s_mu = xSemaphoreCreateMutex();
|
|
session_capture_clear();
|
|
s_deep = false;
|
|
}
|
|
|
|
void session_capture_clear(void)
|
|
{
|
|
if (s_mu) {
|
|
xSemaphoreTake(s_mu, portMAX_DELAY);
|
|
}
|
|
s_len = 0;
|
|
s_lines = 0;
|
|
s_full = false;
|
|
s_buf[0] = 0;
|
|
if (s_mu) {
|
|
xSemaphoreGive(s_mu);
|
|
}
|
|
}
|
|
|
|
bool session_capture_is_full(void)
|
|
{
|
|
bool full = false;
|
|
if (s_mu) {
|
|
xSemaphoreTake(s_mu, portMAX_DELAY);
|
|
}
|
|
full = s_full;
|
|
if (s_mu) {
|
|
xSemaphoreGive(s_mu);
|
|
}
|
|
return full;
|
|
}
|
|
|
|
bool session_capture_deep_enabled(void)
|
|
{
|
|
bool deep = false;
|
|
if (s_mu) {
|
|
xSemaphoreTake(s_mu, portMAX_DELAY);
|
|
}
|
|
deep = s_deep;
|
|
if (s_mu) {
|
|
xSemaphoreGive(s_mu);
|
|
}
|
|
return deep;
|
|
}
|
|
|
|
void session_capture_set_deep(bool on)
|
|
{
|
|
if (s_mu) {
|
|
xSemaphoreTake(s_mu, portMAX_DELAY);
|
|
}
|
|
s_deep = on;
|
|
if (s_mu) {
|
|
xSemaphoreGive(s_mu);
|
|
}
|
|
}
|
|
|
|
size_t session_capture_max(void) { return sizeof(s_buf) - 2; }
|
|
|
|
void session_capture_get_status(size_t *used_bytes, uint32_t *line_count, bool *full)
|
|
{
|
|
if (s_mu) {
|
|
xSemaphoreTake(s_mu, portMAX_DELAY);
|
|
}
|
|
if (used_bytes) {
|
|
*used_bytes = s_len;
|
|
}
|
|
if (line_count) {
|
|
*line_count = s_lines;
|
|
}
|
|
if (full) {
|
|
*full = s_full;
|
|
}
|
|
if (s_mu) {
|
|
xSemaphoreGive(s_mu);
|
|
}
|
|
}
|
|
|
|
bool session_capture_append_line(const char *line)
|
|
{
|
|
if (!line) {
|
|
return false;
|
|
}
|
|
size_t l = strlen(line);
|
|
size_t need = l + 1; /* newline */
|
|
if (s_mu) {
|
|
xSemaphoreTake(s_mu, portMAX_DELAY);
|
|
}
|
|
if (s_full || s_len + need >= sizeof(s_buf)) {
|
|
s_full = true;
|
|
if (s_mu) {
|
|
xSemaphoreGive(s_mu);
|
|
}
|
|
return false;
|
|
}
|
|
memcpy(s_buf + s_len, line, l);
|
|
s_len += l;
|
|
s_buf[s_len++] = '\n';
|
|
s_buf[s_len] = 0;
|
|
s_lines++;
|
|
if (s_len + 2 >= sizeof(s_buf)) {
|
|
s_full = true;
|
|
}
|
|
if (s_mu) {
|
|
xSemaphoreGive(s_mu);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
size_t session_capture_export_size(void)
|
|
{
|
|
if (s_mu) {
|
|
xSemaphoreTake(s_mu, portMAX_DELAY);
|
|
}
|
|
size_t n = s_len;
|
|
if (s_mu) {
|
|
xSemaphoreGive(s_mu);
|
|
}
|
|
return n;
|
|
}
|
|
|
|
void session_capture_copy_to(char *dst, size_t cap, size_t *out_len)
|
|
{
|
|
if (s_mu) {
|
|
xSemaphoreTake(s_mu, portMAX_DELAY);
|
|
}
|
|
size_t n = s_len;
|
|
if (n > cap) {
|
|
n = cap;
|
|
}
|
|
if (dst && n) {
|
|
memcpy(dst, s_buf, n);
|
|
}
|
|
if (out_len) {
|
|
*out_len = n;
|
|
}
|
|
if (s_mu) {
|
|
xSemaphoreGive(s_mu);
|
|
}
|
|
}
|