npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

complete-teltonika-parser-fork

v0.3.8

Published

Parser for teltonika codecs

Downloads

271

Readme

TeltonikaParser

Install this parser using npm: npm i complete-teltonika-parser

const { ProtocolParser, parseIMEI, Data, GPRS } = require('complete-teltonika-parser')
const packet = '00000000000000fd8e0100000176169220e000067673631b1ab6be008f00000f000000000031001800010000020000030100040000b30000b40000320000330000160400470300f00000150300c80000ef00009001004fff0051ff0052ff0053ff0055ff006e01007aff007fff286cff000d00090028000a0036000b003500f50027004327540044000000425c80001800000046009500ecfffd00edffe500ee03d00080ffff00080050ffffffff0054ffffffff0056ffffffff0057ffffffff0058ffffffff0068ffffffff0071ffffffff0087ffffffff000400da0000d546ca81f6ac00db383934343530323700dc303631393934313900dd3332320000000000000001000089fb'
let parsed = new ProtocolParser(packet)
console.log(parsed)
if (parsed.CodecType == "data sending") {
    let data = parsed.Content as Data
} else {
    let gprs = parsed.Content as GPRS
}

const imei = parseIMEI('000F333532303933303839313638383231')
console.log(imei)

Q: How can I know that a packet is the device imei or the data packet?

A: The packet containing the imei has a constant length: 34

function processPacket (packet) {
    if (packet.length == 34) {
        return {
            imei: parseIMEI(packet)
        }
    } else {
        return { 
            dataPacket: new ProtocolParser(packet)
        }
    }
}

ProtocolParser has the following signature:

class ProtocolParser {
    Packet : string
    Preamble: number
    Data_Length: number
    CodecID: number
    Quantity1: number
    CodecType: 'data sending' | 'GPRS messages'
    Content : GPRS | Data | null
    Quantity2: number
    CRC: number
    constructor(packet: string, basic_read: boolean, on_ioElement_error: (e: Error) => void) {
      // code
    }
}

class Data {
  AVL_Datas : AVL_Data[]
}

class AVL_Data  {
    Timestamp : Date
    Priority : number
    GPSelement : GPSelement
    IOelement : IOelement
}

class GPSelement {
    Longitude : number,
    Latitude : number,
    Altitude : number,
    Angle : number,
    Satellites : number,
    Speed : number
}

class IOelement {
    EventID: number
    ElementCount: number
    Elements: {
        [avlid: number]: number | string
    }
}

class GPRS {
    type : 5 | 6
    isResponse : boolean
    responseStr : string
}

Where if basic_read == true, then the property 'Content' will not be parsed.

Notice that values from IOelement.Elements can also be string. Thats because some values may be too bit to fit javascript's number type. To ilustrate that, here is the actual code to extract the value:

function extractValue (x: string) => {
  var y: number | string = parseInt(x, 16);
  if (y > Number.MAX_SAFE_INTEGER) {
    y = BigInt(`0x${x}`).toString();
  }
  return y;
}

NOTICE

  • If the data packet has an invalid CRC, then the parser will fail throwing an exception;
  • The only GPRS codec supported is Codec 12;
  • This is a PROTOCOL parser. It does not parse the device IMEI. For that, use the function parseIMEI;
  • The file "AVL Data Parser/IOelement" has some useful funcitons and an avl id translator for teltonika device model FMB640.