bmiMachine.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {Base} from "@/utils/usbSerial/base";
  2. import {logs} from "@/utils/util";
  3. import {orderToData} from "@/utils/ble/hex";
  4. export class BmiMachine extends Base {
  5. constructor(topClass, usbSerial) {
  6. super(topClass, usbSerial)
  7. this.id = 'bmi'
  8. this.title = 'BMI体重秤'
  9. this.config = {
  10. baudRate: 9600,
  11. dataBits: 8,
  12. stopBits: 1,
  13. parity: 0,
  14. flowControl: 0,
  15. }
  16. }
  17. read(resp) {
  18. // resp.value = ASCIIUtils.decodeUtf8(resp.data)
  19. // logs('bmi usbSerial.read', resp)
  20. // 7.40kg 98.5cm 9???
  21. // let str = '0240303037343030303938353030303030303030303030303030303030303030303030303030303037373030303030403503'
  22. let resArr = this.packetManager(resp.data)
  23. resArr.forEach(it => {
  24. let code = it.substring(2, 4)
  25. let orderContent = it.slice(4, -6)
  26. let result = {}
  27. let acceptOrder = this.getAcceptOrder(code)
  28. if (acceptOrder) result = orderToData(orderContent, acceptOrder.c, 0)
  29. if (this.notifyFun) this.notifyFun(result)
  30. })
  31. }
  32. getAcceptOrder(cmd) {
  33. let order = {
  34. '40': {
  35. l: 20,
  36. c: [
  37. {t: 4, k: 'kg', l: 10, fun: (it) => it ? it / 100 : 0},
  38. {t: 4, k: 'cm', l: 10, fun: (it) => it / 10},
  39. {t: 4, k: 'k3', l: 10, fun: (it) => it / 10},
  40. {t: 4, k: 'k4', l: 10, fun: (it) => it / 10},
  41. {t: 4, k: 'k5', l: 10, fun: (it) => it / 10},
  42. {t: 4, k: 'k6', l: 10, fun: (it) => it / 10},
  43. {t: 4, k: 'k7', l: 10},
  44. {t: 4, k: 'k8', l: 10, fun: (it) => it / 10},
  45. {t: 4, k: 'k9', l: 10, fun: (it) => it / 10},
  46. ]
  47. },
  48. }
  49. return order[cmd] || null
  50. }
  51. }