Browse Source

增加姿态+GPS 串口调试demo
Signed-off-by: caner <5658514@qq.com>

caner 3 years ago
parent
commit
17318d2107
2 changed files with 51 additions and 0 deletions
  1. 36 0
      JY61P+GPS.JS
  2. 15 0
      package.json

+ 36 - 0
JY61P+GPS.JS

@@ -0,0 +1,36 @@
+const { SerialPort } = require('serialport')
+const { ByteLengthParser } = require('@serialport/parser-byte-length')
+const port = new SerialPort({ path: 'COM5', baudRate: 115200 })
+const parser = port.pipe(new ByteLengthParser({ length: 12 }))
+
+
+// 切片
+
+const sliceTo55 = (buffer) => {
+    const num = buffer.indexOf(0x55)
+    if (num === 0) {
+        const newBuffer = buffer.slice(num, num + 11)
+        if (newBuffer[1] === 0x50) {
+            const time = `${newBuffer[2].toString()}年${newBuffer[3].toString()}月${newBuffer[4].toString()}日 ${newBuffer[5].toString()}:${newBuffer[6].toString()}:${newBuffer[7].toString()}`
+            console.log('时间', time);
+        } else if (newBuffer[1] === 0x58) {
+            const gps = `${((newBuffer[9] << 24) | (newBuffer[8] << 16) | (newBuffer[7] << 8) | (newBuffer[6])) / 1000}`
+            console.log('GPS地速', gps);
+        } else if (newBuffer[1] === 0x51) {
+            const C = `${(newBuffer[9] << 8 | newBuffer[8]) / 100}`
+            console.log('温度', C);
+        } else if (newBuffer[1] === 0x53) {
+            const P = `${(newBuffer[9] << 8 | newBuffer[8])}`
+            console.log('版本号', P);
+        } else if (newBuffer[1] === 0x53) {
+            const P = `${(newBuffer[9] << 8 | newBuffer[8])}`
+            console.log('版本号', P);
+        }
+
+    }
+}
+
+
+parser.on('data', data => {
+    sliceTo55(data)
+})

+ 15 - 0
package.json

@@ -0,0 +1,15 @@
+{
+  "name": "test",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "serialport": "^10.4.0",
+    "i2c-bus": "^5.2.2"
+  }
+}