
#ifndef ETHERCAT_SLAVE_PDO_H
#define ETHERCAT_SLAVE_PDO_H

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

#ifdef __cplusplus
extern "C" {
#endif

#ifndef DYNAMIC_LOAD

void     PdoWriteInt8(uint16_t master, uint16_t slave, uint32_t offset, int8_t value);
void     PdoWriteInt16(uint16_t master, uint16_t slave, uint32_t offset, int16_t value);
void     PdoWriteInt32(uint16_t master, uint16_t slave, uint32_t offset, int32_t value);
void     PdoWriteUint8(uint16_t master, uint16_t slave, uint32_t offset, uint8_t value);
void     PdoWriteUint16(uint16_t master, uint16_t slave, uint32_t offset, uint16_t value);
void     PdoWriteUint32(uint16_t master, uint16_t slave, uint32_t offset, uint32_t value);

int8_t   PdoReadInt8(uint16_t master, uint16_t slave, uint32_t offset);
int16_t  PdoReadInt16(uint16_t master, uint16_t slave, uint32_t offset);
int32_t  PdoReadInt32(uint16_t master, uint16_t slave, uint32_t offset);
uint8_t  PdoReadUint8(uint16_t master, uint16_t slave, uint32_t offset);
uint16_t PdoReadUint16(uint16_t master, uint16_t slave, uint32_t offset);
uint32_t PdoReadUint32(uint16_t master, uint16_t slave, uint32_t offset);

uint8_t  PDOReadInputU8(uint16_t master, uint16_t slave, uint32_t offset);
int16_t  PDOReadInputI16(uint16_t master, uint16_t slave, uint32_t offset);
uint16_t PDOReadInputU16(uint16_t master, uint16_t slave, uint32_t offset);
int32_t  PDOReadInputI32(uint16_t master, uint16_t slave, uint32_t offset);
uint32_t PDOReadInputU32(uint16_t master, uint16_t slave, uint32_t offset);
float    PDOReadInputF32(uint16_t master, uint16_t slave, uint32_t offset);

BOOL     PDOWriteOutputU8(uint16_t master, uint16_t slave, uint32_t offset, uint8_t val);
BOOL     PDOWriteOutputI16(uint16_t master, uint16_t slave, uint32_t offset, int16_t val);
BOOL     PDOWriteOutputU16(uint16_t master, uint16_t slave, uint32_t offset, uint16_t val);
BOOL     PDOWriteOutputI32(uint16_t master, uint16_t slave, uint32_t offset, int32_t val);
BOOL     PDOWriteOutputU32(uint16_t master, uint16_t slave, uint32_t offset, uint32_t val);
BOOL     PDOWriteOutputF32(uint16_t master, uint16_t slave, uint32_t offset, float val);

BOOL     PDOReadDirect(uint16_t master_index, uint16_t slave_index, uint16_t pdo_index,
                        void* data_buffer, uint32_t buffer_size, uint32_t* bytes_read);
BOOL     PDOWriteDirect(uint16_t master_index, uint16_t slave_index, uint16_t pdo_index,
                         const void* data_buffer, uint32_t data_size);
uint32_t PDOBatchRead(uint16_t master_index, uint16_t* slave_indices, uint32_t slave_count,
                       void** data_buffers, uint32_t* buffer_sizes, uint32_t* bytes_read);
uint32_t PDOBatchWrite(uint16_t master_index, uint16_t* slave_indices, uint32_t slave_count,
                        const void** data_buffers, uint32_t* data_sizes);

void*    GetPDOStats(uint16_t master_index, uint16_t slave_index);
void     ResetPDOStats(uint16_t master_index, uint16_t slave_index);
void     EnablePDOMonitoring(BOOL enable);
BOOL     IsPDOMonitoringEnabled(void);
BOOL     GetPDOMapping(uint16_t master_index, uint16_t slave_index, uint16_t pdo_type,
                        void* mapping_buffer, uint32_t buffer_size, uint32_t* mapping_count);

void     GetPDOFrameLossStats(uint16_t master_index, uint8_t group,
                               uint32_t* total_lost, uint32_t* consecutive_lost,
                               uint32_t* max_consecutive_lost);
void     ResetPDOFrameLossStats(uint16_t master_index, uint8_t group);

#endif

#ifdef __cplusplus
}
#endif

#endif
