cmd_key_event.js 13 KB

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