| | |
| | | |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import com.blankj.utilcode.util.CacheDiskUtils; |
| | | import com.blankj.utilcode.util.ConvertUtils; |
| | | import com.blankj.utilcode.util.LogUtils; |
| | | import com.blankj.utilcode.util.ThreadUtils; |
| | |
| | | import com.lotaai.canguiayw.device.CanguiStatus; |
| | | import com.lotaai.canguiayw.device.DeviceMessage; |
| | | import com.lotaai.canguiayw.device.MessageType; |
| | | import com.lotaai.canguiayw.sqllitedb.GridModel; |
| | | import com.lotaai.canguiayw.sqllitedb.SqlliteDbManage; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Queue; |
| | |
| | | |
| | | private List<byte[]> commandQueue = new LinkedList<byte[]>(); |
| | | SerialPortUtils serialPortUtils = new SerialPortUtils(); |
| | | private HashMap<String,List<GridModel>> gridStatus = new HashMap<>(); |
| | | |
| | | @Nullable |
| | | @Override |
| | |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | serialPortUtils.openSerialPort("/dev/ttyS4",4800); |
| | | // serialPortUtils.openSerialPort("/dev/ttyS4",4800); |
| | | String str = CacheDiskUtils.getInstance().getString(SettingConfig.getInstance().Cache_Device_Tty); |
| | | if (str == null || "".equals(str)){ |
| | | return; |
| | | } |
| | | serialPortUtils.openSerialPort(str,4800); |
| | | registerListener(); |
| | | SettingConfig.getInstance().getExecutor().execute(selectRunnable); |
| | | SettingConfig.getInstance().getExecutor().execute(sendRunnable); |
| | |
| | | Runnable selectRunnable = new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //开始之前先查询是不是已经有了 |
| | | for (int i = 0; i<20;i++) { |
| | | List<GridModel> lists = SqlliteDbManage.getInstance().selectGridByGui(i); |
| | | if (lists != null && lists.size() > 0) { |
| | | gridStatus.put(Integer.toString(i), lists); |
| | | } |
| | | try { |
| | | Thread.sleep(100); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | while(true){ |
| | | try { |
| | | Thread.sleep(2000); |
| | |
| | | public void onDataReceive(byte[] buffer, int size) { |
| | | if (size >3){ |
| | | List<CanguiStatus> statuses = CanGuiCommand.getInstance().analysisRecvByte(buffer); |
| | | if (statuses!=null){ |
| | | boolean isHas = false; |
| | | int gui = -1; |
| | | if (statuses!=null &&statuses.size()>0){ |
| | | if (gridStatus.containsKey(Integer.toString(statuses.get(0).getGuiHao()))){ |
| | | isHas = true; |
| | | } |
| | | for (int i = 0; i < statuses.size(); i++){ |
| | | CanguiStatus s = statuses.get(i); |
| | | SettingConfig.getInstance().addStatusInList(s); |
| | | LogUtils.i("柜:" + s.getGuiHao(),"格:" + s.getGridNo(),"温度:" + s.getWendu(), |
| | | "门:"+s.isDoorIsOpen(),"加热:"+s.isJiareIsOpen(),"灯光:" + s.isDengGuangIsOpen(),"消毒:" + s.isXiaoDuIsOpen()); |
| | | if (!isHas) { |
| | | GridModel model = new GridModel(); |
| | | model.setGuiHao(s.getGuiHao()); |
| | | model.setGridNo(s.getGridNo()); |
| | | model.setState(0); |
| | | SqlliteDbManage.getInstance().addGrid(model); |
| | | gui = s.getGuiHao(); |
| | | } |
| | | // LogUtils.i("柜:" + s.getGuiHao(),"格:" + s.getGridNo(),"温度:" + s.getWendu(), |
| | | //// "门:"+s.isDoorIsOpen(),"加热:"+s.isJiareIsOpen(),"灯光:" + s.isDengGuangIsOpen(),"消毒:" + s.isXiaoDuIsOpen()); |
| | | } |
| | | if (gui > -1 && !isHas){ |
| | | List<GridModel> lists = SqlliteDbManage.getInstance().selectGridByGui(gui); |
| | | if (lists!=null && lists.size()>0){ |
| | | gridStatus.put(Integer.toString(gui),lists); |
| | | } |
| | | } |
| | | } |
| | | } |