45 lines
952 B
C
45 lines
952 B
C
#ifndef CLIENT_HANDLER_H
|
|
#define CLIENT_HANDLER_H
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/_intsup.h>
|
|
#include <sys/types.h>
|
|
|
|
#define MAX_CLIENTS 16
|
|
#define MAC_LENGTH 6
|
|
|
|
enum ClientErrors {
|
|
CLIENT_OK = 0,
|
|
CLIENT_EXISTS = -1,
|
|
CLIENT_DOES_NOT_EXISTS = -2,
|
|
CLIENT_LIST_FULL = -3,
|
|
CLIENT_INVALID_ID = -4,
|
|
};
|
|
|
|
typedef struct {
|
|
bool slotIsUsed;
|
|
bool isAvailable;
|
|
uint8_t clientID;
|
|
uint8_t macAddr[MAC_LENGTH];
|
|
TickType_t lastSuccessfullPing;
|
|
TickType_t lastPing;
|
|
uint16_t clientVersion;
|
|
} ClientInfo;
|
|
|
|
typedef struct {
|
|
ClientInfo Clients[MAX_CLIENTS];
|
|
uint8_t ClientCount;
|
|
} ClientList;
|
|
|
|
int get_client_id(ClientList *list, const uint8_t *client_mac);
|
|
int add_client(ClientList *list, const uint8_t *client_mac);
|
|
int remove_client(ClientList *list, const uint8_t clientid);
|
|
int get_next_free_slot(ClientList *list);
|
|
|
|
#endif
|