#ifndef __MODBUS_TCP_TC_H__
#define __MODBUS_TCP_TC_H__
#include "msystem.h"
#include "mthread.h"
#include "modbusTCP_contex.h"
#include "ccu_config.h"


typedef struct GUNSlot
{
    uint32_t   supportedMinPowerKW;
    uint32_t   supportedMaxPowerKW;
    
    uint16_t   supportedMaxVoltage;
    uint16_t   supportedMaxCurrent;
    uint16_t   supportedMinVoltage;
    uint16_t   supportedMinCurrent;

    uint16_t   permittedMaxCurrent;
    uint16_t   batteryVoltage;

    uint16_t   requestVoltage;
    uint16_t   requestCurrent;
    uint32_t   requestPowerKW;
}GUNSlot_t;

typedef struct modbusTCP_TC
{
    char connect_ip_string[64];
    short connect_port;
    short resv;

    int fd;
    // int pipe_fd[2];
    short  quit;
    uint16_t transID;

    modbusTCP_frame_t frame;
    pthread_mutex_t mutex;
    mthread_t thread;

    GUNSlot_t gunSlot[2];

    uint8_t rxbuff[2048];
    int rxbyte;
    uint8_t txbuff[2048];
    int txbyte;
}modbusTCP_TC_t;

int modbusTCP_TC_cmd_0x80(modbusTCP_TC_t* dev, uint8_t slave);
int modbusTCP_TC_cmd_0x83(modbusTCP_TC_t* dev, uint8_t slave, uint8_t mode, float requestVoltage, float requestCurrent);
int modbusTCP_TC_cmd_0x81(modbusTCP_TC_t* dev, uint8_t slave);
int modbusTCP_TC_cmd_0x82(modbusTCP_TC_t* dev, uint8_t slave);

void* modbusTCP_TC_loop(void* args);
int modbusTCP_TC_init(modbusTCP_TC_t* dev);
void modbusTCP_TC_exit(modbusTCP_TC_t* dev);

#endif//__MODBUS_TCP_TC_H__