package com.ld.igds.protocol.snap;
|
|
import com.ld.igds.camera.data.ApiSnapReq;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 工具类
|
*
|
* @author Andy
|
*/
|
public class SnapUtils {
|
|
/**
|
* 用于存放已经发送的命令信息
|
*/
|
public static Map<String, ApiSnapReq> contextMap = new HashMap<>();
|
|
/**
|
* 心跳管理MAP
|
*/
|
public static Map<String, Long> contextHeartBeat = new HashMap<>();
|
|
public static final String MSG_BEGIN = "<FZZY>";
|
public static final String MSG_END = "<EEEE>";
|
|
public static final String FUNC_ID_0 = "0";
|
public static final String FUNC_ID_1 = "1";
|
public static final String FUNC_ID_2 = "2";
|
|
|
public static final String ACTION_CODE_10 = "10";//断电
|
public static final String ACTION_CODE_11 = "11";//上电
|
public static final String ACTION_CODE_20 = "20";//心跳
|
public static final String ACTION_CODE_99 = "99";//其它
|
|
|
/**
|
* 单次心跳间隔时间 单位:秒
|
*/
|
public static final int HEART_BEAT_TIME = 30;
|
|
/**
|
* 生成TCP连接的KEY
|
*
|
* @param ip
|
* @param port
|
* @return
|
*/
|
public static String getServerKey(String ip, Integer port) {
|
return ip + ":" + port;
|
}
|
|
public static void addRequest(String orderId, ApiSnapReq param) {
|
contextMap.put("KEY_" + orderId, param);
|
}
|
|
public static ApiSnapReq getRequest(String orderId) {
|
ApiSnapReq apiSnapReq = contextMap.get("KEY_" + orderId);
|
if (null != apiSnapReq) {
|
removeRequest(orderId);
|
}
|
return apiSnapReq;
|
}
|
|
public static void removeRequest(String orderId) {
|
contextMap.remove(orderId);
|
}
|
|
|
|
public static void addHeartBeat(String ip, int port) {
|
contextHeartBeat.put(getServerKey(ip, port), System.currentTimeMillis());
|
}
|
|
public static Long getHeartBeat(String ip, int port) {
|
return contextHeartBeat.get(getServerKey(ip, port));
|
}
|
|
public static void delHeartBeat(String ip, int port) {
|
contextHeartBeat.remove(getServerKey(ip, port));
|
}
|
}
|