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-parserVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
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.
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`.
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.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.
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')`.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 */ }`.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.
No dependency data recorded yet.