package com.dev.electlock.data;
|
|
import java.nio.ByteBuffer;
|
import java.nio.ByteOrder;
|
import java.util.Date;
|
|
import com.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; //¼Ä´æÆ÷ÊýÁ¿
|
public static int Reg_Count_Real = 14; //¼Ä´æÆ÷ÊýÁ¿
|
|
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 bluetooth_st_state; //À¶ÑÀ¿ª¹Ø£º0-¹Ø±ÕÀ¶ÑÀ 1-¿ªÆôÀ¶ÑÀ
|
private int bluetooth_state; //À¶ÑÀ״̬£º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());
|
|
bluetooth_st_state = ComBase.changeShortToInt(buffer.getShort());
|
bluetooth_state = 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;
|
}
|
}
|
|
/**
|
* »ñÈ¡À¶ÑÀ¿ª¹Ø×´Ì¬
|
* @return
|
*/
|
public String getbluetooth_st_stateStr() {
|
String str = "À¶ÑÀδ֪¿ª¹Ø×´Ì¬";
|
if(bluetooth_st_state == 0) {
|
str = "¹Ø±ÕÀ¶ÑÀ";
|
}else if(workmodel == 1){
|
str = "¿ªÆôÀ¶ÑÀ";
|
}
|
return str;
|
}
|
|
/**
|
* »ñÈ¡À¶ÑÀ״̬
|
* @return
|
*/
|
public String getbluetooth_stateStr() {
|
String str = "À¶ÑÀδ֪״̬";
|
if(bluetooth_state == 0) {
|
str = "À¶ÑÀÒѹرÕ";
|
}else if(workmodel == 1){
|
str = "À¶ÑÀÒÑ¿ªÆô";
|
}
|
return str;
|
}
|
|
public String getLockState() {
|
String str = "±ÕËø";
|
if(lock_state == 1) {
|
str = "¿ªËø";
|
}
|
return str;
|
}
|
|
public String getWorkModel() {
|
String str = "δ֪ģʽ";
|
if(workmodel == 1) {
|
str = "ÔÚÏßģʽ";
|
}else if(workmodel == 0){
|
str = "ÀëÏßģʽ";
|
}
|
return str;
|
}
|
|
|
public Object getUnlockType() {
|
String str = "δ֪-" + unlock_type;
|
switch (unlock_type) {
|
case Unlock_Type_485:{
|
str = "RS485¿ªËø";
|
}break;
|
case Unlock_Type_ID:{
|
str = "Ë¢¿¨¿ªËø";
|
}break;
|
case Unlock_Type_Bluetooth:{
|
str = "À¶ÑÀ¿ªËø";
|
}break;
|
case Unlock_Type_DI:{
|
str = "DI¿ªËø";
|
}break;
|
}
|
return str;
|
}
|
|
|
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());
|
}
|
|
|
}
|