1.0.8 • Published 2 years ago

phenet-obd2-pids v1.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

phenet-obd2-pids


Build and Publish React NPM Package

https://dev.to/femi_dev/how-to-build-and-publish-your-first-react-npm-package-24o3

  • install build tool npm i -D microbundle
  • config build package https://github.com/tungsm38/phenet-obd2-pids/blob/phenet-obd2-pids/package.json#L1
    {
      "name": "phenet-obd2-pids",
      "version": "1.0.5",
      "description": "OBD-II command encode/decode.",
      "main": "dist/index.js",
      "type": "module",
      "source": "src/index.js",  
      "module": "dist/index.module.js",
      "unpkg": "dist/index.umd.js",
      "scripts": {
        "build": "microbundle",           
        "dev": "microbundle watch"        
      },
      "repository": {
        "type": "git",
        "url": "git+ssh://git@github.com/tungsm38/phenet-obd2-pids.git"
      },
      "keywords": [
        "phenet"
      ],
      "author": "phenet-smartcar",
      "license": "ISC",
      "bugs": {
        "url": "https://github.com/tungsm38/phenet-obd2-pids/issues"
      },
      "homepage": "https://github.com/tungsm38/phenet-obd2-pids#readme",
      "devDependencies": {
        "microbundle": "^0.15.1"
      }
    }
  • build pkg npm run build

publish to npm

  • npm login
  • npm whoami
  • npm publish

Cách sử dụng package

  • install package npm i phenet-obd2-pids

Khởi tạo command

  • import
    import { ServiceManager } from 'phenet-obd2-pids';
    import { ServicesName, PIDsName } from 'phenet-obd2-pids';
  • khởi tạo object service
    var service = new ServiceManager();
  • khai báo command template:
    let cmd = JSON.parse('{"time": "null", "data": ""}');
  • append các pids cần request:
    service.appendCommandService(ServicesName.MODE_3_REQ_DTCS, cmd);
    service.appendCommandPID(PIDsName.Engine_speed, cmd);
    service.appendCommandPID(PIDsName.Throttle_position, cmd);
    service.appendCommandPID(PIDsName.VIN, cmd);
    service.appendCommandService(ServicesName.MODE_4_CLEAR_DTCS, cmd);
    console.log(cmd);
  • kết quả print log:
    Object { time: "13:33:7:356", data: "/2015:2:3:0:0:0:0:0:0/2015:2:1:12:0:0:0:0:0/2015:2:1:17:0:0:0:0:0/2015:2:9:2:0:0:0:0:0/2015:2:4:0:0:0:0:0:0" }

Decode command nhận được từ ESP

  • decode data nhận từ ESP (đã decrypt)
    // fake command
    let recv_cmd = JSON.parse(
    '{ "time": "13:28:58:730", "data": "2024:3:65:12:18:52:0:0:0;/2024:3:65:13:18:0:0:0:0;/2024:16:20:73:2:1:51:70:65;2024:33:68:80:52:70:74:50:66;2024:34:77:49:49:51:57:49:51;/2024:16:20:67:2:1:51:70:65;2024:33:68:80:52:70:74:50:66;2024:34:77:49:49:51:57:49:51;/"}'
    )
    // decode command
    let results = service.decode(recv_cmd);
    // print result
    console.log(results.data.split('/').filter(Boolean));
  • kết quả print log
    Array(4) [ "1165", "18", "3FADP4FJ2BM113913", "P0133;C0641;C0450;P3446;C01032;C02413;P3131;P3339;P3133;" ]

code example

import { ServiceManager } from 'phenet-obd2-pids';
import { ServicesName, PIDsName } from 'phenet-obd2-pids';

var service = new ServiceManager();

// ### Khởi tạo command (encode) ###
/* test Service */
let cmd = JSON.parse('{"time": "null", "data": ""}');

service.appendCommandService(ServicesName.MODE_3_REQ_DTCS, cmd);
service.appendCommandPID(PIDsName.Engine_speed, cmd);
service.appendCommandPID(PIDsName.Throttle_position, cmd);
service.appendCommandPID(PIDsName.VIN, cmd);
service.appendCommandService(ServicesName.MODE_4_CLEAR_DTCS, cmd);
console.log(cmd);

// ### Decode ###
// fake command
let recv_cmd = JSON.parse(
  '{ "time": "13:28:58:730", "data": "2024:3:65:12:18:52:0:0:0/2024:3:65:13:18:0:0:0:0/2024:16:20:73:2:1:51:70:65;2024:33:68:80:52:70:74:50:66;2024:34:77:49:49:51:57:49:51/2024:16:20:67:2:1:51:70:65;2024:33:68:80:52:70:74:50:66;2024:34:77:49:49:51:57:49:51/"}'
)
// decode command
let results = service.decode(recv_cmd);
// print result
console.log(results.data.split('/').filter(Boolean));
  
1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago