| | |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.drawable.BitmapDrawable; |
| | | import android.hardware.Camera; |
| | | import android.opengl.Visibility; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baidu.idl.main.facesdk.model.BDFaceSDKCommon; |
| | | import com.baidu.idl.main.facesdk.utils.StreamUtil; |
| | | import com.bigkoo.convenientbanner.holder.CBViewHolderCreator; |
| | | import com.bumptech.glide.Glide; |
| | | import com.bumptech.glide.load.DataSource; |
| | |
| | | import com.bumptech.glide.request.target.Target; |
| | | import com.bumptech.glide.request.transition.Transition; |
| | | import com.doumee.keyCabinet.BuildConfig; |
| | | import com.doumee.keyCabinet.base.BannerPicResponsePara; |
| | | import com.doumee.keyCabinet.bean.CabinetConfigDataBean; |
| | | import com.doumee.keyCabinet.bean.DevConfigBean; |
| | | import com.doumee.keyCabinet.bean.FaceUserBean; |
| | | import com.doumee.keyCabinet.bean.LoginBean; |
| | | import com.doumee.keyCabinet.dao.CabinetGridDo; |
| | | import com.doumee.keyCabinet.dao.DaoManager; |
| | | import com.doumee.keyCabinet.databinding.MainActivityBinding; |
| | | import com.doumee.keyCabinet.event.CLGridEvent; |
| | | import com.doumee.keyCabinet.event.CLKeyEvent; |
| | | import com.doumee.keyCabinet.event.CheckGridStatusEvent; |
| | | import com.doumee.keyCabinet.event.CloseGridOneResultEvent; |
| | | import com.doumee.keyCabinet.event.GetFacesEvent; |
| | | import com.doumee.keyCabinet.event.GetKeyStatusEvent; |
| | | import com.doumee.keyCabinet.event.HeartEvent; |
| | | import com.doumee.keyCabinet.event.HttpEvent; |
| | | import com.doumee.keyCabinet.event.JiujinBeginEvent; |
| | | import com.doumee.keyCabinet.event.JiujinResultEvent; |
| | | import com.doumee.keyCabinet.event.KeyResultEvent; |
| | | import com.doumee.keyCabinet.event.ManageOpenGridResultEvent; |
| | | import com.doumee.keyCabinet.event.OpenAllGridEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridListEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridOneResultEvent; |
| | | import com.doumee.keyCabinet.event.ReLoginEvent; |
| | | import com.doumee.keyCabinet.event.TimeClockEvent; |
| | | import com.doumee.keyCabinet.ui.face.ActivationActivity; |
| | | import com.doumee.keyCabinet.ui.face.FaceActivity; |
| | | import com.doumee.keyCabinet.ui.keyCabinet.ChangeUrlActivity; |
| | | import com.doumee.keyCabinet.ui.keyCabinet.KeyCabinetActivity; |
| | | import com.doumee.keyCabinet.ui.keyCabinet.ManageLoginActivity; |
| | |
| | | import com.doumee.keyCabinet.ui.face.UserManagerActivity; |
| | | import com.doumee.keyCabinet.ui.view.BannerViewImageHolder; |
| | | import com.doumee.keyCabinet.utils.BraceletLogUtils; |
| | | import com.doumee.keyCabinet.utils.CircularQueue; |
| | | import com.doumee.keyCabinet.utils.CrashHandler; |
| | | import com.doumee.keyCabinet.utils.LMobileInfo; |
| | | import com.doumee.keyCabinet.utils.TimeUtils; |
| | |
| | | import com.doumee.lib_coremodel.http.utils.GsonTools; |
| | | import com.doumee.lib_coremodel.util.SpUtil; |
| | | import com.doumee.lib_coremodel.util.StringUtil; |
| | | import com.doumee.lib_coremodel.view.ToastView; |
| | | import com.example.datalibrary.api.FaceApi; |
| | | import com.example.datalibrary.listener.DBLoadListener; |
| | | import com.example.datalibrary.listener.SdkInitListener; |
| | | import com.example.datalibrary.model.ImportFeatureResult; |
| | | import com.example.datalibrary.model.User; |
| | | import com.example.datalibrary.utils.ToastUtils; |
| | | import com.example.datalibrary.view.PreviewTexture; |
| | | import com.yanzhenjie.permission.runtime.Permission; |
| | | |
| | |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | |
| | | import java.util.TimerTask; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.Future; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import dagger.hilt.android.AndroidEntryPoint; |
| | | import timber.log.Timber; |
| | |
| | | if(!isFinishing()){ |
| | | switch (msg.what) { |
| | | case 0: |
| | | //initM(); |
| | | initM(); |
| | | TimeUtils.updateTimeUi(getVM().dayObs, getVM().timeObs); |
| | | handler.sendEmptyMessageDelayed(0, 1000); |
| | | EventBus.getDefault().post(new TimeClockEvent()); |
| | |
| | | SpUtil.initWH(this); |
| | | normalConfig(); |
| | | getDB().setModel(getVM()); |
| | | //initRGBCheck(); |
| | | initRGBCheck(); |
| | | handler.sendEmptyMessageDelayed(0, 1000); |
| | | //启动心跳 |
| | | Intent intent = new Intent(MainActivity.this, HeartbeatService.class); |
| | |
| | | startService(intent2); |
| | | getPermission(); |
| | | Timber.tag("====>").d(LMobileInfo.getDeviceUniqueId()); |
| | | initPort(); |
| | | } |
| | | |
| | | private void initM(){ |
| | |
| | | if((availableMemory<400&&showTime!=null&&(System.currentTimeMillis()-showTime>5000))|| |
| | | ("02:00:00".equals(StringUtil.getHM()))){ |
| | | //可用内存小于400M,或者每天凌晨2点,重启app |
| | | restartApp(); |
| | | //restartApp(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | }); |
| | | getDB().tvVersion.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | //todo 临时代码 |
| | | //setJiuConfig(); |
| | | SpUtil.saveString("rbgCameraId","0"); |
| | | } |
| | | }); |
| | | getDB().imgLeft.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | //todo 临时代码 |
| | | if (getDB().nsv.getVisibility()== View.VISIBLE) { |
| | | getDB().nsv.setVisibility(View.GONE); |
| | | }else { |
| | | getDB().nsv.setVisibility(View.VISIBLE); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | upErrInfo(); |
| | | getVM().devLogin(); |
| | | getVM().devHeart(); |
| | |
| | | setBanner(devConfigBean.getBannerList()); |
| | | } |
| | | setJiuConfig(); |
| | | initPort(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void setJiuConfig(){ |
| | | getVM().addInfo("酒精配置:"+(MApplication.getConfigBean().getCabinetConfigDataVO()!=null)+ |
| | | ",串口开启:"+(jiuPort!=null)); |
| | | if(MApplication.getConfigBean().getCabinetConfigDataVO()!=null&& |
| | | jiuPort!=null){ |
| | | setJiuConfig(0); |
| | |
| | | case 2: |
| | | case 3: { |
| | | //校验是否登录 |
| | | /*if(MApplication.getConfigBean().getId()==null){ |
| | | if(MApplication.getConfigBean().getId()==null){ |
| | | Toast.makeText(mContext, "设备未添加,无法操作", Toast.LENGTH_SHORT).show(); |
| | | getVM().devLogin(); |
| | | return; |
| | | } |
| | | MApplication.getLoginBean().setFlag(type==2?0:1); |
| | | startActivity(FaceActivity.class);*/ |
| | | /*if(type==2){ |
| | | send485(1,"A002010000000003"); |
| | | }else { |
| | | send485(1,"A001010000000002"); |
| | | }*/ |
| | | //send485(1,"A001010000000002"); |
| | | //send485(1,"A002010000000003"); |
| | | //startActivity(KeyCabinetActivity.class,b); |
| | | checkGridStatus(0); |
| | | List<CabinetGridDo> gridDos = getVM().getOpenGrids(); |
| | | if (gridDos.size() > 0) { |
| | | tipDownCount = 10; |
| | | isShowTip = true; |
| | | getDB().tvDjs.setText(tipDownCount + "s"); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(CabinetGridDo d:gridDos){ |
| | | if (sb.length()>0) { |
| | | sb.append("、"); |
| | | } |
| | | String name = d.getCabinetName(); |
| | | if (TextUtils.isEmpty(name)) { |
| | | name = gridDos.get(0).getGridKey(); |
| | | } |
| | | sb.append(name); |
| | | } |
| | | |
| | | getDB().tvTip22.setText(getTipText(sb.toString()), TextView.BufferType.SPANNABLE); |
| | | getDB().clTip.setVisibility(View.VISIBLE); |
| | | showUnCloseTip(gridDos); |
| | | return; |
| | | } |
| | | MApplication.setLoginBean(null); |
| | | MApplication.getLoginBean().setFlag(type == 2 ? 0 : 1); |
| | | if(type==3){ |
| | | startActivity(ManageLoginActivity.class); |
| | | return; |
| | | } |
| | | startActivity(KeyCabinetActivity.class); |
| | | startActivity(FaceActivity.class); |
| | | } |
| | | break; |
| | | case 4: |
| | |
| | | case 5: { |
| | | List<CabinetGridDo> gridDos = getVM().getOpenGrids(); |
| | | if (gridDos.size() > 0) { |
| | | tipDownCount = 10; |
| | | isShowTip = true; |
| | | getDB().tvDjs.setText(tipDownCount + "s"); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(CabinetGridDo d:gridDos){ |
| | | if (sb.length()>0) { |
| | | sb.append("、"); |
| | | } |
| | | String name = d.getCabinetName(); |
| | | if (TextUtils.isEmpty(name)) { |
| | | name = gridDos.get(0).getGridKey(); |
| | | } |
| | | sb.append(name); |
| | | } |
| | | getDB().tvTip22.setText(getTipText(sb.toString()), TextView.BufferType.SPANNABLE); |
| | | getDB().clTip.setVisibility(View.VISIBLE); |
| | | showUnCloseTip(gridDos); |
| | | }else { |
| | | isShowTip = false; |
| | | getDB().clTip.setVisibility(View.GONE); |
| | |
| | | } |
| | | } |
| | | |
| | | private void showUnCloseTip(List<CabinetGridDo> gridDos){ |
| | | tipDownCount = 10; |
| | | isShowTip = true; |
| | | getDB().tvDjs.setText(tipDownCount + "s"); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(CabinetGridDo d:gridDos){ |
| | | if (sb.length()>0) { |
| | | sb.append("、"); |
| | | } |
| | | String name = d.getCabinetName(); |
| | | if (TextUtils.isEmpty(name)) { |
| | | name = gridDos.get(0).getGridKey(); |
| | | } |
| | | sb.append(name); |
| | | } |
| | | getDB().tvTip22.setText(getTipText(sb.toString()), TextView.BufferType.SPANNABLE); |
| | | getDB().tvTip23.setText(getErrPhoneText(), TextView.BufferType.SPANNABLE); |
| | | getDB().clTip.setVisibility(View.VISIBLE); |
| | | } |
| | | |
| | | private SpannableString getErrPhoneText(){ |
| | | String phone = MApplication.getConfigBean().getLinkPhone(); |
| | | String text = "如有问题请联系管理员"+phone; |
| | | SpannableString styledText = new SpannableString(text); |
| | | styledText.setSpan(new TextAppearanceSpan(this, R.style.style_tip3), 0, text.length()-phone.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | styledText.setSpan(new TextAppearanceSpan(this,R.style.style_tip1), text.length()-phone.length()+1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| | | return styledText; |
| | | } |
| | | |
| | | private boolean isShowing = false; |
| | | @Override |
| | | protected void onResume() { |
| | |
| | | isShowing = true; |
| | | showTime = System.currentTimeMillis(); |
| | | if(!isFaceOk) { |
| | | //initLicense(); |
| | | initLicense(); |
| | | } |
| | | if(isHavePermission) { |
| | | checkUpdate(); |
| | |
| | | }else { |
| | | getDB().banner.stopTurning(); |
| | | } |
| | | unCloseGrid(); |
| | | //检查所有柜格门、钥匙状态 |
| | | checkKeyStatus(0); |
| | | checkGridStatus(900); |
| | | } |
| | | |
| | | private void unCloseGrid(){ |
| | |
| | | if (ret == 128) { |
| | | Timber.d("==UpdatingFace==>图片特征抽取成功: %s", JSON.toJSONString(bean)); |
| | | User user = new User(); |
| | | user.setUserId(bean.getMemberId()); |
| | | user.setUserId(bean.getMemberId().toString()); |
| | | user.setGroupId(bean.getGroupId()); |
| | | user.setUserName(bean.getMemberName()); |
| | | user.setImageName(bean.getFaceImg()); |
| | |
| | | popupWindow.showAtLocation(getDB().clRoot, Gravity.CENTER, 0, 0); |
| | | RelativeLayout relativeRegister = contentView.findViewById(R.id.relative_register); |
| | | RelativeLayout mPopRelativeManager = contentView.findViewById(R.id.relative_manager); |
| | | RelativeLayout mPopRelativeCamra = contentView.findViewById(R.id.relative_camra); |
| | | RelativeLayout mRlErr = contentView.findViewById(R.id.rl_err); |
| | | relativeRegister.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | |
| | | @Override |
| | | public void onClick(View v) { |
| | | startActivity(UserManagerActivity.class); |
| | | } |
| | | }); |
| | | mPopRelativeCamra.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | //startActivity(); |
| | | } |
| | | }); |
| | | mRlErr.setOnClickListener(new View.OnClickListener() { |
| | |
| | | } |
| | | |
| | | private void initRGBCheck(){ |
| | | if(true){ |
| | | return; |
| | | } |
| | | String index = SpUtil.getString("rbgCameraId"); |
| | | if(index==null){ |
| | | index = "0"; |
| | | } |
| | | String index = SpUtil.getString("rbgCameraId","0"); |
| | | setRgbCameraId(Integer.parseInt(index)); |
| | | /*if (isSetCameraId()){ |
| | | setRgbCameraId(SingleBaseConfig.getBaseConfig().getRBGCameraId()); |
| | | return; |
| | | } |
| | | int mCameraNum = Camera.getNumberOfCameras(); |
| | |
| | | } |
| | | |
| | | private void setRgbCameraId(int index){ |
| | | getVM().addInfo("设置相机:"+index); |
| | | //Toast.makeText(mContext, "设置相机"+index, Toast.LENGTH_SHORT).show(); |
| | | SpUtil.saveString("rbgCameraId",index+""); |
| | | BraceletLogUtils.saveLog("设置相机("+index+")"); |
| | |
| | | } |
| | | |
| | | private int tipDownCount = 10; |
| | | private int loopDownCount = 30; |
| | | private boolean isShowTip; |
| | | @Subscribe |
| | | public void TimeClockEvent(TimeClockEvent e){ |
| | | if(isShowTip){ |
| | | if(tipDownCount==0){ |
| | | isShowTip = false; |
| | | getDB().clTip.setVisibility(View.GONE); |
| | | if(!isFinishing()) { |
| | | if(isShowTip){ |
| | | if(tipDownCount==0){ |
| | | isShowTip = false; |
| | | getDB().clTip.setVisibility(View.GONE); |
| | | }else { |
| | | tipDownCount--; |
| | | getDB().tvDjs.setText(tipDownCount+"s"); |
| | | } |
| | | } |
| | | if(loopDownCount==0){ |
| | | loopDownCount = SpUtil.getInt("loop_time",30); |
| | | //定时拉取基本信息 |
| | | getVM().devLogin(); |
| | | }else { |
| | | tipDownCount--; |
| | | getDB().tvDjs.setText(tipDownCount+"s"); |
| | | loopDownCount--; |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void JiujinBeginEvent(JiujinBeginEvent e){ |
| | | if(!isFinishing()){ |
| | | //开启酒精检测 |
| | | sendPortHandlerMsg(3,"go_wnd:0",0); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Subscribe |
| | | public void CloseGridOneResultEvent(CloseGridOneResultEvent e){ |
| | |
| | | !TextUtils.isEmpty(gridDo.getKeyCode())&& |
| | | !gridDo.getCurKeyCode().equals(gridDo.getKeyCode())){ |
| | | //钥匙不一样,开门 |
| | | Toast.makeText(mContext, "钥匙存放位置错误", Toast.LENGTH_SHORT).show(); |
| | | ToastView.show(MApplication.mContext,gridDo.getCabinetName()+"钥匙存放位置错误"); |
| | | EventBus.getDefault().post(new OpenGridEvent(Integer.parseInt(e.getKey().substring(2,4), 16)+"", |
| | | Integer.parseInt(e.getKey().substring(0,2), 16)+"")); |
| | | }else { |
| | | //todo 关门成功 |
| | | if(isShowTip){ |
| | | doRegister(5,null); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onResultBytes(byte[] bytes) { |
| | | if(isFinishing()){ |
| | | return; |
| | | } |
| | | if(bytes.length==0){ |
| | | return; |
| | | } |
| | |
| | | });*/ |
| | | String key = bh+tdh; |
| | | CabinetGridDo gridDo = DaoManager.getCabinetGridDao().getGridByKey(key); |
| | | if(gridDo==null){ |
| | | //新增 |
| | | gridDo = new CabinetGridDo(); |
| | | gridDo.setIsOpen("00".equals(open)?1:0); |
| | | gridDo.setGridKey(key); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | DaoManager.getCabinetGridDao().insert(gridDo); |
| | | }else { |
| | | if(gridDo!=null){ |
| | | gridDo.setIsOpen("00".equals(open)?1:0); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | //todo 去掉 |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"=================>更新数据当前钥匙3:"+gridDo.getCurKeyCode())); |
| | | |
| | | DaoManager.getCabinetGridDao().update(gridDo); |
| | | EventBus.getDefault().post(new ManageOpenGridResultEvent()); |
| | | if(gridDo.getIsOpen()==0) { |
| | | //开门失败 |
| | | if (isShowing) { |
| | | //首页开门失败,钥匙不对 |
| | | if (!TextUtils.isEmpty(gridDo.getCurKeyCode()) && |
| | | !TextUtils.isEmpty(gridDo.getKeyCode()) && |
| | | !gridDo.getCurKeyCode().equals(gridDo.getKeyCode())) { |
| | | //钥匙不一样,开门 |
| | | ToastView.show(MApplication.mContext, gridDo.getCabinetName() + "钥匙存放位置错误"); |
| | | EventBus.getDefault().post(new OpenGridEvent(Integer.parseInt(gridDo.getGridKey().substring(2, 4), 16) + "", |
| | | Integer.parseInt(gridDo.getGridKey().substring(0, 2), 16) + "")); |
| | | } |
| | | } |
| | | }else { |
| | | //开门成功 |
| | | } |
| | | } |
| | | //开门返回 |
| | | EventBus.getDefault().post(new OpenGridOneResultEvent(key,gridDo.getIsOpen())); |
| | | if(!portHandler.hasMessages(1)){ |
| | | EventBus.getDefault().post(new ManageOpenGridResultEvent()); |
| | | } |
| | | EventBus.getDefault().post(new OpenGridOneResultEvent(key,"00".equals(open)?1:0)); |
| | | }else if(data.length()==16){ |
| | | //批量 |
| | | //8A 02 00 00 00 00 11 99 |
| | |
| | | for(CabinetGridDo d:gridDos){ |
| | | oldMap.put(d.getGridKey(),d); |
| | | } |
| | | List<CabinetGridDo> addList = new ArrayList<>(); |
| | | List<CabinetGridDo> updateList = new ArrayList<>(); |
| | | String finalDm = dm; |
| | | /*runOnUiThread(() -> { |
| | | getVM().addInfo("批量查询返回:" +bh+","+ finalDm+",总数据:"+oldMap.size()); |
| | | });*/ |
| | | try { |
| | | for(int i=1;i<=dm.length();i++){ |
| | | String key = bh+SportUtils.intToHex(i); |
| | |
| | | gridDo.setIsOpen("1".equals(dm.substring(i-1,i))?0:1); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | updateList.add(gridDo); |
| | | }/*else { |
| | | getVM().addInfo("新增key:" +key); |
| | | CabinetGridDo gridDo = new CabinetGridDo(); |
| | | gridDo.setGridKey(key); |
| | | gridDo.setIsOpen("1".equals(dm.substring(i-1,i))?0:1); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | addList.add(gridDo); |
| | | }*/ |
| | | } |
| | | } |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("批量开门更新库数据:版号:" +bh+","+ addList.size()+","+updateList.size()); |
| | | getVM().addInfo("批量开门更新库数据:版号:" +bh+","+updateList.size()); |
| | | }); |
| | | getVM().insertGrids(addList); |
| | | getVM().updateGrids(updateList); |
| | | if(!portHandler.hasMessages(1)){ |
| | | EventBus.getDefault().post(new ManageOpenGridResultEvent()); |
| | | //todo 去掉 |
| | | CabinetGridDo gridDo = oldMap.get("0101"); |
| | | if(gridDo!=null) { |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"=================>更新数据当前钥匙6:" + gridDo.getCurKeyCode())); |
| | | } |
| | | |
| | | getVM().updateGrids(updateList); |
| | | EventBus.getDefault().post(new ManageOpenGridResultEvent()); |
| | | }catch (Exception exception){ |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("批量开门报错:" +exception.getMessage()); |
| | |
| | | String open = data.substring(6,8); |
| | | String key = bh+tdh; |
| | | CabinetGridDo gridDo = DaoManager.getCabinetGridDao().getGridByKey(key); |
| | | if(gridDo==null){ |
| | | //新增 |
| | | gridDo = new CabinetGridDo(); |
| | | gridDo.setIsOpen("00".equals(open)?1:0); |
| | | gridDo.setGridKey(key); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | DaoManager.getCabinetGridDao().insert(gridDo); |
| | | }else { |
| | | if(gridDo!=null){ |
| | | gridDo.setIsOpen("00".equals(open)?1:0); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | //todo 去掉 |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"=================>更新数据当前钥匙3:"+gridDo.getCurKeyCode())); |
| | | |
| | | DaoManager.getCabinetGridDao().update(gridDo); |
| | | } |
| | | //关门返回 |
| | | EventBus.getDefault().post(new CloseGridOneResultEvent(key,gridDo.getIsOpen())); |
| | | EventBus.getDefault().post(new CloseGridOneResultEvent(key,"00".equals(open)?1:0)); |
| | | if(isShowing&&isShowTip){ |
| | | //修改显示提醒 |
| | | doRegister(5,null); |
| | |
| | | gridDo.setIsOpen("1".equals(dm.substring(i-1,i))?0:1); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | updateList.add(gridDo); |
| | | }else { |
| | | CabinetGridDo gridDo = new CabinetGridDo(); |
| | | gridDo.setGridKey(key); |
| | | gridDo.setIsOpen("1".equals(dm.substring(i-1,i))?0:1); |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | addList.add(gridDo); |
| | | } |
| | | } |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("更新库数据:版号:" +bh+","+ addList.size()+","+updateList.size()); |
| | | }); |
| | | getVM().insertGrids(addList); |
| | | //todo 去掉 |
| | | CabinetGridDo gridDo = oldMap.get("0101"); |
| | | if(gridDo!=null){ |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+ |
| | | "=================>更新数据当前钥匙5:"+gridDo.getCurKeyCode())); |
| | | } |
| | | |
| | | getVM().updateGrids(updateList); |
| | | if(isShowing){ |
| | | unCloseGrid(); |
| | | } |
| | | }catch (Exception exception){ |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("报错:" +exception.getMessage()); |
| | |
| | | |
| | | @Override |
| | | public void onResultBytes(byte[] bytes) { |
| | | if(isFinishing()){ |
| | | return; |
| | | } |
| | | if(bytes.length==0){ |
| | | return; |
| | | } |
| | |
| | | String data2 = keyPreviousData+data; |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("获取到钥匙数据:" + data2); |
| | | jxKey(data2); |
| | | if(data2.contains("CC01")&&data2.contains("CC02")){ |
| | | String[] sp = data2.split("CC02"); |
| | | if(sp.length==2){ |
| | | jxKey(sp[0]); |
| | | jxKey("CC02"+sp[1]); |
| | | } |
| | | }else { |
| | | jxKey(data2); |
| | | } |
| | | }); |
| | | keyPreviousData = null; |
| | | } |
| | |
| | | }else { |
| | | gridDo.setCurKeyCode(""); |
| | | } |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | updateList.add(gridDo); |
| | | }else { |
| | | //新增 |
| | | CabinetGridDo gridDo = new CabinetGridDo(); |
| | | gridDo.setGridKey(key); |
| | | if("01".equals(isHaveKey)) { |
| | | gridDo.setCurKeyCode(keyCode); |
| | | }else { |
| | | gridDo.setCurKeyCode(""); |
| | | if("0101".equals(key)) { |
| | | getVM().addInfo(key+" , "+isHaveKey+" "+keyCode); |
| | | getVM().addInfo(key + "设置钥匙:" + gridDo.getCurKeyCode()); |
| | | } |
| | | gridDo.setUpdateTime(StringUtil.DateToStr(new Date())); |
| | | addList.add(gridDo); |
| | | updateList.add(gridDo); |
| | | } |
| | | } |
| | | } |
| | | getVM().insertGrids(addList); |
| | | //todo 去掉 |
| | | CabinetGridDo gridDo = oldMap.get("0101"); |
| | | if(gridDo!=null) { |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+ |
| | | "=================>更新数据当前钥匙7:" + gridDo.getCurKeyCode())); |
| | | } |
| | | |
| | | getVM().updateGrids(updateList); |
| | | EventBus.getDefault().post(new KeyResultEvent()); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onResultBytes(byte[] bytes) { |
| | | if(isFinishing()){ |
| | | return; |
| | | } |
| | | if(bytes.length==0){ |
| | | return; |
| | | } |
| | | runOnUiThread(() -> { |
| | | getVM().addInfo("获取到酒精检测数据:" + new String(bytes)); |
| | | }); |
| | | try { |
| | | runOnUiThread(() -> { |
| | | //getVM().addInfo("获取到酒精检测数据:"+StringUtil.DateToStrSS(new Date())+" " + new String(bytes)); |
| | | }); |
| | | String data = new String(bytes); |
| | | runOnUiThread(() -> { |
| | | //getVM().addInfo("获取到酒精检测是否检测失败:" + (data.contains("blow fail"))); |
| | | }); |
| | | if(data.contains("blow fail")){ |
| | | //检测失败 |
| | | EventBus.getDefault().post(new JiujinResultEvent(false,null)); |
| | | }else if(data.startsWith("Result:")){ |
| | | Pattern pattern = Pattern.compile("([0-9]+\\.[0-9]+)"); |
| | | Matcher matcher = pattern.matcher(data); |
| | | if (matcher.find()) { |
| | | EventBus.getDefault().post(new JiujinResultEvent(true,new BigDecimal(matcher.group(1)))); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | getVM().addInfo("获取到酒精检测报错:" + e.getMessage()); |
| | | } |
| | | } |
| | | }; |
| | | private SerialPortModel chosePort; |
| | |
| | | } |
| | | }; |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void CheckGridStatusEvent(CheckGridStatusEvent e){ |
| | | if(!isFinishing()){ |
| | | checkGridStatus(0); |
| | | } |
| | | } |
| | | |
| | | //检查所有门状态 |
| | | private void checkGridStatus(long time){ |
| | | sendPortHandlerMsg(1,"80010033B2",time+100); |
| | |
| | | sendPortHandlerMsg(3,"alarm:"+config.getConcentration(),time+600); |
| | | //浓度阈值单位 (1=mg/100ml;2=mg/L;3=%BAC) |
| | | sendPortHandlerMsg(3,"unit:"+config.getThreshold(),time+900); |
| | | |
| | | sendPortHandlerMsg(3,"read"+config.getThreshold(),time+1200); |
| | | } |
| | | |
| | | private void sendPortHandlerMsg(int what,String obj,long time){ |
| | |
| | | portHandler.sendMessageDelayed(mc,time); |
| | | } |
| | | |
| | | private boolean isInitPort; |
| | | //初始化串口 |
| | | private void initPort(){ |
| | | SpUtil.setString("port_grid","/dev/ttyS7"); |
| | | SpUtil.setString("port_key","/dev/ttyS1"); |
| | | SpUtil.setString("port_jiu","/dev/ttyS2"); |
| | | gridPath = SpUtil.getString("port_grid"); |
| | | getVM().addInfo("门串口链接:"+gridPath); |
| | | //getVM().addInfo("门串口链接:"+gridPath); |
| | | keyPath = SpUtil.getString("port_key"); |
| | | getVM().addInfo("钥匙串口链接:"+keyPath); |
| | | //getVM().addInfo("钥匙串口链接:"+keyPath); |
| | | jiuPath = SpUtil.getString("port_jiu"); |
| | | getVM().addInfo("酒精串口链接:"+jiuPath); |
| | | //getVM().addInfo("酒精串口链接:"+jiuPath); |
| | | if(!TextUtils.isEmpty(SpUtil.getString("port_grid"))&& |
| | | !TextUtils.isEmpty(SpUtil.getString("port_key"))&& |
| | | !TextUtils.isEmpty(SpUtil.getString("port_jiu"))){ |
| | | if(isInitPort){ |
| | | return; |
| | | } |
| | | xhCount=0; |
| | | closePort(chosePort); |
| | | if(!TextUtils.isEmpty(SpUtil.getString("port_grid"))){ |
| | |
| | | ,1 , 0,gridReadObserver); |
| | | boolean isSucc = gridPort.open(); |
| | | if(isSucc) { |
| | | isInitPort = true; |
| | | getVM().addInfo("门串口链接成功:"+path); |
| | | String msg = isSucc ? "成功" : "失败"; |
| | | //getVM().append("串口 "+ settingBean.getDevicePath() + " -连接"+msg); |
| | |
| | | ,1 , 0,keyReadObserver); |
| | | boolean isSucc = keyPort.open(); |
| | | if(isSucc) { |
| | | isInitPort = true; |
| | | getVM().addInfo("钥匙串口链接成功:"+path); |
| | | String msg = isSucc ? "成功" : "失败"; |
| | | //getVM().append("串口 "+ settingBean.getDevicePath() + " -连接"+msg); |
| | |
| | | ,1 , 0,jiuReadObserver); |
| | | boolean isSucc = jiuPort.open(); |
| | | if(isSucc) { |
| | | isInitPort = true; |
| | | getVM().addInfo("酒精串口链接成功:"+path); |
| | | String msg = isSucc ? "成功" : "失败"; |
| | | //getVM().append("串口 "+ settingBean.getDevicePath() + " -连接"+msg); |
| | |
| | | portHandler.sendEmptyMessageDelayed(0,0); |
| | | } |
| | | |
| | | private CircularQueue openGridQueue = new CircularQueue(); |
| | | private void send485(int type,String code){ |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //todo 去掉 |
| | | if(type==2){ |
| | | return; |
| | | } |
| | | getVM().addInfo("发送指令:"+StringUtil.DateToStrSS(new Date())+"==>"+code); |
| | | } |
| | | }); |
| | | if(type==0){ |
| | | if(gridPort!=null){ |
| | | if(code.startsWith("8A")){ |
| | | openGridQueue.enqueue(code); |
| | | } |
| | | byte[] sendByte = SportUtils.hexToByteArray(code); |
| | | gridPort.write(sendByte); |
| | | } |