
#ifndef ETHERCAT_SLAVE_CORE_H
#define ETHERCAT_SLAVE_CORE_H

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

#ifdef __cplusplus
extern "C" {
#endif

#ifndef DYNAMIC_LOAD

BOOL     GetSlaveIdentity(uint16_t master_index, uint16_t slave_index, ec_slave_identity_t* identity);
BOOL     VerifySlaveIdentity(uint16_t master_index, uint16_t slave_index,
                              ec_slave_identity_t* expected, BOOL check_rev, BOOL check_serial);
BOOL     VerifyAllSlaveIdentities(uint16_t master_index,
                                   ec_slave_identity_t* expected_identities,
                                   uint32_t slave_count, BOOL check_revision, BOOL check_serial,
                                   uint64_t* mismatch_mask);
BOOL     SetSlaveOptional(uint16_t master_index, uint16_t slave_index, BOOL is_optional);
BOOL     GetSlaveOptional(uint16_t master_index, uint16_t slave_index);
BOOL     SetSlaveSupportsFrameRepeat(uint16_t master_index, uint16_t slave_index, BOOL supports);
BOOL     GetSlaveSupportsFrameRepeat(uint16_t master_index, uint16_t slave_index);

BOOL     GetSlaveNeedsStartupReconfig(uint16_t master_index, uint16_t slave_index);
void     ClearSlaveNeedsStartupReconfig(uint16_t master_index, uint16_t slave_index);

BOOL     GetSlaveEsmTimeouts(uint16_t master_index, uint16_t slave_index, ec_esm_timeouts_t* timeouts);
BOOL     SetSlaveEsmTimeouts(uint16_t master_index, uint16_t slave_index, ec_esm_timeouts_t* timeouts);

int      GetTopology(uint16_t master, ec_topology_node_t* out, int max);

int      TopologyBuild(uint16_t master_index, ec_topology_node_t* out_nodes, int max_nodes);

int      TopologyGetChildren(uint16_t master_index, uint16_t parent_index,
                              uint16_t* out_children, int max_children);

int      TopologyGetRoots(uint16_t master_index, uint16_t* out_roots, int max_roots);

uint8_t  GetSlaveActivePorts(uint16_t master, uint16_t slave);

uint16_t GetSlaveParent(uint16_t master, uint16_t slave);

uint16_t GetSlaveConfigAddr(uint16_t master, uint16_t slave);
uint16_t GetSlaveAliasAddr(uint16_t master, uint16_t slave);
uint32_t GetSlaveVendorId(uint16_t master, uint16_t slave);
uint32_t GetSlaveProductCode(uint16_t master, uint16_t slave);
uint32_t GetSlaveRevision(uint16_t master, uint16_t slave);
uint32_t GetSlaveSerialNumber(uint16_t master, uint16_t slave);

uint16_t GetSlaveOutputBits(uint16_t master, uint16_t slave);
uint32_t GetSlaveOutputBytes(uint16_t master, uint16_t slave);
uint32_t GetSlaveOutputOffset(uint16_t master, uint16_t slave);
uint16_t GetSlaveInputBits(uint16_t master, uint16_t slave);
uint32_t GetSlaveInputBytes(uint16_t master, uint16_t slave);
uint32_t GetSlaveInputOffset(uint16_t master, uint16_t slave);

uint16_t GetSlaveMailboxProto(uint16_t master, uint16_t slave);
uint16_t GetSlaveMailboxWriteLength(uint16_t master, uint16_t slave);
uint16_t GetSlaveMailboxWriteOffset(uint16_t master, uint16_t slave);
uint16_t GetSlaveMailboxReadLength(uint16_t master, uint16_t slave);
uint16_t GetSlaveMailboxReadOffset(uint16_t master, uint16_t slave);

BOOL     GetSlaveHasDC(uint16_t master, uint16_t slave);
uint16_t GetSlaveDCActive(uint16_t master, uint16_t slave);
int32_t  GetSlaveDCCycle0(uint16_t master, uint16_t slave);
int32_t  GetSlaveDCCycle1(uint16_t master, uint16_t slave);
int32_t  GetSlaveDCShift(uint16_t master, uint16_t slave);
uint16_t GetSlaveDCNext(uint16_t master, uint16_t slave);
uint16_t GetSlaveDCPrevious(uint16_t master, uint16_t slave);

uint8_t  GetSlaveCoEDetails(uint16_t master, uint16_t slave);
uint8_t  GetSlaveFoEDetails(uint16_t master, uint16_t slave);
uint8_t  GetSlaveEoEDetails(uint16_t master, uint16_t slave);
uint8_t  GetSlaveSoEDetails(uint16_t master, uint16_t slave);

int32_t  GetSlaveDCReceiveTimeA(uint16_t master, uint16_t slave);
int32_t  GetSlaveDCReceiveTimeB(uint16_t master, uint16_t slave);
int32_t  GetSlaveDCReceiveTimeC(uint16_t master, uint16_t slave);
int32_t  GetSlaveDCReceiveTimeD(uint16_t master, uint16_t slave);

uint8_t  GetSlavePhysicalType(uint16_t master, uint16_t slave);
BOOL     GetSlaveBlockLRW(uint16_t master, uint16_t slave);
uint8_t  GetSlaveEep8Byte(uint16_t master, uint16_t slave);
uint8_t  GetSlaveEepPDI(uint16_t master, uint16_t slave);

BOOL     GetSlaveIsLost(uint16_t master, uint16_t slave);
int16_t  GetSlaveEbusCurrent(uint16_t master, uint16_t slave);
uint8_t  GetSlaveTopologyType(uint16_t master, uint16_t slave);
uint8_t  GetSlaveEntryPort(uint16_t master, uint16_t slave);
uint8_t  GetSlaveParentPort(uint16_t master, uint16_t slave);

uint8_t  GetSlaveOutputStartBit(uint16_t master, uint16_t slave);
uint8_t  GetSlaveInputStartBit(uint16_t master, uint16_t slave);

uint8_t  GetSlaveFMMU0Function(uint16_t master, uint16_t slave);
uint8_t  GetSlaveFMMU1Function(uint16_t master, uint16_t slave);
uint8_t  GetSlaveFMMU2Function(uint16_t master, uint16_t slave);
uint8_t  GetSlaveFMMU3Function(uint16_t master, uint16_t slave);

uint8_t  GetSlaveMbxCount(uint16_t master, uint16_t slave);

int32_t  GetSlavePDelay(uint16_t master, uint16_t slave);

int32_t  GetSlaveDCParentPort(uint16_t master, uint16_t slave);

uint8_t  GetSlaveConsumedPorts(uint16_t master, uint16_t slave);

uint16_t GetSlaveParentStation(uint16_t master, uint16_t slave);

int      GetSlaveName(uint16_t master, uint16_t slave, char* buf, int buf_size);
int      GetSlaveDeviceName(uint16_t master, uint16_t slave, char* buf, int buf_size);

BOOL     GetSlaveHasEsi(uint16_t master, uint16_t slave);

BOOL     SetSlaveEsiFile(uint16_t master, uint16_t slave, const char* name);

BOOL     GetSlaveEsiVersion(uint16_t master, uint16_t slave, char* buf, int buf_size);

BOOL     GetSlaveHasMDP(uint16_t master, uint16_t slave);

BOOL     GetSlaveVendorName(uint16_t master, uint16_t slave, char* buf, int buf_size);

BOOL     GetSlaveRedundancyActivated(uint16_t master, uint16_t slave);

BOOL     GetSlavePrimaryLinkBroken(uint16_t master, uint16_t slave);

BOOL     GetSlaveSecondaryLinkBroken(uint16_t master, uint16_t slave);

BOOL     WriteSlaveDLPORT(uint16_t master_index, uint16_t slave_index, uint8_t dlport_value);

BOOL     ReadSlaveDLPORT(uint16_t master_index, uint16_t slave_index, uint8_t* dlport_value);

BOOL     ReadSlaveRegister(uint16_t master_index, uint16_t slave_index,
                           uint16_t reg_addr, uint8_t* data, uint32_t len);

BOOL     WriteSlaveRegister(uint16_t master_index, uint16_t slave_index,
                            uint16_t reg_addr, uint8_t* data, uint32_t len);

int      SIIReadWord(uint16_t master_index, uint16_t slave_index,
                     uint16_t word_addr, uint16_t* out_value);

int      SIIWriteWord(uint16_t master_index, uint16_t slave_index,
                      uint16_t word_addr, uint16_t value);

void     DebugSlaveHasDC(uint16_t master_index, uint16_t slave_index);

#endif

#ifdef __cplusplus
}
#endif

#endif
