package com.dev.lock.data;
|
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.Date;
|
|
import com.base.ComBase;
|
|
public class ElectLock_State {
|
public static final int Unlock_Type_485 = 0; //485
|
public static final int Unlock_Type_ID = 1; //ID卡
|
public static final int Unlock_Type_Bluetooth = 2; //蓝牙
|
public static final int Unlock_Type_DI = 3; //DI
|
|
|
// public static int Reg_Count_Real = 8; //寄存器数量
|
// public static int Reg_Count_Real = 11; //寄存器数量
|
public static int Reg_Count_Real = 12; //寄存器数量
|
|
private Date record_time = new Date(0); //'更新时间',
|
private String gprs_sn; //'gprs模块SN码',
|
private String client_ip; //'设备IP地址',
|
private int already_id_count; //'当前锁已授权卡数量',
|
private int max_id_count; //'授权卡数量存储上限',
|
private int lock_state; //'电子锁状态[0-关 1-开]',
|
private String lock_version; //'软件版本号',
|
private int unlock_type; //'上一次开锁方式[0-485开锁 1-刷卡开锁 2-蓝牙开锁 3-DI开锁]',
|
private int unlock_id; //'上一次刷开开锁卡号[仅刷开开锁时有效]',
|
private int lock_addr; //'设备地址',
|
private int comm_count; //'通信计数',
|
private int err_tol_count; //'总错误计数',
|
private int err_count; //'连续错误计数',
|
private int op_cmd; //'控制命令',
|
private int id_card_set; //'授权ID卡号',
|
private int lock_addr_set; //'设置设备地址[慎用]',
|
private int workmodel; //工作模式【0-离线模式 1-在线模式】
|
|
private int lock_online; //锁具在线状态[0-离线 1-在线]
|
|
private boolean isIDOpen = false; //是否是ID开锁
|
private int last_unlock_type; //'上一次开锁方式[0-485开锁 1-刷卡开锁 2-蓝牙开锁 3-DI开锁]',
|
private int last_unlock_id; //'上一次刷开开锁卡号[仅刷开开锁时有效]',
|
|
private int[] mac_addr = new int[6]; //锁具蓝牙MAC地址
|
|
private String ctl_uname = ""; //操作用户名
|
|
|
private int lock_open_count; //'锁具总开启次数'
|
private Date last_update_time; //上一次锁具开启或关闭时间
|
|
public ElectLock_State() {
|
|
}
|
|
|
public boolean putByteBuffer(ByteBuffer buffer) {
|
if(buffer.limit() < (Reg_Count_Real*2)) {
|
System.out.println("实时信息返回长度错误" + buffer.limit());
|
return false;
|
}
|
|
buffer.order(ByteOrder.BIG_ENDIAN);
|
buffer.position(0);
|
|
this.already_id_count = ComBase.changeShortToInt(buffer.getShort()); //'当前锁已授权卡数量',
|
this.max_id_count = ComBase.changeShortToInt(buffer.getShort()); //'授权卡数量存储上限',
|
int tmp_lock_state = lock_state;
|
this.lock_state = ComBase.changeShortToInt(buffer.getShort()); //'电子锁状态[0-关 1-开]',
|
int ver = ComBase.changeShortToInt(buffer.getShort());
|
this.lock_version = " V"+ ver; //'软件版本号',
|
|
|
this.unlock_type = ComBase.changeShortToInt(buffer.getShort()); //'上一次开锁方式[0-485开锁 1-刷卡开锁 2-蓝牙开锁 3-DI开锁]',
|
this.unlock_id = (buffer.getInt()&0xFFFFFFFF); //'上一次刷开开锁卡号[仅刷开开锁时有效]',
|
this.lock_addr = ComBase.changeShortToInt(buffer.getShort()); //'设备地址',
|
|
for(int k =0;k<mac_addr.length;k++) {
|
mac_addr[k] = ComBase.changeByteToInt(buffer.get());
|
}
|
workmodel = ComBase.changeShortToInt(buffer.getShort());
|
|
System.out.println("工作模式:" + workmodel);
|
// System.out.println("BlutoothMAC:" + getLockMacAddr());
|
|
//System.out.println("this.lock_state:"+tmp_lock_state+"********lock_state:"+lock_state);
|
if(this.lock_state != tmp_lock_state) {
|
if(this.lock_state == 1) {
|
//锁具状态变化;锁从关闭变为打开
|
if(this.unlock_type == Unlock_Type_ID) {
|
//ID最近ID卡开锁
|
isIDOpen = true;
|
last_unlock_type = unlock_type; //'上一次开锁方式[0-485开锁 1-刷卡开锁 2-蓝牙开锁 3-DI开锁]',
|
last_unlock_id = unlock_id; //'上一次刷开开锁卡号[仅刷开开锁时有效]',
|
}
|
this.lock_open_count ++;
|
}
|
//锁具状态变化
|
this.last_update_time = new Date();
|
}
|
record_time = new Date();
|
buffer.compact();
|
return true;
|
}
|
|
public String getLockMacAddr() {
|
return String.format("%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0],mac_addr[1],mac_addr[2],mac_addr[3],mac_addr[4],mac_addr[5]).toUpperCase();
|
}
|
|
public void resetLockMacAddr() {
|
for(int n=0;n<mac_addr.length;n++) {
|
mac_addr[n] = 0xFF;
|
}
|
}
|
|
public int getLockDevId() {
|
return 10000000 + this.lock_addr;
|
}
|
|
public Date getRecord_time() {
|
return record_time;
|
}
|
|
public String getGprs_sn() {
|
return gprs_sn;
|
}
|
|
public String getClient_ip() {
|
return client_ip;
|
}
|
|
public int getAlready_id_count() {
|
return already_id_count;
|
}
|
|
public String getCtl_uname() {
|
return ctl_uname;
|
}
|
public int getLock_open_count() {
|
return lock_open_count;
|
}
|
|
public Date getLast_update_time() {
|
return last_update_time;
|
}
|
|
public void setLock_open_count(int lock_open_count) {
|
this.lock_open_count = lock_open_count;
|
}
|
|
public void setLast_update_time(Date last_update_time) {
|
this.last_update_time = last_update_time;
|
}
|
|
public void setCtl_uname(String ctl_uname) {
|
this.ctl_uname = ctl_uname;
|
}
|
|
|
public int getWorkmodel() {
|
return workmodel;
|
}
|
|
|
public void setWorkmodel(int workmodel) {
|
this.workmodel = workmodel;
|
}
|
|
|
public int getMax_id_count() {
|
return max_id_count;
|
}
|
|
public int getLock_state() {
|
return lock_state;
|
}
|
|
public String getLock_version() {
|
return lock_version;
|
}
|
|
public int getUnlock_type() {
|
return unlock_type;
|
}
|
|
public int getUnlock_id() {
|
return unlock_id;
|
}
|
|
public int getLock_addr() {
|
return lock_addr;
|
}
|
|
public int getComm_count() {
|
return comm_count;
|
}
|
|
public int getErr_tol_count() {
|
return err_tol_count;
|
}
|
|
public int getErr_count() {
|
return err_count;
|
}
|
|
public int getLock_online() {
|
return lock_online;
|
}
|
|
|
public void setLock_online(int lock_online) {
|
this.lock_online = lock_online;
|
}
|
|
|
public int getOp_cmd() {
|
return op_cmd;
|
}
|
|
public int getId_card_set() {
|
return id_card_set;
|
}
|
|
public int getLock_addr_set() {
|
return lock_addr_set;
|
}
|
|
public void setRecord_time(Date record_time) {
|
this.record_time = record_time;
|
}
|
|
public void setGprs_sn(String gprs_sn) {
|
this.gprs_sn = gprs_sn;
|
}
|
|
public void setClient_ip(String client_ip) {
|
this.client_ip = client_ip;
|
}
|
|
public void setAlready_id_count(int already_id_count) {
|
this.already_id_count = already_id_count;
|
}
|
|
public void setMax_id_count(int max_id_count) {
|
this.max_id_count = max_id_count;
|
}
|
|
public void setLock_state(int lock_state) {
|
this.lock_state = lock_state;
|
}
|
|
public void setLock_version(String lock_version) {
|
this.lock_version = lock_version;
|
}
|
|
public void setUnlock_type(int unlock_type) {
|
this.unlock_type = unlock_type;
|
}
|
|
public void setUnlock_id(int unlock_id) {
|
this.unlock_id = unlock_id;
|
}
|
|
public void setLock_addr(int lock_addr) {
|
this.lock_addr = lock_addr;
|
}
|
|
public void setComm_count(int comm_count) {
|
this.comm_count = comm_count;
|
}
|
|
public void setErr_tol_count(int err_tol_count) {
|
this.err_tol_count = err_tol_count;
|
}
|
|
public void setErr_count(int err_count) {
|
this.err_count = err_count;
|
}
|
|
public void setOp_cmd(int op_cmd) {
|
this.op_cmd = op_cmd;
|
}
|
|
public void setId_card_set(int id_card_set) {
|
this.id_card_set = id_card_set;
|
}
|
|
public void setLock_addr_set(int lock_addr_set) {
|
this.lock_addr_set = lock_addr_set;
|
}
|
|
public boolean isIDOpen() {
|
return isIDOpen;
|
}
|
|
|
public int getLast_unlock_type() {
|
return last_unlock_type;
|
}
|
|
|
public int getLast_unlock_id() {
|
return last_unlock_id;
|
}
|
|
|
public void setIDOpen(boolean isIDOpen) {
|
this.isIDOpen = isIDOpen;
|
}
|
|
|
public void setLast_unlock_type(int last_unlock_type) {
|
this.last_unlock_type = last_unlock_type;
|
}
|
|
|
public void setLast_unlock_id(int last_unlock_id) {
|
this.last_unlock_id = last_unlock_id;
|
}
|
|
|
public void addCommCount() {
|
this.comm_count ++ ;
|
if(this.comm_count > 999990000) {
|
this.comm_count = 0;
|
}
|
}
|
|
public void clearErrorCount() {
|
this.err_count = 0;
|
}
|
|
public void addErrorCount() {
|
this.err_tol_count ++ ;
|
if(this.err_tol_count > 999990000) {
|
this.err_tol_count = 0;
|
}
|
err_count++;
|
}
|
|
@Override
|
public String toString() {
|
return "ElectLock_State [record_time=" + record_time + ", gprs_sn=" + gprs_sn + ", client_ip=" + client_ip
|
+ ", already_id_count=" + already_id_count + ", max_id_count=" + max_id_count + ", lock_state="
|
+ lock_state + ", lock_version=" + lock_version + ", unlock_type=" + unlock_type + ", unlock_id="
|
+ unlock_id + ", lock_addr=" + lock_addr + ", comm_count=" + comm_count + ", err_tol_count="
|
+ err_tol_count + ", err_count=" + err_count + ", op_cmd=" + op_cmd + ", id_card_set=" + id_card_set
|
+ ", lock_addr_set=" + lock_addr_set + "]";
|
}
|
|
|
public static void main(String[] args) {
|
int[] ss = new int[] {1,58,65,21,54,23};
|
System.out.println(String.format("%02x:%02x:%02x:%02x:%02x:%02x", ss[0],ss[1],ss[2],ss[3],ss[4],ss[5]).toUpperCase());
|
}
|
}
|