
#ifndef ETHERCAT_MASTER_DARRA_DIAGNOSTICS_H
#define ETHERCAT_MASTER_DARRA_DIAGNOSTICS_H

#pragma once

#include "../ethercat_types.h"
#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

struct dll;

#define ETG1510_DEVICE_TYPE          0x1000
#define ETG1510_DEVICE_NAME          0x1008
#define ETG1510_HW_VERSION           0x1009
#define ETG1510_SW_VERSION           0x100A
#define ETG1510_IDENTITY             0x1018
#define ETG1510_CONFIG_DATA_BASE     0x8000
#define ETG1510_INFO_DATA_BASE       0x9000
#define ETG1510_DIAG_DATA_BASE       0xA000
#define ETG1510_DETECT_MODULES       0xF002
#define ETG1510_MASTER_DIAG_DATA     0xF120
#define ETG1510_DIAG_INTERFACE_CTRL  0xF200

typedef enum {
    AL_ERR_NONE             = 0,
    AL_ERR_GENERAL          = 1,
    AL_ERR_STARTUP          = 2,
    AL_ERR_MAILBOX          = 3,
    AL_ERR_WATCHDOG         = 4,
    AL_ERR_SYNC             = 5,
    AL_ERR_DC               = 6,
    AL_ERR_MBX_EOE          = 7,
    AL_ERR_UNKNOWN          = 99
} DarraAlErrorClass;

DarraAlErrorClass diagnostics_classify_al_error(uint16_t alStatusCode);

int diagnostics_etg1510_read(const struct dll* dll,
                                    uint16_t master_index, uint16_t index, uint8_t subindex,
                                    uint8_t* outBuf, int bufSize);

int diagnostics_etg1510_write(const struct dll* dll,
                                     uint16_t master_index, uint16_t index, uint8_t subindex,
                                     const uint8_t* data, int len);

#ifdef __cplusplus
}
#endif

#endif
