DELL
2025-04-28 eb746715527db9b42740db84bb576735185e21cd
ElectLock_Monitor/src/com/dev/lock/data/ElectLock_State.java
@@ -7,9 +7,23 @@
import com.base.ComBase;
public class ElectLock_State {
   public static int Reg_Count_Real = 8;      //寄存器数量
   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
   
   private Date record_time;         //'更新时间',
//   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;      //寄存器数量
   public static int Reg_Count_Card = 100;      //读取已授权电池卡寄存器数量
   private int lock_id;            //锁具ID[当前需要操作的锁具ID号]
   private Date record_time = new Date(0);         //'更新时间',
   private String gprs_sn;            //'gprs模块SN码',
   private String client_ip;         //'设备IP地址',
   private int already_id_count;      //'当前锁已授权卡数量',
@@ -23,10 +37,30 @@
   private int err_tol_count;         //'总错误计数',
   private int err_count;            //'连续错误计数',
   private int op_cmd;               //'控制命令',
   private int id_card_set;         //'授权ID卡号',
   private long 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 bluetooth_st_state;      //蓝牙开关:0-关闭蓝牙  1-开启蓝牙
   private int bluetooth_state;      //蓝牙状态:0:蓝牙已关闭,1:蓝牙已开启
   private int lock_open_count;   //'锁具总开启次数'
   private Date last_update_time = new Date(0);   //上一次锁具开启或关闭时间
   private long[] id_cards = new long[ElectLock_ComBase.Lock_MaxCardCount];
   private int readCount = 0;            //读取数据次数,用于读取已授权卡号
   
   public ElectLock_State() {
      
@@ -44,19 +78,116 @@
      
      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());            //'设备地址',
      
      //System.out.println(this);
      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("bluetooth_st_state:" + getBluetooth_st_state());
//      System.out.println("bluetooth_state:" + getBluetooth_state());
//      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();
      readCount ++;
      if(readCount >= 999998) {
         readCount = 0;
      }
      buffer.compact();
      return true;
   }
   
   public boolean putCardByteBuffer(ByteBuffer buffer,int idx) {
      if(buffer.limit() < (Reg_Count_Card*2)) {
         System.out.println("实时信息返回长度错误" + buffer.limit());
         return false;
      }
      buffer.order(ByteOrder.BIG_ENDIAN);
      buffer.position(0);
      for(int k = idx;k<(idx+50) && k < ElectLock_ComBase.Lock_MaxCardCount;k++) {
         id_cards[k] = (buffer.getInt()&0xFFFFFFFF);
      }
      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 getReadCount() {
      return readCount;
   }
   public long[] getId_cards() {
      return id_cards;
   }
   public void setId_cards(long[] id_cards) {
      this.id_cards = id_cards;
   }
   public int getBluetooth_st_state() {
      return bluetooth_st_state;
   }
   public int getBluetooth_state() {
      return bluetooth_state;
   }
   public void setBluetooth_st_state(int bluetooth_st_state) {
      this.bluetooth_st_state = bluetooth_st_state;
   }
   public void setBluetooth_state(int bluetooth_state) {
      this.bluetooth_state = bluetooth_state;
   }
   public int getLockDevId() {
      return 10000000 + this.lock_addr;
   }
@@ -76,6 +207,40 @@
   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;
@@ -127,7 +292,7 @@
      return op_cmd;
   }
   public int getId_card_set() {
   public long getId_card_set() {
      return id_card_set;
   }
@@ -191,13 +356,56 @@
      this.op_cmd = op_cmd;
   }
   public void setId_card_set(int id_card_set) {
   public void setId_card_set(long 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 int getLock_id() {
      return lock_id;
   }
   public int getLockAddr() {
      return lock_id%1000;
   }
   public void setLock_id(int lock_id) {
      this.lock_id = lock_id;
   }
   public void addCommCount() {
      this.comm_count ++ ;
@@ -218,7 +426,6 @@
      err_count++;
   }
   @Override
   public String toString() {
      return "ElectLock_State [record_time=" + record_time + ", gprs_sn=" + gprs_sn + ", client_ip=" + client_ip
@@ -229,4 +436,9 @@
            + ", 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());
   }
}