| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | }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());
|
| | |
| | | }
|
| | |
|
| | |
|
| | | 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))) {
|
| | |
| | | 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*100), ElectLock_State.Reg_Count_Card);
|
| | | if(SocketComm(mRtu_Tx, ByteBuffer.allocate(0))) {
|
| | | //更新当前锁具的ID卡
|
| | | Lock_Task_SQL.updateLock_IdCard_Table(pool, mLock_State[NowLockIdx]);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | // res = true;
|
| | | break;
|
| | | }
|
| | | if(rx_read_time_out > 20) {
|
| | | if(rx_read_time_out > 80) {
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | bytebuffer_for_socket_RX.flip();
|
| | |
|
| | | Date d2 = new Date();
|
| | | /*long comm_tms = (d2.getTime() - d1.getTime());
|
| | | if(comm_tms < 200) {
|
| | | Thread.sleep(200 - comm_tms);
|
| | | }*/
|
| | | /*
|
| | | System.out.println(this.getName()
|
| | | + " dev_id: " + m_StatAndParam.dev_id
|
| | | + " d2-d1:" + (comm_tms)+"ms"
|
| | | + " rx_len:" + bytebuffer_for_socket_RX.limit()
|
| | | + " tx_count:" + m_FBS_VCData.m_SysState.CommCount
|
| | | + " rx_err_sum:" + m_FBS_VCData.m_SysState.ErrCommCount
|
| | | + " rx_err_count:" + rx_errcount_for_live_of_thread
|
| | | + Com.getNowTimeWithAt());
|
| | | */
|
| | | |
| | | byte[] cipher_buf = new byte[bytebuffer_for_socket_RX.limit()];
|
| | | bytebuffer_for_socket_RX.get(cipher_buf);
|
| | |
|
| | |
| | | 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;
|
| | | }
|
| | |
| | | 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;
|
| | | }
|
| | | }
|
| | |
| | | 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 + " 设置锁具关闭蓝牙成功");
|
| | | }
|
| | | }
|
| | |
|
| | |
|