# ChuangMC **Repository Path**: llliman/ChuangMC ## Basic Information - **Project Name**: ChuangMC - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-01-15 - **Last Updated**: 2024-02-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Android-SerialPort-Tool Android串口调试助手 根据[**Android官方提供的串口API**](https://github.com/licheedev/Android-SerialPort-API)写的一个小工具, 没啥功能,基本也就用来调调控制板哪串口能用,发送一下简单的命令, 如果没懒癌发作的话,以后可能会加点最近命令保存啥的功能。 挂载出口COM1到虚拟机 不管 emulator @Nexus_5_API_24 -writable-system -qemu -serial COM1 emulator @Pixel_2_API_22 -writable-system -qemu -serial COM1 git http://39.104.55.234:8998/root/truck-app.git 南湖 https://lanhuapp.com/link/#/invite?sid=lX070B5s 接口文档: https://apifox.com/apidoc/shared-72d5ca24-f2ef-4ab2-8a10-5fc3b70ddec6/doc-2772860 域名: https://mock.apifox.cn/m1/3026016-0-default 如:https://mock.apifox.cn/m1/3026016-0-default/box/boxinfo AABBCCDDEEFF // 命令注释 获取设备信息 发送:0x0 0x3 0x0 0x0 0x0 0xd 0x85 0xde 接收:0x0 0x3 0x1a 0xff 0xff 0xff 0x48 0x0 0x8 0x5 0x57 0x0 0x2 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x2 0x0 0x81 0x47 0xad 0x0 0x0 0x0 0x0 0xf8 0x75 # todo 调试工具 里面包含所有命令 mqtt 链接串口 发送指令 接收指令 测试报文 MainActivity.java # 两个服务 # 定时任务 发送读取设备状态指令 APP.java中调用 TimingTaskService # MQTT服务 订阅 接收消息 处理系统发来的消息 HomeActivity.java initMqttInfo()中调用 TqMqttService TqMqttService.startService(App.instance());//开启服务 # todo 初始化串口 连接 连接失败10秒后再连接 (可调) 类 App.java 方法1 initCOM() 打开串口 串口打开成功后开启一个定时任务 发送读取设备状态指令 TimingTaskService.startService(this); ModBusUtils 中 handleDeviceStatusData()中处理报警信息 # todo 获取设备id 类 DeviceIdUtil.java DeviceIdUtil.getDeviceId(App.instance()); # todo 获取缓存的登录后信息 类 TqMqttService.java 方法1 initLoginInfo() SPUtils.getInstance().put(SpConstants.DEVICESERIALNUMBER, params.getDeviceSerialNumber()); SPUtils.getInstance().put(SpConstants.TOKEN,params.getToken()); SPUtils.getInstance().put(SpConstants.TYPE,params.getType()); SPUtils.getInstance().put(SpConstants.DEVICESERIALNUMBER,params.getDeviceSerialNumber()+""); SPUtils.getInstance().put(SpConstants.BAGSERIALNUM,params.getBagSerialNum()+""); SPUtils.getInstance().put(SpConstants.LIMITWEIGHT,params.getLimitWeight()+""); SPUtils.getInstance().put(SpConstants.TAREONE,params.getTareOne()+""); SPUtils.getInstance().put(SpConstants.TARETWO,params.getTareTwo()+""); SPUtils.getInstance().put(SpConstants.PERPRICE,params.getPerPrice()+""); SPUtils.getInstance().put(SpConstants.USERNAME,params.getUserName()+""); SPUtils.getInstance().put(SpConstants.USERAVATAR,params.getUserAvatar()+""); # todo 处理系统发来的消息 类 TqMqttService.java 方法2 sysPublish() # todo 发布 (MQTT向服务器发送消息) 类 TqMqttService.java 方法3 publish(String topic, SendParams params) # todo 处理系统发布的消息 sys 这个代表系统给设备的消息,需要立刻执行对应的操作 类 TqMqttService.java 方法4 sysPublish(String topic, SendParams params) # todo 获取设备状态数据json信息 包含重量 温度 湿度 类 ModBusUtils.java 方法1 handleDeviceStatusData(String msg) 取值 String status = SPUtils.getInstance().getString(SpConstants.DEVICESTATUS); if (!TextUtils.isEmpty(status)){ DeviceStatus deviceStatusInfo = GsonUtils.fromJson(status, DeviceStatus.class); } 取值 List SPUtils.getInstance().getString(SpConstants.DEVICESTATUSLIST); 也可以这样取 ModBusUtils.deviceStatusList; ModBusUtils.deviceStatus; # todo 获取控制指令 类 ModBusUtils.java 方法2 getControlMsg(String msg) # todo 所有发布指令 参数 type ModBusConstants 中取 SerialPortManager.instance().sendCommand(ModBusUtils.getInstance().getControlMsg(type)); # 获取mqtt给服务器发的消息 绑定清运袋的逻辑也在这里 称重 类 MqttUtils.java 方法 getSendParams()