ElectLock_Monitor/bin/com/dev/lock/comm/Lock_SocketClient_Thread.classBinary files differ
ElectLock_Monitor/bin/com/dev/lock/comm/Lock_Task_SQL.classBinary files differ
ElectLock_Monitor/bin/com/dev/lock/data/ElectLock_Array.classBinary files differ
ElectLock_Monitor/bin/com/dev/lock/data/ElectLock_ComBase.classBinary files differ
ElectLock_Monitor/bin/com/dev/lock/data/ElectLock_State.classBinary files differ
ElectLock_Monitor/bin/com/sql/Sql_Mysql.classBinary files differ
ElectLock_Monitor/bin/com/version_inf/version_inf.txt
@@ -7,6 +7,10 @@ 设备ID:10000001 V1.114 edit by lijun 2025-04-22 1.新增定时开启以及关闭蓝牙功能。 2.添加读取锁具已授权ID卡信息功能。 V1.113 edit by lijun 2025-03-15 1.新增远程开启以及关闭蓝牙功能 2.修复锁具开启之后记录bug ElectLock_Monitor/bin/main/main_ElectLock_Monitor.classBinary files differ
ElectLock_Monitor/src/com/dev/lock/comm/Lock_SocketClient_Thread.java
@@ -18,6 +18,7 @@ import com.config.AppConfig; import com.dev.lock.data.ElectLock_Array; import com.dev.lock.data.ElectLock_AuthIdcard; import com.dev.lock.data.ElectLock_Bl; import com.dev.lock.data.ElectLock_ComBase; import com.dev.lock.data.ElectLock_Inf; import com.dev.lock.data.ElectLock_State; @@ -54,6 +55,8 @@ private int NowLockIdx = 0; //当前读取状态的锁具索引 private int ErrorCount = 0; //连续错误计数,连接错误计数 private ElectLock_Bl bl = null; public Lock_SocketClient_Thread(MysqlConnPool pool,ElectLock_Array GB_Lock_Array ,AppConfig config,Socket tmp_socket) { this.pool = pool; @@ -163,7 +166,7 @@ }else if(mLock_param.getOp_cmd() == ElectLock_ComBase.CMD_OpenBluetooth) { //开启蓝牙 mRtu_Tx.mkBusRtu((mLock_param.getLockAddr()%255),MyModBusRtu.CMD_TYPE_WRITE_STD, ElectLock_ComBase.LOCK_SET_Bluetooth_ADDR, ElectLock_ComBase.RegCount_Sigle); System.out.println("mLock_param.getId_card_set():"+mLock_param.getId_card_set()); //System.out.println("mLock_param.getId_card_set():"+mLock_param.getId_card_set()); if(SocketComm(mRtu_Tx, ComBase.mkUInt16Buffer(ElectLock_ComBase.Lock_Bluetooth_Open))) { mLock_param.setOp_cmd(ElectLock_ComBase.CMD_OpenBluetooth_Ack); //tmp_log = new ElectLock_Ctl_Log(mLock_param.getLock_id(), ElectLock_ComBase.CtlType_BluetoothOpen, true,0,mLock_param.getCtl_uname()); @@ -192,7 +195,7 @@ } if((runCount%(16/MaxLockCount)) == 0) { if((runCount%(17/MaxLockCount)) == 1) { //读取锁具的实时状态 mRtu_Tx.mkBusRtu((mLock_State[NowLockIdx].getLockAddr()%255),MyModBusRtu.CMD_TYPE_READ_INPUT, ElectLock_ComBase.LOCK_REAL_ADDR, ElectLock_State.Reg_Count_Real); if(SocketComm(mRtu_Tx, ByteBuffer.allocate(0))) { @@ -230,6 +233,48 @@ Thread.sleep(1000); } } } } //查询当前蓝牙开启计划 bl = Lock_Task_SQL.queryBluetoothOpenPlan(pool, ele_lock[NowLockIdx].getLock_id()); if(null != bl) { //有启用的计划,定时开启蓝牙 if(mLock_State[NowLockIdx].getBluetooth_state() == ElectLock_ComBase.Lock_Bluetooth_Close) { mRtu_Tx.mkBusRtu((mLock_State[NowLockIdx].getLockAddr()%255),MyModBusRtu.CMD_TYPE_WRITE_STD, ElectLock_ComBase.LOCK_SET_Bluetooth_ADDR, ElectLock_ComBase.RegCount_Sigle); //System.out.println("mLock_param.getId_card_set():"+mLock_param.getId_card_set()); if(SocketComm(mRtu_Tx, ComBase.mkUInt16Buffer(ElectLock_ComBase.Lock_Bluetooth_Open))){ logger.info("定时开启蓝牙成功"); }else { logger.info("定时开启蓝牙失败"); } } bl = null; } //查询当前蓝牙关闭计划 bl = Lock_Task_SQL.queryBluetoothClosePlan(pool, ele_lock[NowLockIdx].getLock_id()); if(null != bl) { //有启用的计划,定时关闭蓝牙 if(mLock_State[NowLockIdx].getBluetooth_state() == ElectLock_ComBase.Lock_Bluetooth_Open) { mRtu_Tx.mkBusRtu((mLock_State[NowLockIdx].getLockAddr()%255),MyModBusRtu.CMD_TYPE_WRITE_STD, ElectLock_ComBase.LOCK_SET_Bluetooth_ADDR, ElectLock_ComBase.RegCount_Sigle); //System.out.println("mLock_param.getId_card_set():"+mLock_param.getId_card_set()); if(SocketComm(mRtu_Tx, ComBase.mkUInt16Buffer(ElectLock_ComBase.Lock_Bluetooth_Close))){ logger.info("定时关闭蓝牙成功"); }else { logger.info("定时关闭蓝牙失败"); } } bl = null; } int cnt = mLock_State[NowLockIdx].getReadCount()%4; if(cnt == 0 || cnt == 1) { logger.error(mLock_State[NowLockIdx].getLock_id() + " ReadIDCardCount " + cnt); mRtu_Tx.mkBusRtu((mLock_State[NowLockIdx].getLockAddr()%255),MyModBusRtu.CMD_TYPE_READ_INPUT, (ElectLock_ComBase.LOCK_IDCard1_ADDR + cnt*50), ElectLock_State.Reg_Count_Card); if(SocketComm(mRtu_Tx, ByteBuffer.allocate(0))) { //更新当前锁具的ID卡 Lock_Task_SQL.updateLock_IdCard_Table(pool, mLock_State[NowLockIdx]); } } @@ -486,7 +531,7 @@ this.mLock_State[NowLockIdx].addErrorCount(); addErrorCount(); } finally { if(getErrorCount() > 6) { if(getErrorCount() > 10) { logger.info("设备:DevIp:" + client_ip + " DevId:" + client_id/10000 + "XXXX 通信超时即将断开连接..."); S_thread_run_flag = false; } @@ -507,6 +552,16 @@ if(ElectLock_ComBase.LOCK_REAL_ADDR == rtu.reg_addr) { //读取实时数据 if(mLock_State[NowLockIdx].putByteBuffer(buff)) { isSuccess = true; } }else if(ElectLock_ComBase.LOCK_IDCard1_ADDR == rtu.reg_addr) { //读取前50个ID卡号 if(mLock_State[NowLockIdx].putCardByteBuffer(buff,0)) { isSuccess = true; } }else if(ElectLock_ComBase.LOCK_IDCard2_ADDR == rtu.reg_addr) { //读取后50个ID卡号 if(mLock_State[NowLockIdx].putCardByteBuffer(buff,50)) { isSuccess = true; } } @@ -561,6 +616,11 @@ isSuccess = true; logger.info("LockId:" + mLock_param.getLock_id() + " LockIp:"+client_ip + " 设置锁具关闭蓝牙成功"); } }else if(null != bl) { if(mRtu_Rx.result == ElectLock_ComBase.Lock_Bluetooth_Close || mRtu_Rx.result == ElectLock_ComBase.Lock_Bluetooth_Open) { isSuccess = true; logger.info("LockId:" + mLock_param.getLock_id() + " LockIp:"+client_ip + " 设置锁具关闭蓝牙成功"); } } ElectLock_Monitor/src/com/dev/lock/comm/Lock_Task_SQL.java
@@ -8,6 +8,7 @@ import com.base.Com; import com.dev.lock.data.ElectLock_AuthIdcard; import com.dev.lock.data.ElectLock_Bl; import com.dev.lock.data.ElectLock_ComBase; import com.dev.lock.data.ElectLock_Ctl_Log; import com.dev.lock.data.ElectLock_Inf; @@ -476,4 +477,163 @@ sql.close_con(); } } /** * 插入默认的ID卡信息 * @param pool * @param client_id */ public static void insertLock_IdCard_Table(MysqlConnPool pool, int lock_id) { String sql_str_sel = " SELECT * FROM " + Sql_Mysql.Lock_IdCard_Table + " WHERE lock_id = " + lock_id; String sql_str_ins = " INSERT INTO " + Sql_Mysql.Lock_IdCard_Table + "(lock_id) VALUES(" + lock_id + ");"; Sql_Mysql sql = new Sql_Mysql(pool.getConn()); ResultSet res = null; try { res = sql.sqlMysqlQuery(sql_str_sel); if(!res.next()) { sql.sqlMysqlExecute(sql_str_ins); } } catch (SQLException e) { sql.logger.error(e.toString(),e); } finally { if(null != res) { try { res.close(); } catch (SQLException e) { sql.logger.error(e.toString(),e); } } sql.close_con(); } } /** * 插入默认的ID卡信息 * @param pool * @param client_id */ public static void insertLock_Rt_Table(MysqlConnPool pool, int lock_id) { String sql_str_sel = " SELECT * FROM " + Sql_Mysql.Lock_Rt_Table + " WHERE lock_id = " + lock_id; String sql_str_ins = " INSERT INTO " + Sql_Mysql.Lock_Rt_Table + "(lock_id) VALUES(" + lock_id + ");"; Sql_Mysql sql = new Sql_Mysql(pool.getConn()); ResultSet res = null; try { res = sql.sqlMysqlQuery(sql_str_sel); if(!res.next()) { sql.sqlMysqlExecute(sql_str_ins); } } catch (SQLException e) { sql.logger.error(e.toString(),e); } finally { if(null != res) { try { res.close(); } catch (SQLException e) { sql.logger.error(e.toString(),e); } } sql.close_con(); } } /** * 更细当前锁具的ID卡 * @param pool * @param client_id */ public static void updateLock_IdCard_Table(MysqlConnPool pool, ElectLock_State state) { StringBuffer sql_str = new StringBuffer(" UPDATE " + Sql_Mysql.Lock_IdCard_Table + " SET "); for(int k = 0;k<state.getId_cards().length;k++) { if(k > 0) { sql_str.append(",") ; } sql_str.append("card" + (k+1) + " = '" + state.getId_cards()[k] + "'") ; } sql_str.append(" WHERE lock_id = " + state.getLock_id()) ; Sql_Mysql sql = new Sql_Mysql(pool.getConn()); try { sql.sqlMysqlExecute(sql_str.toString()); } catch (SQLException e) { sql.logger.error(e.toString(),e); } finally { sql.close_con(); } } /** * 查询当前需要开启蓝牙的计划 * @param pool * @param lock_id * @return */ public static ElectLock_Bl queryBluetoothOpenPlan(MysqlConnPool pool,int lock_id) { ElectLock_Bl bl = null; String sql_str_sel = "SELECT * FROM " + Sql_Mysql.Lock_BL_Table + " WHERE NOW() BETWEEN start_time AND DATE_ADD(start_time,INTERVAL " + ElectLock_ComBase.Lock_BluetoothCheckTimeLong + " SECOND)" + " and type = 1 AND lock_id = " + lock_id; Sql_Mysql sql = new Sql_Mysql(pool.getConn()); ResultSet res = null; try { res = sql.sqlMysqlQuery(sql_str_sel); if(res.next()) { bl = new ElectLock_Bl(); bl.setLock_id(lock_id); bl.setCreate_time(res.getTimestamp("create_time")); bl.setStart_time(res.getTime("start_time")); bl.setStop_time(res.getTime("stop_time")); bl.setType(res.getInt("type")); } } catch (SQLException e) { sql.logger.error(e.toString(),e); } finally { if(null != res) { try { res.close(); } catch (SQLException e) { sql.logger.error(e.toString(),e); } } sql.close_con(); } return bl; } /** * 查询当前需要开启蓝牙的计划 * @param pool * @param lock_id * @return */ public static ElectLock_Bl queryBluetoothClosePlan(MysqlConnPool pool,int lock_id) { ElectLock_Bl bl = null; String sql_str_sel = "SELECT * FROM " + Sql_Mysql.Lock_BL_Table + " WHERE NOW() BETWEEN stop_time AND DATE_ADD(stop_time,INTERVAL " + ElectLock_ComBase.Lock_BluetoothCheckTimeLong + " SECOND)" + " and type = 1 AND lock_id = " + lock_id; Sql_Mysql sql = new Sql_Mysql(pool.getConn()); ResultSet res = null; try { res = sql.sqlMysqlQuery(sql_str_sel); if(res.next()) { bl = new ElectLock_Bl(); bl.setLock_id(lock_id); bl.setCreate_time(res.getTimestamp("create_time")); bl.setStart_time(res.getTime("start_time")); bl.setStop_time(res.getTime("stop_time")); bl.setType(res.getInt("type")); } } catch (SQLException e) { sql.logger.error(e.toString(),e); } finally { if(null != res) { try { res.close(); } catch (SQLException e) { sql.logger.error(e.toString(),e); } } sql.close_con(); } return bl; } } ElectLock_Monitor/src/com/dev/lock/data/ElectLock_Array.java
@@ -77,6 +77,9 @@ Lock_Task_SQL.queryLock_Rt_TableByLockId(pool, lock_id, tmp_lock.lockState); Lock_Task_SQL.queryLock_Report_TableByLockId(pool, lock_id, tmp_lock.lockReport, nowYear); Lock_Task_SQL.insertLock_IdCard_Table(pool, lock_id); Lock_Task_SQL.insertLock_Rt_Table(pool, lock_id); mInfs.add(tmp_lock); } ElectLock_Monitor/src/com/dev/lock/data/ElectLock_Bl.java
New file @@ -0,0 +1,42 @@ package com.dev.lock.data; import java.util.Date; public class ElectLock_Bl { private int lock_id; //'锁id', private Date start_time; //'开始时间', private Date stop_time; //'结束时间', private Date create_time; //'创建时间', private int type; //'蓝牙锁操作1:启用,2:取消', public int getLock_id() { return lock_id; } public Date getStart_time() { return start_time; } public Date getStop_time() { return stop_time; } public Date getCreate_time() { return create_time; } public int getType() { return type; } public void setLock_id(int lock_id) { this.lock_id = lock_id; } public void setStart_time(Date start_time) { this.start_time = start_time; } public void setStop_time(Date stop_time) { this.stop_time = stop_time; } public void setCreate_time(Date create_time) { this.create_time = create_time; } public void setType(int type) { this.type = type; } } ElectLock_Monitor/src/com/dev/lock/data/ElectLock_ComBase.java
@@ -2,7 +2,10 @@ public class ElectLock_ComBase { public static final int Lock_BluetoothCheckTimeLong = 20; //监测蓝牙计划开启间隔 public static final int Lock_MaxLineCount = 254; //一个串口服务器最大连接锁具个数 public static final int Lock_MaxCardCount = 100; //一个电子锁最大授权ID卡数量 public static final int Lock_Model_OffLine = 0; //离线模式 public static final int Lock_Model_OnLine = 1; //在线模式 @@ -55,6 +58,11 @@ public static final int LOCK_SET_Bluetooth_ADDR = 6; //设置蓝牙开关地址 public static final int LOCK_IDCard1_ADDR = 100; //已录入锁具ID卡 public static final int LOCK_IDCard2_ADDR = 150; //设置蓝牙开关地址 public static final int RegCount_Sigle = 1; //单点控制时点位 public static final int RegCount_Double = 2; //ID卡控制时点位 ElectLock_Monitor/src/com/dev/lock/data/ElectLock_State.java
@@ -19,6 +19,9 @@ 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码', @@ -54,6 +57,10 @@ 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() { @@ -111,7 +118,26 @@ 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; } @@ -125,6 +151,23 @@ } } 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; } ElectLock_Monitor/src/com/sql/Sql_Mysql.java
@@ -26,12 +26,14 @@ public static final String Lock_Ctl_Log_Table = PLUS_LOCK_RAM + ".tb_lock_ctl_log"; public static final String Lock_Report_Table = PLUS_LOCK_RAM + ".tb_lock_report"; //锁具开锁次数统计表 public static final String Plate_Info_Table = PLUS_LOCK_RAM + ".tb_plate_info"; //平台锁具模式设定表 public static final String Lock_IdCard_Table = PLUS_LOCK_RAM + ".tb_lock_idcard"; //锁具已授权ID卡 /*********************************************************/ /*************** ************ db_area ******************************/ public static final String Lock_Inf_Table = PLUS_INF + ".tb_lock_inf"; public static final String Key_Inf_Table = PLUS_INF + ".tb_key_inf"; public static final String Auth_Idcard_Table = PLUS_INF + ".tb_auth_idcard"; //批量添加授权和取消授权表 public static final String Auth_Idcard_His_Table = PLUS_INF + ".tb_auth_idcard_his"; //批量添加授权和取消授权历史表 public static final String Lock_BL_Table = PLUS_INF + ".tb_lock_bl"; //蓝牙定时开启计划 /*********************************************************/ /***************************** db_lock_his ****************************/ public static final String Lock_His_Table = PLUS_LOCK_HIS + ".tb_lock_his_"; //锁具开锁次数统计表 ElectLock_Monitor/src/com/version_inf/version_inf.txt
@@ -7,6 +7,10 @@ 设备ID:10000001 V1.114 edit by lijun 2025-04-22 1.新增定时开启以及关闭蓝牙功能。 2.添加读取锁具已授权ID卡信息功能。 V1.113 edit by lijun 2025-03-15 1.新增远程开启以及关闭蓝牙功能 2.修复锁具开启之后记录bug ElectLock_Monitor/src/main/main_ElectLock_Monitor.java
@@ -18,7 +18,7 @@ public class main_ElectLock_Monitor { public static final boolean app_debug = false; public static final double m_VersionNum = 3.112D; public static final double m_VersionNum = 3.114D; public static final String m_Version = "Welcome To Use main_ElectLock_Monitor V" + m_VersionNum + " RC_20180324"; public static int MysqlServer_Port; private static AppConfig m_AppConfig;