add ocpp
This commit is contained in:
@@ -1,115 +1,32 @@
|
||||
#ifndef AUTH_H
|
||||
#define AUTH_H
|
||||
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include "auth_types.h" // enum + MAX LEN para API
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// Maximum length of an RFID tag (including null terminator)
|
||||
#define AUTH_TAG_MAX_LEN 30
|
||||
|
||||
/// Event structure emitted after a tag is read
|
||||
/* Evento auxiliar legado/útil (resultado local) */
|
||||
typedef struct {
|
||||
char tag[AUTH_TAG_MAX_LEN]; ///< The tag that was read
|
||||
bool authorized; ///< true if the tag is valid
|
||||
char tag[AUTH_TAG_MAX_LEN];
|
||||
bool authorized;
|
||||
} auth_event_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes the authentication system.
|
||||
*
|
||||
* - Loads configuration (enabled/disabled) from NVS
|
||||
* - Starts the Wiegand reader
|
||||
* - Emits AUTH_EVENT_INIT with current status
|
||||
*/
|
||||
void auth_init(void);
|
||||
void auth_init(void);
|
||||
void auth_set_mode(auth_mode_t mode);
|
||||
auth_mode_t auth_get_mode(void);
|
||||
|
||||
/**
|
||||
* @brief Enables or disables RFID-based authentication.
|
||||
*
|
||||
* This setting is persisted in NVS. If disabled,
|
||||
* all tags will be treated as authorized.
|
||||
*
|
||||
* @param value true to enable authentication, false to disable
|
||||
*/
|
||||
void auth_set_enabled(bool value);
|
||||
|
||||
/**
|
||||
* @brief Checks whether authentication is currently enabled.
|
||||
*
|
||||
* @return true if enabled, false if disabled
|
||||
*/
|
||||
bool auth_is_enabled(void);
|
||||
|
||||
/**
|
||||
* @brief Adds a new RFID tag to the authorized list.
|
||||
*
|
||||
* @param tag The RFID tag (max AUTH_TAG_MAX_LEN-1 characters)
|
||||
* @return true if the tag was added successfully,
|
||||
* false if it already exists or is invalid
|
||||
*/
|
||||
bool auth_add_tag(const char *tag);
|
||||
|
||||
/**
|
||||
* @brief Removes an existing RFID tag from the authorized list.
|
||||
*
|
||||
* @param tag The tag to remove
|
||||
* @return true if the tag was removed, false if not found
|
||||
*/
|
||||
bool auth_remove_tag(const char *tag);
|
||||
|
||||
/**
|
||||
* @brief Checks whether a tag is already registered.
|
||||
*
|
||||
* @param tag The tag to check
|
||||
* @return true if the tag exists, false otherwise
|
||||
*/
|
||||
bool auth_tag_exists(const char *tag);
|
||||
|
||||
/**
|
||||
* @brief Logs all currently registered tags via ESP logging.
|
||||
*/
|
||||
void auth_list_tags(void);
|
||||
|
||||
/**
|
||||
* @brief Processes a read RFID tag.
|
||||
*
|
||||
* - Checks whether it's authorized
|
||||
* - Emits AUTH_EVENT_TAG_PROCESSED event
|
||||
* - Starts expiration timer if authorized
|
||||
*
|
||||
* @param tag The tag that was read
|
||||
*/
|
||||
void auth_process_tag(const char *tag);
|
||||
|
||||
/**
|
||||
* @brief Enables registration mode for the next tag read.
|
||||
*
|
||||
* When registration mode is active, the next tag read
|
||||
* will be added to the authorized list automatically.
|
||||
* Mode is deactivated after one tag is registered.
|
||||
*/
|
||||
void auth_wait_for_tag_registration(void);
|
||||
|
||||
/**
|
||||
* @brief Returns the total number of registered tags.
|
||||
*
|
||||
* @return Number of valid tags
|
||||
*/
|
||||
int auth_get_tag_count(void);
|
||||
|
||||
/**
|
||||
* @brief Returns the tag string at the given index.
|
||||
*
|
||||
* @param index The index (0 ≤ index < auth_get_tag_count())
|
||||
* @return Pointer to the tag string, or NULL if index is invalid
|
||||
*/
|
||||
int auth_get_tag_count(void);
|
||||
const char *auth_get_tag_by_index(int index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AUTH_H
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
#pragma once
|
||||
#include "esp_event.h"
|
||||
|
||||
#define AUTH_EVENT_TAG_MAX_LEN 32
|
||||
#include "auth_types.h" // só tipos comuns; evita incluir auth.h
|
||||
|
||||
ESP_EVENT_DECLARE_BASE(AUTH_EVENTS);
|
||||
|
||||
/* IDs de eventos */
|
||||
typedef enum {
|
||||
AUTH_EVENT_TAG_PROCESSED,
|
||||
AUTH_EVENT_TAG_SAVED,
|
||||
AUTH_EVENT_ENABLED_CHANGED,
|
||||
AUTH_EVENT_INIT,
|
||||
AUTH_EVENT_TAG_PROCESSED = 0, // resultado LOCAL -> auth_tag_event_data_t
|
||||
AUTH_EVENT_TAG_VERIFY, // pedir validação OCPP -> auth_tag_verify_event_t
|
||||
AUTH_EVENT_TAG_SAVED, // registada (modo registo) -> auth_tag_event_data_t
|
||||
AUTH_EVENT_MODE_CHANGED, // modo alterado -> auth_mode_event_data_t
|
||||
AUTH_EVENT_INIT, // estado inicial -> auth_mode_event_data_t
|
||||
} auth_event_id_t;
|
||||
|
||||
/* Payloads */
|
||||
typedef struct {
|
||||
char tag[AUTH_EVENT_TAG_MAX_LEN];
|
||||
char tag[AUTH_TAG_MAX_LEN];
|
||||
bool authorized;
|
||||
} auth_tag_event_data_t;
|
||||
|
||||
typedef struct {
|
||||
bool enabled;
|
||||
} auth_enabled_event_data_t;
|
||||
char tag[AUTH_TAG_MAX_LEN];
|
||||
uint32_t req_id; // opcional p/ correlacionar
|
||||
} auth_tag_verify_event_t;
|
||||
|
||||
typedef struct {
|
||||
auth_mode_t mode;
|
||||
} auth_mode_event_data_t;
|
||||
|
||||
26
components/auth/include/auth_types.h
Normal file
26
components/auth/include/auth_types.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Tamanho máx. da tag (inclui NUL) */
|
||||
#define AUTH_TAG_MAX_LEN 30
|
||||
|
||||
/* Modos de autorização */
|
||||
typedef enum {
|
||||
AUTH_MODE_OPEN = 0, // Sem autenticação
|
||||
AUTH_MODE_LOCAL_RFID, // Lista local (NVS)
|
||||
AUTH_MODE_OCPP_RFID // Validação via OCPP/CSMS
|
||||
} auth_mode_t;
|
||||
|
||||
/* Converte enum -> "open"|"local"|"ocpp" (nunca NULL) */
|
||||
const char *auth_mode_to_str(auth_mode_t mode);
|
||||
|
||||
/* Converte "open"|"local"|"ocpp" (case-insensitive) -> enum */
|
||||
bool auth_mode_from_str(const char *s, auth_mode_t *out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user