commonFunction.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. module.exports = {
  2. // buffer 转16进制
  3. buf2hex:function (buffer) {
  4. // create a byte array (Uint8Array) that we can use to read the array buffer
  5. const byteArray = new Uint8Array(buffer);
  6. // for each element, we want to get its two-digit hexadecimal representation
  7. const hexParts = [];
  8. for(let i = 0; i < byteArray.length; i++) {
  9. // convert value to hexadecimal
  10. const hex = byteArray[i].toString(16);
  11. // pad with zeros to length 2
  12. const paddedHex = ('00' + hex).slice(-2);
  13. // push to array
  14. hexParts.push(paddedHex);
  15. }
  16. // join all the hex values of the elements into a single string
  17. return hexParts.join('');
  18. },
  19. // 足压数据补齐点位为60*60 并进行点扩散
  20. setPressureData:function (data) {
  21. let dataAll = []
  22. // 补到之前 60*60 个点位
  23. for (let j =0;j<60;j++) {
  24. dataAll[j] = []
  25. for (let k =0;k<60;k++) {
  26. if(typeof (data[j]) == 'undefined') {
  27. dataAll[j][k] = 0
  28. } else {
  29. if(typeof (data[j][k]) == 'undefined') {
  30. dataAll[j][k] = 0
  31. } else {
  32. dataAll[j][k] = data[j][k]
  33. }
  34. }
  35. }
  36. }
  37. return pressureDataProcess(dataAll,1,4)
  38. },
  39. }
  40. function pressureDataProcess(a,scale,size) {
  41. var height = 60;
  42. var width = 60;
  43. var newHeight = 60*scale;
  44. var newWidth = 60*scale;
  45. var u =0.0;
  46. var v = 0.0;
  47. var x = 0.0;
  48. var y = 0.0;
  49. var m = 0;
  50. var n = 0;
  51. let temp = new Array()
  52. let rearr = []
  53. for(let i = 0;i<newHeight;++i) {
  54. temp[i] = new Array()
  55. for(let j=0;j<newWidth;++j) {
  56. y = i/scale;
  57. x = j/scale;
  58. m = parseInt(y);
  59. n = parseInt(x);
  60. v = y-m;
  61. u = x-n;
  62. let tt = {}
  63. if(m<height-1 &&n<width-1){
  64. temp[i][j] = parseInt((1.0-v)*((1.0-u)*a[m][n]+u*a[m][n+1])
  65. + v*((1.0-u)*a[m+1][n] + u*a[m+1][n+1])
  66. )
  67. } else {
  68. temp[i][j] = a[m][n]
  69. }
  70. tt.x = i*size
  71. tt.y = j*size
  72. if(temp[i][j]>0) {
  73. tt.value = temp[i][j]
  74. rearr.push(tt)
  75. }
  76. }
  77. }
  78. return rearr
  79. }