1
0

DeviceControl.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. package com.emato.ich.device;
  2. import android.util.Log;
  3. import com.cherry.sdk.controller.InitDevice;
  4. import com.cherry.sdk.controller.MoternDeviceController;
  5. import com.cherry.sdk.controller.callback.CmdCallback;
  6. import com.emato.ich.utils.JacksonUtils;
  7. import java.util.Arrays;
  8. /**
  9. * 0 : 操作成功
  10. * 1 : 操作失败
  11. * 1701:串口通讯超时
  12. * 1702:串口占用
  13. * 1703:串口发送数据错误
  14. * 1704:串口数据校验失败
  15. * 1705:开门时返回锁状态错误
  16. * 1801:不支持该操作
  17. * 单查柜门返回: unlocked(柜门关闭)locked(柜门打开)
  18. * 全查柜门返回 {“section”:1,”port”: 1, “unlocked”: true /false (true柜门打开,false柜门关闭)}
  19. * 其他指令无message返回
  20. */
  21. public class DeviceControl {
  22. private static final String TAG = "DeviceControl";
  23. private static final MoternDeviceController initedInstance;
  24. static {
  25. int boardType = 7;
  26. initedInstance = MoternDeviceController.getInstance();
  27. initedInstance.init(new InitDevice(boardType));
  28. }
  29. /**
  30. * 函数描述
  31. * 函数用途:查询锁版版本
  32. */
  33. public static Object queryVersion(int section) {
  34. Log.d(TAG, "查询锁版本开始");
  35. DeviceResult result = new DeviceResult();
  36. initedInstance.queryVersion(section, new CmdCallback() {
  37. @Override
  38. public void onMessage(int code, String... dataArr) {
  39. result.setData(Arrays.asList(dataArr));
  40. result.setCode(code);
  41. Log.d(TAG, "查询锁版本回调结果:" + JacksonUtils.toJson(result));
  42. }
  43. });
  44. Log.d(TAG, "查询锁版本结束");
  45. return null;
  46. }
  47. /**
  48. * 函数用途:控制面板灯(仅3号类型设备支持)
  49. * 参数 :model, CmdCallback(model灯控指令如下)
  50. * 0; //开补光灯
  51. * 1; //关所有灯
  52. * 2; //打开白灯
  53. * 3; //关闭白灯
  54. * 4; //打开红外补光灯
  55. * 5; //关闭红外补光灯
  56. * 6; //打开红灯
  57. * 7; //打开绿灯
  58. */
  59. public static boolean setFaceLight(int mode) {
  60. initedInstance.setFaceLight(mode, new CmdCallback() {
  61. @Override
  62. public void onMessage(int i, String... strings) {
  63. }
  64. });
  65. return false;
  66. }
  67. /**
  68. * 函数用途:打开柜门
  69. * 参数 :section, port, CmdCallback
  70. */
  71. public static boolean unlockLocker(int section, int port) {
  72. System.out.println("打开柜门开始");
  73. initedInstance.unlockLocker(section, port, new CmdCallback() {
  74. @Override
  75. public void onMessage(int i, String... strings) {
  76. System.out.println("打开柜门回调结果");
  77. System.out.println(Arrays.toString(strings));
  78. System.out.println(i);
  79. }
  80. });
  81. System.out.println("打开柜门结束");
  82. return false;
  83. }
  84. /**
  85. * 函数用途:查询柜门状态
  86. * 参数 :section, port, CmdCallback
  87. */
  88. public static Object queryLocker(int section, int port) {
  89. initedInstance.queryLocker(section, port, new CmdCallback() {
  90. @Override
  91. public void onMessage(int i, String... strings) {
  92. }
  93. });
  94. return false;
  95. }
  96. /**
  97. * 函数用途:全开柜门
  98. * 参数 :section, CmdCallback
  99. */
  100. public static boolean unlockSection() {
  101. initedInstance.unlockSection(1, new CmdCallback() {
  102. @Override
  103. public void onMessage(int i, String... strings) {
  104. }
  105. });
  106. return false;
  107. }
  108. /**
  109. * 函数用途:查询柜门状态
  110. * 参数 :section, CmdCallback
  111. */
  112. public static Object querySection() {
  113. initedInstance.querySection(1, new CmdCallback() {
  114. @Override
  115. public void onMessage(int i, String... strings) {
  116. }
  117. });
  118. return null;
  119. }
  120. /**
  121. * 函数用途:继电器控制
  122. * 参数 :section, port, opt, CmdCallback
  123. * opt: 1 开启继电器
  124. * opt: 0 关闭继电器
  125. */
  126. public static boolean relayOpt() {
  127. initedInstance.relayOpt(1, 1, 1, new CmdCallback() {
  128. @Override
  129. public void onMessage(int i, String... strings) {
  130. }
  131. });
  132. return false;
  133. }
  134. /**
  135. * 函数用途:控制柜门加热
  136. * 参数 :section, port, opt, CmdCallback
  137. * opt: 1 打开加热
  138. * opt: 2 关闭加热
  139. */
  140. public static boolean hotLocker() {
  141. initedInstance.hotLocker(1, 1, 1, new CmdCallback() {
  142. @Override
  143. public void onMessage(int i, String... strings) {
  144. }
  145. });
  146. return false;
  147. }
  148. /**
  149. * 函数用途:全控柜门加热
  150. * 参数 :section, opt, CmdCallback
  151. * opt: 1 打开加热
  152. * opt: 2 关闭加热
  153. */
  154. public static boolean hotSection() {
  155. initedInstance.hotSection(1, 1, new CmdCallback() {
  156. @Override
  157. public void onMessage(int i, String... strings) {
  158. }
  159. });
  160. return false;
  161. }
  162. /**
  163. * 函数用途:控制柜门消毒
  164. * 参数 :section, port, opt, CmdCallback
  165. * opt: 1 打开消毒
  166. * opt: 2 关闭消毒
  167. */
  168. public static boolean degasLocker() {
  169. initedInstance.degasLocker(1, 1, 1, new CmdCallback() {
  170. @Override
  171. public void onMessage(int i, String... strings) {
  172. }
  173. });
  174. return false;
  175. }
  176. /**
  177. * 函数用途:全控柜门消毒
  178. * 参数 :section, opt, CmdCallback
  179. * opt: 1 打开消毒
  180. * opt: 2 关闭消毒
  181. */
  182. public static boolean degasSection() {
  183. // initedInstance.degasSection(1, new CmdCallback() {
  184. // @Override
  185. // public void onMessage(int i, String... strings) {
  186. //
  187. // }
  188. // });
  189. return false;
  190. }
  191. private static class DefaultCmdCallbackHandler implements CmdCallback {
  192. private DeviceResult result;
  193. public DefaultCmdCallbackHandler() {
  194. this.result = new DeviceResult();
  195. }
  196. public DeviceResult getResult() {
  197. return result;
  198. }
  199. @Override
  200. public void onMessage(int i, String... strings) {
  201. result.setCode(i);
  202. result.setData(Arrays.asList(strings));
  203. }
  204. }
  205. }