cmd_key_event.js 12 KB

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