package com.example.user.myapp;

import android.app.Application;

import com.ghgande.j2mod.modbus.facade.ModbusTCPMaster;
import com.ghgande.j2mod.modbus.net.TCPMasterConnection;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;

public class GlobalState extends Application {

    private String ipAddress = "172.16.202.14";
    private int port = 502;
    private HashMap<Integer, Integer> mapMappingValue = new HashMap<Integer, Integer>();
    //
    public enum InputConfig {
        Q_COIL(8192, 8),
        VM_COIL2 (1, 8),
        VM_COIL3 (64, 8),
        AI_IR(0, 2),
        I_DI(0, 12);

        private int startReference;
        private int count;

        InputConfig (int startReference, int count) {
            this.startReference = startReference;
            this.count = count;
        }


        // getter/setter
        public int getStartReference() {
            return startReference;
        }

        public int getCount() {
            return count;
        }
    }

    public HashMap<Integer, Integer> getMapMappingValue() {
        initMappingValue();
        return mapMappingValue;
    }

    // getter/setter
    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    private void initMappingValue () {
        mapMappingValue.clear();
        mapMappingValue.put(InputConfig.VM_COIL3.getStartReference(), InputConfig.Q_COIL.getStartReference()); // 64/8192
        mapMappingValue.put(InputConfig.VM_COIL3.getStartReference() + 6, InputConfig.Q_COIL.getStartReference() + 1); // 70/8193
        mapMappingValue.put(InputConfig.VM_COIL3.getStartReference() + 1, InputConfig.Q_COIL.getStartReference() + 4); // 65/8196
        mapMappingValue.put(InputConfig.VM_COIL3.getStartReference() + 7, InputConfig.Q_COIL.getStartReference() + 5); // 71/8197
        mapMappingValue.put(InputConfig.VM_COIL3.getStartReference() + 4, InputConfig.Q_COIL.getStartReference() + 6); // 68/8198
        mapMappingValue.put(InputConfig.VM_COIL3.getStartReference() + 5, InputConfig.Q_COIL.getStartReference() + 7); // 69/8199
        mapMappingValue.put(InputConfig.VM_COIL3.getStartReference() + 2, InputConfig.Q_COIL.getStartReference() + 2); // 66/8194
        mapMappingValue.put(InputConfig.VM_COIL3.getStartReference() + 3, InputConfig.Q_COIL.getStartReference() + 3); // 67/8195
    }
}
