ailink ble wifi 小程序配网演示demo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. function inArray(arr, key, val) {
  2. if (!arr || !arr.length || typeof arr != 'object' || !Array.isArray(arr)) {
  3. return -1
  4. }
  5. for (let i = 0; i < arr.length; i++) {
  6. if (!key) {
  7. if (arr[i] == val) {
  8. return i
  9. }
  10. } else if (arr[i][key] === val) {
  11. return i
  12. }
  13. }
  14. return -1;
  15. }
  16. // ArrayBuffer转16进度字符串示例
  17. function ab2hex(buffer, split) {
  18. var hexArr = Array.prototype.map.call(
  19. new Uint8Array(buffer),
  20. function (bit) {
  21. return ('00' + bit.toString(16)).slice(-2)
  22. }
  23. )
  24. return hexArr.join(split);
  25. }
  26. const {TextDecoder, TextEncoder} = require('./encoding')
  27. function hex2str(arr) {
  28. let decoder = new TextDecoder('utf8')
  29. let uint8 = new Uint8Array(arr)
  30. let res = decoder.decode(uint8)
  31. return res
  32. }
  33. function str2hex(str) {
  34. let encoder = new TextEncoder('utf8')
  35. return encoder.encode(str)
  36. }
  37. module.exports = {
  38. inArray,
  39. ab2hex,
  40. hex2str,
  41. str2hex,
  42. }