Registry / http-networking / complete-teltonika-parser

complete-teltonika-parser

JSON →
library0.3.6jsnpmunverified

The `complete-teltonika-parser` library, currently at version 0.3.6, provides robust parsing capabilities for various Teltonika communication protocols, specifically focusing on AVL data ('data sending') and GPRS messages. It differentiates itself by handling the complexities of Teltonika codecs, such as Codec 12 for GPRS messages, and includes a separate utility function, `parseIMEI`, for device identification packets. A key feature is its careful handling of large numeric values within `IOelement.Elements`, converting them to strings (via `BigInt`) when they exceed JavaScript's `Number.MAX_SAFE_INTEGER` to prevent data loss. The library also ships with TypeScript types, enhancing developer experience by providing strong type checking for the parsed data structures. While no explicit release cadence is stated, updates are typically driven by new Teltonika codec specifications or community contributions.

npm install complete-teltonika-parser
INSTALL
IMPORT
SIG · COMPLETE-TELTONIKA
C
complete-teltonika-parser
http-networkingjavascriptv0.3.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ProtocolParser
import { ProtocolParser } from 'complete-teltonika-parser'
const { ProtocolParser } = require('complete-teltonika-parser')
While the README uses CommonJS `require`, ESM `import` is the standard for modern JavaScript/TypeScript.
parseIMEI
import { parseIMEI } from 'complete-teltonika-parser'
const { parseIMEI } = require('complete-teltonika-parser')
Used for parsing IMEI packets, separate from the main ProtocolParser class.
Data
import type { Data } from 'complete-teltonika-parser'
import { Data } from 'complete-teltonika-parser'
Imports `Data` as a type for static analysis. It's also exported at runtime, but typically consumed as a type.
IOelement
import type { IOelement } from 'complete-teltonika-parser'
Imports `IOelement` as a type for static analysis, providing structure for parsed I/O data.

This quickstart demonstrates how to use `ProtocolParser` for Teltonika data packets and `parseIMEI` for IMEI packets, including a common pattern for distinguishing between the two packet types based on length. It also illustrates how large numbers within IO elements are handled as strings.

import { ProtocolParser, parseIMEI } from 'complete-teltonika-parser'; // Example Teltonika data packet (hex string) const dataPacket = '00000000000000fd8e0100000176169220e000067673631b1ab6be008f00000f000000000031001800010000020000030100040000b30000b40000320000330000160400470300f00000150300c80000ef00009001004fff0051ff0052ff0053ff0055ff006e01007aff007fff286cff000d00090028000a0036000b003500f50027004327540044000000425c80001800000046009500ecfffd00edffe500ee03d00080ffff00080050ffffffff0054ffffffff0056ffffffff0057ffffffff0058ffffffff0068ffffffff0071ffffffff0087ffffffff000400da0000d546ca81f6ac00db383934343530323700dc303631393934313900dd3332320000000000000001000089fb'; // Example Teltonika IMEI packet (hex string) const imeiPacket = '000F333532303933303839313638383231'; // Function to determine packet type and parse accordingly function processPacket(packet: string) { if (packet.length === 34) { // IMEI packets have a constant length of 34 characters (17 bytes hex) console.log('Detected IMEI packet.'); return { imei: parseIMEI(packet) }; } else { console.log('Detected data packet.'); const parsed = new ProtocolParser(packet); // Type narrowing based on CodecType property if (parsed.CodecType === "data sending") { console.log('Parsed AVL data:', (parsed.Content as typeof parsed.Content).AVL_Datas[0]); } else if (parsed.CodecType === "GPRS messages") { console.log('Parsed GPRS message:', parsed.Content); } return { dataPacket: parsed }; } } // Process the example data packet const dataResult = processPacket(dataPacket); console.log('Data parsing result:', dataResult.dataPacket?.Content?.['AVL_Datas']?.[0]?.GPSelement); // Process the example IMEI packet const imeiResult = processPacket(imeiPacket); console.log('IMEI parsing result:', imeiResult.imei); // Demonstrating large number handling (conceptual, not from live packet) // In a real scenario, you'd check IOelement.Elements values directly. const exampleIOelement = { EventID: 1, ElementCount: 1, Elements: { 1000: 'FFFFFFFFFFFFFFFF' // Represents a very large number } }; const largeValueHex = exampleIOelement.Elements[1000] as string; let largeValue: number | string = parseInt(largeValueHex, 16); if (largeValue > Number.MAX_SAFE_INTEGER) { largeValue = BigInt(`0x${largeValueHex}`).toString(); } console.log('Example of large IO element value:', largeValue);
Debug
Known issues
breakingThe parser will throw an exception if the data packet has an invalid CRC. Implement robust error handling (e.g., try-catch blocks) around parsing operations.
fix
Wrap `new ProtocolParser()` calls in a try-catch block to gracefully handle `Error` exceptions related to invalid CRC. Consider logging the malformed packet for debugging.
affects: >=0.1.0
gotchaOnly GPRS Codec 12 is currently supported for GPRS messages. Attempting to parse packets using other GPRS codecs may result in incorrect data or parsing failures.
fix
Verify that your Teltonika devices are configured to use Codec 12 for GPRS messages if you intend to parse them with this library. For other codecs, consider alternative parsers or contributing to this library.
affects: >=0.1.0
gotchaValues in `IOelement.Elements` that are too large to fit into JavaScript's `Number.MAX_SAFE_INTEGER` will be returned as strings (representing a BigInt). Direct numeric operations on these values will require careful handling or conversion.
fix
Always check the type of `IOelement.Elements` values. If a `string`, parse it as `BigInt` if arithmetic is needed, or handle it as a string. Avoid `parseInt()` alone for these values without prior BigInt conversion if precision beyond `Number.MAX_SAFE_INTEGER` is critical.
affects: >=0.1.0
gotchaThe `ProtocolParser` is designed solely for parsing Teltonika protocol data (AVL, GPRS messages), not the device IMEI. Using it for IMEI packets will lead to parsing errors.
fix
Always use the dedicated `parseIMEI` function for packets identified as IMEI. A common pattern is to check packet length (IMEI packets are often fixed length, e.g., 34 hex characters) before deciding which parser to use.
affects: >=0.1.0
gotchaThe `ProtocolParser` constructor accepts an optional `basic_read: boolean` parameter. If `true`, the `Content` property of the parsed object will be `null`, which can cause runtime `TypeError` if accessed without a null check.
fix
Ensure `basic_read` is `false` if you need the `Content` to be fully parsed. If `basic_read` is `true`, always check `parsed.Content !== null` before attempting to access properties like `parsed.Content.AVL_Datas`.
affects: >=0.1.0
gotchaThe library expects all input packets (for both `ProtocolParser` and `parseIMEI`) to be raw hexadecimal strings. Providing inputs in other formats (e.g., binary buffers, UTF-8 strings) will lead to parsing errors.
fix
Ensure all input data is converted to a hexadecimal string representation before passing it to the parser functions. For example, `Buffer.from('...', 'hex').toString('hex')` or similar pre-processing.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Invalid CRC
The received Teltonika data packet failed its Cyclic Redundancy Check (CRC) validation, indicating data corruption.
fix
Wrap `new ProtocolParser()` calls in a try-catch block. Log the erroneous packet for analysis. The device might be sending corrupted data, or there's network noise. You might consider ignoring the packet or requesting retransmission if your setup allows.
TypeError: packet.slice is not a function
The input `packet` provided to `ProtocolParser` or `parseIMEI` is not a string, but likely a `Buffer` or other object.
fix
Convert your input data to a hexadecimal string before passing it to the parser. For example, if you receive a Node.js `Buffer`, use `buffer.toString('hex')`.
TypeError: Cannot read properties of null (reading 'AVL_Datas')
Attempting to access `parsed.Content.AVL_Datas` when `parsed.Content` is `null`.
fix
This typically occurs if `new ProtocolParser(packet, true)` (with `basic_read: true`) was used. Ensure `basic_read` is `false` if full content parsing is desired, or add a null check: `if (parsed.Content && parsed.CodecType === "data sending") { /* access AVL_Datas */ }`.
IMEI parsing error: Invalid length or format
The string provided to `parseIMEI` does not conform to the expected length (e.g., 34 characters for a 17-byte hex IMEI) or contains non-hexadecimal characters.
fix
Validate the input string's length and character set before calling `parseIMEI`. Ensure it's a pure hexadecimal string of the correct length for Teltonika IMEI packets.
Upgrade
Version history
0.3.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
complete-teltonika-parser — npm install complete-teltonika-parser · libregistry