cmd_key_event.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. // 枚举定义
  2. const EnumCmdEvent = {
  3. nextChannel: 'nextChannel',
  4. previousChannel: 'previousChannel',
  5. switchChannel: 'switchChannel',
  6. previousAlbum: 'previousAlbum',
  7. nextAlbum: 'nextAlbum',
  8. nextSong: 'nextSong',
  9. previousSong: 'previousSong',
  10. speed: 'speed',
  11. fastback: 'fastback',
  12. stopSpeed: 'stopSpeed',
  13. stopFastback: 'stopFastback',
  14. startRecord: 'startRecord',
  15. stopRecord: 'stopRecord',
  16. battery: 'battery',
  17. lowKwnSet: 'lowKwnSet',
  18. batteryEarphone: 'batteryEarphone',
  19. ctrlStatus: 'ctrlStatus',
  20. lowPowerOpen: 'lowPowerOpen',
  21. eq: 'eq',
  22. lowDelayMode: 'lowDelayMode',
  23. sleep: 'sleep',
  24. wake: 'wake',
  25. volume: 'volume',
  26. version: 'version',
  27. sim: 'sim',
  28. dsn: 'dsn',
  29. playInfo: 'playInfo',
  30. playStatus: 'playStatus',
  31. auth: 'auth',
  32. unbind: 'unbind',
  33. enableTTS: 'enableTTS',
  34. switchDeviceMode: 'switchDeviceMode',
  35. netModeAuto: 'netModeAuto',
  36. getDeviceInfo: 'getDeviceInfo',
  37. collectState: 'collectState',
  38. todayStep: 'todayStep',
  39. todayRates: 'todayRates',
  40. targetSteps: 'targetSteps',
  41. setTimeFormat: 'setTimeFormat',
  42. setNotDisturb: 'setNotDisturb',
  43. setQuickViewTime: 'setQuickViewTime',
  44. openPush: 'openPush',
  45. takeHandLight: 'takeHandLight',
  46. payId: 'payId',
  47. authSleepStatus: 'authSleepStatus',
  48. btMac: 'btMac',
  49. otaCmd: 'otaCmd',
  50. wallpaper: 'wallpaper'
  51. };
  52. // 枚举定义
  53. const EnumPlayStatus = {
  54. none: 'none',
  55. play: 'play',
  56. pause: 'pause',
  57. stop: 'stop',
  58. completed: 'completed',
  59. error: 'error',
  60. buffering: 'buffering', // APP自己定义的特殊处理中间状态
  61. };
  62. // 或者使用对象字面量
  63. const EnumSupplier = {
  64. shanJing: "ShanJing",
  65. jieLi: "JieLi",
  66. lingXin: "LingXin",
  67. qiXinWei: "QiXinWei"
  68. };
  69. // 设备操作类
  70. class CmdEvent {
  71. constructor({ cmdEvent }) {
  72. // this.cmdEvent = EnumCmdEvent.value
  73. this.cmdEvent = cmdEvent;
  74. this.channelId = 1;
  75. this.wakeSwitch = null;
  76. this.wakeCycle = [0, 0, 0, 0, 0, 0, 0];
  77. this.ctrlStatus = [0, 0, 0];
  78. this.lowPowerOpen = null;
  79. this.wakeHour = null;
  80. this.wakeMinutes = null;
  81. this.sleepSwitch = null;
  82. this.sleepHour = null;
  83. this.sleepMinutes = null;
  84. this.kwh = 9;
  85. this.kwhLeft = 9;
  86. this.kwhRight = 9;
  87. this.kwhBox = 9;
  88. this.lowKwnSet = false;
  89. this.volume = 0;
  90. this.version = "1.0.0";
  91. this.dsn = null;
  92. this.playStatus = null;
  93. this.playInfo = null;
  94. this.authInfo = null;
  95. this.item = null;
  96. this.eSim = null;
  97. this.sim = null;
  98. this.simIndex = null;
  99. this.enableTTS = null;
  100. this.eqs = null;
  101. this.lowDelayMode = null;
  102. this.lowDelayModeOpen = null;
  103. this.netModeAuto = null;
  104. this.pauseSleep = null;
  105. this.collectStatus = null;
  106. this.audioInfoId = null;
  107. this.todayStep = null;
  108. this.todayRates = null;
  109. this.stepTarget = null;
  110. this.setTimeFormat = null;
  111. this.setQuickViewTime = null;
  112. this.setNotDisturb = null;
  113. this.openPush = null;
  114. this.takeHandLight = null;
  115. this.stepDistance = null;
  116. this.stepCalories = null;
  117. this.stepTime = null;
  118. this.payId = null;
  119. this.btMac = null;
  120. this.deviceMode = null;
  121. this.otaCmd = null;
  122. this.heiJiaoKind = null;
  123. this.wallpaper = null;
  124. }
  125. static eventName = "cmdEventNotification"
  126. static wake({ wakeSwitch, wakeCycle, wakeHour, wakeMinutes }) {
  127. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wake });
  128. event.wakeSwitch = wakeSwitch;
  129. event.wakeCycle = wakeCycle;
  130. event.wakeHour = wakeHour;
  131. event.wakeMinutes = wakeMinutes;
  132. return event;
  133. }
  134. static sim({ eSim, sim, simIndex }) {
  135. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sim });
  136. event.eSim = eSim;
  137. event.sim = sim;
  138. event.simIndex = simIndex;
  139. return event;
  140. }
  141. static sleep({ sleepSwitch, sleepHour, sleepMinutes }) {
  142. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sleep });
  143. event.sleepSwitch = sleepSwitch;
  144. event.sleepHour = sleepHour;
  145. event.sleepMinutes = sleepMinutes;
  146. return event;
  147. }
  148. static ctrlStatus({ ctrlStatus }) {
  149. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.ctrlStatus });
  150. event.ctrlStatus = ctrlStatus;
  151. return event;
  152. }
  153. static switchChannel({ channelId }) {
  154. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchChannel });
  155. event.channelId = channelId;
  156. return event;
  157. }
  158. static switchDeviceMode({ deviceMode }) {
  159. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchDeviceMode });
  160. event.deviceMode = deviceMode;
  161. return event;
  162. }
  163. static enableTTS({ enableTTS }) {
  164. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.enableTTS });
  165. event.enableTTS = enableTTS;
  166. return event;
  167. }
  168. static battery({ kwh }) {
  169. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.battery });
  170. event.kwh = kwh;
  171. return event;
  172. }
  173. static queryLowKwn({ kwh }) {
  174. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowKwnSet });
  175. event.kwh = kwh;
  176. return event;
  177. }
  178. static dsn({ dsn }) {
  179. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.dsn });
  180. event.dsn = dsn;
  181. return event;
  182. }
  183. static getDeviceInfo() {
  184. return new CmdEvent({ cmdEvent: EnumCmdEvent.getDeviceInfo });
  185. }
  186. static todayStep({ todayStep, stepDistance, stepCalories, stepTime }) {
  187. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayStep });
  188. event.todayStep = todayStep;
  189. event.stepDistance = stepDistance;
  190. event.stepCalories = stepCalories;
  191. event.stepTime = stepTime;
  192. return event;
  193. }
  194. static todaySport({ todayStep, stepDistance, stepCalories, stepTime }) {
  195. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayStep });
  196. event.todayStep = todayStep;
  197. event.stepDistance = stepDistance;
  198. event.stepCalories = stepCalories;
  199. event.stepTime = stepTime;
  200. return event;
  201. }
  202. static todayRates({ todayRates }) {
  203. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayRates });
  204. event.todayRates = todayRates;
  205. return event;
  206. }
  207. static pauseSleep({ pauseSleep }) {
  208. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.authSleepStatus });
  209. event.pauseSleep = pauseSleep;
  210. console.log("pauseSleep:", pauseSleep)
  211. return event;
  212. }
  213. static targetSteps({ stepTarget }) {
  214. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.targetSteps });
  215. event.stepTarget = stepTarget;
  216. return event;
  217. }
  218. static setTimeFormat({ setTimeFormat }) {
  219. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setTimeFormat });
  220. event.setTimeFormat = setTimeFormat;
  221. return event;
  222. }
  223. static setNotDisturb({ setNotDisturb }) {
  224. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setNotDisturb });
  225. event.setNotDisturb = setNotDisturb;
  226. return event;
  227. }
  228. static setQuickViewTime({ setQuickViewTime }) {
  229. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setQuickViewTime });
  230. event.setQuickViewTime = setQuickViewTime;
  231. return event;
  232. }
  233. static openPush({ openPush }) {
  234. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.openPush });
  235. event.openPush = openPush;
  236. return event;
  237. }
  238. static takeHandLight({ takeHandLight }) {
  239. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.takeHandLight });
  240. event.takeHandLight = takeHandLight;
  241. return event;
  242. }
  243. static batteryEarphone({ kwh, kwhLeft, kwhRight, kwhBox }) {
  244. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.batteryEarphone });
  245. event.kwh = kwh;
  246. event.kwhLeft = kwhLeft;
  247. event.kwhRight = kwhRight;
  248. event.kwhBox = kwhBox;
  249. return event;
  250. }
  251. static unbind({ item }) {
  252. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.unbind });
  253. event.item = item;
  254. return event;
  255. }
  256. static auth({ authInfo }) {
  257. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.auth });
  258. event.authInfo = authInfo;
  259. return event;
  260. }
  261. static eqs({ eqs }) {
  262. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.eq });
  263. event.eqs = eqs;
  264. return event;
  265. }
  266. static lowDelayMode({ lowDelayMode, lowDelayModeOpen }) {
  267. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowDelayMode });
  268. event.lowDelayMode = lowDelayMode;
  269. event.lowDelayModeOpen = lowDelayModeOpen;
  270. return event;
  271. }
  272. static lowPowerOpen({ lowPowerOpen }) {
  273. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowPowerOpen });
  274. event.lowPowerOpen = lowPowerOpen;
  275. return event;
  276. }
  277. static volume({ volume }) {
  278. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.volume });
  279. event.volume = volume;
  280. return event;
  281. }
  282. static version({ version }) {
  283. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.version });
  284. console.log('版本号:', version, {version});
  285. event.version = version;
  286. return event;
  287. }
  288. static btMac({ btMac }) {
  289. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.btMac });
  290. event.btMac = btMac;
  291. return event;
  292. }
  293. static clientType({ clientType }) {
  294. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.clientType });
  295. console.log("clientType:", clientType)
  296. event.clientType = clientType;
  297. return event;
  298. }
  299. static otaCmd({ value, Kind }) {
  300. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.otaCmd });
  301. event.otaCmd = value;
  302. event.heiJiaoKind = Kind;
  303. return event;
  304. }
  305. static wallpaper({ value, Kind }) {
  306. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wallpaper });
  307. event.wallpaper = value;
  308. event.heiJiaoKind = Kind;
  309. return event;
  310. }
  311. static netModeAuto({ netModeAuto }) {
  312. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.netModeAuto });
  313. event.netModeAuto = netModeAuto;
  314. return event;
  315. }
  316. static playInfo({ playInfo }) {
  317. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playInfo });
  318. event.playInfo = playInfo;
  319. return event;
  320. }
  321. static payId({ payId }) {
  322. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.payId });
  323. event.payId = payId;
  324. return event;
  325. }
  326. static collectState({ collectStatus, audioInfoId }) {
  327. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.collectState });
  328. event.collectStatus = collectStatus;
  329. event.audioInfoId = audioInfoId;
  330. return event;
  331. }
  332. static playStatus({ playStatus }) {
  333. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playStatus });
  334. switch (playStatus) {
  335. case 1:
  336. event.playStatus = EnumPlayStatus.play;
  337. break;
  338. case 2:
  339. event.playStatus = EnumPlayStatus.pause;
  340. break;
  341. case 3:
  342. event.playStatus = EnumPlayStatus.stop;
  343. break;
  344. case 4:
  345. event.playStatus = EnumPlayStatus.completed;
  346. break;
  347. default:
  348. }
  349. return event
  350. }
  351. toString() {
  352. return `CmdEvent{cmdEvent: ${this.cmdEvent}, channelId: ${this.channelId}, wakeSwitch: ${this.wakeSwitch}, wakeCycle: ${this.wakeCycle}, wakeHour: ${this.wakeHour}, wakeMinutes: ${this.wakeMinutes}, sleepSwitch: ${this.sleepSwitch}, sleepHour: ${this.sleepHour}, sleepMinutes: ${this.sleepMinutes}, kwh: ${this.kwh}, volume: ${this.volume}, version: ${this.version}}`;
  353. }
  354. }
  355. module.exports = {
  356. CmdEvent,
  357. EnumCmdEvent,
  358. EnumPlayStatus,
  359. EnumSupplier
  360. };