#pragma once

#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO

#include <DebugLog.h>
#include <RS485_Driver.h>

class remoteIO
{
public:
    typedef enum {CH1, CH2, CH3, CH4, CH5, CH6, CH7, CH8, CH_MAX} channel_t;

private:
    const uint16_t REG_VERSION = 0x8000;
    const uint16_t REG_COILS = 0x0000;
    const uint16_t REG_INPUT = 0x0000;
    const uint16_t REG_ALLCOILS = 0x00FF;

public:
    remoteIO(const uint8_t address, drivers::MODBUS &bus);
    ~remoteIO();

    const bool setOut(const channel_t ch, const bool value);
    const bool toggleOut(const channel_t ch);
    const bool setOutPort(const std::vector<bool> values);

    const bool getOut(const channel_t ch, bool &value);
    const bool getOutPort(std::vector<bool> &values);

    const bool getIn(const channel_t input, bool &value);
    const bool getInPort(std::vector<bool> &values);

    void resetAll(const bool value);

private:
    bool m_initialized;
    drivers::MODBUS &m_bus;
    const uint8_t m_address;
};
