Device.java 4.47 KB
package com.adroplat.fist_switch.jni;


import com.adroplat.fist_switch.config.GlobalVar;
import com.adroplat.fist_switch.utils.ByteUtils;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

/**
 * Created by WLJ on 16-3-8.
 */
public class Device implements Serializable, Cloneable {
    private static final long serialVersionUID = -1055014034866886590L;

    private static Device instance;

    private Device() {
    }

    public static Device getInstance() {
        if (null == instance) {
            instance = new Device();
        }
        Device hub;
        try {
            hub = (Device) instance.clone();
        } catch (CloneNotSupportedException e) {
            hub = new Device();
        }
        return hub;
    }

    /**
     * 控制ID
     */
    private long ControllerId;
    /**
     * 命令类型
     */
    private int CmdType;
    /**
     * 错误码
     */
    private byte ErrorCode;
    /**
     * 设备IP
     */
    private byte[] DeviceIp;
    /**
     * 设备端口
     */
    private int DevicePort;
    /**
     * 设备公网IP
     */
    private byte[] MappedIp;
    /**
     * 设备公网端口
     */
    private int MappedPort;
    /**
     * 设备号
     */
    private byte[] DeviceNum;
    /**
     * 设备口令
     */
    private byte[] DeviceKey;
    /**
     * 是否是广域网控制
     */
    private boolean IsWan;
    /**
     * 子设备
     */
    private ArrayList<SubDevice> SubDevices;

    public long getControllerId() {
        return ControllerId;
    }

    public void setControllerId(long controllerId) {
        ControllerId = controllerId;
    }

    public int getCmdType() {
        return CmdType;
    }

    public void setCmdType(int cmdType) {
        CmdType = cmdType;
    }

    public byte getErrorCode() {
        return ErrorCode;
    }

    public void setErrorCode(byte errorCode) {
        ErrorCode = errorCode;
    }

    public byte[] getDeviceIp() {
        return DeviceIp;
    }

    public String getStringDeviceIp() {
        String strIp = "null";
        if (null != DeviceIp) {
            char point = '.';
            StringBuilder builder = new StringBuilder();
            for (byte b : DeviceIp) {
                builder.append(b & GlobalVar.MAX_BYTE).append(point);
            }
            builder.deleteCharAt(builder.length() - 1);
            strIp = builder.toString();
        }
        return strIp;
    }

    public void setDeviceIp(byte[] deviceIp) {
        DeviceIp = deviceIp;
    }

    public int getDevicePort() {
        return DevicePort;
    }

    public void setDevicePort(int devicePort) {
        DevicePort = devicePort;
    }

    public byte[] getMappedIp() {
        return MappedIp;
    }

    public void setMappedIp(byte[] mappedIp) {
        MappedIp = mappedIp;
    }

    public int getMappedPort() {
        return MappedPort;
    }

    public void setMappedPort(int mappedPort) {
        MappedPort = mappedPort;
    }

    public byte[] getDeviceNum() {
        return DeviceNum;
    }

    public void setDeviceNum(byte[] deviceNum) {
        DeviceNum = deviceNum;
    }

    public byte[] getDeviceKey() {
        return DeviceKey;
    }

    public String getDeviceStrKey() {
        String strKey = "";
        try {
            strKey = new String(DeviceKey, GlobalVar.CHARSET_UTF8);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return strKey;
    }

    public void setDeviceKey(byte[] deviceKey) {
        DeviceKey = deviceKey;
    }

    public boolean isWan() {
        return IsWan;
    }

    public void setWan(boolean wan) {
        IsWan = wan;
    }

    public ArrayList<SubDevice> getSubDevices() {
        return SubDevices;
    }

    public void setSubDevices(ArrayList<SubDevice> subDevices) {
        this.SubDevices = subDevices;
    }

    /**
     * DeviceNum转换成long
     *
     * @return
     */
    public long getLongDeviceNum() {
        return ByteUtils.macArrayToLong(DeviceNum);
    }

    /**
     * DeviceKey转换成long
     *
     * @return
     */
    public long getLongDeviceKey() {
        return ByteUtils.macArrayToLong(DeviceKey);
    }

    /**
     * MappedIp转换成int
     *
     * @return
     */
    public int getIntMappedIp() {
        return ByteUtils.byteArrayToInt(MappedIp);
    }

    /**
     * DeviceIp转换成int
     *
     * @return
     */
    public int getIntDeviceIp() {
        return ByteUtils.byteArrayToInt(DeviceIp);
    }
}