/*
 * Copyright (c) 2021, Erich Styger
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef ESP32_MAC_H_
#define ESP32_MAC_H_

#include "platform.h"
#if PL_CONFIG_USE_IDENTIFY
#include "Identify.h"
#include <stdint.h>
#include <stddef.h> /* for size_t */

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
  const char *hostName; /* name for module, usually matching robot, e.g. "AdisRobotR8" */
  ID_Robot_e robotID;   /* ID of the robot */
  const char *macStr;   /* ESP32 MAC, e.g. "d8:a0:1d:42:ed:50" */
  const char *eee_id;   /* eee network id/name */
  const char *eee_pwd;  /* eee network password */
} ESP32_Device_t;

/*!
 * \brief transforms a binary MAC into a string, e.g. "d8:a0:1d:42:ed:50"
 * \param mac binary MAC
 * \param buf buffer where to store the string
 * \param bufSize size of buffer
 */
void ESP32_MacToString(uint8_t mac[6], uint8_t *buf, size_t bufSize);

/*!
 * \brief return for a given MAC address string (e.g. "d8:a0:1d:42:e2:08") the device or NULL if not found.
 */
const ESP32_Device_t *ESP32_MacStrGetDevice(const char *macStr);

/*!
 * \brief Read the MAC address into buffer
 * \param mac buffer where to store the MAC address
 */
void ESP32_MacRead(uint8_t mac[6]);

/*!
 * \brief return a device configuration based on MAC address
 * \return pointer to device configuration. Pointing to a dummy configuration if MAC is not found in list.
 */
const ESP32_Device_t *ESP32_GetDeviceConfig(void);

/*!
 * \brief Module initialization
 */
void ESP32_MacInit(void);

#endif /* PL_CONFIG_USE_IDENTIFY */

#ifdef __cplusplus
}  /* extern "C" */
#endif

#endif /* ESP32_MAC_H_ */
