package com.emato.ich.device; import android.util.Log; import com.cherry.sdk.controller.InitDevice; import com.cherry.sdk.controller.MoternDeviceController; import com.cherry.sdk.controller.callback.CmdCallback; import com.emato.ich.utils.JacksonUtils; import java.util.Arrays; /** * 0 : 操作成功 * 1 : 操作失败 * 1701:串口通讯超时 * 1702:串口占用 * 1703:串口发送数据错误 * 1704:串口数据校验失败 * 1705:开门时返回锁状态错误 * 1801:不支持该操作 * 单查柜门返回: unlocked(柜门关闭)locked(柜门打开) * 全查柜门返回 {“section”:1,”port”: 1, “unlocked”: true /false (true柜门打开,false柜门关闭)} * 其他指令无message返回 */ public class DeviceControl { private static final String TAG = "DeviceControl"; private static final MoternDeviceController initedInstance; static { int boardType = 7; initedInstance = MoternDeviceController.getInstance(); initedInstance.init(new InitDevice(boardType)); } /** * 函数描述 * 函数用途:查询锁版版本 */ public static Object queryVersion(int section) { Log.d(TAG, "查询锁版本开始"); DeviceResult result = new DeviceResult(); initedInstance.queryVersion(section, new CmdCallback() { @Override public void onMessage(int code, String... dataArr) { result.setData(Arrays.asList(dataArr)); result.setCode(code); Log.d(TAG, "查询锁版本回调结果:" + JacksonUtils.toJson(result)); } }); Log.d(TAG, "查询锁版本结束"); return null; } /** * 函数用途:控制面板灯(仅3号类型设备支持) * 参数 :model, CmdCallback(model灯控指令如下) * 0; //开补光灯 * 1; //关所有灯 * 2; //打开白灯 * 3; //关闭白灯 * 4; //打开红外补光灯 * 5; //关闭红外补光灯 * 6; //打开红灯 * 7; //打开绿灯 */ public static boolean setFaceLight(int mode) { initedInstance.setFaceLight(mode, new CmdCallback() { @Override public void onMessage(int i, String... strings) { } }); return false; } /** * 函数用途:打开柜门 * 参数 :section, port, CmdCallback */ public static boolean unlockLocker(int section, int port) { System.out.println("打开柜门开始"); initedInstance.unlockLocker(section, port, new CmdCallback() { @Override public void onMessage(int i, String... strings) { System.out.println("打开柜门回调结果"); System.out.println(Arrays.toString(strings)); System.out.println(i); } }); System.out.println("打开柜门结束"); return false; } /** * 函数用途:查询柜门状态 * 参数 :section, port, CmdCallback */ public static Object queryLocker(int section, int port) { initedInstance.queryLocker(section, port, new CmdCallback() { @Override public void onMessage(int i, String... strings) { } }); return false; } /** * 函数用途:全开柜门 * 参数 :section, CmdCallback */ public static boolean unlockSection() { initedInstance.unlockSection(1, new CmdCallback() { @Override public void onMessage(int i, String... strings) { } }); return false; } /** * 函数用途:查询柜门状态 * 参数 :section, CmdCallback */ public static Object querySection() { initedInstance.querySection(1, new CmdCallback() { @Override public void onMessage(int i, String... strings) { } }); return null; } /** * 函数用途:继电器控制 * 参数 :section, port, opt, CmdCallback * opt: 1 开启继电器 * opt: 0 关闭继电器 */ public static boolean relayOpt() { initedInstance.relayOpt(1, 1, 1, new CmdCallback() { @Override public void onMessage(int i, String... strings) { } }); return false; } /** * 函数用途:控制柜门加热 * 参数 :section, port, opt, CmdCallback * opt: 1 打开加热 * opt: 2 关闭加热 */ public static boolean hotLocker() { initedInstance.hotLocker(1, 1, 1, new CmdCallback() { @Override public void onMessage(int i, String... strings) { } }); return false; } /** * 函数用途:全控柜门加热 * 参数 :section, opt, CmdCallback * opt: 1 打开加热 * opt: 2 关闭加热 */ public static boolean hotSection() { initedInstance.hotSection(1, 1, new CmdCallback() { @Override public void onMessage(int i, String... strings) { } }); return false; } /** * 函数用途:控制柜门消毒 * 参数 :section, port, opt, CmdCallback * opt: 1 打开消毒 * opt: 2 关闭消毒 */ public static boolean degasLocker() { initedInstance.degasLocker(1, 1, 1, new CmdCallback() { @Override public void onMessage(int i, String... strings) { } }); return false; } /** * 函数用途:全控柜门消毒 * 参数 :section, opt, CmdCallback * opt: 1 打开消毒 * opt: 2 关闭消毒 */ public static boolean degasSection() { // initedInstance.degasSection(1, new CmdCallback() { // @Override // public void onMessage(int i, String... strings) { // // } // }); return false; } private static class DefaultCmdCallbackHandler implements CmdCallback { private DeviceResult result; public DefaultCmdCallbackHandler() { this.result = new DeviceResult(); } public DeviceResult getResult() { return result; } @Override public void onMessage(int i, String... strings) { result.setCode(i); result.setData(Arrays.asList(strings)); } } }