-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJY61P.js
157 lines (127 loc) · 4.85 KB
/
JY61P.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const i2c = require('i2c-bus');
const i2c1 = i2c.openSync(1);
// 电量
// i2c1.writeByteSync(0x48, 0x40, 255)
const d = i2c1.readByteSync(0x48, 0x40);
console.log(d);
// x,y,z角度=Angle/32768*180
// const data1 = i2c1.readWordSync(0x50, 0x3d);
// const data2 = i2c1.readWordSync(0x50, 0x3e);
// const data3 = i2c1.readWordSync(0x50, 0x3f);
// // 时间
// const data4 = i2c1.readWordSync(0x50, 0x30);
// const data5 = i2c1.readWordSync(0x50, 0x31);
// const data6 = i2c1.readWordSync(0x50, 0x32);
// const data7 = i2c1.readWordSync(0x50, 0x33);
// 模块温度 = */100 °c
// const data8 = i2c1.readWordSync(0x50, 0x40);
// // 轴加速度xyz = Angle/32768*16
// const data9 = i2c1.readWordSync(0x50, 0x34);
// const data10 = i2c1.readWordSync(0x50, 0x35);
// const data11 = i2c1.readWordSync(0x50, 0x36);
// // 轴角速度xyz = Angle/32768*2000
// const data12 = i2c1.readWordSync(0x50, 0x37);
// const data13 = i2c1.readWordSync(0x50, 0x38);
// const data14 = i2c1.readWordSync(0x50, 0x39);
// // 高低气压pa
// const data15 = i2c1.readWordSync(0x50, 0x45);
// const data16 = i2c1.readWordSync(0x50, 0x46);
// // 高度低|高cm
// const data17 = i2c1.readWordSync(0x50, 0x47);
// const data18 = i2c1.readWordSync(0x50, 0x48);
// 高低经度 = %10000000/100000 lon
// const data19 = i2c1.readWordSync(0x50, 0x49);
// const data20 = i2c1.readWordSync(0x50, 0x4a);
// // 高低纬度 = %10000000/100000 lat
// const data21 = i2c1.readWordSync(0x50, 0x4b);
// const data22 = i2c1.readWordSync(0x50, 0x4c);
// // GPS高度
// const data23 = i2c1.readWordSync(0x50, 0x4d);
// // GPS航向角
// const data24 = i2c1.readWordSync(0x50, 0x4e);
// // GPS 地速低字
// const data25 = i2c1.readWordSync(0x50, 0x4f);
// // GPS 地速高字
// const data26 = i2c1.readWordSync(0x50, 0x50);
// const txt1 = `角度:x:${data1 / 32768 * 180},y:${data2 / 32768 * 180},z:${data3 / 32768 * 180}`
// const txt2 = `GPS高度:${data23 / 100}`
// const txt3 = `模块温度:${data8 / 100}`
// const a = (data19.toString() + data20.toString()) % 10000000
// const b = (data21.toString() + data22.toString()) % 10000000
// console.log(data19, data20);
// console.log(data21, data22);
// console.log(txt1);
const bf = Buffer.alloc(8)
i2c1.writeByteSync(0x50, 0x49, 2)
i2c1.i2cReadSync(0x50, bf.length, bf);
const a = bf.readUIntBE(0, 6).toString();//切分字节流
console.log(a);
console.log(bf);
const bd = Buffer.alloc(8)
i2c1.writeByteSync(0x50, 0x4a, 2)
i2c1.i2cReadSync(0x50, bd.length, bd);
const b = bd.readUIntBE(0, 6).toString();//切分字节流
console.log(b);
console.log(bd);
console.log(+a + +b);
/**
* 北斗坐标系度分秒计算
* @param msg
* @return
*/
function str_To_Gps84 (msg) {
let lat = 0;
let lon = 0;
let split = msg.split(",");
if (split[4] == ("N") || split[4] == ("S")) {
const i = split[3].indexOf(".");
const latInt = split[3].substring(0, i - 2);
const latDec = split[3].substring(i - 2);
const i1 = split[5].indexOf(".");
const lonInt = split[5].substring(0, i1 - 2);
const lonDec = split[5].substring(i1 - 2);
lat = (+latInt) + (latDec) / 60;
lon = (+lonInt) + (lonDec) / 60;
}
return { lat, lon };
}
/** 高德采用GCJ编码 https://blog.csdn.net/weixin_45566249/article/details/118305913
* 84 to 火星坐标系 (GCJ-02)
* @param lat
* @param lon
*/
function gps84_To_Gcj02 (lat, lon) {
const pi = 3.1415926535897932384626;
const a = 6378245.0;
const ee = 0.00669342162296594323;
let dLat = transformLat(lon - 105.0, lat - 35.0);
let dLon = transformLon(lon - 105.0, lat - 35.0);
const radLat = lat / 180.0 * pi;
let magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
const sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
const Lat = +lat + dLat;
const Lon = +lon + dLon;
return { Lat, Lon }
}
function transformLat (x, y) {
const pi = 3.1415926535897932384626;
let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y
+ 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
function transformLon (x, y) {
const pi = 3.1415926535897932384626;
let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1
* Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0
* pi)) * 2.0 / 3.0;
return ret;
}