cmd_key_event.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. otaUrl: 'otaUrl',
  51. otaWifi: 'otaWifi',
  52. wallpaper: 'wallpaper',
  53. wallPaperData: 'wallPaperData',
  54. wallPaperMD5: 'wallPaperMD5',
  55. onoffline: 'onoffline',
  56. };
  57. // 枚举定义
  58. const EnumPlayStatus = {
  59. none: 'none',
  60. play: 'play',
  61. pause: 'pause',
  62. stop: 'stop',
  63. completed: 'completed',
  64. error: 'error',
  65. buffering: 'buffering', // APP自己定义的特殊处理中间状态
  66. };
  67. // 或者使用对象字面量
  68. const EnumSupplier = {
  69. shanJing: "ShanJing",
  70. jieLi: "JieLi",
  71. lingXin: "LingXin",
  72. qiXinWei: "QiXinWei"
  73. };
  74. // 设备操作类
  75. class CmdEvent {
  76. constructor({ cmdEvent }) {
  77. // this.cmdEvent = EnumCmdEvent.value
  78. this.cmdEvent = cmdEvent;
  79. this.channelId = 1;
  80. this.wakeSwitch = null;
  81. this.wakeCycle = [0, 0, 0, 0, 0, 0, 0];
  82. this.ctrlStatus = [0, 0, 0];
  83. this.lowPowerOpen = null;
  84. this.wakeHour = null;
  85. this.wakeMinutes = null;
  86. this.sleepSwitch = null;
  87. this.sleepHour = null;
  88. this.sleepMinutes = null;
  89. this.kwh = 9;
  90. this.kwhLeft = 9;
  91. this.kwhRight = 9;
  92. this.kwhBox = 9;
  93. this.lowKwnSet = false;
  94. this.volume = 0;
  95. this.version = "1.0.0";
  96. this.dsn = null;
  97. this.playStatus = null;
  98. this.playInfo = null;
  99. this.authInfo = null;
  100. this.item = null;
  101. this.eSim = null;
  102. this.sim = null;
  103. this.simIndex = null;
  104. this.enableTTS = null;
  105. this.eqs = null;
  106. this.lowDelayMode = null;
  107. this.lowDelayModeOpen = null;
  108. this.netModeAuto = null;
  109. this.pauseSleep = null;
  110. this.collectStatus = null;
  111. this.audioInfoId = null;
  112. this.todayStep = null;
  113. this.todayRates = null;
  114. this.stepTarget = null;
  115. this.setTimeFormat = null;
  116. this.setQuickViewTime = null;
  117. this.setNotDisturb = null;
  118. this.openPush = null;
  119. this.takeHandLight = null;
  120. this.stepDistance = null;
  121. this.stepCalories = null;
  122. this.stepTime = null;
  123. this.payId = null;
  124. this.btMac = null;
  125. this.deviceMode = null;
  126. this.otaCmd = null;
  127. this.otaUrl = null;
  128. this.heiJiaoKind = null;
  129. this.wallpaper = null;
  130. this.deviceId = null;
  131. this.commonValue = null;
  132. }
  133. static eventName = "cmdEventNotification"
  134. static wake({ wakeSwitch, wakeCycle, wakeHour, wakeMinutes }) {
  135. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wake });
  136. event.wakeSwitch = wakeSwitch;
  137. event.wakeCycle = wakeCycle;
  138. event.wakeHour = wakeHour;
  139. event.wakeMinutes = wakeMinutes;
  140. return event;
  141. }
  142. static sim({ eSim, sim, simIndex }) {
  143. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sim });
  144. event.eSim = eSim;
  145. event.sim = sim;
  146. event.simIndex = simIndex;
  147. return event;
  148. }
  149. static sleep({ sleepSwitch, sleepHour, sleepMinutes }) {
  150. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sleep });
  151. event.sleepSwitch = sleepSwitch;
  152. event.sleepHour = sleepHour;
  153. event.sleepMinutes = sleepMinutes;
  154. return event;
  155. }
  156. static ctrlStatus({ ctrlStatus }) {
  157. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.ctrlStatus });
  158. event.ctrlStatus = ctrlStatus;
  159. return event;
  160. }
  161. static switchChannel({ channelId }) {
  162. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchChannel });
  163. event.channelId = channelId;
  164. return event;
  165. }
  166. static switchDeviceMode({ deviceMode }) {
  167. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchDeviceMode });
  168. event.deviceMode = deviceMode;
  169. return event;
  170. }
  171. static enableTTS({ enableTTS }) {
  172. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.enableTTS });
  173. event.enableTTS = enableTTS;
  174. return event;
  175. }
  176. static battery({ kwh }) {
  177. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.battery });
  178. event.kwh = kwh;
  179. return event;
  180. }
  181. static queryLowKwn({ kwh }) {
  182. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowKwnSet });
  183. event.kwh = kwh;
  184. return event;
  185. }
  186. static dsn({ dsn }) {
  187. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.dsn });
  188. event.dsn = dsn;
  189. return event;
  190. }
  191. static getDeviceInfo() {
  192. return new CmdEvent({ cmdEvent: EnumCmdEvent.getDeviceInfo });
  193. }
  194. static todayStep({ 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 todaySport({ todayStep, stepDistance, stepCalories, stepTime }) {
  203. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayStep });
  204. event.todayStep = todayStep;
  205. event.stepDistance = stepDistance;
  206. event.stepCalories = stepCalories;
  207. event.stepTime = stepTime;
  208. return event;
  209. }
  210. static todayRates({ todayRates }) {
  211. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayRates });
  212. event.todayRates = todayRates;
  213. return event;
  214. }
  215. static pauseSleep({ pauseSleep }) {
  216. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.authSleepStatus });
  217. event.pauseSleep = pauseSleep;
  218. console.log("pauseSleep:", pauseSleep)
  219. return event;
  220. }
  221. static targetSteps({ stepTarget }) {
  222. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.targetSteps });
  223. event.stepTarget = stepTarget;
  224. return event;
  225. }
  226. static setTimeFormat({ setTimeFormat }) {
  227. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setTimeFormat });
  228. event.setTimeFormat = setTimeFormat;
  229. return event;
  230. }
  231. static setNotDisturb({ setNotDisturb }) {
  232. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setNotDisturb });
  233. event.setNotDisturb = setNotDisturb;
  234. return event;
  235. }
  236. static setQuickViewTime({ setQuickViewTime }) {
  237. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setQuickViewTime });
  238. event.setQuickViewTime = setQuickViewTime;
  239. return event;
  240. }
  241. static openPush({ openPush }) {
  242. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.openPush });
  243. event.openPush = openPush;
  244. return event;
  245. }
  246. static takeHandLight({ takeHandLight }) {
  247. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.takeHandLight });
  248. event.takeHandLight = takeHandLight;
  249. return event;
  250. }
  251. static batteryEarphone({ kwh, kwhLeft, kwhRight, kwhBox }) {
  252. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.batteryEarphone });
  253. event.kwh = kwh;
  254. event.kwhLeft = kwhLeft;
  255. event.kwhRight = kwhRight;
  256. event.kwhBox = kwhBox;
  257. return event;
  258. }
  259. static unbind({ item }) {
  260. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.unbind });
  261. event.item = item;
  262. return event;
  263. }
  264. static auth({ authInfo }) {
  265. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.auth });
  266. event.authInfo = authInfo;
  267. return event;
  268. }
  269. static eqs({ eqs }) {
  270. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.eq });
  271. event.eqs = eqs;
  272. return event;
  273. }
  274. static lowDelayMode({ lowDelayMode, lowDelayModeOpen }) {
  275. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowDelayMode });
  276. event.lowDelayMode = lowDelayMode;
  277. event.lowDelayModeOpen = lowDelayModeOpen;
  278. return event;
  279. }
  280. static lowPowerOpen({ lowPowerOpen }) {
  281. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowPowerOpen });
  282. event.lowPowerOpen = lowPowerOpen;
  283. return event;
  284. }
  285. static volume({ volume }) {
  286. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.volume });
  287. event.volume = volume;
  288. return event;
  289. }
  290. static version({ version }) {
  291. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.version });
  292. console.log('版本号:', version, { version });
  293. event.version = version;
  294. return event;
  295. }
  296. static btMac({ btMac }) {
  297. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.btMac });
  298. event.btMac = btMac;
  299. return event;
  300. }
  301. static clientType({ clientType }) {
  302. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.clientType });
  303. console.log("clientType:", clientType)
  304. event.clientType = clientType;
  305. return event;
  306. }
  307. static otaCmd({ value, kind }) {
  308. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.otaCmd });
  309. event.otaCmd = value;
  310. event.heiJiaoKind = kind;
  311. return event;
  312. }
  313. static otaUrl({ value, kind }) {
  314. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.otaUrl });
  315. event.otaCmd = value;
  316. event.heiJiaoKind = kind;
  317. return event;
  318. }
  319. static otaWifi({ value, kind }) {
  320. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.otaWifi });
  321. event.otaCmd = value;
  322. event.heiJiaoKind = kind;
  323. return event;
  324. }
  325. static wallpaper({ value, kind }) {
  326. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wallpaper });
  327. console.log("wallpaper:", value, kind)
  328. event.wallpaper = value;
  329. event.heiJiaoKind = kind;
  330. return event;
  331. }
  332. static wallPaperData({ value, kind }) {
  333. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wallPaperData });
  334. // console.log("wallPaperData", value, kind)
  335. event.wallpaper = value;
  336. event.heiJiaoKind = kind;
  337. return event;
  338. }
  339. static wallPaperMD5({ value, kind }) {
  340. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wallPaperMD5 });
  341. console.log("wallPaperMD5", value, kind)
  342. event.wallpaper = value;
  343. event.heiJiaoKind = kind;
  344. return event;
  345. }
  346. static netModeAuto({ netModeAuto }) {
  347. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.netModeAuto });
  348. event.netModeAuto = netModeAuto;
  349. return event;
  350. }
  351. static playInfo({ playInfo }) {
  352. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playInfo });
  353. event.playInfo = playInfo;
  354. return event;
  355. }
  356. static payId({ payId }) {
  357. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.payId });
  358. event.payId = payId;
  359. return event;
  360. }
  361. static collectState({ collectStatus, audioInfoId }) {
  362. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.collectState });
  363. event.collectStatus = collectStatus;
  364. event.audioInfoId = audioInfoId;
  365. return event;
  366. }
  367. static onoffline({ deviceId, state }) {
  368. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.onoffline });
  369. event.commonValue = state;
  370. event.deviceId = deviceId;
  371. return event;
  372. }
  373. static playStatus({ playStatus }) {
  374. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playStatus });
  375. switch (playStatus) {
  376. case 1:
  377. event.playStatus = EnumPlayStatus.play;
  378. break;
  379. case 2:
  380. event.playStatus = EnumPlayStatus.pause;
  381. break;
  382. case 3:
  383. event.playStatus = EnumPlayStatus.stop;
  384. break;
  385. case 4:
  386. event.playStatus = EnumPlayStatus.completed;
  387. break;
  388. default:
  389. }
  390. return event
  391. }
  392. toString() {
  393. 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}}`;
  394. }
  395. }
  396. module.exports = {
  397. CmdEvent,
  398. EnumCmdEvent,
  399. EnumPlayStatus,
  400. EnumSupplier
  401. };